def on_start(self): ''' This is the start point of the kivy ui ''' import time Logger.info('Time to on_start: {} <<<<<<<<'.format(time.clock())) Logger.info("dpi: {} {}".format(metrics.dpi, metrics.dpi_rounded)) 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.renpy.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 update(self): is_relevant, is_mine, v, fee = self.wallet.get_tx_value(self.tx) if self.wallet.can_sign(self.tx): self.sign_button.show() else: self.sign_button.hide() if self.tx.is_complete(): status = _("Signed") tx_hash = self.tx.hash() if tx_hash in self.wallet.transactions.keys(): conf, timestamp = self.wallet.verifier.get_confirmations(tx_hash) if timestamp: time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3] else: time_str = 'pending' status = _("%d confirmations")%conf self.broadcast_button.hide() else: time_str = None conf = 0 self.broadcast_button.show() else: s, r = self.tx.signature_count() status = _("Unsigned") if s == 0 else _('Partially signed (%d/%d)'%(s,r)) time_str = None self.broadcast_button.hide() tx_hash = 'unknown' self.tx_hash_e.setText(tx_hash) self.status_label.setText(_('Status:') + ' ' + status) if time_str is not None: self.date_label.setText(_("Date: %s")%time_str) self.date_label.show() else: self.date_label.hide() # if we are not synchronized, we cannot tell if self.parent.network is None or not self.parent.network.is_running() or not self.parent.network.is_connected(): return if not self.wallet.up_to_date: return if is_relevant: if is_mine: if fee is not None: self.amount_label.setText(_("Amount sent:")+' %s'% self.parent.format_amount(v-fee) + ' ' + self.parent.base_unit()) self.fee_label.setText(_("Transaction fee")+': %s'% self.parent.format_amount(fee) + ' ' + self.parent.base_unit()) else: self.amount_label.setText(_("Amount sent:")+' %s'% self.parent.format_amount(v) + ' ' + self.parent.base_unit()) self.fee_label.setText(_("Transaction fee")+': '+ _("unknown")) else: self.amount_label.setText(_("Amount received:")+' %s'% self.parent.format_amount(v) + ' ' + self.parent.base_unit()) else: self.amount_label.setText(_("Transaction unrelated to your wallet")) run_hook('transaction_dialog_update', self)
def __init__(self, tx, parent): self.tx = tx tx_dict = tx.as_dict() self.parent = parent self.wallet = parent.wallet self.saved = True QDialog.__init__(self) self.setMinimumWidth(600) self.setWindowTitle(_("Transaction")) self.setModal(1) vbox = QVBoxLayout() self.setLayout(vbox) vbox.addWidget(QLabel(_("Transaction ID:"))) self.tx_hash_e = ButtonsLineEdit() qr_show = lambda: self.parent.show_qrcode(str(self.tx_hash_e.text()), 'Transaction ID') 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.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) b.hide() 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), self.parent.app) self.buttons = [self.copy_button, self.qr_button, self.sign_button, self.broadcast_button, self.save_button, self.cancel_button] run_hook('transaction_dialog', self) vbox.addLayout(Buttons(*self.buttons)) self.update()
def __init__(self, config, network, 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.network = network self.config = config 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') 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 on_start(self): ''' This is the start point of the kivy ui ''' import time Logger.info('Time to on_start: {} <<<<<<<<'.format(time.clock())) Logger.info("dpi: {} {}".format(metrics.dpi, metrics.dpi_rounded)) win = Window win.bind(size=self.on_size, on_keyboard=self.on_keyboard) win.bind(on_key_down=self.on_key_down) # Register fonts without this you won't be able to use bold/italic... # inside markup. from kivy.core.text import Label Label.register('Roboto', 'gui/kivy/data/fonts/Roboto.ttf', 'gui/kivy/data/fonts/Roboto.ttf', 'gui/kivy/data/fonts/Roboto-Bold.ttf', 'gui/kivy/data/fonts/Roboto-Bold.ttf') 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) # were we sent a url? self.uri = self.electrum_config.get('url') # default tab self.switch_to('send' if self.uri else 'history')
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: conf = max(1, conf) icon = "atlas://gui/kivy/theming/light/clock{}".format(conf) else: icon = "atlas://gui/kivy/theming/light/confirmed" label = self.app.wallet.get_label(tx_hash) if tx_hash else _("Pruned transaction outputs") date = timestamp_to_datetime(timestamp) rate = run_hook("history_rate", date) if self.app.fiat_unit: s = run_hook("historical_value_str", value, date) quote_text = "..." if s is None else s + " " + self.app.fiat_unit else: quote_text = "" yield (conf, icon, time_str, label, value, tx_hash, quote_text)
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 create_quote_text(self, btc_balance): """Return a string copy of the amount fiat currency the user has in bitcoins.""" from electrum.plugins import run_hook r = {} run_hook('set_quote_text', btc_balance, r) return r.get(0,'')
def start_new_window(self, path, uri): for w in self.windows: if w.wallet.storage.path == path: w.bring_to_top() break else: wallet = self.load_wallet_file(path) if not wallet: return w = ElectrumWindow(self, wallet) w.connect_slots(self.timer) # save path if self.config.get('wallet_path') is None: self.config.set_key('gui_last_wallet', path) # add to recently visited w.update_recently_visited(path) # initial configuration if self.config.get('hide_gui') is True and self.tray.isVisible(): w.hide() else: w.show() self.windows.append(w) self.build_tray_menu() run_hook('on_new_window', w) if uri: w.pay_to_URI(uri) 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.renpy.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 update(self, h): self.wallet = self.parent.wallet item = self.currentItem() current_tx = item.data(0, Qt.UserRole).toString() if item else None self.clear() for item in h: tx_hash, conf, value, timestamp, balance = item if conf is None and timestamp is None: continue # skip history in offline mode icon, time_str = self.get_icon(conf, timestamp) v_str = self.parent.format_amount(value, True, whitespaces=True) balance_str = self.parent.format_amount(balance, whitespaces=True) label, is_default_label = self.wallet.get_label(tx_hash) item = EditableItem(['', tx_hash, time_str, label, v_str, balance_str]) item.setIcon(0, icon) item.setFont(3, QFont(MONOSPACE_FONT)) item.setFont(4, QFont(MONOSPACE_FONT)) item.setFont(5, QFont(MONOSPACE_FONT)) if value < 0: item.setForeground(4, QBrush(QColor("#BC1E1E"))) if tx_hash: item.setData(0, Qt.UserRole, tx_hash) if is_default_label: item.setForeground(3, QBrush(QColor('grey'))) self.insertTopLevelItem(0, item) if current_tx == tx_hash: self.setCurrentItem(item) run_hook('history_tab_update')
def __init__(self, text=""): ButtonsTextEdit.__init__(self, text) self.setReadOnly(0) self.addButton(":icons/file.png", self.file_input, _("Read file")) icon = ":icons/qrcode_white.png" if ColorScheme.dark_scheme else ":icons/qrcode.png" self.addButton(icon, self.qr_input, _("Read QR code")) run_hook('scan_text_edit', self)
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 __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)]) QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads) self.config = config self.daemon = daemon self.plugins = plugins self.windows = [] self.efilter = OpenFileEventFilter(self.windows) self.app = QElectrumApplication(sys.argv) self.app.installEventFilter(self.efilter) self.timer = Timer() self.nd = None self.network_updated_signal_obj = QNetworkUpdatedSignalObject() # init tray self.dark_icon = self.config.get("dark_icon", False) self.tray = QSystemTrayIcon(self.tray_icon(), None) self.tray.setToolTip('Electrum') self.tray.activated.connect(self.tray_activated) self.build_tray_menu() self.tray.show() self.app.new_window_signal.connect(self.start_new_window) run_hook('init_qt', self) ColorScheme.update_from_widget(QWidget())
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) # fiat currency self.fiat_unit = self.fx.ccy if self.fx.is_enabled() else '' self.network.register_callback(self.on_quotes, ['on_quotes']) self.network.register_callback(self.on_history, ['on_history']) # 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 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 = _('Not Verified') icon = "atlas://gui/kivy/theming/light/close" elif conf == 0: time_str = _('Unconfirmed') icon = "atlas://gui/kivy/theming/light/unconfirmed" elif conf < 6: conf = max(1, conf) icon = "atlas://gui/kivy/theming/light/clock{}".format(conf) else: icon = "atlas://gui/kivy/theming/light/confirmed" label = self.app.wallet.get_label(tx_hash) if tx_hash else _('Pruned transaction outputs') date = timestamp_to_datetime(timestamp) quote_text = '' if self.app.fiat_unit and date: rate = run_hook('history_rate', date) if rate: s = run_hook('value_str', value, rate) quote_text = '' if s is None else s + ' ' + self.app.fiat_unit yield (conf, icon, time_str, label, value, tx_hash, quote_text)
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; print 'python time to on_start:', time.clock(), '<<<<<<<<<' Logger.info("dpi: {} {}".format(metrics.dpi, metrics.dpi_rounded)) win = Window win.bind(size=self.on_size, on_keyboard=self.on_keyboard) win.bind(on_key_down=self.on_key_down) # Register fonts without this you won't be able to use bold/italic... # inside markup. from kivy.core.text import Label Label.register('Roboto', 'gui/kivy/data/fonts/Roboto.ttf', 'gui/kivy/data/fonts/Roboto.ttf', 'gui/kivy/data/fonts/Roboto-Bold.ttf', 'gui/kivy/data/fonts/Roboto-Bold.ttf') 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()) run_hook('init_kivy', self)
def on_start(self): ''' This is the start point of the kivy ui ''' Logger.info("dpi: {} {}".format(metrics.dpi, metrics.dpi_rounded)) win = Window win.bind(size=self.on_size, on_keyboard=self.on_keyboard) win.bind(on_key_down=self.on_key_down) # Register fonts without this you won't be able to use bold/italic... # inside markup. from kivy.core.text import Label Label.register('Roboto', 'data/fonts/Roboto.ttf', 'data/fonts/Roboto.ttf', 'data/fonts/Roboto-Bold.ttf', 'data/fonts/Roboto-Bold.ttf') if platform == 'android': # bind to keyboard height so we can get the window contents to # behave the way we want when the keyboard appears. win.bind(keyboard_height=self.on_keyboard_height) self.on_size(win, win.size) self.init_ui() self.load_wallet_by_name(self.electrum_config.get_wallet_path()) run_hook('init_kivy', self)
def main(self, url): storage = WalletStorage(self.config) if not storage.file_exists: import installwizard wizard = installwizard.InstallWizard(self.config, self.network, storage) wallet = wizard.run() if not wallet: exit() else: wallet = Wallet(storage) wallet.start_threads(self.network) self.main_window = w = ElectrumWindow(self.config, self.network) # plugins that need to change the GUI do it here run_hook("init") w.load_wallet(wallet) s = Timer() s.start() self.windows.append(w) if url: w.set_url(url) w.app = self.app w.connect_slots(s) w.update_wallet() self.app.exec_() wallet.stop_threads()
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 tx in h: tx_hash, conf, value, timestamp, balance = tx if conf is None and timestamp is None: continue # skip history in offline mode icon, time_str = self.get_icon(conf, timestamp) v_str = self.parent.format_amount(value, True, whitespaces=True) balance_str = self.parent.format_amount(balance, whitespaces=True) label, is_default_label = self.wallet.get_label(tx_hash) entry = ["", tx_hash, time_str, label, v_str, balance_str] run_hook("history_tab_update", tx, 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(4, QBrush(QColor("#BC1E1E"))) if tx_hash: item.setData(0, Qt.UserRole, tx_hash) if is_default_label: item.setForeground(3, QBrush(QColor("grey"))) self.insertTopLevelItem(0, item) if current_tx == tx_hash: self.setCurrentItem(item)
def __init__(self, parent=None): headers = ['', '', _('Date'), _('Description') , _('Amount'), _('Balance')] run_hook('history_tab_headers', headers) MyTreeWidget.__init__(self, parent, self.create_menu, headers, 3) self.setColumnHidden(1, True) self.config = self.parent.config self.setSortingEnabled(False)
def main(self, url): last_wallet = self.config.get('gui_last_wallet') if last_wallet is not None and self.config.get('wallet_path') is None: if os.path.exists(last_wallet): self.config.cmdline_options['default_wallet_path'] = last_wallet # init tray self.dark_icon = self.config.get("dark_icon", False) icon = QIcon(":icons/electrum_dark_icon.png") if self.dark_icon else QIcon(':icons/electrum_light_icon.png') self.tray = QSystemTrayIcon(icon, None) self.tray.setToolTip('Electrum') self.tray.activated.connect(self.tray_activated) self.build_tray_menu() self.tray.show() # main window self.main_window = w = ElectrumWindow(self.config, self.network, self) self.current_window = self.main_window w.show() #lite window self.init_lite() w.load_wallet_file(self.config.get_wallet_path()) # plugins interact with main window run_hook('init_qt', self) # initial configuration if self.config.get('hide_gui') is True and self.tray.isVisible(): self.main_window.hide() self.lite_window.hide() else: if self.config.get('lite_mode') is True: self.go_lite() else: self.go_full() s = Timer() s.start() self.windows.append(w) if url: self.set_url(url) w.connect_slots(s) signal.signal(signal.SIGINT, lambda *args: self.app.quit()) self.app.exec_() if self.tray: self.tray.hide() # clipboard persistence # see http://www.mail-archive.com/[email protected]/msg17328.html event = QtCore.QEvent(QtCore.QEvent.Clipboard) self.app.sendEvent(self.app.clipboard(), event) w.close_wallet()
def close_window(self, window): self.windows.remove(window) self.build_tray_menu() # save wallet path of last open window if self.config.get('wallet_path') is None and not self.windows: path = window.wallet.storage.path self.config.set_key('gui_last_wallet', path) run_hook('on_close_window', window)
def main(self, url): storage = WalletStorage(self.config) if storage.file_exists: wallet = Wallet(storage) action = wallet.get_action() else: action = 'new' if action is not None: import installwizard wizard = installwizard.InstallWizard(self.config, self.network, storage) wallet = wizard.run(action) if not wallet: exit() else: wallet.start_threads(self.network) # init tray self.dark_icon = self.config.get("dark_icon", False) icon = QIcon(":icons/electrum_dark_icon.png") if self.dark_icon else QIcon(':icons/electrum_light_icon.png') self.tray = QSystemTrayIcon(icon, None) self.tray.setToolTip('Electrum') self.tray.activated.connect(self.tray_activated) self.build_tray_menu() self.tray.show() # main window self.main_window = w = ElectrumWindow(self.config, self.network, self) self.current_window = self.main_window #lite window self.init_lite() # plugins that need to change the GUI do it here run_hook('init') w.load_wallet(wallet) s = Timer() s.start() self.windows.append(w) if url: self.set_url(url) w.app = self.app w.connect_slots(s) w.update_wallet() self.app.exec_() # clipboard persistence # see http://www.mail-archive.com/[email protected]/msg17328.html event = QtCore.QEvent(QtCore.QEvent.Clipboard) self.app.sendEvent(self.app.clipboard(), event) wallet.stop_threads()
def load_wallet(self, wallet): self.wallet = wallet 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): 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 self.update_history_tab() self.notify_transactions() run_hook('load_wallet', wallet, self)
def __init__(self, win, text=""): super(ScanQRTextEdit,self).__init__(text) self.setReadOnly(0) self.win = win assert win, "You must pass a window with access to the config to ScanQRTextEdit constructor." if win: assert hasattr(win,"config"), "You must pass a window with access to the config to ScanQRTextEdit constructor." self.button.clicked.connect(self.qr_input) run_hook('scan_text_edit', self)
def load_wallet(self, 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 self.update_tabs() self.notify_transactions() run_hook('load_wallet', wallet, self)
def __init__(self, win, text=""): super(ScanQRTextEdit,self).__init__(text) self.setReadOnly(0) self.win = win assert win, "You must pass a window with access to the config to ScanQRTextEdit constructor." if win: assert hasattr(win,"config"), "You must pass a window with access to the config to ScanQRTextEdit constructor." self.add_button(":icons/qrcode.png", self.qr_input, _("Read QR code")) run_hook('scan_text_edit', self)
def __init__(self, parent): QDialog.__init__(self, parent=parent) self.setWindowTitle(_('Create Smart Contract')) self.setMinimumSize(700, 150) self.setMaximumSize(780, 150) self.main_window = parent run_hook('contract_create_dialog', self) layout = ContractCreateLayout(self) self.setLayout(layout)
def create_window_for_wallet(self, wallet, task): w = ElectrumWindow(self, wallet) self.windows.append(w) self.build_tray_menu() if task: WaitingDialog(w, task[0], task[1]) # FIXME: Remove in favour of the load_wallet hook run_hook('on_new_window', w) return w
def create_menu_title(self, position): menu = QMenu() menu.addAction(_("Add contract"), lambda: self.parent.contract_add_dialog()) menu.addAction(_("Create contract"), lambda: self.parent.contract_create_dialog()) run_hook('create_smart_contract_menu', menu, []) menu.exec_(self.viewport().mapToGlobal(position))
def __init__(self, text="", allow_multi=False, show_qrscanner=True): ButtonsTextEdit.__init__(self, text) self.allow_multi = allow_multi self.show_qrscanner = show_qrscanner self.setReadOnly(0) self.addButton(":icons/file.png", self.file_input, _("Read file")) if self.show_qrscanner: icon = ":icons/qrcode_white.png" if ColorScheme.dark_scheme else ":icons/qrcode.png" self.addButton(icon, self.qr_input, _("Read QR code")) run_hook('scan_text_edit', self)
def refresh_headers(self): headers = [ '', '', _('Date'), _('Description'), _('Amount'), _('Balance') ] run_hook('history_tab_headers', headers) self.update_headers(headers)
def create_menu(self, position): from electrum.wallet import Multisig_Wallet, Imported_Wallet is_multisig = isinstance(self.wallet, Multisig_Wallet) is_imported = isinstance(self.wallet, Imported_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 is_imported: menu.addAction(_("Remove from wallet"), lambda: self.parent.remove_address(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 __init__(self, win, text=""): super(ScanQRTextEdit, self).__init__(text) self.setReadOnly(0) self.win = win assert win, "You must pass a window with access to the config to ScanQRTextEdit constructor." if win: assert hasattr( win, "config" ), "You must pass a window with access to the config to ScanQRTextEdit constructor." self.addButton(":icons/qrcode.png", self.qr_input, _("Read QR code")) run_hook('scan_text_edit', self)
def on_update(self): item = self.currentItem() current_key = item.data(0, Qt.UserRole) if item else None self.clear() for address in sorted(self.parent.smart_contracts.keys()): name, abi = self.parent.smart_contracts[address] item = QTreeWidgetItem([name, address]) item.setData(0, Qt.UserRole, address) self.addTopLevelItem(item) if address == current_key: self.setCurrentItem(item) run_hook('update_smart_contract_tab', self)
def create_menu(self, position): from electrum.wallet import Multisig_Wallet is_multisig = isinstance(self.wallet, Multisig_Wallet) can_delete = self.wallet.can_delete_address() 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): 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 can_delete: menu.addAction(_("Remove from wallet"), lambda: self.parent.remove_address(addr)) addr_URL = block_explorer_URL(self.config, 'addr', addr) if addr_URL: menu.addAction(_("View on block explorer"), lambda: webbrowser.open(addr_URL)) run_hook('receive_menu', menu, addrs, self.wallet) menu.exec_(self.viewport().mapToGlobal(position))
def __init__(self, parent, seed, passphrase): WindowModalDialog.__init__(self, parent, ('Electrum - ' + _('Seed'))) self.setMinimumWidth(400) vbox = QVBoxLayout(self) title = _("Your wallet generation seed is:") slayout = SeedLayout(title=title, seed=seed, msg=True, passphrase=passphrase) vbox.addLayout(slayout) run_hook('set_seed', seed, slayout.seed_e) vbox.addLayout(Buttons(CloseButton(self)))
def __init__(self, parent, contract): QDialog.__init__(self, parent=parent) self.contract = contract self.setWindowTitle(contract['name']) self.setMinimumSize(700, 200) self.main_window = parent run_hook('contract_func_dialog', self) # if contract['contractType'] == 'Token': # layout = ContractTokenLayout(self, contract) # else: layout = ContractFuncLayout(self, contract) self.setLayout(layout)
def on_update(self): item = self.currentItem() current_key = item.data(0, Qt.UserRole) 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): self.stop_wallet() self.wallet = wallet self.wallet.start_threads(self.network) 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 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) size = self.tx.estimated_size() self.broadcast_button.setEnabled(can_broadcast) can_sign = not self.tx.is_complete() and \ (self.wallet.can_sign(self.tx) or bool(self.main_window.tx_external_keypairs)) self.sign_button.setEnabled(can_sign) 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: {}").format(time_str)) self.date_label.show() elif exp_n: text = '%.2f MB' % (exp_n / 1000000) self.date_label.setText( _('Position in mempool') + ': ' + text + ' ' + _('from tip')) self.date_label.show() else: self.date_label.hide() 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 size_str = _("Size:") + ' %d bytes' % size fee_str = _("Fee") + ': %s' % (format_amount(fee) + ' ' + base_unit if fee is not None else _('unknown')) if fee is not None: fee_rate = fee / size * 1000 fee_str += ' ( %s ) ' % self.main_window.format_fee_rate(fee_rate) confirm_rate = simple_config.FEERATE_WARNING_HIGH_FEE if fee_rate > confirm_rate: fee_str += ' - ' + _('Warning') + ': ' + _("high fee") + '!' self.amount_label.setText(amount_str) self.fee_label.setText(fee_str) self.size_label.setText(size_str) run_hook('transaction_dialog_update', self)
def create_menu(self, position): menu = QMenu() selected = self.selectedItems() item = self.itemAt(position) if selected: names = [item.text(2) for item in selected] keys = [item.text(3) for item in selected] 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 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) size = self.tx.estimated_size() self.broadcast_button.setEnabled(can_broadcast) can_sign = not self.tx.is_complete() and \ (self.wallet.can_sign(self.tx) or bool(self.main_window.tx_external_keypairs)) self.sign_button.setEnabled(can_sign) 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 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 size_str = _("Size:") + ' %d bytes' % size fee_str = _("Fee") + ': %s' % (format_amount(fee) + ' ' + base_unit if fee is not None else _('unknown')) if fee is not None: fee_str += ' ( %s ) ' % self.main_window.format_fee_rate( fee / size * 1000) self.amount_label.setText(amount_str) self.fee_label.setText(fee_str) self.size_label.setText(size_str) self.txcomment_label.setText("TX Comment: " + self.tx.txcomment) run_hook('transaction_dialog_update', self)
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 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.wallet import Multisig_Wallet is_multisig = isinstance(self.wallet, Multisig_Wallet) can_delete = self.wallet.can_delete_address() selected = self.selectedItems() multi_select = len(selected) > 1 addrs = [item.text(1) 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): item.setExpanded(not item.isExpanded()) return menu = QMenu() if not multi_select: column_title = self.headerItem().text(col) copy_text = item.text(col) menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(copy_text)) menu.addAction(_('Details'), lambda: self.parent.show_address(addr)) if col in self.editable_columns: menu.addAction(_("Edit {}").format(column_title), lambda: self.editItem(item, col)) menu.addAction(_("Request payment"), lambda: self.parent.receive_at(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 can_delete: menu.addAction(_("Remove from wallet"), lambda: self.parent.remove_address(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 not self.wallet.is_frozen(addr): menu.addAction(_("Freeze"), lambda: self.parent.set_frozen_state([addr], True)) else: menu.addAction(_("Unfreeze"), lambda: self.parent.set_frozen_state([addr], False)) coins = self.wallet.get_utxos(addrs) if coins: menu.addAction(_("Spend from"), lambda: self.parent.spend_coins(coins)) run_hook('receive_menu', menu, addrs, self.wallet) menu.exec_(self.viewport().mapToGlobal(position))
def __init__(self, parent=None, msg=None): msg = msg or _('Please enter your password') WindowModalDialog.__init__(self, parent, _("Enter Password")) self.pw = pw = QLineEdit() pw.setEchoMode(2) vbox = QVBoxLayout() vbox.addWidget(QLabel(msg)) grid = QGridLayout() grid.setSpacing(8) grid.addWidget(QLabel(_('Password')), 1, 0) grid.addWidget(pw, 1, 1) vbox.addLayout(grid) vbox.addLayout(Buttons(CancelButton(self), OkButton(self))) self.setLayout(vbox) run_hook('password_dialog', pw, grid, 1)
def create_menu(self, position): item = self.itemAt(position) if not item: return addr = str(item.text(1)) 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(addr)) run_hook('receive_list_menu', menu, addr) menu.exec_(self.viewport().mapToGlobal(position))
def _do_send(self, amount, message, outputs, rbf): # make unsigned transaction config = self.app.electrum_config coins = self.app.wallet.get_spendable_coins(None, config) try: tx = self.app.wallet.make_unsigned_transaction( coins, outputs, config, None) except NotEnoughFunds: self.app.show_error(_("Not enough funds")) return except Exception as e: traceback.print_exc(file=sys.stdout) self.app.show_error(str(e)) return if rbf: tx.set_rbf(True) fee = tx.get_fee() msg = [ _("Amount to be sent") + ": " + self.app.format_amount_and_units(amount), _("Mining fee") + ": " + self.app.format_amount_and_units(fee), ] x_fee = run_hook('get_tx_extra_fee', self.app.wallet, tx) if x_fee: x_fee_address, x_fee_amount = x_fee msg.append( _("Additional fees") + ": " + self.app.format_amount_and_units(x_fee_amount)) if fee >= config.get('confirm_fee', 100000): msg.append( _('Warning') + ': ' + _("The fee for this transaction seems unusually high.")) msg.append(_("Enter your PIN code to proceed")) self.app.protected('\n'.join(msg), self.send_tx, (tx, message))
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: conf = max(1, conf) icon = "atlas://gui/kivy/theming/light/clock{}".format(conf) else: icon = "atlas://gui/kivy/theming/light/confirmed" label = self.app.wallet.get_label(tx_hash) if tx_hash else _('Pruned transaction outputs') date = timestamp_to_datetime(timestamp) rate = run_hook('history_rate', date) if self.app.fiat_unit: quote_text = "..." if rate is None else "{0:.3} {1}".format(Decimal(value) / 100000000 * Decimal(rate), self.app.fiat_unit) else: quote_text = '' yield (conf, icon, time_str, label, value, tx_hash, quote_text)
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 on_update(self): item = self.currentItem() current_key = item.data(0, Qt.UserRole) if item else None self.clear() for address in sorted(self.parent.smart_contracts.keys()): name, abi = self.parent.smart_contracts[address] if self.isTokenContract(abi): contractType = 'Token' else: contractType = 'Common' item = QTreeWidgetItem([name, address, contractType]) item.setData(0, Qt.UserRole, address) item.setData(1, Qt.UserRole, contractType) self.addTopLevelItem(item) if address == current_key: self.setCurrentItem(item) run_hook('update_smart_contract_tab', self)
def create_menu(self, position): menu = QMenu() selected = self.selectedItems() item = self.itemAt(position) col = self.currentColumn() if len(selected) == 1: names = [item.text(2) for item in selected] keys = [item.text(3) for item in selected] 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)) if col : # filter 0 col column_title = self.headerItem().text(col) copy_text = item.text(col) #menu.addAction(_("Copy %s")%column_title, lambda: self.parent.app.clipboard().setText(copy_text)) run_hook('create_contact_menu', menu, selected) menu.exec_(self.viewport().mapToGlobal(position))
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 on_update(self): item = self.currentItem() current_key = item.data(3, Qt.UserRole) if item else None self.clear() self.print_error("delegate :", self.delegate_list) #self.print_error("selected :", self.selected_list) #self.print_error("filter :", self.filter_status) for each in self.voted_ls: voter = each.get('voter') voted = each.get('voted') item = QTreeWidgetItem([self.get_address_name(voted), voted, self.get_address_name(voter), voter]) #item.setData(3, Qt.UserRole, each.get('address')) #item.setCheckState(0, Qt.Unchecked) self.addTopLevelItem(item) if each.get('voter') == current_key: self.setCurrentItem(item) run_hook('update_contacts_tab', self)
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 on_success = run_hook('tc_sign_wrapper', self.wallet, tx, on_success, on_failure) or on_success Clock.schedule_once(lambda dt: on_success(tx))