Пример #1
0
def generate_GUI(menus):
    app_gui = TabbedPanel()
    app_gui.clear_tabs()
    app_gui.orientation = "vertical"
    app_gui.do_default_tab = False
    app_gui.tab_width = 150

    for menu_key, sub_menu in menus.items():
        main_menu = TabbedPanelHeader(text=menu_key)
        scroll_pane = ScrollView()
        scroll_pane.scroll_type = ['bars', 'content']
        scroll_pane.bar_pos_y = 'left'
        scroll_pane.bar_width = 6
        scroll_pane.do_scroll_y = True
        scroll_pane.do_scroll_x = False
        scroll_pane.scroll_y = 1

        menu_grid = GridLayout(cols=1, spacing=2, size_hint_y=None)
        menu_grid.orientation = "vertical"
        menu_grid.padding = 10
        menu_grid.row_default_height = 1
        menu_height = 0

        print(">>>" + menu_key)
        for sub_menu_key, items in sub_menu.items():
            menu_grid.add_widget(
                Label(text="     " + sub_menu_key, size_hint=(None, None), font_size=14, halign="left",
                      valign="middle"))
            print("\t" + sub_menu_key)
            for option in items:

                if "Name" in option:
                    print("\t\t" + option["Name"])
                    btn = Button(text=option["Name"], size_hint=(0.1, None), background_color=(0.2, 1, 1, 0.8))
                    btn.bind(on_press=lambda x: webbrowser.open(option["URL"]))
                else:
                    print("\t\t" + "<EMPTY>")
                    btn = Button(text="<EMPTY>", size_hint=(0.1, None), background_color=(0.2, 1, 1, 0.8))
                    btn.bind(on_press=lambda x: webbrowser.open(option["URL"]))
                btn.width = 250
                btn.height = 50
                menu_grid.add_widget(btn)
                menu_height += 80
            menu_height += 51
        menu_grid.height = menu_height
        scroll_pane.add_widget(menu_grid)
        main_menu.content = scroll_pane
        main_menu.orientation = "vertical"

        # Adding headers to main layout
        app_gui.add_widget(main_menu)
    return app_gui
Пример #2
0
    def build(self):
        base_layout = BaseLayout()

        step_base = ScrollView(size_hint=(1, 1),
                               do_scroll_y=True,
                               do_scroll_x=True)
        step_base.bar_width = 20
        step_base.scroll_type = ['bars']

        paint_widget = MyPaintWidget()
        step_base.add_widget(paint_widget)

        return step_base
Пример #3
0
    def fill_accordion_item(self, store):
        storage_butt = AccordionItem()
        storage_butt.id = str(store.id)
        storage_butt.height = 22
        storage_butt.title = str(store.name)

        scroll = ScrollView()
        scroll.do_scroll_x = False
        scroll.size_hint = (1, 1)
        scroll.bar_color = [.5, .10, .15, .8]
        scroll.bar_inactive_color = [.5, .20, .10, .5]
        scroll.scroll_type = ['bars']  # [‘bars’, ‘content’]

        tree_obj = TreeView()
        tree_obj.size_hint = (1, None)
        tree_obj.hide_root = True

        store.tree_view = WeakProxy(tree_obj)
        scroll.add_widget(tree_obj)
        storage_butt.add_widget(scroll)
        return storage_butt
def fill_menu_with_data():
	# Necesary to flush old data 
	airtable_content.clear_tabs()

	# Layout metadata to specify dimension and style
	airtable_content.orientation = "vertical"
	airtable_content.do_default_tab = False # Necesary to disable Default Tab that TabbedPanel generate automatically
	airtable_content.background_color = (0, 0, 1, .5) #50% translucent
	airtable_content.tab_width = 150

	# Trigger airtable connection and data retrieval
	# tab_headers and tab_menus have all data needed to fill airtable_content
	fetch_airtable_data()

	# Creation of each Tab and their respective items 
	for header in tab_headers:

		tab = TabbedPanelHeader(text=header)

		# Scrollview required to adequatly contain items without window or objec distortion
		# Effectively scroll through the menu effortlessly
		scroll = ScrollView()
		scroll.bar_margin = 10
		scroll.size_hint = (1, 1) # Needed to allow scrollview to fit the window regarless od size
		scroll.scroll_type = ['bars', 'content'] # allow scrolling via the bar or by draging content 
		scroll.bar_pos_y = 'left'
		scroll.bar_width = 20
		scroll.bar_color = (5, 10, 15, 0.8)
		scroll.bar_inactive_color = (5, 20, 15, 0.8)
		scroll.do_scroll_y = True # Needed for vertical scrolling
		scroll.do_scroll_x = False
		scroll.scroll_y = 1 # Scrolling speed
		
		# Adding item specifically fitted for the current tab
		scroll.add_widget(format_airtable_data(header))

		tab.content = scroll # adding scrollview with fitted items as content of the tab
		tab.content.orientation = "vertical"
		
		airtable_content.add_widget(tab) # adding the entirity of a tab page to the TabbedPanel
Пример #5
0
    def setMenu(self, menuNum, *largs):

        self.menu = menuNum
        print("menu is now: " + str(menuNum))

        # Undo the previous menu
        self.clear_widgets()

        if self.menu == 0:

            # Add the start button
            self.startLayout = AnchorLayout(anchor_x='center',
                                            anchor_y='center')
            self.startLayout.size = Window.size
            self.startLayout.center = Window.center
            startButton = Button(text="Start")
            startButton.size_hint = 0.5, 0.2
            startButton.font_size = 35
            buttonEvent = partial(self.setMenu, 1)
            startButton.bind(on_press=buttonEvent)
            self.startLayout.add_widget(startButton)

            # Add the settings button
            self.settingsLayout = AnchorLayout(anchor_x='left',
                                               anchor_y='bottom')
            self.settingsLayout.size = Window.size
            self.settingsLayout.center = Window.center
            settingsButton = Button(text="")
            settingsButton.size_hint = None, None
            settingsButton.size = 50, 50
            settingsButton.font_size = 15
            buttonEvent = partial(self.setMenu, 3)
            settingsButton.bind(on_press=buttonEvent)
            self.settingsLayout.add_widget(settingsButton)

            # Add the layouts to the main widget
            self.add_widget(self.startLayout)
            self.add_widget(self.settingsLayout)

        elif self.menu == 1:

            # Add the back button
            self.backLayout = AnchorLayout(anchor_x='center', anchor_y='top')
            self.backLayout.size_hint = None, None
            self.backLayout.size = Window.size[0], Window.size[1] * 0.95
            self.backLayout.center = Window.center
            btn = Button(text="back",
                         size_hint=(None, None),
                         size=(Window.width / 1.1, Window.height / 10.0),
                         font_size=fs)
            btn.bind(on_press=partial(self.setMenu, 0))
            self.backLayout.add_widget(btn)

            # Set up the centered drinks list
            self.mainLayout = AnchorLayout(anchor_x='center',
                                           anchor_y='bottom')
            self.mainLayout.size_hint = None, None
            self.mainLayout.size = Window.size[0], Window.size[1]
            self.mainLayout.center = Window.center
            layout = GridLayout(cols=1, spacing=30, size_hint_y=None)
            layout.size_hint_x = 0.8
            layout.bind(minimum_height=layout.setter('height'))

            # Add all the different drinks
            for i in range(len(drinksList)):
                if drinksList[i]["canMake"]:
                    btn = Button(text=str(drinksList[i]["name"]))
                    btn.font_size = 25
                    btn.size_hint_y = None
                    btn.height = 60
                    btn.bind(on_press=partial(self.setDrink, drinksList[i]))
                    layout.add_widget(btn)

            # Add some spacing at the end
            lbl = Label(text="", height=60)
            layout.add_widget(lbl)

            # Set up scrolling of the main list
            scrolling = ScrollView(size_hint=(None, None),
                                   size=(Window.width, Window.height))
            scrolling.add_widget(layout)
            scrolling.size_hint = None, None
            scrolling.size = self.mainLayout.size[
                0] * 0.75, self.mainLayout.size[1] * 0.83
            scrolling.center = self.mainLayout.center
            scrolling.bar_width = 30
            scrolling.bar_margin = 0
            scrolling.bar_inactive_color = [.7, .7, .7, .9]
            scrolling.scroll_type = ["bars"]
            layout.center = scrolling.center
            self.mainLayout.add_widget(scrolling)

            # Add the various sections to the root widget
            self.add_widget(self.mainLayout)
            self.add_widget(self.backLayout)

        elif self.menu == 2:

            # Add the back button
            self.backLayout = AnchorLayout(anchor_x='center', anchor_y='top')
            self.backLayout.size_hint = None, None
            self.backLayout.size = Window.size[0], Window.size[1] * 0.95
            self.backLayout.center = Window.center
            btn = Button(text="back",
                         size_hint=(None, None),
                         size=(Window.width / 1.1, Window.height / 10.0),
                         font_size=fs)
            buttonEvent = partial(self.setMenu, 1)
            btn.bind(on_press=buttonEvent)
            self.backLayout.add_widget(btn)

            # Add the make button
            self.makeLayout = AnchorLayout(anchor_x='center',
                                           anchor_y='bottom')
            self.makeLayout.size_hint = None, None
            self.makeLayout.size = Window.size[0], Window.size[1] * 0.95
            self.makeLayout.center = Window.center
            btn = Button(id="btnmake",
                         text="make",
                         size_hint=(None, None),
                         size=(Window.width / 1.1, Window.height / 10.0),
                         font_size=fs)
            buttonEvent = partial(self.makeDrink)
            btn.bind(on_press=buttonEvent)
            self.makeLayout.add_widget(btn)

            # Make the central layout
            self.drinkLayout = AnchorLayout(anchor_x='center',
                                            anchor_y='bottom')
            self.drinkLayout.size_hint = None, None
            self.drinkLayout.size = Window.size[0], Window.size[1]
            self.drinkLayout.center = Window.center

            for ing in self.currentDrink["ingredients"]:
                if ing["name"] not in self.settings["liquidsAvail"]:
                    print("substituting " + ing["name"] + " for " +
                          getLiquid(ing["name"])["subs"])
                    ing["oldName"] = ing["name"]
                    ing["name"] = getLiquid(ing["name"])["subs"]

            # Add the drop down boxes to the info
            self.drinkInfo = GridLayout(cols=4,
                                        spacing=15,
                                        size_hint=(None, None))
            for index, ing in enumerate(self.currentDrink["ingredients"]):
                if "oldName" in ing.keys():
                    spinner = Label(text=ing["oldName"] + "\n(" + ing["name"] +
                                    ")",
                                    size_hint=(None, None),
                                    size=(190, 50),
                                    font_size=fs)
                else:
                    spinner = Label(text=ing["name"],
                                    size_hint=(None, None),
                                    size=(190, 50),
                                    font_size=fs)
                spinner.ind = index

                self.drinkInfo.add_widget(spinner)
                btn = Button(text="-",
                             size_hint=(None, None),
                             height=50,
                             width=50,
                             font_size=fs)
                btn.bind(on_press=partial(self.changeDrink, index, -25))
                self.drinkInfo.add_widget(btn)
                lbl = Label(id="lbl" + str(index),
                            text=str(ing["ml"]) + " ml",
                            size_hint=(None, None),
                            height=50,
                            width=80,
                            font_size=fs)
                self.drinkInfo.add_widget(lbl)
                btn = Button(text="+",
                             size_hint=(None, None),
                             height=50,
                             width=50,
                             font_size=fs)
                btn.bind(on_press=partial(self.changeDrink, index, 25))
                self.drinkInfo.add_widget(btn)

            # Set up the scrolling list of ingredients
            self.scrollingDrinks = ScrollView(size_hint=(None, None),
                                              size=(Window.width,
                                                    Window.height))
            self.scrollingDrinks.size_hint = None, None
            self.scrollingDrinks.size = self.drinkLayout.size[
                0] * 0.85, self.drinkLayout.size[1] * 0.85
            self.scrollingDrinks.center = self.drinkLayout.center
            self.scrollingDrinks.add_widget(self.drinkInfo)
            self.drinkLayout.add_widget(self.scrollingDrinks)

            # Add the various sections to the root widget
            self.add_widget(self.backLayout)
            self.add_widget(self.drinkLayout)
            self.add_widget(self.makeLayout)

            self.checkDrink()

        elif self.menu == 3:

            # Add the back button
            self.backLayout = AnchorLayout(anchor_x='center', anchor_y='top')
            self.backLayout.size_hint = None, None
            self.backLayout.size = Window.size[0], Window.size[1] * 0.95
            self.backLayout.center = Window.center
            btn = Button(text="back",
                         size_hint=(None, None),
                         size=(Window.width / 1.1, Window.height / 10.0),
                         font_size=fs)
            buttonEvent = partial(self.setMenu, 0)
            btn.bind(on_press=buttonEvent)
            self.backLayout.add_widget(btn)

            # Create the keypad
            self.keypadWrapper = AnchorLayout(anchor_x='center',
                                              anchor_y='center')
            self.keypadWrapper.size_hint = None, None
            self.keypadWrapper.size = Window.size[0], Window.size[1]
            self.keypadWrapper.center = Window.center
            self.keypadLayout = GridLayout(cols=3)
            self.keypadLayout.size_hint = None, None
            self.keypadLayout.size = Window.size[0] * 0.5, Window.size[1] * 0.5
            self.keypadLayout.center = Window.center
            for i in range(9):
                btn = Button(size_hint=(None, None),
                             size=(80, 80),
                             font_size=fs)
                buttonEvent = partial(self.enterCode, i + 1)
                btn.bind(on_press=buttonEvent)
                self.keypadLayout.add_widget(btn)
            self.keypadWrapper.add_widget(self.keypadLayout)

            # Add the various sections to the root widget
            self.add_widget(self.backLayout)
            self.add_widget(self.keypadWrapper)

        elif self.menu == 4:

            # Add the back button
            self.backLayout = AnchorLayout(anchor_x='center', anchor_y='top')
            self.backLayout.size_hint = None, None
            self.backLayout.size = Window.size[0], Window.size[1] * 0.95
            self.backLayout.center = Window.center
            btn = Button(text="back",
                         size_hint=(None, None),
                         size=(Window.width / 1.1, Window.height / 10.0),
                         font_size=fs)
            buttonEvent = partial(self.setMenu, 0)
            btn.bind(on_press=buttonEvent)
            self.backLayout.add_widget(btn)

            self.controlLayout = AnchorLayout(anchor_x='center',
                                              anchor_y='bottom')
            self.controlLayout.size_hint = None, None
            self.controlLayout.size = Window.size[0] * 0.9, Window.size[
                1] * 0.80
            self.controlLayout.center = (Window.center[0],
                                         Window.center[1] - 50)

            # Set up the wrapper grid
            self.wrapperGrid = GridLayout(cols=1,
                                          spacing=15,
                                          size_hint=(None, None))
            self.wrapperGrid.size = (self.controlLayout.size[0] * 0.99,
                                     self.controlLayout.size[1] * 0.99)
            self.wrapperGrid.center = self.controlLayout.center

            # Set up the liquid list grid
            self.liquidGrid = GridLayout(cols=2,
                                         spacing=15,
                                         size_hint=(None, None))
            self.liquidGrid.size = (self.wrapperGrid.size[0] * 0.9,
                                    self.wrapperGrid.size[1] * 0.5)
            self.liquidGrid.center = (self.wrapperGrid.center[0],
                                      self.wrapperGrid.center[1])
            for index, liq in enumerate(self.settings["liquidsAvail"]):
                spinner = Spinner(text=liq,
                                  id="sd" + str(index),
                                  values=liquidNameList,
                                  size_hint=(None, None),
                                  size=(200, 60),
                                  font_size=fs,
                                  pos_hint=(None, None))
                spinner.bind(text=self.change_avail_drink)
                self.liquidGrid.add_widget(spinner)

            # Add the settings layout
            self.controlGrid = GridLayout(cols=4,
                                          spacing=15,
                                          size_hint=(None, None))
            self.controlGrid.size = (self.wrapperGrid.size[0] * 0.9,
                                     self.wrapperGrid.size[1] * 0.30)
            self.controlGrid.center = self.wrapperGrid.center

            # Add a value setting
            lbl = Label(text="maxBooze",
                        size_hint=(None, None),
                        height=50,
                        width=180,
                        font_size=fs)
            self.controlGrid.add_widget(lbl)
            btn = Button(text="-",
                         size_hint=(None, None),
                         height=50,
                         width=50,
                         font_size=fs)
            btn.bind(on_press=partial(self.changeSetting, "maxBooze", -25))
            self.controlGrid.add_widget(btn)
            lbl = Label(id="maxBooze",
                        text=str(self.settings["maxBooze"]),
                        size_hint=(None, None),
                        height=50,
                        width=80,
                        font_size=fs)
            self.controlGrid.add_widget(lbl)
            btn = Button(text="+",
                         size_hint=(None, None),
                         height=50,
                         width=50,
                         font_size=fs)
            btn.bind(on_press=partial(self.changeSetting, "maxBooze", 25))
            self.controlGrid.add_widget(btn)

            # Add a value setting
            lbl = Label(text="maxVol",
                        size_hint=(None, None),
                        height=50,
                        width=180,
                        font_size=fs)
            self.controlGrid.add_widget(lbl)
            btn = Button(text="-",
                         size_hint=(None, None),
                         height=50,
                         width=50,
                         font_size=fs)
            btn.bind(on_press=partial(self.changeSetting, "maxVol", -25))
            self.controlGrid.add_widget(btn)
            lbl = Label(id="maxVol",
                        text=str(self.settings["maxVol"]),
                        size_hint=(None, None),
                        height=50,
                        width=80,
                        font_size=fs)
            self.controlGrid.add_widget(lbl)
            btn = Button(text="+",
                         size_hint=(None, None),
                         height=50,
                         width=50,
                         font_size=fs)
            btn.bind(on_press=partial(self.changeSetting, "maxVol", 25))
            self.controlGrid.add_widget(btn)

            # Add a value setting
            lbl = Label(text="maxChange",
                        size_hint=(None, None),
                        height=50,
                        width=180,
                        font_size=fs)
            self.controlGrid.add_widget(lbl)
            btn = Button(text="-",
                         size_hint=(None, None),
                         height=50,
                         width=50,
                         font_size=fs)
            btn.bind(on_press=partial(self.changeSetting, "maxChange", -25))
            self.controlGrid.add_widget(btn)
            lbl = Label(id="maxChange",
                        text=str(self.settings["maxChange"]),
                        size_hint=(None, None),
                        height=50,
                        width=80,
                        font_size=fs)
            self.controlGrid.add_widget(lbl)
            btn = Button(text="+",
                         size_hint=(None, None),
                         height=50,
                         width=50,
                         font_size=fs)
            btn.bind(on_press=partial(self.changeSetting, "maxChange", 25))
            self.controlGrid.add_widget(btn)

            # Add buttons to change active solenoid setting
            lbl = Label(text="selectedDrink",
                        size_hint=(None, None),
                        height=50,
                        width=180,
                        font_size=fs)
            self.controlGrid.add_widget(lbl)
            btn = Button(text="-",
                         size_hint=(None, None),
                         height=50,
                         width=50,
                         font_size=fs)
            btn.bind(
                on_press=partial(self.changeSetting, "selectedSetting", -1))
            self.controlGrid.add_widget(btn)
            lbl = Label(id="selectedSetting",
                        text=str(self.settings["selectedSetting"]),
                        size_hint=(None, None),
                        height=50,
                        width=80,
                        font_size=fs)
            self.controlGrid.add_widget(lbl)
            btn = Button(text="+",
                         size_hint=(None, None),
                         height=50,
                         width=50,
                         font_size=fs)
            btn.bind(
                on_press=partial(self.changeSetting, "selectedSetting", 1))
            self.controlGrid.add_widget(btn)

            # Add a value setting
            lbl = Label(text="milliPer25",
                        size_hint=(None, None),
                        height=50,
                        width=180,
                        font_size=fs)
            self.controlGrid.add_widget(lbl)
            btn = Button(text="-",
                         size_hint=(None, None),
                         height=50,
                         width=50,
                         font_size=fs)
            btn.bind(on_press=partial(self.changeSetting, "milliPer25", -5,
                                      self.settings["selectedSetting"]))
            self.controlGrid.add_widget(btn)
            lbl = Label(id="milliPer25",
                        text=str(self.settings["milliPer25"][
                            self.settings["selectedSetting"] - 1]),
                        size_hint=(None, None),
                        height=50,
                        width=80,
                        font_size=fs)
            self.controlGrid.add_widget(lbl)
            btn = Button(text="+",
                         size_hint=(None, None),
                         height=50,
                         width=50,
                         font_size=fs)
            btn.bind(on_press=partial(self.changeSetting, "milliPer25", 5))
            self.controlGrid.add_widget(btn)

            # Add the various sections to the root widget
            self.add_widget(self.backLayout)
            self.wrapperGrid.add_widget(self.liquidGrid)
            self.wrapperGrid.add_widget(self.controlGrid)
            self.controlLayout.add_widget(self.wrapperGrid)
            self.add_widget(self.controlLayout)