def addButtons(self): for i, button_text_label in enumerate(self.buttonList): temp_button = MyButton(text = button_text_label) #if these two colors are not redefined in the inherited class, the default is used temp_button.color = self.menu_color_letters temp_button.background_color = [.8, .7,0, .9] #now add dropdown buttons dropdown = DropDown() #if in parameter settings, combine dict to string if i is 1: for y in self.paradigm_setup_values: submenu_string = y+': '+str(self.paradigm_setup_values[y]) btn = Button(text=submenu_string, size_hint_y=None, height=44) btn.background_color = [.8, .9,.7, .9] btn.bind(on_release=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) else: for submenu_string in self.menu_items[i]: # when adding widgets, we need to specify the height manually (disabling # the size_hint_y) so the dropdown can calculate the area it needs. btn = Button(text=submenu_string, size_hint_y=None, height=44) btn.background_color = [.8, .9,.7, .9] # for each button, attach a callback that will call the select() method # on the dropdown. We'll pass the text of the button as the data of the # selection. btn.bind(on_release=lambda btn: dropdown.select(btn.text)) #then add the button inside the dropdown dropdown.add_widget(btn) #bind the dropdown to the main menu button temp_button.bind(on_release = dropdown.open) dropdown.bind(on_select=lambda instance, x: self.menu_function_handler(x)) #get info about what has been pressed #dropdown.bind(on_select=lambda instance, x: setattr(temp_button, 'text', x)) self.layout_top_menu.add_widget(temp_button)
def showModes(self, relativeTo): """show the list of modes""" try: dropdown = DropDown(auto_width=True) btn = Button(text='Disabled', markup=True, size_hint_y=None, height='44dp') btn.bind(on_press=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) btn = Button(text='Toggle', markup=True, size_hint_y=None, height='44dp') btn.bind(on_press=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) btn = Button(text='Button', markup=True, size_hint_y=None, height='44dp') btn.bind(on_press=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) btn = Button(text='Analog', markup=True, size_hint_y=None, height='44dp') btn.bind(on_press=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) dropdown.bind(on_select=self.ModeSelected) dropdown.open(relativeTo) except Exception as e: showError(e)
def showOutputs(self, relativeTo): """show a list of possible outputs""" if self.mode != 'Disabled': try: dropdown = DropDown(auto_width=True) btn = Button(text="None", markup=True, size_hint_y=None, height='44dp') btn.dataItem = None btn.bind(on_press=lambda btn: dropdown.select(btn.dataItem)) dropdown.add_widget(btn) for item in out.outputs: if item.isActive == True: btn = Button(text=str(item.number) + " (" + item.assetLabel + ")", markup=True, size_hint_y=None, height='44dp') btn.dataItem = item btn.bind(on_press=lambda btn: dropdown.select(btn.dataItem)) dropdown.add_widget(btn) for item in out.relays: if item.isActive == True: btn = Button(text=str(item.number) + " (" + item.assetLabel + ")", markup=True, size_hint_y=None, height='44dp') btn.dataItem = item btn.bind(on_press=lambda btn: dropdown.select(btn.dataItem)) dropdown.add_widget(btn) dropdown.bind(on_select=self.OutputSelected) dropdown.open(relativeTo) except Exception as e: showError(e)
class GroupDropdown(Button): def __init__(self, db: DBMuziek, default=None, **kwargs): super(GroupDropdown, self).__init__(**kwargs) self.dropdown = DropDown() self.group_id = None self.text = "<Choice>" self.update_data(default) self._db = db self.groups = None self.update_groups() self.bind(on_release=self.open) self.dropdown.bind(on_select=lambda _, btn: self.on_select(btn)) def update_data(self, data): if data: self.group_id = data["group_id"] self.text = data["group_name"] def reset_choice(self, dd=None): if dd: dd.dismiss() self.text = "<Choice>" self.group_id = None def update_groups(self): self.groups = self._db.get_groups() self.dropdown.clear_widgets() btn = Button(text="<Choice>", size_hint_y=None, height=44) btn.bind(on_release=lambda _: self.reset_select()) self.dropdown.add_widget(btn) for group in self.groups: btn = GroupButton(text=group["group_name"], size_hint_y=None, height=44) btn.set_id(group["group_id"]) btn.bind(on_release=self.dropdown.select) self.dropdown.add_widget(btn) btn = Button(text="+", size_hint_y=None, height=44) btn.bind(on_release=lambda _: summon_popup_group(self._db, self.dropdown)) self.dropdown.add_widget(btn) def reset_select(self): self.reset_choice() self.dropdown.select(None) def open(self, btn): self.update_groups() self.dropdown.open(btn) def on_select(self, btn=None): if btn is not None: self.text = btn.text self.group_id = btn.group_id
def selectList(w): global shoppingList dropdown = DropDown( on_select=lambda instance, selected: setActive(selected), ) index = -1 for item in shoppingList['lists']: index += 1 if index == shoppingList['active']: continue btn = Button( text=item['name'], size_hint_y=None, background_color=settings['sectionColor'], height=settings['itemSize'], ) btn.index = index btn.bind(on_release=lambda btn: dropdown.select(btn.index)) dropdown.add_widget(btn) about = Button( text="About Plocka", size_hint_y=None, background_color=settings['sectionColor'], height=settings['itemSize'], ) about.bind(on_release=lambda about: dropdown.select(-1)) dropdown.add_widget(about) dropdown.open(w)
class PlaylistDropdown(Button): def __init__(self, db: DBMuziek, **kwargs): super(PlaylistDropdown, self).__init__(**kwargs) self._db = db self.dropdown = DropDown() self.playlist_id = None self.text = "<Choice>" self.playlists = None self.update_playlists() self.bind(on_release=self.open) self.dropdown.bind(on_select=lambda _, btn: self.on_select(btn)) def reset_choice(self, dd=None): if dd: dd.dismiss() self.text = "<Choice>" self.playlist_id = None def update_playlists(self): self.playlists = self._db.get_playlists() self.dropdown.clear_widgets() btn = Button(text="<Choice>", size_hint_y=None, height=44) btn.bind(on_release=lambda _: self.reset_select()) self.dropdown.add_widget(btn) for playlist in self.playlists: btn = PlaylistButton(text=playlist["playlist_name"], size_hint_y=None, height=44) btn.set_id(playlist["playlist_id"]) btn.bind(on_release=self.dropdown.select) self.dropdown.add_widget(btn) btn = Button(text="+", size_hint_y=None, height=44) btn.bind(on_release=lambda _: summon_popup_playlist( self._db, self.dropdown)) self.dropdown.add_widget(btn) def reset_select(self): self.reset_choice() self.dropdown.select(None) def open(self, btn): self.update_playlists() self.dropdown.open(btn) def on_select(self, btn=None): if btn is not None: self.text = btn.text self.playlist_id = btn.playlist_id
class ControlTypePicker(Button): app = ObjectProperty() key = ObjectProperty() mainbutton = ObjectProperty() dropdown = ObjectProperty() set_control = ObjectProperty() def __init__(self, **kwargs): super().__init__(**kwargs) self.build() def set_value(self, k, v): if v is None: del self.app.selected_proxy[k] else: self.app.selected_proxy[k] = v def build(self, *args): if None in (self.key, self.set_control): Clock.schedule_once(self.build, 0) return self.mainbutton = None self.dropdown = None self.dropdown = DropDown() self.dropdown.bind( on_select=lambda instance, x: self.set_control(self.key, x)) readoutbut = Button(text='readout', size_hint_y=None, height=self.height, background_color=(0.7, 0.7, 0.7, 1)) readoutbut.bind( on_release=lambda instance: self.dropdown.select('readout')) self.dropdown.add_widget(readoutbut) textinbut = Button(text='textinput', size_hint_y=None, height=self.height, background_color=(0.7, 0.7, 0.7, 1)) textinbut.bind( on_release=lambda instance: self.dropdown.select('textinput')) self.dropdown.add_widget(textinbut) togbut = Button(text='togglebutton', size_hint_y=None, height=self.height, background_color=(0.7, 0.7, 0.7, 1)) togbut.bind( on_release=lambda instance: self.dropdown.select('togglebutton')) self.dropdown.add_widget(togbut) sliderbut = Button(text='slider', size_hint_y=None, height=self.height, background_color=(0.7, 0.7, 0.7, 1)) sliderbut.bind( on_release=lambda instance: self.dropdown.select('slider')) self.dropdown.add_widget(sliderbut) self.bind(on_release=self.dropdown.open)
def build(self): rl = RelativeLayout(size=(300, 300)) currencies = ["Dollar", "Euro", "Robux", "Dong"] results = Label(text="Results", pos=(352, 135), size_hint=(.2, .1)) #self.hide_widget(results) b5 = Button(text="Convert", pos=(352, 235), size_hint=(.2, .1)) b2 = DropDown() for i in currencies: btn = Button(text=i, size_hint_y=None, height=44) btn.bind(on_release=lambda btn: b2.select(btn.text)) b2.add_widget(btn) # create a big main button mainbutton = Button(text='Currency 1', size_hint=(.2, .2), pos_hint={ 'center_x': .27, 'center_y': .6 }) mainbutton.bind(on_release=b2.open) b2.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x)) b3 = DropDown() for z in currencies: btn1 = Button(text=z, size_hint_y=None, height=44) btn1.bind(on_release=lambda btn1: b3.select(btn1.text)) b3.add_widget(btn1) # create a big main button mainbutton2 = Button(text='Currency 2', size_hint=(.2, .2), pos_hint={ 'center_x': .81, 'center_y': .6 }) mainbutton2.bind(on_release=b3.open) b3.bind(on_select=lambda instance, x: setattr(mainbutton2, 'text', x)) b4 = TextInput(size_hint=(.2, .1), pos=(352, 335), text="Enter Value", multiline=False) def callback(instance): value = float(b4.text) * 2.5 results.text = str(value) b5.bind(on_press=callback) rl.add_widget(mainbutton) rl.add_widget(mainbutton2) rl.add_widget(b4) rl.add_widget(results) rl.add_widget(b5) return rl
def __init__(self, *args, **kwargs): super(OneDayParameterWindow, self).__init__(*args, **kwargs) self.drop_down = CustomDropDown() self.temperatures = [ 0, -999, -999, -999, -999 ] # stores the values user inputs in each temperature box, used for value comparison # create drop down menu of select cities dropdown = DropDown() events = ["Light Rain", "Moderate Rain", "Heavy Rain", "Thunderstorm", "Wintry Mix", "Sleet", "Freezing Rain", "Flurries", "Snow Showers", \ "Snow", "Heavy Snow"] for event in events: # create button individually for each city btn = Button(text='%r' % event, size_hint_y=None, height=30, pos=(25, 25), on_release=lambda btn: sv.eventSave(btn.text)) btn.bind( on_release=lambda btn: dropdown.select(btn.text) ) # attach a callback which will pass the text selected as data dropdown.add_widget(btn) # create the main or default button mainbutton = Button(text='Event Type', size_hint=(0.5, 0.5)) mainbutton.bind( on_release=dropdown.open) # show drop down menu when released dropdown.bind(on_select=lambda instance, x: setattr( mainbutton, 'text', x)) # assign data to button text self.dropDownList.add_widget(mainbutton) ## For second drop down menu, for units measuring precipitation amounts dropdownTwo = DropDown() units = ["in", "ft", "mm", "cm"] for unit in units: # create button individually for each unit btnTwo = Button(text='%r' % unit, size_hint_y=None, height=30, pos=(25, 25), on_release=lambda btn: sv.unitSave(btnTwo.text)) btnTwo.bind( on_release=lambda btnTwo: dropdownTwo.select(btnTwo.text) ) # attach a callback which will pass the text selected as data dropdownTwo.add_widget(btnTwo) # create the main or default button mainbuttonTwo = Button(text='Units', size_hint=(0.5, 0.5)) mainbuttonTwo.bind(on_release=dropdownTwo.open) dropdownTwo.bind(on_select=lambda instance, x: setattr( mainbuttonTwo, 'text', x)) # assign data to button text self.dropDownListTwo.add_widget(mainbuttonTwo)
class TransactionDetailsDropDownButton(Button): def __init__(self, **kwargs): super(TransactionDetailsDropDownButton, self).__init__(**kwargs) self.text = 'All' self.details_id = None self.dropdown = DropDown() self.dropdown.max_height = 150 self.populate('earnings') self.bind(on_release=self.dropdown.open) self.dropdown.bind( on_select=lambda instance, x: setattr(self, 'text', x[1])) self.dropdown.bind( on_select=lambda instance, x: setattr(self, 'details_id', x[0])) def reset_button(self): self.text = 'All' self.details_id = None def populate(self, earnings_or_spendings): self.dropdown.clear_widgets() transaction_details = [] if earnings_or_spendings == "earnings": transaction_details = database_manager.details_read_by_type(1) elif earnings_or_spendings == "spendings": transaction_details = database_manager.details_read_by_type(0) btn = Button(text='All', size_hint_y=None, height=44) btn.data = (None, 'All') btn.bind(on_release=lambda btn: self.dropdown.select(btn.data)) # then add the button inside the dropdown self.dropdown.add_widget(btn) for transaction_detail in transaction_details: # When adding widgets, we need to specify the height manually # (disabling the size_hint_y) so the dropdown can calculate # the area it needs. btn = Button(text=transaction_detail[1], size_hint_y=None, height=44) btn.data = (str(transaction_detail[0]), transaction_detail[1]) # for each button, attach a callback that will call the select() method # on the dropdown. We'll pass the text of the button as the data of the # selection. btn.bind(on_release=lambda btn: self.dropdown.select(btn.data)) # then add the button inside the dropdown self.dropdown.add_widget(btn)
def alarmPopup(self, *args): # content of the popup to be sorted in this float layout box = FloatLayout() # hour selector hourbutton = Button(text='Select Hour', size_hint=(.2, .2), pos_hint={'x': .2, 'y': .5}) # dropdown menu which drops down from the hourbutton hourdropdown = DropDown() for i in range(24): if i < 10: btn = Button(text='0%r' % i, size_hint_y=None, height=70) else: btn = Button(text='%r' % i, size_hint_y=None, height=70) btn.bind(on_release=lambda btn: hourdropdown.select(btn.text)) hourdropdown.add_widget(btn) hourbutton.bind(on_release=hourdropdown.open) hourdropdown.bind(on_select=lambda instance, x: setattr(hourbutton, 'text', x)) # add widgets to the popup's float layout box.add_widget(hourbutton) box.add_widget(hourdropdown) # minute selector minutebutton = Button(text='Select Minute', size_hint=(.2, .2), pos_hint={'x': .6, 'y': .5}) # dopdown menu which drops down from the minutebutton minutedropdown = DropDown() for i in range(60): if i < 10: btn = Button(text='0%r' % i, size_hint_y=None, height=70) else: btn = Button(text='%r' % i, size_hint_y=None, height=70) btn.bind(on_release=lambda btn: minutedropdown.select(btn.text)) minutedropdown.add_widget(btn) minutebutton.bind(on_release=minutedropdown.open) minutedropdown.bind(on_select=lambda instance, x: setattr(minutebutton, 'text', x)) # add widgets to the popup's float layout box.add_widget(minutebutton) box.add_widget(minutedropdown) # button to dismiss alarm selector and set alarm once user has chosen alarm dismissButton = PopupDismissButton() box.add_widget(dismissButton) currentDay = time.strftime("%A") alarmPopup = Popup(title='Set Your Alarm for {}:'.format(currentDay), content=box, size_hint=(.8, .8)) dismissButton.bind(on_press=partial(dismissButton.dismissPopup, alarmPopup, hourbutton, minutebutton)) alarmPopup.open()
class InitOptions(GridLayout): def __init__(self, **kwargs): super(InitOptions, self).__init__(**kwargs) self.cols = 3 self.rows = 2 self.add_widget(Label(text='Number of frets')) self.add_widget(Label(text='Tuning')) self.add_widget(Label(text='Orientation')) self.fretDropDown = DropDown() for scaleLength in SCALELENGTHTABLE: btn = Button(text=scaleLength) btn.size_hint_y = None btn.height = 44 btn.bind(on_release=lambda btn: self.fretDropDown.select(btn.text)) self.fretDropDown.add_widget(btn) self.frets = Button(text='24') self.frets.bind(on_release=self.fretDropDown.open) self.fretDropDown.bind( on_select=lambda instance, x: setattr(self.frets, 'text', x)) self.tuningDropDown = DropDown() for tuning in TUNINGTABLE: btn = Button(text=tuning[0]) btn.size_hint_y = None btn.height = 44 btn.bind( on_release=lambda btn: self.tuningDropDown.select(btn.text)) self.tuningDropDown.add_widget(btn) self.tunings = Button(text='Standard') self.tunings.bind(on_release=self.tuningDropDown.open) self.tuningDropDown.bind( on_select=lambda instance, x: setattr(self.tunings, 'text', x)) self.orientationDropDown = DropDown() for orientation in ORIENTATIONTABLE: btn = Button(text=orientation) btn.size_hint_y = None btn.height = 44 btn.bind(on_release=lambda btn: self.orientationDropDown.select( btn.text)) self.orientationDropDown.add_widget(btn) self.orientations = Button(text='LEFT HANDED') self.orientations.bind(on_release=self.orientationDropDown.open) self.orientationDropDown.bind(on_select=lambda instance, x: setattr( self.orientations, 'text', x)) self.add_widget(self.frets) self.add_widget(self.tunings) self.add_widget(self.orientations)
class DropBut(Button): def __init__(self, **kwargs): super(DropBut, self).__init__(**kwargs) self.drop_list = None self.drop_list = DropDown() self.picked = False self.id = self.get_id() for ing in supported_ings: btn = Button(text=ing, size_hint_y=None, height=25) btn.bind(on_release=lambda btn: self.drop_list.select(btn.text)) self.drop_list.add_widget(btn) self.bind(on_release=self.drop_list.open) self.drop_list.bind(on_select=self.pick_ing) def get_id(self): dp_btns.append(True) return str(len(dp_btns) - 1) def pick_ing(self, instance, x): setattr(self, 'text', x) if not self.picked: inputs.append(x) self.picked = True else: inputs[int(self.id)] = x print(inputs)
def discover(self): """ Discovers nearby devices using the client object. :return: None """ my_box = DropDown() # drop down for discovered devices my_box.btns = [] # contains the buttons in the drop down child devices = self.client.discover( ) # discover and retrieve nearby devices my_box.btns = [] for device in devices: # create buttons for each discovered device in a drop down view print(device) button = Button(text=device[0], padding_x=25, padding_y=25, font_size=20, height=100, width=100) button.bind(on_press=lambda button: my_box.select(button.text)) my_box.btns.append(button) # keep tab on buttons my_box.add_widget(button) # add it to screen mainbutton = Button(text='Show devices', size_hint=(None, None)) mainbutton.bind(on_release=my_box.open) my_box.bind( on_select=lambda instance, x: setattr(mainbutton, 'text', x)) self.ids.d2.clear_widgets() # remove current widgets to add new one self.ids.d2.add_widget(my_box) # add the discovered devices
def build(self): self.title = 'Quick-Keys' self.icon = '1479186122476.png' Window.size = (winheight, winwidth) parent = FloatLayout() #parent.size = Window.size for i in range(len(symbols)): #btn[i] = Button(text = symbols[str(i+1)], size_hint = (widspacex, widspacey), pos_hint = widspaces[i]) #btn[i].bind(on_press = callback) #parent.add_widget(btn[i]) popup[i] = Popup(title = 'replace ' + symbols[str(i + 1)] + ' with', content = TextInput(text = symbols[str(i+1)], multiline = False)) #print popup[i].content.text popup[i].bind(on_dismiss = popup_callback) #newSymbol(str(i+1), popup[i].content.text)) btn[i] = addbutton(symbols[str(i+1)], (widspacex, widspacey), widspaces[i], popup[i].open, parent) serports = serial_ports() #print len(serports) port = DropDown() for i in range(len(serports)): dropbtn = Button(text = serports[i], size_hint_y = None, height = 44) dropbtn.bind(on_release = lambda dropbtn: port.select(dropbtn.text)) port.add_widget(dropbtn) portbtn = Button(text = ser.port, size_hint = (2/3, widspacey), pos_hint = {'x' : 0, 'y' : 0}) portbtn.bind(on_release = port.open) port.bind(on_select=lambda instance, x: setattr(portbtn, 'text', x)) parent.add_widget(portbtn) applybtn = addbutton('save', (1/3, widspacey), {'x' : 2/3, 'y' : 0}, callback, parent) #applybtn.bind(on_press = ser #applybtn = Button(text = 'apply', size_hint = (1/3, widspacey), pos_hint = {'x' : 2/3, 'y' : 0}) #applybtn.bind(on_press = callback) #parent.add_widget(applybtn) return parent
def createMainPage(app): # look for the current dir, its content and recipes in RECIPE_DIR f1 = os.popen('pwd') f2 = os.popen('ls') f3 = os.popen('ls ' + Settings.RECIPE_DIR) current_dir = f1.read() content_dir = f2.read() recipe_files = f3.read() # load main page main_page = Builder.load_file(Settings.KV_DIR + 'main.kv') # update message with recipe files main_page.ids[ '_message_'].text = text = "Looking for recipes in {}\n it contains: \n {}".format( Settings.RECIPE_DIR, recipe_files) # add each recipe file to the droplist and bind it so it is selected when # released droplist = DropDown() for rf in recipe_files.split('\n'): print(rf) if rf.endswith(".yaml") or rf.endswith(".yml"): btn = Button(text=rf, size_hint_y=None, height='30dp') btn.bind(on_release=lambda btn: droplist.select(btn.text)) btn.id droplist.add_widget(btn) main_page.ids['_mainbutton_'].bind(on_release=droplist.open) droplist.bind(on_select=app.loadRecipePage) #droplist.bind(on_select=lambda instance, x: setattr(main_page.ids['_mainbutton_'], 'text', x)) return main_page
def ouvrirMenuAttaque(self): box = BoxLayout(orientation='vertical') self.fenetreAttaque = Popup(title="Attaque") dropdown = DropDown() stats = Label(text='Veuillez selectionner une cible') confirm = Button(text="Voir") attaquer = Button(text="Attaquer") for key in store: btn = Button(text=store.get(key)['nom'], size_hint_y=None, height=44) btn.bind(on_release=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) mainbutton = Button(text='Cible :', size_hint=(None, None)) mainbutton.bind(on_release=dropdown.open) dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x)) box2 = BoxLayout(orientation='horizontal') fermer = Button(text="Fermer", font_size=20) box.add_widget(mainbutton) box.add_widget(stats) box2.add_widget(confirm) box2.add_widget(attaquer) box.add_widget(box2) box.add_widget(fermer) self.fenetreAttaque.add_widget(box) mainbutton.size_hint=(1,.1) confirm.size_hint=(.1,.1) fermer.size_hint=(1,.1) attaquer.size_hint=(.1,.1) confirm.bind(on_press=lambda x: self.actualise(stats, mainbutton.text)) attaquer.bind(on_press=lambda x: self.attaque(mainbutton.text)) fermer.bind(on_press=self.fenetreAttaque.dismiss) self.fenetreAttaque.open()
def create_drop_down(self, button, list=None, icon=None, border=None): border.rgb = get_color_from_hex('#023b80') icon.color = get_color_from_hex('#023b80') drop_down = DropDown() drop_down.fbind('on_dismiss', self.on_deselect, icon=icon, border=border) drop_down.bind(on_select=lambda instance, x: (setattr(button.ids.category, 'text', x), setattr(button.ids.category, 'color', get_color_from_hex('#023b80')), setattr(button.ids.icon, 'color', get_color_from_hex('#023b80')))) for text in list: new_item = CustomMenu(size_hint=(1, None), height=dp(45), text=text) new_item.bind( on_release=lambda item: drop_down.select(item.text)) drop_down.add_widget(new_item) drop_down.open(button)
def addDetails(*args): print("In procedure to add details") gridlayout = args[0] btn_add = args[1] label = Label(text="Argument Value Type: ",color=(1,0,0,1),font_size=10) label2 = Label(text="Default Argument Parameter: ",color=(1,0,0,1),font_size=10) label3 = Label(text="Default Value",color=(1,0,0,1),font_size=10) textInput = TextInput(id="textInputIDForDefaultArgParameter") textInput2 = TextInput(id="textInputIDForDefaultValue") gridlayout.add_widget(label) btnMain = Button(text="ValueType",id="valueTypeID") gridlayout.add_widget(btnMain) gridlayout.add_widget(label2) gridlayout.add_widget(textInput) gridlayout.add_widget(label3) gridlayout.add_widget(textInput2) kindOfValues = ['ABP','NSR','NER','STR','NBR'] dropdown = DropDown() for eachType in kindOfValues: btn_tmp = Button(text=eachType, size_hint_y=None, height=20) btn_tmp.bind(on_release=lambda btn_tmp: dropdown.select(btn_tmp.text)) dropdown.add_widget(btn_tmp) btnMain.bind(on_release=dropdown.open) dropdown.bind(on_select=lambda instance, x: setattr(btnMain,'text',x)) btn_add.disabled = False
class DefinedCharPopup: def __init__(self, text_processor): self.text_processor = text_processor self.word_input = TextInput(text='Input your ') self.drop_down = DropDown() part_of_speech_btns = ["noun", "adjective", "verb"] for part in part_of_speech_btns: btn = Button(text=part, size_hint_y=None, height=44) btn.bind(on_release=lambda btn: self.drop_down.select(btn.text)) self.drop_down.bind(on_select=self.on_select) self.drop_down.add_widget(btn) box_layout = BoxLayout(orientation='vertical') close_btn = Button(text='Close!') submit_btn = Button(text='Submit!') box_layout.add_widget(self.word_input) buttons_layout = BoxLayout(orientation='horizontal') buttons_layout.add_widget(submit_btn) buttons_layout.add_widget(close_btn) mainbtn_layot = RelativeLayout() mainbutton = Button(text='speech part', size_hint=(None, None), pos=(335, 35)) mainbutton.bind(on_release=self.drop_down.open) self.part_of_speech_char_layout = BoxLayout(orientation='horizontal') mainbtn_layot.add_widget(mainbutton) box_layout.add_widget(mainbtn_layot) box_layout.add_widget(self.part_of_speech_char_layout) self.drop_down.bind( on_select=lambda instance, x: setattr(mainbutton, 'text', x)) box_layout.add_widget(buttons_layout) self.popup = Popup(content=box_layout) close_btn.bind(on_press=self.popup.dismiss) submit_btn.bind(on_press=self.on_sumbit) self.part_of_speech_layout = None self.speach_part_to_layout = { 'noun': NounLayout(), 'adjective': AdjfLayout(), 'verb': VerbLayout() } def on_sumbit(self, obj): self.popup.dismiss() self.text_processor.set_word_analysis( self.word_input.text, self.part_of_speech_layout.string()) def open(self, obj): self.popup.open() def on_select(self, obj, x): if self.part_of_speech_layout != None: self.part_of_speech_char_layout.remove_widget( self.part_of_speech_layout.get()) self.part_of_speech_layout = self.speach_part_to_layout[x] self.part_of_speech_char_layout.add_widget( self.part_of_speech_layout.get())
class DropDownButton(Button): def __init__(self, **kwargs): super(DropDownButton, self).__init__(**kwargs) self.drop_list = DropDown() if kwargs.has_key('type'): types = kwargs['type'] else: types = ['empty'] if kwargs.has_key('module') and kwargs.has_key('widget'): mod = __import__(kwargs['module'], fromlist=kwargs['widget']) widget_name = kwargs['widget'] else: mod = __import__('kivy.uix.button', fromlist=['Button']) widget_name = 'Button' for i in types: attr = getattr(mod, widget_name) btn = attr(text=i, size_hint_y=None, height=50) btn.bind(on_release=lambda btn: self.drop_list.select(btn.text)) self.drop_list.add_widget(btn) self.bind(on_release=self.drop_list.open) self.drop_list.bind(on_select=lambda instance, x: setattr(self, 'text', x))
def __init__(self, widget, **kwargs): super(DataBindingEditor, self).__init__(**kwargs) dropdown = DropDown() for variable in variables: # when adding widgets, we need to specify the height manually (disabling # the size_hint_y) so the dropdown can calculate the area it needs. btn = Button(text='%s' % variable, size_hint_y=None, height=40) # for each button, attach a callback that will call the select() method # on the dropdown. We'll pass the text of the button as the data of the # selection. btn.bind(on_release=lambda btn: dropdown.select(btn.text)) # then add the button inside the dropdown dropdown.add_widget(btn) # create a big main button mainbutton = Button(text=widget.variable.name, size_hint=(None, None), pos_hint={'center_x': 0.5, 'center_y': 0.5}) # show the dropdown menu when the main button is released # note: all the bind() calls pass the instance of the caller (here, the # mainbutton instance) as the first argument of the callback (here, # dropdown.open.). mainbutton.bind(on_release=dropdown.open) # one last thing, listen for the selection in the dropdown list and # assign the data to the button text. dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x)) dropdown.bind(on_select=lambda instance, x: widget.set_var(x)) self.add_widget(mainbutton)
def update(self, *args): self.ids["Title"].text = self.title self.ids["Description"].text = self.description self._editorHolder.clear_widgets() if self.type == "numericSlider": if self.sliderMin is None or self.sliderMax is None: raise ValueError("'sliderMin' and / or 'sliderMax' cannot be 'None' if type is numericSlider") self._editorWidget = Slider(min=self.sliderMin, max=self.sliderMax, value=Config.getint(self.section, self.option), step=1) self._editorWidget.bind(value=self.value_changed) self._editorWidget2 = TextInput(multiline=False, font_size=self._editorHolder.height / 2, text=Config.get(self.section, self.option), input_filter="int") self._editorWidget2.bind(on_text_validate=self.text_box_int_validator) self._editorWidget2.bind(focus=self.text_box_int_validator) elif self.type == "bool": self._editorWidget = Switch(active=Config.getboolean(self.section, self.option)) self._editorWidget.bind(active=self.value_changed) elif self.type == "string": self._editorWidget = TextInput(multiline=False, font_size=self._editorHolder.height / 2, text=Config.get(self.section, self.option)) self._editorWidget.bind(on_text_validate=lambda *args: self.value_changed(None, self._editorWidget.text)) self._editorWidget.bind(focus=lambda *args: self.value_changed(None, self._editorWidget.text)) elif self.type == "option": self._editorWidget = Button(text=Config.get(self.section, self.option)) dropDown = DropDown() for option in self.options: text = str(option) try: text = text + " - " + str(self.extra_info[option]) except KeyError: pass btn = Button(text=text, size_hint_y=None, height=self.height) btn.tag = str(option) btn.bind(on_release=lambda _btn: dropDown.select(_btn.tag)) dropDown.add_widget(btn) self._editorWidget.bind(on_release=dropDown.open) self._editorWidget.bind(on_release=lambda *args: emptyFunction(dropDown.children)) dropDown.bind(on_select=lambda instance, x: setattr(self._editorWidget, 'text', x)) dropDown.bind(on_select=self.value_changed) if self._editorWidget2 is not None: self._editorHolder.add_widget(self._editorWidget2) if self.type != "title": self._editorHolder.add_widget(self._editorWidget)
def DropDown(self): dropdown = DropDown() for index in self.players: # When adding widgets, we need to specify the height manually # (disabling the size_hint_y) so the dropdown can calculate # the area it needs. btn = Button(text='%s' % index, font_size=40, size_hint_y=None, height=60) # for each button, attach a callback that will call the select() method # on the dropdown. We'll pass the text of the button as the data of the # selection. btn.bind(on_release=lambda btn: dropdown.select(btn.text)) # then add the button inside the dropdown dropdown.add_widget(btn) # create a big main button #mainbutton = Button(text='Hello', size_hint_y= None, height=44) # show the dropdown menu when the main button is released # note: all the bind() calls pass the instance of the caller (here, the # mainbutton instance) as the first argument of the callback (here, # dropdown.open.). #self.ids.addplayerbtn.bind(on_release=dropdown.open) dropdown.open(self.ids.splayerbtn) # one last thing, listen for the selection in the dropdown list and # assign the data to the button text. dropdown.bind(on_select=lambda instance, x: setattr( self.ids.splayerbtn, 'text', x)) #print(mainbutton.text) #runTouchApp(mainbutton) self.ids.checkoutbtn.disabled = False self.ids.checkinbtn.disabled = False
class ScaleOptions(GridLayout): def __init__(self, **kwargs): super(ScaleOptions, self).__init__(**kwargs) self.cols = 3 self.rows = 1 self.root = TextInput(text='Root Note') #self.scaleType = TextInput(text='Scale Type') self.scaleDropDown = DropDown() for scale in SCALETABLE: btn = Button(text=scale[0]) btn.size_hint_y = None btn.height = 44 btn.bind( on_release=lambda btn: self.scaleDropDown.select(btn.text)) self.scaleDropDown.add_widget(btn) self.scaleType = Button(text='Scale Type') self.scaleType.bind(on_release=self.scaleDropDown.open) self.scaleDropDown.bind( on_select=lambda instance, x: setattr(self.scaleType, 'text', x)) self.loadButton = Button(text='Show Scale') self.loadButton.bind(on_press=self.callback) self.add_widget(self.root) self.add_widget(self.scaleType) self.add_widget(self.loadButton) def callback(self, dt): scale = Scale(self.root.text, self.scaleType.text) highlight(scale.notes)
def build_dropdown(self): dropdown_layout = DropDown() for index in range(10): # When adding widgets, we need to specify the height manually # (disabling the size_hint_y) so the dropdown can calculate # the area it needs. btn2 = Button(text=f"Model {index:d}", size_hint_y=None, height=20) # for each button, attach a callback that will call the select() method # on the dropdown. We'll pass the text of the button as the data of the # selection. btn2.bind(on_release=lambda btn: dropdown_layout.select(btn.text)) dropdown_layout.add_widget( btn2) # then add the button inside the dropdown self._dropdown_btn = Button( text="Model", size_hint=(0.5, 0.1)) # create a big main button # show the dropdown menu when the main button is released # note: all the bind() calls pass the instance of the caller (here, the # mainbutton instance) as the first argument of the callback (here, # dropdown.open.). self._dropdown_btn.bind(on_release=dropdown_layout.open) # one last thing, listen for the selection in the dropdown list and # assign the data to the button text. dropdown_layout.bind(on_select=self.on_select_model) return self._dropdown_btn
class Color_Picker(Selection): colors = {"Sky Blue": (0.529, 0.808, 0.922)} browse_btn = Button(text="Browse") #browse_btn.bind(on_release=lambda x : x.root.browse(x)) # bind button to static FileBrowser' browse() function #browse_btn.bind(on_release=lambda x : FileBrowser.open(FileBrowser.instance)) def __init__(self, **kwargs): super(Color_Picker, self).__init__(**kwargs) # Layout for selecting items self.dropdown = DropDown() self.app = MDApp.get_running_app() self.picker_btn.text = "Choose Color" self.picker_btn.bind(on_release=self.dropdown.open) # Add colors to dropdown for color in self.colors: btn = Button(text=color, size_hint_y=None, height=40) # When a color is selected the name is passed to dropdown object btn.bind(on_release=lambda btn: self.dropdown.select(btn.text)) self.dropdown.add_widget(btn) self.dropdown.bind( on_select=lambda instance, x: setattr(self, 'selection', x)) def dismiss(self): self.dropdown.dismiss() def on_leave(self): self.dropdown.clear_widgets()
def DropDownCreation(data): Dropdown = DropDown() for i in data: drop_option = Button(text = i, size_hint_y = None, height = 40) drop_option.bind(on_release = lambda drop_option: Dropdown.select(drop_option.text)) Dropdown.add_widget(drop_option) return Dropdown
class SettingsScreen(ActionBarScreen): STR_SETTINGS = StringProperty() STR_RESET_DEFAULTS = StringProperty() STR_RESET_DEFAULTS_HELP = StringProperty() STR_RESET = StringProperty() STR_LANGUAGE_CHANGE = StringProperty() def __init__(self, **kwargs): # inicializace self.root = kwargs['root'] self.root.insertStrings.append((self, )) super(SettingsScreen, self).__init__(**kwargs) self.dropdown = DropDown() for index in LANGUAGES.itervalues(): btn = Button(text=index, size_hint_y=None, height=44, font_size='24dp', font_name="font/Roboto-Regular.ttf") btn.bind(on_release=lambda btn: self.dropdown.select(btn.text)) self.dropdown.add_widget(btn) self.language.bind(on_release=self.dropdown.open) self.dropdown.bind(on_select=lambda instance, x: setattr(self.language, 'text', x)) self.language.bind(text=self.change) def reset_defaults(self, *args): # Výmaz konfiguračního souboru po stisku tlačítka reset self.root.Cfg = ['' for y in range(4)] self.root.refreshCfg() def on_pre_enter(self, *args): # Před vstupem na obrazovku načte jazyky self.language.text = LANGUAGES.get(self.root.Cfg[0]) def change(self, *args): # Změní jazyk, znovu načte řetězce self.root.Cfg[0] = [y[0] for y in LANGUAGES.items() if y[1] == self.language.text][0] self.root.refreshCfg() self.root.doStrInsert()
class UserManagementInterface(ModalView): message_input = ObjectProperty(None) sprite_input = ObjectProperty(None) delay_input = ObjectProperty(None) user_dropdown_button = ObjectProperty(None) def __init__(self, caller, **kwargs): super(UserManagementInterface, self).__init__(**kwargs) self.caller = caller self.dropdown = DropDown() def ready(self): users = self.caller.debug_mode.get_created_users() for username in users: user = users[username] btn = Button(text=user.username, size_hint_y=None, height=40) btn.bind(on_release=lambda b: self.dropdown.select(b.text)) self.dropdown.add_widget(btn) self.user_dropdown_button.bind(on_release=self.dropdown.open) self.dropdown.bind(on_select=lambda instance, x: setattr( self.user_dropdown_button, 'text', x)) def send_message(self): self.caller.send_message(self.user_dropdown_button.text, self.message_input.text, self.sprite_input.text, self.delay_input.text) self.dismiss()
class EnumDropDown(Widget): dropdown = ObjectProperty() def __init__(self, enum_class, **kwargs): super(EnumDropDown, self).__init__(**kwargs) self.dropdown = DropDown() self.mainbutton = Button(text='Hello', size_hint=(None, None)) self.mainbutton.bind(on_release=self.dropdown.open) for data in enum_class: # When adding widgets, we need to specify the height manually # (disabling the size_hint_y) so the dropdown can calculate # the area it needs. btn = Button(text=f'Value {data.name!s}', size_hint_y=None, height=44) # for each button, attach a callback that will call the select() method # on the dropdown. We'll pass the text of the button as the data of the # selection. btn.bind(on_release=lambda btn: self.dropdown.select(btn.text)) # then add the button inside the dropdown self.dropdown.add_widget(btn) self.dropdown.bind( on_select=lambda instance, x: setattr(self.mainbutton, 'text', x)) self.add_widget(self.mainbutton)
class DropBut(SelectableView, Button): # drop_list = None types = ['int16', 'int32', 'int64', 'uint16', 'uint32', 'uint64', 'float32', 'float64'] drop_down = None def __init__(self, data_model, **kwargs): super(DropBut, self).__init__(**kwargs) self.data_model = data_model self.drop_down = DropDown() for i in self.types: btn = Button(text=i, size_hint_y=None, height=45, background_color=(0.0, 0.5, 1.0, 1.0)) btn.bind(on_release=lambda b: self.drop_down.select(b.text)) self.drop_down.add_widget(btn) self.bind(on_release=self.drop_down.open) self.drop_down.bind(on_select=self.on_formatter_select) def select_from_composite(self, *args): # self.bold = True pass def deselect_from_composite(self, *args): # self.bold = False pass def on_formatter_select(self, instance, value): self.data_model.on_formatter_update(self.index, self.text, value) self.text = value
class DropDownMenu(Button): types = DictProperty() def __init__(self, default_text='', **kwargs): super(DropDownMenu, self).__init__(**kwargs) self.drop_list = None self.drop_list = DropDown() self.text = default_text self.name = '' """Button bindings""" self.bind(on_release=self.drop_list.open) """Dropdown bindings""" self.drop_list.bind(on_select=self.set_text) """generates a button for each type in types""" def on_types(self, instance, value): self.clear_widgets() for type in self.types: btn = Button(text=type, size_hint_y=None, height=50) btn.bind(on_release=lambda btn: self.drop_list.select(btn.text)) self.drop_list.add_widget(btn) def set_text(self, instance, value): setattr(self, 'text', value)
def __init__(self, *args, **kwargs): super(CityWindow, self).__init__(*args, **kwargs) self.drop_down = CustomDropDown() # create drop down menu of select cities dropdown = DropDown() cities = ["All", "San Francisco/Oakland", "Davis/Sacramento", "Santa Clara Valley", "Los Angeles/Orange County", "San Diego", "New York City", \ "Baltimore"] for city in cities: # create button individually for each city btn = Button(text='%r' % city, size_hint_y=None, height=30, pos=(25, 25), on_release=lambda btn: sv.citySelect(btn.text)) btn.bind( on_release=lambda btn: dropdown.select(btn.text) ) # attach a callback which will pass the text selected as data dropdown.add_widget(btn) # create the main or default button mainbutton = Button(text='Select city/region', size_hint=(0.5, 0.5)) mainbutton.bind( on_release=dropdown.open) # show drop down menu when released dropdown.bind(on_select=lambda instance, x: setattr( mainbutton, 'text', x)) # assign data to button text self.dropDownList.add_widget(mainbutton)
def __init__(self,*args,**kwargs): super(MenuScreen, self).__init__(*args, **kwargs) self.drop_down = CustomDropDown() notes_dropdown = ObjectProperty(None) dropdown = DropDown() notes = ['Features', 'Suggestions', 'Abbreviations', 'Miscellaneous'] for note in notes: # when adding widgets, we need to specify the height manually (disabling # the size_hint_y) so the dropdown can calculate the area it needs. btn = Button(text='%r' % note, size_hint_y=None, height=30) # for each button, attach a callback that will call the select() method # on the dropdown. We'll pass the text of the button as the data of the # selection. btn.bind(on_release=lambda btn: dropdown.select(btn.text)) # then add the button inside the dropdown dropdown.add_widget(btn) # create a big main button mainbutton = Button(text='Usage Notes 2', size_hint=(1, 1)) # show the dropdown menu when the main button is released # note: all the bind() calls pass the instance of the caller (here, the # mainbutton instance) as the first argument of the callback (here, # dropdown.open.). mainbutton.bind(on_release=dropdown.open) #dd_btn.bind(on_release=dropdown.open) # one last thing, listen for the selection in the dropdown list and # assign the data to the button text. dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x)) #dropdown.bind(on_select=lambda instance, x: setattr(dd_btn, 'text', x)) self.top_layout.add_widget(mainbutton)
def create_droplist(self): def updatelist(instance, x): setattr(mainbutton, 'text', x) self.tableSelected = x print(x) dropdown = DropDown() for index in self.tables: # When adding widgets, we need to specify the height manually # (disabling the size_hint_y) so the dropdown can calculate # the area it needs. btn = Button(text=index['TABLE_NAME'], size_hint_y=None, height=25) # for each button, attach a callback that will call the select() method # on the dropdown. We'll pass the text of the button as the data of the # selection. btn.bind(on_release=lambda btn: dropdown.select(btn.text)) # then add the button inside the dropdown dropdown.add_widget(btn) mainbutton = Button(text='Select the Table ', size_hint=(None, None), width=250, height=35) mainbutton.bind(on_release=dropdown.open) #ropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x)) dropdown.bind(on_select=updatelist) sn2 = self.sm.get_screen(name='tablescreen') sn2.children[0].add_widget(mainbutton) return dropdown
class OverviewScreen(BoxLayout): def __init__(self, **kwargs): super(OverviewScreen, self).__init__(**kwargs) self.orientation = 'vertical' self.add_widget(Label(text='Player Name')) self.p_name = TextInput(multiline=False) self.add_widget(self.p_name) self.add_widget(Label(text='Character Name')) self.c_name = TextInput(multiline=False) self.add_widget(self.c_name) self.add_widget(Label(text='Race')) self.race_dropdown = DropDown() race_list = [] with open("races.txt") as f: for line in f: race_list.append(line) for index in race_list: btn = Button(text=index, size_hint_y=None, height=30) btn.bind( on_release=lambda btn: self.race_dropdown.select(btn.text)) self.race_dropdown.add_widget(btn) self.race_mainbutton = Button(text='Races') self.race_mainbutton.bind(on_release=self.race_dropdown.open) self.race_dropdown.bind(on_select=lambda instance, x: setattr( self.race_mainbutton, 'text', x)) self.add_widget(self.race_mainbutton) self.add_widget(Label(text='Occupation')) self.occupation_dropdown = DropDown() occupation_list = [] with open("occupations.txt") as f: for line in f: occupation_list.append(line) for index in occupation_list: btn = Button(text=index, size_hint_y=None, height=30) btn.bind(on_release=lambda btn: self.occupation_dropdown.select( btn.text)) self.occupation_dropdown.add_widget(btn) self.occupation_mainbutton = Button(text='Occupations') self.occupation_mainbutton.bind( on_release=self.occupation_dropdown.open) self.occupation_dropdown.bind(on_select=lambda instance, x: setattr( self.occupation_mainbutton, 'text', x)) self.add_widget(self.occupation_mainbutton)
class FormScreen(GridLayout): def submission(self): print("Submitted") print(self.username.text) print(self.password.text) print(self.mainbutton.text) def __init__(self, **kwargs): super(FormScreen, self).__init__(**kwargs) self.cols = 2 self.image = AsyncImage(source='https://www.logolynx.com/images/logolynx/ad/ad0eb0cfc1afa21d427b5bae775fe536.jpeg') self.add_widget(self.image) self.add_widget(Label(text='Registration Form')) # Label and Text Entry self.add_widget(Label(text='User Name')) self.username = TextInput(multiline=False) self.add_widget(self.username) # Label and Password Entry self.add_widget(Label(text='password')) self.password = TextInput(password=True, multiline=False) self.add_widget(self.password) # Label and Dropdown self.add_widget(Label(text='Select Option')) self.dropdown = DropDown() options = ['One', 'Two', 'Three'] self.mainbutton = Button(text="One") self.add_widget(self.mainbutton) self.mainbutton.bind(on_release=self.dropdown.open) ## Assigns the selected option self.dropdown.bind(on_select=lambda instance, x: setattr(self.mainbutton, 'text', x)) for option in options: # When adding widgets, we need to specify the height manually # (disabling the size_hint_y) so the dropdown can calculate # the area it needs. self.btn = Button(text=option, size_hint_y=None, height=44) # for each button, attach a callback that will call the select() method # on the dropdown. We'll pass the text of the button as the data of the # selection. self.btn.bind(on_release=lambda btn: self.dropdown.select(btn.text)) # then add the button inside the dropdown self.dropdown.add_widget(self.btn) # Submit Button self.submitbtn = Button(text="Submit") self.add_widget(self.submitbtn) self.submitbtn.bind(on_release=lambda x:self.submission())
def __init__(self, intManager, cursor, caller,**kwargs): super(ReservationSet, self).__init__(**kwargs) self.intManager = intManager; self.caller = caller self.cols = 8 for colName in (\ "Number",\ "Plate Number",\ "Brand",\ "Model",\ "Type of Fuel",\ "Number of doors",\ "Type of car",\ "Price",\ ): self.add_widget(MyLabel(\ text="[color=FD0000]" + colName + "[/color]",\ markup=True,\ font_size=20,\ underline=True,multiline=True)) self.cursorList = [] selectDropdown = DropDown() counter = 0 ff = 0 for row in cursor: self.cursorList.append(row) self.add_widget( MyLabelAlt1(text=str(counter)) if ff == 0 else MyLabelAlt2(text=str(counter)) ) for el in row: self.add_widget( MyLabelAlt1(text=str(el)) if ff == 0 else MyLabelAlt2(text=str(el)) ) ff = (ff + 1)%2 twoBtn = Button(text=str(counter), font_size=14, size_hint_y=None, height=30, background_color=(1.0, 0.0, 0.0, 1.0)) twoBtn.bind(on_release=lambda btn: selectDropdown.select(btn.text)) selectDropdown.add_widget(twoBtn); counter = counter + 1 self.selectionBtn = Button(text='1', font_size=14, background_color=(0.0, 0.0, 1.0, 1.0)) self.selectionBtn.bind(on_release=selectDropdown.open) selectDropdown.bind(on_select=lambda instance, x: setattr(self.selectionBtn, 'text', x)) self.add_widget(self.selectionBtn) submitBtn = Button(text='Make reservation', font_size=14) submitBtn.bind(on_press=processReservation) self.add_widget(submitBtn) backBtn = Button(text='Back', font_size=14) backBtn.bind(on_press=backCall) self.add_widget(backBtn)
def show_dropdown(self, button, *largs): dp = DropDown() dp.bind(on_select=lambda instance, x: setattr(button, 'text', x)) for i in self.modality_list: item = Button(text=i, size_hint_y=None, height=44) item.bind(on_release=lambda btn: dp.select(btn.text)) dp.add_widget(item) dp.open(button)
def make_dropdown(labels, callback, width = 80, line_height = 30): dropdown = DropDown(auto_width=False, width=width) for name in labels: btn = Button(text=str(name), size_hint_y=None, height=line_height) btn.bind(on_release=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) dropdown.bind(on_select=callback) return dropdown
def __init__(self, *args, **kwargs): super(EyeballerEntry, self).__init__(*args, **kwargs) self.drop_down = CustomDropDown() dropdown = DropDown() notes = [] try: with open((str(App.get_running_app().user_data_dir))[:-5]\ + "/usernames.csv", 'r+') as usernamefile: for row in usernamefile: if row != "": notes.append(row[:-1]) except IOError: notes.append("No Users") for note in notes: btn = Button(text='%s' % note, size_y = "30", size_hint_y =\ None, color = (0,0,0,0.75), background_color = (255.0, 255.0,\ 255.0, 1)) btn.bind(on_release=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) self.ids.user_name.bind(on_release=dropdown.open) dropdown.bind(on_select=lambda instance, x: setattr(\ self.ids.user_name, 'text', x)) dropdown2 = DropDown() notes2 = [] try: with open((str(App.get_running_app().user_data_dir))[:-5]\ + "/categories.csv", 'r+') as categoryfile: for row2 in categoryfile: if row2 != "": notes2.append(row2[:-1]) except IOError: notes2.append("No Categories") for note2 in notes2: btn2 = Button(text='%s' % note2, size_y = "30", size_hint_y =\ None, color = (0,0,0,0.75), background_color = (255.0, 255.0,\ 255.0, 1)) btn2.bind(on_release=lambda btn2: dropdown2.select(btn2.text)) dropdown2.add_widget(btn2) self.ids.category.bind(on_release=dropdown2.open) dropdown2.bind(on_select=lambda instance, x: setattr(\ self.ids.category, 'text', x))
def comment_pop(instance): """ Creates a Popup to Log Task into timesheet """ con=lite.connect('TimeTracker.db') with con: cur=con.cursor() cur.execute("SELECT DISTINCT TASK FROM Timesheet ORDER BY TASK ") rows = cur.fetchall() task_list=['OTHER'] for row in rows: task_list.append(row[0]) if con: con.close() f=FloatLayout() global popup1 popup1 = Popup(title='Task Desciption', content=f, size_hint=(1.0, 0.6), size=(400, 400)) g=GridLayout(cols=2,row_force_default=True, row_default_height=40, padding=(1,0,1,0)) g.add_widget(Label(text="SELECT TASK ",pos=(400,800))) global task task=TextInput(size_hint=(1,0.75),write_tab=False,text_size=(2,None)) dropdown = DropDown() for index in range(len(rows)+1): btn = Button(text=task_list[index], size_hint_y=None, height=44) btn.bind(on_release=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) global mainbutton mainbutton = Button(text='TASK', size_hint=(None, None),size=(100, 44), pos_hint={'center_x': .5, 'center_y': .5}) mainbutton.bind(on_release=dropdown.open) dropdown.bind(on_select=MyApp.select_task) g.add_widget(mainbutton) g.add_widget(Label(text="ADD TASK",pos=(400,600))) g.add_widget(task) g.add_widget(Label(text="COMMENTS",pos=(400,400))) global comment comment=TextInput(size_hint=(1,0.75),write_tab=False) g.add_widget(comment) global msg msg=Label(text="Please enter the task and comment to save the task \n", pos=(popup1.width-350,popup1.height-200)) comment.bind(on_text= msg.setter("Please enter the task and comment to save the task \n")) btn1=Button(text='SAVE',size_hint=(0.2,0.1),pos=(popup1.width-350, popup1.height-250)) btn1.bind(on_press=MyApp.update_timesheet) btn2=Button(text='CANCEL',size_hint=(0.2,0.1), pos=(popup1.width-50,popup1.height-250)) f.add_widget(msg) f.add_widget(btn1) f.add_widget(btn2) f.add_widget(g) popup1.open() btn2.bind(on_press=popup1.dismiss)
class LeaderBoardLayout(Widget): def __init__(self, **kwargs): """ Creates the buttons, text inputs and labels to be used by the other functions :param kwargs: :return: """ super(LeaderBoardLayout, self).__init__(**kwargs) self.choice_button = Button(text="Get results") self.results_label = Label(text="High scores", font_size="20sp") self.name_input = TextInput(text="Enter username here.", multiline=False) self.options_dropdown = DropDown() self.dropdown_button = Button(text="Select an option") self.dropdown_button.bind(on_release=self.options_dropdown.open) self.layout = GridLayout(rows=5) self.drop_down_options = ["Top 10 Scores", "Add New User", "Top scores for user"] self.selected_url = "None" def create_layout(self): """Adds the objects created in __init__ to a GridLayout and creates a drop down :return: """ self.choice_button.bind(on_press=self.callback) for d in self.drop_down_options: btn = Button(text=d, size_hint_y=None, height=44) btn.bind(on_release=lambda btn: self.options_dropdown.select(btn.text)) self.options_dropdown.add_widget(btn) self.options_dropdown.bind(on_select=lambda instance, x: setattr(self.dropdown_button, "text", x)) self.layout.add_widget(self.dropdown_button) self.layout.add_widget(self.name_input) self.layout.add_widget(self.choice_button) self.layout.add_widget(self.results_label) return self.layout def server_results(self, request, results): """ Outputs the request result into a label """ self.results_label.text = str(results) def callback(self, event): """Depending on which drop down option was selected a request a URL is chosen to request data from teh server. """ playername = self.name_input.text[:3] self.name_input.text = playername self.results_label.text = "Getting scores" if self.dropdown_button.text == "Top 10 Scores": self.selected_url = "http://bsccg04.ga.fal.io/top10.py" elif self.dropdown_button.text == "Add New User": self.selected_url = "http://bsccg04.ga.fal.io/new_user.py?playername=" + playername elif self.dropdown_button.text == "Top scores for user": self.selected_url = "http://bsccg04.ga.fal.io/users_high_score.py?playername=" + playername request = UrlRequest(self.selected_url, self.server_results)
def __init__(self, **kwargs): super(ApplicationDisplay, self).__init__(**kwargs) self.text= Label (text = str (UID_result)) self.add_widget(self.text) dropdown = DropDown() ApplicationList = ["Gmail","Vault"] for index in ApplicationList: # when adding widgets, we need to specify the height manually (disabling # the size_hint_y) so the dropdown can calculate the area it needs. btn = Button(text=str(index), size_hint_y=None, height=44) # for each button, attach a callback that will call the select() method # on the dropdown. We'll pass the text of the button as the data of the # selection. btn.bind(on_release=lambda btn: dropdown.select(btn.text)) # then add the button inside the dropdown dropdown.add_widget(btn) # create a big main button mainbutton = Button(text='Application Menu', size_hint=(1, None)) # show the dropdown menu when the main button is released # note: all the bind() calls pass the instance of the caller (here, the # mainbutton instance) as the first argument of the callback (here, # dropdown.open.). mainbutton.bind(on_release=dropdown.open) # one last thing, listen for the selection in the dropdown list and # assign the data to the button text. dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x)) self.add_widget(mainbutton)
def changeSecurity(self): security = [1, 2, 3, 4, 5] #Create Dropdown dropdown = DropDown() #Fill DropDown for row in range(len(security)): btn = Button(text= str(security[row]), size_hint_y = None, height=44) btn.bind(on_release=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) mainbutton = self.ids.security mainbutton.bind(on_release=dropdown.open) dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x))
def __init__(self, *args, **kwargs): super(topBar, self).__init__(*args, **kwargs) dropdown = DropDown() self.dropdown = dropdown os.chdir("./SavedTMs/") turingMachines = [] for file in glob.glob("*.xml"): turingMachines.append(str(file)) #Check that there is a file to load, if not display "No saved Files" if len(turingMachines) == 0: # the size_hint_y) so the dropdown can calculate the area it needs. btn = Button(text="No Saved Files", size_hint_y=None, height=30) # then add the button inside the dropdown dropdown.add_widget(btn) for tms in turingMachines: # when adding widgets, we need to specify the height manually (disabling # the size_hint_y) so the dropdown can calculate the area it needs. btn = Button(text='%s' % tms, size_hint_y=None, height=30) # for each button, attach a callback that will call the select() method # on the dropdown. We'll pass the text of the button as the data of the # selection. btn.bind(on_release=lambda btn: dropdown.select(btn.text)) # then add the button inside the dropdown dropdown.add_widget(btn) # create a big main button mainbutton = Button(text='Load Turing Machine', size_hint=(1, 1)) print 'load Turing Machine has been selected' self.mainbutton = mainbutton # show the dropdown menu when the main button is released # note: all the bind() calls pass the instance of the caller (here, the # mainbutton instance) as the first argument of the callback (here, # dropdown.open.). mainbutton.bind(on_release=dropdown.open) #dd_btn.bind(on_release=dropdown.open) # one last thing, listen for the selection in the dropdown list and # assign the data to the button text. #dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x)) # USE THE BELOW CODE TO CALL METHODS FROM THIS CLASS dropdown.bind(on_select=lambda instance, x: self.printMeth(getattr(x,'text',x))) self.top_layout.add_widget(mainbutton)
def fillSubcategory(self): #Create Dropdown dropdown = DropDown() #Fill Dropdown for index in range(4): btn = Button(text='Value %d' % index, size_hint_y = None, height=44) btn.bind(on_release=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) #Bind new text to original button mainbutton = self.ids.subcatDrop mainbutton.bind(on_release=dropdown.open) dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x)) bsdb.close()
def display_verbs(self): dropdown = DropDown() verbs = get_all_verbs(False) for verb in verbs: new_option = ComOption(verb) new_option.bind(on_release=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(new_option) mainbutton = self.ids.verb mainbutton.text = 'Did' mainbutton.bind(on_release=dropdown.open) dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x))
def mileStonePopup_inner(_,__=None): popupLayout = BoxLayout(orientation='horizontal') popup = Popup(title=localisation.get(language,"newdate"), content=popupLayout, size_hint=(None, None), size=(400, 200)) yearSelector = Button(text_size=(400, 100), valign = 'middle', halign='center') popupLayout.add_widget(yearSelector) monthSelector = Button(text_size=(400, 100), valign = 'middle', halign='center') popupLayout.add_widget(monthSelector) daySelector = Button(text_size=(400, 100), valign = 'middle', halign='center') popupLayout.add_widget(daySelector) yearDropdown = DropDown() yearSelector.bind(on_release=yearDropdown.open) yearDropdown.bind(on_select=lambda instance, x: setattr(yearSelector, 'text', x)) firstYear = getFirstYear(tid) for year in range(firstYear,firstYear+101): if yearSelector.text == '': yearSelector.text = str(year) btn = Button(text=str(year),background_color = (0.6,0.6,0.6,1), text_size=(400, 100), valign = 'middle', halign='center', size_hint_y=None, width = 400, height=100) btn.bind(on_release=lambda btn: yearDropdown.select(btn.text)) yearDropdown.add_widget(btn) monthDropdown = DropDown() monthSelector.bind(on_release=monthDropdown.open) monthDropdown.bind(on_select=lambda instance, x: setattr(monthSelector, 'text', x)) for month in range(1,12+1): if monthSelector.text == '': monthSelector.text = str(month) btn = Button(text=str(month),background_color = (0.6,0.6,0.6,1), text_size=(400, 100), valign = 'middle', halign='center', size_hint_y=None, width = 400, height=100) btn.bind(on_release=lambda btn: monthDropdown.select(btn.text)) monthDropdown.add_widget(btn) dayDropdown= DropDown() daySelector.bind(on_release=dayDropdown.open) dayDropdown.bind(on_select=lambda instance, x: setattr(daySelector, 'text', x)) for day in range(1,31+1): if daySelector.text == '': daySelector.text = str(day) btn = Button(text=str(day),background_color = (0.6,0.6,0.6,1), text_size=(400, 100), valign = 'middle', halign='center', size_hint_y=None, width = 400, height=100) btn.bind(on_release=lambda btn: dayDropdown.select(btn.text)) dayDropdown.add_widget(btn) popup.bind(on_dismiss=self.addMilestone(tid, yearSelector, monthSelector, daySelector)) popup.open()
def createMenu(self): d = DropDown() for user in users: btn = Button(text=str(user), size_hint_y=None, height=35) btn.bind(on_press=lambda btn: d.select(btn.text)) d.add_widget(btn) self.mainbutton = Button(text="Select User", size_hint=[.4, .05], pos_hint={'x': .3, 'y': .5}) self.mainbutton.bind(on_release=d.open) d.bind(on_select=lambda d, x: setattr(self.mainbutton, 'text', x)) self.add_widget(self.mainbutton)
def on_cinfdata(self, instance, value): """Setup the setup selection page, when the cinfdata ObjectProperty is set (happens only on startup)""" dropdown = DropDown() for setup in self.cinfdata.get_setups(): btn = SetupButton(text='Setup: ' + setup['title'], size_hint_y=None, height=44, setup=setup) btn.bind(on_release=lambda btn: dropdown.select(btn)) dropdown.add_widget(btn) self.mainbutton.bind(on_release=lambda widget: dropdown.open(widget)) dropdown.bind(on_select=self._select)
def dropdown(): dropdown = DropDown() for index in range(10): btn = Button(text= "Value %d" % index, size_hint_y= None, height=44) btn.bind(on_release=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) mainbutton = Button(text='hello', size_hint=(None,None)) mainbutton.bind(on_release=dropdown.open) dropdown.bind(on_select=lambda instance, x: setattr(mainbutton,'text',x)) return dropdown
def fillToteSize(self): bsdb = sqlite3.connect('backstockdb') cursor = bsdb.cursor() sql = "SELECT value FROM miscFields WHERE param = 'toteSize'" #Create Dropdown dropdown = DropDown() #Fill DropDown for row in cursor.execute(sql): btn = Button(text=row[0], size_hint_y = None, height=44) btn.bind(on_release=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) mainbutton = self.ids.toteSize mainbutton.bind(on_release=dropdown.open) dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x))
def on_enter(self, *args): super(PanelScreen,self).on_enter(*args) self.entered=True self.selectedCat=None js=JsonStore("titles.json") titles=js.get("titles") drop=DropDown() for t in titles["all"]: btn=MiButton(text=titles["all"][t],size_hint_y=None,height=50,key=t) btn.bind(on_release=lambda btn:drop.select(btn)) drop.add_widget(btn) def set_select(inst,btn): self.drp.text=btn.text self.selectedCat=btn.key drop.bind(on_select=set_select) self.drp.bind(on_release=drop.open)
class ProcesoPopup(Popup): def __init__(self, sistema): Popup.__init__(self) self.sistema = sistema self.lista_recursos = DropDown() self.btn_lista.bind(on_release=self.lista_recursos.open) self.lista_recursos.bind(on_select=self.usar_recurso) def agregar_recurso(self, recurso): btn = Button(text=recurso, size_hint_y=None, height=44) btn.bind(on_release=lambda btn: self.lista_recursos.select(btn.text)) self.lista_recursos.add_widget(btn) def usar_recurso(self, btn, recurso): self.txt_recursos.text = self.txt_recursos.text + recurso + ", " def info_nuevo(self): return {} def limpiar(self): self.txt_nombre.text = "" self.txt_tiempo.text = "" self.txt_recursos.text = "" self.txt_procesador.text= "" self.dismiss() def agregar(self): nombre = self.txt_nombre.text tiempo = int(self.txt_tiempo.text) recursos = self.txt_recursos.text.replace(" ", "").split(",") if '' in recursos: recursos.remove('') n_procesador = int(self.txt_procesador.text) self.sistema.agregar_proceso(nombre, tiempo, recursos, n_procesador, **self.info_nuevo()) self.limpiar()
class Root(FloatLayout): slides = ListProperty([]) sm = ObjectProperty(None) controls = ObjectProperty(None) dropdown = ObjectProperty(None) dd_open = BooleanProperty(False) def __init__(self, **kwargs): super(Root, self).__init__(**kwargs) self.sm.transition = BlurTransition() for slide, name in self.slides: self.sm.add_widget(slide, name) self.dropdown = DropDown() for name in self.sm.slide_names: btn = Button(text=name, size_hint_y=None, height="40dp") btn.bind(on_release=lambda btn: self.dropdown.select(btn.text)) self.dropdown.add_widget(btn) self.sm.add_widget(Factory.EndSlide, "Fine della presentazione") def dd_open_wrapper(*args, **kwargs): self.dd_open = True return self.dropdown.open(*args, **kwargs) def dd_dismiss_wrapper(*args): self.dd_open = False self.controls.ddbutton.bind(on_release=dd_open_wrapper) self.dropdown.bind(on_select=lambda instance, x: setattr(self.controls.ddbutton, 'text', x), on_dismiss=dd_dismiss_wrapper) self.dropdown.bind(on_select=lambda instance, x: self.sm.switch_to_slide(x)) self.controls.ddbutton.text = self.sm.current self.sm.bind(current=self.controls.ddbutton.setter("text")) def fade_out_controls(self, *args): if self.controls.collide_point(*Window.mouse_pos) or self.dd_open: Clock.schedule_once(self.fade_out_controls, 1.5) return anim = Animation(opacity=.2, duration=1) anim.start(self.controls) def fade_in_controls(self, *args): anim = Animation(opacity=.8, duration=.2) anim.start(self.controls)
class DtbObjctDropDown(DtbObjctDPbutton): # Class of a DtbObjctDPbutton triggering a dropdown list on_release. def __init__(self, **kwargs): super(DtbObjctDropDown, self).__init__(**kwargs) self.create_dropdown() def create_dropdown(self): self.dropdownlist = DropDown() for ix in self.linked_dataframe.index: # when adding widgets, we need to specify the height manually # (disabling the size_hint_y) so the dropdown can calculate the # area it needs. btn = DtbObjctDPbutton( linked_dataframe = self.linked_dataframe, objct_id = ix, attr_displayed_list = self.attr_displayed_list, attr_backcolor = self.attr_backcolor, size_hint = (None,None), size = self.size ) # for each button, attach a callback that will call the select() # method on the dropdown. We'll pass the text of the button as # the data of the selection. btn.bind( on_release=lambda btn: self.dropdownlist.select(btn.objct_id) ) # then add the button inside the dropdown self.dropdownlist.add_widget(btn) # one last thing, listen for the selection in the dropdown list and # assign the data to the button text. self.dropdownlist.bind( on_select=lambda instance, x: self.new_objct_id(objct_id = x) ) def on_release(self): self.dropdownlist.open(self)
def __init__(self, listOfChoices, pick_action, **kwargs): result = super(DropDownPicker, self).__init__(**kwargs) self._pick_action = pick_action pickerList = DropDown() for item in listOfChoices: choiceButton = Button(text=item, size_hint_y=None, height=50) choiceButton.bind(on_release=lambda btn: pickerList.select(btn.text)) pickerList.add_widget(choiceButton) self.bind(on_release=pickerList.open) pickerList.bind(on_select=lambda instance, x: self._after_pick(x)) pickerList.size_hint = (None, 0.4) return result
def build(self): bm = GridLayout(cols=2) bm.add_widget(Label(text='choose')) dropdown = DropDown() for index in range(10): btn = Button(text='Value %d' % index, size_hint_y=None, height=20) btn.bind(on_release=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) mainbutton = Button(text='Hello', size_hint=(None, None)) mainbutton.bind(on_release=dropdown.open) dropdown.bind( on_select=lambda instance, x: setattr(mainbutton, 'text', x)) bm.add_widget(mainbutton) return bm