Beispiel #1
0
class DropDownSelection(DropDown):
	def __init___(self, **kwargs):
		super(DropDownSelection, self).__init__(**kwargs)
		self.mainButton = ObjectProperty(None)
	
	def select(self, button):
		self.mainButton.text = button.text
		self.dismiss()

	def main(self, button):
		self.mainButton = button
		self.mainButton.bind(on_release = self.open)
Beispiel #2
0
    def showFoodInList(self, *args):

        if os.path.isfile('foodDatabase.txt') == False:
            #define Gridlayout for buttons
            buttonWithoutDatabaseGrid = GridLayout(cols=1,
                                                   row_force_default=True,
                                                   row_default_height=200,
                                                   spacing=15)

            backButton = Button(text='go back',
                                size_hint_y=None,
                                font_size=35,
                                background_normal='',
                                background_color=(0, 1, 1, 0.5),
                                on_release=self.changer)

            buttonWithoutDatabaseGrid.add_widget(backButton)
            self.add_widget(buttonWithoutDatabaseGrid)

        #if foodDatabase.txt exists read it and make it into dictionary
        elif os.path.isfile('foodDatabase.txt') or \
        len(eval(open('foodDatabase.txt', 'r').read())) >1:

            data = eval(open('foodDatabase.txt',
                             'r').read())  #evaluate data into dictionary
            nameList = list(data.keys(
            ))  #extract keys of nested dict to list -> names of foods

            buttonGrid = GridLayout(cols=1,
                                    id='btnGrid',
                                    size_hint_y=None,
                                    row_force_default=True,
                                    row_default_height=200,
                                    rows_minimum={
                                        0: 100,
                                        1: 100
                                    },
                                    spacing=15)

            # when we add children to the grid layout, its size doesn't change at
            # all. we need to ensure that the height will be the minimum required
            # to contain all the childs. (otherwise, we'll child outside the
            # bounding box of the childs)
            buttonGrid.bind(minimum_height=buttonGrid.setter('height'))

            backButton = Button(text='go back',
                                size_hint_y=None,
                                font_size=35,
                                background_normal='',
                                background_color=(0, 1, 1, 0.8),
                                on_release=self.changer)

            removeTextInput = TextInput(text='',
                                        font_size=45,
                                        multiline=False,
                                        on_text_validate=self.rmFoodInstant)

            buttonGrid.add_widget(backButton)
            buttonGrid.add_widget(removeTextInput)

            # add buttons into above defined grid
            for foodName in nameList:
                #buttons loop to create as many buttons as food dictionary/foodDatabase.txt has foods
                #in it
                btn = ObjectProperty(None)

                btn = Button(
                    text=str(foodName),  #text of buttons is name of food
                    size=self.size,
                    font_size=45,
                    valign='center',
                    on_release=self.buttonPressIdentification)
                # on button release buttonPressIdentification function is called
                # which returnes the button instances text (buttontext)
                buttonGrid.add_widget(btn)  #add buttons to the gridlayout
                btn.bind(on_release=(self.changer))
                #bind button to an on_release event -> here screenchanger
                btn.bind(on_release=(self.on_enter))
                #bind buttons to the on_enter event which will input the saved food properties
                #into the main input window

            # create a scroll view, with a size < size of the grid
            scrollingPanel = ScrollView(do_scroll_x=False)
            #defining scrolling screen
            scrollingPanel.add_widget(buttonGrid)
            #add child to the ScreenView -> GridLayout
            self.add_widget(scrollingPanel)
            #add widget back to ScrollView? dont no exactly
        else:
            pass