Example #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
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
Example #3
0
    def ui_layout(self, contact):
        self.contact = contact
        self.clear_widgets()

        layout = BoxLayout(orientation='vertical')
        scroll = ScrollView(do_scroll_x=False,
                            size_hint=(1, None),
                            size=(Window.width, Window.height))
        scroll_box = BoxLayout(orientation='vertical',
                               size_hint_y=None,
                               padding=(dp(12), dp(60)),
                               spacing=dp(5))
        scroll_box.bind(minimum_height=scroll_box.setter('height'))
        # Add more self.scrollbox.add_widget(MDLabel(text='')) to increase padding
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' ', size_hint=(1, 5)))

        if contact != '' and contact in self.util.user_data[
                'message_dict'].keys():
            for message in self.util.user_data['message_dict'][contact]:
                if self.util.username != message['sender']:
                    pos_hint = {'center_x': 0.3}
                    md_bg_color = [0.698, 0.875, 0.859, 1]
                    text_color = [0, 0, 0, 1]
                else:
                    pos_hint = {'center_x': 0.7}
                    md_bg_color = [1, 1, 1, 0.6]
                    text_color = [0, 0, 0, 1]
                message_label = MDLabel(text=message['message'],
                                        font_style='Caption',
                                        size_hint=(1, None))
                if '_' not in message_label.text:
                    self.util.morse.read(words=str(message_label.text))
                    message_label.text = self.util.morse.morse
                message_card = ConversationBubble(util=self.util,
                                                  size=message_label.size,
                                                  message=message_label,
                                                  pos_hint=pos_hint,
                                                  md_bg_color=md_bg_color,
                                                  text_color=text_color)
                scroll_box.add_widget(message_card)

        # This is disgusting but its late and I'm running out of time
        # keeps the text off of the text input
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' '))
        scroll_box.add_widget(MDLabel(text=' '))

        scroll.add_widget(scroll_box)
        layout.add_widget(scroll)

        self.text_input = MDTextFieldRound()
        # Hides left icon
        self.text_input.icon_left_dasabled = True
        # Moves widget out of the field of view
        self.text_input.children[2].children[2].pos_hint = {
            'center_x': 500,
            'center_y': 500
        }

        self.text_input.icon_right = 'send'
        self.text_input.children[2].children[0].bind(
            on_press=lambda x: self.send_message(self.text_input.text))

        self.long_press_btn = LongpressButton(text_input_cb=self.text_input_cb,
                                              size=(dp(50), dp(1)),
                                              size_hint=(3, None))

        input_box_horz = BoxLayout(orientation='horizontal')
        input_box_horz.add_widget(MDLabel(text='', size_hint=(0.05, None)))
        input_box_horz.add_widget(self.long_press_btn)
        input_box_horz.add_widget(MDLabel(text='', size_hint=(0.05, None)))

        text_input_anchor = AnchorLayout(anchor_x='center',
                                         anchor_y='bottom',
                                         padding=dp(65))
        text_input_anchor.add_widget(self.text_input)

        tap_input_anchor = AnchorLayout(anchor_x='center',
                                        anchor_y='bottom',
                                        size_hint=(1, 0.1),
                                        padding=dp(15))
        tap_input_anchor.add_widget(input_box_horz)

        toolbar_anchor = AnchorLayout(anchor_x='center', anchor_y='top')
        toolbar = MDToolbar(title=contact, anchor_title='center')
        toolbar.md_bg_color = App.get_running_app().theme_cls.primary_color
        toolbar.left_action_items = [[
            'arrow-left', lambda x: self.return_screen()
        ]]
        toolbar_anchor.add_widget(toolbar)

        self.add_widget(layout)
        self.add_widget(text_input_anchor)
        self.add_widget(tap_input_anchor)
        self.add_widget(toolbar_anchor)
        self.do_layout()
        scroll.scroll_y = 0
    def __init__(self, *args, **kwargs):
        global s_y, n, yh, yg, sa, btnlist, lbllist
        btnlist = []
        lbllist = []
        super().__init__(*args)
        sel = ScrollView()
        self.add_widget(sel)

        dat = os.listdir('.')
        data = []
        for item in range(len(dat)):
            if dat[item].endswith(".pdf"):
                data.append(dat[item])

        n = len(data)
        sa = FloatLayout()
        s_y = 1.02
        if n < 11:
            pass
        else:
            s_y = s_y + (n - 10) / 11

        sa.size_hint = (1, s_y)

        with self.canvas:
            Color(0, 0.5, 1, 1)
            Rectangle(pos=(0, 0.95 * h), size=(w, h * 0.05))
        self.bt2 = Button(size_hint=(0.1, 0.05),
                          pos_hint={
                              'x': 0.9,
                              'y': 0.95
                          },
                          background_normal="Icon/add.png")
        self.add_widget(self.bt2)
        self.bt2.bind(on_press=self.change)

        sel.do_scroll_x: False
        sel.do_scroll_y: True
        sel.scroll_y = 1
        sel.bar_width = 5
        sel.size = Window.size
        sel.add_widget(sa)

        yh = 0.2
        for i in range(n):
            if i % 2 == 0:
                z = 0
            else:
                z = 0.5

            lb = Label(color=(0, 0, 0, 1),
                       text=data[i],
                       size_hint=(0.5, 0.05 / s_y),
                       pos_hint={
                           'x': z,
                           'y': (s_y - yh) / s_y
                       })
            sa.add_widget(lb)
            if i % 2 != 0:
                yh = yh + 0.17

            lbllist.append(lb)

        yg = 0.16
        for i in range(n):
            if i % 2 == 0:
                z = 0.15
            else:
                z = 0.65

            btn = Button(background_normal="Icon/pdf.png",
                         size_hint=(0.2, 0.1 / s_y),
                         pos_hint={
                             'x': z,
                             'y': (s_y - yg) / s_y
                         })
            sa.add_widget(btn)
            if i % 2 != 0:
                yg = yg + 0.17

            btnlist.append(btn)