''' Created on Dec 6, 2014 @author: Brett Paufler (c) Copyright Brett Paufler Kivy App Kivy is not loaded In CBU-Installed, please find Kivy-1.8.0-py2.7-win32kivy.zip unzip drop this naked .py file on kivy.bat in first directly program should run unzip drop this naked .py file on This is a sort of paint/sticker app push the button, stuff goes to screen very rudimentary (dots, squares, ovals, different colors, incomplete implementation) if I were another person, I'd delete but I'm not, so I keep thus, not the end of the world, if never recoverable or never run again Or per previous notes: A simple text app for shapes, but not really More of a paiting (sticker style) app Main Widget Class, then an App Class ''' from kivy.app import App from kivy.uix.widget import Widget from kivy.graphics import Color, Ellipse, Line, Rectangle, Point from kivy.uix.button import Button from kivy.uix.floatlayout import FloatLayout class ShapeShifter(Widget): def __init__(self): Widget.__init__(self) self.paintColor = [1,1,1,1] self.objectSize = 10.0 self.effect = "rectangle" def on_touch_down(self, touch): with self.canvas: Color(self.paintColor[0],self.paintColor[1], self.paintColor[2],self.paintColor[3]) d = self.objectSize if self.effect == "rectangle": Rectangle(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d)) elif self.effect == "ellipse": Ellipse(pos=(touch.x - d / 2, touch.y - d / 2), size=(2*d, d)) elif self.effect == "circle": Line(circle=(touch.x,touch.y,d)) elif self.effect == "point": Point(points=[touch.x,touch.y], pointsize=d/5) class ShapeShifterApp(App): def build(self): parent = FloatLayout() drawArea = ShapeShifter() drawArea.size_hint=(1.0, 0.8) drawArea.pos_hint={'x':0, 'y':.1} parent.add_widget(drawArea) #Top Row Color Buttons def color_set(button): drawArea.paintColor = button.background_color print drawArea.paintColor colorButton = [] colorList = [[1,0,0,1],[1,1,0,1],[0,1,0,1], [0,1,1,1],[0,0,1,1],[1,0,1,1] ] for r in range(len(colorList)): cB = Button(size_hint=(1.0, 0.1), pos_hint={'x':r*1.0/len(colorList), 'y':0.9}, opacity = 1, background_color = colorList[r] ) colorButton.append(cB) parent.add_widget(colorButton[r]) colorButton[r].bind(on_release=color_set) #Functions for Buttons def clearScreen(obj): drawArea.canvas.clear() def plusSize(obj): drawArea.objectSize += 5.0 def minusSize(obj): drawArea.objectSize -= 5.0 def setRectangle(obj): drawArea.effect = "rectangle" def setEllipse(obj): drawArea.effect = "ellipse" def setCircle(obj): drawArea.effect = "circle" def setPoint(obj): drawArea.effect = "point" effectButton = [] effectList = [("CLEAR",clearScreen), ("PLUS", plusSize), ("MINUS",minusSize), ("SQUARE",setRectangle), ("OVAL",setEllipse), ("CIRCLE",setCircle), ("POINT", setPoint) ] dS = float(len(effectList)) c = 0 for k,v in effectList: eB = Button(size_hint=(1.0/dS, 0.1), pos_hint={'x':c/dS, 'y':0.0}, opacity = 1, text = k, id = k ) effectButton.append(eB) parent.add_widget(effectButton[c]) effectButton[c].bind(on_release=v) c += 1 print "Parent Ids" print (parent.ids) ''' parent.add_widget(Button(text='Clear', size_hint=(0.5, 0.1), pos_hint={'x':0, 'y':0.0})) parent.add_widget(Button(text='Clear Again', size_hint=(0.5, 0.1), pos_hint={'x':0.5, 'y':0.0})) ''' return parent if __name__ == '__main__': ShapeShifterApp().run()