当前位置: 首页>>代码示例>>Python>>正文


Python DropDown.bind方法代码示例

本文整理汇总了Python中kivy.uix.dropdown.DropDown.bind方法的典型用法代码示例。如果您正苦于以下问题:Python DropDown.bind方法的具体用法?Python DropDown.bind怎么用?Python DropDown.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kivy.uix.dropdown.DropDown的用法示例。


在下文中一共展示了DropDown.bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build

# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import bind [as 别名]
 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
开发者ID:stuffandahalf,项目名称:Quick-Keys,代码行数:37,代码来源:Quick-Keys_Kivy_App.py

示例2: addButtons

# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import bind [as 别名]
 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)
开发者ID:ninehundred1,项目名称:TouchBehaviorApp,代码行数:36,代码来源:TouchTraining.py

示例3: ouvrirMenuAttaque

# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import bind [as 别名]
	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()
开发者ID:SuperToad,项目名称:SmartphoneGame,代码行数:35,代码来源:inCastle.py

示例4: SettingsScreen

# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import bind [as 别名]
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()
开发者ID:Smug28,项目名称:Mobile-TetriNET,代码行数:35,代码来源:screens.py

示例5: __init__

# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import bind [as 别名]
 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)
开发者ID:JosephLee19,项目名称:InteractiveProgramming-1,代码行数:31,代码来源:GUI.py

示例6: showModes

# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import bind [as 别名]
    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)
开发者ID:ATT-JBO,项目名称:CLC-configurator,代码行数:27,代码来源:inputItem.py

示例7: showOutputs

# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import bind [as 别名]
    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)
开发者ID:ATT-JBO,项目名称:CLC-configurator,代码行数:29,代码来源:inputItem.py

示例8: addDetails

# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import bind [as 别名]
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
开发者ID:arkobasu0713,项目名称:CompleteFramework,代码行数:29,代码来源:dynamicUtilsUI.py

示例9: __init__

# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import bind [as 别名]
  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)
开发者ID:victor-rene,项目名称:MicroScada,代码行数:35,代码来源:databindingeditor.py

示例10: make_dropdown

# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import bind [as 别名]
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
开发者ID:sbrother,项目名称:wassum-lab-lick-program,代码行数:10,代码来源:main.py

示例11: comment_pop

# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import bind [as 别名]
	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)
开发者ID:rev20,项目名称:Time-Tracker,代码行数:58,代码来源:main.py

示例12: LeaderBoardLayout

# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import bind [as 别名]
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)
开发者ID:MaddieK19,项目名称:comp-130-mobile-game-app,代码行数:57,代码来源:Leaderboard.py

示例13: __init__

# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import bind [as 别名]
    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)
开发者ID:GuruShiva,项目名称:UIDgen,代码行数:56,代码来源:main.py

示例14: changeSecurity

# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import bind [as 别名]
 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))
开发者ID:fitzerc,项目名称:backstockmanager,代码行数:14,代码来源:main.py

示例15: __init__

# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import bind [as 别名]
    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)
开发者ID:Kazooy,项目名称:Advanc3d-Pr0graming,代码行数:54,代码来源:DropDown.py


注:本文中的kivy.uix.dropdown.DropDown.bind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。