def build(self):
        """
        This method call before on_start() method so anything
        that need before start application all other method and code 
        write here.
        """
        self.theme_cls.theme_style="Light"
    
        self.screen_manager = Root()
        self.screen_manager.add_widget(Login_Screen())
        self.screen_manager.add_widget(Signup_Screen())
        self.screen_manager.add_widget(Forgot_Screen())
        self.screen_manager.add_widget(Verification_Screen())
        self.screen_manager.add_widget(Home_Screen())
        self.screen_manager.add_widget(Chat_Room_Screen())
        self.screen_manager.add_widget(Profile_Screen())

        return self.screen_manager
    def build(self):
        FONT_PATH = os.path.join("assets", "fonts/")

        self.theme_cls.font_styles.update({
            "H1": [FONT_PATH + "RobotoMono-Medium", 96, False, -1.5],
            "H2": [FONT_PATH + "Overpass-Regular", 60, False, -0.5],
            "H3": [FONT_PATH + "RobotoMono-Regular", 48, False, 0],
            "H4": [FONT_PATH + "RobotoMono-SemiBold", 34, False, 0.25],
            "H5": [FONT_PATH + "Overpass-SemiBold", 24, False, 0],
            "H6": [FONT_PATH + "RobotoMono-Medium", 20, False, 0.15],
            # "Subtitle1": [
            #     FONT_PATH + "RobotoCondensed-Regular",
            #     16,
            #     False,
            #     0.15,
            # ],
            # "Subtitle2": [
            #     FONT_PATH + "RobotoCondensed-Medium",
            #     14,
            #     False,
            #     0.1,
            # ],
            "Body1": [FONT_PATH + "Overpass-Regular", 16, False, 0.5],
            # "Body2": [FONT_PATH + "RobotoCondensed-Light", 14, False, 0.25],
            "Button": [FONT_PATH + "Overpass-Black", 14, True, 1.25],
            # "Caption": [
            #     FONT_PATH + "RobotoCondensed-Regular",
            #     12,
            #     False,
            #     0.4,
            # ],
            "Overline": [
                FONT_PATH + "RobotoMono-Regular",
                10,
                True,
                1.5,
            ],
        })
        return Root()
 def build(self):
     return Root()
Exemple #4
0
 def build_app(self):  # build_app works like build method
     return Root()
Exemple #5
0
class HamsterApp(MDApp):
    """
    Hamster App start from here this class is root of app.
    in kivy (.kv) file when use app.method_name app is start from here
    """
    def __init__(self, **kwargs):
        super(HamsterApp, self).__init__(**kwargs)

        self.APP_NAME = "Hamster"
        self.COMPANY_NAME = "Hamster.org"

    def chat_room(self, touch, a):
        """Switch to Chatroom. but username and chatroom username 
        change according to which one you touch in chat list"""

        name = touch.text
        self.screen_manager.get_screen(
            "chat_room").ids.profile_bar.title = name

        self.screen_manager.change_screen("chat_room")

    def all_chats(self):
        """
        All Chat that show in home chat tab. all chat are added by 
        this method. it will use in differe t in future.
        """
        # for dummy chats [------
        # self.change_screen("profile")
        twolineW = TwoLineAvatarListItem(text=f"Hamster",
                                         secondary_text="@username",
                                         on_touch_up=self.chat_room)

        twolineW.add_widget(
            ImageLeftWidget(source="assets//img//hamster_icon.png"))

        self.screen_manager.get_screen("home").ids.chat_tab.add_widget(
            twolineW)
        #  ----- ] end dummy chats

    def build(self):
        """
        This method call before on_start() method so anything
        that need before start application all other method and code 
        write here.
        """
        self.theme_cls.primary_palette = "Blue"
        self.theme_cls.primary_hue = "500"

        self.theme_cls.accent_palette = "Amber"
        self.theme_cls.accent_hue = "500"

        self.theme_cls.theme_style = "Light"

        self.screen_manager = Root()
        self.screen_manager.add_widget(Login_Screen())
        self.screen_manager.add_widget(Signup_Screen())
        self.screen_manager.add_widget(Forgot_Screen())
        self.screen_manager.add_widget(Verification_Screen())
        self.screen_manager.add_widget(Home_Screen())
        self.screen_manager.add_widget(Chat_Room_Screen())
        self.screen_manager.add_widget(Profile_Screen())

        return self.screen_manager

    def on_start(self):
        """
        Anything we want to run when start application that code is here.
        """
        self.screen_manager.change_screen("login")
        self.all_chats()
class HamsterApp(MDApp):
    """
    Hamster App start from here this class is root of app.
    in kivy (.kv) file when use app.method_name app is start from here
    """

    def __init__(self, **kwargs):
        super(HamsterApp, self).__init__(**kwargs)
        Window.bind(on_keyboard=self._key_handler)
        
        self.screen_list = list() #this list have all screen that user switched

    def _key_handler(self, instance, key, *args):
        
        if key is 27:
            #in Desktop this key 27 is Esc and in Phone it's Back btn
            self.previous_screen()
            return True
    
    def previous_screen(self):
        """
        Switch to previous screen last screen in screen_list
        """
        last_screen=self.screen_list.pop()
        if last_screen == "home" or last_screen == "login":
            exit()
        print(self.screen_list)
        self.screen_manager.transition.direction = "left"
        self.screen_manager.current = self.screen_list[len(self.screen_list)-1]
        
        

    def change_screen(self,name):
        """
        Switch Screen using screen name and 
        """
        self.screen_manager.current = name 
        if name not in self.screen_list:
            self.screen_list.append(self.screen_manager.current)
        else:
            self.screen_list.remove(name)
            self.screen_list.append(self.screen_manager.current)
        
        print(self.screen_list)

        if name == "home":            
            # MDBottomNavigation not resize there tabs when app stat in android 
            # to resize when switch to home screen 
            self.screen_manager.get_screen(name).ids.android_tabs.on_resize()
        
        
    def chat_textbox(self):
        """
            MDCard size change when MSGbox use multilines.
            MDCard y axis size incress when MSGbox y axis size incress
        """
        fixed_Y_size = self.screen_manager.get_screen("chat_room").ids.root_chatroom.size[1]/3
        msg_textbox=self.screen_manager.get_screen("chat_room").ids.msg_textbox.size
        if msg_textbox[1] <= fixed_Y_size:
            self.screen_manager.get_screen("chat_room").ids.send_card.size[1]=msg_textbox[1]
            print(msg_textbox)
        else:
            self.screen_manager.get_screen("chat_room").ids.send_card.size[1]=fixed_Y_size

    def send_msg(self,msg_data):
        """
            When send button use to send msg this function call
            and clear MSGbox 
        """
        
        text_msg = MDLabel(text=msg_data,halign="left")
        
        sizeX = self.screen_manager.get_screen("chat_room").ids.msg_textbox.size[0]    

        sizeY = self.screen_manager.get_screen("chat_room").ids.msg_textbox.size[1]+60
        # ->> sizeY is equal to msg_textbox sizeY because text_msg sizeY not work 
        # that's why i use msg_textbox is called 'Jugaad'
        
        
        msg_card= MDCard(
            orientation= "vertical",
            size_hint=[None,None],
            size=[sizeX,sizeY],
            spacing=8,
            padding=20,
            elevation=9,
            ripple_behavior= True,
            radius= [25,25,25,0 ]

        )
        msg_card.add_widget(MDLabel(
            text= f"Hamster {' '*8} |1:00 PM|",
            theme_text_color= "Secondary",
            size_hint_y= None,
            height= 50
        ))
        msg_card.add_widget(MDSeparator(
            height= "1dp"
        ))

        msg_card.add_widget(text_msg)
        self.screen_manager.get_screen("chat_room").ids.all_msgs.add_widget(msg_card)
        print(msg_data)
        self.screen_manager.get_screen("chat_room").ids.msg_scroll_view.scroll_to(msg_card)
        self.screen_manager.get_screen("chat_room").ids.msg_textbox.text=""

    def chat_room(self,touch,a):
        """Switch to Chatroom. but username and chatroom username 
        change according to which one you touch in chat list"""
        
        name = touch.text
        self.screen_manager.get_screen("chat_room").ids.profile_bar.title = name


        self.change_screen("chat_room")
    
    def all_chats(self):
        """
        All Chat that show in home chat tab. all chat are added by 
        this method. it will use in differe t in future.
        """
        # for dummy chats [------
        # self.change_screen("profile")
        twolineW= TwoLineAvatarListItem(text=f"Hamster",
            secondary_text="@username",
            on_touch_up=self.chat_room)

        twolineW.add_widget(ImageLeftWidget(source="hamster_icon.png"))
        
        self.screen_manager.get_screen("home").ids.chat_tab.add_widget(twolineW)
        #  ----- ] end dummy chats

    def search_account(self,search_field):
        """
        this method use when search button pressed search_field
        contain data in string that you want to search on hamster server
        """

        # for dummy search item [------
        
        twolineW= TwoLineAvatarListItem(text=f"{search_field}",
            secondary_text=f"@{search_field}")

        twolineW.add_widget(ImageLeftWidget(source="hamster_icon.png"))
        
        self.screen_manager.get_screen("home").ids.search_items.add_widget(twolineW)
        # #  ----- ] end dummy search

    
    def change_profile_img(self):
        """
        method call when image click on profile_view page.
        if it's user own profile than show options of change.
        """
        bottom_sheet_menu = MDGridBottomSheet(
            animation=True,
        )
        data = {
            "Upload": "cloud-upload",
            "Camera": "camera",
        }
        for item in data.items():
            bottom_sheet_menu.add_item(
                item[0],
                lambda x, y=item[0]: print("hello",x,y),
                icon_src=item[1],
            )
        bottom_sheet_menu.open()
        
    
    def change_text_data(self,widget):
        """Change text data using Dialog box.
        [widget] change this widget text"""
        dialogObj =None
        Dialog=OneLineTextDialog()
        def cancel_btn(btn):
            # use function when CANCEL btn click
            dialogObj.dismiss(force=True)
        def ok_btn(btn):
            # use function when OK btn click
            widget.text = Dialog.ids.dialog_text.text
            cancel_btn(btn)
            
            
        if not dialogObj:
            dialogObj=MDDialog(
                auto_dismiss=True,
                title= widget.secondary_text,
                type="custom",
                content_cls=Dialog,
                buttons=[
                    MDFlatButton(
                        text="CANCEL", text_color=self.theme_cls.primary_color,
                        on_release=cancel_btn,
                    ),
                    MDFlatButton(
                        text="OK", text_color=self.theme_cls.primary_color,
                        on_release=ok_btn,
                    ),
                ],
            )
        dialogObj.open()


    def build(self):
        """
        This method call before on_start() method so anything
        that need before start application all other method and code 
        write here.
        """
        self.theme_cls.theme_style="Light"
    
        self.screen_manager = Root()
        self.screen_manager.add_widget(Login_Screen())
        self.screen_manager.add_widget(Signup_Screen())
        self.screen_manager.add_widget(Forgot_Screen())
        self.screen_manager.add_widget(Verification_Screen())
        self.screen_manager.add_widget(Home_Screen())
        self.screen_manager.add_widget(Chat_Room_Screen())
        self.screen_manager.add_widget(Profile_Screen())

        return self.screen_manager
    
    def on_start(self):
        """
        Anything we want to run when start application that code is here.
        """
        self.all_chats()