Exemple #1
0
    def ui_layout(self):
        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)))

        for contact in self.util.contact_list:
            contact_card = ContactCard(util=self.util,
                                       contact=contact
                                       )
            scroll_box.add_widget(contact_card)

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

        # Add floating action button to write messages
        add_contact_anchor = AnchorLayout(anchor_x='right', anchor_y='bottom',
                                          padding=[dp(25), dp(25), dp(25), dp(25)])
        add_contact_btn = MDFloatingActionButton(icon='account-plus', size=[dp(56), dp(56)])
        add_contact_btn.md_bg_color = App.get_running_app().theme_cls.primary_color
        add_contact_btn.theme_text_color = "Custom"
        add_contact_btn.text_color = [1, 1, 1, 1]
        add_contact_btn.bind(on_press=lambda x: self.change_screen('add_contact'))
        add_contact_anchor.add_widget(add_contact_btn)

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

        self.add_widget(layout)
        self.add_widget(add_contact_anchor)
        self.add_widget(toolbar_anchor)

        self.do_layout()
    def ui_layout(self):
        self.clear_widgets()
        layout = BoxLayout(orientation='vertical')

        self.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(1), dp(60)),
                               spacing=dp(1))
        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=' '))

        for key in self.util.user_data['message_dict']:
            morse_code = ''
            temp_dict = self.util.user_data['message_dict'][key][-1:][0]
            if '_.' not in temp_dict['message']:
                morse_code = self.util.morse_helper.text_to_morse(
                    str(temp_dict['message']))
            else:
                morse_code = str(temp_dict['message'])

            message_card = MessageCard(
                text_post=morse_code,
                name=key,
                name_data=(key + '\n' + temp_dict['timestamp']),
                swipe=True,
                source='ui/img/default_avatar.png',
            )
            scroll_box.add_widget(message_card)

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

        self.add_widget(layout)

        # Add floating action button to write messages
        create_message_anchor = AnchorLayout(
            anchor_x='right',
            anchor_y='bottom',
            padding=[dp(25), dp(25), dp(25), dp(25)])
        create_message_btn = MDFloatingActionButton(icon='message',
                                                    size=[dp(56),
                                                          dp(56)])
        create_message_btn.md_bg_color = App.get_running_app(
        ).theme_cls.primary_color
        create_message_btn.theme_text_color = "Custom"
        create_message_btn.text_color = [1, 1, 1, 1]
        create_message_btn.bind(on_press=lambda x: self.switch_screens())
        create_message_anchor.add_widget(create_message_btn)
        self.add_widget(create_message_anchor)

        # Nav Bar
        self.nav_bar = MyNavigationLayout(scroll_view=self.scroll)
        self.nav_bar_anchor = AnchorLayout(anchor_x='center', anchor_y='top')
        self.nav_bar_anchor.add_widget(self.nav_bar)
        self.add_widget(self.nav_bar_anchor)
        self.do_layout()