def __init__(self, **kwargs): super(Menu, self).__init__(**kwargs) global fullapp self.size = fullapp.size self.canvas.add(Color(1,1,1)) LoginField = Widget() LoginField.orientation = 'vertical' LoginField.size = (Window.size[0]*0.7,Window.size[1]*0.23) LoginField.pos = (Window.size[0]*0.327,Window.size[1]*0.793) rect = Rectangle(size = LoginField.size,source = 'LoginWindow.png',pos = LoginField.pos) LoginField.canvas.add(rect) SomeLabel = Label(text='acc',color=(0,0,0,0.85),font_size=Window.size[1]*0.03,bold=True) SomeLabel.pos = (Window.size[0]*0.5,Window.size[1]*0.865) NickNameButton = Button(color=(0,0,0,1),font_size=Window.size[1]*0.034,bold=True) NickNameButton.pos = (Window.size[0]*0.4,Window.size[1]*0.88) NickNameButton.size = (Window.size[0]*0.55,Window.size[1]*0.064) NickNameButton.text = fullapp.get_user_name() NickNameButton.on_press = self.change_user NickNameButton.background_color = (0,0,0,0) LoginButton = Button(text = 'Pushers',color=(0.48,0.14,0.165,1),font_size=Window.size[1]*0.03,italic=True) LoginButton.background_color = (0,0,0,0) LoginButton.pos = (Window.size[0]*0.5,Window.size[1]*0.82) LoginButton.size = (Window.size[0]*0.38,Window.size[1]*0.064) LoginButton.on_press = self.notify LoginField.add_widget(SomeLabel) LoginField.add_widget(NickNameButton) LoginField.add_widget(LoginButton) self.LoginField = LoginField self.add_widget(LoginField)
def _key_handler(self, a, b, c, d, e): if b == 1001 and self.bPopup == False: self.bPopup = True content = Widget() sizehintW = 0.9 sizehintH = 0.2 btnSizeW = rootW * sizehintW * 0.5 btnSizeH = rootH * sizehintH * 0.5 popup = Popup(title="Exit?", content=content, auto_dismiss=False, size_hint=(sizehintW, sizehintH)) content.pos = popup.pos btn_Yes = Button(text='Yes', pos=(cx - btnSizeW * 0.1 - btnSizeW * 0.75, cy - btnSizeH * 0.5), size=(btnSizeW * 0.75, btnSizeH * 0.75)) btn_No = Button(text='No', pos=(cx + btnSizeW * 0.1, cy - btnSizeH * 0.5), size=(btnSizeW * 0.75, btnSizeH * 0.75)) content.add_widget(btn_Yes) content.add_widget(btn_No) def closePopup(instance): popup.dismiss() self.bPopup = False btn_Yes.bind(on_press=self.stop) btn_No.bind(on_press=closePopup) popup.open()
def on_subloc_select_clicked(self): subloc_drop_main_btn = Widget(size_hint=(None, None), size=(200, 30)) self.add_widget(subloc_drop_main_btn) subloc_drop_main_btn.pos = ( self.subloc_btn.x + self.subloc_btn.width, self.subloc_btn.y + self.subloc_btn.height) try: self.subloc_drop.open(subloc_drop_main_btn) except: pass self.remove_widget(subloc_drop_main_btn)
def createProgressPopup(self, title, itemCount): self.destroyProgressPopup() # loading flag self.bProgress = True content = Widget() sizehintW = 0.3 sizehintH = 0.25 self.progressPopup = Popup(title = title, content=content, auto_dismiss=False, size_hint = (sizehintW, sizehintH)) content.pos = self.progressPopup.pos pbSize = mul(WH, (sizehintW * 0.9, sizehintH * 0.9)) self.progress = ProgressBar(value=0, max=itemCount, pos=sub(cXY, (pbSize[0] * 0.5, sizehintH * H * 0.75)), size=pbSize) content.add_widget(self.progress) self.progressPopup.open()
def createProgressPopup(self, title, itemCount): self.destroyProgressPopup() # loading flag self.bProgress = True content = Widget() sizehintW = 0.3 sizehintH = 0.25 self.progressPopup = Popup(title=title, content=content, auto_dismiss=False, size_hint=(sizehintW, sizehintH)) content.pos = self.progressPopup.pos pbSize = mul(WH, (sizehintW * 0.9, sizehintH * 0.9)) self.progress = ProgressBar( value=0, max=itemCount, pos=sub(cXY, (pbSize[0] * 0.5, sizehintH * H * 0.75)), size=pbSize) content.add_widget(self.progress) self.progressPopup.open()
def _key_handler(self, a,b,c,d,e): if b == 1001 and self.bPopup == False: self.bPopup = True content = Widget() sizehintW = 0.9 sizehintH = 0.2 btnSizeW = rootW * sizehintW * 0.5 btnSizeH = rootH * sizehintH * 0.5 popup = Popup(title = "Exit?", content=content, auto_dismiss=False, size_hint = (sizehintW, sizehintH)) content.pos=popup.pos btn_Yes = Button(text='Yes', pos = (cx-btnSizeW*0.1- btnSizeW*0.75, cy - btnSizeH*0.5), size=(btnSizeW*0.75, btnSizeH*0.75)) btn_No = Button(text='No', pos = (cx+btnSizeW*0.1, cy - btnSizeH*0.5), size=(btnSizeW*0.75, btnSizeH*0.75)) content.add_widget(btn_Yes) content.add_widget(btn_No) def closePopup(instance): popup.dismiss() self.bPopup=False btn_Yes.bind(on_press=self.stop) btn_No.bind(on_press=closePopup) popup.open()
def popup_Exit(self): if self.bPopup: return self.bPopup = True content = Widget() sizehintW = 0.9 sizehintH = 0.2 btnSizeW = W * sizehintW * 0.5 btnSizeH = H * sizehintH * 0.5 popup = Popup(title = "Exit?", content=content, auto_dismiss=False, size_hint = (sizehintW, sizehintH)) content.pos=popup.pos btn_Yes = Button(text='Yes', pos = (cX-btnSizeW*0.1- btnSizeW*0.75, cY - btnSizeH*0.5), size=(btnSizeW*0.75, btnSizeH*0.75)) btn_No = Button(text='No', pos = (cX+btnSizeW*0.1, cY - btnSizeH*0.5), size=(btnSizeW*0.75, btnSizeH*0.75)) content.add_widget(btn_Yes) content.add_widget(btn_No) def closePopup(instance): popup.dismiss() self.bPopup=False btn_Yes.bind(on_press=self.stop) btn_No.bind(on_press=closePopup) popup.open()
def test_no_parent(): from kivy.uix.widget import Widget from kivy_garden.draggable import \ save_widget_location, restore_widget_location w = Widget() location = save_widget_location(w) assert location == { 'x': 0, 'y': 0, 'width': 100, 'height': 100, 'size_hint_x': 1, 'size_hint_y': 1, 'pos_hint': {}, 'size_hint_min_x': None, 'size_hint_min_y': None, 'size_hint_max_x': None, 'size_hint_max_y': None, } w.pos = [ 20, 20, ] w.size = [ 40, 40, ] w.size_hint = [ None, None, ] w.pos_hint = { 'x': 1, 'top': .5, } w.size_hint_min = [ 30, 30, ] w.size_hint_max = [ 70, 70, ] restore_widget_location(w, location) assert w.size == [ 100, 100, ] assert w.pos == [ 0, 0, ] assert w.size_hint == [ 1, 1, ] assert w.pos_hint == {} assert w.size_hint_min == [ None, None, ] assert w.size_hint_max == [ None, None, ]
def __init__(self, title, body, options, **kwargs): """Construct NSPopup Arguments title: title of Popup body: text to comprise of Popup body options: dictionary of format {"option": callback, ...} -- options to be listed on buttons, and the function to call on option trigger """ """Basic Widget constructor""" super(NSPopup, self).__init__(width=self.DEFAULT_WIDTH, height=self.DEFAULT_HEIGHT) """Store data""" self.options = options """Center popup relative to screen""" self.x = (Window.width - self.width) / 2 self.y = (Window.height - self.height) / 2 """Set formatting defaults""" self.size = [self.DEFAULT_WIDTH, self.DEFAULT_HEIGHT] """Selection is originally nothing""" self.selection = None """Layout constants""" num_buttons = len(options) BUTTON_MAX_WIDTH = 150 PADDING = 10 BUTTON_BALANCED_WIDTH = (self.width - (num_buttons + 1) * PADDING) / num_buttons BUTTON_WIDTH = min(BUTTON_BALANCED_WIDTH, BUTTON_MAX_WIDTH) BUTTON_HEIGHT = 50 BUTTON_PADDING = (self.width - (num_buttons * BUTTON_WIDTH)) /\ (num_buttons + 1) BUTTON_TEXT_SIZE = [BUTTON_WIDTH, BUTTON_HEIGHT] BUTTON_FONT_SIZE = 12 BUTTON_Y = self.y + PADDING BACKGROUND_COLOR = Color(0.2, 0.2, 0.2) EDGE_COLOR = Color(0.6, 0.6, 0.6) EDGE_WIDTH = self.width EDGE_HEIGHT = self.height EDGE_SIZE = [EDGE_WIDTH, EDGE_HEIGHT] BORDER_SIZE = 5 BACKGROUND_WIDTH = EDGE_WIDTH - BORDER_SIZE * 2 BACKGROUND_HEIGHT = EDGE_HEIGHT - BORDER_SIZE * 2 BACKGROUND_SIZE = [BACKGROUND_WIDTH, BACKGROUND_HEIGHT] TITLE_HEIGHT = 50 TITLE_WIDTH = BACKGROUND_WIDTH - PADDING TITLE_FONT_SIZE = 18 TITLE_PADDING_ABOVE = 50 TITLE_TOP = self.top - BORDER_SIZE - TITLE_PADDING_ABOVE TITLE_TEXT_SIZE = [TITLE_WIDTH, TITLE_HEIGHT] BODY_HEIGHT = self.height - PADDING - BUTTON_HEIGHT - PADDING - \ PADDING - TITLE_HEIGHT - PADDING BODY_PADDING_SIDES = 30 BODY_WIDTH = BACKGROUND_WIDTH - PADDING - BODY_PADDING_SIDES * 2 BODY_TEXT_SIZE = [BODY_WIDTH, BODY_HEIGHT] BODY_FONT_SIZE = 14 """Create background""" edge = Widget() edge.pos = self.pos edge.canvas = Canvas() edge.canvas.add(EDGE_COLOR) edge_rectangle = Rectangle(size=EDGE_SIZE) edge_rectangle.pos = edge.pos edge.canvas.add(edge_rectangle) self.add_widget(edge) background = Widget() background.x = edge.x + BORDER_SIZE background.y = edge.y + BORDER_SIZE background.canvas = Canvas() background.canvas.add(BACKGROUND_COLOR) background_rectangle = Rectangle(size=BACKGROUND_SIZE) background_rectangle.pos = background.pos background.canvas.add(background_rectangle) self.add_widget(background) """Make a button for each option""" option_button_x = self.x + BUTTON_PADDING for option in options.keys(): option_button = Button(text=option, width=BUTTON_WIDTH, valign='middle', halign='center', height=BUTTON_HEIGHT, text_size=BUTTON_TEXT_SIZE, font_size=BUTTON_FONT_SIZE) option_button.x = option_button_x option_button.y = BUTTON_Y option_button.bind(on_release=self.select_option) self.add_widget(option_button) """Increment x for the next button""" option_button_x += option_button.width + BUTTON_PADDING """Create title label""" title = Label(text=title, valign='middle', halign='center', text_size=TITLE_TEXT_SIZE, font_size=TITLE_FONT_SIZE, TITLE=TITLE_WIDTH, height=TITLE_HEIGHT) title.center_x = self.center_x title.top = TITLE_TOP self.add_widget(title) """Create main message label""" body = Label(text=body, valign='top', halign='center', text_size=BODY_TEXT_SIZE, font_size=BODY_FONT_SIZE, BODY=BODY_WIDTH, height=BODY_HEIGHT) body.center_x = self.center_x body.top = title.y - PADDING self.add_widget(body)
def drawObj(self, obj=None): ''' Updates a object if object already on widget. Otherwise it will create a object Override this function to create your own apperance of ojects ''' assert isinstance(obj, mrGraphicsObject) if type(obj) == None: return False # get obj attributes objID = obj.getID() objname = obj.getName() location = self.convertPosition( obj.getLocation() ) color = obj.getColor() wObj = None # draw objects with self.canvas: # set color Color( color[0], color[1], color[2], color[3] ) if type(obj) == mrGraphicsBot: # draw bot assert isinstance(obj, mrGraphicsBot) size = self.convertSize( obj.getSize() ) angle = obj.getAngle() lineW, points, points2, corners = self.getBotDrawData(location, size) print "points", points, points2 p0 = corners[0] p3 = corners[3] # draw object wObj = {'widget': Widget( pos=p0 ), 'label': None} lbl = Label( text=str(objID)+":"+objname, pos=p3 ) lbl.texture_update() tsize = lbl.texture.size lbl.size = (tsize[0], tsize[1]) wObj['label'] = lbl # draw dot with wObj['widget'].canvas.before: PushMatrix() Rotate( angle=angle, axis=(0,0,1), origin=(location[0], location[1], 0) ) with wObj['widget'].canvas.after: PopMatrix() with wObj['widget'].canvas: Color( color[0], color[1], color[2], color[3] ) Line( points=points, width=lineW ) Line( points=points2, width=lineW ) if angle != 0: with wObj['label'].canvas.before: PushMatrix() Rotate( angle=angle, axis=(0,0,1), origin=(location[0], location[1], 0) ) with wObj['label'].canvas.after: PopMatrix() if type(obj) == mrGraphicsRectangle: # draw rectangle assert isinstance(obj, mrGraphicsRectangle) size = self.convertSize( obj.getSize() ) pos = ( location[0]-size[0]/2, location[1]-size[1]/2 ) angle = obj.getAngle() # draw new object wObj = Widget( size=size, pos=pos ) # draw rectangle with wObj.canvas: Color( color[0], color[1], color[2], color[3] ) Rectangle( size=size, pos=pos ) if angle != 0: with wObj.canvas.before: PushMatrix() Rotate( angle=angle, axis=(0,0,1), origin=(location[0], location[1], 0) ) with wObj.canvas.after: PopMatrix() if type(obj) == mrGraphicsLine: #draw line assert isinstance(obj, mrGraphicsLine) points = self.convertPoints( obj.getPoints() ) width = self.convertSize( obj.getWidth() ) # draw new object wObj = Line( points=points, width=width ) if type(obj) == mrGraphicsDot: #draw dot assert isinstance(obj, mrGraphicsDot) radius = self.convertSize( obj.getRadius() ) size = (2*radius, 2*radius) pos = ( location[0]-radius, location[1]-radius ) # draw new object wObj = Ellipse( pos=pos, size=size ) if type(obj) == mrGraphicsCircle: #draw cricle assert isinstance(obj, mrGraphicsCircle) radius = self.convertSize( obj.getRadius() ) width = self.convertSize( obj.getWidth() ) # draw new object wObj = Line( circle=(location[0], location[1], radius), width=width ) if type(obj) == mrGraphicsText: #draw text assert isinstance(obj, mrGraphicsText) text = obj.getText() textcolor = obj.getTextColor() fontsize = obj.getFontSize() angle = obj.getAngle() # draw new object padding = 5 wObj = Label( text=text, pos=location, markup=True, color=textcolor ) if fontsize != None: print "set fontsize", fontsize wObj.font_size = fontsize wObj.texture_update() size = wObj.texture.size wObj.size = (size[0]+2*padding, size[1]+2*padding) with wObj.canvas.before: PushMatrix() Rotate( angle=angle, axis=(0,0,1), origin=(location[0], location[1], 0) ) Color( color[0], color[1], color[2], color[3] ) Rectangle( pos=wObj.pos, size=wObj.size) with wObj.canvas.after: PopMatrix() if type(obj) == mrGraphicsImage: # draw image assert isinstance(obj, mrGraphicsImage) src = obj.getSource() keepRatio = obj.keepRatio() size = self.convertSize( obj.getSize() ) angle = obj.getAngle() if isfile(src): wObj = AsyncImage( source=src, size=size, allow_stretch=True, keep_ratio=keepRatio ) wObj.texture_update() pos = (location[0]-size[0]*0.5, location[1]-size[1]*0.5) wObj.pos = pos size = wObj.size if angle != 0: with wObj.canvas.before: PushMatrix() Rotate( angle=angle, axis=(0,0,1), origin=(location[0], location[1], 0) ) with wObj.canvas.after: PopMatrix() # send update request to canvas self.canvas.ask_update() # return new object return wObj