jayyu3333

Untitled

Dec 24th, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.38 KB | None | 0 0
  1. from kivy.config import Config
  2. Config.set('kivy', 'keyboard_mode', 'dock')
  3.  
  4. from kivymd.app import MDApp
  5. from kivy.lang import Builder
  6. from kivymd.uix.screen import MDScreen
  7. from kivy.uix.screenmanager import ScreenManager
  8. from kivymd.uix.textfield import MDTextFieldRound
  9. from kivy.properties import NumericProperty
  10. from kivy.core.window import Window
  11. from kivy.uix.scrollview import ScrollView
  12. import re
  13.  
  14. KV = ('''
  15. <REGITRATION_Window>:
  16.    name:'regitration_window1'
  17.    #RelativeLayout:
  18.  
  19.    MDToolbar:
  20.        title: 'Registration'
  21.        elevation: 10
  22.        left_action_items: [['arrow-left', lambda x: app.change_screen('login_window1')]]
  23.        pos_hint: {"left":1, "top":1}
  24.  
  25.    MDLabel:
  26.        text: 'Full Name'
  27.        font_size: 15
  28.        pos_hint : {'x':0.0322, 'y':0.35}
  29.        
  30.    MainKeypad:
  31.        max_characters: 70
  32.        hint_text: 'For Eg:- xxx yyy zzz'
  33.        pos_hint : {'x':0.0322, 'y':0.790}
  34.        size_hint : 0.6, .045
  35.  
  36.  
  37.    MDLabel:
  38.        text: 'Country Code '
  39.        font_size: 15
  40.        pos_hint : {'x':0.0322, 'y':0.272}
  41.        
  42.    NumericInput:
  43.        max_characters: 3
  44.        int_text: 'For Eg:- +91'
  45.        pos_hint : {'x':0.0322, 'y':0.710}
  46.        size_hint : 0.09, .045
  47.  
  48.    MDLabel:
  49.        text: 'Mobile Number'
  50.        font_size: 15
  51.        pos_hint : {'x':0.305, 'y':0.272}
  52.        
  53.    NumericInput:
  54.        max_characters: 10
  55.        hint_text: 'For Eg:- 987654321'
  56.        pos_hint :{'x':0.305, 'y':0.710}
  57.        size_hint : 0.35, .045
  58.                
  59.  
  60.    MDLabel:
  61.        text: 'Location'
  62.        font_size: 15
  63.        pos_hint : {'x':0.0322, 'y':0.190}
  64.        
  65.    MainKeypad:
  66.        max_characters: 70
  67.        hint_text: 'For Eg:- kalyan'
  68.        pos_hint : {'x':0.0322, 'y':0.630}
  69.        size_hint : 0.6, .045
  70.  
  71.    MDLabel:
  72.        text: 'Pin Code'
  73.        font_size: 15
  74.        pos_hint : {'x':0.0322, 'y':0.11}
  75.        
  76.    NumericInput:
  77.        max_characters: 7
  78.        hint_text: 'For Eg:- 400050'
  79.        pos_hint : {'x':0.0322, 'y':0.550}
  80.        size_hint : 0.6, .045
  81.  
  82.    MDLabel:
  83.        text: 'City/Town/Village'
  84.        font_size: 15
  85.        pos_hint : {'x':0.0322, 'y':0.03}
  86.        
  87.    MainKeypad:
  88.        max_characters: 70
  89.        hint_text: 'For Eg:- Mumbai'
  90.        pos_hint : {'x':0.0322, 'y':0.470}
  91.        size_hint : 0.6, .045
  92.  
  93.    MDLabel:
  94.        text: 'District/Taluka'
  95.        font_size: 15
  96.        pos_hint : {'x':0.0322, 'y':-0.05}
  97.        
  98.    MainKeypad:
  99.        max_characters: 70
  100.        hint_text: 'For Eg:- Mumbai'
  101.        pos_hint : {'x':0.0322, 'y':0.390}
  102.        size_hint : 0.6, .045
  103.  
  104.    MDLabel:
  105.        text: 'State'
  106.        font_size: 15
  107.        pos_hint : {'x':0.0322, 'y':-0.13}
  108.        
  109.    MainKeypad:
  110.        max_characters: 70
  111.        hint_text: 'For Eg:- Maharashtra'
  112.        pos_hint : {'x':0.0322, 'y':0.310}
  113.        size_hint : 0.6, .045
  114.  
  115.    MDLabel:
  116.        text: 'Country'
  117.        font_size: 15
  118.        pos_hint : {'x':0.0322, 'y':-0.21}
  119.        
  120.    MainKeypad:
  121.        max_characters: 70
  122.        hint_text: 'For Eg:- India'
  123.        pos_hint : {'x':0.0322, 'y':0.230}
  124.        size_hint : 0.6, .045
  125.  
  126.    MDLabel:
  127.        text: 'Password'
  128.        font_size: 15
  129.        pos_hint : {'x':0.0322, 'y':-0.29}
  130.        
  131.    MainKeypad:
  132.        id: field_password
  133.        max_characters: 70          
  134.        hint_text: 'For Eg:- Chennai@123'
  135.        pos_hint : {'x':0.0322, 'y':0.150}
  136.        size_hint : 0.6, .045
  137.            
  138.    MDLabel:
  139.        text: 'Confirm Password'
  140.        font_size: 15
  141.        pos_hint : {'x':0.0322, 'y':-0.37}
  142.        
  143.    MainKeypad:
  144.        id: field_confirmpassword
  145.        max_characters: 70          
  146.        hint_text: 'For Eg:- Chennai@123'
  147.        password: True
  148.        pos_hint : {'x':0.0322, 'y':0.070}
  149.        size_hint : 0.6, .045
  150.  
  151.    MDLabel:
  152.        id: is_vallid
  153.        #text: 'Vallidation'
  154.        font_size: 45
  155.        pos_hint : {'x':0.67, 'y':0.38}
  156.            
  157.    MDFillRoundFlatButton:
  158.        text:'REGISTER'
  159.        pos_hint: {'x':.1, 'y':.1}
  160.        on_press: app.vall()
  161.  
  162.    MDFillRoundFlatButton:
  163.        text:'Cancel'
  164.        pos_hint: {'x':.3, 'y':.1}
  165.  
  166. WindowManager:
  167.    REGITRATION_Window:
  168.        id: key_num
  169.  
  170.            ''')
  171.  
  172. class REGITRATION_Window(MDScreen):
  173.     pass
  174.    
  175. class WindowManager(ScreenManager):
  176.     pass
  177.  
  178. class NumericInput(MDTextFieldRound):
  179.     max_characters = NumericProperty()
  180.  
  181.     def __init__(self, **kwargs):
  182.         super().__init__(input_filter=self.char_limit, **kwargs)
  183.  
  184.     def on_focus(self, instance_text_field, focus_value: bool):
  185.         if focus_value:
  186.             num_kb = Window.request_keyboard(self.close_key, self)
  187.             if num_kb.widget:
  188.                 num_kb.widget.layout = 'numeric.json'
  189.  
  190.     def close_key(self):
  191.         pass
  192.  
  193.     def char_limit(self, substring, from_undo):
  194.         if len(self.text) < self.max_characters:
  195.             return substring
  196.  
  197.  
  198. class MainKeypad(MDTextFieldRound):
  199.     max_characters = NumericProperty()
  200.     def __init__(self, **kwargs):
  201.         super().__init__(input_filter=self.char_limit, **kwargs)
  202.  
  203.     def on_focus(self, instance_text_field, focus_value: str):
  204.        
  205.         if focus_value:
  206.             kb = Window.request_keyboard(self.close_key, self)
  207.             if kb.widget:
  208.                 kb.widget.layout = 'qwerty'
  209.  
  210.     def close_key(self):
  211.         pass
  212.  
  213.     def char_limit(self, substring, from_undo):
  214.         if len(self.text) < self.max_characters:
  215.             return substring
  216.  
  217.  
  218. class MainApp(MDApp):
  219.     def build(self):
  220.         return Builder.load_string(KV)
  221.  
  222.     def vall(self):
  223.         main_pswd = self.root.get_screen('regitration_window1').ids.field_password.text
  224.         confirm_pswd=self.root.get_screen('regitration_window1').ids.field_confirmpassword.text
  225.  
  226.         reg = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!#%*?&]{6,16}$"
  227.  
  228.         match_re = re.compile(reg)
  229.  
  230.         main_res = re.search(match_re, main_pswd)
  231.         confirm_res = re.search(match_re, confirm_pswd)
  232.  
  233.         if (main_res==confirm_res):
  234.             self.root.get_screen('regitration_window1').ids.is_vallid.text = "Error"
  235.         else:
  236.             self.root.get_screen('regitration_window1').ids.is_vallid.text = "Vallidation"
  237.  
  238. if __name__ == '__main__':
  239.     MainApp().run()
Advertisement
Add Comment
Please, Sign In to add comment