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
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