electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

wallets.py (2102B)


      1 import os
      2 
      3 from kivy.app import App
      4 from kivy.factory import Factory
      5 from kivy.properties import ObjectProperty
      6 from kivy.lang import Builder
      7 
      8 from electrum.util import base_units
      9 from electrum.storage import StorageReadWriteError
     10 
     11 from ...i18n import _
     12 from .label_dialog import LabelDialog
     13 
     14 Builder.load_string('''
     15 <WalletDialog@Popup>:
     16     title: _('Wallets')
     17     id: popup
     18     path: ''
     19     disable_new: True
     20     BoxLayout:
     21         orientation: 'vertical'
     22         padding: '10dp'
     23         FileChooserIconView:
     24             id: wallet_selector
     25             dirselect: False
     26             filter_dirs: True
     27             filter: '*.*'
     28             path: root.path
     29             rootpath: root.path
     30             size_hint_y: 0.6
     31         Widget
     32             size_hint_y: 0.1
     33         GridLayout:
     34             cols: 3
     35             size_hint_y: 0.1
     36             Button:
     37                 id: new_button
     38                 disabled: root.disable_new
     39                 size_hint: 0.1, None
     40                 height: '48dp'
     41                 text: _('New')
     42                 on_release:
     43                     popup.dismiss()
     44                     root.new_wallet(wallet_selector.path)
     45             Button:
     46                 id: open_button
     47                 size_hint: 0.1, None
     48                 height: '48dp'
     49                 text: _('Open')
     50                 disabled: not wallet_selector.selection
     51                 on_release:
     52                     popup.dismiss()
     53                     root.callback(wallet_selector.selection[0])
     54 ''')
     55 
     56 class WalletDialog(Factory.Popup):
     57 
     58     def __init__(self, path, callback, disable_new):
     59         Factory.Popup.__init__(self)
     60         self.path = path
     61         self.callback = callback
     62         self.disable_new = disable_new
     63 
     64     def new_wallet(self, dirname):
     65         assert self.disable_new is False
     66         def cb(filename):
     67             if not filename:
     68                 return
     69             # FIXME? "filename" might contain ".." (etc) and hence sketchy path traversals are possible
     70             self.callback(os.path.join(dirname, filename))
     71         d = LabelDialog(_('Enter wallet name'), '', cb)
     72         d.open()