Browse Source

Merge pull request #476 from shunyata/bugfix/parsing-error-in-csv-transaction

Bugfix/parsing error in csv transaction
283
ThomasV 11 years ago
parent
commit
c389b47c21
  1. 122
      gui/qt/main_window.py

122
gui/qt/main_window.py

@ -68,7 +68,7 @@ import re
from util import *
@ -185,7 +185,7 @@ class ElectrumWindow(QMainWindow):
QShortcut(QKeySequence("Ctrl+Q"), self, self.close)
QShortcut(QKeySequence("Ctrl+PgUp"), self, lambda: tabs.setCurrentIndex( (tabs.currentIndex() - 1 )%tabs.count() ))
QShortcut(QKeySequence("Ctrl+PgDown"), self, lambda: tabs.setCurrentIndex( (tabs.currentIndex() + 1 )%tabs.count() ))
self.connect(self, QtCore.SIGNAL('update_status'), self.update_status)
self.connect(self, QtCore.SIGNAL('banner_signal'), lambda: self.console.showMessage(self.network.banner) )
self.connect(self, QtCore.SIGNAL('transaction_signal'), lambda: self.notify_transactions() )
@ -254,7 +254,7 @@ class ElectrumWindow(QMainWindow):
def check_qt_version(self):
qtVersion = qVersion()
return int(qtVersion[0]) >= 4 and int(qtVersion[2]) >= 7
def update_account_selector(self):
# account selector
@ -301,8 +301,8 @@ class ElectrumWindow(QMainWindow):
return
self.wallet.stop_threads()
# create new wallet
# create new wallet
wallet = Wallet(storage)
wallet.start_threads(self.network)
@ -343,7 +343,7 @@ class ElectrumWindow(QMainWindow):
wizard = installwizard.InstallWizard(self.config, self.network, storage)
wallet = wizard.run()
if wallet:
if wallet:
self.load_wallet(wallet)
@ -437,7 +437,7 @@ class ElectrumWindow(QMainWindow):
help_menu = menubar.addMenu(_("&Help"))
show_about = help_menu.addAction(_("&About"))
show_about.triggered.connect(self.show_about)
web_open = help_menu.addAction(_("&Official website"))
web_open = help_menu.addAction(_("&Official website"))
web_open.triggered.connect(lambda: webbrowser.open("http://electrum.org"))
help_menu.addSeparator()
@ -458,7 +458,7 @@ class ElectrumWindow(QMainWindow):
def notify_transactions(self):
if not self.network or not self.network.is_connected():
if not self.network or not self.network.is_connected():
return
print_error("Notifying GUI")
@ -518,7 +518,7 @@ class ElectrumWindow(QMainWindow):
self.update_wallet()
self.need_update.clear()
run_hook('timer_actions')
def format_amount(self, x, is_diff=False, whitespaces=False):
return format_satoshis(x, is_diff, self.num_zeros, self.decimal_point, whitespaces)
@ -573,7 +573,7 @@ class ElectrumWindow(QMainWindow):
self.update_contacts_tab()
self.update_completions()
def create_history_tab(self):
self.history_list = l = MyTreeWidget(self)
l.setColumnCount(5)
@ -588,7 +588,7 @@ class ElectrumWindow(QMainWindow):
def create_history_menu(self, position):
self.history_list.selectedIndexes()
self.history_list.selectedIndexes()
item = self.history_list.currentItem()
if not item: return
tx_hash = str(item.data(0, Qt.UserRole).toString())
@ -614,14 +614,14 @@ class ElectrumWindow(QMainWindow):
self.is_edit=False
def tx_label_changed(self, item, column):
if self.is_edit:
if self.is_edit:
return
self.is_edit=True
tx_hash = str(item.data(0, Qt.UserRole).toString())
tx = self.wallet.transactions.get(tx_hash)
text = unicode( item.text(2) )
self.wallet.set_label(tx_hash, text)
if text:
self.wallet.set_label(tx_hash, text)
if text:
item.setForeground(2, QBrush(QColor('black')))
else:
text = self.wallet.get_default_label(tx_hash)
@ -663,7 +663,7 @@ class ElectrumWindow(QMainWindow):
if changed:
self.update_history_tab()
self.update_completions()
self.current_item_changed(item)
run_hook('item_changed', item, column)
@ -706,7 +706,7 @@ class ElectrumWindow(QMainWindow):
v_str = '--'
balance_str = self.format_amount(balance, whitespaces=True)
if tx_hash:
label, is_default_label = self.wallet.get_label(tx_hash)
else:
@ -727,7 +727,7 @@ class ElectrumWindow(QMainWindow):
item.setIcon(0, icon)
self.history_list.insertTopLevelItem(0,item)
self.history_list.setCurrentItem(self.history_list.topLevelItem(0))
@ -744,7 +744,7 @@ class ElectrumWindow(QMainWindow):
self.payto_e = QLineEdit()
grid.addWidget(QLabel(_('Pay to')), 1, 0)
grid.addWidget(self.payto_e, 1, 1, 1, 3)
grid.addWidget(HelpButton(_('Recipient of the funds.') + '\n\n' + _('You may enter a Bitcoin address, a label from your list of contacts (a list of completions will be proposed), or an alias (email-like address that forwards to a Bitcoin address)')), 1, 4)
completer = QCompleter()
@ -776,7 +776,7 @@ class ElectrumWindow(QMainWindow):
_('Amount to be sent.') + '\n\n' \
+ _('The amount will be displayed in red if you do not have enough funds in your wallet. Note that if you have frozen some of your addresses, the available funds will be lower than your total balance.') \
+ '\n\n' + _('Keyboard shortcut: type "!" to send all your coins.')), 4, 3)
self.fee_e = AmountEdit(self.base_unit)
grid.addWidget(QLabel(_('Fee')), 5, 0)
grid.addWidget(self.fee_e, 5, 1, 1, 2)
@ -797,7 +797,7 @@ class ElectrumWindow(QMainWindow):
QShortcut(QKeySequence("Up"), w, w.focusPreviousChild)
QShortcut(QKeySequence("Down"), w, w.focusNextChild)
w.setLayout(grid)
w.setLayout(grid)
w2 = QWidget()
vbox = QVBoxLayout()
@ -817,7 +817,7 @@ class ElectrumWindow(QMainWindow):
self.amount_e.setText( self.format_amount(amount) )
self.fee_e.setText( self.format_amount( fee ) )
return
amount = self.read_amount(str(self.amount_e.text()))
fee = self.read_amount(str(self.fee_e.text()))
@ -921,7 +921,7 @@ class ElectrumWindow(QMainWindow):
QMessageBox.warning(self, _('Error'), _("This transaction requires a higher fee, or it will not be propagated by the network."), _('OK'))
return
if label:
if label:
self.wallet.set_label(tx.hash(), label)
if tx.is_complete:
@ -1064,7 +1064,7 @@ class ElectrumWindow(QMainWindow):
self.column_widths["receive"] = []
for i in range(self.receive_list.columnCount() -1):
self.column_widths["receive"].append(self.receive_list.columnWidth(i))
self.column_widths["history"] = []
for i in range(self.history_list.columnCount() - 1):
self.column_widths["history"].append(self.history_list.columnWidth(i))
@ -1127,7 +1127,7 @@ class ElectrumWindow(QMainWindow):
def create_receive_menu(self, position):
# fixme: this function apparently has a side effect.
# if it is not called the menu pops up several times
#self.receive_list.selectedIndexes()
#self.receive_list.selectedIndexes()
selected = self.receive_list.selectedItems()
multi_select = len(selected) > 1
@ -1162,7 +1162,7 @@ class ElectrumWindow(QMainWindow):
menu.addAction(_("Unfreeze"), lambda: self.set_addrs_frozen(addrs, False))
menu.addAction(_("Send From"), lambda: self.send_from_addresses(addrs))
run_hook('receive_menu', menu, addrs)
menu.exec_(self.receive_list.viewport().mapToGlobal(position))
@ -1235,13 +1235,13 @@ class ElectrumWindow(QMainWindow):
balance = self.format_amount(c + u)
item.setData(2,0,balance)
if address in self.wallet.frozen_addresses:
if address in self.wallet.frozen_addresses:
item.setBackgroundColor(0, QColor('lightblue'))
def update_receive_tab(self):
l = self.receive_list
l.clear()
l.setColumnHidden(2, False)
l.setColumnHidden(3, False)
@ -1266,7 +1266,7 @@ class ElectrumWindow(QMainWindow):
if not self.wallet.is_seeded(k):
icon = QIcon(":icons/key.png")
account_item.setIcon(0, icon)
for is_change in ([0,1]):
name = _("Receiving") if not is_change else _("Change")
seq_item = QTreeWidgetItem( [ name, '', '', '', ''] )
@ -1280,7 +1280,7 @@ class ElectrumWindow(QMainWindow):
for address in account.get_addresses(is_change):
h = self.wallet.history.get(address,[])
if h == []:
gap += 1
if gap > self.wallet.gap_limit:
@ -1324,7 +1324,7 @@ class ElectrumWindow(QMainWindow):
item = QTreeWidgetItem( [ address, '', '', ''] )
self.update_receive_item(item)
account_item.addChild(item)
# we use column 1 because column 0 may be hidden
l.setCurrentItem(l.topLevelItem(0),1)
@ -1371,7 +1371,7 @@ class ElectrumWindow(QMainWindow):
for m in dir(c):
if m[0]=='_' or m in ['network','wallet']: continue
methods[m] = mkfunc(c._run, m)
console.updateNamespace(methods)
@ -1400,7 +1400,7 @@ class ElectrumWindow(QMainWindow):
self.updatelabel = UpdateLabel(self.config, sb)
self.account_selector = QComboBox()
self.connect(self.account_selector,SIGNAL("activated(QString)"),self.change_account)
self.connect(self.account_selector,SIGNAL("activated(QString)"),self.change_account)
sb.addPermanentWidget(self.account_selector)
if (int(qtVersion[0]) >= 4 and int(qtVersion[2]) >= 7):
@ -1409,11 +1409,11 @@ class ElectrumWindow(QMainWindow):
self.lock_icon = QIcon()
self.password_button = StatusBarButton( self.lock_icon, _("Password"), self.change_password_dialog )
sb.addPermanentWidget( self.password_button )
sb.addPermanentWidget( StatusBarButton( QIcon(":icons/preferences.png"), _("Preferences"), self.settings_dialog ) )
self.seed_button = StatusBarButton( QIcon(":icons/seed.png"), _("Seed"), self.show_seed_dialog )
self.seed_button = StatusBarButton( QIcon(":icons/seed.png"), _("Seed"), self.show_seed_dialog )
sb.addPermanentWidget( self.seed_button )
self.status_button = StatusBarButton( QIcon(":icons/status_disconnected.png"), _("Network"), self.run_network_dialog )
self.status_button = StatusBarButton( QIcon(":icons/status_disconnected.png"), _("Network"), self.run_network_dialog )
sb.addPermanentWidget( self.status_button )
run_hook('create_status_bar', (sb,))
@ -1449,7 +1449,7 @@ class ElectrumWindow(QMainWindow):
d = QDialog(self)
vbox = QVBoxLayout(d)
vbox.addWidget(QLabel(_('New Contact')+':'))
grid = QGridLayout()
line1 = QLineEdit()
line2 = QLineEdit()
@ -1460,17 +1460,17 @@ class ElectrumWindow(QMainWindow):
vbox.addLayout(grid)
vbox.addLayout(ok_cancel_buttons(d))
if not d.exec_():
return
address = str(line1.text())
label = unicode(line2.text())
if not is_valid(address):
QMessageBox.warning(self, _('Error'), _('Invalid Address'), _('OK'))
return
self.wallet.add_contact(address)
if label:
self.wallet.set_label(address, label)
@ -1508,8 +1508,8 @@ class ElectrumWindow(QMainWindow):
self.wallet.create_pending_account('1', name)
self.update_receive_tab()
self.tabs.setCurrentIndex(2)
def show_master_public_key_old(self):
dialog = QDialog(self)
@ -1537,7 +1537,7 @@ class ElectrumWindow(QMainWindow):
vbox.addLayout(close_button(dialog))
dialog.setLayout(vbox)
dialog.exec_()
def show_master_public_key(self):
@ -1577,14 +1577,14 @@ class ElectrumWindow(QMainWindow):
mpk_text.setText(K)
mpk_qrw.set_addr(K)
mpk_qrw.update_qr()
key_selector = QComboBox()
keys = sorted(self.wallet.master_public_keys.keys())
key_selector.addItems(keys)
main_layout.addWidget(QLabel(_('Derivation:')), 0, 0)
main_layout.addWidget(key_selector, 0, 1)
dialog.connect(key_selector,SIGNAL("activated(QString)"),update)
dialog.connect(key_selector,SIGNAL("activated(QString)"),update)
update(keys[0])
@ -1594,7 +1594,7 @@ class ElectrumWindow(QMainWindow):
dialog.setLayout(vbox)
dialog.exec_()
@protected
def show_seed_dialog(self, password):
@ -1673,7 +1673,7 @@ class ElectrumWindow(QMainWindow):
return
else:
password = None
if args != (False,):
args = (self,) + args + (password,)
else:
@ -1781,7 +1781,7 @@ class ElectrumWindow(QMainWindow):
d.setLayout(vbox)
d.exec_()
def question(self, msg):
@ -1842,7 +1842,7 @@ class ElectrumWindow(QMainWindow):
return tx
except Exception:
pass
QMessageBox.critical(None, _("Unable to parse transaction"), _("Electrum was unable to parse your transaction"))
@ -1882,7 +1882,7 @@ class ElectrumWindow(QMainWindow):
try:
for row in csvReader:
address = row[0]
amount = float(row[1])
amount = Decimal(row[1])
amount = int(100000000*amount)
outputs.append((address, amount))
except (ValueError, IOError, os.error), reason:
@ -1933,7 +1933,7 @@ class ElectrumWindow(QMainWindow):
transaction.writerow(["address", "private_key"])
addresses = self.wallet.addresses(True)
for addr in addresses:
pk = "".join(self.wallet.get_private_key(addr, password))
transaction.writerow(["%34s"%addr,pk])
@ -1961,7 +1961,7 @@ class ElectrumWindow(QMainWindow):
QMessageBox.information(None, _("Labels imported"), _("Your labels were imported from")+" '%s'" % str(labelsFile))
except (IOError, os.error), reason:
QMessageBox.critical(None, _("Unable to import labels"), _("Electrum was unable to import your labels.")+"\n" + str(reason))
def do_export_labels(self):
labels = self.wallet.labels
@ -2000,7 +2000,7 @@ class ElectrumWindow(QMainWindow):
except Exception as e:
badkeys.append(key)
continue
if not addr:
if not addr:
badkeys.append(key)
else:
addrlist.append(addr)
@ -2029,7 +2029,7 @@ class ElectrumWindow(QMainWindow):
grid.addWidget(HelpButton(msg), 0, 2)
if not self.config.is_modifiable('num_zeros'):
for w in [nz_e, nz_label]: w.setEnabled(False)
lang_label=QLabel(_('Language') + ':')
grid.addWidget(lang_label, 1, 0)
lang_combo = QComboBox()
@ -2045,7 +2045,7 @@ class ElectrumWindow(QMainWindow):
if not self.config.is_modifiable('language'):
for w in [lang_combo, lang_label]: w.setEnabled(False)
fee_label = QLabel(_('Transaction fee') + ':')
grid.addWidget(fee_label, 2, 0)
fee_e = AmountEdit(self.base_unit)
@ -2078,7 +2078,7 @@ class ElectrumWindow(QMainWindow):
vbox.addLayout(grid)
vbox.addLayout(ok_cancel_buttons(d))
d.setLayout(vbox)
d.setLayout(vbox)
# run the dialog
if not d.exec_(): return
@ -2091,7 +2091,7 @@ class ElectrumWindow(QMainWindow):
return
self.wallet.set_fee(fee)
nz = unicode(nz_e.text())
try:
nz = int( nz )
@ -2110,21 +2110,21 @@ class ElectrumWindow(QMainWindow):
if self.wallet.use_change != usechange_result:
self.wallet.use_change = usechange_result
self.wallet.storage.put('use_change', self.wallet.use_change)
unit_result = units[unit_combo.currentIndex()]
if self.base_unit() != unit_result:
self.decimal_point = 8 if unit_result == 'BTC' else 5
self.config.set_key('decimal_point', self.decimal_point, True)
self.update_history_tab()
self.update_status()
need_restart = False
lang_request = languages.keys()[lang_combo.currentIndex()]
if lang_request != self.config.get('language'):
self.config.set_key("language", lang_request, True)
need_restart = True
run_hook('close_settings_dialog')
if need_restart:
@ -2189,7 +2189,7 @@ class ElectrumWindow(QMainWindow):
w = p.settings_widget(self)
w.setEnabled( p.is_enabled() )
grid.addWidget(w, i, 1)
else:
else:
w = None
cb.clicked.connect(mk_toggle(cb,p,w))
grid.addWidget(HelpButton(p.description()), i, 2)

Loading…
Cancel
Save