jayyu3333

Text Clearing and Reset

Feb 16th, 2022
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 23.39 KB | None | 0 0
  1. from kivymd.app import MDApp
  2. from kivy.lang import Builder
  3. from kivymd.uix.screen import MDScreen
  4. from kivy.uix.screenmanager import ScreenManager
  5. from kivy.lang import Builder
  6. import re
  7. KV=('''
  8. <LOGIN_Window>:
  9.    name:'login_window1'
  10.    FloatLayout:
  11.    
  12.        MDBoxLayout:
  13.            orientation :'vertical'
  14.            MDToolbar:
  15.                title: 'Login Screen'
  16.                elevation: 10
  17.                left_action_items: [['menu', lambda x: nav_drawer.set_state('open')]]
  18.                md_bg_color: 225/255,96/255,1/255,1
  19.  
  20.            MDLabel:
  21.            MDLabel:
  22.            MDLabel:
  23.  
  24.            MDBoxLayout:
  25.                orientation :'vertical'
  26.                pos_hint: {'center_x':.5}
  27.                # size_hint:None, None
  28.                size_hint: 0.8, 0.8
  29.                size_hint_y:None
  30.                spacing:'10dp'
  31.  
  32.                MDLabel:
  33.                    text:'Email-ID'
  34.                    font_size: '15sp'
  35.                    size_hint_y: None
  36.                    height: self.texture_size[1] + dp(10)
  37.                    color:0,0,0,1
  38.                    
  39.  
  40.                MDTextFieldRound:
  41.                    id:login_emaiid
  42.                    hint_text: 'For Eg:- [email protected]'
  43.                    icon_left: "email"
  44.                    input_type:'text'
  45.                    icon_left_color:[0,0,0,1]
  46.                    hint_text_color:0,0,0,1
  47.                    icon_right_color:[0,0,0,1]
  48.                    foreground_color:0,0,0,1
  49.                    line_color_focus: 255/255,96/255,1/255,1
  50.                    normal_color: [255/255,96/255,1/255,1]
  51.                    color_active: [255/255,96/255,1/255,1]
  52.                    cursor_color: 0,0,0,1
  53.                    #required: True
  54.                    on_text_validate: login_passw.focus=True
  55.                    on_text:app.logIn_Email_pass_validate()
  56.                    multiline: False
  57.                    
  58.                        
  59.                MDLabel:
  60.                    text:'Password'
  61.                    font_size: '15sp'
  62.                    size_hint_y: None
  63.                    height: self.texture_size[1] + dp(10)
  64.                    color:0,0,0,1
  65.                    
  66.                
  67.                    
  68.  
  69.                MDTextFieldRound:
  70.                    id:login_passw
  71.                    multiline: False
  72.                    hint_text: 'Password'
  73.                    icon_left: 'key-variant'
  74.                    #password: True
  75.                    #icon_right:'eye-off'
  76.                    input_type:'text'
  77.                    icon_left_color:0,0,0,1
  78.                    hint_text_color:0,0,0,1
  79.                    icon_right_color:0,0,0,1
  80.                    foreground_color:0,0,0,1
  81.                    line_color_focus: 255/255,96/255,1/255,1
  82.                    normal_color: 255/255,96/255,1/255,1
  83.                    color_active: 255/255,96/255,1/255,1
  84.                    cursor_color: 0,0,0,1
  85.                    on_text_validate: login_emaiid.focus=True
  86.                    on_text:app.logIn_Email_pass_validate()
  87.                    multiline: False
  88.                    
  89.  
  90.                MDLabel:
  91.  
  92.                
  93.                
  94.                MDFillRoundFlatButton:
  95.                    id: logIn
  96.                    text: 'Go to Register'
  97.                    md_bg_color_disabled: 255/255,96/255,1/255,1
  98.                    md_bg_color: 255/255,96/255,1/255,1
  99.                    on_release:
  100.                        root.manager.current = 'regitration_window1'
  101.                        app.Clear_Login()
  102.                    
  103.                        
  104.                        
  105.                
  106.                    
  107.  
  108.            
  109.            MDLabel:
  110.            MDLabel:
  111.            MDLabel:
  112.            
  113.          
  114. <REGITRATION_Window>:
  115.    name:'regitration_window1'
  116.    FloatLayout:
  117.        BoxLayout:
  118.            orientation: 'vertical'
  119.            MDToolbar:
  120.                title: 'Registration Screen'
  121.                elevation: 10
  122.                left_action_items: [['arrow-left', lambda x: app.change_screen('login_window1')]]
  123.                size_hint_y:None
  124.                md_bg_color: 225/255,96/255,1/255,1
  125.  
  126.            MDLabel:
  127.            MDLabel:
  128.            MDLabel:
  129.  
  130.            MDBoxLayout:
  131.                orientation :'vertical'
  132.                pos_hint: {'center_x':.5}
  133.                # size_hint:None, None
  134.                size_hint: 0.8, 0.8
  135.                size_hint_y:None
  136.                spacing:'10dp'
  137.                
  138.                MDLabel:
  139.                    text: 'Full Name'
  140.                    font_size: '15sp'
  141.                    height: self.texture_size[1] + dp(10)
  142.                    color:0,0,0,1
  143.  
  144.                MDTextFieldRound:
  145.                    id:field_Name
  146.                    hint_text: 'xxx yyy zzz'
  147.                    input_type:'text'
  148.                    icon_left_color:0,0,0,1
  149.                    hint_text_color:0,0,0,1
  150.                    icon_right_color:0,0,0,1
  151.                    foreground_color:0,0,0,1
  152.                    line_color_focus: 255/255,96/255,1/255,1
  153.                    normal_color: 255/255,96/255,1/255,1
  154.                    color_active: 255/255,96/255,1/255,1
  155.                    cursor_color: 0,0,0,1
  156.                    helper_text: "or click on forgot username"
  157.                    helper_text_mode: "on_focus"
  158.                    on_text_validate: field_EmailID.focus=True
  159.                    on_text:app.logIn_Email_pass_validate()
  160.                    multiline: False
  161.  
  162.                MDLabel:
  163.                    text:'Email-ID'
  164.                    font_size: '15sp'
  165.                    height: self.texture_size[1] + dp(10)
  166.                    color:0,0,0,1
  167.                    
  168.                MDTextFieldRound:
  169.                    id:field_EmailID
  170.                    hint_text: '[email protected]'
  171.                    input_type:'text'
  172.                    color:0,0,0,1
  173.                    icon_left_color:0,0,0,1
  174.                    hint_text_color:0,0,0,1
  175.                    icon_right_color:0,0,0,1
  176.                    foreground_color:0,0,0,1
  177.                    line_color_focus: 255/255,96/255,1/255,1
  178.                    normal_color: 255/255,96/255,1/255,1
  179.                    color_active: 255/255,96/255,1/255,1
  180.                    on_text_validate: field_Contrycode.focus=True
  181.                    on_text:app.logIn_Email_pass_validate()
  182.                    multiline: False
  183.                
  184.                    
  185.                
  186.                MDLabel:
  187.                    text: 'Country Code '
  188.                    font_size: '15sp'
  189.                    height: self.texture_size[1] + dp(10)
  190.                    color:0,0,0,1
  191.                            
  192.                MDTextFieldRound:
  193.                    id: field_Contrycode
  194.                    hint_text: '+91'
  195.                    input_type:'number'
  196.                    icon_left_color:0,0,0,1
  197.                    hint_text_color:0,0,0,1
  198.                    icon_right_color:0,0,0,1
  199.                    foreground_color:0,0,0,1
  200.                    line_color_focus: 255/255,96/255,1/255,1
  201.                    normal_color: 255/255,96/255,1/255,1
  202.                    color_active: 255/255,96/255,1/255,1
  203.                    cursor_color: 0,0,0,1
  204.                    on_text_validate: field_MobileNumber.focus=True
  205.                    on_text:app.logIn_Email_pass_validate()
  206.                    multiline: False
  207.                            
  208.    
  209.                MDLabel:
  210.                    text: 'Mobile Number'
  211.                    font_size: '15sp'
  212.                    height: self.texture_size[1] + dp(10)
  213.                    color:0,0,0,1
  214.                    
  215.                MDTextFieldRound:
  216.                    id: field_MobileNumber
  217.                    hint_text: '987654321'
  218.                    input_type:'number'
  219.                    icon_left_color:0,0,0,1
  220.                    hint_text_color:0,0,0,1
  221.                    icon_right_color:0,0,0,1
  222.                    foreground_color:0,0,0,1
  223.                    line_color_focus: 255/255,96/255,1/255,1
  224.                    normal_color: 255/255,96/255,1/255,1
  225.                    color_active: 255/255,96/255,1/255,1
  226.                    cursor_color: 0,0,0,1
  227.                    input_filter: 'int'
  228.                    on_text_validate: field_Location.focus=True
  229.                    on_text:app.logIn_Email_pass_validate()
  230.                
  231.                MDLabel:
  232.                    text: 'Password'
  233.                    font_size: '15sp'
  234.                    height: self.texture_size[1] + dp(10)
  235.                    color:0,0,0,1
  236.                        
  237.                    
  238.                MDTextFieldRound:
  239.                    id: field_password
  240.                    max_characters: 70          
  241.                    hint_text: 'Chennai@123'
  242.                    icon_left_color:0,0,0,1
  243.                    hint_text_color:0,0,0,1
  244.                    icon_right_color:0,0,0,1
  245.                    foreground_color:0,0,0,1
  246.                    line_color_focus: 255/255,96/255,1/255,1
  247.                    normal_color: 255/255,96/255,1/255,1
  248.                    color_active: 255/255,96/255,1/255,1
  249.                    cursor_color: 0,0,0,1
  250.                    on_text_validate: field_confirmpassword.focus=True
  251.                    on_text:app.logIn_Email_pass_validate()
  252.                    multiline: False
  253.  
  254.                MDFillRoundFlatButton:
  255.                    text:'Go to Login'
  256.                    on_release:
  257.                        root.manager.current = 'login_window1'
  258.                        app.Clear_Register()
  259.                    md_bg_color: 255/255,96/255,1/255,1
  260.            MDLabel:
  261.            MDLabel:
  262.            MDLabel:
  263.                
  264.  
  265.                
  266.                
  267.  
  268.            
  269. WindowManager:
  270.    LOGIN_Window:
  271.  
  272.    REGITRATION_Window:
  273.    
  274.            ''')
  275.  
  276. class LOGIN_Window(MDScreen):
  277.     pass
  278.  
  279.  
  280. class REGITRATION_Window(MDScreen):
  281.     pass
  282.  
  283.  
  284. class WindowManager(ScreenManager):
  285.     pass
  286.              
  287.  
  288. class MainApp(MDApp):
  289.    
  290.     def build(self):
  291.         self.theme_cls.primary_palette = "Orange"
  292.         self.theme_cls.primary_hue = "A700"
  293.         return Builder.load_string(KV)
  294.  
  295.     regEmailID='^[a-zA-Z0-9]+[\._-]?[a-zA-Z0-9]+[@]\w+[.]\w{2,3}$'
  296.     match_re_EmailID= re.compile(regEmailID)
  297.  
  298.     regpassword = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*#?&+-/=)(^~`,.<>;:"'"'"'|}{\[\]\s\\\\_])[A-Za-z\d@$!#%*?&+-/=)(^~`,.<>;:"'"'"'|}{\[\]\s\\\\_]{4,18}$"
  299.     match_re_pasword = re.compile(regpassword)
  300.  
  301.     regName='^([a-zA-Z]+)\s([a-zA-Z]+)*\s([a-z]+)*$'
  302.     match_re_Name = re.compile(regName)
  303.    
  304.     regContryCode='^\+(\d{1}\-)?(\d{1,3})$'
  305.     match_re_CountryCode = re.compile(regContryCode)
  306.    
  307.     regMobileNumber='^[1-9]{2}[0-9]{8}$'
  308.     match_re_Mobile = re.compile(regMobileNumber)
  309.    
  310.     regOnlyALPHA='(^\w+)\s?'
  311.     match_re_OnlyAlpha= re.compile(regOnlyALPHA)
  312.  
  313.     regPincode= '^[1-9]{1}[0-9]{2}[0-9]{2,6}$'
  314.     match_re_Pincode= re.compile(regPincode)
  315.  
  316.  
  317.     def logIn_Email_pass_validate(self):
  318.         if MDApp.get_running_app().root.current== 'login_window1':
  319.             if MDApp.get_running_app().root.get_screen('login_window1').ids.login_emaiid.focus==True:
  320.                 if not re.search(self.match_re_EmailID, MDApp.get_running_app().root.get_screen('login_window1').ids.login_emaiid.text):
  321.                     MDApp.get_running_app().root.get_screen('login_window1').ids.login_passw.disabled= True
  322.                     MDApp.get_running_app().root.get_screen('login_window1').ids.login_emaiid.focus=True
  323.                     MDApp.get_running_app().root.get_screen('login_window1').ids.login_emaiid.disabled=False
  324.                     MDApp.get_running_app().root.get_screen('login_window1').ids.logIn.disabled=True
  325.                     MDApp.get_running_app().root.get_screen('login_window1').ids.login_emaiid.icon_right="text-box-remove"
  326.                 elif re.search(self.match_re_EmailID,MDApp.get_running_app().root.get_screen('login_window1').ids.login_emaiid.text):
  327.                     MDApp.get_running_app().root.get_screen('login_window1').ids.login_passw.disabled= False
  328.                     MDApp.get_running_app().root.get_screen('login_window1').ids.logIn.disabled=False
  329.                     MDApp.get_running_app().root.get_screen('login_window1').ids.login_emaiid.icon_right="text-box-check-outline"
  330.  
  331.             elif MDApp.get_running_app().root.get_screen('login_window1').ids.login_passw.focus==True:
  332.                 if not re.search(self.match_re_pasword, MDApp.get_running_app().root.get_screen('login_window1').ids.login_passw.text):
  333.                     MDApp.get_running_app().root.get_screen('login_window1').ids.login_emaiid.disabled= True
  334.                     MDApp.get_running_app().root.get_screen('login_window1').ids.login_passw.focus=True
  335.                     MDApp.get_running_app().root.get_screen('login_window1').ids.login_passw.disabled=False
  336.                     MDApp.get_running_app().root.get_screen('login_window1').ids.logIn.disabled=True
  337.                     MDApp.get_running_app().root.get_screen('login_window1').ids.login_passw.icon_right="text-box-remove"
  338.                 elif re.search(self.match_re_pasword, MDApp.get_running_app().root.get_screen('login_window1').ids.login_passw.text):
  339.                     MDApp.get_running_app().root.get_screen('login_window1').ids.login_emaiid.disabled= False
  340.                     MDApp.get_running_app().root.get_screen('login_window1').ids.logIn.disabled=False
  341.                     MDApp.get_running_app().root.get_screen('login_window1').ids.login_passw.icon_right="text-box-check-outline"
  342.    
  343.         elif self.root.current == 'regitration_window1':
  344.    
  345.             if MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_Name.focus==True:
  346.                 if not re.search(self.match_re_Name, self.root.get_screen('regitration_window1').ids.field_Name.text):
  347.                     self.root.get_screen('regitration_window1').ids.field_EmailID.disabled= True
  348.                     self.root.get_screen('regitration_window1').ids.field_Contrycode.disabled= True
  349.                     self.root.get_screen('regitration_window1').ids.field_MobileNumber.disabled= True
  350.                     self.root.get_screen('regitration_window1').ids.field_password.disabled= True
  351.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_Name.focus=True
  352.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_Name.disabled=False
  353.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_Name.icon_right="text-box-remove"
  354.  
  355.                 elif re.search(self.match_re_Name, self.root.get_screen('regitration_window1').ids.field_Name.text):
  356.                     self.root.get_screen('regitration_window1').ids.field_EmailID.disabled= False
  357.                     self.root.get_screen('regitration_window1').ids.field_Contrycode.disabled= False
  358.                     self.root.get_screen('regitration_window1').ids.field_MobileNumber.disabled= False
  359.                     self.root.get_screen('regitration_window1').ids.field_password.disabled= False
  360.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_Name.icon_right="text-box-check-outline"
  361.                    
  362.  
  363.             elif MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_EmailID.focus==True:
  364.                 if not re.search(self.match_re_EmailID, self.root.get_screen('regitration_window1').ids.field_EmailID.text):
  365.                     self.root.get_screen('regitration_window1').ids.field_Name.disabled= True
  366.                     self.root.get_screen('regitration_window1').ids.field_Contrycode.disabled= True
  367.                     self.root.get_screen('regitration_window1').ids.field_MobileNumber.disabled= True
  368.                     self.root.get_screen('regitration_window1').ids.field_password.disabled= True
  369.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_EmailID.focus=True
  370.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_EmailID.disabled=False
  371.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_EmailID.icon_right="text-box-remove"
  372.                 elif re.search(self.match_re_EmailID, self.root.get_screen('regitration_window1').ids.field_EmailID.text):
  373.                     self.root.get_screen('regitration_window1').ids.field_Name.disabled= False
  374.                     self.root.get_screen('regitration_window1').ids.field_Contrycode.disabled= False
  375.                     self.root.get_screen('regitration_window1').ids.field_MobileNumber.disabled= False
  376.                     self.root.get_screen('regitration_window1').ids.field_password.disabled= False
  377.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_EmailID.icon_right="text-box-check-outline"
  378.                
  379.             elif MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_Contrycode.focus==True:
  380.                 if not re.search(self.match_re_CountryCode, self.root.get_screen('regitration_window1').ids.field_Contrycode.text):
  381.                     self.root.get_screen('regitration_window1').ids.field_Name.disabled= True
  382.                     self.root.get_screen('regitration_window1').ids.field_EmailID.disabled= True
  383.                     self.root.get_screen('regitration_window1').ids.field_MobileNumber.disabled= True
  384.                     self.root.get_screen('regitration_window1').ids.field_password.disabled= True
  385.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_Contrycode.focus=True
  386.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_Contrycode.disabled=False
  387.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_Contrycode.icon_right="text-box-remove"
  388.                 elif re.search(self.match_re_CountryCode, self.root.get_screen('regitration_window1').ids.field_Contrycode.text):
  389.                     self.root.get_screen('regitration_window1').ids.field_Name.disabled= False
  390.                     self.root.get_screen('regitration_window1').ids.field_EmailID.disabled= False
  391.                     self.root.get_screen('regitration_window1').ids.field_MobileNumber.disabled= False
  392.                     self.root.get_screen('regitration_window1').ids.field_password.disabled= False
  393.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_Contrycode.icon_right="text-box-check-outline"
  394.  
  395.             elif MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_MobileNumber.focus==True:
  396.                 if not re.search(self.match_re_Mobile, self.root.get_screen('regitration_window1').ids.field_MobileNumber.text):
  397.                     self.root.get_screen('regitration_window1').ids.field_Name.disabled= True
  398.                     self.root.get_screen('regitration_window1').ids.field_EmailID.disabled= True
  399.                     self.root.get_screen('regitration_window1').ids.field_Contrycode.disabled= True
  400.                     self.root.get_screen('regitration_window1').ids.field_password.disabled= True
  401.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_MobileNumber.focus=True
  402.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_MobileNumber.disabled=False
  403.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_MobileNumber.icon_right="text-box-remove"
  404.                 elif re.search(self.match_re_Mobile, self.root.get_screen('regitration_window1').ids.field_MobileNumber.text):
  405.                     self.root.get_screen('regitration_window1').ids.field_Name.disabled= False
  406.                     self.root.get_screen('regitration_window1').ids.field_EmailID.disabled= False
  407.                     self.root.get_screen('regitration_window1').ids.field_Contrycode.disabled= False
  408.                     self.root.get_screen('regitration_window1').ids.field_password.disabled= False
  409.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_MobileNumber.icon_right="text-box-check-outline"
  410.  
  411.             elif MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_password.focus==True:
  412.                 if not re.search(self.match_re_pasword, self.root.get_screen('regitration_window1').ids.field_password.text):
  413.                     self.root.get_screen('regitration_window1').ids.field_Name.disabled= True
  414.                     self.root.get_screen('regitration_window1').ids.field_EmailID.disabled= True
  415.                     self.root.get_screen('regitration_window1').ids.field_Contrycode.disabled= True
  416.                     self.root.get_screen('regitration_window1').ids.field_MobileNumber.disabled= True
  417.                    
  418.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_password.focus=True
  419.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_password.disabled=False
  420.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_password.icon_right="text-box-remove"
  421.                 elif re.search(self.match_re_pasword, self.root.get_screen('regitration_window1').ids.field_password.text):
  422.                     self.root.get_screen('regitration_window1').ids.field_Name.disabled= False
  423.                     self.root.get_screen('regitration_window1').ids.field_EmailID.disabled= False
  424.                     self.root.get_screen('regitration_window1').ids.field_Contrycode.disabled= False
  425.                     self.root.get_screen('regitration_window1').ids.field_MobileNumber.disabled= False
  426.                    
  427.                     MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_password.icon_right="text-box-check-outline"
  428.  
  429.     def Clear_Register(self):
  430.         MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_Name.text=""
  431.         MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_Name.icon_right=""
  432.         MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_EmailID.text=""
  433.         MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_EmailID.icon_right=""
  434.         MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_Contrycode.text=""
  435.         MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_Contrycode.icon_right=""
  436.         MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_MobileNumber.text=""
  437.         MDApp.get_running_app().root.get_screen('regitration_window1').ids.field_MobileNumber.icon_right=""  
  438.  
  439.     def Clear_Login(self):
  440.         MDApp.get_running_app().root.get_screen('login_window1').ids.login_emaiid.text=""
  441.         MDApp.get_running_app().root.get_screen('login_window1').ids.login_emaiid.focus=""
  442.         MDApp.get_running_app().root.get_screen('login_window1').ids.login_passw.text=""
  443.         MDApp.get_running_app().root.get_screen('login_window1').ids.login_passw.focus=""
  444.    
  445.     def change_screen(self, screen):
  446.         MDApp.get_running_app().root.current = screen
  447.         self.Clear_Register()
  448.         self.logIn_Email_pass_validate()
  449. ()
  450.  
  451.  
  452. if __name__ == '__main__':  
  453.     MainApp().run()
  454.  
Advertisement
Add Comment
Please, Sign In to add comment