示例#1
0
 def change_password(self, cb):
     if self.wallet.has_password():
         self.protected(
             _("Changing PIN code.") + '\n' + _("Enter your current PIN:"),
             self._change_password, (cb, ))
     else:
         self._change_password(cb, None)
示例#2
0
    def scan_qr(self, on_complete):
        if platform != 'android':
            return
        from jnius import autoclass
        from android import activity
        PythonActivity = autoclass('org.kivy.android.PythonActivity')
        Intent = autoclass('android.content.Intent')
        intent = Intent("com.google.zxing.client.android.SCAN")
        intent.putExtra("SCAN_MODE", "QR_CODE_MODE")

        def on_qr_result(requestCode, resultCode, intent):
            if requestCode == 0:
                if resultCode == -1:  # RESULT_OK:
                    contents = intent.getStringExtra("SCAN_RESULT")
                    if intent.getStringExtra(
                            "SCAN_RESULT_FORMAT") == 'QR_CODE':
                        on_complete(contents)
                    else:
                        self.show_error(
                            "wrong format " +
                            intent.getStringExtra("SCAN_RESULT_FORMAT"))

        activity.bind(on_activity_result=on_qr_result)
        try:
            PythonActivity.mActivity.startActivityForResult(intent, 0)
        except:
            self.show_error(
                _('Could not start Barcode Scanner.') + ' ' +
                _('Please install the Barcode Scanner app from ZXing'))
示例#3
0
 def _show_seed(self, label, password):
     if self.wallet.has_password() and password is None:
         return
     keystore = self.wallet.keystore
     try:
         seed = keystore.get_seed(password)
         passphrase = keystore.get_passphrase(password)
     except:
         self.show_error("Invalid PIN")
         return
     label.text = _('Seed') + ':\n' + seed
     if passphrase:
         label.text += '\n\n' + _('Passphrase') + ': ' + passphrase
示例#4
0
 def description_dialog(self, screen):
     from .uix.dialogs.label_dialog import LabelDialog
     text = screen.message
     def callback(text):
         screen.message = text
     d = LabelDialog(_('Enter description'), text, callback)
     d.open()
示例#5
0
 def _sign_tx(self, tx, password, on_success, on_failure):
     try:
         self.wallet.sign_transaction(tx, password)
     except InvalidPassword:
         Clock.schedule_once(lambda dt: on_failure(_("Invalid PIN")))
         return
     Clock.schedule_once(lambda dt: on_success(tx))
示例#6
0
 def on_ref_label(self, label, touch):
     if label.touched:
         label.touched = False
         self.qr_dialog(label.name, label.data, True)
     else:
         label.touched = True
         self._clipboard.copy(label.data)
         Clock.schedule_once(lambda dt: self.show_info(_('Text copied to clipboard.\nTap again to display it as QR code.')))
示例#7
0
 def on_currency(self, ccy):
     b = (ccy != _('None'))
     self.fx.set_enabled(b)
     if b:
         if ccy != self.fx.get_currency():
             self.fx.set_currency(ccy)
         self.app.fiat_unit = ccy
     Clock.schedule_once(lambda dt: self.add_exchanges())
示例#8
0
 def fx_status(self):
     fx = self.app.fx
     if fx.is_enabled():
         source = fx.exchange.name()
         ccy = fx.get_currency()
         return '%s [%s]' %(ccy, source)
     else:
         return _('None')
示例#9
0
    def unit_dialog(self, item, dt):
        if self._unit_dialog is None:
            def cb(text):
                self.app._set_bu(text)
                item.bu = self.app.base_unit

            self._unit_dialog = ChoiceDialog(_('Denomination'), list(base_units.keys()), self.app.base_unit, cb)
        self._unit_dialog.open()
示例#10
0
 def coinselect_dialog(self, item, dt):
     if self._coinselect_dialog is None:
         choosers = sorted(coinchooser.COIN_CHOOSERS.keys())
         chooser_name = coinchooser.get_name(self.config)
         def cb(text):
             self.config.set_key('coin_chooser', text)
             item.status = text
         self._coinselect_dialog = ChoiceDialog(_('Coin selection'), choosers, chooser_name, cb)
     self._coinselect_dialog.open()
示例#11
0
 def language_dialog(self, item, dt):
     if self._language_dialog is None:
         l = self.config.get('language', 'en_UK')
         def cb(key):
             self.config.set_key("language", key, True)
             item.lang = self.get_language_name()
             self.app.language = key
         self._language_dialog = ChoiceDialog(_('Language'), languages, l, cb)
     self._language_dialog.open()
示例#12
0
    def broadcast(self, tx, pr=None):
        def on_complete(ok, msg):
            if ok:
                self.show_info(_('Payment sent.'))
                if self.send_screen:
                    self.send_screen.do_clear()
                if pr:
                    self.wallet.invoices.set_paid(pr, tx.txid())
                    self.wallet.invoices.save()
                    self.update_tab('invoices')
            else:
                self.show_error(msg)

        if self.network and self.network.is_connected():
            self.show_info(_('Sending'))
            threading.Thread(target=self._broadcast_thread, args=(tx, on_complete)).start()
        else:
            self.show_info(_('Cannot broadcast transaction') + ':\n' + _('Not connected'))
示例#13
0
 def on_keyboard(self, instance, key, keycode, codepoint, modifiers):
     if key == 27 and self.is_exit is False:
         self.is_exit = True
         self.show_info(_('Press again to exit'))
         return True
     # override settings button
     if key in (319, 282): #f1/settings button on android
         #self.gui.main_gui.toggle_settings(self)
         return True
示例#14
0
 def _change_password(self, cb, old_password):
     if self.wallet.has_password():
         if old_password is None:
             return
         try:
             self.wallet.check_password(old_password)
         except InvalidPassword:
             self.show_error("Invalid PIN")
             return
     self.password_dialog(_('Enter new PIN'), self._change_password2, (cb, old_password,))
示例#15
0
    def show_info_bubble(self,
                         text=_('Hello World'),
                         pos=None,
                         duration=0,
                         arrow_pos='bottom_mid',
                         width=None,
                         icon='',
                         modal=False,
                         exit=False):
        '''Method to show a Information Bubble

        .. parameters::
            text: Message to be displayed
            pos: position for the bubble
            duration: duration the bubble remains on screen. 0 = click to hide
            width: width of the Bubble
            arrow_pos: arrow position for the bubble
        '''
        info_bubble = self.info_bubble
        if not info_bubble:
            info_bubble = self.info_bubble = Factory.InfoBubble()

        win = Window
        if info_bubble.parent:
            win.remove_widget(info_bubble if not info_bubble.modal else
                              info_bubble._modal_view)

        if not arrow_pos:
            info_bubble.show_arrow = False
        else:
            info_bubble.show_arrow = True
            info_bubble.arrow_pos = arrow_pos
        img = info_bubble.ids.img
        if text == 'texture':
            # icon holds a texture not a source image
            # display the texture in full screen
            text = ''
            img.texture = icon
            info_bubble.fs = True
            info_bubble.show_arrow = False
            img.allow_stretch = True
            info_bubble.dim_background = True
            info_bubble.background_image = 'atlas://gui/kivy/theming/light/card'
        else:
            info_bubble.fs = False
            info_bubble.icon = icon
            #if img.texture and img._coreimage:
            #    img.reload()
            img.allow_stretch = False
            info_bubble.dim_background = False
            info_bubble.background_image = 'atlas://data/images/defaulttheme/bubble'
        info_bubble.message = text
        if not pos:
            pos = (win.center[0], win.center[1] - (info_bubble.height / 2))
        info_bubble.show(pos, duration, width, modal=modal, exit=exit)
示例#16
0
 def on_complete(ok, msg):
     if ok:
         self.show_info(_('Payment sent.'))
         if self.send_screen:
             self.send_screen.do_clear()
         if pr:
             self.wallet.invoices.set_paid(pr, tx.txid())
             self.wallet.invoices.save()
             self.update_tab('invoices')
     else:
         self.show_error(msg)
示例#17
0
 def choose_server_dialog(self, popup):
     from .uix.dialogs.choice_dialog import ChoiceDialog
     protocol = 's'
     def cb2(host):
         from qtum_electrum import constants
         pp = servers.get(host, constants.net.DEFAULT_PORTS)
         port = pp.get(protocol, '')
         popup.ids.host.text = host
         popup.ids.port.text = port
     servers = self.network.get_servers()
     ChoiceDialog(_('Choose a server'), sorted(servers), popup.ids.host.text, cb2).open()
示例#18
0
 def __init__(self, obj, action_list):
     Bubble.__init__(self)
     self.obj = obj
     for k, v in action_list:
         l = MenuItem()
         l.text = _(k)
         def func(f=v):
             Clock.schedule_once(lambda dt: self.hide(), 0.1)
             Clock.schedule_once(lambda dt: f(obj), 0.15)
         l.on_release = func
         self.ids.buttons.add_widget(l)
示例#19
0
 def choose_blockchain_dialog(self, dt):
     from .uix.dialogs.choice_dialog import ChoiceDialog
     chains = self.network.get_blockchains()
     def cb(name):
         for index, b in self.network.blockchains.items():
             if name == self.network.get_blockchain_name(b):
                 self.network.follow_chain(index)
                 #self.block
     names = [self.network.blockchains[b].get_name() for b in chains]
     if len(names) >1:
         ChoiceDialog(_('Choose your chain'), names, '', cb).open()
示例#20
0
    def update_status(self, *dt):
        self.num_blocks = self.network.get_local_height()
        if not self.wallet:
            self.status = _("No Wallet")
            return
        if self.network is None or not self.network.is_running():
            status = _("Offline")
        elif self.network.is_connected():
            server_height = self.network.get_server_height()
            server_lag = self.network.get_local_height() - server_height
            if not self.wallet.up_to_date or server_height == 0:
                status = _("Synchronizing...")
            elif server_lag > 1:
                status = _("Server lagging (%d blocks)"%server_lag)
            else:
                c, u, x = self.wallet.get_balance()
                text = self.format_amount(c+x+u)
                status = str(text.strip() + ' ' + self.base_unit)
        else:
            status = _("Disconnected")

        n = self.wallet.basename()
        self.status = '[size=15dp]%s[/size]\n%s' %(n, status)
示例#21
0
 def get_fee_text(self, value):
     if self.ids.dynfees.active:
         tooltip = fee_levels[value]
         if self.config.has_fee_estimates():
             dynfee = self.config.dynfee(value)
             tooltip += '\n' + (
                 self.app.format_amount_and_units(dynfee)) + '/kB'
     else:
         fee_rate = self.config.static_fee(value)
         tooltip = self.app.format_amount_and_units(fee_rate) + '/kB'
         if self.config.has_fee_estimates():
             i = self.config.reverse_dynfee(fee_rate)
             tooltip += '\n' + (_('low fee')
                                if i < 0 else 'Within %d blocks' % i)
     return tooltip
示例#22
0
    def __init__(self, **kwargs):
        # initialize variables
        self._clipboard = Clipboard
        self.info_bubble = None
        self.nfcscanner = None
        self.tabs = None
        self.is_exit = False
        self.wallet = None

        App.__init__(self)  #, **kwargs)

        title = _('Qtum Electrum App')
        self.electrum_config = config = kwargs.get('config', None)
        self.language = config.get('language', 'en')
        self.network = network = kwargs.get('network', None)
        if self.network:
            self.num_blocks = self.network.get_local_height()
            self.num_nodes = len(self.network.get_interfaces())
            host, port, protocol, proxy_config, auto_connect = self.network.get_parameters(
            )
            self.server_host = host
            self.server_port = port
            self.auto_connect = auto_connect
            self.proxy_config = proxy_config if proxy_config else {}

        self.plugins = kwargs.get('plugins', [])
        self.gui_object = kwargs.get('gui_object', None)
        self.daemon = self.gui_object.daemon
        self.fx = self.daemon.fx

        self.use_rbf = config.get('use_rbf', False)
        self.use_change = config.get('use_change', True)
        self.use_unconfirmed = not config.get('confirmed_only', False)

        # create triggers so as to minimize updation a max of 2 times a sec
        self._trigger_update_wallet = Clock.create_trigger(
            self.update_wallet, .5)
        self._trigger_update_status = Clock.create_trigger(
            self.update_status, .5)
        self._trigger_update_history = Clock.create_trigger(
            self.update_history, .5)
        self._trigger_update_interfaces = Clock.create_trigger(
            self.update_interfaces, .5)
        # cached dialogs
        self._settings_dialog = None
        self._password_dialog = None
示例#23
0
 def on_pr(self, pr):
     if pr.verify(self.wallet.contacts):
         key = self.wallet.invoices.add(pr)
         if self.invoices_screen:
             self.invoices_screen.update()
         status = self.wallet.invoices.get_status(key)
         if status == PR_PAID:
             self.show_error("invoice already paid")
             self.send_screen.do_clear()
         else:
             if pr.has_expired():
                 self.show_error(_('Payment request has expired'))
             else:
                 self.switch_to('send')
                 self.send_screen.set_request(pr)
     else:
         self.show_error("invoice error:" + pr.error)
         self.send_screen.do_clear()
示例#24
0
class InfoBubble(Factory.Bubble):
    '''Bubble to be used to display short Help Information'''

    message = StringProperty(_('Nothing set !'))
    '''Message to be displayed; defaults to "nothing set"'''

    icon = StringProperty('')
    ''' Icon to be displayed along with the message defaults to ''

    :attr:`icon` is a  `StringProperty` defaults to `''`
    '''

    fs = BooleanProperty(False)
    ''' Show Bubble in half screen mode

    :attr:`fs` is a `BooleanProperty` defaults to `False`
    '''

    modal = BooleanProperty(False)
    ''' Allow bubble to be hidden on touch.

    :attr:`modal` is a `BooleanProperty` defauult to `False`.
    '''

    exit = BooleanProperty(False)
    '''Indicates whether to exit app after bubble is closed.

    :attr:`exit` is a `BooleanProperty` defaults to False.
    '''

    dim_background = BooleanProperty(False)
    ''' Indicates Whether to draw a background on the windows behind the bubble.

    :attr:`dim` is a `BooleanProperty` defaults to `False`.
    '''

    def on_touch_down(self, touch):
        if self.modal:
            return True
        self.hide()
        if self.collide_point(*touch.pos):
            return True

    def show(self, pos, duration, width=None, modal=False, exit=False):
        '''Animate the bubble into position'''
        self.modal, self.exit = modal, exit
        if width:
            self.width = width
        if self.modal:
            from kivy.uix.modalview import ModalView
            self._modal_view = m = ModalView(background_color=[.5, .5, .5, .2])
            Window.add_widget(m)
            m.add_widget(self)
        else:
            Window.add_widget(self)

        # wait for the bubble to adjust it's size according to text then animate
        Clock.schedule_once(lambda dt: self._show(pos, duration))

    def _show(self, pos, duration):

        def on_stop(*l):
            if duration:
                Clock.schedule_once(self.hide, duration + .5)

        self.opacity = 0
        arrow_pos = self.arrow_pos
        if arrow_pos[0] in ('l', 'r'):
            pos = pos[0], pos[1] - (self.height/2)
        else:
            pos = pos[0] - (self.width/2), pos[1]

        self.limit_to = Window

        anim = Factory.Animation(opacity=1, pos=pos, d=.32)
        anim.bind(on_complete=on_stop)
        anim.cancel_all(self)
        anim.start(self)


    def hide(self, now=False):
        ''' Auto fade out the Bubble
        '''
        def on_stop(*l):
            if self.modal:
                m = self._modal_view
                m.remove_widget(self)
                Window.remove_widget(m)
            Window.remove_widget(self)
            if self.exit:
                App.get_running_app().stop()
                import sys
                sys.exit()
            else:
                App.get_running_app().is_exit = False

        if now:
            return on_stop()

        anim = Factory.Animation(opacity=0, d=.25)
        anim.bind(on_complete=on_stop)
        anim.cancel_all(self)
        anim.start(self)
示例#25
0
 def __init__(self, msg, callback):
     Factory.Popup.__init__(self)
     self.title = _('Question')
     self.message = msg
     self.callback = callback
示例#26
0
 def _change_password2(self, cb, old_password, new_password):
     self.password_dialog(_('Confirm new PIN'), self._change_password3, (cb, old_password, new_password))
示例#27
0
 def add_currencies(self):
     currencies = [_('None')] + self.fx.get_currencies(True)
     my_ccy = self.fx.get_currency() if self.fx.is_enabled() else _('None')
     self.ids.ccy.values = currencies
     self.ids.ccy.text = my_ccy
示例#28
0
 def show_seed(self, label):
     self.protected(_("Enter your PIN code in order to decrypt your seed"), self._show_seed, (label,))
示例#29
0
 def _delete_wallet(self, b):
     if b:
         basename = os.path.basename(self.wallet.storage.path)
         self.protected(_("Enter your PIN code to confirm deletion of %s") % basename, self.__delete_wallet, ())
示例#30
0
 def delete_wallet(self):
     from .uix.dialogs.question import Question
     basename = os.path.basename(self.wallet.storage.path)
     d = Question(_('Delete wallet?') + '\n' + basename, self._delete_wallet)
     d.open()