Advertisement
jwinterm

popupTest.py

Dec 22nd, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.00 KB | None | 0 0
  1. from kivy.app import App
  2. from kivy.lang import Builder
  3. from kivy.properties import ObjectProperty
  4. from kivy.uix.boxlayout import BoxLayout
  5. from kivy.uix.popup import Popup
  6. from kivy.uix.textinput import TextInput
  7.  
  8.  
  9. Builder.load_string("""
  10. <LoadWalletPopup>:
  11.    id: load_wallet_popup
  12.    title: "Load Wallet Window"
  13.    size_hint: 0.75, 0.75
  14.    auto_dismiss: False
  15.    wallet_path: wallet_path
  16.    wallet_pw: wallet_pw
  17.    repeat_wallet_pw: repeat_wallet_pw
  18.    BoxLayout:
  19.        padding: 60, 30, 60, 30
  20.        orientation: 'vertical'
  21.        Label:
  22.            text: "Enter wallet keys path:"
  23.        TabTextInput:
  24.            id: wallet_path
  25.            next: wallet_pw
  26.        Label:
  27.            text: "Enter wallet password:"
  28.        TabTextInput:
  29.            id: wallet_pw
  30.            password: True
  31.            next: repeat_wallet_pw
  32.        Label:
  33.            text: "Repeat wallet password:"
  34.        TabTextInput:
  35.            id: repeat_wallet_pw
  36.            password: True
  37.            next: wallet_path
  38.        Button:
  39.            text: "Click to load wallet"
  40.            on_press: root.submitForm()
  41.  
  42. <RootWidget>
  43.    BoxLayout:
  44.        Button:
  45.            text: "Press to launch popup"
  46.            on_press: root.launchPopup()
  47. """)
  48.  
  49.  
  50. class TabTextInput(TextInput):
  51.     """ Tab or enter to next TextInput class """
  52.     def __init__(self, *args, **kwargs):
  53.         self.next = kwargs.pop('next', None)
  54.         super(TabTextInput, self).__init__(*args, **kwargs)
  55.         self.multiline = False
  56.  
  57.     def set_next(self, next):
  58.         self.next = next
  59.  
  60.     def _keyboard_on_key_down(self, window, keycode, text, modifiers):
  61.         key, key_str = keycode
  62.         print(key, key_str)
  63.         if key == 9 and self.next is not None:
  64.             self.next.focus = True
  65.             self.next.select_all()
  66.         else:
  67.             super(TabTextInput, self)._keyboard_on_key_down(window, keycode, text, modifiers)
  68.  
  69.  
  70. class LoadWalletPopup(Popup):
  71.     """ Wallet creation screen popup """
  72.     wallet_name = ObjectProperty()
  73.     wallet_pw = ObjectProperty()
  74.     repeat_wallet_pw = ObjectProperty()
  75.  
  76.     def __init__(self, *args, **kwargs):
  77.         super(LoadWalletPopup, self).__init__(*args, **kwargs)
  78.  
  79.     def _keyboard_on_key_down(self, window, keycode, text, modifiers):
  80.         key, key_str = keycode
  81.         print(key, key_str)
  82.         if key in (13, 271):
  83.             self.submitForm()
  84.         else:
  85.             super(LoadWalletPopup, self)._keyboard_on_key_down(window, keycode, text, modifiers)
  86.  
  87.     def submitForm(self):
  88.         self.dismiss()
  89.         print("dismissed")
  90.  
  91. class RootWidget(BoxLayout):
  92.     """Root Kivy accordion widget class"""
  93.     def __init__(self, **kwargs):
  94.         super(RootWidget, self).__init__(**kwargs)
  95.  
  96.     def launchPopup(self):
  97.         p = LoadWalletPopup()
  98.         p.open()
  99.  
  100. class lightWalletApp(App):
  101.     def build(self):
  102.         root = RootWidget()
  103.         return root
  104.  
  105.  
  106. if __name__ == '__main__':
  107.     lightWalletApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement