def __init__(self, **kwargs): super(FilePopup, self).__init__(**kwargs) self.title = "Choose file" # create popup layout containing a boxLayout content = BoxLayout(orientation='vertical', spacing=5) self.popup = popup = Popup(title=self.title, content=content, size_hint=(None, None), size=(600, 400)) self.fileChooser = fileChooser = FileChooserListView(size_hint_y=None) drives = win32api.GetLogicalDriveStrings() drives = drives.split('\000')[:-1] def test(drive): # first, create the scrollView fileChooser.path = drive fileChooser.bind(on_submit=self._validate) fileChooser.height = 500 # this is a bit ugly... scrollView.add_widget(fileChooser) # construct the content, widget are used as a spacer content.add_widget(Widget(size_hint_y=None, height=5)) content.add_widget(scrollView) content.add_widget(Widget(size_hint_y=None, height=5)) # 2 buttons are created for accept or cancel the current value btnlayout = BoxLayout(size_hint_y=None, height=50, spacing=5) btn = Button(text='Ok') btn.bind(on_release=self._validate) btnlayout.add_widget(btn) btn = Button(text='Cancel') btn.bind(on_release=popup.dismiss) btnlayout.add_widget(btn) content.add_widget(btnlayout) dropdown.clear_widgets() mainbutton.clear_widgets() mainbutton.disabled mainbutton.text = drive dropdown = DropDown() for index in drives: btn = Button(text=index, size_hint_y=None, height=44) btn.bind(on_release=lambda btn: test(btn.text)) dropdown.add_widget(btn) self.scrollView = scrollView = ScrollView() mainbutton = Button(text='Drive', size_hint_y=None, height=44) mainbutton.bind(on_release=dropdown.open) dropdown.bind( on_select=lambda instance, x: setattr(mainbutton, 'text', x)) content.add_widget(mainbutton) # all done, open the popup ! popup.open()
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 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 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 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 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)
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)
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 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
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 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
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 switch_to_card_browser(self): self.current = 'card_browser' #creating a dropdown for the user to select deck dropdown = DropDown() self.ids.s8.ids.ddbox.clear_widgets() self.mainbutton = Button(text='All Cards', color=[0, 0, 0, 1], background_color=[1, 1, 1, 1], background_normal='') self.ids.s8.ids.ddbox.add_widget(self.mainbutton) self.mainbutton.fast_bind('on_release', dropdown.open) for decks in self.manager.implementation.decks: btn = Button(text=decks.find_attribute("name").attribute_value_, size_hint_y=None, height='48dp', color=[0, 0, 0, 1], background_color=[1, 1, 1, 1], background_normal='') btn.fast_bind('on_release', self.dd_select, btn, dropdown) dropdown.add_widget(btn) dropdown.bind( on_select=lambda instance, x: setattr(self.mainbutton, 'text', x)) #dispalying the cards self.cb_display_cards('basic', self.mainbutton)
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 __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)
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 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 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 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()
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
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 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 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 _filter_layout(self): filter_box = BoxLayout(orientation='vertical', spacing=50) dropdown = DropDown() for filter_type in FILTERS.keys(): filter_button = Button(text=filter_type, font_size=30, background_normal='', background_color=rgb_to_kivy(239, 93, 5, 1), size_hint_y=None, height=130) handle_filter_button_with_dropdown = partial( self.handle_filter_button, dropdown) filter_button.bind(on_release=handle_filter_button_with_dropdown) dropdown.add_widget(filter_button) filter_dropdown_btn = Button(text=ALL_FILTER, font_size=30, size_hint=(1, 1), background_normal='', background_color=rgb_to_kivy( 239, 93, 5, 1)) filter_dropdown_btn.bind(on_release=dropdown.open) dropdown.bind(on_select=lambda instance, x: setattr( filter_dropdown_btn, 'text', x)) filter_box.add_widget(filter_dropdown_btn) return filter_box
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)
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)
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 genDropdown(self): """ Fuction to be used to add possible gauge values from file. """ Values = [ 'Calculated Engine Load', 'Fuel Pressure', 'Engine RPM', 'Vehicle Speed', 'MAF air flow rate', 'Throttle position', ] codetype = DropDown() for x in Values: cur = Button(text=x, height=40, width=250) codetype.add_widget(cur) mainbutton = Button(text='Add New Gauge', height=40, width=250, pos=(20, 20)) mainbutton.bind(on_release=codetype.open) codetype.bind( on_select=lambda instance, x: setattr(mainbutton, 'text', x)) return 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)
class OSD_DropIcon(OSD_Icon): icons = ListProperty(None) selected = StringProperty(None) def __init__(self, **kwargs): super(OSD_DropIcon, self).__init__(**kwargs) self.dropdown = DropDown(auto_width=False, size_hint_x=0.3) self.dropdown.bind(on_select=self.setter("selected")) def on_selected(self, *args): print(args) def open_dropdown(self): self.dropdown.open(self) def on_icons(self, wid, icons): dropdown = self.dropdown dropdown.clear_widgets() for i, icon in enumerate(icons): btn = Button(text=icon, size_hint_y=None, height=dp(44)) btn.index = i btn.bind(on_release=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) def on_touch_down(self, touch): if self.collide_point(*touch.pos): # self.state = not self.state self.open_dropdown() return True
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)
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 build(self): dropdown = DropDown() for map in self.maps['Alarak']: btn = Button(text=map, size_hint_y=None, height=44) btn.bind(on_release=lambda btn: dropdown.select(btn.text)) dropdown.add_widget(btn) mainbutton = Button(text='Map', size_hint=(None, None)) mainbutton.bind(on_release=dropdown.open) dropdown.bind( on_select=lambda instance, x: setattr(mainbutton, 'text', x)) mainbutton.pos = (self.w / 4, self.h - 50) mainbutton.size_hint = (.5, .06) layout = FloatLayout(size=(self.w, self.h)) layout.add_widget(mainbutton) MapImg.pos = (self.w / 4 - 110, self.h - 90) mainbutton.add_widget(MapImg) for i in range(0, 10): self.hero_buttons.append( Spinner( # default value shown text='Player ' + str(i), # available values values=sorted(self.neutral), # just for positioning in our example size_hint=(None, None), size=(90, 50), pos=(5 + (self.w - 100) * int(i / 5), self.h / 5 * (i % 5)))) self.hero_buttons[i].bind(text=self.show_selected_value) layout.add_widget(self.hero_buttons[i]) # spinner.bind(text=show_selected_value) # layout.add_widget(spinner) self.stack = StackLayout(size_hint=(0.7, 0.8), pos=(120, 0)) dict_list = sorted(self.neutral, key=self.neutral.get, reverse=True) for hero in dict_list: self.stack.add_widget( Button(text=hero + "\n" + str(self.neutral[hero]), size_hint=(0.142, 0.1), halign='center')) layout.add_widget(self.stack) manager = ScreenManager() screen = HotsAnalyse(name='HotsAnalyse') screen.add_widget(layout) manager.add_widget(screen) return manager
def __init__(self, **kwargs): ''' Initializes the primary application layout, the parent to all the other layouts. Holds the prime row for user's to fill in ''' super(RootWidget, self).__init__(**kwargs) self.error_pop_set = Popup(title="PRIME ROW ERROR", content=Label(text='''RULES FOR A PRIME ROW: \n -Must contain all numbers zero through eleven \n -Must contain each only once''', font_size=self.height / 6), size_hint=(None, None), size=(600, 400)) my_mat = self.ids.matrix prime_row = self.ids.prime_row my_tools = self.ids.matrix_tools.children my_tools_h2 = my_tools[2].children my_tools_h1 = my_tools[1].children tool_bar = self.ids.tools.children #Binding functions to settings drop down menu file_dropdown = DropDown() btn_names = ['Save', 'Save & Print', 'Properties'] for indx in range(3): btn = Button(text=f'{btn_names[indx]}', size_hint=(None, None), width=self.width, height=40) btn.bind(on_press=lambda btn: file_dropdown.select(btn.text)) file_dropdown.add_widget(btn) tool_bar[0].bind(on_release=file_dropdown.open) file_dropdown.bind( on_select=lambda instance, x: self._dropdown_funcs(x, my_mat)) #Binds functions directly effecting the matrix to their buttons my_tools[4].bind( on_press=lambda *args: self.build_matrix(prime_row, my_mat)) my_tools[3].bind( on_press=lambda *args: self.clear_matrix(prime_row, my_mat)) my_tools_h2[1].bind(on_press=lambda *args: self.flip_matrix( my_mat, MatrixWidget.FLAT_ALPHA_REP)) my_tools_h2[0].bind(on_press=lambda *args: self.flip_matrix( my_mat, MatrixWidget.SHARP_ALPHA_REP)) my_tools_h1[1].bind(on_press=lambda *args: self.flip_matrix( my_mat, MatrixWidget.EXPAND)) my_tools_h1[0].bind(on_press=lambda *args: self.flip_matrix( my_mat, MatrixWidget.ALPHANUM_REP)) my_tools[0].bind(on_press=lambda *args: self.flip_matrix( my_mat, MatrixWidget.DEFAULT)) #Binds text inputs to labels for col in range(12): txt_in = prime_row.children[11 - col] lbl = my_mat.children[my_mat.translate_coords(0, col)] txt_in.bind(text=lbl.setter('text'))
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 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 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 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 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 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 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 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 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 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()
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
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, *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))
class PlayerPerformanceScreen(Screen): top_graph = ObjectProperty(None) item_texture = ObjectProperty(None) item_drop_btn = ObjectProperty(None) _item_dropdown = None def _item_selected(self, local_item_name): # convert local to key name try: item = [k for k,v in dotalocal.item.iteritems() if v == local_item_name][0] except IndexError: log.error('_item_selected: Invalid item name {}'.format(local_item_name)) return self.item_drop_btn.text = local_item_name self.item_texture = pas_agg.create_item_graph(squeeze.my_id, item) def _init_item_dropdown(self): self._item_dropdown = DropDown() for item_name in sorted(dotalocal.item.itervalues()): btn = Button(text=item_name, size_hint_y=None, height=32) btn.bind(on_release=lambda btn: self._item_dropdown.select(btn.text)) self._item_dropdown.add_widget(btn) self.item_drop_btn.bind(on_release=self._item_dropdown.open) self._item_dropdown.bind(on_select=lambda inst, x: self._item_selected(x)) def load_replays(self, replay_list): if not self._item_dropdown: self._init_item_dropdown() pas_agg.d2rp_list = [] for replay_id in replay_list: # skip replays the player did not play in player = squeeze.player_from_replay(squeeze.my_id, replay_id) if player is None: continue squeeze.dump_demo(replay_id) match = squeeze.replay(replay_id) d2rp = D2RP(squeeze.fs_replay_path(replay_id)) pas_agg.d2rp_list.append(d2rp) self.top_graph.texture = pas_agg.create_cs_graph(squeeze.my_id)
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
def Initialize(self, path): self.sample, self.contents, self.line_nos = ParseData(path) platforms = DropDown() for platform in sorted(self.contents.itervalues().next().keys()): btn = Button(text = platform, size_hint_y = None, height = 33) btn.bind(on_release = lambda btn: self.SetPlatform(btn.text, platforms)) platforms.add_widget(btn) self.plat_list.append(platform) self.plat_btn.bind(on_release = platforms.open) platforms.bind(on_select = lambda instance, x: setattr(self.plat_btn, 'text', x)) test_filter = DropDown() for filter_type in ["None", "Matching", "MatchingPlat", "Matching+NoRes", "MatchingPlat+NoRes"]: btn = Button(text = filter_type, size_hint_y = None, height = 33) btn.bind(on_release = lambda btn: self.SetFilter(btn.text, test_filter)) test_filter.add_widget(btn) self.filter_btn.bind(on_release = test_filter.open) test_filter.bind(on_select = lambda instance, x: setattr(self.filter_btn, 'text', x))