def get_card(self, tx_hash, height, conf, timestamp, value, balance): status, status_str = self.app.wallet.get_tx_status( tx_hash, height, conf, timestamp) icon = "atlas://gui/kivy/theming/light/" + TX_ICONS[status] label = self.app.wallet.get_label(tx_hash) if tx_hash else _( 'Pruned transaction outputs') date = timestamp_to_datetime(timestamp) ri = self.cards.get(tx_hash) if ri is None: ri = Factory.HistoryItem() ri.screen = self ri.tx_hash = tx_hash self.cards[tx_hash] = ri ri.icon = icon ri.date = status_str ri.message = label ri.value = value or 0 ri.value_known = value is not None ri.confirmations = conf if self.app.fiat_unit and date: rate = run_hook('history_rate', date) if rate: s = run_hook('value_str', value, rate) ri.quote_text = '' if s is None else s + ' ' + self.app.fiat_unit return ri
def create_window_for_wallet(self, wallet): w = ElectrumWindow(self, wallet) self.windows.append(w) self.build_tray_menu() # FIXME: Remove in favour of the load_wallet hook run_hook('on_new_window', w) return w
def on_start(self): ''' This is the start point of the kivy ui ''' import time Logger.info('Time to on_start: {} <<<<<<<<'.format(time.clock())) win = Window win.bind(size=self.on_size, on_keyboard=self.on_keyboard) win.bind(on_key_down=self.on_key_down) win.softinput_mode = 'below_target' self.on_size(win, win.size) self.init_ui() self.load_wallet_by_name(self.electrum_config.get_wallet_path()) # init plugins run_hook('init_kivy', self) # default tab self.switch_to('history') # bind intent for bitcoin: URI scheme if platform == 'android': from android import activity from jnius import autoclass PythonActivity = autoclass('org.kivy.android.PythonActivity') mactivity = PythonActivity.mActivity self.on_new_intent(mactivity.getIntent()) activity.bind(on_new_intent=self.on_new_intent) # URI passed in config uri = self.electrum_config.get('url') if uri: self.set_URI(uri)
def on_update(self): self.wallet = self.parent.wallet h = self.wallet.get_history(self.get_domain()) item = self.currentItem() current_tx = item.data(0, Qt.UserRole).toString() if item else None self.clear() run_hook('history_tab_update_begin') for h_item in h: tx_hash, height, conf, timestamp, value, balance = h_item status, status_str = self.wallet.get_tx_status(tx_hash, height, conf, timestamp) icon = QIcon(":icons/" + TX_ICONS[status]) v_str = self.parent.format_amount(value, True, whitespaces=True) balance_str = self.parent.format_amount(balance, whitespaces=True) label = self.wallet.get_label(tx_hash) entry = ['', tx_hash, status_str, label, v_str, balance_str] run_hook('history_tab_update', h_item, entry) item = QTreeWidgetItem(entry) item.setIcon(0, icon) for i in range(len(entry)): if i>3: item.setTextAlignment(i, Qt.AlignRight) if i!=2: item.setFont(i, QFont(MONOSPACE_FONT)) if value < 0: item.setForeground(3, QBrush(QColor("#BC1E1E"))) item.setForeground(4, QBrush(QColor("#BC1E1E"))) if tx_hash: item.setData(0, Qt.UserRole, tx_hash) self.insertTopLevelItem(0, item) if current_tx == tx_hash: self.setCurrentItem(item)
def close_window(self, window): self.windows.remove(window) self.build_tray_menu() # save wallet path of last open window if not self.windows: self.config.save_last_wallet(window.wallet) run_hook('on_close_window', window)
def on_start(self): ''' This is the start point of the kivy ui ''' import time Logger.info('Time to on_start: {} <<<<<<<<'.format(time.clock())) win = Window win.bind(size=self.on_size, on_keyboard=self.on_keyboard) win.bind(on_key_down=self.on_key_down) win.softinput_mode = 'below_target' self.on_size(win, win.size) self.init_ui() self.load_wallet_by_name(self.electrum_config.get_wallet_path()) # init plugins run_hook('init_kivy', self) # default tab self.switch_to('history') # bind intent for bitcoin: URI scheme if platform == 'android': from android import activity from jnius import autoclass PythonActivity = autoclass('org.kivy.android.PythonActivity') mactivity = PythonActivity.mActivity self.on_new_intent(mactivity.getIntent()) activity.bind(on_new_intent=self.on_new_intent) # URI passed in config uri = self.electrum_config.get('url') if uri: self.set_URI(uri)
def __init__(self, config, daemon, plugins): set_language(config.get('language')) # Uncomment this call to verify objects are being properly # GC-ed when windows are closed #network.add_jobs([DebugMem([Abstract_Wallet, SPV, Synchronizer, # ElectrumWindow], interval=5)]) self.config = config self.daemon = daemon self.plugins = plugins self.windows = [] self.efilter = OpenFileEventFilter(self.windows) self.app = QApplication(sys.argv) self.app.installEventFilter(self.efilter) self.timer = Timer() # shared objects self.invoices = InvoiceStore(self.config) self.contacts = Contacts(self.config) # init tray self.dark_icon = self.config.get("dark_icon", False) self.tray = QSystemTrayIcon(self.tray_icon(), None) self.tray.setToolTip('Electrum-CESC') self.tray.activated.connect(self.tray_activated) self.build_tray_menu() self.tray.show() self.app.connect(self.app, QtCore.SIGNAL('new_window'), self.start_new_window) run_hook('init_qt', self)
def create_quote_text(self, btc_balance): """Return a string copy of the amount fiat currency the user has in bitcoins.""" from electrum_cesc.plugins import run_hook r = {} run_hook('get_fiat_balance_text', btc_balance, r) return r.get(0,'')
def create_quote_text(self, btc_balance): """Return a string copy of the amount fiat currency the user has in bitcoins.""" from electrum_cesc.plugins import run_hook r = {} run_hook('get_fiat_balance_text', btc_balance, r) return r.get(0, '')
def update(self): desc = self.desc base_unit = self.main_window.base_unit() format_amount = self.main_window.format_amount tx_hash, status, label, can_broadcast, can_rbf, amount, fee, height, conf, timestamp, exp_n = self.wallet.get_tx_info( self.tx) if can_broadcast: self.broadcast_button.show() else: self.broadcast_button.hide() if self.wallet.can_sign(self.tx): self.sign_button.show() else: self.sign_button.hide() self.tx_hash_e.setText(tx_hash or _('Unknown')) if desc is None: self.tx_desc.hide() else: self.tx_desc.setText(_("Description") + ': ' + desc) self.tx_desc.show() self.status_label.setText(_('Status:') + ' ' + status) if timestamp: time_str = datetime.datetime.fromtimestamp(timestamp).isoformat( ' ')[:-3] self.date_label.setText(_("Date: %s") % time_str) self.date_label.show() elif exp_n: text = '%d blocks' % (exp_n) if exp_n > 0 else _( 'unknown (low fee)') self.date_label.setText( _('Expected confirmation time') + ': ' + text) self.date_label.show() else: self.date_label.hide() # if we are not synchronized, we cannot tell if not self.wallet.up_to_date: return if amount is None: amount_str = _("Transaction unrelated to your wallet") elif amount > 0: amount_str = _("Amount received:" ) + ' %s' % format_amount(amount) + ' ' + base_unit else: amount_str = _("Amount sent:" ) + ' %s' % format_amount(-amount) + ' ' + base_unit fee_str = _("Transaction fee") + ': %s' % (format_amount( fee) + ' ' + base_unit if fee is not None else _('unknown')) self.amount_label.setText(amount_str) self.fee_label.setText(fee_str) run_hook('transaction_dialog_update', self)
def create_menu(self, position): from electrum_cesc.wallet import Multisig_Wallet is_multisig = isinstance(self.wallet, Multisig_Wallet) selected = self.selectedItems() multi_select = len(selected) > 1 addrs = [unicode(item.text(0)) for item in selected] if not addrs: return if not multi_select: item = self.itemAt(position) col = self.currentColumn() if not item: return addr = addrs[0] if not is_address(addr): k = str(item.data(0,32).toString()) if k: self.create_account_menu(position, k, item) else: item.setExpanded(not item.isExpanded()) return menu = QMenu() if not multi_select: column_title = self.headerItem().text(col) menu.addAction(_("Copy %s")%column_title, lambda: self.parent.app.clipboard().setText(item.text(col))) if col in self.editable_columns: menu.addAction(_("Edit %s")%column_title, lambda: self.editItem(item, col)) menu.addAction(_("Request payment"), lambda: self.parent.receive_at(addr)) menu.addAction(_('History'), lambda: self.parent.show_address(addr)) menu.addAction(_('Public Keys'), lambda: self.parent.show_public_keys(addr)) if self.wallet.can_export(): menu.addAction(_("Private key"), lambda: self.parent.show_private_key(addr)) if not is_multisig and not self.wallet.is_watching_only(): menu.addAction(_("Sign/verify message"), lambda: self.parent.sign_verify_message(addr)) menu.addAction(_("Encrypt/decrypt message"), lambda: self.parent.encrypt_message(addr)) if self.wallet.is_imported(addr): menu.addAction(_("Remove from wallet"), lambda: self.parent.delete_imported_key(addr)) addr_URL = block_explorer_URL(self.config, 'addr', addr) if addr_URL: menu.addAction(_("View on block explorer"), lambda: webbrowser.open(addr_URL)) if any(not self.wallet.is_frozen(addr) for addr in addrs): menu.addAction(_("Freeze"), lambda: self.parent.set_frozen_state(addrs, True)) if any(self.wallet.is_frozen(addr) for addr in addrs): menu.addAction(_("Unfreeze"), lambda: self.parent.set_frozen_state(addrs, False)) def can_send(addr): return not self.wallet.is_frozen(addr) and sum(self.wallet.get_addr_balance(addr)[:2]) if any(can_send(addr) for addr in addrs): menu.addAction(_("Send From"), lambda: self.parent.send_from_addresses(addrs)) run_hook('receive_menu', menu, addrs, self.wallet) menu.exec_(self.viewport().mapToGlobal(position))
def on_update(self): item = self.currentItem() current_key = item.data(0, Qt.UserRole).toString() if item else None self.clear() for key in sorted(self.parent.contacts.keys()): _type, name = self.parent.contacts[key] item = QTreeWidgetItem([name, key]) item.setData(0, Qt.UserRole, key) self.addTopLevelItem(item) if key == current_key: self.setCurrentItem(item) run_hook('update_contacts_tab', self)
def load_wallet(self, wallet): print "load wallet", wallet.storage.path self.stop_wallet() self.wallet = wallet self.current_account = self.wallet.storage.get('current_account', None) self.update_wallet() # Once GUI has been initialized check if we want to announce something # since the callback has been called before the GUI was initialized if self.receive_screen: self.receive_screen.clear() self.update_tabs() run_hook('load_wallet', wallet, self)
def load_wallet(self, wallet): print "load wallet", wallet.storage.path self.stop_wallet() self.wallet = wallet self.current_account = self.wallet.storage.get('current_account', None) self.update_wallet() # Once GUI has been initialized check if we want to announce something # since the callback has been called before the GUI was initialized if self.receive_screen: self.receive_screen.clear() self.update_tabs() run_hook('load_wallet', wallet, self)
def create_menu(self, position): item = self.itemAt(position) if not item: return addr = str(item.text(2)) req = self.wallet.receive_requests[addr] column = self.currentColumn() column_title = self.headerItem().text(column) column_data = item.text(column) menu = QMenu(self) menu.addAction(_("Copy %s")%column_title, lambda: self.parent.app.clipboard().setText(column_data)) menu.addAction(_("Copy URI"), lambda: self.parent.view_and_paste('URI', '', self.parent.get_request_URI(addr))) menu.addAction(_("Save as BIP70 file"), lambda: self.parent.export_payment_request(addr)) menu.addAction(_("Delete"), lambda: self.parent.delete_payment_request(item)) run_hook('receive_list_menu', menu, addr) menu.exec_(self.viewport().mapToGlobal(position))
def update(self): desc = self.desc base_unit = self.main_window.base_unit() format_amount = self.main_window.format_amount tx_hash, status, label, can_broadcast, can_rbf, amount, fee, height, conf, timestamp, exp_n = self.wallet.get_tx_info(self.tx) if can_broadcast: self.broadcast_button.show() else: self.broadcast_button.hide() if self.wallet.can_sign(self.tx): self.sign_button.show() else: self.sign_button.hide() self.tx_hash_e.setText(tx_hash or _('Unknown')) if desc is None: self.tx_desc.hide() else: self.tx_desc.setText(_("Description") + ': ' + desc) self.tx_desc.show() self.status_label.setText(_('Status:') + ' ' + status) if timestamp: time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3] self.date_label.setText(_("Date: %s")%time_str) self.date_label.show() elif exp_n: text = '%d blocks'%(exp_n) if exp_n > 0 else _('unknown (low fee)') self.date_label.setText(_('Expected confirmation time') + ': ' + text) self.date_label.show() else: self.date_label.hide() # if we are not synchronized, we cannot tell if not self.wallet.up_to_date: return if amount is None: amount_str = _("Transaction unrelated to your wallet") elif amount > 0: amount_str = _("Amount received:") + ' %s'% format_amount(amount) + ' ' + base_unit else: amount_str = _("Amount sent:") + ' %s'% format_amount(-amount) + ' ' + base_unit fee_str = _("Transaction fee") + ': %s'% (format_amount(fee) + ' ' + base_unit if fee is not None else _('unknown')) self.amount_label.setText(amount_str) self.fee_label.setText(fee_str) run_hook('transaction_dialog_update', self)
def fiat_to_btc(self, fiat_amount): if not fiat_amount: return '' rate = run_hook('exchange_rate') if not rate: return '' satoshis = int(pow(10, 8) * Decimal(fiat_amount) / Decimal(rate)) return format_satoshis_plain(satoshis, self.decimal_point())
def fiat_to_btc(self, fiat_amount): if not fiat_amount: return '' rate = run_hook('exchange_rate') if not rate: return '' satoshis = int(pow(10,8) * Decimal(fiat_amount) / Decimal(rate)) return format_satoshis_plain(satoshis, self.decimal_point())
def btc_to_fiat(self, amount_str): if not amount_str: return '' rate = run_hook('exchange_rate') if not rate: return '' fiat_amount = self.get_amount(amount_str + ' ' + self.base_unit) * rate / pow(10, 8) return "{:.2f}".format(fiat_amount).rstrip('0').rstrip('.')
def btc_to_fiat(self, amount_str): if not amount_str: return '' rate = run_hook('exchange_rate') if not rate: return '' fiat_amount = self.get_amount(amount_str + ' ' + self.base_unit) * rate / pow(10, 8) return "{:.2f}".format(fiat_amount).rstrip('0').rstrip('.')
def get_card(self, tx_hash, height, conf, timestamp, value, balance): status, status_str = self.app.wallet.get_tx_status(tx_hash, height, conf, timestamp) icon = "atlas://gui/kivy/theming/light/" + TX_ICONS[status] label = self.app.wallet.get_label(tx_hash) if tx_hash else _('Pruned transaction outputs') date = timestamp_to_datetime(timestamp) ri = self.cards.get(tx_hash) if ri is None: ri = Factory.HistoryItem() ri.screen = self ri.tx_hash = tx_hash self.cards[tx_hash] = ri ri.icon = icon ri.date = status_str ri.message = label ri.value = value or 0 ri.value_known = value is not None ri.confirmations = conf if self.app.fiat_unit and date: rate = run_hook('history_rate', date) if rate: s = run_hook('value_str', value, rate) ri.quote_text = '' if s is None else s + ' ' + self.app.fiat_unit return ri
def create_menu(self, position): menu = QMenu() selected = self.selectedItems() if not selected: menu.addAction(_("New contact"), lambda: self.parent.new_contact_dialog()) else: names = [unicode(item.text(0)) for item in selected] keys = [unicode(item.text(1)) for item in selected] column = self.currentColumn() column_title = self.headerItem().text(column) column_data = '\n'.join([unicode(item.text(column)) for item in selected]) menu.addAction(_("Copy %s")%column_title, lambda: self.parent.app.clipboard().setText(column_data)) if column in self.editable_columns: menu.addAction(_("Edit %s")%column_title, lambda: self.editItem(item, column)) menu.addAction(_("Pay to"), lambda: self.parent.payto_contacts(keys)) menu.addAction(_("Delete"), lambda: self.parent.delete_contacts(keys)) URLs = [block_explorer_URL(self.config, 'addr', key) for key in filter(is_address, keys)] if URLs: menu.addAction(_("View on block explorer"), lambda: map(webbrowser.open, URLs)) run_hook('create_contact_menu', menu, selected) menu.exec_(self.viewport().mapToGlobal(position))
def __init__(self, tx, parent, desc, prompt_if_unsaved): '''Transactions in the wallet will show their description. Pass desc to give a description for txs not yet in the wallet. ''' # We want to be a top-level window QDialog.__init__(self, parent=None) # Take a copy; it might get updated in the main window by # e.g. the FX plugin. If this happens during or after a long # sign operation the signatures are lost. self.tx = copy.deepcopy(tx) self.tx.deserialize() self.main_window = parent self.wallet = parent.wallet self.prompt_if_unsaved = prompt_if_unsaved self.saved = False self.desc = desc self.setMinimumWidth(660) self.setWindowTitle(_("Transaction")) vbox = QVBoxLayout() self.setLayout(vbox) vbox.addWidget(QLabel(_("Transaction ID:"))) self.tx_hash_e = ButtonsLineEdit() qr_show = lambda: parent.show_qrcode( str(self.tx_hash_e.text()), 'Transaction ID', parent=self) self.tx_hash_e.addButton(":icons/qrcode.png", qr_show, _("Show as QR code")) self.tx_hash_e.setReadOnly(True) vbox.addWidget(self.tx_hash_e) self.tx_desc = QLabel() vbox.addWidget(self.tx_desc) self.status_label = QLabel() vbox.addWidget(self.status_label) self.date_label = QLabel() vbox.addWidget(self.date_label) self.amount_label = QLabel() vbox.addWidget(self.amount_label) self.fee_label = QLabel() vbox.addWidget(self.fee_label) self.add_io(vbox) vbox.addStretch(1) self.sign_button = b = QPushButton(_("Sign")) b.clicked.connect(self.sign) self.broadcast_button = b = QPushButton(_("Broadcast")) b.clicked.connect(self.do_broadcast) self.save_button = b = QPushButton(_("Save")) b.clicked.connect(self.save) self.cancel_button = b = QPushButton(_("Close")) b.clicked.connect(self.close) b.setDefault(True) self.qr_button = b = QPushButton() b.setIcon(QIcon(":icons/qrcode.png")) b.clicked.connect(self.show_qr) self.copy_button = CopyButton(lambda: str(self.tx), parent.app) # Action buttons self.buttons = [ self.sign_button, self.broadcast_button, self.cancel_button ] # Transaction sharing buttons self.sharing_buttons = [ self.copy_button, self.qr_button, self.save_button ] run_hook('transaction_dialog', self) hbox = QHBoxLayout() hbox.addLayout(Buttons(*self.sharing_buttons)) hbox.addStretch(1) hbox.addLayout(Buttons(*self.buttons)) vbox.addLayout(hbox) self.update()
def refresh_headers(self): headers = ['', '', _('Date'), _('Description') , _('Amount'), _('Balance')] run_hook('history_tab_headers', headers) self.update_headers(headers)
def __init__(self, tx, parent, desc, prompt_if_unsaved): '''Transactions in the wallet will show their description. Pass desc to give a description for txs not yet in the wallet. ''' # We want to be a top-level window QDialog.__init__(self, parent=None) # Take a copy; it might get updated in the main window by # e.g. the FX plugin. If this happens during or after a long # sign operation the signatures are lost. self.tx = copy.deepcopy(tx) self.tx.deserialize() self.main_window = parent self.wallet = parent.wallet self.prompt_if_unsaved = prompt_if_unsaved self.saved = False self.desc = desc self.setMinimumWidth(660) self.setWindowTitle(_("Transaction")) vbox = QVBoxLayout() self.setLayout(vbox) vbox.addWidget(QLabel(_("Transaction ID:"))) self.tx_hash_e = ButtonsLineEdit() qr_show = lambda: parent.show_qrcode(str(self.tx_hash_e.text()), 'Transaction ID', parent=self) self.tx_hash_e.addButton(":icons/qrcode.png", qr_show, _("Show as QR code")) self.tx_hash_e.setReadOnly(True) vbox.addWidget(self.tx_hash_e) self.tx_desc = QLabel() vbox.addWidget(self.tx_desc) self.status_label = QLabel() vbox.addWidget(self.status_label) self.date_label = QLabel() vbox.addWidget(self.date_label) self.amount_label = QLabel() vbox.addWidget(self.amount_label) self.fee_label = QLabel() vbox.addWidget(self.fee_label) self.add_io(vbox) vbox.addStretch(1) self.sign_button = b = QPushButton(_("Sign")) b.clicked.connect(self.sign) self.broadcast_button = b = QPushButton(_("Broadcast")) b.clicked.connect(self.do_broadcast) self.save_button = b = QPushButton(_("Save")) b.clicked.connect(self.save) self.cancel_button = b = QPushButton(_("Close")) b.clicked.connect(self.close) b.setDefault(True) self.qr_button = b = QPushButton() b.setIcon(QIcon(":icons/qrcode.png")) b.clicked.connect(self.show_qr) self.copy_button = CopyButton(lambda: str(self.tx), parent.app) # Action buttons self.buttons = [self.sign_button, self.broadcast_button, self.cancel_button] # Transaction sharing buttons self.sharing_buttons = [self.copy_button, self.qr_button, self.save_button] run_hook('transaction_dialog', self) hbox = QHBoxLayout() hbox.addLayout(Buttons(*self.sharing_buttons)) hbox.addStretch(1) hbox.addLayout(Buttons(*self.buttons)) vbox.addLayout(hbox) self.update()
def __init__(self, text=""): ButtonsTextEdit.__init__(self, text) self.setReadOnly(0) self.addButton(":icons/file.png", self.file_input, _("Read file")) self.addButton(":icons/qrcode.png", self.qr_input, _("Read QR code")) run_hook('scan_text_edit', self)
def __init__(self, text=None): ButtonsTextEdit.__init__(self, text) self.setReadOnly(1) self.addButton(":icons/qrcode.png", self.qr_show, _("Show as QR code")) run_hook('show_text_edit', self)
def __init__(self, text=""): ButtonsTextEdit.__init__(self, text) self.setReadOnly(0) self.addButton(":icons/file.png", self.file_input, _("Read file")) self.addButton(":icons/qrcode.png", self.qr_input, _("Read QR code")) run_hook('scan_text_edit', self)
def __init__(self, text=None): ButtonsTextEdit.__init__(self, text) self.setReadOnly(1) self.addButton(":icons/qrcode.png", self.qr_show, _("Show as QR code")) run_hook('show_text_edit', self)