def notify_transactions(self, *dt): ''' ''' if not self.network or not self.network.is_connected(): return # temporarily disabled for merge return iface = self.network ptfn = iface.pending_transactions_for_notifications if len(ptfn) > 0: # Combine the transactions if there are more then three tx_amount = len(ptfn) if(tx_amount >= 3): total_amount = 0 for tx in ptfn: is_relevant, is_mine, v, fee = self.wallet.get_tx_value(tx) if(v > 0): total_amount += v self.notify(_("{txs}s new transactions received. Total amount" "received in the new transactions {amount}s" "{unit}s").format(txs=tx_amount, amount=self.format_amount(total_amount), unit=self.base_unit())) iface.pending_transactions_for_notifications = [] else: for tx in iface.pending_transactions_for_notifications: if tx: iface.pending_transactions_for_notifications.remove(tx) is_relevant, is_mine, v, fee = self.wallet.get_tx_value(tx) if(v > 0): self.notify( _("{txs} new transaction received. {amount} {unit}"). format(txs=tx_amount, amount=self.format_amount(v), unit=self.base_unit))
def __init__(self, address, parent): self.address = address self.parent = parent self.config = parent.config self.wallet = parent.wallet self.app = parent.app self.saved = True QDialog.__init__(self) self.setMinimumWidth(700) self.setWindowTitle(_("Address")) self.setModal(1) vbox = QVBoxLayout() self.setLayout(vbox) vbox.addWidget(QLabel(_("Address:"))) self.addr_e = ButtonsLineEdit(self.address) self.addr_e.addCopyButton(self.app) self.addr_e.addButton(":icons/qrcode.png", self.show_qr, _("Show QR Code")) self.addr_e.setReadOnly(True) vbox.addWidget(self.addr_e) vbox.addWidget(QLabel(_("History"))) self.hw = HistoryWidget(self.parent) self.hw.get_domain = self.get_domain vbox.addWidget(self.hw) vbox.addStretch(1) vbox.addLayout(Buttons(CloseButton(self))) self.format_amount = self.parent.format_amount self.hw.update()
def network_dialog(self): grid = QGridLayout() grid.setSpacing(5) label = QLabel(_("Electrum communicates with remote servers to get information about your transactions and addresses. The servers all fulfil the same purpose only differing in hardware. In most cases you simply want to let Electrum pick one at random if you have a preference though feel free to select a server manually.") + "\n\n" \ + _("How do you want to connect to a server:")+" ") label.setWordWrap(True) grid.addWidget(label, 0, 0) gb = QGroupBox() b1 = QRadioButton(gb) b1.setText(_("Auto connect")) b1.setChecked(True) b2 = QRadioButton(gb) b2.setText(_("Select server manually")) grid.addWidget(b1,1,0) grid.addWidget(b2,2,0) vbox = QVBoxLayout() vbox.addLayout(grid) vbox.addStretch(1) vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _('Next')))) self.set_layout(vbox) if not self.exec_(): return if b2.isChecked(): return NetworkDialog(self.network, self.config, None).do_exec() else: self.config.set_key('auto_connect', True, True) return
def network_dialog(self): grid = QGridLayout() grid.setSpacing(5) label = QLabel(_("Electrum communicates with remote servers to get information about your transactions and addresses. The servers all fulfil the same purpose only differing in hardware. In most cases you simply want to let Electrum pick one at random if you have a preference though feel free to select a server manually.") + "\n\n" \ + _("How do you want to connect to a server:")+" ") label.setWordWrap(True) grid.addWidget(label, 0, 0) gb = QGroupBox() b1 = QRadioButton(gb) b1.setText(_("Auto connect")) b1.setChecked(True) b2 = QRadioButton(gb) b2.setText(_("Select server manually")) grid.addWidget(b1, 1, 0) grid.addWidget(b2, 2, 0) vbox = QVBoxLayout() vbox.addLayout(grid) vbox.addStretch(1) vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _('Next')))) self.set_layout(vbox) if not self.exec_(): return if b2.isChecked(): return NetworkDialog(self.network, self.config, None).do_exec() else: self.config.set_key('auto_connect', True, True) return
def multi_mpk_dialog(self, xpub_hot, n): vbox = QVBoxLayout() scroll = QScrollArea() scroll.setEnabled(True) scroll.setWidgetResizable(True) vbox.addWidget(scroll) w = QWidget() scroll.setWidget(w) innerVbox = QVBoxLayout() w.setLayout(innerVbox) vbox0 = seed_dialog.show_seed_box(MSG_SHOW_MPK, xpub_hot, 'hot') innerVbox.addLayout(vbox0) entries = [] for i in range(n): msg = _("Please enter the master public key of cosigner" ) + ' %d' % (i + 1) vbox2, seed_e2 = seed_dialog.enter_seed_box(msg, self, 'cold') innerVbox.addLayout(vbox2) entries.append(seed_e2) vbox.addStretch(1) button = OkButton(self, _('Next')) vbox.addLayout(Buttons(CancelButton(self), button)) button.setEnabled(False) f = lambda: button.setEnabled( map(lambda e: Wallet.is_xpub(self.get_seed_text(e)), entries) == [True] * len(entries)) for e in entries: e.textChanged.connect(f) self.set_layout(vbox) if not self.exec_(): return return map(lambda e: self.get_seed_text(e), entries)
def value_str(self, satoshis, rate): if satoshis is None: # Can happen with incomplete history return _("Unknown") if rate: value = Decimal(satoshis) / COIN * Decimal(rate) return "%s" % (self.ccy_amount_str(value, True)) return _("No data")
def add_io(self, vbox): if self.tx.locktime > 0: vbox.addWidget(QLabel("LockTime: %d\n" % self.tx.locktime)) vbox.addWidget(QLabel(_("Inputs") + ' (%d)' % len(self.tx.inputs))) ext = QTextCharFormat() rec = QTextCharFormat() rec.setBackground(QBrush(QColor("lightgreen"))) rec.setToolTip(_("Wallet receive address")) chg = QTextCharFormat() chg.setBackground(QBrush(QColor("yellow"))) chg.setToolTip(_("Wallet change address")) def text_format(addr): if self.wallet.is_mine(addr): return chg if self.wallet.is_change(addr) else rec return ext i_text = QTextEdit() i_text.setFont(QFont(MONOSPACE_FONT)) i_text.setReadOnly(True) i_text.setMaximumHeight(100) cursor = i_text.textCursor() for x in self.tx.inputs: if x.get('is_coinbase'): cursor.insertText('coinbase') else: prevout_hash = x.get('prevout_hash') prevout_n = x.get('prevout_n') cursor.insertText(prevout_hash[0:8] + '...', ext) cursor.insertText(prevout_hash[-8:] + ":%-4d " % prevout_n, ext) addr = x.get('address') if addr == "(pubkey)": _addr = self.wallet.find_pay_to_pubkey_address( prevout_hash, prevout_n) if _addr: addr = _addr if addr is None: addr = _('unknown') cursor.insertText(addr, text_format(addr)) cursor.insertBlock() vbox.addWidget(i_text) vbox.addWidget(QLabel(_("Outputs") + ' (%d)' % len(self.tx.outputs))) o_text = QTextEdit() o_text.setFont(QFont(MONOSPACE_FONT)) o_text.setReadOnly(True) o_text.setMaximumHeight(100) cursor = o_text.textCursor() for addr, v in self.tx.get_outputs(): cursor.insertText(addr, text_format(addr)) if v is not None: cursor.insertText('\t', ext) cursor.insertText( self.parent.format_amount(v, whitespaces=True), ext) cursor.insertBlock() vbox.addWidget(o_text)
def multi_mpk_dialog(self, xpub_hot, n): vbox = QVBoxLayout() scroll = QScrollArea() scroll.setEnabled(True) scroll.setWidgetResizable(True) vbox.addWidget(scroll) w = QWidget() scroll.setWidget(w) innerVbox = QVBoxLayout() w.setLayout(innerVbox) vbox0 = seed_dialog.show_seed_box(MSG_SHOW_MPK, xpub_hot, 'hot') innerVbox.addLayout(vbox0) entries = [] for i in range(n): msg = _("Please enter the master public key of cosigner") + ' %d'%(i+1) vbox2, seed_e2 = seed_dialog.enter_seed_box(msg, self, 'cold') innerVbox.addLayout(vbox2) entries.append(seed_e2) vbox.addStretch(1) button = OkButton(self, _('Next')) vbox.addLayout(Buttons(CancelButton(self), button)) button.setEnabled(False) f = lambda: button.setEnabled( map(lambda e: Wallet.is_xpub(self.get_seed_text(e)), entries) == [True]*len(entries)) for e in entries: e.textChanged.connect(f) self.set_layout(vbox) if not self.exec_(): return return map(lambda e: self.get_seed_text(e), entries)
def on_verify_restore_ok(self, wallet, _dlg, btn, restore=False): if btn in (_dlg.ids.back, _dlg.ids.but_close) : _dlg.close() Factory.CreateRestoreDialog( on_release=self.on_creatrestore_complete).open() return seed = self.get_seed_text(_dlg.ids.text_input_seed) if not seed: return app.show_error(_("No seed!"), duration=.5) _dlg.close() if Wallet.is_seed(seed): return self.password_dialog(wallet=wallet, mode='restore', seed=seed) elif Wallet.is_mpk(seed): wallet = Wallet.from_mpk(seed, self.storage) elif Wallet.is_address(seed): wallet = Wallet.from_address(seed, self.storage) elif Wallet.is_private_key(seed): wallet = Wallet.from_private_key(seed, self.storage) else: return app.show_error(_('Not a valid seed. App will now exit'), exit=True, modal=True, duration=.5) return
def show_seed(self, wallet=None, instance=None, password=None, wallet_name=None, mode='create', seed=''): if instance and (not wallet or not wallet.seed): return app.show_error(_('No seed')) if not seed: try: seed = self.wallet.get_seed(password) except Exception: return app.show_error(_('Incorrect Password')) brainwallet = seed msg2 = _("[color=#414141]"+\ "[b]PLEASE WRITE DOWN YOUR SEED PASS[/b][/color]"+\ "[size=9]\n\n[/size]" +\ "[color=#929292]If you ever forget your pincode, your seed" +\ " phrase will be the [color=#EB984E]"+\ "[b]only way to recover[/b][/color] your wallet. Your " +\ " [color=#EB984E][b]gamecreditss[/b][/color] will otherwise be" +\ " [color=#EB984E][b]lost forever![/b][/color]") if wallet.imported_keys: msg2 += "[b][color=#ff0000ff]" + _("WARNING") + "[/color]:[/b] " +\ _("Your wallet contains imported keys. These keys cannot" +\ " be recovered from seed.") def on_ok_press(_dlg, _btn): _dlg.close() mode = _dlg.mode if _btn != _dlg.ids.confirm: if not instance: self.password_dialog(wallet, mode=mode) return # confirm if instance is None: # in initial phase create mode # save seed with password def create(password): wallet.add_seed(seed, password) wallet.create_master_keys(password) wallet.create_main_account(password) wallet.synchronize() # generate first addresses offline self.waiting_dialog(partial(create, password), on_complete=partial(self.load_network, wallet, mode=mode)) from electrum_gmc_gui.kivy.uix.dialogs.create_restore import InitSeedDialog InitSeedDialog(message=msg2, seed_msg=brainwallet, on_release=on_ok_press, mode=mode).open()
def on_verify_restore_ok(self, wallet, _dlg, btn, restore=False): if btn in (_dlg.ids.back, _dlg.ids.but_close): _dlg.close() Factory.CreateRestoreDialog( on_release=self.on_creatrestore_complete).open() return seed = self.get_seed_text(_dlg.ids.text_input_seed) if not seed: return app.show_error(_("No seed!"), duration=.5) _dlg.close() if Wallet.is_seed(seed): return self.password_dialog(wallet=wallet, mode='restore', seed=seed) elif Wallet.is_mpk(seed): wallet = Wallet.from_mpk(seed, self.storage) elif Wallet.is_address(seed): wallet = Wallet.from_address(seed, self.storage) elif Wallet.is_private_key(seed): wallet = Wallet.from_private_key(seed, self.storage) else: return app.show_error(_('Not a valid seed. App will now exit'), exit=True, modal=True, duration=.5) return
def parse_history(self, items): for item in items: tx_hash, conf, value, timestamp, balance = item time_str = _("unknown") if conf > 0: try: time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3] except Exception: time_str = _("error") if conf == -1: time_str = _('unverified') icon = "atlas://gui/kivy/theming/light/close" elif conf == 0: time_str = _('pending') icon = "atlas://gui/kivy/theming/light/unconfirmed" elif conf < 6: time_str = '' # add new to fix error when conf < 0 conf = max(1, conf) icon = "atlas://gui/kivy/theming/light/clock{}".format(conf) else: icon = "atlas://gui/kivy/theming/light/confirmed" if tx_hash: label, is_default_label = self.app.wallet.get_label(tx_hash) else: label = _('Pruned transaction outputs') is_default_label = False quote_currency = 'USD' rate = self.get_history_rate(value, timestamp) quote_text = "..." if rate is None else "{0:.3} {1}".format(rate, quote_currency) yield (conf, icon, time_str, label, value, tx_hash, quote_text)
def load_wallet_file(self, filename): try: storage = WalletStorage(filename) except Exception as e: QMessageBox.information(None, _('Error'), str(e), _('OK')) return if not storage.file_exists: recent = self.config.get('recently_open', []) if filename in recent: recent.remove(filename) self.config.set_key('recently_open', recent) action = 'new' else: try: wallet = Wallet(storage) except BaseException as e: traceback.print_exc(file=sys.stdout) QMessageBox.warning(None, _('Warning'), str(e), _('OK')) return action = wallet.get_action() # run wizard if action is not None: wizard = InstallWizard(self.app, self.config, self.network, storage) wallet = wizard.run(action) # keep current wallet if not wallet: return else: wallet.start_threads(self.network) return wallet
def save(self): name = 'signed_%s.txn' % (self.tx.hash()[0:8]) if self.tx.is_complete() else 'unsigned.txn' fileName = self.parent.getSaveFileName(_("Select where to save your signed transaction"), name, "*.txn") if fileName: with open(fileName, "w+") as f: f.write(json.dumps(self.tx.as_dict(), indent=4) + '\n') self.show_message(_("Transaction saved successfully")) self.saved = True
def verify_seed(self, seed, sid, func=None): r = self.enter_seed_dialog(MSG_VERIFY_SEED, sid, func) if not r: return if prepare_seed(r) != prepare_seed(seed): QMessageBox.warning(None, _('Error'), _('Incorrect seed'), _('OK')) return False else: return True
def add_io(self, vbox): if self.tx.locktime > 0: vbox.addWidget(QLabel("LockTime: %d\n" % self.tx.locktime)) vbox.addWidget(QLabel(_("Inputs") + ' (%d)'%len(self.tx.inputs))) ext = QTextCharFormat() rec = QTextCharFormat() rec.setBackground(QBrush(QColor("lightgreen"))) rec.setToolTip(_("Wallet receive address")) chg = QTextCharFormat() chg.setBackground(QBrush(QColor("yellow"))) chg.setToolTip(_("Wallet change address")) def text_format(addr): if self.wallet.is_mine(addr): return chg if self.wallet.is_change(addr) else rec return ext i_text = QTextEdit() i_text.setFont(QFont(MONOSPACE_FONT)) i_text.setReadOnly(True) i_text.setMaximumHeight(100) cursor = i_text.textCursor() for x in self.tx.inputs: if x.get('is_coinbase'): cursor.insertText('coinbase') else: prevout_hash = x.get('prevout_hash') prevout_n = x.get('prevout_n') cursor.insertText(prevout_hash[0:8] + '...', ext) cursor.insertText(prevout_hash[-8:] + ":%-4d " % prevout_n, ext) addr = x.get('address') if addr == "(pubkey)": _addr = self.wallet.find_pay_to_pubkey_address(prevout_hash, prevout_n) if _addr: addr = _addr if addr is None: addr = _('unknown') cursor.insertText(addr, text_format(addr)) cursor.insertBlock() vbox.addWidget(i_text) vbox.addWidget(QLabel(_("Outputs") + ' (%d)'%len(self.tx.outputs))) o_text = QTextEdit() o_text.setFont(QFont(MONOSPACE_FONT)) o_text.setReadOnly(True) o_text.setMaximumHeight(100) cursor = o_text.textCursor() for addr, v in self.tx.get_outputs(): cursor.insertText(addr, text_format(addr)) if v is not None: cursor.insertText('\t', ext) cursor.insertText(self.parent.format_amount(v, whitespaces = True), ext) cursor.insertBlock() vbox.addWidget(o_text)
def closeEvent(self, event): if (self.prompt_if_unsaved and not self.saved and not self.broadcast and QMessageBox.question( self, _('Warning'), _('This transaction is not saved. Close anyway?'), QMessageBox.Yes | QMessageBox.No) == QMessageBox.No): event.ignore() else: event.accept() dialogs.remove(self)
def give_error(self, message, clear_client=False): print_error(message) if not self.signing: QMessageBox.warning(QDialog(), _('Warning'), _(message), _('OK')) else: self.signing = False if clear_client and self.client is not None: self.client.bad = True self.device_checked = False raise Exception(message)
def export_history_dialog(self, window, hbox): wallet = window.wallet history = wallet.get_history() if len(history) > 0: b = QPushButton(_("Preview plot")) hbox.addWidget(b) b.clicked.connect(lambda: self.do_plot(wallet, history)) else: b = QPushButton(_("No history to plot")) hbox.addWidget(b)
def installwizard_restore(self, wizard, storage): if storage.get('wallet_type') != 'btchip': return wallet = BTChipWallet(storage) try: wallet.create_main_account(None) except BaseException as e: QMessageBox.information(None, _('Error'), str(e), _('OK')) return return wallet
def __init__(self, parent, seed, imported_keys): QDialog.__init__(self, parent) self.setModal(1) self.setMinimumWidth(400) self.setWindowTitle('Electrum' + ' - ' + _('Seed')) vbox = show_seed_box_msg(seed) if imported_keys: vbox.addWidget(QLabel("<b>"+_("WARNING")+":</b> " + _("Your wallet contains imported keys. These keys cannot be recovered from seed.") + "</b><p>")) vbox.addLayout(Buttons(CloseButton(self))) self.setLayout(vbox)
def save(self): name = 'signed_%s.txn' % ( self.tx.hash()[0:8]) if self.tx.is_complete() else 'unsigned.txn' fileName = self.parent.getSaveFileName( _("Select where to save your signed transaction"), name, "*.txn") if fileName: with open(fileName, "w+") as f: f.write(json.dumps(self.tx.as_dict(), indent=4) + '\n') self.show_message(_("Transaction saved successfully")) self.saved = True
def give_error(self, message, clear_client = False): print_error(message) if not self.signing: QMessageBox.warning(QDialog(), _('Warning'), _(message), _('OK')) else: self.signing = False if clear_client and self.client is not None: self.client.bad = True self.device_checked = False raise Exception(message)
def build_tray_menu(self): # Avoid immediate GC of old menu when window closed via its action self.old_menu = self.tray.contextMenu() m = QMenu() for window in self.windows: submenu = m.addMenu(window.wallet.basename()) submenu.addAction(_("Show/Hide"), window.show_or_hide) submenu.addAction(_("Close"), window.close) m.addAction(_("Dark/Light"), self.toggle_tray_icon) m.addSeparator() m.addAction(_("Exit Electrum-GMC"), self.close) self.tray.setContextMenu(m)
def close(self): self.d.accept() if self.error: QMessageBox.warning(self.parent, _('Error'), self.error, _('OK')) else: if self.on_success: if type(self.result) is not tuple: self.result = (self.result,) self.on_success(*self.result) if self.on_complete: self.on_complete()
def load_wallet(self, wallet, window): self.wallet = wallet self.wallet.plugin = self if self.handler is None: self.handler = BTChipQTHandler(window) if self.btchip_is_connected(): if not self.wallet.check_proper_device(): QMessageBox.information(window, _('Error'), _("This wallet does not match your Ledger device"), _('OK')) self.wallet.force_watching_only = True else: QMessageBox.information(window, _('Error'), _("Ledger device not detected.\nContinuing in watching-only mode."), _('OK')) self.wallet.force_watching_only = True
def on_complete(*l): if not self.network: app.show_info( _("This wallet was restored offline. It may contain more" " addresses than displayed."), duration=.5) return self.dispatch('on_wizard_complete', wallet) if wallet.is_found(): app.show_info(_("Recovery successful"), duration=.5) else: app.show_info(_("No transactions found for this seed"), duration=.5) return self.dispatch('on_wizard_complete', wallet)
def settings_dialog(self): d = QDialog() d.setWindowTitle("Settings") layout = QGridLayout(d) layout.addWidget(QLabel(_('Exchange rate API: ')), 0, 0) layout.addWidget(QLabel(_('Currency: ')), 1, 0) layout.addWidget(QLabel(_('History Rates: ')), 2, 0) # Currency list self.ccy_combo = QComboBox() self.ccy_combo.currentIndexChanged.connect(self.on_ccy_combo_change) self.populate_ccy_combo() def on_change_ex(idx): exchange = str(combo_ex.currentText()) if exchange != self.exchange.name(): self.set_exchange(exchange) self.hist_checkbox_update() def on_change_hist(checked): if checked: self.config.set_key('history_rates', 'checked') self.get_historical_rates() else: self.config.set_key('history_rates', 'unchecked') self.refresh_headers() def ok_clicked(): self.timeout = 0 self.ccy_combo = None d.accept() combo_ex = QComboBox() combo_ex.addItems(sorted(self.exchanges.keys())) combo_ex.setCurrentIndex(combo_ex.findText(self.config_exchange())) combo_ex.currentIndexChanged.connect(on_change_ex) self.hist_checkbox = QCheckBox() self.hist_checkbox.stateChanged.connect(on_change_hist) self.hist_checkbox_update() ok_button = QPushButton(_("OK")) ok_button.clicked.connect(lambda: ok_clicked()) layout.addWidget(self.ccy_combo,1,1) layout.addWidget(combo_ex,0,1) layout.addWidget(self.hist_checkbox,2,1) layout.addWidget(ok_button,3,1) return d.exec_()
def dropdown_selected(self, value): app = App.get_running_app() try: labels = self.labels except AttributeError: return address = labels.get(self.address, self.address[1:]) if value.startswith(_('Copy')): app.copy(address) elif value.startswith(_('Send')): app.send_payment(address) self.dismiss()
def on_complete(*l): if not self.network: app.show_info(_( "This wallet was restored offline. It may contain more" " addresses than displayed."), duration=.5) return self.dispatch('on_wizard_complete', wallet) if wallet.is_found(): app.show_info(_("Recovery successful"), duration=.5) else: app.show_info(_("No transactions found for this seed"), duration=.5) return self.dispatch('on_wizard_complete', wallet)
def question(self, msg, yes_label=_('OK'), no_label=_('Cancel'), icon=None): vbox = QVBoxLayout() self.set_layout(vbox) if icon: logo = QLabel() logo.setPixmap(icon) vbox.addWidget(logo) label = QLabel(msg) label.setWordWrap(True) vbox.addWidget(label) vbox.addStretch(1) vbox.addLayout(Buttons(CancelButton(self, no_label), OkButton(self, yes_label))) if not self.exec_(): return None return True
def __init__(self, data, parent=None, title="", show_text=False): QDialog.__init__(self, parent) d = self d.setWindowTitle(title) vbox = QVBoxLayout() qrw = QRCodeWidget(data) vbox.addWidget(qrw, 1) if show_text: text = QTextEdit() text.setText(data) text.setReadOnly(True) vbox.addWidget(text) hbox = QHBoxLayout() hbox.addStretch(1) config = electrum_gmc.get_config() if config: filename = os.path.join(config.path, "qrcode.bmp") def print_qr(): bmp.save_qrcode(qrw.qr, filename) QMessageBox.information( None, _('Message'), _("QR code saved to file") + " " + filename, _('OK')) def copy_to_clipboard(): bmp.save_qrcode(qrw.qr, filename) QApplication.clipboard().setImage(QImage(filename)) QMessageBox.information(None, _('Message'), _("QR code saved to clipboard"), _('OK')) b = QPushButton(_("Copy")) hbox.addWidget(b) b.clicked.connect(copy_to_clipboard) b = QPushButton(_("Save")) hbox.addWidget(b) b.clicked.connect(print_qr) b = QPushButton(_("Close")) hbox.addWidget(b) b.clicked.connect(d.accept) b.setDefault(True) vbox.addLayout(hbox) d.setLayout(vbox)
def choice(self, title, msg, choices): vbox = QVBoxLayout() self.set_layout(vbox) vbox.addWidget(QLabel(title)) gb2 = QGroupBox(msg) vbox.addWidget(gb2) vbox2 = QVBoxLayout() gb2.setLayout(vbox2) group2 = QButtonGroup() for i,c in enumerate(choices): button = QRadioButton(gb2) button.setText(c[1]) vbox2.addWidget(button) group2.addButton(button) group2.setId(button, i) if i==0: button.setChecked(True) vbox.addStretch(1) vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _('Next')))) if not self.exec_(): return wallet_type = choices[group2.checkedId()][0] return wallet_type
def __init__(self, **kwargs): # initialize variables self._clipboard = None self.info_bubble = None self.qrscanner = None self.nfcscanner = None self.tabs = None super(ElectrumWindow, self).__init__(**kwargs) title = _('Electrum-GMC App') self.electrum_config = config = kwargs.get('config', None) self.network = network = kwargs.get('network', None) self.plugins = kwargs.get('plugins', []) self.gui_object = kwargs.get('gui_object', None) #self.config = self.gui_object.config self.contacts = Contacts(self.electrum_config) self.bind(url=self.set_url) # were we sent a url? url = self.electrum_config.get('url', None) if url: self.set_url(url) # 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_notify_transactions = \ Clock.create_trigger(self.notify_transactions, 5)
def __init__(self, win): QWidget.__init__(self) self.win = win self.setWindowTitle('Electrum - ' + _('Payment Request')) self.setMinimumSize(800, 250) self.address = '' self.label = '' self.amount = 0 self.setFocusPolicy(QtCore.Qt.NoFocus) main_box = QHBoxLayout() self.qrw = QRCodeWidget() main_box.addWidget(self.qrw, 1) vbox = QVBoxLayout() main_box.addLayout(vbox) self.address_label = QLabel("") #self.address_label.setFont(QFont(MONOSPACE_FONT)) vbox.addWidget(self.address_label) self.label_label = QLabel("") vbox.addWidget(self.label_label) self.amount_label = QLabel("") vbox.addWidget(self.amount_label) vbox.addStretch(1) self.setLayout(main_box)
def waiting_dialog(self, task, msg= _("Electrum is generating your addresses," " please wait."), on_complete=None): '''Perform a blocking task in the background by running the passed method in a thread. ''' def target(): # run your threaded function try: task() except Exception as err: Clock.schedule_once(lambda dt: app.show_error(str(err))) # on completion hide message Clock.schedule_once(lambda dt: app.info_bubble.hide(now=True), -1) # call completion routine if on_complete: Clock.schedule_once(lambda dt: on_complete()) app.show_info_bubble( text=msg, icon='atlas://gui/kivy/theming/light/important', pos=Window.center, width='200sp', arrow_pos=None, modal=True) t = threading.Thread(target = target) t.start()
def password_dialog(self, pw, grid, pos): vkb_button = QPushButton(_("+")) vkb_button.setFixedWidth(20) vkb_button.clicked.connect(lambda: self.toggle_vkb(grid, pw)) grid.addWidget(vkb_button, pos, 2) self.kb_pos = 2 self.vkb = None
def waiting_dialog(self, task, msg=_("Electrum is generating your addresses," " please wait."), on_complete=None): '''Perform a blocking task in the background by running the passed method in a thread. ''' def target(): # run your threaded function try: task() except Exception as err: Clock.schedule_once(lambda dt: app.show_error(str(err))) # on completion hide message Clock.schedule_once(lambda dt: app.info_bubble.hide(now=True), -1) # call completion routine if on_complete: Clock.schedule_once(lambda dt: on_complete()) app.show_info_bubble(text=msg, icon='atlas://gui/kivy/theming/light/important', pos=Window.center, width='200sp', arrow_pos=None, modal=True) t = threading.Thread(target=target) t.start()
def choice(self, title, msg, choices): vbox = QVBoxLayout() self.set_layout(vbox) vbox.addWidget(QLabel(title)) gb2 = QGroupBox(msg) vbox.addWidget(gb2) vbox2 = QVBoxLayout() gb2.setLayout(vbox2) group2 = QButtonGroup() for i, c in enumerate(choices): button = QRadioButton(gb2) button.setText(c[1]) vbox2.addWidget(button) group2.addButton(button) group2.setId(button, i) if i == 0: button.setChecked(True) vbox.addStretch(1) vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _('Next')))) if not self.exec_(): return wallet_type = choices[group2.checkedId()][0] return wallet_type
def multi_seed_dialog(self, n): vbox = QVBoxLayout() scroll = QScrollArea() scroll.setEnabled(True) scroll.setWidgetResizable(True) vbox.addWidget(scroll) w = QWidget() scroll.setWidget(w) innerVbox = QVBoxLayout() w.setLayout(innerVbox) vbox1, seed_e1 = seed_dialog.enter_seed_box(MSG_ENTER_SEED_OR_MPK, self, 'hot') innerVbox.addLayout(vbox1) entries = [seed_e1] for i in range(n): vbox2, seed_e2 = seed_dialog.enter_seed_box(MSG_ENTER_SEED_OR_MPK, self, 'cold') innerVbox.addLayout(vbox2) entries.append(seed_e2) vbox.addStretch(1) button = OkButton(self, _('Next')) vbox.addLayout(Buttons(CancelButton(self), button)) button.setEnabled(False) f = lambda: button.setEnabled( map(lambda e: self.is_any(self.get_seed_text(e)), entries) == [True]*len(entries)) for e in entries: e.textChanged.connect(f) self.set_layout(vbox) if not self.exec_(): return return map(lambda e: self.get_seed_text(e), entries)
def multi_seed_dialog(self, n): vbox = QVBoxLayout() scroll = QScrollArea() scroll.setEnabled(True) scroll.setWidgetResizable(True) vbox.addWidget(scroll) w = QWidget() scroll.setWidget(w) innerVbox = QVBoxLayout() w.setLayout(innerVbox) vbox1, seed_e1 = seed_dialog.enter_seed_box(MSG_ENTER_SEED_OR_MPK, self, 'hot') innerVbox.addLayout(vbox1) entries = [seed_e1] for i in range(n): vbox2, seed_e2 = seed_dialog.enter_seed_box( MSG_ENTER_SEED_OR_MPK, self, 'cold') innerVbox.addLayout(vbox2) entries.append(seed_e2) vbox.addStretch(1) button = OkButton(self, _('Next')) vbox.addLayout(Buttons(CancelButton(self), button)) button.setEnabled(False) f = lambda: button.setEnabled( map(lambda e: self.is_any(self.get_seed_text(e)), entries) == [True] * len(entries)) for e in entries: e.textChanged.connect(f) self.set_layout(vbox) if not self.exec_(): return return map(lambda e: self.get_seed_text(e), entries)
def __init__(self, win): QWidget.__init__(self) self.win = win self.setWindowTitle('Electrum - '+_('Payment Request')) self.setMinimumSize(800, 250) self.address = '' self.label = '' self.amount = 0 self.setFocusPolicy(QtCore.Qt.NoFocus) main_box = QHBoxLayout() self.qrw = QRCodeWidget() main_box.addWidget(self.qrw, 1) vbox = QVBoxLayout() main_box.addLayout(vbox) self.address_label = QLabel("") #self.address_label.setFont(QFont(MONOSPACE_FONT)) vbox.addWidget(self.address_label) self.label_label = QLabel("") vbox.addWidget(self.label_label) self.amount_label = QLabel("") vbox.addWidget(self.amount_label) vbox.addStretch(1) self.setLayout(main_box)
def settings_dialog(self, window): print "window:", window d = QDialog(window) vbox = QVBoxLayout(d) layout = QGridLayout() vbox.addLayout(layout) layout.addWidget(QLabel("Label sync options: "), 2, 0) self.upload = ThreadedButton("Force upload", partial(self.push_thread, window), self.done_processing) layout.addWidget(self.upload, 2, 1) self.download = ThreadedButton("Force download", partial(self.pull_thread, window, True), self.done_processing) layout.addWidget(self.download, 2, 2) self.accept = OkButton(d, _("Done")) vbox.addLayout(Buttons(CancelButton(d), self.accept)) if d.exec_(): return True else: return False
def create_menu(self, position): self.selectedIndexes() item = self.currentItem() if not item: return tx_hash = str(item.data(0, Qt.UserRole).toString()) if not tx_hash: return tx_URL = block_explorer_URL(self.config, 'tx', tx_hash) if not tx_URL: return menu = QMenu() menu.addAction(_("Copy ID to Clipboard"), lambda: self.parent.app.clipboard().setText(tx_hash)) menu.addAction(_("Details"), lambda: self.parent.show_transaction(self.wallet.transactions.get(tx_hash))) menu.addAction(_("Edit description"), lambda: self.editItem(item, self.editable_columns[0])) menu.addAction(_("View on block explorer"), lambda: webbrowser.open(tx_URL)) menu.exec_(self.viewport().mapToGlobal(position))
def load_wallet(self, wallet, window): self.print_error("load_wallet") self.wallet = wallet self.wallet.plugin = self self.keepkey_button = StatusBarButton( QIcon(":icons/keepkey.png"), _("KeepKey"), partial(self.settings_dialog, window)) if type(window) is ElectrumWindow: window.statusBar().addPermanentWidget(self.keepkey_button) if self.handler is None: self.handler = KeepKeyQtHandler(window) try: self.get_client().ping('t') except BaseException as e: QMessageBox.information( window, _('Error'), _("KeepKey device not detected.\nContinuing in watching-only mode." + '\n\nReason:\n' + str(e)), _('OK')) self.wallet.force_watching_only = True return if self.wallet.addresses() and not self.wallet.check_proper_device(): QMessageBox.information( window, _('Error'), _("This wallet does not match your KeepKey device"), _('OK')) self.wallet.force_watching_only = True
def update_status(self, *dt): if not self.wallet: return unconfirmed = '' quote_text = '' if self.network is None or not self.network.is_running(): text = _("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: self.status = _("Synchronizing...") elif server_lag > 1: self.status = _("Server lagging (%d blocks)" % server_lag) else: c, u, x = self.wallet.get_account_balance(self.current_account) text = self.format_amount(c) if u: unconfirmed = " [%s unconfirmed]" % (self.format_amount( u, True).strip()) if x: unmatured = " [%s unmatured]" % (self.format_amount( x, True).strip()) #quote_text = self.create_quote_text(Decimal(c+u+x)/100000000, mode='symbol') or '' self.status = text.strip() + ' ' + self.base_unit else: self.status = _("Not connected") return print self.root.manager.ids #try: status_card = self.root.main_screen.ids.tabs.ids.\ screen_dashboard.ids.status_card #except AttributeError: # return status_card.quote_text = quote_text.strip() status_card.uncomfirmed = unconfirmed.strip()
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)
def question(self, msg, yes_label=_('OK'), no_label=_('Cancel'), icon=None): vbox = QVBoxLayout() self.set_layout(vbox) if icon: logo = QLabel() logo.setPixmap(icon) vbox.addWidget(logo) label = QLabel(msg) label.setWordWrap(True) vbox.addWidget(label) vbox.addStretch(1) vbox.addLayout( Buttons(CancelButton(self, no_label), OkButton(self, yes_label))) if not self.exec_(): return None return True