X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=gui%2Fqt%2Fmain_window.py;h=cc61f4237098d67afe97914be705df02757d48a9;hb=029e0b8b0d788463feb56cb34540d9dcc9f31e93;hp=cd288e9bcf07a1582ea8432cd3af2b2dee6d8288;hpb=2a07ed47f25c263d5fc2e055948495746cf6bbc6;p=electrum-nvc.git diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index cd288e9..cc61f42 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -35,7 +35,7 @@ from electrum.plugins import run_hook import icons_rc -from electrum.wallet import format_satoshis +from electrum.util import format_satoshis from electrum import Transaction from electrum import mnemonic from electrum import util, bitcoin, commands, Interface, Wallet @@ -134,7 +134,6 @@ class ElectrumWindow(QMainWindow): set_language(config.get('language')) - self.funds_error = False self.completions = QStringListModel() self.tabs = tabs = QTabWidget(self) @@ -557,7 +556,7 @@ class ElectrumWindow(QMainWindow): def edit_label(self, is_recv): - l = self.receive_list if is_recv else self.contacts_list + l = self.address_list if is_recv else self.contacts_list item = l.currentItem() item.setFlags(Qt.ItemIsEditable|Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsDragEnabled) l.editItem( item, 1 ) @@ -862,7 +861,6 @@ class ElectrumWindow(QMainWindow): w.setLayout(grid) def entry_changed( is_fee ): - self.funds_error = False if self.amount_e.is_shortcut: self.amount_e.is_shortcut = False @@ -872,27 +870,33 @@ class ElectrumWindow(QMainWindow): fee = self.wallet.estimated_fee(inputs, 1) amount = total - fee self.amount_e.setAmount(amount) + self.amount_e.textEdited.emit("") self.fee_e.setAmount(fee) return amount = self.amount_e.get_amount() fee = self.fee_e.get_amount() + outputs = self.payto_e.get_outputs() + + if not is_fee: + fee = None - if not is_fee: fee = None if amount is None: - return - # assume that there will be 2 outputs (one for change) - inputs, total, fee = self.wallet.choose_tx_inputs(amount, fee, 2, coins = self.get_coins()) - if not is_fee: - self.fee_e.setAmount(fee) - if inputs: + self.fee_e.setAmount(None) + not_enough_funds = False + else: + inputs, total, fee = self.wallet.choose_tx_inputs(amount, fee, len(outputs), coins = self.get_coins()) + not_enough_funds = len(inputs) == 0 + if not is_fee: + self.fee_e.setAmount(fee) + + if not not_enough_funds: palette = QPalette() palette.setColor(self.amount_e.foregroundRole(), QColor('black')) text = "" else: palette = QPalette() palette.setColor(self.amount_e.foregroundRole(), QColor('red')) - self.funds_error = True text = _( "Not enough funds" ) c, u = self.wallet.get_frozen_balance() if c+u: text += ' (' + self.format_amount(c+u).strip() + ' ' + self.base_unit() + ' ' +_("are frozen") + ')' @@ -1022,13 +1026,15 @@ class ElectrumWindow(QMainWindow): # sign the tx def sign_thread(): - time.sleep(0.1) keypairs = {} - self.wallet.add_keypairs_from_wallet(tx, keypairs, password) - self.wallet.sign_transaction(tx, keypairs, password) - return tx, fee, label + try: + self.wallet.add_keypairs(tx, keypairs, password) + self.wallet.sign_transaction(tx, keypairs, password) + except Exception as e: + tx.error = str(e) + return tx - def sign_done(tx, fee, label): + def sign_done(tx): if tx.error: self.show_message(tx.error) self.send_button.setDisabled(False) @@ -1048,6 +1054,7 @@ class ElectrumWindow(QMainWindow): self.broadcast_transaction(tx) + # keep a reference to WaitingDialog or the gui might crash self.waiting_dialog = WaitingDialog(self, 'Signing..', sign_thread, sign_done) self.waiting_dialog.start() @@ -1489,24 +1496,6 @@ class ElectrumWindow(QMainWindow): menu.exec_(self.invoices_list.viewport().mapToGlobal(position)) - def update_address_item(self, item): - item.setFont(0, QFont(MONOSPACE_FONT)) - address = str(item.data(0,0).toString()) - label = self.wallet.labels.get(address,'') - item.setData(1,0,label) - item.setData(0,32, True) # is editable - - run_hook('update_address_item', address, item) - - if not self.wallet.is_mine(address): return - - c, u = self.wallet.get_addr_balance(address) - balance = self.format_amount(c + u) - item.setData(2,0,balance) - - if address in self.wallet.frozen_addresses: - item.setBackgroundColor(0, QColor('lightblue')) - def update_address_tab(self): l = self.address_list @@ -1549,27 +1538,22 @@ class ElectrumWindow(QMainWindow): used_item = QTreeWidgetItem( [ _("Used"), '', '', '', ''] ) used_flag = False - is_red = False - gap = 0 - - for address in account.get_addresses(is_change): - + addr_list = account.get_addresses(is_change) + for address in addr_list: num, is_used = self.wallet.is_used(address) - if num == 0: - gap += 1 - if gap > self.wallet.gap_limit: - is_red = True - else: - gap = 0 - - item = QTreeWidgetItem( [ address, '', '', "%d"%num] ) - self.update_address_item(item) - if is_red: - item.setBackgroundColor(1, QColor('red')) - + label = self.wallet.labels.get(address,'') + c, u = self.wallet.get_addr_balance(address) + balance = self.format_amount(c + u) + item = QTreeWidgetItem( [ address, label, balance, "%d"%num] ) + item.setFont(0, QFont(MONOSPACE_FONT)) + item.setData(0, 32, True) # label can be edited + if address in self.wallet.frozen_addresses: + item.setBackgroundColor(0, QColor('lightblue')) + if self.wallet.is_beyond_limit(address, account, is_change): + item.setBackgroundColor(0, QColor('red')) if is_used: if not used_flag: - seq_item.insertChild(0,used_item) + seq_item.insertChild(0, used_item) used_flag = True used_item.addChild(item) else: @@ -1598,7 +1582,6 @@ class ElectrumWindow(QMainWindow): l.setCurrentItem(l.topLevelItem(0)) - def create_console_tab(self): from console import Console self.console = console = Console() @@ -1814,7 +1797,6 @@ class ElectrumWindow(QMainWindow): def show_qrcode(self, data, title = _("QR code")): if not data: return - print_error("qrcode:", data) d = QRDialog(data, self, title) d.exec_() @@ -2046,24 +2028,29 @@ class ElectrumWindow(QMainWindow): "json or raw hexadecimal" try: txt.decode('hex') - tx = Transaction(txt) - return tx - except Exception: - pass + is_hex = True + except: + is_hex = False + + if is_hex: + try: + return Transaction(txt) + except: + traceback.print_exc(file=sys.stdout) + QMessageBox.critical(None, _("Unable to parse transaction"), _("Electrum was unable to parse your transaction")) + return try: tx_dict = json.loads(str(txt)) assert "hex" in tx_dict.keys() tx = Transaction(tx_dict["hex"]) - if tx_dict.has_key("input_info"): - input_info = json.loads(tx_dict['input_info']) - tx.add_input_info(input_info) + #if tx_dict.has_key("input_info"): + # input_info = json.loads(tx_dict['input_info']) + # tx.add_input_info(input_info) return tx except Exception: traceback.print_exc(file=sys.stdout) - pass - - QMessageBox.critical(None, _("Unable to parse transaction"), _("Electrum was unable to parse your transaction")) + QMessageBox.critical(None, _("Unable to parse transaction"), _("Electrum was unable to parse your transaction")) @@ -2081,10 +2068,11 @@ class ElectrumWindow(QMainWindow): @protected - def sign_raw_transaction(self, tx, input_info, password): + def sign_raw_transaction(self, tx, password): try: - self.wallet.signrawtransaction(tx, input_info, [], password) + self.wallet.signrawtransaction(tx, [], password) except Exception as e: + traceback.print_exc(file=sys.stdout) QMessageBox.warning(self, _("Error"), str(e)) def do_process_from_text(self):