2012-02-14 07:44:23 -08:00
#!/usr/bin/env python
#
# Electrum - lightweight Bitcoin client
# Copyright (C) 2012 thomasv@gitorious
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2013-04-27 10:17:36 -07:00
import sys , time , datetime , re , threading
2013-09-11 04:43:37 -07:00
from electrum . i18n import _ , set_language
2013-03-03 03:00:38 -08:00
from electrum . util import print_error , print_msg
import os . path , json , ast , traceback
2014-03-02 04:19:49 -08:00
import webbrowser
2013-05-31 04:45:59 -07:00
import shutil
2013-09-04 01:57:15 -07:00
import StringIO
2013-04-28 04:47:19 -07:00
2013-03-02 09:03:29 -08:00
2013-09-30 01:30:43 -07:00
import PyQt4
2012-02-11 04:14:12 -08:00
from PyQt4 . QtGui import *
2012-02-11 08:02:28 -08:00
from PyQt4 . QtCore import *
2012-02-11 04:14:12 -08:00
import PyQt4 . QtCore as QtCore
2013-04-28 04:47:19 -07:00
2013-09-04 08:27:13 -07:00
from electrum . bitcoin import MIN_RELAY_TX_FEE , is_valid
2013-09-23 07:14:28 -07:00
from electrum . plugins import run_hook
2012-02-11 04:14:12 -08:00
2013-09-30 01:30:43 -07:00
import icons_rc
2012-02-14 02:33:09 -08:00
2014-06-24 07:34:22 -07:00
from electrum . util import format_satoshis
2013-09-04 07:46:27 -07:00
from electrum import Transaction
2013-03-02 03:26:21 -08:00
from electrum import mnemonic
2013-09-01 09:44:19 -07:00
from electrum import util , bitcoin , commands , Interface , Wallet
from electrum import SimpleConfig , Wallet , WalletStorage
2014-06-26 09:55:22 -07:00
from electrum import Imported_Wallet
2013-09-01 06:26:52 -07:00
2014-06-11 06:28:07 -07:00
from amountedit import AmountEdit , BTCAmountEdit , MyLineEdit
2013-04-28 04:47:19 -07:00
from network_dialog import NetworkDialog
2014-06-14 03:17:44 -07:00
from qrcodewidget import QRCodeWidget , QRDialog
2014-06-14 04:05:55 -07:00
from qrtextedit import QRTextEdit
2013-04-06 14:34:12 -07:00
2012-02-13 06:22:15 -08:00
from decimal import Decimal
2012-02-11 13:19:22 -08:00
2012-03-31 07:46:32 -07:00
import platform
2013-01-15 12:31:21 -08:00
import httplib
import socket
import webbrowser
2013-02-14 08:31:29 -08:00
import csv
2012-06-25 08:09:59 -07:00
if platform . system ( ) == ' Windows ' :
MONOSPACE_FONT = ' Lucida Console '
elif platform . system ( ) == ' Darwin ' :
MONOSPACE_FONT = ' Monaco '
else :
MONOSPACE_FONT = ' monospace '
2014-06-13 07:25:25 -07:00
# status of payment requests
PR_UNPAID = 0
PR_EXPIRED = 1
PR_SENT = 2 # sent but not propagated
PR_PAID = 3 # send and propagated
PR_ERROR = 4 # could not parse
2013-03-02 03:26:21 -08:00
from electrum import ELECTRUM_VERSION
2013-01-15 12:31:21 -08:00
import re
2014-07-12 09:09:31 -07:00
from util import MyTreeWidget , HelpButton , EnterButton , line_dialog , text_dialog , ok_cancel_buttons , close_button , WaitingDialog
2013-04-28 04:47:19 -07:00
2013-01-15 12:31:21 -08:00
2014-06-12 02:27:18 -07:00
def format_status ( x ) :
if x == PR_UNPAID :
return _ ( ' Unpaid ' )
elif x == PR_PAID :
return _ ( ' Paid ' )
2014-06-13 07:53:43 -07:00
elif x == PR_EXPIRED :
return _ ( ' Expired ' )
2012-06-10 08:47:27 -07:00
2012-06-09 13:23:56 -07:00
2012-02-13 12:36:41 -08:00
class StatusBarButton ( QPushButton ) :
def __init__ ( self , icon , tooltip , func ) :
QPushButton . __init__ ( self , icon , ' ' )
self . setToolTip ( tooltip )
self . setFlat ( True )
self . setMaximumWidth ( 25 )
self . clicked . connect ( func )
self . func = func
2013-09-04 23:02:54 -07:00
self . setIconSize ( QSize ( 25 , 25 ) )
2012-02-13 12:36:41 -08:00
def keyPressEvent ( self , e ) :
if e . key ( ) == QtCore . Qt . Key_Return :
apply ( self . func , ( ) )
2012-02-11 04:14:12 -08:00
2012-05-01 08:06:14 -07:00
2012-11-29 07:14:07 -08:00
2012-11-28 06:38:44 -08:00
2012-02-14 07:41:09 -08:00
2012-02-14 00:52:03 -08:00
2013-03-13 06:23:10 -07:00
2013-10-04 06:05:59 -07:00
default_column_widths = { " history " : [ 40 , 140 , 350 , 140 ] , " contacts " : [ 350 , 330 ] , " receive " : [ 370 , 200 , 130 ] }
2013-01-12 02:23:35 -08:00
2012-02-12 00:52:26 -08:00
class ElectrumWindow ( QMainWindow ) :
2014-04-25 01:31:34 -07:00
2014-04-25 02:22:16 -07:00
def __init__ ( self , config , network , gui_object ) :
2012-02-11 08:38:44 -08:00
QMainWindow . __init__ ( self )
2013-09-01 06:26:52 -07:00
self . config = config
2013-09-09 04:33:25 -07:00
self . network = network
2014-05-07 09:10:14 -07:00
self . gui_object = gui_object
2014-04-25 02:22:16 -07:00
self . tray = gui_object . tray
self . go_lite = gui_object . go_lite
2013-01-05 04:44:20 -08:00
self . lite = None
2013-11-10 09:11:26 -08:00
2014-04-25 01:31:34 -07:00
self . create_status_bar ( )
2013-04-27 10:17:36 -07:00
self . need_update = threading . Event ( )
2012-04-07 06:13:18 -07:00
2014-04-23 23:38:01 -07:00
self . decimal_point = config . get ( ' decimal_point ' , 5 )
2013-09-01 06:26:52 -07:00
self . num_zeros = int ( config . get ( ' num_zeros ' , 0 ) )
2014-06-07 03:45:56 -07:00
self . invoices = { }
2012-10-11 11:10:12 -07:00
2013-03-02 03:26:21 -08:00
set_language ( config . get ( ' language ' ) )
2012-06-12 02:32:12 -07:00
self . completions = QStringListModel ( )
2012-02-11 13:19:22 -08:00
2012-02-13 08:16:02 -08:00
self . tabs = tabs = QTabWidget ( self )
2013-10-07 08:15:24 -07:00
self . column_widths = self . config . get ( " column_widths_2 " , default_column_widths )
2012-05-18 06:28:55 -07:00
tabs . addTab ( self . create_history_tab ( ) , _ ( ' History ' ) )
2012-12-05 09:18:47 -08:00
tabs . addTab ( self . create_send_tab ( ) , _ ( ' Send ' ) )
2012-05-18 06:28:55 -07:00
tabs . addTab ( self . create_receive_tab ( ) , _ ( ' Receive ' ) )
2014-06-14 07:15:00 -07:00
tabs . addTab ( self . create_addresses_tab ( ) , _ ( ' Addresses ' ) )
2012-05-18 06:28:55 -07:00
tabs . addTab ( self . create_contacts_tab ( ) , _ ( ' Contacts ' ) )
2014-06-06 07:16:14 -07:00
tabs . addTab ( self . create_invoices_tab ( ) , _ ( ' Invoices ' ) )
2013-02-26 04:56:48 -08:00
tabs . addTab ( self . create_console_tab ( ) , _ ( ' Console ' ) )
2012-02-11 13:19:22 -08:00
tabs . setMinimumSize ( 600 , 400 )
2012-02-13 10:02:48 -08:00
tabs . setSizePolicy ( QSizePolicy . Expanding , QSizePolicy . Expanding )
2012-02-12 00:52:26 -08:00
self . setCentralWidget ( tabs )
2012-10-11 11:10:12 -07:00
g = self . config . get ( " winpos-qt " , [ 100 , 100 , 840 , 400 ] )
2012-09-20 20:53:14 -07:00
self . setGeometry ( g [ 0 ] , g [ 1 ] , g [ 2 ] , g [ 3 ] )
2014-05-04 12:58:02 -07:00
if self . config . get ( " is_maximized " ) :
self . showMaximized ( )
2012-02-11 08:38:44 -08:00
2013-11-05 14:34:58 -08:00
self . setWindowIcon ( QIcon ( " :icons/electrum.png " ) )
2013-05-15 01:53:49 -07:00
self . init_menubar ( )
QShortcut ( QKeySequence ( " Ctrl+W " ) , self , self . close )
2013-12-17 13:20:24 -08:00
QShortcut ( QKeySequence ( " Ctrl+Q " ) , self , self . close )
2013-05-31 08:12:51 -07:00
QShortcut ( QKeySequence ( " Ctrl+R " ) , self , self . update_wallet )
2013-05-15 01:53:49 -07:00
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 ( ) ) )
2013-11-29 12:27:48 -08:00
2013-11-30 11:03:51 -08:00
for i in range ( tabs . count ( ) ) :
QShortcut ( QKeySequence ( " Alt+ " + str ( i + 1 ) ) , self , lambda i = i : tabs . setCurrentIndex ( i ) )
2013-05-15 01:53:49 -07:00
self . connect ( self , QtCore . SIGNAL ( ' update_status ' ) , self . update_status )
2013-09-11 23:41:27 -07:00
self . connect ( self , QtCore . SIGNAL ( ' banner_signal ' ) , lambda : self . console . showMessage ( self . network . banner ) )
2013-05-31 13:24:04 -07:00
self . connect ( self , QtCore . SIGNAL ( ' transaction_signal ' ) , lambda : self . notify_transactions ( ) )
2014-05-07 06:26:38 -07:00
self . connect ( self , QtCore . SIGNAL ( ' payment_request_ok ' ) , self . payment_request_ok )
2014-05-07 09:10:14 -07:00
self . connect ( self , QtCore . SIGNAL ( ' payment_request_error ' ) , self . payment_request_error )
2013-09-10 12:53:26 -07:00
2013-05-15 01:53:49 -07:00
self . history_list . setFocus ( True )
2013-09-27 12:53:57 -07:00
# network callbacks
2013-11-05 09:55:53 -08:00
if self . network :
self . network . register_callback ( ' updated ' , lambda : self . need_update . set ( ) )
self . network . register_callback ( ' banner ' , lambda : self . emit ( QtCore . SIGNAL ( ' banner_signal ' ) ) )
2014-07-24 14:14:47 -07:00
self . network . register_callback ( ' status ' , lambda : self . emit ( QtCore . SIGNAL ( ' update_status ' ) ) )
2013-11-05 09:55:53 -08:00
self . network . register_callback ( ' new_transaction ' , lambda : self . emit ( QtCore . SIGNAL ( ' transaction_signal ' ) ) )
2014-07-30 22:47:59 -07:00
self . network . register_callback ( ' stop ' , self . close )
2013-11-05 09:55:53 -08:00
# set initial message
self . console . showMessage ( self . network . banner )
2013-09-27 12:53:57 -07:00
2013-09-28 02:21:25 -07:00
self . wallet = None
2014-06-13 08:51:11 -07:00
self . payment_request = None
2014-07-31 01:10:14 -07:00
self . qr_window = None
2013-09-01 06:26:52 -07:00
2013-10-10 04:59:21 -07:00
def update_account_selector ( self ) :
# account selector
accounts = self . wallet . get_account_names ( )
self . account_selector . clear ( )
if len ( accounts ) > 1 :
self . account_selector . addItems ( [ _ ( " All accounts " ) ] + accounts . values ( ) )
self . account_selector . setCurrentIndex ( 0 )
self . account_selector . show ( )
else :
self . account_selector . hide ( )
2013-09-01 06:26:52 -07:00
2013-08-30 01:11:10 -07:00
def load_wallet ( self , wallet ) :
import electrum
2014-06-01 23:59:41 -07:00
2013-08-30 01:11:10 -07:00
self . wallet = wallet
2014-06-01 23:59:41 -07:00
self . update_wallet_format ( )
2014-06-07 03:45:56 -07:00
self . invoices = self . wallet . storage . get ( ' invoices ' , { } )
2013-10-05 05:30:02 -07:00
self . accounts_expanded = self . wallet . storage . get ( ' accounts_expanded ' , { } )
2013-10-05 08:29:51 -07:00
self . current_account = self . wallet . storage . get ( " current_account " , None )
2013-09-01 09:16:15 -07:00
title = ' Electrum ' + self . wallet . electrum_version + ' - ' + self . wallet . storage . path
2013-10-01 08:33:39 -07:00
if self . wallet . is_watching_only ( ) : title + = ' [ %s ] ' % ( _ ( ' watching only ' ) )
2013-08-30 01:11:10 -07:00
self . setWindowTitle ( title )
self . update_wallet ( )
2013-06-17 06:12:20 -07:00
# Once GUI has been initialized check if we want to announce something since the callback has been called before the GUI was initialized
self . notify_transactions ( )
2013-10-10 04:59:21 -07:00
self . update_account_selector ( )
2014-05-01 03:19:24 -07:00
# update menus
self . new_account_menu . setEnabled ( self . wallet . can_create_accounts ( ) )
self . private_keys_menu . setEnabled ( not self . wallet . is_watching_only ( ) )
2014-08-19 01:36:55 -07:00
self . password_menu . setEnabled ( self . wallet . can_change_password ( ) )
2014-05-01 03:19:24 -07:00
self . seed_menu . setEnabled ( self . wallet . has_seed ( ) )
self . mpk_menu . setEnabled ( self . wallet . is_deterministic ( ) )
2014-05-07 06:26:38 -07:00
self . import_menu . setEnabled ( self . wallet . can_import ( ) )
2014-05-01 03:19:24 -07:00
2013-08-30 12:44:16 -07:00
self . update_lock_icon ( )
self . update_buttons_on_seed ( )
2013-08-30 13:59:36 -07:00
self . update_console ( )
2013-08-05 08:15:01 -07:00
2014-06-16 08:02:20 -07:00
self . clear_receive_tab ( )
self . update_receive_tab ( )
2013-09-29 01:52:47 -07:00
run_hook ( ' load_wallet ' , wallet )
2013-09-02 13:43:58 -07:00
2013-05-15 01:53:49 -07:00
2014-06-01 23:59:41 -07:00
def update_wallet_format ( self ) :
# convert old-format imported keys
if self . wallet . imported_keys :
password = self . password_dialog ( _ ( " Please enter your password in order to update imported keys " ) )
try :
self . wallet . convert_imported_keys ( password )
except :
self . show_message ( " error " )
2013-08-22 03:39:41 -07:00
def open_wallet ( self ) :
2013-11-11 09:56:28 -08:00
wallet_folder = self . wallet . storage . path
filename = unicode ( QFileDialog . getOpenFileName ( self , " Select your wallet file " , wallet_folder ) )
2013-08-30 01:11:10 -07:00
if not filename :
return
2013-09-01 06:26:52 -07:00
storage = WalletStorage ( { ' wallet_path ' : filename } )
if not storage . file_exists :
2013-08-30 01:11:10 -07:00
self . show_message ( " file not found " + filename )
return
2013-09-01 09:44:19 -07:00
self . wallet . stop_threads ( )
2013-11-29 12:27:48 -08:00
# create new wallet
2013-09-01 06:26:52 -07:00
wallet = Wallet ( storage )
2013-09-13 05:43:53 -07:00
wallet . start_threads ( self . network )
2013-08-30 01:11:10 -07:00
self . load_wallet ( wallet )
2013-08-22 03:39:41 -07:00
2013-09-13 06:08:40 -07:00
def backup_wallet ( self ) :
import shutil
path = self . wallet . storage . path
wallet_folder = os . path . dirname ( path )
2013-11-11 09:56:28 -08:00
filename = unicode ( QFileDialog . getSaveFileName ( self , _ ( ' Enter a filename for the copy of your wallet ' ) , wallet_folder ) )
if not filename :
2013-09-13 06:08:40 -07:00
return
2013-11-11 09:56:28 -08:00
new_path = os . path . join ( wallet_folder , filename )
2013-09-13 06:08:40 -07:00
if new_path != path :
try :
shutil . copy2 ( path , new_path )
QMessageBox . information ( None , " Wallet backup created " , _ ( " A copy of your wallet file was created in " ) + " ' %s ' " % str ( new_path ) )
except ( IOError , os . error ) , reason :
QMessageBox . critical ( None , " Unable to create backup " , _ ( " Electrum was unable to copy your wallet file to the specified location. " ) + " \n " + str ( reason ) )
2013-08-22 03:39:41 -07:00
def new_wallet ( self ) :
2013-08-30 01:11:10 -07:00
import installwizard
2013-08-22 03:39:41 -07:00
2013-09-13 06:08:40 -07:00
wallet_folder = os . path . dirname ( self . wallet . storage . path )
2014-07-11 10:29:18 -07:00
i = 1
while True :
filename = " wallet_ %d " % i
if filename in os . listdir ( wallet_folder ) :
i + = 1
else :
break
filename = line_dialog ( self , _ ( ' New Wallet ' ) , _ ( ' Enter file name ' ) + ' : ' , _ ( ' OK ' ) , filename )
2013-11-11 09:56:28 -08:00
if not filename :
2013-09-13 06:08:40 -07:00
return
2013-08-30 01:11:10 -07:00
2014-07-11 10:29:18 -07:00
full_path = os . path . join ( wallet_folder , filename )
storage = WalletStorage ( { ' wallet_path ' : full_path } )
2013-11-11 10:05:32 -08:00
if storage . file_exists :
QMessageBox . critical ( None , " Error " , _ ( " File exists " ) )
return
2013-08-30 01:11:10 -07:00
2013-09-12 05:58:42 -07:00
wizard = installwizard . InstallWizard ( self . config , self . network , storage )
2014-05-01 05:55:29 -07:00
wallet = wizard . run ( ' new ' )
2013-11-29 12:27:48 -08:00
if wallet :
2013-08-22 03:39:41 -07:00
self . load_wallet ( wallet )
2013-11-12 13:55:42 -08:00
2013-05-31 04:45:59 -07:00
2013-05-15 01:53:49 -07:00
def init_menubar ( self ) :
2013-04-21 12:53:08 -07:00
menubar = QMenuBar ( )
2013-08-30 13:15:49 -07:00
file_menu = menubar . addMenu ( _ ( " &File " ) )
2014-03-04 07:49:31 -08:00
file_menu . addAction ( _ ( " &Open " ) , self . open_wallet ) . setShortcut ( QKeySequence . Open )
file_menu . addAction ( _ ( " &New/Restore " ) , self . new_wallet ) . setShortcut ( QKeySequence . New )
file_menu . addAction ( _ ( " &Save Copy " ) , self . backup_wallet ) . setShortcut ( QKeySequence . SaveAs )
file_menu . addAction ( _ ( " &Quit " ) , self . close )
2013-04-21 12:53:08 -07:00
2013-08-30 13:15:49 -07:00
wallet_menu = menubar . addMenu ( _ ( " &Wallet " ) )
2014-03-04 07:49:31 -08:00
wallet_menu . addAction ( _ ( " &New contact " ) , self . new_contact_dialog )
2014-05-01 03:19:24 -07:00
self . new_account_menu = wallet_menu . addAction ( _ ( " &New account " ) , self . new_account_dialog )
2013-04-21 12:53:08 -07:00
2013-08-30 13:15:49 -07:00
wallet_menu . addSeparator ( )
2014-05-01 03:19:24 -07:00
self . password_menu = wallet_menu . addAction ( _ ( " &Password " ) , self . change_password_dialog )
self . seed_menu = wallet_menu . addAction ( _ ( " &Seed " ) , self . show_seed_dialog )
self . mpk_menu = wallet_menu . addAction ( _ ( " &Master Public Keys " ) , self . show_master_public_keys )
2013-05-31 04:45:59 -07:00
2013-09-23 01:53:04 -07:00
wallet_menu . addSeparator ( )
2013-10-02 06:55:09 -07:00
labels_menu = wallet_menu . addMenu ( _ ( " &Labels " ) )
2014-03-04 07:49:31 -08:00
labels_menu . addAction ( _ ( " &Import " ) , self . do_import_labels )
labels_menu . addAction ( _ ( " &Export " ) , self . do_export_labels )
2013-09-04 01:57:15 -07:00
2014-05-01 03:19:24 -07:00
self . private_keys_menu = wallet_menu . addMenu ( _ ( " &Private keys " ) )
2014-05-01 08:35:01 -07:00
self . private_keys_menu . addAction ( _ ( " &Sweep " ) , self . sweep_key_dialog )
2014-05-05 03:03:01 -07:00
self . import_menu = self . private_keys_menu . addAction ( _ ( " &Import " ) , self . do_import_privkey )
2014-05-01 07:33:56 -07:00
self . private_keys_menu . addAction ( _ ( " &Export " ) , self . export_privkeys_dialog )
2014-05-05 02:31:04 -07:00
wallet_menu . addAction ( _ ( " &Export History " ) , self . export_history_dialog )
2013-05-31 04:45:59 -07:00
2013-09-23 01:53:04 -07:00
tools_menu = menubar . addMenu ( _ ( " &Tools " ) )
2013-04-21 12:53:08 -07:00
2013-09-23 01:53:04 -07:00
# Settings / Preferences are all reserved keywords in OSX using this as work around
2014-03-04 07:49:31 -08:00
tools_menu . addAction ( _ ( " Electrum preferences " ) if sys . platform == ' darwin ' else _ ( " Preferences " ) , self . settings_dialog )
2014-03-03 01:39:10 -08:00
tools_menu . addAction ( _ ( " &Network " ) , self . run_network_dialog )
tools_menu . addAction ( _ ( " &Plugins " ) , self . plugins_dialog )
2014-03-02 23:57:30 -08:00
tools_menu . addSeparator ( )
2014-03-03 01:39:10 -08:00
tools_menu . addAction ( _ ( " &Sign/verify message " ) , self . sign_verify_message )
2014-06-11 10:30:43 -07:00
tools_menu . addAction ( _ ( " &Encrypt/decrypt message " ) , self . encrypt_message )
2014-03-03 01:39:10 -08:00
tools_menu . addSeparator ( )
2014-03-02 10:08:11 -08:00
2013-10-02 06:55:09 -07:00
csv_transaction_menu = tools_menu . addMenu ( _ ( " &Create transaction " ) )
2014-03-04 07:49:31 -08:00
csv_transaction_menu . addAction ( _ ( " &From CSV file " ) , self . do_process_from_csv_file )
csv_transaction_menu . addAction ( _ ( " &From CSV text " ) , self . do_process_from_csv_text )
2013-10-02 06:55:09 -07:00
raw_transaction_menu = tools_menu . addMenu ( _ ( " &Load transaction " ) )
2014-03-04 07:49:31 -08:00
raw_transaction_menu . addAction ( _ ( " &From file " ) , self . do_process_from_file )
raw_transaction_menu . addAction ( _ ( " &From text " ) , self . do_process_from_text )
raw_transaction_menu . addAction ( _ ( " &From the blockchain " ) , self . do_process_from_txid )
2014-07-12 09:39:28 -07:00
raw_transaction_menu . addAction ( _ ( " &From QR code " ) , self . read_tx_from_qrcode )
2014-06-12 13:24:10 -07:00
self . raw_transaction_menu = raw_transaction_menu
2013-04-21 12:53:08 -07:00
help_menu = menubar . addMenu ( _ ( " &Help " ) )
2014-03-04 07:49:31 -08:00
help_menu . addAction ( _ ( " &About " ) , self . show_about )
help_menu . addAction ( _ ( " &Official website " ) , lambda : webbrowser . open ( " http://electrum.org " ) )
2013-09-11 07:21:44 -07:00
help_menu . addSeparator ( )
2014-03-04 07:49:31 -08:00
help_menu . addAction ( _ ( " &Documentation " ) , lambda : webbrowser . open ( " http://electrum.org/documentation.html " ) ) . setShortcut ( QKeySequence . HelpContents )
help_menu . addAction ( _ ( " &Report Bug " ) , self . show_report_bug )
2013-09-11 07:21:44 -07:00
2013-04-21 12:53:08 -07:00
self . setMenuBar ( menubar )
2013-09-11 07:21:44 -07:00
def show_about ( self ) :
QMessageBox . about ( self , " Electrum " ,
_ ( " Version " ) + " %s " % ( self . wallet . electrum_version ) + " \n \n " + _ ( " Electrum ' s focus is speed, with low resource usage and simplifying Bitcoin. You do not need to perform regular backups, because your wallet can be recovered from a secret phrase that you can memorize or write on paper. Startup times are instant because it operates in conjunction with high-performance servers that handle the most complicated parts of the Bitcoin system. " ) )
def show_report_bug ( self ) :
QMessageBox . information ( self , " Electrum - " + _ ( " Reporting Bugs " ) ,
_ ( " Please report any bugs as issues on github: " ) + " <a href= \" https://github.com/spesmilo/electrum/issues \" >https://github.com/spesmilo/electrum/issues</a> " )
2013-08-22 03:39:41 -07:00
2013-03-12 10:40:21 -07:00
2013-05-31 09:23:51 -07:00
def notify_transactions ( self ) :
2013-11-29 12:27:48 -08:00
if not self . network or not self . network . is_connected ( ) :
2013-10-04 06:55:10 -07:00
return
2013-06-17 06:12:20 -07:00
print_error ( " Notifying GUI " )
2014-04-17 08:38:21 -07:00
if len ( self . network . pending_transactions_for_notifications ) > 0 :
2013-06-17 06:12:20 -07:00
# Combine the transactions if there are more then three
2014-04-17 08:38:21 -07:00
tx_amount = len ( self . network . pending_transactions_for_notifications )
2013-06-17 06:12:20 -07:00
if ( tx_amount > = 3 ) :
total_amount = 0
2014-04-17 08:38:21 -07:00
for tx in self . network . pending_transactions_for_notifications :
2013-06-17 06:12:20 -07:00
is_relevant , is_mine , v , fee = self . wallet . get_tx_value ( tx )
if ( v > 0 ) :
total_amount + = v
2013-09-16 20:19:23 -07:00
self . notify ( _ ( " %(txs)s new transactions received. Total amount received in the new transactions %(amount)s %(unit)s " ) \
% { ' txs ' : tx_amount , ' amount ' : self . format_amount ( total_amount ) , ' unit ' : self . base_unit ( ) } )
2013-06-17 06:12:20 -07:00
2014-04-17 08:38:21 -07:00
self . network . pending_transactions_for_notifications = [ ]
2013-06-17 06:12:20 -07:00
else :
2014-04-17 08:38:21 -07:00
for tx in self . network . pending_transactions_for_notifications :
2013-06-17 06:12:20 -07:00
if tx :
2014-04-17 08:38:21 -07:00
self . network . pending_transactions_for_notifications . remove ( tx )
2013-06-17 06:12:20 -07:00
is_relevant , is_mine , v , fee = self . wallet . get_tx_value ( tx )
if ( v > 0 ) :
2013-09-16 20:19:23 -07:00
self . notify ( _ ( " New transaction received. %(amount)s %(unit)s " ) % { ' amount ' : self . format_amount ( v ) , ' unit ' : self . base_unit ( ) } )
2013-05-31 09:23:51 -07:00
def notify ( self , message ) :
2014-07-27 22:53:02 -07:00
if self . tray :
self . tray . showMessage ( " Electrum " , message , QSystemTrayIcon . Information , 20000 )
2013-03-03 07:01:47 -08:00
2013-09-01 06:26:52 -07:00
2013-03-11 07:57:37 -07:00
# custom wrappers for getOpenFileName and getSaveFileName, that remember the path selected by the user
2013-09-13 06:08:40 -07:00
def getOpenFileName ( self , title , filter = " " ) :
2014-05-01 10:19:57 -07:00
directory = self . config . get ( ' io_dir ' , unicode ( os . path . expanduser ( ' ~ ' ) ) )
2013-03-11 07:57:37 -07:00
fileName = unicode ( QFileDialog . getOpenFileName ( self , title , directory , filter ) )
if fileName and directory != os . path . dirname ( fileName ) :
self . config . set_key ( ' io_dir ' , os . path . dirname ( fileName ) , True )
return fileName
2013-09-13 06:08:40 -07:00
def getSaveFileName ( self , title , filename , filter = " " ) :
2014-05-01 10:19:57 -07:00
directory = self . config . get ( ' io_dir ' , unicode ( os . path . expanduser ( ' ~ ' ) ) )
2013-03-11 07:57:37 -07:00
path = os . path . join ( directory , filename )
fileName = unicode ( QFileDialog . getSaveFileName ( self , title , path , filter ) )
if fileName and directory != os . path . dirname ( fileName ) :
self . config . set_key ( ' io_dir ' , os . path . dirname ( fileName ) , True )
return fileName
2012-11-28 12:14:12 -08:00
def close ( self ) :
2014-07-31 01:10:14 -07:00
if self . qr_window :
self . qr_window . close ( )
2012-11-28 12:14:12 -08:00
QMainWindow . close ( self )
2013-09-23 07:14:28 -07:00
run_hook ( ' close_main_window ' )
2012-02-12 00:52:26 -08:00
2012-02-11 13:19:22 -08:00
def connect_slots ( self , sender ) :
2012-12-20 05:39:33 -08:00
self . connect ( sender , QtCore . SIGNAL ( ' timersignal ' ) , self . timer_actions )
self . previous_payto_e = ' '
2012-02-14 05:05:58 -08:00
2012-11-29 07:14:07 -08:00
def timer_actions ( self ) :
2013-04-27 10:17:36 -07:00
if self . need_update . is_set ( ) :
self . update_wallet ( )
self . need_update . clear ( )
2014-06-14 09:02:45 -07:00
2013-09-23 07:14:28 -07:00
run_hook ( ' timer_actions ' )
2013-11-29 12:27:48 -08:00
2013-07-13 11:19:52 -07:00
def format_amount ( self , x , is_diff = False , whitespaces = False ) :
2013-09-01 06:26:52 -07:00
return format_satoshis ( x , is_diff , self . num_zeros , self . decimal_point , whitespaces )
2013-04-06 14:34:12 -07:00
2014-06-05 03:40:07 -07:00
def get_decimal_point ( self ) :
return self . decimal_point
2013-04-06 14:34:12 -07:00
def base_unit ( self ) :
2014-06-30 07:40:11 -07:00
assert self . decimal_point in [ 2 , 5 , 8 ]
if self . decimal_point == 2 :
return ' bits '
if self . decimal_point == 5 :
return ' mBTC '
if self . decimal_point == 8 :
return ' BTC '
raise Exception ( ' Unknown base unit ' )
2013-09-23 07:14:28 -07:00
2013-03-04 08:20:38 -08:00
def update_status ( self ) :
2014-09-04 06:45:03 -07:00
if not self . wallet :
return
2013-12-12 22:30:35 -08:00
if self . network is None or not self . network . is_running ( ) :
2013-11-05 09:55:53 -08:00
text = _ ( " Offline " )
icon = QIcon ( " :icons/status_disconnected.png " )
elif self . network . is_connected ( ) :
2014-07-25 07:32:19 -07:00
server_lag = self . network . get_local_height ( ) - self . network . get_server_height ( )
2012-10-25 15:40:19 -07:00
if not self . wallet . up_to_date :
2013-01-30 01:16:00 -08:00
text = _ ( " Synchronizing... " )
2012-03-18 04:38:40 -07:00
icon = QIcon ( " :icons/status_waiting.png " )
2014-07-25 07:32:19 -07:00
elif server_lag > 1 :
text = _ ( " Server is lagging ( %d blocks) " % server_lag )
icon = QIcon ( " :icons/status_lagging.png " )
2012-02-11 13:19:22 -08:00
else :
2013-04-05 07:00:34 -07:00
c , u = self . wallet . get_account_balance ( self . current_account )
2013-04-06 14:34:12 -07:00
text = _ ( " Balance " ) + " : %s " % ( self . format_amount ( c ) ) + self . base_unit ( )
2013-04-08 07:06:56 -07:00
if u : text + = " [ %s unconfirmed] " % ( self . format_amount ( u , True ) . strip ( ) )
2013-09-28 02:21:25 -07:00
2014-03-27 13:30:24 -07:00
# append fiat balance and price from exchange rate plugin
2013-09-28 02:21:25 -07:00
r = { }
2014-03-27 13:30:24 -07:00
run_hook ( ' get_fiat_status_text ' , c + u , r )
2013-09-28 02:21:25 -07:00
quote = r . get ( 0 )
if quote :
2014-03-27 13:30:24 -07:00
text + = " %s " % quote
2013-09-28 02:21:25 -07:00
2014-07-27 22:53:02 -07:00
if self . tray :
self . tray . setToolTip ( text )
2012-02-14 02:33:09 -08:00
icon = QIcon ( " :icons/status_connected.png " )
2012-02-11 13:19:22 -08:00
else :
2013-01-30 01:16:00 -08:00
text = _ ( " Not connected " )
2012-02-14 02:33:09 -08:00
icon = QIcon ( " :icons/status_disconnected.png " )
2012-02-12 08:19:16 -08:00
2013-09-28 02:21:25 -07:00
self . balance_label . setText ( text )
2012-02-12 08:19:16 -08:00
self . status_button . setIcon ( icon )
2012-02-11 13:19:22 -08:00
2013-09-28 02:21:25 -07:00
2013-03-04 08:20:38 -08:00
def update_wallet ( self ) :
self . update_status ( )
2013-11-05 09:55:53 -08:00
if self . wallet . up_to_date or not self . network or not self . network . is_connected ( ) :
2012-02-11 22:27:32 -08:00
self . update_history_tab ( )
2012-02-11 22:45:18 -08:00
self . update_receive_tab ( )
2014-06-14 07:15:00 -07:00
self . update_address_tab ( )
2012-02-11 22:45:18 -08:00
self . update_contacts_tab ( )
2012-06-09 08:18:53 -07:00
self . update_completions ( )
2014-06-06 07:16:14 -07:00
self . update_invoices_tab ( )
2012-02-11 22:27:32 -08:00
2013-11-29 12:27:48 -08:00
2012-02-11 08:02:28 -08:00
def create_history_tab ( self ) :
2012-06-09 13:23:56 -07:00
self . history_list = l = MyTreeWidget ( self )
2012-06-09 08:49:44 -07:00
l . setColumnCount ( 5 )
2013-01-12 02:23:35 -08:00
for i , width in enumerate ( self . column_widths [ ' history ' ] ) :
l . setColumnWidth ( i , width )
2013-01-30 01:16:00 -08:00
l . setHeaderLabels ( [ ' ' , _ ( ' Date ' ) , _ ( ' Description ' ) , _ ( ' Amount ' ) , _ ( ' Balance ' ) ] )
2014-06-17 09:24:46 -07:00
l . itemDoubleClicked . connect ( self . tx_label_clicked )
l . itemChanged . connect ( self . tx_label_changed )
2012-06-09 08:49:44 -07:00
l . customContextMenuRequested . connect ( self . create_history_menu )
return l
2012-11-28 06:38:44 -08:00
2012-06-09 08:49:44 -07:00
def create_history_menu ( self , position ) :
2013-11-29 12:27:48 -08:00
self . history_list . selectedIndexes ( )
2012-06-09 08:49:44 -07:00
item = self . history_list . currentItem ( )
2014-04-24 10:26:48 -07:00
be = self . config . get ( ' block_explorer ' , ' Blockchain.info ' )
if be == ' Blockchain.info ' :
block_explorer = ' https://blockchain.info/tx/ '
elif be == ' Blockr.io ' :
block_explorer = ' https://blockr.io/tx/info/ '
elif be == ' Insight.is ' :
block_explorer = ' http://live.insight.is/tx/ '
2014-08-22 03:53:39 -07:00
elif be == " Blocktrail.com " :
block_explorer = ' https://www.blocktrail.com/tx/ '
2012-06-09 09:06:01 -07:00
if not item : return
2013-01-05 07:49:19 -08:00
tx_hash = str ( item . data ( 0 , Qt . UserRole ) . toString ( ) )
2012-11-16 05:39:31 -08:00
if not tx_hash : return
2012-06-09 08:49:44 -07:00
menu = QMenu ( )
2013-09-14 12:07:54 -07:00
menu . addAction ( _ ( " Copy ID to Clipboard " ) , lambda : self . app . clipboard ( ) . setText ( tx_hash ) )
menu . addAction ( _ ( " Details " ) , lambda : self . show_transaction ( self . wallet . transactions . get ( tx_hash ) ) )
2012-06-09 08:49:44 -07:00
menu . addAction ( _ ( " Edit description " ) , lambda : self . tx_label_clicked ( item , 2 ) )
2014-04-24 10:26:48 -07:00
menu . addAction ( _ ( " View on block explorer " ) , lambda : webbrowser . open ( block_explorer + tx_hash ) )
2012-06-09 08:49:44 -07:00
menu . exec_ ( self . contacts_list . viewport ( ) . mapToGlobal ( position ) )
2012-02-11 22:27:32 -08:00
2012-02-12 09:02:11 -08:00
2013-09-14 12:07:54 -07:00
def show_transaction ( self , tx ) :
import transaction_dialog
d = transaction_dialog . TxDialog ( tx , self )
d . exec_ ( )
2012-02-12 09:02:11 -08:00
2012-02-12 12:41:42 -08:00
def tx_label_clicked ( self , item , column ) :
if column == 2 and item . isSelected ( ) :
self . is_edit = True
item . setFlags ( Qt . ItemIsEditable | Qt . ItemIsSelectable | Qt . ItemIsUserCheckable | Qt . ItemIsEnabled | Qt . ItemIsDragEnabled )
self . history_list . editItem ( item , column )
item . setFlags ( Qt . ItemIsSelectable | Qt . ItemIsUserCheckable | Qt . ItemIsEnabled | Qt . ItemIsDragEnabled )
self . is_edit = False
def tx_label_changed ( self , item , column ) :
2013-11-29 12:27:48 -08:00
if self . is_edit :
2012-02-12 12:41:42 -08:00
return
self . is_edit = True
2013-01-09 01:11:01 -08:00
tx_hash = str ( item . data ( 0 , Qt . UserRole ) . toString ( ) )
2012-11-03 01:17:40 -07:00
tx = self . wallet . transactions . get ( tx_hash )
2012-02-14 14:11:59 -08:00
text = unicode ( item . text ( 2 ) )
2013-11-29 12:27:48 -08:00
self . wallet . set_label ( tx_hash , text )
if text :
2012-02-12 12:41:42 -08:00
item . setForeground ( 2 , QBrush ( QColor ( ' black ' ) ) )
else :
2012-11-05 01:42:57 -08:00
text = self . wallet . get_default_label ( tx_hash )
2012-02-12 12:41:42 -08:00
item . setText ( 2 , text )
item . setForeground ( 2 , QBrush ( QColor ( ' gray ' ) ) )
self . is_edit = False
2012-02-12 09:02:11 -08:00
2012-11-28 06:38:44 -08:00
2012-06-09 08:18:53 -07:00
def edit_label ( self , is_recv ) :
2014-06-22 04:25:30 -07:00
l = self . address_list if is_recv else self . contacts_list
2012-06-09 08:18:53 -07:00
item = l . currentItem ( )
item . setFlags ( Qt . ItemIsEditable | Qt . ItemIsSelectable | Qt . ItemIsUserCheckable | Qt . ItemIsEnabled | Qt . ItemIsDragEnabled )
2013-03-03 11:17:30 -08:00
l . editItem ( item , 1 )
2012-06-09 08:18:53 -07:00
item . setFlags ( Qt . ItemIsSelectable | Qt . ItemIsUserCheckable | Qt . ItemIsEnabled | Qt . ItemIsDragEnabled )
2012-11-28 06:38:44 -08:00
2012-06-07 07:07:49 -07:00
def address_label_clicked ( self , item , column , l , column_addr , column_label ) :
2012-11-28 06:38:44 -08:00
if column == column_label and item . isSelected ( ) :
2013-03-14 08:32:05 -07:00
is_editable = item . data ( 0 , 32 ) . toBool ( )
if not is_editable :
return
2012-06-07 07:07:49 -07:00
addr = unicode ( item . text ( column_addr ) )
2012-06-09 03:23:01 -07:00
label = unicode ( item . text ( column_label ) )
2012-02-12 15:00:33 -08:00
item . setFlags ( Qt . ItemIsEditable | Qt . ItemIsSelectable | Qt . ItemIsUserCheckable | Qt . ItemIsEnabled | Qt . ItemIsDragEnabled )
l . editItem ( item , column )
item . setFlags ( Qt . ItemIsSelectable | Qt . ItemIsUserCheckable | Qt . ItemIsEnabled | Qt . ItemIsDragEnabled )
2012-11-28 06:38:44 -08:00
2012-06-07 07:07:49 -07:00
def address_label_changed ( self , item , column , l , column_addr , column_label ) :
2012-11-28 06:38:44 -08:00
if column == column_label :
addr = unicode ( item . text ( column_addr ) )
text = unicode ( item . text ( column_label ) )
2013-03-14 08:32:05 -07:00
is_editable = item . data ( 0 , 32 ) . toBool ( )
if not is_editable :
return
2013-03-12 09:24:14 -07:00
2013-09-29 03:14:01 -07:00
changed = self . wallet . set_label ( addr , text )
2013-03-14 08:32:05 -07:00
if changed :
self . update_history_tab ( )
self . update_completions ( )
2013-11-29 12:27:48 -08:00
2013-03-03 04:50:08 -08:00
self . current_item_changed ( item )
2012-11-28 22:38:32 -08:00
2013-09-23 07:14:28 -07:00
run_hook ( ' item_changed ' , item , column )
2012-11-28 22:38:32 -08:00
2013-03-03 04:50:08 -08:00
def current_item_changed ( self , a ) :
2013-09-23 07:14:28 -07:00
run_hook ( ' current_item_changed ' , a )
2012-11-28 06:38:44 -08:00
2012-06-09 03:23:01 -07:00
2012-02-12 15:00:33 -08:00
2012-02-11 22:27:32 -08:00
def update_history_tab ( self ) :
2012-11-16 05:39:31 -08:00
2012-02-11 22:27:32 -08:00
self . history_list . clear ( )
2013-04-05 07:00:34 -07:00
for item in self . wallet . get_tx_history ( self . current_account ) :
2012-11-16 05:39:31 -08:00
tx_hash , conf , is_mine , value , fee , balance , timestamp = item
2013-10-15 09:23:47 -07:00
time_str = _ ( " unknown " )
2013-04-27 08:48:27 -07:00
if conf > 0 :
2012-11-15 00:14:24 -08:00
try :
2012-11-16 05:39:31 -08:00
time_str = datetime . datetime . fromtimestamp ( timestamp ) . isoformat ( ' ' ) [ : - 3 ]
2013-11-10 12:30:57 -08:00
except Exception :
2013-10-15 09:23:47 -07:00
time_str = _ ( " error " )
2013-04-27 08:48:27 -07:00
if conf == - 1 :
time_str = ' unverified '
2013-04-27 08:55:44 -07:00
icon = QIcon ( " :icons/unconfirmed.png " )
2013-04-27 08:48:27 -07:00
elif conf == 0 :
2012-02-11 22:27:32 -08:00
time_str = ' pending '
2012-03-18 04:38:40 -07:00
icon = QIcon ( " :icons/unconfirmed.png " )
2013-04-27 08:48:27 -07:00
elif conf < 6 :
icon = QIcon ( " :icons/clock %d .png " % conf )
else :
icon = QIcon ( " :icons/confirmed.png " )
2012-02-12 09:02:11 -08:00
2012-11-16 05:39:31 -08:00
if value is not None :
2013-07-13 11:19:52 -07:00
v_str = self . format_amount ( value , True , whitespaces = True )
2012-11-16 05:39:31 -08:00
else :
v_str = ' -- '
2013-07-13 11:19:52 -07:00
balance_str = self . format_amount ( balance , whitespaces = True )
2013-11-29 12:27:48 -08:00
2012-11-16 05:39:31 -08:00
if tx_hash :
label , is_default_label = self . wallet . get_label ( tx_hash )
else :
label = _ ( ' Pruned transaction outputs ' )
is_default_label = False
item = QTreeWidgetItem ( [ ' ' , time_str , label , v_str , balance_str ] )
2012-03-30 14:44:54 -07:00
item . setFont ( 2 , QFont ( MONOSPACE_FONT ) )
item . setFont ( 3 , QFont ( MONOSPACE_FONT ) )
item . setFont ( 4 , QFont ( MONOSPACE_FONT ) )
2013-01-03 21:25:29 -08:00
if value < 0 :
2013-01-03 21:33:57 -08:00
item . setForeground ( 3 , QBrush ( QColor ( " #BC1E1E " ) ) )
2012-11-16 05:39:31 -08:00
if tx_hash :
2013-01-05 07:49:19 -08:00
item . setData ( 0 , Qt . UserRole , tx_hash )
item . setToolTip ( 0 , " %d %s \n TxId: %s " % ( conf , _ ( ' Confirmations ' ) , tx_hash ) )
2012-02-12 02:51:06 -08:00
if is_default_label :
2012-02-12 12:41:42 -08:00
item . setForeground ( 2 , QBrush ( QColor ( ' grey ' ) ) )
2012-02-12 01:58:38 -08:00
item . setIcon ( 0 , icon )
self . history_list . insertTopLevelItem ( 0 , item )
2013-11-29 12:27:48 -08:00
2012-02-11 22:27:32 -08:00
2012-06-09 14:26:41 -07:00
self . history_list . setCurrentItem ( self . history_list . topLevelItem ( 0 ) )
2014-03-02 18:08:46 -08:00
run_hook ( ' history_tab_update ' )
2012-06-09 14:26:41 -07:00
2012-02-11 08:02:28 -08:00
2014-06-14 07:15:00 -07:00
def create_receive_tab ( self ) :
w = QWidget ( )
grid = QGridLayout ( w )
2014-06-14 09:02:45 -07:00
grid . setColumnMinimumWidth ( 3 , 300 )
grid . setColumnStretch ( 5 , 1 )
2014-06-14 07:15:00 -07:00
self . receive_address_e = QLineEdit ( )
self . receive_address_e . setReadOnly ( True )
grid . addWidget ( QLabel ( _ ( ' Receiving address ' ) ) , 0 , 0 )
2014-06-14 09:02:45 -07:00
grid . addWidget ( self . receive_address_e , 0 , 1 , 1 , 3 )
2014-06-14 07:15:00 -07:00
self . receive_address_e . textChanged . connect ( self . update_receive_qr )
self . receive_message_e = QLineEdit ( )
grid . addWidget ( QLabel ( _ ( ' Message ' ) ) , 1 , 0 )
2014-06-14 09:02:45 -07:00
grid . addWidget ( self . receive_message_e , 1 , 1 , 1 , 3 )
2014-06-14 07:15:00 -07:00
self . receive_message_e . textChanged . connect ( self . update_receive_qr )
self . receive_amount_e = BTCAmountEdit ( self . get_decimal_point )
grid . addWidget ( QLabel ( _ ( ' Requested amount ' ) ) , 2 , 0 )
2014-06-14 09:02:45 -07:00
grid . addWidget ( self . receive_amount_e , 2 , 1 , 1 , 2 )
2014-06-14 07:15:00 -07:00
self . receive_amount_e . textChanged . connect ( self . update_receive_qr )
2014-06-16 08:29:50 -07:00
self . save_request_button = QPushButton ( _ ( ' Save ' ) )
self . save_request_button . clicked . connect ( self . save_payment_request )
grid . addWidget ( self . save_request_button , 3 , 1 )
2014-06-16 08:09:34 -07:00
clear_button = QPushButton ( _ ( ' New ' ) )
2014-06-26 09:55:22 -07:00
clear_button . clicked . connect ( self . new_receive_address )
2014-06-16 08:29:50 -07:00
grid . addWidget ( clear_button , 3 , 2 )
2014-06-14 09:02:45 -07:00
grid . setRowStretch ( 4 , 1 )
2014-06-17 05:58:12 -07:00
self . receive_qr = QRCodeWidget ( fixedSize = 200 )
2014-06-14 09:02:45 -07:00
grid . addWidget ( self . receive_qr , 0 , 4 , 5 , 2 )
2014-07-31 01:10:14 -07:00
self . receive_qr . mousePressEvent = lambda x : self . toggle_qr_window ( )
2014-06-14 09:02:45 -07:00
2014-06-16 09:46:30 -07:00
grid . setRowStretch ( 5 , 1 )
2014-06-16 08:29:50 -07:00
self . receive_requests_label = QLabel ( _ ( ' Saved Requests ' ) )
2014-06-14 09:02:45 -07:00
self . receive_list = MyTreeWidget ( self )
self . receive_list . customContextMenuRequested . connect ( self . receive_list_menu )
2014-06-16 08:02:20 -07:00
self . receive_list . currentItemChanged . connect ( self . receive_item_changed )
2014-06-16 08:29:50 -07:00
self . receive_list . itemClicked . connect ( self . receive_item_changed )
2014-06-16 09:46:30 -07:00
self . receive_list . setHeaderLabels ( [ _ ( ' Address ' ) , _ ( ' Message ' ) , _ ( ' Amount ' ) ] )
self . receive_list . setColumnWidth ( 0 , 340 )
2014-06-16 04:30:33 -07:00
h = self . receive_list . header ( )
h . setStretchLastSection ( False )
h . setResizeMode ( 1 , QHeaderView . Stretch )
2014-06-16 09:46:30 -07:00
grid . addWidget ( self . receive_requests_label , 6 , 0 )
grid . addWidget ( self . receive_list , 7 , 0 , 1 , 6 )
2014-06-14 07:15:00 -07:00
return w
2014-06-16 08:02:20 -07:00
def receive_item_changed ( self , item ) :
if item is None :
return
addr = str ( item . text ( 0 ) )
amount , message = self . receive_requests [ addr ]
self . receive_address_e . setText ( addr )
self . receive_message_e . setText ( message )
self . receive_amount_e . setAmount ( amount )
2014-06-14 09:02:45 -07:00
def receive_list_delete ( self , item ) :
addr = str ( item . text ( 0 ) )
self . receive_requests . pop ( addr )
self . update_receive_tab ( )
2014-06-16 08:09:34 -07:00
self . clear_receive_tab ( )
2014-06-16 08:02:20 -07:00
2014-06-14 09:02:45 -07:00
def receive_list_menu ( self , position ) :
item = self . receive_list . itemAt ( position )
menu = QMenu ( )
2014-07-28 01:17:05 -07:00
menu . addAction ( _ ( " Copy to clipboard " ) , lambda : self . app . clipboard ( ) . setText ( str ( item . text ( 0 ) ) ) )
2014-06-14 09:02:45 -07:00
menu . addAction ( _ ( " Delete " ) , lambda : self . receive_list_delete ( item ) )
menu . exec_ ( self . receive_list . viewport ( ) . mapToGlobal ( position ) )
def save_payment_request ( self ) :
addr = str ( self . receive_address_e . text ( ) )
amount = self . receive_amount_e . get_amount ( )
message = str ( self . receive_message_e . text ( ) )
if not message and not amount :
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' No message or amount ' ) , _ ( ' OK ' ) )
return
self . receive_requests = self . wallet . storage . get ( ' receive_requests ' , { } )
self . receive_requests [ addr ] = ( amount , message )
self . wallet . storage . put ( ' receive_requests ' , self . receive_requests )
self . update_receive_tab ( )
2014-06-26 09:55:22 -07:00
def new_receive_address ( self ) :
domain = self . wallet . get_account_addresses ( self . current_account , include_change = False )
for addr in domain :
2014-07-09 09:38:59 -07:00
if not self . wallet . history . get ( addr ) and addr not in self . receive_requests . keys ( ) :
2014-06-26 09:55:22 -07:00
break
else :
if isinstance ( self . wallet , Imported_Wallet ) :
self . show_message ( _ ( ' No more addresses in your wallet. ' ) )
return
if not self . question ( _ ( " Warning: The next address will not be recovered automatically if you restore your wallet from seed; you may need to add it manually. \n \n This occurs because you have too many unused addresses in your wallet. To avoid this situation, use the existing addresses first. \n \n Create anyway? " ) ) :
return
addr = self . wallet . create_new_address ( self . current_account , False )
self . receive_address_e . setText ( addr )
self . receive_message_e . setText ( ' ' )
self . receive_amount_e . setAmount ( None )
2014-06-14 09:02:45 -07:00
def clear_receive_tab ( self ) :
self . receive_requests = self . wallet . storage . get ( ' receive_requests ' , { } )
domain = self . wallet . get_account_addresses ( self . current_account , include_change = False )
for addr in domain :
2014-07-09 09:23:33 -07:00
if not self . wallet . history . get ( addr ) and addr not in self . receive_requests . keys ( ) :
2014-06-14 09:02:45 -07:00
break
else :
2014-06-26 09:55:22 -07:00
addr = ' '
2014-06-14 09:02:45 -07:00
self . receive_address_e . setText ( addr )
2014-06-16 08:02:20 -07:00
self . receive_message_e . setText ( ' ' )
2014-06-14 09:02:45 -07:00
self . receive_amount_e . setAmount ( None )
2014-07-31 01:10:14 -07:00
def toggle_qr_window ( self ) :
import qrwindow
if not self . qr_window :
self . qr_window = qrwindow . QR_Window ( self )
self . qr_window . setVisible ( True )
self . qr_window_geometry = self . qr_window . geometry ( )
else :
if not self . qr_window . isVisible ( ) :
self . qr_window . setVisible ( True )
self . qr_window . setGeometry ( self . qr_window_geometry )
else :
self . qr_window_geometry = self . qr_window . geometry ( )
self . qr_window . setVisible ( False )
self . update_receive_qr ( )
2014-06-16 08:02:20 -07:00
def receive_at ( self , addr ) :
if not bitcoin . is_address ( addr ) :
return
self . tabs . setCurrentIndex ( 2 )
self . receive_address_e . setText ( addr )
def update_receive_tab ( self ) :
self . receive_requests = self . wallet . storage . get ( ' receive_requests ' , { } )
2014-06-14 09:02:45 -07:00
b = len ( self . receive_requests ) > 0
self . receive_list . setVisible ( b )
self . receive_requests_label . setVisible ( b )
self . receive_list . clear ( )
for address , v in self . receive_requests . items ( ) :
amount , message = v
2014-06-16 09:46:30 -07:00
item = QTreeWidgetItem ( [ address , message , self . format_amount ( amount ) if amount else " " ] )
2014-06-17 09:38:32 -07:00
item . setFont ( 0 , QFont ( MONOSPACE_FONT ) )
2014-06-14 09:02:45 -07:00
self . receive_list . addTopLevelItem ( item )
2014-06-14 07:15:00 -07:00
def update_receive_qr ( self ) :
2014-06-16 04:29:55 -07:00
import urlparse , urllib
2014-06-14 07:15:00 -07:00
addr = str ( self . receive_address_e . text ( ) )
2014-06-16 08:29:50 -07:00
amount = self . receive_amount_e . get_amount ( )
message = unicode ( self . receive_message_e . text ( ) ) . encode ( ' utf8 ' )
self . save_request_button . setEnabled ( ( amount is not None ) or ( message != " " ) )
2014-06-14 07:15:00 -07:00
if addr :
query = [ ]
if amount :
query . append ( ' amount= %s ' % format_satoshis ( amount ) )
if message :
2014-06-16 04:29:55 -07:00
query . append ( ' message= %s ' % urllib . quote ( message ) )
2014-06-14 07:15:00 -07:00
p = urlparse . ParseResult ( scheme = ' bitcoin ' , netloc = ' ' , path = addr , params = ' ' , query = ' & ' . join ( query ) , fragment = ' ' )
url = urlparse . urlunparse ( p )
else :
url = " "
2014-06-17 02:02:46 -07:00
self . receive_qr . setData ( url )
2014-07-31 01:10:14 -07:00
if self . qr_window :
self . qr_window . set_content ( addr , amount , message , url )
2014-06-14 07:15:00 -07:00
2012-02-11 08:02:28 -08:00
def create_send_tab ( self ) :
2012-02-11 22:27:32 -08:00
w = QWidget ( )
2014-06-11 09:10:21 -07:00
self . send_grid = grid = QGridLayout ( w )
2012-02-11 22:27:32 -08:00
grid . setSpacing ( 8 )
2012-02-13 05:52:59 -08:00
grid . setColumnMinimumWidth ( 3 , 300 )
2012-06-12 11:26:37 -07:00
grid . setColumnStretch ( 5 , 1 )
2014-06-03 12:47:27 -07:00
grid . setRowStretch ( 8 , 1 )
2013-04-05 07:00:34 -07:00
2014-06-03 12:53:25 -07:00
from paytoedit import PayToEdit
2014-06-11 05:44:26 -07:00
self . amount_e = BTCAmountEdit ( self . get_decimal_point )
2014-06-14 03:17:44 -07:00
self . payto_e = PayToEdit ( self )
2014-05-10 14:05:49 -07:00
self . payto_help = 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) ' ) )
2012-05-18 06:28:55 -07:00
grid . addWidget ( QLabel ( _ ( ' Pay to ' ) ) , 1 , 0 )
2012-02-14 04:38:47 -08:00
grid . addWidget ( self . payto_e , 1 , 1 , 1 , 3 )
2014-05-10 14:05:49 -07:00
grid . addWidget ( self . payto_help , 1 , 4 )
2012-02-11 22:27:32 -08:00
2012-06-09 03:23:01 -07:00
completer = QCompleter ( )
2012-06-10 12:27:31 -07:00
completer . setCaseSensitivity ( False )
2012-06-09 03:23:01 -07:00
self . payto_e . setCompleter ( completer )
completer . setModel ( self . completions )
2014-06-05 05:49:32 -07:00
self . message_e = MyLineEdit ( )
2014-05-10 14:05:49 -07:00
self . message_help = HelpButton ( _ ( ' Description of the transaction (not mandatory). ' ) + ' \n \n ' + _ ( ' The description is not sent to the recipient of the funds. It is stored in your wallet file, and displayed in the \' History \' tab. ' ) )
2012-05-18 06:28:55 -07:00
grid . addWidget ( QLabel ( _ ( ' Description ' ) ) , 2 , 0 )
2012-02-14 04:38:47 -08:00
grid . addWidget ( self . message_e , 2 , 1 , 1 , 3 )
2014-05-10 14:05:49 -07:00
grid . addWidget ( self . message_help , 2 , 4 )
2012-02-11 22:27:32 -08:00
2013-11-16 07:02:38 -08:00
self . from_label = QLabel ( _ ( ' From ' ) )
grid . addWidget ( self . from_label , 3 , 0 )
2014-06-05 12:55:11 -07:00
self . from_list = MyTreeWidget ( self )
2013-11-14 17:05:45 -08:00
self . from_list . setColumnCount ( 2 )
self . from_list . setColumnWidth ( 0 , 350 )
self . from_list . setColumnWidth ( 1 , 50 )
2014-06-05 12:55:11 -07:00
self . from_list . setHeaderHidden ( True )
2013-11-14 17:05:45 -08:00
self . from_list . setMaximumHeight ( 80 )
2014-06-05 12:55:11 -07:00
self . from_list . setContextMenuPolicy ( Qt . CustomContextMenu )
self . from_list . customContextMenuRequested . connect ( self . from_list_menu )
2013-11-14 17:05:45 -08:00
grid . addWidget ( self . from_list , 3 , 1 , 1 , 3 )
2014-01-08 09:24:30 -08:00
self . set_pay_from ( [ ] )
2013-11-14 17:05:45 -08:00
2014-05-10 14:05:49 -07:00
self . amount_help = HelpButton ( _ ( ' 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. ' ) )
2013-11-14 17:05:45 -08:00
grid . addWidget ( QLabel ( _ ( ' Amount ' ) ) , 4 , 0 )
2013-11-16 07:02:38 -08:00
grid . addWidget ( self . amount_e , 4 , 1 , 1 , 2 )
2014-05-10 14:05:49 -07:00
grid . addWidget ( self . amount_help , 4 , 3 )
2013-11-29 12:27:48 -08:00
2014-08-27 13:49:35 -07:00
self . fee_e_label = QLabel ( _ ( ' Fee ' ) )
2014-06-11 05:44:26 -07:00
self . fee_e = BTCAmountEdit ( self . get_decimal_point )
2014-08-27 13:49:35 -07:00
grid . addWidget ( self . fee_e_label , 5 , 0 )
2013-11-16 07:02:38 -08:00
grid . addWidget ( self . fee_e , 5 , 1 , 1 , 2 )
2014-08-27 13:49:35 -07:00
msg = _ ( ' Bitcoin transactions are in general not free. A transaction fee is paid by the sender of the funds. ' ) + ' \n \n ' \
+ _ ( ' The amount of fee can be decided freely by the sender. However, transactions with low fees take more time to be processed. ' ) + ' \n \n ' \
+ _ ( ' A suggested fee is automatically added to this field. You may override it. The suggested fee increases with the size of the transaction. ' )
self . fee_e_help = HelpButton ( msg )
grid . addWidget ( self . fee_e_help , 5 , 3 )
self . update_fee_edit ( )
2013-08-30 01:11:10 -07:00
2013-08-30 12:44:16 -07:00
self . send_button = EnterButton ( _ ( " Send " ) , self . do_send )
grid . addWidget ( self . send_button , 6 , 1 )
2012-02-13 05:52:59 -08:00
2014-06-03 12:47:27 -07:00
b = EnterButton ( _ ( " Clear " ) , self . do_clear )
2012-06-13 02:51:01 -07:00
grid . addWidget ( b , 6 , 2 )
2012-02-12 15:00:33 -08:00
2012-02-14 04:38:47 -08:00
self . payto_sig = QLabel ( ' ' )
2012-06-13 02:51:01 -07:00
grid . addWidget ( self . payto_sig , 7 , 0 , 1 , 4 )
2012-02-14 04:38:47 -08:00
2014-06-05 12:55:11 -07:00
#QShortcut(QKeySequence("Up"), w, w.focusPreviousChild)
#QShortcut(QKeySequence("Down"), w, w.focusNextChild)
2013-11-29 12:27:48 -08:00
w . setLayout ( grid )
2012-02-11 22:27:32 -08:00
2012-02-14 05:34:19 -08:00
def entry_changed ( is_fee ) :
2013-04-05 09:03:52 -07:00
2013-04-07 13:08:56 -07:00
if self . amount_e . is_shortcut :
self . amount_e . is_shortcut = False
2013-11-14 20:07:25 -08:00
sendable = self . get_sendable_balance ( )
2014-03-05 00:35:54 -08:00
# there is only one output because we are completely spending inputs
2014-06-05 12:55:11 -07:00
inputs , total , fee = self . wallet . choose_tx_inputs ( sendable , 0 , 1 , coins = self . get_coins ( ) )
2014-03-05 00:35:54 -08:00
fee = self . wallet . estimated_fee ( inputs , 1 )
2013-11-04 01:16:48 -08:00
amount = total - fee
2014-06-12 00:25:04 -07:00
self . amount_e . setAmount ( amount )
2014-06-24 08:44:31 -07:00
self . amount_e . textEdited . emit ( " " )
2014-06-12 00:25:04 -07:00
self . fee_e . setAmount ( fee )
2013-04-05 09:03:52 -07:00
return
2013-11-29 12:27:48 -08:00
2014-06-05 03:40:07 -07:00
amount = self . amount_e . get_amount ( )
fee = self . fee_e . get_amount ( )
2014-06-26 01:40:33 -07:00
outputs = self . payto_e . get_outputs ( )
if not is_fee :
fee = None
2013-04-06 14:34:12 -07:00
2012-02-14 05:34:19 -08:00
if amount is None :
2014-06-24 09:02:19 -07:00
self . fee_e . setAmount ( None )
2014-06-26 01:40:33 -07:00
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 :
2012-02-14 05:34:19 -08:00
palette = QPalette ( )
palette . setColor ( self . amount_e . foregroundRole ( ) , QColor ( ' black ' ) )
2013-05-10 05:12:33 -07:00
text = " "
2012-02-14 05:34:19 -08:00
else :
palette = QPalette ( )
palette . setColor ( self . amount_e . foregroundRole ( ) , QColor ( ' red ' ) )
2013-01-06 06:11:20 -08:00
text = _ ( " Not enough funds " )
2013-04-12 05:29:11 -07:00
c , u = self . wallet . get_frozen_balance ( )
2014-03-26 09:47:22 -07:00
if c + u : text + = ' ( ' + self . format_amount ( c + u ) . strip ( ) + ' ' + self . base_unit ( ) + ' ' + _ ( " are frozen " ) + ' ) '
2013-01-06 06:11:20 -08:00
self . statusBar ( ) . showMessage ( text )
2012-02-14 05:34:19 -08:00
self . amount_e . setPalette ( palette )
self . fee_e . setPalette ( palette )
self . amount_e . textChanged . connect ( lambda : entry_changed ( False ) )
self . fee_e . textChanged . connect ( lambda : entry_changed ( True ) )
2013-09-23 07:14:28 -07:00
run_hook ( ' create_send_tab ' , grid )
2014-06-03 12:47:27 -07:00
return w
2012-02-11 08:02:28 -08:00
2014-08-27 13:49:35 -07:00
def update_fee_edit ( self ) :
b = self . config . get ( ' can_edit_fees ' , False )
self . fee_e . setVisible ( b )
self . fee_e_label . setVisible ( b )
self . fee_e_help . setVisible ( b )
2014-06-05 12:55:11 -07:00
def from_list_delete ( self , item ) :
i = self . from_list . indexOfTopLevelItem ( item )
self . pay_from . pop ( i )
self . redraw_from_list ( )
2012-06-09 03:23:01 -07:00
2014-06-05 12:55:11 -07:00
def from_list_menu ( self , position ) :
item = self . from_list . itemAt ( position )
menu = QMenu ( )
menu . addAction ( _ ( " Remove " ) , lambda : self . from_list_delete ( item ) )
menu . exec_ ( self . from_list . viewport ( ) . mapToGlobal ( position ) )
def set_pay_from ( self , domain = None ) :
self . pay_from = [ ] if domain == [ ] else self . wallet . get_unspent_coins ( domain )
self . redraw_from_list ( )
def redraw_from_list ( self ) :
2013-11-14 17:05:45 -08:00
self . from_list . clear ( )
2013-11-16 07:02:38 -08:00
self . from_label . setHidden ( len ( self . pay_from ) == 0 )
self . from_list . setHidden ( len ( self . pay_from ) == 0 )
2013-11-14 17:05:45 -08:00
2014-06-05 12:55:11 -07:00
def format ( x ) :
h = x . get ( ' prevout_hash ' )
return h [ 0 : 8 ] + ' ... ' + h [ - 8 : ] + " : %d " % x . get ( ' prevout_n ' ) + u ' \t ' + " %s " % x . get ( ' address ' )
for item in self . pay_from :
self . from_list . addTopLevelItem ( QTreeWidgetItem ( [ format ( item ) , self . format_amount ( item [ ' value ' ] ) ] ) )
2013-11-14 17:05:45 -08:00
2012-06-09 03:23:01 -07:00
def update_completions ( self ) :
l = [ ]
for addr , label in self . wallet . labels . items ( ) :
if addr in self . wallet . addressbook :
l . append ( label + ' < ' + addr + ' > ' )
2013-09-23 07:14:28 -07:00
run_hook ( ' update_completions ' , l )
2012-06-09 03:23:01 -07:00
self . completions . setStringList ( l )
2013-03-04 22:55:43 -08:00
def protected ( func ) :
return lambda s , * args : s . do_protect ( func , args )
2012-06-09 03:23:01 -07:00
2013-03-04 22:55:43 -08:00
2014-06-12 08:31:18 -07:00
def read_send_tab ( self ) :
2014-06-13 07:39:07 -07:00
if self . payment_request and self . payment_request . has_expired ( ) :
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Payment request has expired ' ) , _ ( ' OK ' ) )
return
2012-02-14 14:11:59 -08:00
label = unicode ( self . message_e . text ( ) )
2012-02-13 07:49:20 -08:00
2014-06-13 07:02:30 -07:00
if self . payment_request :
outputs = self . payment_request . get_outputs ( )
2014-05-07 06:26:38 -07:00
else :
2014-06-05 03:55:02 -07:00
outputs = self . payto_e . get_outputs ( )
2014-06-05 22:48:08 -07:00
if not outputs :
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' No outputs ' ) , _ ( ' OK ' ) )
return
2014-07-08 10:38:16 -07:00
for type , addr , amount in outputs :
2014-06-27 08:08:20 -07:00
if addr is None :
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Bitcoin Address is None ' ) , _ ( ' OK ' ) )
return
2014-07-08 10:38:16 -07:00
if type == ' op_return ' :
2014-06-27 08:08:20 -07:00
continue
2014-07-08 10:38:16 -07:00
if type == ' address ' and not bitcoin . is_address ( addr ) :
2014-06-05 22:48:08 -07:00
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Invalid Bitcoin Address ' ) , _ ( ' OK ' ) )
return
2014-07-08 10:38:16 -07:00
if amount is None :
2014-06-05 22:48:08 -07:00
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Invalid Amount ' ) , _ ( ' OK ' ) )
return
2014-07-08 10:38:16 -07:00
amount = sum ( map ( lambda x : x [ 2 ] , outputs ) )
2012-02-13 07:49:20 -08:00
2014-06-12 00:15:25 -07:00
fee = self . fee_e . get_amount ( )
if fee is None :
2012-05-18 06:28:55 -07:00
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Invalid Fee ' ) , _ ( ' OK ' ) )
2012-02-13 07:49:20 -08:00
return
2013-07-13 11:47:10 -07:00
confirm_amount = self . config . get ( ' confirm_amount ' , 100000000 )
if amount > = confirm_amount :
2014-07-08 10:38:16 -07:00
o = ' \n ' . join ( map ( lambda x : x [ 1 ] , outputs ) )
2014-06-05 22:17:47 -07:00
if not self . question ( _ ( " send %(amount)s to %(address)s ? " ) % { ' amount ' : self . format_amount ( amount ) + ' ' + self . base_unit ( ) , ' address ' : o } ) :
2013-07-13 11:47:10 -07:00
return
2013-12-16 06:16:10 -08:00
2014-08-27 13:49:35 -07:00
if not self . config . get ( ' can_edit_fees ' , False ) :
if not self . question ( _ ( " A fee of %(fee)s will be added to this transaction. \n Proceed? " ) % { ' fee ' : self . format_amount ( fee ) + ' ' + self . base_unit ( ) } ) :
2013-12-16 06:16:10 -08:00
return
2014-08-27 13:49:35 -07:00
else :
confirm_fee = self . config . get ( ' confirm_fee ' , 100000 )
if fee > = confirm_fee :
if not self . question ( _ ( " The fee for this transaction seems unusually high. \n Are you really sure you want to pay %(fee)s in fees? " ) % { ' fee ' : self . format_amount ( fee ) + ' ' + self . base_unit ( ) } ) :
return
2013-07-13 11:47:10 -07:00
2014-06-12 08:31:18 -07:00
coins = self . get_coins ( )
return outputs , fee , label , coins
2013-07-13 11:47:10 -07:00
2014-06-12 08:31:18 -07:00
def do_send ( self ) :
r = self . read_send_tab ( )
if not r :
return
outputs , fee , label , coins = r
self . send_tx ( outputs , fee , label , coins )
2013-07-13 11:47:10 -07:00
2014-03-28 09:05:34 -07:00
2013-07-13 11:47:10 -07:00
@protected
2014-06-12 08:31:18 -07:00
def send_tx ( self , outputs , fee , label , coins , password ) :
2014-05-29 06:30:23 -07:00
self . send_button . setDisabled ( True )
2014-03-28 09:05:34 -07:00
# first, create an unsigned tx
2012-02-13 07:49:20 -08:00
try :
2014-06-05 12:55:11 -07:00
tx = self . wallet . make_unsigned_transaction ( outputs , fee , None , coins = coins )
2014-03-28 09:37:31 -07:00
tx . error = None
2013-11-09 20:21:02 -08:00
except Exception as e :
2013-08-01 11:08:56 -07:00
traceback . print_exc ( file = sys . stdout )
2012-05-16 10:20:21 -07:00
self . show_message ( str ( e ) )
2014-05-29 06:30:23 -07:00
self . send_button . setDisabled ( False )
2012-02-13 07:49:20 -08:00
return
2012-10-13 23:25:09 -07:00
2014-03-28 09:05:34 -07:00
# call hook to see if plugin needs gui interaction
run_hook ( ' send_tx ' , tx )
2014-04-05 07:52:38 -07:00
# sign the tx
2014-03-28 09:05:34 -07:00
def sign_thread ( ) :
2014-06-30 23:35:28 -07:00
if self . wallet . is_watching_only ( ) :
return tx
2014-03-28 09:05:34 -07:00
keypairs = { }
2014-06-24 10:09:41 -07:00
try :
self . wallet . add_keypairs ( tx , keypairs , password )
self . wallet . sign_transaction ( tx , keypairs , password )
except Exception as e :
2014-07-08 14:53:20 -07:00
traceback . print_exc ( file = sys . stdout )
2014-06-24 10:09:41 -07:00
tx . error = str ( e )
return tx
2014-03-28 09:05:34 -07:00
2014-06-24 10:09:41 -07:00
def sign_done ( tx ) :
2014-05-10 11:36:07 -07:00
if tx . error :
self . show_message ( tx . error )
2014-05-29 06:30:23 -07:00
self . send_button . setDisabled ( False )
2014-05-10 11:36:07 -07:00
return
if tx . requires_fee ( self . wallet . verifier ) and fee < MIN_RELAY_TX_FEE :
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( " This transaction requires a higher fee, or it will not be propagated by the network. " ) , _ ( ' OK ' ) )
2014-05-29 06:30:23 -07:00
self . send_button . setDisabled ( False )
2014-05-10 11:36:07 -07:00
return
if label :
self . wallet . set_label ( tx . hash ( ) , label )
2014-03-28 09:05:34 -07:00
2014-06-05 08:55:27 -07:00
if not tx . is_complete ( ) or self . config . get ( ' show_before_broadcast ' ) :
self . show_transaction ( tx )
self . do_clear ( )
self . send_button . setDisabled ( False )
return
2014-03-28 09:05:34 -07:00
2014-05-10 11:36:07 -07:00
self . broadcast_transaction ( tx )
2014-03-28 09:37:31 -07:00
2014-06-24 10:09:41 -07:00
# keep a reference to WaitingDialog or the gui might crash
2014-05-25 20:40:04 -07:00
self . waiting_dialog = WaitingDialog ( self , ' Signing.. ' , sign_thread , sign_done )
self . waiting_dialog . start ( )
2013-03-23 01:23:57 -07:00
2013-02-27 03:51:49 -08:00
2014-05-10 11:36:07 -07:00
def broadcast_transaction ( self , tx ) :
2014-03-28 09:05:34 -07:00
2014-04-05 07:52:38 -07:00
def broadcast_thread ( ) :
2014-06-13 07:02:30 -07:00
pr = self . payment_request
2014-06-12 06:15:05 -07:00
if pr is None :
return self . wallet . sendtx ( tx )
if pr . has_expired ( ) :
2014-06-13 07:02:30 -07:00
self . payment_request = None
2014-06-12 06:15:05 -07:00
return False , _ ( " Payment request has expired " )
status , msg = self . wallet . sendtx ( tx )
if not status :
return False , msg
2014-06-13 07:53:43 -07:00
self . invoices [ pr . get_id ( ) ] = ( pr . get_domain ( ) , pr . get_memo ( ) , pr . get_amount ( ) , pr . get_expiration_date ( ) , PR_PAID , tx . hash ( ) )
2014-06-12 06:15:05 -07:00
self . wallet . storage . put ( ' invoices ' , self . invoices )
self . update_invoices_tab ( )
2014-06-13 07:02:30 -07:00
self . payment_request = None
2014-06-12 06:15:05 -07:00
refund_address = self . wallet . addresses ( ) [ 0 ]
ack_status , ack_msg = pr . send_ack ( str ( tx ) , refund_address )
if ack_status :
msg = ack_msg
2014-05-10 11:36:07 -07:00
return status , msg
2014-04-05 07:52:38 -07:00
2014-05-10 11:36:07 -07:00
def broadcast_done ( status , msg ) :
if status :
QMessageBox . information ( self , ' ' , _ ( ' Payment sent. ' ) + ' \n ' + msg , _ ( ' OK ' ) )
self . do_clear ( )
else :
QMessageBox . warning ( self , _ ( ' Error ' ) , msg , _ ( ' OK ' ) )
2014-05-29 06:30:23 -07:00
self . send_button . setDisabled ( False )
2014-05-07 06:26:38 -07:00
2014-05-25 20:47:00 -07:00
self . waiting_dialog = WaitingDialog ( self , ' Broadcasting.. ' , broadcast_thread , broadcast_done )
self . waiting_dialog . start ( )
2014-04-05 07:52:38 -07:00
2013-11-12 02:14:16 -08:00
2012-02-13 07:49:20 -08:00
2014-05-07 09:10:14 -07:00
def prepare_for_payment_request ( self ) :
self . tabs . setCurrentIndex ( 1 )
2014-06-06 07:16:14 -07:00
self . payto_e . is_pr = True
2014-05-10 13:43:53 -07:00
for e in [ self . payto_e , self . amount_e , self . message_e ] :
2014-06-05 05:49:32 -07:00
e . setFrozen ( True )
2014-05-10 14:05:49 -07:00
for h in [ self . payto_help , self . amount_help , self . message_help ] :
h . hide ( )
2014-05-07 09:10:14 -07:00
self . payto_e . setText ( _ ( " please wait... " ) )
return True
def payment_request_ok ( self ) :
2014-06-13 07:02:30 -07:00
pr = self . payment_request
2014-06-06 07:16:14 -07:00
pr_id = pr . get_id ( )
2014-06-12 02:27:18 -07:00
if pr_id not in self . invoices :
2014-06-13 07:53:43 -07:00
self . invoices [ pr_id ] = ( pr . get_domain ( ) , pr . get_memo ( ) , pr . get_amount ( ) , pr . get_expiration_date ( ) , PR_UNPAID , None )
2014-06-12 02:27:18 -07:00
self . wallet . storage . put ( ' invoices ' , self . invoices )
self . update_invoices_tab ( )
else :
print_error ( ' invoice already in list ' )
2014-06-13 08:02:58 -07:00
status = self . invoices [ pr_id ] [ 4 ]
2014-06-12 02:27:18 -07:00
if status == PR_PAID :
self . do_clear ( )
self . show_message ( " invoice already paid " )
2014-06-13 07:02:30 -07:00
self . payment_request = None
2014-06-12 02:27:18 -07:00
return
2014-06-06 07:16:14 -07:00
2014-06-05 08:40:58 -07:00
self . payto_help . show ( )
2014-06-07 10:53:54 -07:00
self . payto_help . set_alt ( lambda : self . show_pr_details ( pr ) )
2014-06-13 07:39:07 -07:00
if not pr . has_expired ( ) :
self . payto_e . setGreen ( )
else :
self . payto_e . setExpired ( )
2014-06-05 08:40:58 -07:00
self . payto_e . setText ( pr . domain )
self . amount_e . setText ( self . format_amount ( pr . get_amount ( ) ) )
2014-06-12 02:27:18 -07:00
self . message_e . setText ( pr . get_memo ( ) )
2014-05-07 09:10:14 -07:00
def payment_request_error ( self ) :
2014-05-10 14:05:49 -07:00
self . do_clear ( )
2014-06-13 07:02:30 -07:00
self . show_message ( self . payment_request . error )
self . payment_request = None
2013-09-28 02:45:39 -07:00
2014-06-13 07:02:30 -07:00
def pay_from_URI ( self , URI ) :
2014-06-13 07:08:46 -07:00
if not URI :
return
2014-06-13 07:02:30 -07:00
address , amount , label , message , request_url = util . parse_URI ( URI )
try :
address , amount , label , message , request_url = util . parse_URI ( URI )
except Exception as e :
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Invalid bitcoin URI: ' ) + ' \n ' + str ( e ) , _ ( ' OK ' ) )
return
2013-03-14 08:32:05 -07:00
2012-02-14 04:38:47 -08:00
self . tabs . setCurrentIndex ( 1 )
2012-06-09 09:20:15 -07:00
2014-06-13 07:02:30 -07:00
if not request_url :
if label :
if self . wallet . labels . get ( address ) != label :
if self . question ( _ ( ' Save label " %s " for address %s ? ' % ( label , address ) ) ) :
if address not in self . wallet . addressbook and not self . wallet . is_mine ( address ) :
self . wallet . addressbook . append ( address )
self . wallet . set_label ( address , label )
else :
label = self . wallet . labels . get ( address )
if address :
self . payto_e . setText ( label + ' < ' + address + ' > ' if label else address )
if message :
self . message_e . setText ( message )
if amount :
self . amount_e . setAmount ( amount )
return
from electrum import paymentrequest
def payment_request ( ) :
self . payment_request = paymentrequest . PaymentRequest ( self . config )
self . payment_request . read ( request_url )
if self . payment_request . verify ( ) :
self . emit ( SIGNAL ( ' payment_request_ok ' ) )
else :
self . emit ( SIGNAL ( ' payment_request_error ' ) )
self . pr_thread = threading . Thread ( target = payment_request ) . start ( )
self . prepare_for_payment_request ( )
2013-09-28 02:21:25 -07:00
2012-02-14 04:38:47 -08:00
def do_clear ( self ) :
2014-06-06 07:16:14 -07:00
self . payto_e . is_pr = False
2012-02-14 04:38:47 -08:00
self . payto_sig . setVisible ( False )
for e in [ self . payto_e , self . message_e , self . amount_e , self . fee_e ] :
e . setText ( ' ' )
2014-06-05 05:49:32 -07:00
e . setFrozen ( False )
2014-05-10 14:05:49 -07:00
for h in [ self . payto_help , self . amount_help , self . message_help ] :
h . show ( )
2013-11-14 17:05:45 -08:00
2014-06-05 08:40:58 -07:00
self . payto_help . set_alt ( None )
2014-01-08 09:24:30 -08:00
self . set_pay_from ( [ ] )
2013-04-12 05:15:58 -07:00
self . update_status ( )
2012-02-14 04:38:47 -08:00
2012-02-13 07:49:20 -08:00
2013-11-14 18:10:52 -08:00
def set_addrs_frozen ( self , addrs , freeze ) :
for addr in addrs :
if not addr : continue
if addr in self . wallet . frozen_addresses and not freeze :
self . wallet . unfreeze ( addr )
elif addr not in self . wallet . frozen_addresses and freeze :
self . wallet . freeze ( addr )
2014-06-14 07:15:00 -07:00
self . update_address_tab ( )
2012-06-07 08:36:39 -07:00
2012-06-06 05:55:11 -07:00
def create_list_tab ( self , headers ) :
2012-06-09 13:23:56 -07:00
" generic tab creation method "
l = MyTreeWidget ( self )
2012-06-06 05:55:11 -07:00
l . setColumnCount ( len ( headers ) )
l . setHeaderLabels ( headers )
2012-02-12 01:58:38 -08:00
2012-05-05 02:33:53 -07:00
w = QWidget ( )
2012-02-13 10:02:48 -08:00
vbox = QVBoxLayout ( )
2012-05-05 02:33:53 -07:00
w . setLayout ( vbox )
2012-02-12 03:37:43 -08:00
vbox . setMargin ( 0 )
2012-02-12 08:19:16 -08:00
vbox . setSpacing ( 0 )
2012-02-12 02:26:38 -08:00
vbox . addWidget ( l )
2012-05-05 02:33:53 -07:00
buttons = QWidget ( )
vbox . addWidget ( buttons )
2012-02-12 02:26:38 -08:00
2014-06-07 04:15:52 -07:00
return l , w
2012-05-13 04:09:59 -07:00
2012-06-07 08:36:39 -07:00
2014-06-14 07:15:00 -07:00
def create_addresses_tab ( self ) :
2014-06-07 04:15:52 -07:00
l , w = self . create_list_tab ( [ _ ( ' Address ' ) , _ ( ' Label ' ) , _ ( ' Balance ' ) , _ ( ' Tx ' ) ] )
2014-06-12 13:51:39 -07:00
for i , width in enumerate ( self . column_widths [ ' receive ' ] ) :
l . setColumnWidth ( i , width )
2012-06-07 08:36:39 -07:00
l . setContextMenuPolicy ( Qt . CustomContextMenu )
l . customContextMenuRequested . connect ( self . create_receive_menu )
2013-11-14 17:05:45 -08:00
l . setSelectionMode ( QAbstractItemView . ExtendedSelection )
2014-06-17 09:24:46 -07:00
l . itemDoubleClicked . connect ( lambda a , b : self . address_label_clicked ( a , b , l , 0 , 1 ) )
l . itemChanged . connect ( lambda a , b : self . address_label_changed ( a , b , l , 0 , 1 ) )
l . currentItemChanged . connect ( lambda a , b : self . current_item_changed ( a ) )
2014-06-14 09:02:45 -07:00
self . address_list = l
2012-02-12 15:00:33 -08:00
return w
2012-11-29 01:19:54 -08:00
2012-10-11 03:56:57 -07:00
2013-02-02 01:20:24 -08:00
2013-01-12 02:23:35 -08:00
def save_column_widths ( self ) :
2013-10-04 06:05:59 -07:00
self . column_widths [ " receive " ] = [ ]
2014-06-14 09:02:45 -07:00
for i in range ( self . address_list . columnCount ( ) - 1 ) :
self . column_widths [ " receive " ] . append ( self . address_list . columnWidth ( i ) )
2013-11-29 12:27:48 -08:00
2013-01-12 02:23:35 -08:00
self . column_widths [ " history " ] = [ ]
2013-02-02 01:20:24 -08:00
for i in range ( self . history_list . columnCount ( ) - 1 ) :
2013-01-12 02:23:35 -08:00
self . column_widths [ " history " ] . append ( self . history_list . columnWidth ( i ) )
2013-02-02 01:20:24 -08:00
2013-01-12 02:23:35 -08:00
self . column_widths [ " contacts " ] = [ ]
2013-02-02 01:20:24 -08:00
for i in range ( self . contacts_list . columnCount ( ) - 1 ) :
2013-01-12 02:23:35 -08:00
self . column_widths [ " contacts " ] . append ( self . contacts_list . columnWidth ( i ) )
2012-06-07 08:36:39 -07:00
2013-10-07 08:15:24 -07:00
self . config . set_key ( " column_widths_2 " , self . column_widths , True )
2013-04-13 09:15:55 -07:00
2013-02-02 01:20:24 -08:00
2012-02-12 15:00:33 -08:00
def create_contacts_tab ( self ) :
2014-06-07 04:15:52 -07:00
l , w = self . create_list_tab ( [ _ ( ' Address ' ) , _ ( ' Label ' ) , _ ( ' Tx ' ) ] )
2012-06-07 08:36:39 -07:00
l . setContextMenuPolicy ( Qt . CustomContextMenu )
l . customContextMenuRequested . connect ( self . create_contact_menu )
2013-02-02 01:20:24 -08:00
for i , width in enumerate ( self . column_widths [ ' contacts ' ] ) :
l . setColumnWidth ( i , width )
2014-06-17 09:24:46 -07:00
l . itemDoubleClicked . connect ( lambda a , b : self . address_label_clicked ( a , b , l , 0 , 1 ) )
l . itemChanged . connect ( lambda a , b : self . address_label_changed ( a , b , l , 0 , 1 ) )
2012-02-12 15:00:33 -08:00
self . contacts_list = l
2012-02-12 02:26:38 -08:00
return w
2012-02-12 01:58:38 -08:00
2012-06-07 08:36:39 -07:00
2014-06-06 07:16:14 -07:00
def create_invoices_tab ( self ) :
2014-07-13 14:40:29 -07:00
l , w = self . create_list_tab ( [ _ ( ' Requestor ' ) , _ ( ' Memo ' ) , _ ( ' Date ' ) , _ ( ' Amount ' ) , _ ( ' Status ' ) ] )
2014-06-17 09:24:46 -07:00
l . setColumnWidth ( 0 , 150 )
2014-07-13 14:40:29 -07:00
l . setColumnWidth ( 2 , 150 )
l . setColumnWidth ( 3 , 150 )
2014-06-12 01:20:06 -07:00
h = l . header ( )
h . setStretchLastSection ( False )
h . setResizeMode ( 1 , QHeaderView . Stretch )
2014-06-06 07:16:14 -07:00
l . setContextMenuPolicy ( Qt . CustomContextMenu )
2014-06-07 03:45:56 -07:00
l . customContextMenuRequested . connect ( self . create_invoice_menu )
2014-06-06 07:16:14 -07:00
self . invoices_list = l
return w
def update_invoices_tab ( self ) :
invoices = self . wallet . storage . get ( ' invoices ' , { } )
l = self . invoices_list
l . clear ( )
2014-07-13 14:56:24 -07:00
for key , value in sorted ( invoices . items ( ) , key = lambda x : - x [ 1 ] [ 3 ] ) :
2014-07-13 14:40:29 -07:00
domain , memo , amount , expiration_date , status , tx_hash = value
2014-06-13 07:53:43 -07:00
if status == PR_UNPAID and expiration_date and expiration_date < time . time ( ) :
status = PR_EXPIRED
2014-07-13 14:40:29 -07:00
date_str = datetime . datetime . fromtimestamp ( expiration_date ) . isoformat ( ' ' ) [ : - 3 ]
item = QTreeWidgetItem ( [ domain , memo , date_str , self . format_amount ( amount , whitespaces = True ) , format_status ( status ) ] )
2014-07-13 14:56:24 -07:00
item . setData ( 0 , 32 , key )
2014-07-13 14:40:29 -07:00
item . setFont ( 0 , QFont ( MONOSPACE_FONT ) )
item . setFont ( 3 , QFont ( MONOSPACE_FONT ) )
2014-06-06 07:16:14 -07:00
l . addTopLevelItem ( item )
l . setCurrentItem ( l . topLevelItem ( 0 ) )
2013-01-05 13:24:03 -08:00
def delete_imported_key ( self , addr ) :
2013-01-30 01:16:00 -08:00
if self . question ( _ ( " Do you want to remove " ) + " %s " % addr + _ ( " from your wallet? " ) ) :
2013-05-02 00:54:43 -07:00
self . wallet . delete_imported_key ( addr )
2014-06-14 07:15:00 -07:00
self . update_address_tab ( )
2013-01-05 13:24:03 -08:00
self . update_history_tab ( )
2013-09-24 07:55:25 -07:00
def edit_account_label ( self , k ) :
2013-10-04 10:02:01 -07:00
text , ok = QInputDialog . getText ( self , _ ( ' Rename account ' ) , _ ( ' Name ' ) + ' : ' , text = self . wallet . labels . get ( k , ' ' ) )
2013-09-24 07:55:25 -07:00
if ok :
label = unicode ( text )
2013-09-29 03:14:01 -07:00
self . wallet . set_label ( k , label )
2014-06-14 07:15:00 -07:00
self . update_address_tab ( )
2013-09-24 07:55:25 -07:00
2013-10-05 05:30:02 -07:00
def account_set_expanded ( self , item , k , b ) :
item . setExpanded ( b )
self . accounts_expanded [ k ] = b
2013-09-24 07:55:25 -07:00
def create_account_menu ( self , position , k , item ) :
menu = QMenu ( )
if item . isExpanded ( ) :
2013-10-05 05:30:02 -07:00
menu . addAction ( _ ( " Minimize " ) , lambda : self . account_set_expanded ( item , k , False ) )
2013-09-24 07:55:25 -07:00
else :
2013-10-05 05:30:02 -07:00
menu . addAction ( _ ( " Maximize " ) , lambda : self . account_set_expanded ( item , k , True ) )
2013-09-24 07:55:25 -07:00
menu . addAction ( _ ( " Rename " ) , lambda : self . edit_account_label ( k ) )
2014-03-12 02:04:08 -07:00
if self . wallet . seed_version > 4 :
menu . addAction ( _ ( " View details " ) , lambda : self . show_account_details ( k ) )
2013-10-12 04:55:48 -07:00
if self . wallet . account_is_pending ( k ) :
2013-10-05 08:29:51 -07:00
menu . addAction ( _ ( " Delete " ) , lambda : self . delete_pending_account ( k ) )
2014-06-14 09:02:45 -07:00
menu . exec_ ( self . address_list . viewport ( ) . mapToGlobal ( position ) )
2013-01-05 13:24:03 -08:00
2013-10-05 08:29:51 -07:00
def delete_pending_account ( self , k ) :
2013-10-12 04:55:48 -07:00
self . wallet . delete_pending_account ( k )
2014-06-14 07:15:00 -07:00
self . update_address_tab ( )
2013-10-05 08:29:51 -07:00
2012-06-07 08:36:39 -07:00
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
2014-06-14 09:02:45 -07:00
#self.address_list.selectedIndexes()
2012-06-09 14:52:45 -07:00
2014-06-14 09:02:45 -07:00
selected = self . address_list . selectedItems ( )
2013-11-14 18:10:52 -08:00
multi_select = len ( selected ) > 1
addrs = [ unicode ( item . text ( 0 ) ) for item in selected ]
if not multi_select :
2014-06-14 09:02:45 -07:00
item = self . address_list . itemAt ( position )
2013-11-14 18:10:52 -08:00
if not item : return
addr = addrs [ 0 ]
if not is_valid ( addr ) :
k = str ( item . data ( 0 , 32 ) . toString ( ) )
if k :
self . create_account_menu ( position , k , item )
else :
item . setExpanded ( not item . isExpanded ( ) )
return
2013-09-24 07:55:25 -07:00
2012-06-07 08:36:39 -07:00
menu = QMenu ( )
2013-11-14 18:10:52 -08:00
if not multi_select :
menu . addAction ( _ ( " Copy to clipboard " ) , lambda : self . app . clipboard ( ) . setText ( addr ) )
2014-06-14 07:15:00 -07:00
menu . addAction ( _ ( " Request payment " ) , lambda : self . receive_at ( addr ) )
2013-11-14 18:10:52 -08:00
menu . addAction ( _ ( " Edit label " ) , lambda : self . edit_label ( True ) )
2014-04-05 01:34:51 -07:00
menu . addAction ( _ ( " Public keys " ) , lambda : self . show_public_keys ( addr ) )
2014-05-01 03:42:06 -07:00
if not self . wallet . is_watching_only ( ) :
2013-11-14 18:10:52 -08:00
menu . addAction ( _ ( " Private key " ) , lambda : self . show_private_key ( addr ) )
2014-03-03 01:39:10 -08:00
menu . addAction ( _ ( " Sign/verify message " ) , lambda : self . sign_verify_message ( addr ) )
2014-06-11 10:30:43 -07:00
menu . addAction ( _ ( " Encrypt/decrypt message " ) , lambda : self . encrypt_message ( addr ) )
2014-05-04 10:43:15 -07:00
if self . wallet . is_imported ( addr ) :
2013-11-14 18:10:52 -08:00
menu . addAction ( _ ( " Remove from wallet " ) , lambda : self . delete_imported_key ( addr ) )
if any ( addr not in self . wallet . frozen_addresses for addr in addrs ) :
menu . addAction ( _ ( " Freeze " ) , lambda : self . set_addrs_frozen ( addrs , True ) )
if any ( addr in self . wallet . frozen_addresses for addr in addrs ) :
menu . addAction ( _ ( " Unfreeze " ) , lambda : self . set_addrs_frozen ( addrs , False ) )
2013-11-14 17:05:45 -08:00
2014-06-16 08:42:47 -07:00
def can_send ( addr ) :
return addr not in self . wallet . frozen_addresses and self . wallet . get_addr_balance ( addr ) != ( 0 , 0 )
if any ( can_send ( addr ) for addr in addrs ) :
2014-01-11 14:37:37 -08:00
menu . addAction ( _ ( " Send From " ) , lambda : self . send_from_addresses ( addrs ) )
2013-11-29 12:27:48 -08:00
2013-11-23 01:38:02 -08:00
run_hook ( ' receive_menu ' , menu , addrs )
2014-06-14 09:02:45 -07:00
menu . exec_ ( self . address_list . viewport ( ) . mapToGlobal ( position ) )
2012-06-07 08:36:39 -07:00
2013-11-14 20:07:25 -08:00
def get_sendable_balance ( self ) :
2014-06-05 12:55:11 -07:00
return sum ( map ( lambda x : x [ ' value ' ] , self . get_coins ( ) ) )
2013-11-14 20:07:25 -08:00
2014-06-05 12:55:11 -07:00
def get_coins ( self ) :
2013-11-14 20:07:25 -08:00
if self . pay_from :
return self . pay_from
else :
2014-06-05 12:55:11 -07:00
domain = self . wallet . get_account_addresses ( self . current_account )
for i in self . wallet . frozen_addresses :
if i in domain : domain . remove ( i )
return self . wallet . get_unspent_coins ( domain )
2013-11-14 20:07:25 -08:00
2013-11-14 17:05:45 -08:00
def send_from_addresses ( self , addrs ) :
2014-01-08 09:24:30 -08:00
self . set_pay_from ( addrs )
2013-11-14 17:05:45 -08:00
self . tabs . setCurrentIndex ( 1 )
2013-03-14 08:32:05 -07:00
def payto ( self , addr ) :
if not addr : return
label = self . wallet . labels . get ( addr )
m_addr = label + ' < ' + addr + ' > ' if label else addr
2012-06-07 08:36:39 -07:00
self . tabs . setCurrentIndex ( 1 )
2012-06-09 13:31:42 -07:00
self . payto_e . setText ( m_addr )
2012-06-07 08:36:39 -07:00
self . amount_e . setFocus ( )
2013-03-14 08:32:05 -07:00
def delete_contact ( self , x ) :
2013-01-30 01:16:00 -08:00
if self . question ( _ ( " Do you want to remove " ) + " %s " % x + _ ( " from your list of contacts? " ) ) :
2013-05-02 01:19:18 -07:00
self . wallet . delete_contact ( x )
2013-09-29 03:14:01 -07:00
self . wallet . set_label ( x , None )
2013-05-02 01:19:18 -07:00
self . update_history_tab ( )
self . update_contacts_tab ( )
self . update_completions ( )
2012-06-07 08:36:39 -07:00
2012-06-09 14:52:45 -07:00
2013-03-14 08:32:05 -07:00
def create_contact_menu ( self , position ) :
2012-06-09 14:52:45 -07:00
item = self . contacts_list . itemAt ( position )
2012-06-07 08:36:39 -07:00
menu = QMenu ( )
2013-12-24 08:33:29 -08:00
if not item :
menu . addAction ( _ ( " New contact " ) , lambda : self . new_contact_dialog ( ) )
else :
addr = unicode ( item . text ( 0 ) )
label = unicode ( item . text ( 1 ) )
is_editable = item . data ( 0 , 32 ) . toBool ( )
payto_addr = item . data ( 0 , 33 ) . toString ( )
menu . addAction ( _ ( " Copy to Clipboard " ) , lambda : self . app . clipboard ( ) . setText ( addr ) )
menu . addAction ( _ ( " Pay to " ) , lambda : self . payto ( payto_addr ) )
menu . addAction ( _ ( " QR code " ) , lambda : self . show_qrcode ( " bitcoin: " + addr , _ ( " Address " ) ) )
if is_editable :
menu . addAction ( _ ( " Edit label " ) , lambda : self . edit_label ( False ) )
menu . addAction ( _ ( " Delete " ) , lambda : self . delete_contact ( addr ) )
2013-03-14 08:32:05 -07:00
2013-09-23 07:14:28 -07:00
run_hook ( ' create_contact_menu ' , menu , item )
2012-06-09 08:18:53 -07:00
menu . exec_ ( self . contacts_list . viewport ( ) . mapToGlobal ( position ) )
2012-06-07 08:36:39 -07:00
2014-06-12 01:21:44 -07:00
def delete_invoice ( self , key ) :
2014-06-07 03:45:56 -07:00
self . invoices . pop ( key )
self . wallet . storage . put ( ' invoices ' , self . invoices )
self . update_invoices_tab ( )
2014-06-07 10:53:54 -07:00
def show_invoice ( self , key ) :
from electrum . paymentrequest import PaymentRequest
2014-06-13 08:11:15 -07:00
domain , memo , value , expiration , status , tx_hash = self . invoices [ key ]
2014-06-07 10:53:54 -07:00
pr = PaymentRequest ( self . config )
pr . read_file ( key )
pr . domain = domain
pr . verify ( )
2014-07-13 15:10:53 -07:00
self . show_pr_details ( pr , tx_hash )
2014-06-07 10:53:54 -07:00
2014-07-13 15:10:53 -07:00
def show_pr_details ( self , pr , tx_hash = None ) :
2014-06-07 10:53:54 -07:00
msg = ' Domain: ' + pr . domain
msg + = ' \n Status: ' + pr . get_status ( )
2014-06-12 02:27:18 -07:00
msg + = ' \n Memo: ' + pr . get_memo ( )
2014-06-07 10:53:54 -07:00
msg + = ' \n Payment URL: ' + pr . payment_url
2014-07-13 14:56:24 -07:00
msg + = ' \n \n Outputs: \n ' + ' \n ' . join ( map ( lambda x : x [ 1 ] + ' ' + self . format_amount ( x [ 2 ] ) + self . base_unit ( ) , pr . get_outputs ( ) ) )
2014-07-13 15:10:53 -07:00
if tx_hash :
msg + = ' \n \n Transaction ID: ' + tx_hash
2014-06-07 10:53:54 -07:00
QMessageBox . information ( self , ' Invoice ' , msg , ' OK ' )
2014-06-12 06:35:46 -07:00
def do_pay_invoice ( self , key ) :
from electrum . paymentrequest import PaymentRequest
2014-06-14 03:21:08 -07:00
domain , memo , value , expiration , status , tx_hash = self . invoices [ key ]
2014-06-12 06:35:46 -07:00
pr = PaymentRequest ( self . config )
pr . read_file ( key )
pr . domain = domain
2014-06-13 07:02:30 -07:00
self . payment_request = pr
2014-06-12 06:35:46 -07:00
self . prepare_for_payment_request ( )
2014-06-12 06:47:48 -07:00
if pr . verify ( ) :
self . payment_request_ok ( )
else :
self . payment_request_error ( )
2014-06-12 06:35:46 -07:00
2014-06-07 03:45:56 -07:00
def create_invoice_menu ( self , position ) :
item = self . invoices_list . itemAt ( position )
if not item :
return
2014-07-13 14:56:24 -07:00
key = str ( item . data ( 0 , 32 ) . toString ( ) )
2014-06-13 07:53:43 -07:00
domain , memo , value , expiration , status , tx_hash = self . invoices [ key ]
2014-06-07 03:45:56 -07:00
menu = QMenu ( )
2014-06-07 10:53:54 -07:00
menu . addAction ( _ ( " Details " ) , lambda : self . show_invoice ( key ) )
2014-06-12 06:35:46 -07:00
if status == PR_UNPAID :
menu . addAction ( _ ( " Pay Now " ) , lambda : self . do_pay_invoice ( key ) )
2014-06-07 10:53:54 -07:00
menu . addAction ( _ ( " Delete " ) , lambda : self . delete_invoice ( key ) )
2014-06-07 03:45:56 -07:00
menu . exec_ ( self . invoices_list . viewport ( ) . mapToGlobal ( position ) )
2012-06-07 08:36:39 -07:00
2012-11-28 06:38:44 -08:00
2014-06-14 07:15:00 -07:00
def update_address_tab ( self ) :
2014-06-14 09:02:45 -07:00
l = self . address_list
2014-05-02 02:10:12 -07:00
# extend the syntax for consistency
l . addChild = l . addTopLevelItem
2014-05-12 02:28:00 -07:00
l . insertChild = l . insertTopLevelItem
2013-11-29 12:27:48 -08:00
2012-06-07 07:07:49 -07:00
l . clear ( )
2012-06-07 08:36:39 -07:00
2014-05-02 02:10:12 -07:00
accounts = self . wallet . get_accounts ( )
2013-04-05 07:00:34 -07:00
if self . current_account is None :
2014-05-02 02:10:12 -07:00
account_items = sorted ( accounts . items ( ) )
2013-04-05 07:00:34 -07:00
else :
2014-05-02 02:10:12 -07:00
account_items = [ ( self . current_account , accounts . get ( self . current_account ) ) ]
2012-06-07 07:07:49 -07:00
2014-04-25 02:56:17 -07:00
2013-04-05 07:00:34 -07:00
for k , account in account_items :
2013-09-24 07:55:25 -07:00
2014-05-02 02:10:12 -07:00
if len ( accounts ) > 1 :
2014-04-25 02:56:17 -07:00
name = self . wallet . get_account_name ( k )
c , u = self . wallet . get_account_balance ( k )
account_item = QTreeWidgetItem ( [ name , ' ' , self . format_amount ( c + u ) , ' ' ] )
l . addTopLevelItem ( account_item )
account_item . setExpanded ( self . accounts_expanded . get ( k , True ) )
account_item . setData ( 0 , 32 , k )
else :
2014-05-02 02:10:12 -07:00
account_item = l
2013-11-29 12:27:48 -08:00
2014-05-02 02:10:12 -07:00
sequences = [ 0 , 1 ] if account . has_change ( ) else [ 0 ]
for is_change in sequences :
if len ( sequences ) > 1 :
name = _ ( " Receiving " ) if not is_change else _ ( " Change " )
seq_item = QTreeWidgetItem ( [ name , ' ' , ' ' , ' ' , ' ' ] )
2014-04-25 02:56:17 -07:00
account_item . addChild ( seq_item )
2014-05-02 02:10:12 -07:00
if not is_change :
seq_item . setExpanded ( True )
2014-04-25 02:56:17 -07:00
else :
2014-05-02 02:10:12 -07:00
seq_item = account_item
2014-04-25 02:56:17 -07:00
2013-11-15 20:11:00 -08:00
used_item = QTreeWidgetItem ( [ _ ( " Used " ) , ' ' , ' ' , ' ' , ' ' ] )
2013-11-15 20:22:47 -08:00
used_flag = False
2013-10-02 22:27:34 -07:00
2014-06-24 11:47:44 -07:00
addr_list = account . get_addresses ( is_change )
for address in addr_list :
2014-05-12 02:28:00 -07:00
num , is_used = self . wallet . is_used ( address )
2014-06-24 11:47:44 -07:00
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 ' ) )
2014-05-12 02:28:00 -07:00
if is_used :
2013-11-15 20:22:47 -08:00
if not used_flag :
2014-06-24 11:47:44 -07:00
seq_item . insertChild ( 0 , used_item )
2013-11-15 20:22:47 -08:00
used_flag = True
2013-11-15 20:11:00 -08:00
used_item . addChild ( item )
else :
seq_item . addChild ( item )
2013-02-27 00:04:22 -08:00
2012-06-09 15:29:19 -07:00
# we use column 1 because column 0 may be hidden
l . setCurrentItem ( l . topLevelItem ( 0 ) , 1 )
2012-02-11 22:45:18 -08:00
2012-02-12 12:41:42 -08:00
2012-02-11 22:45:18 -08:00
def update_contacts_tab ( self ) :
2012-06-07 07:07:49 -07:00
l = self . contacts_list
l . clear ( )
2012-05-05 02:51:06 -07:00
2012-02-11 22:45:18 -08:00
for address in self . wallet . addressbook :
label = self . wallet . labels . get ( address , ' ' )
2013-03-16 10:17:50 -07:00
n = self . wallet . get_num_tx ( address )
2013-02-27 12:22:52 -08:00
item = QTreeWidgetItem ( [ address , label , " %d " % n ] )
2012-03-30 14:44:54 -07:00
item . setFont ( 0 , QFont ( MONOSPACE_FONT ) )
2013-03-14 08:32:05 -07:00
# 32 = label can be edited (bool)
item . setData ( 0 , 32 , True )
# 33 = payto string
item . setData ( 0 , 33 , address )
2012-06-09 14:26:41 -07:00
l . addTopLevelItem ( item )
2012-02-11 22:45:18 -08:00
2013-09-23 07:14:28 -07:00
run_hook ( ' update_contacts_tab ' , l )
2012-06-09 14:26:41 -07:00
l . setCurrentItem ( l . topLevelItem ( 0 ) )
2012-02-11 22:45:18 -08:00
2013-02-01 09:22:36 -08:00
2013-02-26 04:56:48 -08:00
def create_console_tab ( self ) :
2013-09-24 01:06:03 -07:00
from console import Console
2013-02-02 00:40:54 -08:00
self . console = console = Console ( )
2013-08-30 01:11:10 -07:00
return console
2013-08-30 13:59:36 -07:00
def update_console ( self ) :
console = self . console
console . history = self . config . get ( " console-history " , [ ] )
console . history_index = len ( console . history )
2013-03-02 07:29:14 -08:00
2013-09-10 09:27:32 -07:00
console . updateNamespace ( { ' wallet ' : self . wallet , ' network ' : self . network , ' gui ' : self } )
2013-02-23 11:48:22 -08:00
console . updateNamespace ( { ' util ' : util , ' bitcoin ' : bitcoin } )
2013-02-26 04:56:48 -08:00
2013-09-15 02:19:48 -07:00
c = commands . Commands ( self . wallet , self . network , lambda : self . console . set_json ( True ) )
2013-02-26 04:56:48 -08:00
methods = { }
def mkfunc ( f , method ) :
return lambda * args : apply ( f , ( method , args , self . password_dialog ) )
for m in dir ( c ) :
2013-10-04 07:44:36 -07:00
if m [ 0 ] == ' _ ' or m in [ ' network ' , ' wallet ' ] : continue
2013-02-26 04:56:48 -08:00
methods [ m ] = mkfunc ( c . _run , m )
2013-11-29 12:27:48 -08:00
2013-02-26 04:56:48 -08:00
console . updateNamespace ( methods )
2013-08-30 13:59:36 -07:00
2012-02-11 08:02:28 -08:00
2013-04-05 07:00:34 -07:00
def change_account ( self , s ) :
if s == _ ( " All accounts " ) :
self . current_account = None
else :
2013-09-03 01:09:13 -07:00
accounts = self . wallet . get_account_names ( )
2013-04-05 07:00:34 -07:00
for k , v in accounts . items ( ) :
if v == s :
self . current_account = k
self . update_history_tab ( )
self . update_status ( )
2014-06-14 07:15:00 -07:00
self . update_address_tab ( )
2013-04-05 07:00:34 -07:00
self . update_receive_tab ( )
2013-01-15 12:31:21 -08:00
2012-02-11 08:38:44 -08:00
def create_status_bar ( self ) :
2013-05-10 05:12:33 -07:00
2012-02-11 08:38:44 -08:00
sb = QStatusBar ( )
2012-02-12 08:19:16 -08:00
sb . setFixedHeight ( 35 )
2013-01-05 04:44:20 -08:00
qtVersion = qVersion ( )
2013-01-15 12:31:21 -08:00
2013-05-10 05:12:33 -07:00
self . balance_label = QLabel ( " " )
sb . addWidget ( self . balance_label )
2013-09-10 14:48:28 -07:00
from version_getter import UpdateLabel
2013-09-10 12:53:26 -07:00
self . updatelabel = UpdateLabel ( self . config , sb )
2013-01-15 12:31:21 -08:00
2013-08-30 01:11:10 -07:00
self . account_selector = QComboBox ( )
2014-03-27 08:23:30 -07:00
self . account_selector . setSizeAdjustPolicy ( QComboBox . AdjustToContents )
2013-11-29 12:27:48 -08:00
self . connect ( self . account_selector , SIGNAL ( " activated(QString) " ) , self . change_account )
2013-08-30 01:11:10 -07:00
sb . addPermanentWidget ( self . account_selector )
2013-04-05 07:00:34 -07:00
2013-01-09 01:42:19 -08:00
if ( int ( qtVersion [ 0 ] ) > = 4 and int ( qtVersion [ 2 ] ) > = 7 ) :
2013-01-30 11:27:28 -08:00
sb . addPermanentWidget ( StatusBarButton ( QIcon ( " :icons/switchgui.png " ) , _ ( " Switch to Lite Mode " ) , self . go_lite ) )
2013-08-30 12:44:16 -07:00
self . lock_icon = QIcon ( )
self . password_button = StatusBarButton ( self . lock_icon , _ ( " Password " ) , self . change_password_dialog )
sb . addPermanentWidget ( self . password_button )
2013-11-29 12:27:48 -08:00
2013-01-13 16:34:06 -08:00
sb . addPermanentWidget ( StatusBarButton ( QIcon ( " :icons/preferences.png " ) , _ ( " Preferences " ) , self . settings_dialog ) )
2013-11-29 12:27:48 -08:00
self . seed_button = StatusBarButton ( QIcon ( " :icons/seed.png " ) , _ ( " Seed " ) , self . show_seed_dialog )
2013-08-30 12:44:16 -07:00
sb . addPermanentWidget ( self . seed_button )
2013-11-29 12:27:48 -08:00
self . status_button = StatusBarButton ( QIcon ( " :icons/status_disconnected.png " ) , _ ( " Network " ) , self . run_network_dialog )
2012-02-13 12:36:41 -08:00
sb . addPermanentWidget ( self . status_button )
2013-01-15 12:31:21 -08:00
2013-09-23 07:14:28 -07:00
run_hook ( ' create_status_bar ' , ( sb , ) )
2013-03-10 09:04:00 -07:00
2012-02-11 08:38:44 -08:00
self . setStatusBar ( sb )
2013-08-22 03:39:41 -07:00
2013-08-30 12:44:16 -07:00
def update_lock_icon ( self ) :
icon = QIcon ( " :icons/lock.png " ) if self . wallet . use_encryption else QIcon ( " :icons/unlock.png " )
self . password_button . setIcon ( icon )
def update_buttons_on_seed ( self ) :
2014-08-19 01:36:55 -07:00
self . seed_button . setVisible ( self . wallet . has_seed ( ) )
self . password_button . setVisible ( self . wallet . can_change_password ( ) )
self . send_button . setText ( _ ( " Create unsigned transaction " ) if self . wallet . is_watching_only ( ) else _ ( " Send " ) )
2013-08-30 12:44:16 -07:00
2013-08-22 03:39:41 -07:00
def change_password_dialog ( self ) :
from password_dialog import PasswordDialog
d = PasswordDialog ( self . wallet , self )
d . run ( )
2013-08-30 12:44:16 -07:00
self . update_lock_icon ( )
2013-08-22 03:39:41 -07:00
2013-08-30 12:44:16 -07:00
2012-06-07 08:54:40 -07:00
def new_contact_dialog ( self ) :
2013-10-10 04:22:08 -07:00
d = QDialog ( self )
2014-03-25 15:08:23 -07:00
d . setWindowTitle ( _ ( " New Contact " ) )
2013-10-10 04:22:08 -07:00
vbox = QVBoxLayout ( d )
vbox . addWidget ( QLabel ( _ ( ' New Contact ' ) + ' : ' ) )
2013-11-29 12:27:48 -08:00
2013-10-10 04:22:08 -07:00
grid = QGridLayout ( )
line1 = QLineEdit ( )
line2 = QLineEdit ( )
grid . addWidget ( QLabel ( _ ( " Address " ) ) , 1 , 0 )
grid . addWidget ( line1 , 1 , 1 )
grid . addWidget ( QLabel ( _ ( " Name " ) ) , 2 , 0 )
grid . addWidget ( line2 , 2 , 1 )
vbox . addLayout ( grid )
vbox . addLayout ( ok_cancel_buttons ( d ) )
2013-11-29 12:27:48 -08:00
2013-10-10 04:22:08 -07:00
if not d . exec_ ( ) :
return
2013-11-29 12:27:48 -08:00
2013-10-10 04:22:08 -07:00
address = str ( line1 . text ( ) )
label = unicode ( line2 . text ( ) )
2013-11-29 12:27:48 -08:00
2013-10-10 04:22:08 -07:00
if not is_valid ( address ) :
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Invalid Address ' ) , _ ( ' OK ' ) )
return
2013-11-29 12:27:48 -08:00
2013-10-10 04:22:08 -07:00
self . wallet . add_contact ( address )
if label :
self . wallet . set_label ( address , label )
self . update_contacts_tab ( )
self . update_history_tab ( )
self . update_completions ( )
self . tabs . setCurrentIndex ( 3 )
2012-02-12 15:00:33 -08:00
2013-08-07 12:53:05 -07:00
2014-04-01 02:25:12 -07:00
@protected
def new_account_dialog ( self , password ) :
2013-08-29 06:08:03 -07:00
dialog = QDialog ( self )
dialog . setModal ( 1 )
dialog . setWindowTitle ( _ ( " New Account " ) )
vbox = QVBoxLayout ( )
2013-10-05 08:29:51 -07:00
vbox . addWidget ( QLabel ( _ ( ' Account name ' ) + ' : ' ) )
e = QLineEdit ( )
2013-08-29 06:08:03 -07:00
vbox . addWidget ( e )
2013-10-05 08:29:51 -07:00
msg = _ ( " Note: Newly created accounts are ' pending ' until they receive bitcoins. " ) + " " \
+ _ ( " You will need to wait for 2 confirmations until the correct balance is displayed and more addresses are created for that account. " )
l = QLabel ( msg )
l . setWordWrap ( True )
vbox . addWidget ( l )
2013-08-29 06:08:03 -07:00
2013-09-15 03:34:07 -07:00
vbox . addLayout ( ok_cancel_buttons ( dialog ) )
2013-08-29 06:08:03 -07:00
dialog . setLayout ( vbox )
2013-09-15 03:34:07 -07:00
r = dialog . exec_ ( )
2013-10-05 08:29:51 -07:00
if not r : return
name = str ( e . text ( ) )
if not name : return
2013-08-29 06:08:03 -07:00
2014-04-25 02:56:17 -07:00
self . wallet . create_pending_account ( name , password )
2014-06-14 07:15:00 -07:00
self . update_address_tab ( )
2014-07-07 06:43:02 -07:00
self . tabs . setCurrentIndex ( 3 )
2013-11-29 12:27:48 -08:00
2013-08-01 11:08:56 -07:00
2013-09-30 09:30:07 -07:00
2014-04-25 01:16:07 -07:00
def show_master_public_keys ( self ) :
2013-09-30 09:30:07 -07:00
dialog = QDialog ( self )
dialog . setModal ( 1 )
dialog . setWindowTitle ( _ ( " Master Public Keys " ) )
main_layout = QGridLayout ( )
2014-04-25 01:16:07 -07:00
mpk_dict = self . wallet . get_master_public_keys ( )
i = 0
for key , value in mpk_dict . items ( ) :
main_layout . addWidget ( QLabel ( key ) , i , 0 )
mpk_text = QTextEdit ( )
mpk_text . setReadOnly ( True )
mpk_text . setMaximumHeight ( 170 )
mpk_text . setText ( value )
main_layout . addWidget ( mpk_text , i + 1 , 0 )
i + = 2
2013-09-30 09:30:07 -07:00
2013-01-10 13:04:52 -08:00
vbox = QVBoxLayout ( )
vbox . addLayout ( main_layout )
2013-09-30 09:30:07 -07:00
vbox . addLayout ( close_button ( dialog ) )
2013-01-08 05:29:42 -08:00
2013-01-10 13:04:52 -08:00
dialog . setLayout ( vbox )
2013-01-08 05:29:42 -08:00
dialog . exec_ ( )
2013-11-29 12:27:48 -08:00
2013-01-08 05:29:42 -08:00
2013-03-04 22:55:43 -08:00
@protected
def show_seed_dialog ( self , password ) :
2014-04-30 02:40:53 -07:00
if not self . wallet . has_seed ( ) :
QMessageBox . information ( self , _ ( ' Message ' ) , _ ( ' This wallet has no seed ' ) , _ ( ' OK ' ) )
2012-02-13 06:11:31 -08:00
return
2013-01-10 14:10:01 -08:00
2014-04-30 02:40:53 -07:00
try :
mnemonic = self . wallet . get_mnemonic ( password )
except Exception :
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Incorrect Password ' ) , _ ( ' OK ' ) )
return
from seed_dialog import SeedDialog
2014-06-01 23:59:41 -07:00
d = SeedDialog ( self , mnemonic , self . wallet . has_imported_keys ( ) )
2014-04-30 02:40:53 -07:00
d . exec_ ( )
2013-01-08 08:01:45 -08:00
2012-08-16 15:31:46 -07:00
2012-02-13 06:11:31 -08:00
2013-09-16 20:19:23 -07:00
def show_qrcode ( self , data , title = _ ( " QR code " ) ) :
2014-06-14 03:17:44 -07:00
if not data :
return
d = QRDialog ( data , self , title )
2012-05-01 08:06:14 -07:00
d . exec_ ( )
2013-03-04 22:55:43 -08:00
def do_protect ( self , func , args ) :
2013-02-02 02:46:02 -08:00
if self . wallet . use_encryption :
password = self . password_dialog ( )
if not password :
return
else :
password = None
2013-11-29 12:27:48 -08:00
2013-03-04 22:55:43 -08:00
if args != ( False , ) :
args = ( self , ) + args + ( password , )
else :
args = ( self , password )
apply ( func , args )
2013-02-02 02:46:02 -08:00
2014-04-05 01:34:51 -07:00
def show_public_keys ( self , address ) :
if not address : return
try :
pubkey_list = self . wallet . get_public_keys ( address )
except Exception as e :
traceback . print_exc ( file = sys . stdout )
self . show_message ( str ( e ) )
return
d = QDialog ( self )
d . setMinimumSize ( 600 , 200 )
d . setModal ( 1 )
vbox = QVBoxLayout ( )
vbox . addWidget ( QLabel ( _ ( " Address " ) + ' : ' + address ) )
vbox . addWidget ( QLabel ( _ ( " Public key " ) + ' : ' ) )
2014-06-14 04:05:55 -07:00
keys = QRTextEdit ( )
2014-04-05 01:34:51 -07:00
keys . setReadOnly ( True )
keys . setText ( ' \n ' . join ( pubkey_list ) )
vbox . addWidget ( keys )
vbox . addLayout ( close_button ( d ) )
d . setLayout ( vbox )
d . exec_ ( )
2013-03-04 22:55:43 -08:00
@protected
def show_private_key ( self , address , password ) :
if not address : return
2013-02-02 02:46:02 -08:00
try :
2013-09-10 07:07:59 -07:00
pk_list = self . wallet . get_private_key ( address , password )
2013-11-09 20:21:02 -08:00
except Exception as e :
2014-04-01 02:25:12 -07:00
traceback . print_exc ( file = sys . stdout )
2013-02-02 02:46:02 -08:00
self . show_message ( str ( e ) )
return
2013-12-16 06:40:24 -08:00
d = QDialog ( self )
d . setMinimumSize ( 600 , 200 )
d . setModal ( 1 )
vbox = QVBoxLayout ( )
vbox . addWidget ( QLabel ( _ ( " Address " ) + ' : ' + address ) )
vbox . addWidget ( QLabel ( _ ( " Private key " ) + ' : ' ) )
2014-06-14 04:05:55 -07:00
keys = QRTextEdit ( )
2013-12-16 06:40:24 -08:00
keys . setReadOnly ( True )
keys . setText ( ' \n ' . join ( pk_list ) )
vbox . addWidget ( keys )
vbox . addLayout ( close_button ( d ) )
d . setLayout ( vbox )
d . exec_ ( )
2013-02-02 02:46:02 -08:00
2013-03-04 22:55:43 -08:00
@protected
def do_sign ( self , address , message , signature , password ) :
2013-09-15 08:49:23 -07:00
message = unicode ( message . toPlainText ( ) )
message = message . encode ( ' utf-8 ' )
2013-03-04 22:55:43 -08:00
try :
2013-09-15 08:49:23 -07:00
sig = self . wallet . sign_message ( str ( address . text ( ) ) , message , password )
2013-03-04 22:55:43 -08:00
signature . setText ( sig )
2013-11-09 20:21:02 -08:00
except Exception as e :
2013-03-04 22:55:43 -08:00
self . show_message ( str ( e ) )
2014-03-02 11:20:21 -08:00
def do_verify ( self , address , message , signature ) :
message = unicode ( message . toPlainText ( ) )
message = message . encode ( ' utf-8 ' )
if bitcoin . verify_message ( address . text ( ) , str ( signature . toPlainText ( ) ) , message ) :
self . show_message ( _ ( " Signature verified " ) )
else :
self . show_message ( _ ( " Error: wrong signature " ) )
2014-03-03 01:39:10 -08:00
def sign_verify_message ( self , address = ' ' ) :
2012-11-24 23:28:10 -08:00
d = QDialog ( self )
d . setModal ( 1 )
2014-03-03 01:39:10 -08:00
d . setWindowTitle ( _ ( ' Sign/verify Message ' ) )
2013-01-05 13:50:59 -08:00
d . setMinimumSize ( 410 , 290 )
2012-11-24 23:28:10 -08:00
2014-03-02 11:20:21 -08:00
layout = QGridLayout ( d )
2012-11-24 23:28:10 -08:00
2014-03-02 11:36:54 -08:00
message_e = QTextEdit ( )
2014-03-03 01:39:10 -08:00
layout . addWidget ( QLabel ( _ ( ' Message ' ) ) , 1 , 0 )
layout . addWidget ( message_e , 1 , 1 )
2013-01-05 13:50:59 -08:00
layout . setRowStretch ( 2 , 3 )
2012-11-24 23:28:10 -08:00
2014-03-03 01:39:10 -08:00
address_e = QLineEdit ( )
address_e . setText ( address )
layout . addWidget ( QLabel ( _ ( ' Address ' ) ) , 2 , 0 )
layout . addWidget ( address_e , 2 , 1 )
2014-03-02 11:36:54 -08:00
signature_e = QTextEdit ( )
2012-11-24 23:28:10 -08:00
layout . addWidget ( QLabel ( _ ( ' Signature ' ) ) , 3 , 0 )
2014-03-02 11:36:54 -08:00
layout . addWidget ( signature_e , 3 , 1 )
2013-01-05 13:50:59 -08:00
layout . setRowStretch ( 3 , 1 )
2012-11-24 23:28:10 -08:00
hbox = QHBoxLayout ( )
2014-03-03 01:39:10 -08:00
b = QPushButton ( _ ( " Sign " ) )
b . clicked . connect ( lambda : self . do_sign ( address_e , message_e , signature_e ) )
hbox . addWidget ( b )
b = QPushButton ( _ ( " Verify " ) )
b . clicked . connect ( lambda : self . do_verify ( address_e , message_e , signature_e ) )
2012-11-24 23:28:10 -08:00
hbox . addWidget ( b )
2014-03-03 01:39:10 -08:00
2012-11-24 23:28:10 -08:00
b = QPushButton ( _ ( " Close " ) )
b . clicked . connect ( d . accept )
hbox . addWidget ( b )
layout . addLayout ( hbox , 4 , 1 )
d . exec_ ( )
2013-11-29 12:27:48 -08:00
2014-03-03 01:39:10 -08:00
@protected
def do_decrypt ( self , message_e , pubkey_e , encrypted_e , password ) :
try :
decrypted = self . wallet . decrypt_message ( str ( pubkey_e . text ( ) ) , str ( encrypted_e . toPlainText ( ) ) , password )
message_e . setText ( decrypted )
2014-09-03 01:45:41 -07:00
except BaseException as e :
2014-08-26 03:55:53 -07:00
traceback . print_exc ( file = sys . stdout )
2014-09-03 01:45:41 -07:00
self . show_warning ( str ( e ) )
2014-03-03 01:39:10 -08:00
def do_encrypt ( self , message_e , pubkey_e , encrypted_e ) :
message = unicode ( message_e . toPlainText ( ) )
message = message . encode ( ' utf-8 ' )
try :
encrypted = bitcoin . encrypt_message ( message , str ( pubkey_e . text ( ) ) )
encrypted_e . setText ( encrypted )
2014-09-03 01:45:41 -07:00
except BaseException as e :
2014-08-26 03:55:53 -07:00
traceback . print_exc ( file = sys . stdout )
2014-09-03 01:45:41 -07:00
self . show_warning ( str ( e ) )
2014-03-03 01:39:10 -08:00
def encrypt_message ( self , address = ' ' ) :
d = QDialog ( self )
d . setModal ( 1 )
d . setWindowTitle ( _ ( ' Encrypt/decrypt Message ' ) )
d . setMinimumSize ( 610 , 490 )
layout = QGridLayout ( d )
message_e = QTextEdit ( )
layout . addWidget ( QLabel ( _ ( ' Message ' ) ) , 1 , 0 )
layout . addWidget ( message_e , 1 , 1 )
layout . setRowStretch ( 2 , 3 )
pubkey_e = QLineEdit ( )
if address :
2014-07-06 13:24:09 -07:00
pubkey = self . wallet . get_public_keys ( address ) [ 0 ]
2014-03-03 01:39:10 -08:00
pubkey_e . setText ( pubkey )
layout . addWidget ( QLabel ( _ ( ' Public key ' ) ) , 2 , 0 )
layout . addWidget ( pubkey_e , 2 , 1 )
encrypted_e = QTextEdit ( )
layout . addWidget ( QLabel ( _ ( ' Encrypted ' ) ) , 3 , 0 )
layout . addWidget ( encrypted_e , 3 , 1 )
layout . setRowStretch ( 3 , 1 )
hbox = QHBoxLayout ( )
b = QPushButton ( _ ( " Encrypt " ) )
b . clicked . connect ( lambda : self . do_encrypt ( message_e , pubkey_e , encrypted_e ) )
hbox . addWidget ( b )
b = QPushButton ( _ ( " Decrypt " ) )
b . clicked . connect ( lambda : self . do_decrypt ( message_e , pubkey_e , encrypted_e ) )
hbox . addWidget ( b )
b = QPushButton ( _ ( " Close " ) )
b . clicked . connect ( d . accept )
hbox . addWidget ( b )
layout . addLayout ( hbox , 4 , 1 )
d . exec_ ( )
2012-02-14 00:52:03 -08:00
def question ( self , msg ) :
2012-05-18 06:28:55 -07:00
return QMessageBox . question ( self , _ ( ' Message ' ) , msg , QMessageBox . Yes | QMessageBox . No , QMessageBox . No ) == QMessageBox . Yes
2012-02-13 06:11:31 -08:00
2012-02-14 00:52:03 -08:00
def show_message ( self , msg ) :
2012-05-18 06:28:55 -07:00
QMessageBox . information ( self , _ ( ' Message ' ) , msg , _ ( ' OK ' ) )
2012-02-14 00:52:03 -08:00
2014-09-03 01:45:41 -07:00
def show_warning ( self , msg ) :
QMessageBox . warning ( self , _ ( ' Warning ' ) , msg , _ ( ' OK ' ) )
2014-06-01 23:59:41 -07:00
def password_dialog ( self , msg = None ) :
2012-02-14 02:10:06 -08:00
d = QDialog ( self )
2012-02-13 05:52:59 -08:00
d . setModal ( 1 )
2014-03-25 15:08:23 -07:00
d . setWindowTitle ( _ ( " Enter Password " ) )
2012-02-13 05:52:59 -08:00
2012-02-13 06:11:31 -08:00
pw = QLineEdit ( )
pw . setEchoMode ( 2 )
2012-02-13 10:02:48 -08:00
vbox = QVBoxLayout ( )
2014-06-01 23:59:41 -07:00
if not msg :
msg = _ ( ' Please enter your password ' )
2012-02-13 10:02:48 -08:00
vbox . addWidget ( QLabel ( msg ) )
2012-02-13 06:11:31 -08:00
2012-02-13 10:02:48 -08:00
grid = QGridLayout ( )
grid . setSpacing ( 8 )
2012-05-18 06:28:55 -07:00
grid . addWidget ( QLabel ( _ ( ' Password ' ) ) , 1 , 0 )
2012-02-13 06:11:31 -08:00
grid . addWidget ( pw , 1 , 1 )
2012-02-13 10:02:48 -08:00
vbox . addLayout ( grid )
2012-02-13 06:11:31 -08:00
2012-02-14 00:52:03 -08:00
vbox . addLayout ( ok_cancel_buttons ( d ) )
2013-03-15 10:35:05 -07:00
d . setLayout ( vbox )
2012-02-13 06:11:31 -08:00
2013-09-23 07:14:28 -07:00
run_hook ( ' password_dialog ' , pw , grid , 1 )
2012-02-13 06:11:31 -08:00
if not d . exec_ ( ) : return
2012-02-14 14:11:59 -08:00
return unicode ( pw . text ( ) )
2012-02-13 06:11:31 -08:00
2012-06-07 09:52:29 -07:00
2012-02-14 00:52:03 -08:00
2013-02-27 06:58:46 -08:00
2013-09-15 02:37:22 -07:00
def tx_from_text ( self , txt ) :
" json or raw hexadecimal "
try :
txt . decode ( ' hex ' )
2014-06-21 12:06:09 -07:00
is_hex = True
except :
is_hex = False
if is_hex :
try :
2014-07-06 12:10:41 -07:00
return Transaction . deserialize ( txt )
2014-06-21 12:06:09 -07:00
except :
traceback . print_exc ( file = sys . stdout )
QMessageBox . critical ( None , _ ( " Unable to parse transaction " ) , _ ( " Electrum was unable to parse your transaction " ) )
return
2013-09-15 02:37:22 -07:00
2013-02-28 02:16:07 -08:00
try :
tx_dict = json . loads ( str ( txt ) )
assert " hex " in tx_dict . keys ( )
2014-07-06 12:10:41 -07:00
tx = Transaction . deserialize ( tx_dict [ " hex " ] )
2014-06-21 12:06:09 -07:00
#if tx_dict.has_key("input_info"):
# input_info = json.loads(tx_dict['input_info'])
# tx.add_input_info(input_info)
2013-09-15 02:37:22 -07:00
return tx
2013-11-10 12:30:57 -08:00
except Exception :
2014-05-21 14:59:24 -07:00
traceback . print_exc ( file = sys . stdout )
2014-06-21 12:06:09 -07:00
QMessageBox . critical ( None , _ ( " Unable to parse transaction " ) , _ ( " Electrum was unable to parse your transaction " ) )
2013-09-15 02:37:22 -07:00
2013-02-27 06:58:46 -08:00
2014-07-12 09:39:28 -07:00
def read_tx_from_qrcode ( self ) :
data = run_hook ( ' scan_qr_hook ' )
if not data :
return
# transactions are binary, but qrcode seems to return utf8...
z = data . decode ( ' utf8 ' )
s = ' '
for b in z :
s + = chr ( ord ( b ) )
data = s . encode ( ' hex ' )
tx = self . tx_from_text ( data )
if not tx :
return
self . show_transaction ( tx )
2013-02-27 06:58:46 -08:00
2013-02-28 02:16:07 -08:00
def read_tx_from_file ( self ) :
2013-03-11 07:57:37 -07:00
fileName = self . getOpenFileName ( _ ( " Select your transaction file " ) , " *.txn " )
2013-02-28 02:16:07 -08:00
if not fileName :
return
try :
with open ( fileName , " r " ) as f :
file_content = f . read ( )
except ( ValueError , IOError , os . error ) , reason :
2013-09-16 20:19:23 -07:00
QMessageBox . critical ( None , _ ( " Unable to read file or no transaction found " ) , _ ( " Electrum was unable to open your transaction file " ) + " \n " + str ( reason ) )
2013-02-27 06:58:46 -08:00
2013-09-15 02:37:22 -07:00
return self . tx_from_text ( file_content )
2013-02-27 06:58:46 -08:00
2013-02-28 02:16:07 -08:00
2013-03-04 22:55:43 -08:00
@protected
2014-06-21 12:06:09 -07:00
def sign_raw_transaction ( self , tx , password ) :
2014-06-16 09:18:02 -07:00
try :
2014-06-21 12:06:09 -07:00
self . wallet . signrawtransaction ( tx , [ ] , password )
2014-06-16 09:18:02 -07:00
except Exception as e :
2014-06-21 12:06:09 -07:00
traceback . print_exc ( file = sys . stdout )
2014-06-16 09:18:02 -07:00
QMessageBox . warning ( self , _ ( " Error " ) , str ( e ) )
2013-02-28 02:16:07 -08:00
2013-03-08 07:48:40 -08:00
def do_process_from_text ( self ) :
2013-03-13 06:23:10 -07:00
text = text_dialog ( self , _ ( ' Input raw transaction ' ) , _ ( " Transaction: " ) , _ ( " Load transaction " ) )
if not text :
return
2013-09-15 02:37:22 -07:00
tx = self . tx_from_text ( text )
if tx :
self . show_transaction ( tx )
2013-02-27 06:58:46 -08:00
2013-03-04 08:05:26 -08:00
def do_process_from_file ( self ) :
2013-09-15 02:37:22 -07:00
tx = self . read_tx_from_file ( )
if tx :
self . show_transaction ( tx )
2013-02-28 02:16:07 -08:00
2014-02-02 20:38:48 -08:00
def do_process_from_txid ( self ) :
from electrum import transaction
txid , ok = QInputDialog . getText ( self , _ ( ' Lookup transaction ' ) , _ ( ' Transaction ID ' ) + ' : ' )
if ok and txid :
r = self . network . synchronous_get ( [ ( ' blockchain.transaction.get ' , [ str ( txid ) ] ) ] ) [ 0 ]
if r :
2014-07-06 12:10:41 -07:00
tx = transaction . Transaction . deserialize ( r )
2014-02-02 20:38:48 -08:00
if tx :
self . show_transaction ( tx )
else :
self . show_message ( " unknown transaction " )
2013-09-04 01:57:15 -07:00
def do_process_from_csvReader ( self , csvReader ) :
outputs = [ ]
2014-02-24 04:22:13 -08:00
errors = [ ]
errtext = " "
2013-09-04 01:57:15 -07:00
try :
2014-02-24 04:22:13 -08:00
for position , row in enumerate ( csvReader ) :
2013-09-04 01:57:15 -07:00
address = row [ 0 ]
2014-07-08 10:38:16 -07:00
if not is_address ( address ) :
2014-02-24 04:22:13 -08:00
errors . append ( ( position , address ) )
continue
2013-11-29 12:27:59 -08:00
amount = Decimal ( row [ 1 ] )
2013-09-04 01:57:15 -07:00
amount = int ( 100000000 * amount )
2014-07-08 10:38:16 -07:00
outputs . append ( ( ' address ' , address , amount ) )
2013-09-04 01:57:15 -07:00
except ( ValueError , IOError , os . error ) , reason :
2013-09-16 20:19:23 -07:00
QMessageBox . critical ( None , _ ( " Unable to read file or no transaction found " ) , _ ( " Electrum was unable to open your transaction file " ) + " \n " + str ( reason ) )
2013-09-04 01:57:15 -07:00
return
2014-02-24 04:22:13 -08:00
if errors != [ ] :
for x in errors :
errtext + = " CSV Row " + str ( x [ 0 ] + 1 ) + " : " + x [ 1 ] + " \n "
QMessageBox . critical ( None , _ ( " Invalid Addresses " ) , _ ( " ABORTING! Invalid Addresses found: " ) + " \n \n " + errtext )
return
2013-09-04 01:57:15 -07:00
try :
2013-09-15 07:30:04 -07:00
tx = self . wallet . make_unsigned_transaction ( outputs , None , None )
2013-11-09 20:21:02 -08:00
except Exception as e :
2013-09-04 01:57:15 -07:00
self . show_message ( str ( e ) )
return
2013-09-14 12:07:54 -07:00
self . show_transaction ( tx )
2013-09-04 01:57:15 -07:00
def do_process_from_csv_file ( self ) :
fileName = self . getOpenFileName ( _ ( " Select your transaction CSV " ) , " *.csv " )
if not fileName :
return
try :
with open ( fileName , " r " ) as f :
csvReader = csv . reader ( f )
self . do_process_from_csvReader ( csvReader )
except ( ValueError , IOError , os . error ) , reason :
2013-09-16 20:19:23 -07:00
QMessageBox . critical ( None , _ ( " Unable to read file or no transaction found " ) , _ ( " Electrum was unable to open your transaction file " ) + " \n " + str ( reason ) )
2013-09-04 01:57:15 -07:00
return
def do_process_from_csv_text ( self ) :
2013-09-28 07:03:52 -07:00
text = text_dialog ( self , _ ( ' Input CSV ' ) , _ ( " Please enter a list of outputs. " ) + ' \n ' \
+ _ ( " Format: address, amount. One output per line " ) , _ ( " Load CSV " ) )
2013-09-04 01:57:15 -07:00
if not text :
return
f = StringIO . StringIO ( text )
csvReader = csv . reader ( f )
self . do_process_from_csvReader ( csvReader )
2013-09-14 12:07:54 -07:00
2013-02-27 06:58:46 -08:00
2013-03-04 22:55:43 -08:00
@protected
2014-05-01 07:33:56 -07:00
def export_privkeys_dialog ( self , password ) :
2014-05-01 06:04:12 -07:00
if self . wallet . is_watching_only ( ) :
self . show_message ( _ ( " This is a watching-only wallet " ) )
2013-12-04 09:06:07 -08:00
return
2014-05-01 07:33:56 -07:00
d = QDialog ( self )
d . setWindowTitle ( _ ( ' Private keys ' ) )
d . setMinimumSize ( 850 , 300 )
vbox = QVBoxLayout ( d )
2013-02-14 08:31:29 -08:00
2014-05-01 07:33:56 -07:00
msg = " %s \n %s \n %s " % ( _ ( " WARNING: ALL your private keys are secret. " ) ,
_ ( " Exposing a single private key can compromise your entire wallet! " ) ,
_ ( " In particular, DO NOT use ' redeem private key ' services proposed by third parties. " ) )
vbox . addWidget ( QLabel ( msg ) )
e = QTextEdit ( )
e . setReadOnly ( True )
vbox . addWidget ( e )
defaultname = ' electrum-private-keys.csv '
2014-05-05 02:31:04 -07:00
select_msg = _ ( ' Select file to export your private keys to ' )
hbox , filename_e , csv_button = filename_field ( self , self . config , defaultname , select_msg )
vbox . addLayout ( hbox )
2014-05-01 07:33:56 -07:00
h , b = ok_cancel_buttons2 ( d , _ ( ' Export ' ) )
b . setEnabled ( False )
vbox . addLayout ( h )
private_keys = { }
addresses = self . wallet . addresses ( True )
2014-05-05 00:58:29 -07:00
done = False
2014-05-01 07:33:56 -07:00
def privkeys_thread ( ) :
for addr in addresses :
2014-05-05 00:20:19 -07:00
time . sleep ( 0.1 )
2014-05-05 00:58:29 -07:00
if done :
break
2014-05-01 07:33:56 -07:00
private_keys [ addr ] = " \n " . join ( self . wallet . get_private_key ( addr , password ) )
d . emit ( SIGNAL ( ' computing_privkeys ' ) )
d . emit ( SIGNAL ( ' show_privkeys ' ) )
def show_privkeys ( ) :
s = " \n " . join ( map ( lambda x : x [ 0 ] + " \t " + x [ 1 ] , private_keys . items ( ) ) )
e . setText ( s )
b . setEnabled ( True )
2013-02-14 08:31:29 -08:00
2014-05-01 07:33:56 -07:00
d . connect ( d , QtCore . SIGNAL ( ' computing_privkeys ' ) , lambda : e . setText ( " Please wait... %d / %d " % ( len ( private_keys ) , len ( addresses ) ) ) )
d . connect ( d , QtCore . SIGNAL ( ' show_privkeys ' ) , show_privkeys )
threading . Thread ( target = privkeys_thread ) . start ( )
2013-11-29 12:27:48 -08:00
2014-05-01 07:33:56 -07:00
if not d . exec_ ( ) :
2014-05-05 00:58:29 -07:00
done = True
2014-05-01 07:33:56 -07:00
return
2013-02-14 08:31:29 -08:00
2014-05-01 07:33:56 -07:00
filename = filename_e . text ( )
if not filename :
return
2013-02-14 08:31:29 -08:00
2014-05-01 07:33:56 -07:00
try :
2014-05-05 02:31:04 -07:00
self . do_export_privkeys ( filename , private_keys , csv_button . isChecked ( ) )
2013-02-14 08:31:29 -08:00
except ( IOError , os . error ) , reason :
export_error_label = _ ( " Electrum was unable to produce a private key-export. " )
2013-09-16 20:19:23 -07:00
QMessageBox . critical ( None , _ ( " Unable to create csv " ) , export_error_label + " \n " + str ( reason ) )
2013-02-14 08:31:29 -08:00
2013-11-09 20:21:02 -08:00
except Exception as e :
2014-05-01 07:33:56 -07:00
self . show_message ( str ( e ) )
return
self . show_message ( _ ( " Private keys exported. " ) )
2013-02-14 08:31:29 -08:00
2012-06-07 08:42:50 -07:00
2014-05-05 02:31:04 -07:00
def do_export_privkeys ( self , fileName , pklist , is_csv ) :
with open ( fileName , " w+ " ) as f :
if is_csv :
transaction = csv . writer ( f )
transaction . writerow ( [ " address " , " private_key " ] )
for addr , pk in pklist . items ( ) :
transaction . writerow ( [ " %34s " % addr , pk ] )
else :
import json
f . write ( json . dumps ( pklist , indent = 4 ) )
2014-05-05 00:24:29 -07:00
2013-01-05 12:03:46 -08:00
def do_import_labels ( self ) :
2013-03-11 07:57:37 -07:00
labelsFile = self . getOpenFileName ( _ ( " Open labels file " ) , " *.dat " )
2013-01-05 12:03:46 -08:00
if not labelsFile : return
try :
f = open ( labelsFile , ' r ' )
data = f . read ( )
f . close ( )
2013-01-07 05:03:45 -08:00
for key , value in json . loads ( data ) . items ( ) :
2013-09-08 11:10:43 -07:00
self . wallet . set_label ( key , value )
2013-03-16 06:04:46 -07:00
QMessageBox . information ( None , _ ( " Labels imported " ) , _ ( " Your labels were imported from " ) + " ' %s ' " % str ( labelsFile ) )
2013-01-05 12:03:46 -08:00
except ( IOError , os . error ) , reason :
2013-01-30 01:16:00 -08:00
QMessageBox . critical ( None , _ ( " Unable to import labels " ) , _ ( " Electrum was unable to import your labels. " ) + " \n " + str ( reason ) )
2013-11-29 12:27:48 -08:00
2013-01-05 12:03:46 -08:00
def do_export_labels ( self ) :
labels = self . wallet . labels
try :
2013-03-11 07:57:37 -07:00
fileName = self . getSaveFileName ( _ ( " Select file to save your labels " ) , ' electrum_labels.dat ' , " *.dat " )
if fileName :
with open ( fileName , ' w+ ' ) as f :
json . dump ( labels , f )
2013-09-16 20:19:23 -07:00
QMessageBox . information ( None , _ ( " Labels exported " ) , _ ( " Your labels where exported to " ) + " ' %s ' " % str ( fileName ) )
2013-01-05 12:03:46 -08:00
except ( IOError , os . error ) , reason :
2013-09-16 20:19:23 -07:00
QMessageBox . critical ( None , _ ( " Unable to export labels " ) , _ ( " Electrum was unable to export your labels. " ) + " \n " + str ( reason ) )
2013-01-05 12:03:46 -08:00
2013-03-04 22:55:43 -08:00
2014-05-05 02:31:04 -07:00
def export_history_dialog ( self ) :
2014-04-18 01:04:25 -07:00
2014-05-05 02:31:04 -07:00
d = QDialog ( self )
d . setWindowTitle ( _ ( ' Export History ' ) )
d . setMinimumSize ( 400 , 200 )
vbox = QVBoxLayout ( d )
2014-04-18 01:04:25 -07:00
2014-05-05 02:31:04 -07:00
defaultname = os . path . expanduser ( ' ~/electrum-history.csv ' )
select_msg = _ ( ' Select file to export your wallet transactions to ' )
2014-04-18 01:04:25 -07:00
2014-05-05 02:31:04 -07:00
hbox , filename_e , csv_button = filename_field ( self , self . config , defaultname , select_msg )
vbox . addLayout ( hbox )
2014-04-18 01:04:25 -07:00
2014-05-05 02:31:04 -07:00
vbox . addStretch ( 1 )
2014-04-18 01:04:25 -07:00
2014-05-05 02:31:04 -07:00
h , b = ok_cancel_buttons2 ( d , _ ( ' Export ' ) )
vbox . addLayout ( h )
if not d . exec_ ( ) :
return
2014-04-18 01:04:25 -07:00
2014-05-05 02:31:04 -07:00
filename = filename_e . text ( )
if not filename :
return
try :
self . do_export_history ( self . wallet , filename , csv_button . isChecked ( ) )
2014-04-18 01:04:25 -07:00
except ( IOError , os . error ) , reason :
export_error_label = _ ( " Electrum was unable to produce a transaction export. " )
2014-05-05 02:31:04 -07:00
QMessageBox . critical ( self , _ ( " Unable to export history " ) , export_error_label + " \n " + str ( reason ) )
return
QMessageBox . information ( self , _ ( " History exported " ) , _ ( " Your wallet history has been successfully exported. " ) )
def do_export_history ( self , wallet , fileName , is_csv ) :
history = wallet . get_tx_history ( )
lines = [ ]
for item in history :
tx_hash , confirmations , is_mine , value , fee , balance , timestamp = item
if confirmations :
if timestamp is not None :
try :
time_string = datetime . datetime . fromtimestamp ( timestamp ) . isoformat ( ' ' ) [ : - 3 ]
except [ RuntimeError , TypeError , NameError ] as reason :
time_string = " unknown "
pass
else :
time_string = " unknown "
else :
time_string = " pending "
if value is not None :
value_string = format_satoshis ( value , True )
else :
value_string = ' -- '
if fee is not None :
fee_string = format_satoshis ( fee , True )
else :
fee_string = ' 0 '
if tx_hash :
label , is_default_label = wallet . get_label ( tx_hash )
label = label . encode ( ' utf-8 ' )
else :
label = " "
balance_string = format_satoshis ( balance , False )
if is_csv :
lines . append ( [ tx_hash , label , confirmations , value_string , fee_string , balance_string , time_string ] )
else :
lines . append ( { ' txid ' : tx_hash , ' date ' : " %16s " % time_string , ' label ' : label , ' value ' : value_string } )
with open ( fileName , " w+ " ) as f :
if is_csv :
transaction = csv . writer ( f )
transaction . writerow ( [ " transaction_hash " , " label " , " confirmations " , " value " , " fee " , " balance " , " timestamp " ] )
for line in lines :
transaction . writerow ( line )
else :
import json
f . write ( json . dumps ( lines , indent = 4 ) )
2014-04-18 01:04:25 -07:00
2012-06-07 07:07:49 -07:00
2014-05-01 08:35:01 -07:00
def sweep_key_dialog ( self ) :
d = QDialog ( self )
d . setWindowTitle ( _ ( ' Sweep private keys ' ) )
2014-05-05 00:58:29 -07:00
d . setMinimumSize ( 600 , 300 )
2014-05-01 08:35:01 -07:00
vbox = QVBoxLayout ( d )
vbox . addWidget ( QLabel ( _ ( " Enter private keys " ) ) )
keys_e = QTextEdit ( )
keys_e . setTabChangesFocus ( True )
vbox . addWidget ( keys_e )
2014-05-05 00:58:29 -07:00
h , address_e = address_field ( self . wallet . addresses ( ) )
vbox . addLayout ( h )
2014-05-01 08:35:01 -07:00
vbox . addStretch ( 1 )
hbox , button = ok_cancel_buttons2 ( d , _ ( ' Sweep ' ) )
vbox . addLayout ( hbox )
button . setEnabled ( False )
2014-05-05 00:58:29 -07:00
def get_address ( ) :
addr = str ( address_e . text ( ) )
if bitcoin . is_address ( addr ) :
return addr
def get_pk ( ) :
pk = str ( keys_e . toPlainText ( ) ) . strip ( )
if Wallet . is_private_key ( pk ) :
return pk . split ( )
f = lambda : button . setEnabled ( get_address ( ) is not None and get_pk ( ) is not None )
keys_e . textChanged . connect ( f )
address_e . textChanged . connect ( f )
2014-05-01 08:35:01 -07:00
if not d . exec_ ( ) :
return
fee = self . wallet . fee
2014-05-05 00:58:29 -07:00
tx = Transaction . sweep ( get_pk ( ) , self . network , get_address ( ) , fee )
2014-05-01 08:35:01 -07:00
self . show_transaction ( tx )
2013-03-04 22:55:43 -08:00
@protected
def do_import_privkey ( self , password ) :
2014-06-01 23:59:41 -07:00
if not self . wallet . has_imported_keys ( ) :
2013-03-16 04:02:34 -07:00
r = QMessageBox . question ( None , _ ( ' Warning ' ) , ' <b> ' + _ ( ' Warning ' ) + ' : \n </b><br/> ' + _ ( ' Imported keys are not recoverable from seed. ' ) + ' ' \
+ _ ( ' If you ever need to restore your wallet from its seed, these keys will be lost. ' ) + ' <p> ' \
2013-01-05 16:44:12 -08:00
+ _ ( ' Are you sure you understand what you are doing? ' ) , 3 , 4 )
if r == 4 : return
2013-03-13 06:23:10 -07:00
text = text_dialog ( self , _ ( ' Import private keys ' ) , _ ( " Enter private keys " ) + ' : ' , _ ( " Import " ) )
if not text : return
text = str ( text ) . split ( )
badkeys = [ ]
addrlist = [ ]
for key in text :
try :
addr = self . wallet . import_key ( key , password )
2013-11-09 20:21:02 -08:00
except Exception as e :
2013-03-13 06:23:10 -07:00
badkeys . append ( key )
continue
2013-11-29 12:27:48 -08:00
if not addr :
2013-03-13 06:23:10 -07:00
badkeys . append ( key )
2013-01-05 12:58:16 -08:00
else :
2013-03-13 06:23:10 -07:00
addrlist . append ( addr )
if addrlist :
QMessageBox . information ( self , _ ( ' Information ' ) , _ ( " The following addresses were added " ) + ' : \n ' + ' \n ' . join ( addrlist ) )
if badkeys :
QMessageBox . critical ( self , _ ( ' Error ' ) , _ ( " The following inputs could not be imported " ) + ' : \n ' + ' \n ' . join ( badkeys ) )
2014-06-14 07:15:00 -07:00
self . update_address_tab ( )
2013-03-13 06:23:10 -07:00
self . update_history_tab ( )
2013-01-05 12:58:16 -08:00
2013-03-04 22:55:43 -08:00
2012-02-13 06:22:15 -08:00
def settings_dialog ( self ) :
2014-08-27 13:49:35 -07:00
self . need_restart = False
2012-02-13 06:22:15 -08:00
d = QDialog ( self )
2013-01-03 03:23:59 -08:00
d . setWindowTitle ( _ ( ' Electrum Settings ' ) )
2012-02-13 06:22:15 -08:00
d . setModal ( 1 )
2012-02-13 10:02:48 -08:00
vbox = QVBoxLayout ( )
2013-10-02 22:27:34 -07:00
grid = QGridLayout ( )
grid . setColumnStretch ( 0 , 1 )
2014-08-28 01:32:03 -07:00
widgets = [ ]
2013-11-29 12:27:48 -08:00
2014-08-28 01:12:28 -07:00
lang_label = QLabel ( _ ( ' Language ' ) + ' : ' )
2014-08-28 01:32:03 -07:00
lang_help = HelpButton ( _ ( ' Select which language is used in the GUI (after restart). ' ) )
2013-01-02 07:57:18 -08:00
lang_combo = QComboBox ( )
2013-09-11 05:52:44 -07:00
from electrum . i18n import languages
2013-01-03 05:44:48 -08:00
lang_combo . addItems ( languages . values ( ) )
2013-01-02 07:57:18 -08:00
try :
2013-01-03 05:44:48 -08:00
index = languages . keys ( ) . index ( self . config . get ( " language " , ' ' ) )
2013-11-10 12:30:57 -08:00
except Exception :
2013-01-02 07:57:18 -08:00
index = 0
lang_combo . setCurrentIndex ( index )
if not self . config . is_modifiable ( ' language ' ) :
for w in [ lang_combo , lang_label ] : w . setEnabled ( False )
2014-08-27 13:49:35 -07:00
def on_lang ( x ) :
lang_request = languages . keys ( ) [ lang_combo . currentIndex ( ) ]
if lang_request != self . config . get ( ' language ' ) :
self . config . set_key ( " language " , lang_request , True )
self . need_restart = True
lang_combo . currentIndexChanged . connect ( on_lang )
2014-08-28 01:32:03 -07:00
widgets . append ( ( lang_label , lang_combo , lang_help ) )
nz_label = QLabel ( _ ( ' Zeros after decimal point ' ) + ' : ' )
nz_help = HelpButton ( _ ( ' Number of zeros displayed after the decimal point. For example, if this is set to 2, " 1. " will be displayed as " 1.00 " ' ) )
nz = QSpinBox ( )
nz . setMinimum ( 0 )
nz . setMaximum ( self . decimal_point )
nz . setValue ( self . num_zeros )
if not self . config . is_modifiable ( ' num_zeros ' ) :
for w in [ nz , nz_label ] : w . setEnabled ( False )
def on_nz ( ) :
value = nz . value ( )
if self . num_zeros != value :
self . num_zeros = value
self . config . set_key ( ' num_zeros ' , nz , True )
self . update_history_tab ( )
self . update_address_tab ( )
nz . valueChanged . connect ( on_nz )
widgets . append ( ( nz_label , nz , nz_help ) )
2013-11-29 12:27:48 -08:00
2014-08-28 01:35:22 -07:00
fee_label = QLabel ( _ ( ' Transaction fee per kb ' ) + ' : ' )
2014-08-28 01:32:03 -07:00
fee_help = HelpButton ( _ ( ' Fee per kilobyte of transaction. ' ) + ' \n ' + _ ( ' Recommended value ' ) + ' : ' + self . format_amount ( 10000 ) + ' ' + self . base_unit ( ) )
2014-06-11 05:44:26 -07:00
fee_e = BTCAmountEdit ( self . get_decimal_point )
2014-06-12 00:25:04 -07:00
fee_e . setAmount ( self . wallet . fee )
2013-03-24 01:24:45 -07:00
if not self . config . is_modifiable ( ' fee_per_kb ' ) :
2013-01-05 12:03:46 -08:00
for w in [ fee_e , fee_label ] : w . setEnabled ( False )
2014-08-27 13:49:35 -07:00
def on_fee ( ) :
fee = fee_e . get_amount ( )
self . wallet . set_fee ( fee )
fee_e . editingFinished . connect ( on_fee )
2014-08-28 01:32:03 -07:00
widgets . append ( ( fee_label , fee_e , fee_help ) )
2013-01-05 12:03:46 -08:00
2014-06-30 07:40:11 -07:00
units = [ ' BTC ' , ' mBTC ' , ' bits ' ]
2013-10-02 22:27:34 -07:00
unit_label = QLabel ( _ ( ' Base unit ' ) + ' : ' )
2013-04-06 14:34:12 -07:00
unit_combo = QComboBox ( )
unit_combo . addItems ( units )
unit_combo . setCurrentIndex ( units . index ( self . base_unit ( ) ) )
2014-08-27 13:49:35 -07:00
msg = _ ( ' Base unit of your wallet. ' ) \
+ ' \n 1BTC=1000mBTC. \n ' \
+ _ ( ' These settings affects the fields in the Send tab ' ) + ' '
2014-08-28 01:32:03 -07:00
unit_help = HelpButton ( msg )
2014-08-27 13:49:35 -07:00
def on_unit ( x ) :
unit_result = units [ unit_combo . currentIndex ( ) ]
if self . base_unit ( ) == unit_result :
return
if unit_result == ' BTC ' :
self . decimal_point = 8
elif unit_result == ' mBTC ' :
self . decimal_point = 5
elif unit_result == ' bits ' :
self . decimal_point = 2
else :
raise Exception ( ' Unknown base unit ' )
self . config . set_key ( ' decimal_point ' , self . decimal_point , True )
self . update_history_tab ( )
2014-08-30 08:33:02 -07:00
self . update_receive_tab ( )
self . update_address_tab ( )
self . update_invoices_tab ( )
2014-08-27 13:49:35 -07:00
self . update_status ( )
unit_combo . currentIndexChanged . connect ( on_unit )
2014-08-28 01:32:03 -07:00
widgets . append ( ( unit_label , unit_combo , unit_help ) )
2013-03-03 03:00:38 -08:00
2014-08-22 03:53:39 -07:00
block_explorers = [ ' Blockchain.info ' , ' Blockr.io ' , ' Insight.is ' , " Blocktrail.com " ]
2014-04-24 10:26:48 -07:00
block_ex_label = QLabel ( _ ( ' Online Block Explorer ' ) + ' : ' )
block_ex_combo = QComboBox ( )
block_ex_combo . addItems ( block_explorers )
block_ex_combo . setCurrentIndex ( block_explorers . index ( self . config . get ( ' block_explorer ' , ' Blockchain.info ' ) ) )
2014-08-28 01:32:03 -07:00
block_ex_help = HelpButton ( _ ( ' Choose which online block explorer to use for functions that open a web browser ' ) )
2014-08-27 13:49:35 -07:00
def on_be ( x ) :
be_result = block_explorers [ block_ex_combo . currentIndex ( ) ]
self . config . set_key ( ' block_explorer ' , be_result , True )
block_ex_combo . currentIndexChanged . connect ( on_be )
2014-08-28 01:32:03 -07:00
widgets . append ( ( block_ex_label , block_ex_combo , block_ex_help ) )
2014-08-23 08:45:47 -07:00
from electrum import qrscanner
system_cameras = qrscanner . _find_system_cameras ( )
qr_combo = QComboBox ( )
qr_combo . addItem ( " Default " , " default " )
for camera , device in system_cameras . items ( ) :
qr_combo . addItem ( camera , device )
#combo.addItem("Manually specify a device", config.get("video_device"))
index = qr_combo . findData ( self . config . get ( " video_device " ) )
qr_combo . setCurrentIndex ( index )
qr_label = QLabel ( _ ( ' Video Device ' ) + ' : ' )
qr_combo . setEnabled ( qrscanner . zbar is not None )
2014-08-28 01:32:03 -07:00
qr_help = HelpButton ( _ ( " Install the zbar package to enable this. \n On linux, type: ' apt-get install python-zbar ' " ) )
2014-08-27 13:49:35 -07:00
on_video_device = lambda x : self . config . set_key ( " video_device " , str ( qr_combo . itemData ( x ) . toString ( ) ) , True )
qr_combo . currentIndexChanged . connect ( on_video_device )
2014-08-28 01:32:03 -07:00
widgets . append ( ( qr_label , qr_combo , qr_help ) )
usechange_cb = QCheckBox ( _ ( ' Use change addresses ' ) )
usechange_cb . setChecked ( self . wallet . use_change )
usechange_help = HelpButton ( _ ( ' Using change addresses makes it more difficult for other people to track your transactions. ' ) )
if not self . config . is_modifiable ( ' use_change ' ) : usechange_cb . setEnabled ( False )
def on_usechange ( x ) :
usechange_result = x == Qt . Checked
if self . wallet . use_change != usechange_result :
self . wallet . use_change = usechange_result
self . wallet . storage . put ( ' use_change ' , self . wallet . use_change )
usechange_cb . stateChanged . connect ( on_usechange )
widgets . append ( ( usechange_cb , None , usechange_help ) )
2014-08-28 01:36:28 -07:00
showtx_cb = QCheckBox ( _ ( ' Show transaction before broadcast ' ) )
2014-08-28 01:32:03 -07:00
showtx_cb . setChecked ( self . config . get ( ' show_before_broadcast ' , False ) )
showtx_cb . stateChanged . connect ( lambda x : self . config . set_key ( ' show_before_broadcast ' , showtx_cb . isChecked ( ) ) )
showtx_help = HelpButton ( _ ( ' Display the details of your transactions before broadcasting it. ' ) )
widgets . append ( ( showtx_cb , None , showtx_help ) )
2014-08-27 13:49:35 -07:00
can_edit_fees_cb = QCheckBox ( _ ( ' Set transaction fees manually ' ) )
can_edit_fees_cb . setChecked ( self . config . get ( ' can_edit_fees ' , False ) )
def on_editfees ( x ) :
self . config . set_key ( ' can_edit_fees ' , x == Qt . Checked )
self . update_fee_edit ( )
can_edit_fees_cb . stateChanged . connect ( on_editfees )
2014-08-28 01:32:03 -07:00
can_edit_fees_help = HelpButton ( _ ( ' This option lets you edit fees in the send tab. ' ) )
widgets . append ( ( can_edit_fees_cb , None , can_edit_fees_help ) )
for a , b , c in widgets :
i = grid . rowCount ( )
if b :
grid . addWidget ( a , i , 0 )
grid . addWidget ( b , i , 1 )
else :
grid . addWidget ( a , i , 0 , 1 , 2 )
grid . addWidget ( c , i , 2 )
2014-08-23 08:45:47 -07:00
2013-10-02 22:27:34 -07:00
vbox . addLayout ( grid )
2014-04-28 06:25:47 -07:00
vbox . addStretch ( 1 )
2014-08-27 13:49:35 -07:00
vbox . addLayout ( close_button ( d ) )
2013-11-29 12:27:48 -08:00
d . setLayout ( vbox )
2012-02-13 06:22:15 -08:00
2012-06-12 04:21:01 -07:00
# run the dialog
2014-08-27 13:49:35 -07:00
d . exec_ ( )
2014-04-24 10:26:48 -07:00
2013-09-23 07:14:28 -07:00
run_hook ( ' close_settings_dialog ' )
2014-08-27 13:49:35 -07:00
if self . need_restart :
2013-01-03 05:44:48 -08:00
QMessageBox . warning ( self , _ ( ' Success ' ) , _ ( ' Please restart Electrum to activate the new GUI settings ' ) , _ ( ' OK ' ) )
2012-06-12 04:21:01 -07:00
2014-08-27 13:49:35 -07:00
2013-04-28 04:47:19 -07:00
def run_network_dialog ( self ) :
2013-11-05 09:55:53 -08:00
if not self . network :
return
2013-09-10 09:27:32 -07:00
NetworkDialog ( self . wallet . network , self . config , self ) . do_exec ( )
2012-02-13 06:44:16 -08:00
2012-09-20 20:53:14 -07:00
def closeEvent ( self , event ) :
2014-05-04 12:58:02 -07:00
self . config . set_key ( " is_maximized " , self . isMaximized ( ) )
if not self . isMaximized ( ) :
g = self . geometry ( )
self . config . set_key ( " winpos-qt " , [ g . left ( ) , g . top ( ) , g . width ( ) , g . height ( ) ] )
2013-01-12 02:23:35 -08:00
self . save_column_widths ( )
2013-08-30 13:59:36 -07:00
self . config . set_key ( " console-history " , self . console . history [ - 50 : ] , True )
2013-10-05 05:30:02 -07:00
self . wallet . storage . put ( ' accounts_expanded ' , self . accounts_expanded )
2012-09-20 20:53:14 -07:00
event . accept ( )
2012-02-13 06:44:16 -08:00
2013-09-23 01:53:04 -07:00
def plugins_dialog ( self ) :
2013-09-23 07:14:28 -07:00
from electrum . plugins import plugins
2013-09-23 01:53:04 -07:00
d = QDialog ( self )
d . setWindowTitle ( _ ( ' Electrum Plugins ' ) )
d . setModal ( 1 )
2013-09-23 07:14:28 -07:00
vbox = QVBoxLayout ( d )
2013-09-23 01:53:04 -07:00
2013-09-23 07:14:28 -07:00
# plugins
scroll = QScrollArea ( )
scroll . setEnabled ( True )
scroll . setWidgetResizable ( True )
scroll . setMinimumSize ( 400 , 250 )
vbox . addWidget ( scroll )
2013-09-23 01:53:04 -07:00
w = QWidget ( )
2013-09-23 07:14:28 -07:00
scroll . setWidget ( w )
w . setMinimumHeight ( len ( plugins ) * 35 )
2013-09-23 01:53:04 -07:00
2013-09-23 07:14:28 -07:00
grid = QGridLayout ( )
grid . setColumnStretch ( 0 , 1 )
w . setLayout ( grid )
2013-09-23 01:53:04 -07:00
2013-10-08 02:38:40 -07:00
def do_toggle ( cb , p , w ) :
2014-09-04 06:45:03 -07:00
if p . is_enabled ( ) :
if p . disable ( ) :
p . close ( )
else :
if p . enable ( ) :
2014-09-04 07:37:51 -07:00
p . load_wallet ( self . wallet )
2014-09-04 06:45:03 -07:00
p . init_qt ( self . gui_object )
r = p . is_enabled ( )
2013-10-08 02:38:40 -07:00
cb . setChecked ( r )
if w : w . setEnabled ( r )
def mk_toggle ( cb , p , w ) :
return lambda : do_toggle ( cb , p , w )
2013-09-23 07:14:28 -07:00
for i , p in enumerate ( plugins ) :
2013-09-23 01:53:04 -07:00
try :
cb = QCheckBox ( p . fullname ( ) )
cb . setDisabled ( not p . is_available ( ) )
cb . setChecked ( p . is_enabled ( ) )
2013-09-23 07:14:28 -07:00
grid . addWidget ( cb , i , 0 )
2013-09-23 01:53:04 -07:00
if p . requires_settings ( ) :
2013-10-08 02:38:40 -07:00
w = p . settings_widget ( self )
w . setEnabled ( p . is_enabled ( ) )
grid . addWidget ( w , i , 1 )
2013-11-29 12:27:48 -08:00
else :
2013-10-08 02:38:40 -07:00
w = None
cb . clicked . connect ( mk_toggle ( cb , p , w ) )
2013-09-23 07:14:28 -07:00
grid . addWidget ( HelpButton ( p . description ( ) ) , i , 2 )
2013-11-10 12:30:57 -08:00
except Exception :
2013-09-23 01:53:04 -07:00
print_msg ( _ ( " Error: cannot display plugin " ) , p )
traceback . print_exc ( file = sys . stdout )
2013-09-23 07:14:28 -07:00
grid . setRowStretch ( i + 1 , 1 )
vbox . addLayout ( close_button ( d ) )
2013-09-23 01:53:04 -07:00
d . exec_ ( )
2013-09-24 07:55:25 -07:00
def show_account_details ( self , k ) :
2014-04-01 02:25:12 -07:00
account = self . wallet . accounts [ k ]
2013-09-24 07:55:25 -07:00
d = QDialog ( self )
d . setWindowTitle ( _ ( ' Account Details ' ) )
d . setModal ( 1 )
vbox = QVBoxLayout ( d )
name = self . wallet . get_account_name ( k )
label = QLabel ( ' Name: ' + name )
vbox . addWidget ( label )
2014-04-01 02:25:12 -07:00
vbox . addWidget ( QLabel ( _ ( ' Address type ' ) + ' : ' + account . get_type ( ) ) )
2013-09-24 07:55:25 -07:00
2014-04-01 02:25:12 -07:00
vbox . addWidget ( QLabel ( _ ( ' Derivation ' ) + ' : ' + k ) )
vbox . addWidget ( QLabel ( _ ( ' Master Public Key: ' ) ) )
text = QTextEdit ( )
text . setReadOnly ( True )
text . setMaximumHeight ( 170 )
vbox . addWidget ( text )
2013-09-24 07:55:25 -07:00
2014-04-01 02:25:12 -07:00
mpk_text = ' \n ' . join ( account . get_master_pubkeys ( ) )
text . setText ( mpk_text )
2013-09-24 07:55:25 -07:00
vbox . addLayout ( close_button ( d ) )
d . exec_ ( )