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/>.
2012-02-13 07:49:20 -08:00
import sys , time , datetime , re
2013-03-02 03:26:21 -08:00
from 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
2013-03-03 04:50:08 -08:00
from qrcodewidget import QRCodeWidget
2013-03-02 09:03:29 -08:00
2012-05-10 11:39:50 -07:00
try :
import PyQt4
except :
2012-08-19 19:59:05 -07:00
sys . exit ( " Error: Could not import PyQt4 on Linux systems, you may try ' sudo apt-get install python-qt4 ' " )
2012-05-10 11:39:50 -07:00
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
2012-02-11 08:02:28 -08:00
import PyQt4 . QtGui as QtGui
2013-04-01 03:11:24 -07:00
from electrum . interface import DEFAULT_SERVERS , DEFAULT_PORTS
2013-03-24 03:25:17 -07:00
from electrum . bitcoin import MIN_RELAY_TX_FEE
2012-02-11 04:14:12 -08:00
2012-02-14 06:56:01 -08:00
try :
import icons_rc
except :
2013-03-02 09:03:29 -08:00
sys . exit ( " Error: Could not import icons_rc.py, please generate it with: ' pyrcc4 icons.qrc -o gui/icons_rc.py ' " )
2012-02-14 02:33:09 -08:00
2013-03-02 03:26:21 -08:00
from electrum . wallet import format_satoshis
from electrum . bitcoin import Transaction , is_valid
from electrum import mnemonic
2013-03-03 22:15:36 -08:00
from electrum import util , bitcoin , commands
2013-03-02 03:26:21 -08:00
2013-03-03 05:49:42 -08:00
import bmp , pyqrnative
2013-01-05 06:23:35 -08:00
import exchange_rate
2012-05-30 07:46:04 -07:00
2013-04-06 14:34:12 -07:00
from amountedit import AmountEdit
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 '
2013-03-02 03:26:21 -08:00
from electrum import ELECTRUM_VERSION
2013-01-15 12:31:21 -08:00
import re
class UpdateLabel ( QtGui . QLabel ) :
def __init__ ( self , config , parent = None ) :
QtGui . QLabel . __init__ ( self , parent )
2013-01-30 07:25:48 -08:00
self . new_version = False
2013-01-15 12:31:21 -08:00
try :
2013-01-16 00:32:03 -08:00
con = httplib . HTTPConnection ( ' electrum.org ' , 80 , timeout = 5 )
2013-01-15 12:31:21 -08:00
con . request ( " GET " , " /version " )
res = con . getresponse ( )
2013-01-16 03:37:21 -08:00
except socket . error as msg :
2013-01-16 04:30:53 -08:00
print_error ( " Could not retrieve version information " )
2013-01-16 03:37:21 -08:00
return
if res . status == 200 :
self . latest_version = res . read ( )
self . latest_version = self . latest_version . replace ( " \n " , " " )
2013-01-16 04:44:18 -08:00
if ( re . match ( ' ^ \ d+( \ . \ d+)*$ ' , self . latest_version ) ) :
2013-01-16 03:37:21 -08:00
self . config = config
self . current_version = ELECTRUM_VERSION
if ( self . compare_versions ( self . latest_version , self . current_version ) == 1 ) :
2013-01-16 04:44:18 -08:00
latest_seen = self . config . get ( " last_seen_version " , ELECTRUM_VERSION )
2013-01-16 03:37:21 -08:00
if ( self . compare_versions ( self . latest_version , latest_seen ) == 1 ) :
2013-01-30 07:25:48 -08:00
self . new_version = True
2013-01-16 04:30:53 -08:00
self . setText ( _ ( " New version available " ) + " : " + self . latest_version )
2013-01-15 12:31:21 -08:00
2013-01-16 03:37:21 -08:00
def compare_versions ( self , version1 , version2 ) :
2013-01-16 05:45:07 -08:00
def normalize ( v ) :
return [ int ( x ) for x in re . sub ( r ' ( \ .0+)*$ ' , ' ' , v ) . split ( " . " ) ]
return cmp ( normalize ( version1 ) , normalize ( version2 ) )
2013-01-15 12:31:21 -08:00
def ignore_this_version ( self ) :
self . setText ( " " )
2013-01-16 03:37:21 -08:00
self . config . set_key ( " last_seen_version " , self . latest_version , True )
2013-01-15 12:31:21 -08:00
QMessageBox . information ( self , _ ( " Preference saved " ) , _ ( " Notifications about this update will not be shown again. " ) )
self . dialog . done ( 0 )
def ignore_all_version ( self ) :
self . setText ( " " )
2013-01-16 03:37:21 -08:00
self . config . set_key ( " last_seen_version " , " 9.9.9 " , True )
2013-01-15 12:31:21 -08:00
QMessageBox . information ( self , _ ( " Preference saved " ) , _ ( " No more notifications about version updates will be shown. " ) )
self . dialog . done ( 0 )
def open_website ( self ) :
webbrowser . open ( " http://electrum.org/download.html " )
self . dialog . done ( 0 )
def mouseReleaseEvent ( self , event ) :
dialog = QDialog ( self )
dialog . setWindowTitle ( _ ( ' Electrum update ' ) )
dialog . setModal ( 1 )
main_layout = QGridLayout ( )
2013-01-30 01:16:00 -08:00
main_layout . addWidget ( QLabel ( _ ( " A new version of Electrum is available: " ) + " " + self . latest_version ) , 0 , 0 , 1 , 3 )
2013-01-15 12:31:21 -08:00
ignore_version = QPushButton ( _ ( " Ignore this version " ) )
ignore_version . clicked . connect ( self . ignore_this_version )
ignore_all_versions = QPushButton ( _ ( " Ignore all versions " ) )
ignore_all_versions . clicked . connect ( self . ignore_all_version )
open_website = QPushButton ( _ ( " Goto download page " ) )
open_website . clicked . connect ( self . open_website )
main_layout . addWidget ( ignore_version , 1 , 0 )
main_layout . addWidget ( ignore_all_versions , 1 , 1 )
main_layout . addWidget ( open_website , 1 , 2 )
dialog . setLayout ( main_layout )
self . dialog = dialog
if not dialog . exec_ ( ) : return
2012-02-14 05:34:19 -08:00
2012-02-14 00:52:03 -08:00
2012-02-14 05:05:58 -08:00
class Timer ( QtCore . QThread ) :
2012-02-11 13:19:22 -08:00
def run ( self ) :
while True :
2012-02-14 05:05:58 -08:00
self . emit ( QtCore . SIGNAL ( ' timersignal ' ) )
2012-02-11 13:19:22 -08:00
time . sleep ( 0.5 )
2012-06-12 04:21:01 -07:00
class HelpButton ( QPushButton ) :
def __init__ ( self , text ) :
QPushButton . __init__ ( self , ' ? ' )
2012-06-13 02:38:54 -07:00
self . setFocusPolicy ( Qt . NoFocus )
2012-06-12 04:21:01 -07:00
self . setFixedWidth ( 20 )
self . clicked . connect ( lambda : QMessageBox . information ( self , ' Help ' , text , ' OK ' ) )
2012-02-14 07:41:09 -08:00
class EnterButton ( QPushButton ) :
def __init__ ( self , text , func ) :
QPushButton . __init__ ( self , text )
self . func = func
self . clicked . connect ( func )
def keyPressEvent ( self , e ) :
if e . key ( ) == QtCore . Qt . Key_Return :
apply ( self . func , ( ) )
2012-06-09 13:23:56 -07:00
class MyTreeWidget ( QTreeWidget ) :
def __init__ ( self , parent ) :
QTreeWidget . __init__ ( self , parent )
2012-06-09 14:52:45 -07:00
def ddfr ( item ) :
2012-06-09 13:23:56 -07:00
if not item : return
2012-06-10 11:36:30 -07:00
for i in range ( 0 , self . viewport ( ) . height ( ) / 5 ) :
2012-06-09 13:23:56 -07:00
if self . itemAt ( QPoint ( 0 , i * 5 ) ) == item :
break
else :
return
2012-06-10 07:54:43 -07:00
for j in range ( 0 , 30 ) :
if self . itemAt ( QPoint ( 0 , i * 5 + j ) ) != item :
break
self . emit ( SIGNAL ( ' customContextMenuRequested(const QPoint&) ' ) , QPoint ( 50 , i * 5 + j - 1 ) )
2012-06-10 08:47:27 -07:00
2012-06-09 13:23:56 -07:00
self . connect ( self , SIGNAL ( ' itemActivated(QTreeWidgetItem*, int) ' ) , ddfr )
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
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-10-13 23:25:09 -07:00
def waiting_dialog ( f ) :
s = Timer ( )
s . start ( )
w = QDialog ( )
w . resize ( 200 , 70 )
w . setWindowTitle ( ' Electrum ' )
l = QLabel ( ' ' )
vbox = QVBoxLayout ( )
vbox . addWidget ( l )
w . setLayout ( vbox )
w . show ( )
def ff ( ) :
s = f ( )
if s : l . setText ( s )
else : w . close ( )
w . connect ( s , QtCore . SIGNAL ( ' timersignal ' ) , ff )
w . exec_ ( )
w . destroy ( )
2012-02-14 07:41:09 -08:00
2013-03-13 06:23:10 -07:00
def ok_cancel_buttons ( dialog , ok_label = _ ( " OK " ) ) :
2012-02-14 00:52:03 -08:00
hbox = QHBoxLayout ( )
hbox . addStretch ( 1 )
2013-03-13 06:23:10 -07:00
b = QPushButton ( _ ( " Cancel " ) )
2012-02-14 00:52:03 -08:00
hbox . addWidget ( b )
b . clicked . connect ( dialog . reject )
2013-03-13 06:23:10 -07:00
b = QPushButton ( ok_label )
2013-03-04 21:35:34 -08:00
hbox . addWidget ( b )
b . clicked . connect ( dialog . accept )
b . setDefault ( True )
2012-02-14 00:52:03 -08:00
return hbox
2013-03-13 06:23:10 -07:00
def text_dialog ( parent , title , label , ok_label ) :
dialog = QDialog ( parent )
dialog . setMinimumWidth ( 500 )
dialog . setWindowTitle ( title )
dialog . setModal ( 1 )
l = QVBoxLayout ( )
dialog . setLayout ( l )
l . addWidget ( QLabel ( label ) )
txt = QTextEdit ( )
l . addWidget ( txt )
l . addLayout ( ok_cancel_buttons ( dialog , ok_label ) )
if dialog . exec_ ( ) :
return unicode ( txt . toPlainText ( ) )
2013-02-02 01:20:24 -08:00
default_column_widths = { " history " : [ 40 , 140 , 350 , 140 ] , " contacts " : [ 350 , 330 ] ,
2013-03-03 10:14:27 -08:00
" receive " : [ [ 370 ] , [ 370 , 200 , 130 ] ] }
2013-01-12 02:23:35 -08:00
2012-02-12 00:52:26 -08:00
class ElectrumWindow ( QMainWindow ) :
2012-02-11 04:14:12 -08:00
2012-10-11 11:10:12 -07:00
def __init__ ( self , wallet , config ) :
2012-02-11 08:38:44 -08:00
QMainWindow . __init__ ( self )
2013-01-05 04:44:20 -08:00
self . lite = None
2012-02-11 04:14:12 -08:00
self . wallet = wallet
2012-10-11 11:10:12 -07:00
self . config = config
2013-04-05 07:00:34 -07:00
self . current_account = self . config . get ( " current_account " , None )
2013-03-03 07:01:47 -08:00
2013-04-05 07:00:34 -07:00
self . init_plugins ( )
2013-03-10 09:04:00 -07:00
self . create_status_bar ( )
2013-03-04 08:20:38 -08:00
self . wallet . interface . register_callback ( ' updated ' , lambda : self . emit ( QtCore . SIGNAL ( ' update_wallet ' ) ) )
self . wallet . interface . register_callback ( ' banner ' , lambda : self . emit ( QtCore . SIGNAL ( ' banner_signal ' ) ) )
self . wallet . interface . register_callback ( ' disconnected ' , lambda : self . emit ( QtCore . SIGNAL ( ' update_status ' ) ) )
self . wallet . interface . register_callback ( ' disconnecting ' , lambda : self . emit ( QtCore . SIGNAL ( ' update_status ' ) ) )
2012-04-07 06:13:18 -07:00
2013-03-03 04:50:08 -08:00
self . expert_mode = config . get ( ' classic_expert_mode ' , False )
2013-04-06 14:34:12 -07:00
self . decimal_point = config . get ( ' decimal_point ' , 8 )
2012-10-11 11:10:12 -07:00
2013-03-02 03:26:21 -08:00
set_language ( config . get ( ' language ' ) )
2012-02-14 05:34:19 -08:00
self . funds_error = False
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-03-17 05:50:45 -07:00
self . column_widths = self . config . get ( " column_widths " , 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 ' ) )
tabs . addTab ( self . create_contacts_tab ( ) , _ ( ' Contacts ' ) )
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 ] )
2012-10-11 11:10:12 -07:00
title = ' Electrum ' + self . wallet . electrum_version + ' - ' + self . config . path
2013-01-29 23:52:24 -08:00
if not self . wallet . seed : title + = ' [ %s ] ' % ( _ ( ' seedless ' ) )
2012-05-13 01:54:03 -07:00
self . setWindowTitle ( title )
2012-02-11 08:38:44 -08:00
2012-02-12 00:52:26 -08:00
QShortcut ( QKeySequence ( " Ctrl+W " ) , self , self . close )
QShortcut ( QKeySequence ( " Ctrl+Q " ) , self , self . close )
2012-02-13 05:52:59 -08: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 ( ) ) )
2012-04-07 06:13:18 -07:00
2013-03-04 08:20:38 -08:00
self . connect ( self , QtCore . SIGNAL ( ' update_wallet ' ) , self . update_wallet )
self . connect ( self , QtCore . SIGNAL ( ' update_status ' ) , self . update_status )
2013-03-17 02:54:21 -07:00
self . connect ( self , QtCore . SIGNAL ( ' banner_signal ' ) , lambda : self . console . showMessage ( self . wallet . interface . banner ) )
2012-06-09 15:16:09 -07:00
self . history_list . setFocus ( True )
2013-01-05 06:23:35 -08:00
self . exchanger = exchange_rate . Exchanger ( self )
self . connect ( self , SIGNAL ( " refresh_balance() " ) , self . update_wallet )
2012-02-14 00:52:03 -08:00
2012-06-14 07:53:23 -07:00
# dark magic fix by flatfly; https://bitcointalk.org/index.php?topic=73651.msg959913#msg959913
if platform . system ( ) == ' Windows ' :
2012-06-15 04:46:30 -07:00
n = 3 if self . wallet . seed else 2
2012-06-14 07:56:20 -07:00
tabs . setCurrentIndex ( n )
2012-06-14 07:53:23 -07:00
tabs . setCurrentIndex ( 0 )
2013-02-02 00:40:54 -08:00
# set initial message
2013-03-17 02:54:21 -07:00
self . console . showMessage ( self . wallet . interface . banner )
2013-02-02 00:40:54 -08:00
2013-03-12 10:40:21 -07:00
# plugins that need to change the GUI do it here
2013-03-15 01:58:05 -07:00
self . run_hook ( ' init_gui ' )
2013-03-12 10:40:21 -07:00
2013-03-03 07:01:47 -08:00
# plugins
def init_plugins ( self ) :
2013-03-15 05:00:59 -07:00
import imp , pkgutil , __builtin__
if __builtin__ . use_local_modules :
2013-03-03 07:01:47 -08:00
fp , pathname , description = imp . find_module ( ' plugins ' )
2013-03-15 05:00:59 -07:00
plugin_names = [ name for a , name , b in pkgutil . iter_modules ( [ pathname ] ) ]
2013-03-15 05:16:41 -07:00
plugin_names = filter ( lambda name : os . path . exists ( os . path . join ( pathname , name + ' .py ' ) ) , plugin_names )
2013-03-03 07:01:47 -08:00
imp . load_module ( ' electrum_plugins ' , fp , pathname , description )
2013-03-15 01:58:05 -07:00
plugins = map ( lambda name : imp . load_source ( ' electrum_plugins. ' + name , os . path . join ( pathname , name + ' .py ' ) ) , plugin_names )
2013-03-03 07:01:47 -08:00
else :
2013-03-03 07:33:09 -08:00
import electrum_plugins
plugin_names = [ name for a , name , b in pkgutil . iter_modules ( electrum_plugins . __path__ ) ]
2013-03-15 01:58:05 -07:00
plugins = [ __import__ ( ' electrum_plugins. ' + name , fromlist = [ ' electrum_plugins ' ] ) for name in plugin_names ]
2013-03-03 07:01:47 -08:00
2013-03-15 01:58:05 -07:00
self . plugins = [ ]
for p in plugins :
2013-03-03 00:52:46 -08:00
try :
2013-03-15 01:58:05 -07:00
self . plugins . append ( p . Plugin ( self ) )
2013-03-03 00:52:46 -08:00
except :
print_msg ( " Error:cannot initialize plugin " , p )
traceback . print_exc ( file = sys . stdout )
2013-03-03 07:01:47 -08:00
2013-03-14 09:05:50 -07:00
def run_hook ( self , name , * args ) :
2013-03-15 01:58:05 -07:00
for p in self . plugins :
if not p . is_enabled ( ) :
continue
try :
f = eval ( ' p. ' + name )
except :
continue
apply ( f , args )
return
2013-03-03 00:52:46 -08:00
2013-03-15 01:58:05 -07:00
2013-03-12 09:10:35 -07:00
def set_label ( self , name , text = None ) :
changed = False
old_text = self . wallet . labels . get ( name )
if text :
if old_text != text :
self . wallet . labels [ name ] = text
changed = True
else :
if old_text :
self . wallet . labels . pop ( name )
changed = True
2013-03-14 09:05:50 -07:00
self . run_hook ( ' set_label ' , name , text , changed )
2013-03-12 09:10:35 -07:00
return changed
2013-03-11 07:57:37 -07:00
# custom wrappers for getOpenFileName and getSaveFileName, that remember the path selected by the user
def getOpenFileName ( self , title , filter = None ) :
directory = self . config . get ( ' io_dir ' , os . path . expanduser ( ' ~ ' ) )
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
def getSaveFileName ( self , title , filename , filter = None ) :
directory = self . config . get ( ' io_dir ' , os . path . expanduser ( ' ~ ' ) )
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 ) :
QMainWindow . close ( self )
2013-03-12 10:07:17 -07:00
self . 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-03-12 10:07:17 -07:00
self . run_hook ( ' timer_actions ' )
2013-04-06 14:34:12 -07:00
def format_amount ( self , x , is_diff = False ) :
return format_satoshis ( x , is_diff , self . wallet . num_zeros , self . decimal_point )
def read_amount ( self , x ) :
2013-04-07 13:08:56 -07:00
if x in [ ' . ' , ' ' ] : return None
2013-04-06 14:34:12 -07:00
p = pow ( 10 , self . decimal_point )
return int ( p * Decimal ( x ) )
def base_unit ( self ) :
assert self . decimal_point in [ 5 , 8 ]
return " BTC " if self . decimal_point == 8 else " mBTC "
2013-03-04 08:20:38 -08:00
def update_status ( self ) :
2012-05-16 08:29:05 -07:00
if self . wallet . interface and self . wallet . interface . is_connected :
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 " )
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 ( )
if u : text + = " [ %s unconfirmed] " % ( self . format_amount ( u , True ) . strip ( ) )
2013-01-05 06:23:35 -08:00
text + = self . create_quote_text ( Decimal ( c + u ) / 100000000 )
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-01-06 06:11:20 -08:00
self . status_text = text
2012-02-11 13:19:22 -08:00
self . statusBar ( ) . showMessage ( text )
2012-02-12 08:19:16 -08:00
self . status_button . setIcon ( icon )
2012-02-11 13:19:22 -08:00
2013-03-04 08:20:38 -08:00
def update_wallet ( self ) :
self . update_status ( )
2012-11-20 12:36:06 -08:00
if self . wallet . up_to_date or not self . wallet . interface . 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 ( )
self . update_contacts_tab ( )
2012-06-09 08:18:53 -07:00
self . update_completions ( )
2012-02-11 22:27:32 -08:00
2013-02-01 09:22:36 -08:00
2013-01-05 06:23:35 -08:00
def create_quote_text ( self , btc_balance ) :
quote_currency = self . config . get ( " currency " , " None " )
quote_balance = self . exchanger . exchange ( btc_balance , quote_currency )
if quote_balance is None :
quote_text = " "
else :
quote_text = " ( %.2f %s ) " % ( quote_balance , quote_currency )
return quote_text
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 ' ) ] )
2012-06-09 08:49:44 -07:00
self . connect ( l , SIGNAL ( ' itemDoubleClicked(QTreeWidgetItem*, int) ' ) , self . tx_label_clicked )
self . connect ( l , SIGNAL ( ' itemChanged(QTreeWidgetItem*, int) ' ) , self . tx_label_changed )
2012-11-28 06:38:44 -08:00
2012-06-09 08:49:44 -07:00
l . setContextMenuPolicy ( Qt . CustomContextMenu )
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 ) :
self . history_list . selectedIndexes ( )
item = self . history_list . currentItem ( )
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-02-28 04:13:35 -08:00
#menu.addAction(_("Copy ID to Clipboard"), lambda: self.app.clipboard().setText(tx_hash))
menu . addAction ( _ ( " Details " ) , lambda : self . show_tx_details ( 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 ) )
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-02-28 04:13:35 -08:00
def show_tx_details ( self , tx ) :
2013-03-04 08:20:38 -08:00
dialog = QDialog ( self )
2013-01-12 20:52:03 -08:00
dialog . setModal ( 1 )
dialog . setWindowTitle ( _ ( " Transaction Details " ) )
2013-02-28 04:13:35 -08:00
vbox = QVBoxLayout ( )
dialog . setLayout ( vbox )
dialog . setMinimumSize ( 600 , 300 )
tx_hash = tx . hash ( )
if tx_hash in self . wallet . transactions . keys ( ) :
2013-04-06 14:35:07 -07:00
is_relevant , is_mine , v , fee = self . wallet . get_tx_value ( tx )
2013-02-28 04:13:35 -08:00
conf , timestamp = self . wallet . verifier . get_confirmations ( tx_hash )
if timestamp :
time_str = datetime . datetime . fromtimestamp ( timestamp ) . isoformat ( ' ' ) [ : - 3 ]
else :
time_str = ' pending '
else :
is_mine = False
vbox . addWidget ( QLabel ( " Transaction ID: " ) )
e = QLineEdit ( tx_hash )
e . setReadOnly ( True )
vbox . addWidget ( e )
vbox . addWidget ( QLabel ( " Date: %s " % time_str ) )
vbox . addWidget ( QLabel ( " Status: %d confirmations " % conf ) )
if is_mine :
2013-03-16 05:34:51 -07:00
if fee is not None :
2013-04-06 14:34:12 -07:00
vbox . addWidget ( QLabel ( " Amount sent: %s " % self . format_amount ( v - fee ) ) )
vbox . addWidget ( QLabel ( " Transaction fee: %s " % self . format_amount ( fee ) ) )
2013-02-28 04:13:35 -08:00
else :
2013-04-06 14:34:12 -07:00
vbox . addWidget ( QLabel ( " Amount sent: %s " % self . format_amount ( v ) ) )
2013-02-28 04:13:35 -08:00
vbox . addWidget ( QLabel ( " Transaction fee: unknown " ) )
else :
2013-04-06 14:34:12 -07:00
vbox . addWidget ( QLabel ( " Amount received: %s " % self . format_amount ( v ) ) )
2013-01-12 20:52:03 -08:00
2013-02-28 04:13:35 -08:00
vbox . addWidget ( self . generate_transaction_information_widget ( tx ) )
ok_button = QPushButton ( _ ( " Close " ) )
2013-01-12 20:52:03 -08:00
ok_button . setDefault ( True )
ok_button . clicked . connect ( dialog . accept )
hbox = QHBoxLayout ( )
hbox . addStretch ( 1 )
hbox . addWidget ( ok_button )
vbox . addLayout ( hbox )
dialog . 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 ) :
if self . is_edit :
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-03-12 09:10:35 -07:00
self . set_label ( tx_hash , text )
2012-02-12 15:00:33 -08:00
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 ) :
l = self . receive_list if is_recv else self . contacts_list
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-03-14 08:32:05 -07:00
changed = self . set_label ( addr , text )
if changed :
self . update_history_tab ( )
self . update_completions ( )
2012-11-28 06:38:44 -08:00
2013-03-03 04:50:08 -08:00
self . current_item_changed ( item )
2012-11-28 22:38:32 -08:00
2013-03-14 09:05:50 -07:00
self . 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-03-14 09:05:50 -07:00
self . 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
2012-11-04 06:38:34 -08:00
if conf :
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 ]
2012-11-15 00:14:24 -08:00
except :
time_str = " unknown "
if conf == - 1 :
icon = None
2012-10-29 01:31:42 -07:00
if conf == 0 :
icon = QIcon ( " :icons/unconfirmed.png " )
elif conf < 6 :
2012-10-12 23:57:22 -07:00
icon = QIcon ( " :icons/clock %d .png " % conf )
else :
icon = QIcon ( " :icons/confirmed.png " )
2012-02-11 22:27:32 -08:00
else :
time_str = ' pending '
2012-03-18 04:38:40 -07:00
icon = QIcon ( " :icons/unconfirmed.png " )
2012-02-12 09:02:11 -08:00
2012-11-16 05:39:31 -08:00
if value is not None :
2013-04-06 14:34:12 -07:00
v_str = self . format_amount ( value , True )
2012-11-16 05:39:31 -08:00
else :
v_str = ' -- '
2013-04-06 14:34:12 -07:00
balance_str = self . format_amount ( balance )
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 )
2012-11-16 05:39:31 -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 ) )
2012-02-11 08:02:28 -08:00
def create_send_tab ( self ) :
2012-02-11 22:27:32 -08:00
w = QWidget ( )
2012-02-13 10:02:48 -08:00
grid = QGridLayout ( )
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 )
2012-02-11 22:27:32 -08:00
2013-04-05 07:00:34 -07:00
2012-02-14 04:38:47 -08:00
self . payto_e = QLineEdit ( )
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 )
2013-03-03 05:49:42 -08:00
2012-06-23 04:30:58 -07:00
grid . addWidget ( HelpButton ( _ ( ' Recipient of the funds. ' ) + ' \n \n ' + _ ( ' You may enter a Bitcoin address, a label from your list of contacts (a list of completions will be proposed), or an alias (email-like address that forwards to a Bitcoin address) ' ) ) , 1 , 4 )
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 )
2012-02-14 04:38:47 -08:00
self . message_e = QLineEdit ( )
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 )
2012-06-23 04:30:58 -07:00
grid . addWidget ( 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. ' ) ) , 2 , 4 )
2012-02-11 22:27:32 -08:00
2013-04-06 14:34:12 -07:00
self . amount_e = AmountEdit ( self . base_unit )
2012-05-18 06:28:55 -07:00
grid . addWidget ( QLabel ( _ ( ' Amount ' ) ) , 3 , 0 )
2012-02-14 04:38:47 -08:00
grid . addWidget ( self . amount_e , 3 , 1 , 1 , 2 )
2012-06-23 04:30:58 -07:00
grid . addWidget ( HelpButton (
_ ( ' Amount to be sent. ' ) + ' \n \n ' \
2013-04-07 12:27:27 -07:00
+ _ ( ' 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. ' ) \
2013-04-07 13:09:40 -07:00
+ ' \n \n ' + _ ( ' Keyboard shortcut: type " ! " to send all your coins. ' ) ) , 3 , 3 )
2012-02-11 22:27:32 -08:00
2013-04-06 14:34:12 -07:00
self . fee_e = AmountEdit ( self . base_unit )
2012-05-18 06:28:55 -07:00
grid . addWidget ( QLabel ( _ ( ' Fee ' ) ) , 4 , 0 )
2012-06-12 11:26:37 -07:00
grid . addWidget ( self . fee_e , 4 , 1 , 1 , 2 )
2012-06-23 04:30:58 -07:00
grid . addWidget ( HelpButton (
_ ( ' 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. ' ) ) , 4 , 3 )
2013-02-27 06:58:46 -08:00
b = ' '
if self . wallet . seed :
b = EnterButton ( _ ( " Send " ) , self . do_send )
else :
b = EnterButton ( _ ( " Create unsigned transaction " ) , self . do_send )
2012-06-13 02:51:01 -07:00
grid . addWidget ( b , 6 , 1 )
2012-02-13 05:52:59 -08:00
2012-05-18 06:28:55 -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
2012-06-10 01:52:44 -07:00
QShortcut ( QKeySequence ( " Up " ) , w , w . focusPreviousChild )
QShortcut ( QKeySequence ( " Down " ) , w , w . focusNextChild )
2012-02-11 22:27:32 -08:00
w . setLayout ( grid )
w2 = QWidget ( )
2012-02-13 10:02:48 -08:00
vbox = QVBoxLayout ( )
2012-02-11 22:27:32 -08:00
vbox . addWidget ( w )
vbox . addStretch ( 1 )
w2 . setLayout ( vbox )
2012-02-14 05:34:19 -08:00
def entry_changed ( is_fee ) :
self . funds_error = False
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-04-05 07:00:34 -07:00
c , u = self . wallet . get_account_balance ( self . current_account )
inputs , total , fee = self . wallet . choose_tx_inputs ( c + u , 0 , self . current_account )
2013-04-05 09:03:52 -07:00
fee = self . wallet . estimated_fee ( inputs )
amount = c + u - fee
2013-04-06 14:34:12 -07:00
self . amount_e . setText ( self . format_amount ( amount ) )
self . fee_e . setText ( self . format_amount ( fee ) )
2013-04-05 09:03:52 -07:00
return
2013-04-06 14:34:12 -07:00
amount = self . read_amount ( str ( self . amount_e . text ( ) ) )
fee = self . read_amount ( str ( self . fee_e . text ( ) ) )
2012-02-14 05:34:19 -08:00
if not is_fee : fee = None
if amount is None :
return
2013-04-05 07:00:34 -07:00
inputs , total , fee = self . wallet . choose_tx_inputs ( amount , fee , self . current_account )
2012-02-14 05:34:19 -08:00
if not is_fee :
2013-04-06 14:34:12 -07:00
self . fee_e . setText ( self . format_amount ( fee ) )
2012-02-14 05:34:19 -08:00
if inputs :
palette = QPalette ( )
palette . setColor ( self . amount_e . foregroundRole ( ) , QColor ( ' black ' ) )
2013-01-06 06:11:20 -08:00
text = self . status_text
2012-02-14 05:34:19 -08:00
else :
palette = QPalette ( )
palette . setColor ( self . amount_e . foregroundRole ( ) , QColor ( ' red ' ) )
self . funds_error = True
2013-01-06 06:11:20 -08:00
text = _ ( " Not enough funds " )
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-03-14 09:05:50 -07:00
self . run_hook ( ' create_send_tab ' , grid )
2012-02-11 22:27:32 -08:00
return w2
2012-02-11 08:02:28 -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-03-14 08:32:05 -07:00
self . 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
@protected
def do_send ( self , password ) :
2012-02-13 07:49:20 -08:00
2012-02-14 14:11:59 -08:00
label = unicode ( self . message_e . text ( ) )
r = unicode ( self . payto_e . text ( ) )
2012-02-13 07:49:20 -08:00
r = r . strip ( )
2012-06-09 03:23:01 -07:00
# label or alias, with address in brackets
2013-03-14 08:32:05 -07:00
m = re . match ( ' (.*?) \ s* \ <([1-9A-HJ-NP-Za-km-z] { 26,}) \ > ' , r )
to_address = m . group ( 2 ) if m else r
2012-02-13 07:49:20 -08:00
2013-03-01 05:27:56 -08:00
if not is_valid ( to_address ) :
2012-05-18 06:28:55 -07:00
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Invalid Bitcoin Address ' ) + ' : \n ' + to_address , _ ( ' OK ' ) )
2012-02-13 07:49:20 -08:00
return
try :
2013-04-06 14:34:12 -07:00
amount = self . read_amount ( unicode ( self . amount_e . text ( ) ) )
2012-02-13 07:49:20 -08:00
except :
2012-05-18 06:28:55 -07:00
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Invalid Amount ' ) , _ ( ' OK ' ) )
2012-02-13 07:49:20 -08:00
return
try :
2013-04-06 14:34:12 -07:00
fee = self . read_amount ( unicode ( self . fee_e . text ( ) ) )
2012-02-13 07:49:20 -08:00
except :
2012-05-18 06:28:55 -07:00
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Invalid Fee ' ) , _ ( ' OK ' ) )
2012-02-13 07:49:20 -08:00
return
try :
2013-04-05 07:00:34 -07:00
tx = self . wallet . mktx ( [ ( to_address , amount ) ] , password , fee , account = self . current_account )
2012-02-13 07:49:20 -08:00
except BaseException , e :
2012-05-16 10:20:21 -07:00
self . show_message ( str ( e ) )
2012-02-13 07:49:20 -08:00
return
2012-10-13 23:25:09 -07:00
2013-03-24 03:25:17 -07:00
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 ' ) )
2013-03-23 01:23:57 -07:00
return
2013-03-14 09:05:50 -07:00
self . run_hook ( ' send_tx ' , tx )
2013-03-02 07:29:14 -08:00
2013-02-27 03:51:49 -08:00
if label :
2013-03-12 09:10:35 -07:00
self . set_label ( tx . hash ( ) , label )
2013-02-27 03:51:49 -08:00
2013-02-27 00:04:22 -08:00
if tx . is_complete :
2012-12-05 09:18:47 -08:00
h = self . wallet . send_tx ( tx )
waiting_dialog ( lambda : False if self . wallet . tx_event . isSet ( ) else _ ( " Please wait... " ) )
status , msg = self . wallet . receive_tx ( h )
if status :
QMessageBox . information ( self , ' ' , _ ( ' Payment sent. ' ) + ' \n ' + msg , _ ( ' OK ' ) )
self . do_clear ( )
self . update_contacts_tab ( )
else :
QMessageBox . warning ( self , _ ( ' Error ' ) , msg , _ ( ' OK ' ) )
2012-02-13 07:49:20 -08:00
else :
2013-03-11 07:57:37 -07:00
filename = label + ' .txn ' if label else ' unsigned_ %s .txn ' % ( time . mktime ( time . gmtime ( ) ) )
2013-02-27 06:58:46 -08:00
try :
2013-03-11 07:57:37 -07:00
fileName = self . getSaveFileName ( _ ( " Select a transaction filename " ) , filename , " *.txn " )
2013-02-27 10:14:51 -08:00
with open ( fileName , ' w ' ) as f :
f . write ( json . dumps ( tx . as_dict ( ) , indent = 4 ) + ' \n ' )
2013-02-27 09:20:11 -08:00
QMessageBox . information ( self , _ ( ' Unsigned transaction created ' ) , _ ( " Unsigned transaction was saved to file: " ) + " " + fileName , _ ( ' OK ' ) )
2013-02-27 06:58:46 -08:00
except :
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Could not write transaction to file ' ) , _ ( ' OK ' ) )
2012-02-13 07:49:20 -08:00
2013-02-27 00:04:22 -08:00
2012-02-14 04:38:47 -08:00
def set_url ( self , url ) :
2013-03-14 08:32:05 -07:00
address , amount , label , message , signature , identity , url = util . parse_url ( url )
2013-04-06 14:34:12 -07:00
if self . base_unit ( ) == ' mBTC ' : amount = str ( 1000 * Decimal ( amount ) )
2013-03-14 08:32:05 -07:00
if label and self . wallet . labels . get ( address ) != label :
if self . question ( ' Give label " %s " to address %s ? ' % ( label , address ) ) :
if address not in self . wallet . addressbook and not self . wallet . is_mine ( address ) :
self . wallet . addressbook . append ( address )
self . set_label ( address , label )
self . run_hook ( ' set_url ' , url , self . show_message , self . question )
2012-02-14 04:38:47 -08:00
self . tabs . setCurrentIndex ( 1 )
2013-03-14 08:32:05 -07:00
label = self . wallet . labels . get ( address )
m_addr = label + ' < ' + address + ' > ' if label else address
2012-06-09 13:31:42 -07:00
self . payto_e . setText ( m_addr )
2012-06-09 09:20:15 -07:00
2012-02-14 04:38:47 -08:00
self . message_e . setText ( message )
self . amount_e . setText ( amount )
if identity :
self . set_frozen ( self . payto_e , True )
self . set_frozen ( self . amount_e , True )
self . set_frozen ( self . message_e , True )
self . payto_sig . setText ( ' The bitcoin URI was signed by ' + identity )
else :
self . payto_sig . setVisible ( False )
def do_clear ( self ) :
self . payto_sig . setVisible ( False )
for e in [ self . payto_e , self . message_e , self . amount_e , self . fee_e ] :
e . setText ( ' ' )
self . set_frozen ( e , False )
def set_frozen ( self , entry , frozen ) :
if frozen :
entry . setReadOnly ( True )
entry . setFrame ( False )
palette = QPalette ( )
palette . setColor ( entry . backgroundRole ( ) , QColor ( ' lightgray ' ) )
entry . setPalette ( palette )
else :
entry . setReadOnly ( False )
entry . setFrame ( True )
palette = QPalette ( )
palette . setColor ( entry . backgroundRole ( ) , QColor ( ' white ' ) )
entry . setPalette ( palette )
2012-02-13 07:49:20 -08:00
2012-06-07 08:36:39 -07:00
def toggle_freeze ( self , addr ) :
if not addr : return
if addr in self . wallet . frozen_addresses :
self . wallet . unfreeze ( addr )
else :
self . wallet . freeze ( addr )
self . update_receive_tab ( )
def toggle_priority ( self , addr ) :
if not addr : return
if addr in self . wallet . prioritized_addresses :
self . wallet . unprioritize ( addr )
else :
self . wallet . prioritize ( addr )
self . update_receive_tab ( )
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
2012-02-13 10:02:48 -08:00
hbox = QHBoxLayout ( )
2012-02-12 03:37:43 -08:00
hbox . setMargin ( 0 )
2012-02-12 08:19:16 -08:00
hbox . setSpacing ( 0 )
2012-02-12 02:26:38 -08:00
buttons . setLayout ( hbox )
2012-06-06 05:55:11 -07:00
return l , w , hbox
2012-05-13 04:09:59 -07:00
2012-06-07 08:36:39 -07:00
2012-06-06 05:55:11 -07:00
def create_receive_tab ( self ) :
2013-03-03 10:14:27 -08:00
l , w , hbox = self . create_list_tab ( [ _ ( ' Address ' ) , _ ( ' Label ' ) , _ ( ' Balance ' ) , _ ( ' Tx ' ) ] )
2012-06-07 08:36:39 -07:00
l . setContextMenuPolicy ( Qt . CustomContextMenu )
l . customContextMenuRequested . connect ( self . create_receive_menu )
2013-02-27 00:04:22 -08:00
self . connect ( l , SIGNAL ( ' itemDoubleClicked(QTreeWidgetItem*, int) ' ) , lambda a , b : self . address_label_clicked ( a , b , l , 0 , 1 ) )
self . connect ( l , SIGNAL ( ' itemChanged(QTreeWidgetItem*, int) ' ) , lambda a , b : self . address_label_changed ( a , b , l , 0 , 1 ) )
2013-03-03 04:50:08 -08:00
self . connect ( l , SIGNAL ( ' currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*) ' ) , lambda a , b : self . current_item_changed ( a ) )
2012-02-12 15:00:33 -08:00
self . receive_list = l
2012-05-05 02:51:06 -07:00
self . receive_buttons_hbox = hbox
2012-10-11 03:56:57 -07:00
hbox . addStretch ( 1 )
2012-02-12 15:00:33 -08:00
return w
2012-11-29 01:19:54 -08:00
def receive_tab_set_mode ( self , i ) :
2013-01-12 02:23:35 -08:00
self . save_column_widths ( )
2013-03-03 04:50:08 -08:00
self . expert_mode = ( i == 1 )
self . config . set_key ( ' classic_expert_mode ' , self . expert_mode , True )
2012-10-11 03:56:57 -07:00
self . wallet . save ( )
self . update_receive_tab ( )
2013-02-02 01:20:24 -08:00
2013-01-12 02:23:35 -08:00
def save_column_widths ( self ) :
2013-03-03 04:50:08 -08:00
if not self . expert_mode :
2013-02-27 00:04:22 -08:00
widths = [ self . receive_list . columnWidth ( 0 ) ]
2013-02-02 01:20:24 -08:00
else :
widths = [ ]
for i in range ( self . receive_list . columnCount ( ) - 1 ) :
widths . append ( self . receive_list . columnWidth ( i ) )
2013-03-03 04:50:08 -08:00
self . column_widths [ " receive " ] [ self . expert_mode ] = widths
2013-02-02 01:20:24 -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-02-02 01:20:24 -08:00
2012-02-12 15:00:33 -08:00
def create_contacts_tab ( self ) :
2012-06-06 05:55:11 -07:00
l , w , hbox = 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 )
2012-06-07 07:07:49 -07:00
self . connect ( l , SIGNAL ( ' itemDoubleClicked(QTreeWidgetItem*, int) ' ) , lambda a , b : self . address_label_clicked ( a , b , l , 0 , 1 ) )
self . connect ( l , SIGNAL ( ' itemChanged(QTreeWidgetItem*, int) ' ) , 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-05-05 02:51:06 -07:00
self . contacts_buttons_hbox = hbox
2012-06-07 08:54:40 -07:00
hbox . addWidget ( EnterButton ( _ ( " New " ) , self . new_contact_dialog ) )
2012-06-07 08:36:39 -07:00
hbox . addStretch ( 1 )
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
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-01-05 13:24:03 -08:00
self . wallet . imported_keys . pop ( addr )
self . update_receive_tab ( )
self . update_history_tab ( )
self . wallet . save ( )
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
2012-06-09 14:52:45 -07:00
#self.receive_list.selectedIndexes()
2012-06-09 15:05:14 -07:00
item = self . receive_list . itemAt ( position )
2012-06-10 12:33:56 -07:00
if not item : return
2013-02-27 00:04:22 -08:00
addr = unicode ( item . text ( 0 ) )
2013-03-03 10:53:35 -08:00
if not is_valid ( addr ) :
item . setExpanded ( not item . isExpanded ( ) )
return
2012-06-07 08:36:39 -07:00
menu = QMenu ( )
2012-11-28 13:52:35 -08:00
menu . addAction ( _ ( " Copy to clipboard " ) , lambda : self . app . clipboard ( ) . setText ( addr ) )
2013-03-04 08:20:38 -08:00
menu . addAction ( _ ( " QR code " ) , lambda : self . show_qrcode ( " bitcoin: " + addr , _ ( " Address " ) ) )
2012-06-09 08:18:53 -07:00
menu . addAction ( _ ( " Edit label " ) , lambda : self . edit_label ( True ) )
2013-03-04 22:55:43 -08:00
menu . addAction ( _ ( " Private key " ) , lambda : self . show_private_key ( addr ) )
2012-11-24 23:28:10 -08:00
menu . addAction ( _ ( " Sign message " ) , lambda : self . sign_message ( addr ) )
2013-01-05 13:24:03 -08:00
if addr in self . wallet . imported_keys :
menu . addAction ( _ ( " Remove from wallet " ) , lambda : self . delete_imported_key ( addr ) )
2012-10-11 11:10:12 -07:00
2013-03-03 04:50:08 -08:00
if self . expert_mode :
2013-01-03 06:13:12 -08:00
t = _ ( " Unfreeze " ) if addr in self . wallet . frozen_addresses else _ ( " Freeze " )
menu . addAction ( t , lambda : self . toggle_freeze ( addr ) )
t = _ ( " Unprioritize " ) if addr in self . wallet . prioritized_addresses else _ ( " Prioritize " )
menu . addAction ( t , lambda : self . toggle_priority ( addr ) )
2013-03-14 09:05:50 -07:00
self . run_hook ( ' receive_menu ' , menu )
2012-06-07 08:36:39 -07:00
menu . exec_ ( self . receive_list . viewport ( ) . mapToGlobal ( position ) )
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-03-14 08:32:05 -07:00
if x in self . wallet . addressbook :
2012-06-09 23:33:34 -07:00
self . wallet . addressbook . remove ( x )
2013-03-12 09:10:35 -07:00
self . set_label ( x , None )
2013-03-14 08:32:05 -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-09 09:06:01 -07:00
if not item : return
2012-06-09 14:58:20 -07:00
addr = unicode ( item . text ( 0 ) )
2012-06-09 23:33:34 -07:00
label = unicode ( item . text ( 1 ) )
2013-03-14 08:32:05 -07:00
is_editable = item . data ( 0 , 32 ) . toBool ( )
payto_addr = item . data ( 0 , 33 ) . toString ( )
2012-06-07 08:36:39 -07:00
menu = QMenu ( )
menu . addAction ( _ ( " Copy to Clipboard " ) , lambda : self . app . clipboard ( ) . setText ( addr ) )
2013-03-14 08:32:05 -07:00
menu . addAction ( _ ( " Pay to " ) , lambda : self . payto ( payto_addr ) )
2013-03-02 04:27:12 -08:00
menu . addAction ( _ ( " QR code " ) , lambda : self . show_qrcode ( " bitcoin: " + addr , _ ( " Address " ) ) )
2013-03-14 08:32:05 -07:00
if is_editable :
2012-06-09 08:18:53 -07:00
menu . addAction ( _ ( " Edit label " ) , lambda : self . edit_label ( False ) )
2013-03-14 08:32:05 -07:00
menu . addAction ( _ ( " Delete " ) , lambda : self . delete_contact ( addr ) )
self . 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
2012-11-28 06:38:44 -08:00
def update_receive_item ( self , item ) :
2013-03-03 10:14:27 -08:00
item . setFont ( 0 , QFont ( MONOSPACE_FONT ) )
2013-02-27 00:04:22 -08:00
address = str ( item . data ( 0 , 0 ) . toString ( ) )
2012-11-28 06:38:44 -08:00
label = self . wallet . labels . get ( address , ' ' )
2013-02-27 00:04:22 -08:00
item . setData ( 1 , 0 , label )
2013-03-17 05:15:03 -07:00
item . setData ( 0 , 32 , True ) # is editable
2012-11-28 06:38:44 -08:00
2013-03-14 09:05:50 -07:00
self . run_hook ( ' update_receive_item ' , address , item )
2013-01-08 02:04:04 -08:00
2012-11-28 06:38:44 -08:00
c , u = self . wallet . get_addr_balance ( address )
2013-04-06 14:34:12 -07:00
balance = self . format_amount ( c + u )
2013-03-03 10:14:27 -08:00
item . setData ( 2 , 0 , balance )
2012-11-28 06:38:44 -08:00
2013-03-03 04:50:08 -08:00
if self . expert_mode :
2013-01-03 06:13:12 -08:00
if address in self . wallet . frozen_addresses :
2013-02-27 00:04:22 -08:00
item . setBackgroundColor ( 0 , QColor ( ' lightblue ' ) )
2013-01-03 06:13:12 -08:00
elif address in self . wallet . prioritized_addresses :
2013-02-27 00:04:22 -08:00
item . setBackgroundColor ( 0 , QColor ( ' lightgreen ' ) )
2012-11-28 06:38:44 -08:00
2012-02-11 22:45:18 -08:00
def update_receive_tab ( self ) :
2012-06-07 07:07:49 -07:00
l = self . receive_list
2012-11-28 06:38:44 -08:00
2012-06-07 07:07:49 -07:00
l . clear ( )
2013-03-03 10:14:27 -08:00
l . setColumnHidden ( 2 , not self . expert_mode )
2013-03-03 04:50:08 -08:00
l . setColumnHidden ( 3 , not self . expert_mode )
if not self . expert_mode :
2013-02-02 01:20:24 -08:00
width = self . column_widths [ ' receive ' ] [ 0 ] [ 0 ]
2013-02-27 00:04:22 -08:00
l . setColumnWidth ( 0 , width )
2013-02-02 01:20:24 -08:00
else :
2013-03-03 04:50:08 -08:00
for i , width in enumerate ( self . column_widths [ ' receive ' ] [ self . expert_mode ] ) :
2013-02-02 01:20:24 -08:00
l . setColumnWidth ( i , width )
2012-06-07 08:36:39 -07:00
2013-04-05 07:00:34 -07:00
if self . current_account is None :
account_items = self . wallet . accounts . items ( )
elif self . current_account != - 1 :
account_items = [ ( self . current_account , self . wallet . accounts . get ( self . current_account ) ) ]
else :
account_items = [ ]
2012-06-07 07:07:49 -07:00
2013-04-05 07:00:34 -07:00
for k , account in account_items :
2013-02-27 00:04:22 -08:00
name = account . get ( ' name ' , str ( k ) )
2013-03-02 05:20:21 -08:00
c , u = self . wallet . get_account_balance ( k )
2013-04-06 14:34:12 -07:00
account_item = QTreeWidgetItem ( [ name , ' ' , self . format_amount ( c + u ) , ' ' ] )
2013-02-27 00:04:22 -08:00
l . addTopLevelItem ( account_item )
account_item . setExpanded ( True )
2013-03-02 05:20:21 -08:00
2013-04-04 19:48:04 -07:00
for is_change in ( [ 0 , 1 ] if self . expert_mode else [ 0 ] ) :
if self . expert_mode :
name = " Receiving " if not is_change else " Change "
seq_item = QTreeWidgetItem ( [ name , ' ' , ' ' , ' ' , ' ' ] )
account_item . addChild ( seq_item )
if not is_change : seq_item . setExpanded ( True )
else :
seq_item = account_item
2013-02-27 00:04:22 -08:00
is_red = False
gap = 0
2012-05-05 02:33:53 -07:00
2013-02-27 00:04:22 -08:00
for address in account [ is_change ] :
h = self . wallet . history . get ( address , [ ] )
2013-03-16 10:24:45 -07:00
if h == [ ] :
gap + = 1
if gap > self . wallet . gap_limit :
is_red = True
else :
gap = 0
2013-02-27 00:04:22 -08:00
num_tx = ' * ' if h == [ ' * ' ] else " %d " % len ( h )
2013-03-03 10:14:27 -08:00
item = QTreeWidgetItem ( [ address , ' ' , ' ' , num_tx ] )
2013-02-27 00:04:22 -08:00
self . update_receive_item ( item )
2013-03-02 05:20:21 -08:00
if is_red :
2013-02-27 00:04:22 -08:00
item . setBackgroundColor ( 1 , QColor ( ' red ' ) )
seq_item . addChild ( item )
2013-04-05 07:00:34 -07:00
if self . wallet . imported_keys and ( self . current_account is None or self . current_account == - 1 ) :
2013-03-02 05:20:21 -08:00
c , u = self . wallet . get_imported_balance ( )
2013-04-06 14:34:12 -07:00
account_item = QTreeWidgetItem ( [ _ ( ' Imported ' ) , ' ' , self . format_amount ( c + u ) , ' ' ] )
2013-02-27 00:04:22 -08:00
l . addTopLevelItem ( account_item )
account_item . setExpanded ( True )
for address in self . wallet . imported_keys . keys ( ) :
2013-03-03 10:14:27 -08:00
item = QTreeWidgetItem ( [ address , ' ' , ' ' , ' ' ] )
2013-02-27 00:04:22 -08:00
self . update_receive_item ( item )
account_item . addChild ( item )
2012-06-09 14:26:41 -07: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-09 03:23:01 -07:00
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-03-14 08:32:05 -07:00
self . 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-03-14 08:32:05 -07:00
2013-02-26 04:56:48 -08:00
def create_console_tab ( self ) :
2013-02-01 09:22:36 -08:00
from qt_console import Console
2013-02-02 00:40:54 -08:00
self . console = console = Console ( )
2013-03-02 05:05:35 -08:00
self . console . history = self . config . get ( " console-history " , [ ] )
self . console . history_index = len ( self . console . history )
2013-03-02 07:29:14 -08:00
2013-02-02 02:46:02 -08:00
console . updateNamespace ( { ' wallet ' : self . wallet , ' interface ' : self . wallet . interface , ' 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-02-26 08:57:48 -08:00
c = commands . Commands ( self . wallet , self . wallet . interface , 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 ) :
if m [ 0 ] == ' _ ' or m == ' wallet ' or m == ' interface ' : continue
methods [ m ] = mkfunc ( c . _run , m )
console . updateNamespace ( methods )
2013-02-01 09:22:36 -08:00
return console
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 :
accounts = self . wallet . get_accounts ( )
for k , v in accounts . items ( ) :
if v == s :
self . current_account = k
self . update_history_tab ( )
self . update_status ( )
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-01-06 06:11:20 -08:00
self . status_text = " "
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
update_notification = UpdateLabel ( self . config )
2013-01-30 07:25:48 -08:00
if ( update_notification . new_version ) :
2013-01-30 11:27:28 -08:00
sb . addPermanentWidget ( update_notification )
2013-01-15 12:31:21 -08:00
2013-04-05 07:00:34 -07:00
accounts = self . wallet . get_accounts ( )
if len ( accounts ) > 1 :
from_combo = QComboBox ( )
from_combo . addItems ( [ _ ( " All accounts " ) ] + accounts . values ( ) )
from_combo . setCurrentIndex ( 0 )
self . connect ( from_combo , SIGNAL ( " activated(QString) " ) , self . change_account )
sb . addPermanentWidget ( from_combo )
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 ) )
2012-05-13 01:54:03 -07:00
if self . wallet . seed :
2013-03-16 16:18:46 -07:00
self . lock_icon = QIcon ( " :icons/lock.png " ) if self . wallet . use_encryption else QIcon ( " :icons/unlock.png " )
self . password_button = StatusBarButton ( self . lock_icon , _ ( " Password " ) , lambda : self . change_password_dialog ( self . wallet , self ) )
sb . addPermanentWidget ( self . password_button )
2013-01-13 16:34:06 -08:00
sb . addPermanentWidget ( StatusBarButton ( QIcon ( " :icons/preferences.png " ) , _ ( " Preferences " ) , self . settings_dialog ) )
2012-05-13 01:54:03 -07:00
if self . wallet . seed :
2013-03-04 22:55:43 -08:00
sb . addPermanentWidget ( StatusBarButton ( QIcon ( " :icons/seed.png " ) , _ ( " Seed " ) , self . show_seed_dialog ) )
2013-01-13 16:34:06 -08:00
self . status_button = StatusBarButton ( QIcon ( " :icons/status_disconnected.png " ) , _ ( " Network " ) , lambda : self . network_dialog ( self . wallet , self ) )
2012-02-13 12:36:41 -08:00
sb . addPermanentWidget ( self . status_button )
2013-01-15 12:31:21 -08:00
2013-03-10 09:04:00 -07:00
self . run_hook ( ' create_status_bar ' , ( sb , ) )
2012-02-11 08:38:44 -08:00
self . setStatusBar ( sb )
2013-01-05 04:44:20 -08:00
def go_lite ( self ) :
import gui_lite
2013-01-07 03:03:32 -08:00
self . config . set_key ( ' gui ' , ' lite ' , True )
2013-01-05 04:44:20 -08:00
self . hide ( )
if self . lite :
self . lite . mini . show ( )
else :
self . lite = gui_lite . ElectrumGui ( self . wallet , self . config , self )
self . lite . main ( None )
2012-02-11 08:38:44 -08:00
2012-06-07 08:54:40 -07:00
def new_contact_dialog ( self ) :
2012-05-18 06:28:55 -07:00
text , ok = QInputDialog . getText ( self , _ ( ' New Contact ' ) , _ ( ' Address ' ) + ' : ' )
2012-02-14 14:11:59 -08:00
address = unicode ( text )
2012-02-12 15:00:33 -08:00
if ok :
2013-03-01 05:27:56 -08:00
if is_valid ( address ) :
2012-02-12 15:00:33 -08:00
self . wallet . addressbook . append ( address )
self . wallet . save ( )
self . update_contacts_tab ( )
2012-06-09 08:18:53 -07:00
self . update_history_tab ( )
self . update_completions ( )
2012-02-12 15:00:33 -08:00
else :
2012-05-18 06:28:55 -07:00
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Invalid Address ' ) , _ ( ' OK ' ) )
2012-02-12 15:00:33 -08:00
2013-01-08 05:29:42 -08:00
def show_master_public_key ( self ) :
2013-03-04 08:20:38 -08:00
dialog = QDialog ( self )
2013-01-08 05:29:42 -08:00
dialog . setModal ( 1 )
2013-01-30 01:16:00 -08:00
dialog . setWindowTitle ( _ ( " Master Public Key " ) )
2013-01-08 05:29:42 -08:00
main_text = QTextEdit ( )
2013-02-23 02:35:46 -08:00
main_text . setText ( self . wallet . get_master_public_key ( ) )
2013-01-08 05:29:42 -08:00
main_text . setReadOnly ( True )
2013-01-10 13:04:52 -08:00
main_text . setMaximumHeight ( 170 )
2013-03-04 02:01:09 -08:00
qrw = QRCodeWidget ( self . wallet . get_master_public_key ( ) )
2013-01-08 05:29:42 -08:00
ok_button = QPushButton ( _ ( " OK " ) )
ok_button . setDefault ( True )
ok_button . clicked . connect ( dialog . accept )
main_layout = QGridLayout ( )
2013-01-10 13:04:52 -08:00
main_layout . addWidget ( QLabel ( _ ( ' Your Master Public Key is: ' ) ) , 0 , 0 , 1 , 2 )
2013-01-08 05:29:42 -08:00
2013-01-10 13:04:52 -08:00
main_layout . addWidget ( main_text , 1 , 0 )
main_layout . addWidget ( qrw , 1 , 1 )
2013-01-08 05:29:42 -08:00
2013-01-10 13:04:52 -08:00
vbox = QVBoxLayout ( )
vbox . addLayout ( main_layout )
hbox = QHBoxLayout ( )
hbox . addStretch ( 1 )
hbox . addWidget ( ok_button )
vbox . addLayout ( hbox )
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-03-04 22:55:43 -08:00
@protected
def show_seed_dialog ( self , password ) :
if not self . wallet . seed :
2013-01-08 05:29:42 -08:00
QMessageBox . information ( parent , _ ( ' Message ' ) , _ ( ' No seed ' ) , _ ( ' OK ' ) )
2012-05-12 15:43:22 -07:00
return
2012-02-13 06:11:31 -08:00
try :
2013-03-04 22:55:43 -08:00
seed = self . wallet . decode_seed ( password )
2012-02-13 06:11:31 -08:00
except :
2013-03-13 10:51:38 -07:00
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Incorrect Password ' ) , _ ( ' OK ' ) )
2012-02-13 06:11:31 -08:00
return
2013-04-05 09:54:00 -07:00
self . show_seed ( seed , self . wallet . imported_keys , self )
2012-02-12 15:00:33 -08:00
2013-02-27 00:04:22 -08:00
@classmethod
2013-04-05 09:54:00 -07:00
def show_seed ( self , seed , imported_keys , parent = None ) :
2013-03-04 08:20:38 -08:00
dialog = QDialog ( parent )
2012-08-16 15:31:46 -07:00
dialog . setModal ( 1 )
2013-01-30 01:16:00 -08:00
dialog . setWindowTitle ( ' Electrum ' + ' - ' + _ ( ' Seed ' ) )
2012-05-05 07:42:42 -07:00
2012-08-16 15:31:46 -07:00
brainwallet = ' ' . join ( mnemonic . mn_encode ( seed ) )
2012-05-05 07:42:42 -07:00
2013-01-08 08:01:45 -08:00
label1 = QLabel ( _ ( " Your wallet generation seed is " ) + " : " )
2012-10-02 04:41:38 -07:00
2013-01-08 08:01:45 -08:00
seed_text = QTextEdit ( brainwallet )
seed_text . setReadOnly ( True )
2013-01-10 14:10:01 -08:00
seed_text . setMaximumHeight ( 130 )
2013-01-08 08:01:45 -08:00
msg2 = _ ( " Please write down or memorize these 12 words (order is important). " ) + " " \
2013-01-10 14:10:01 -08:00
+ _ ( " This seed will allow you to recover your wallet in case of computer failure. " ) + " " \
2013-01-10 14:12:28 -08:00
+ _ ( " Your seed is also displayed as QR code, in case you want to transfer it to a mobile phone. " ) + " <p> " \
2013-01-10 14:10:01 -08:00
+ " <b> " + _ ( " WARNING " ) + " :</b> " + _ ( " Never disclose your seed. Never type it on a website. " ) + " </b><p> "
2013-04-05 09:54:00 -07:00
if imported_keys :
msg2 + = " <b> " + _ ( " WARNING " ) + " :</b> " + _ ( " Your wallet contains imported keys. These keys cannot be recovered from seed. " ) + " </b><p> "
2013-01-08 08:01:45 -08:00
label2 = QLabel ( msg2 )
label2 . setWordWrap ( True )
2012-05-05 07:42:42 -07:00
2012-08-16 15:31:46 -07:00
logo = QLabel ( )
logo . setPixmap ( QPixmap ( " :icons/seed.png " ) . scaledToWidth ( 56 ) )
2013-01-08 08:01:45 -08:00
logo . setMaximumWidth ( 60 )
2012-05-05 07:42:42 -07:00
2013-03-04 08:20:38 -08:00
qrw = QRCodeWidget ( seed )
2012-08-16 15:31:46 -07:00
ok_button = QPushButton ( _ ( " OK " ) )
2012-10-16 07:39:34 -07:00
ok_button . setDefault ( True )
2012-08-16 15:31:46 -07:00
ok_button . clicked . connect ( dialog . accept )
2013-01-10 14:10:01 -08:00
grid = QGridLayout ( )
#main_layout.addWidget(logo, 0, 0)
grid . addWidget ( logo , 0 , 0 )
grid . addWidget ( label1 , 0 , 1 )
grid . addWidget ( seed_text , 1 , 0 , 1 , 2 )
grid . addWidget ( qrw , 0 , 2 , 2 , 1 )
vbox = QVBoxLayout ( )
vbox . addLayout ( grid )
vbox . addWidget ( label2 )
2013-01-08 08:01:45 -08:00
2013-01-10 14:10:01 -08:00
hbox = QHBoxLayout ( )
hbox . addStretch ( 1 )
hbox . addWidget ( ok_button )
vbox . addLayout ( hbox )
2012-08-16 15:31:46 -07:00
2013-01-10 14:10:01 -08:00
dialog . setLayout ( vbox )
2012-08-16 15:31:46 -07:00
dialog . exec_ ( )
2012-02-13 06:11:31 -08:00
2013-03-04 08:20:38 -08:00
def show_qrcode ( self , data , title = " QR code " ) :
2012-12-02 20:32:31 -08:00
if not data : return
2013-03-04 08:20:38 -08:00
d = QDialog ( self )
2012-05-01 08:06:14 -07:00
d . setModal ( 1 )
2012-12-02 20:32:31 -08:00
d . setWindowTitle ( title )
2012-05-01 08:06:14 -07:00
d . setMinimumSize ( 270 , 300 )
vbox = QVBoxLayout ( )
2012-12-02 20:32:31 -08:00
qrw = QRCodeWidget ( data )
2013-01-03 22:57:10 -08:00
vbox . addWidget ( qrw , 1 )
vbox . addWidget ( QLabel ( data ) , 0 , Qt . AlignHCenter )
2012-05-01 08:06:14 -07:00
hbox = QHBoxLayout ( )
hbox . addStretch ( 1 )
2012-12-02 20:32:31 -08:00
def print_qr ( self ) :
filename = " qrcode.bmp "
bmp . save_qrcode ( qrw . qr , filename )
QMessageBox . information ( None , _ ( ' Message ' ) , _ ( " QR code saved to file " ) + " " + filename , _ ( ' OK ' ) )
2013-03-02 04:31:35 -08:00
b = QPushButton ( _ ( " Save " ) )
2012-12-02 20:32:31 -08:00
hbox . addWidget ( b )
b . clicked . connect ( print_qr )
b = QPushButton ( _ ( " Close " ) )
2012-05-01 08:06:14 -07:00
hbox . addWidget ( b )
b . clicked . connect ( d . accept )
2013-03-02 04:31:35 -08:00
b . setDefault ( True )
2012-05-01 08:06:14 -07:00
vbox . addLayout ( hbox )
d . setLayout ( vbox )
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-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
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-02-22 08:27:19 -08:00
pk = self . wallet . get_private_key ( address , password )
2013-02-02 02:46:02 -08:00
except BaseException , e :
self . show_message ( str ( e ) )
return
QMessageBox . information ( self , _ ( ' Private key ' ) , ' Address ' + ' : ' + address + ' \n \n ' + _ ( ' Private key ' ) + ' : ' + pk , _ ( ' OK ' ) )
2013-03-04 22:55:43 -08:00
@protected
def do_sign ( self , address , message , signature , password ) :
try :
sig = self . wallet . sign_message ( str ( address . text ( ) ) , str ( message . toPlainText ( ) ) , password )
signature . setText ( sig )
except BaseException , e :
self . show_message ( str ( e ) )
def sign_message ( self , address ) :
2012-11-24 23:28:10 -08:00
if not address : return
d = QDialog ( self )
d . setModal ( 1 )
2013-01-30 01:16:00 -08:00
d . setWindowTitle ( _ ( ' Sign Message ' ) )
2013-01-05 13:50:59 -08:00
d . setMinimumSize ( 410 , 290 )
2012-11-24 23:28:10 -08:00
tab_widget = QTabWidget ( )
tab = QWidget ( )
layout = QGridLayout ( tab )
sign_address = QLineEdit ( )
2013-01-05 13:50:59 -08:00
2012-11-24 23:28:10 -08:00
sign_address . setText ( address )
layout . addWidget ( QLabel ( _ ( ' Address ' ) ) , 1 , 0 )
layout . addWidget ( sign_address , 1 , 1 )
sign_message = QTextEdit ( )
layout . addWidget ( QLabel ( _ ( ' Message ' ) ) , 2 , 0 )
2013-01-05 13:50:59 -08:00
layout . addWidget ( sign_message , 2 , 1 )
layout . setRowStretch ( 2 , 3 )
2012-11-24 23:28:10 -08:00
2013-01-05 13:50:59 -08:00
sign_signature = QTextEdit ( )
2012-11-24 23:28:10 -08:00
layout . addWidget ( QLabel ( _ ( ' Signature ' ) ) , 3 , 0 )
layout . addWidget ( sign_signature , 3 , 1 )
2013-01-05 13:50:59 -08:00
layout . setRowStretch ( 3 , 1 )
2012-11-24 23:28:10 -08:00
hbox = QHBoxLayout ( )
b = QPushButton ( _ ( " Sign " ) )
hbox . addWidget ( b )
2013-03-04 22:55:43 -08:00
b . clicked . connect ( lambda : self . do_sign ( sign_address , sign_message , sign_signature ) )
2012-11-24 23:28:10 -08:00
b = QPushButton ( _ ( " Close " ) )
b . clicked . connect ( d . accept )
hbox . addWidget ( b )
layout . addLayout ( hbox , 4 , 1 )
2013-01-30 01:16:00 -08:00
tab_widget . addTab ( tab , _ ( " Sign " ) )
2012-11-24 23:28:10 -08:00
tab = QWidget ( )
layout = QGridLayout ( tab )
verify_address = QLineEdit ( )
layout . addWidget ( QLabel ( _ ( ' Address ' ) ) , 1 , 0 )
layout . addWidget ( verify_address , 1 , 1 )
verify_message = QTextEdit ( )
layout . addWidget ( QLabel ( _ ( ' Message ' ) ) , 2 , 0 )
2013-01-05 13:50:59 -08:00
layout . addWidget ( verify_message , 2 , 1 )
layout . setRowStretch ( 2 , 3 )
2012-11-24 23:28:10 -08:00
2013-01-05 13:50:59 -08:00
verify_signature = QTextEdit ( )
2012-11-24 23:28:10 -08:00
layout . addWidget ( QLabel ( _ ( ' Signature ' ) ) , 3 , 0 )
layout . addWidget ( verify_signature , 3 , 1 )
2013-01-05 13:50:59 -08:00
layout . setRowStretch ( 3 , 1 )
2012-11-24 23:28:10 -08:00
def do_verify ( ) :
try :
2013-01-05 13:54:01 -08:00
self . wallet . verify_message ( verify_address . text ( ) , str ( verify_signature . toPlainText ( ) ) , str ( verify_message . toPlainText ( ) ) )
2013-01-30 01:16:00 -08:00
self . show_message ( _ ( " Signature verified " ) )
2012-11-24 23:28:10 -08:00
except BaseException , e :
self . show_message ( str ( e ) )
return
hbox = QHBoxLayout ( )
b = QPushButton ( _ ( " Verify " ) )
b . clicked . connect ( do_verify )
hbox . addWidget ( b )
b = QPushButton ( _ ( " Close " ) )
b . clicked . connect ( d . accept )
hbox . addWidget ( b )
layout . addLayout ( hbox , 4 , 1 )
2013-01-30 01:16:00 -08:00
tab_widget . addTab ( tab , _ ( " Verify " ) )
2012-11-24 23:28:10 -08:00
vbox = QVBoxLayout ( )
vbox . addWidget ( tab_widget )
d . setLayout ( vbox )
d . exec_ ( )
2012-11-28 10:05:58 -08:00
2012-04-03 16:13:12 -07:00
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
2012-02-14 02:10:06 -08:00
def password_dialog ( self ) :
d = QDialog ( self )
2012-02-13 05:52:59 -08:00
d . setModal ( 1 )
2012-02-13 06:11:31 -08:00
pw = QLineEdit ( )
pw . setEchoMode ( 2 )
2012-02-13 10:02:48 -08:00
vbox = QVBoxLayout ( )
2012-05-18 06:28:55 -07:00
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-03-15 10:35:05 -07:00
self . 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
@staticmethod
def change_password_dialog ( wallet , parent = None ) :
2012-05-12 15:43:22 -07:00
if not wallet . seed :
2012-05-18 06:28:55 -07:00
QMessageBox . information ( parent , _ ( ' Error ' ) , _ ( ' No seed ' ) , _ ( ' OK ' ) )
2012-05-12 15:43:22 -07:00
return
2012-02-14 00:52:03 -08:00
d = QDialog ( parent )
2012-02-13 06:11:31 -08:00
d . setModal ( 1 )
2012-02-13 05:52:59 -08:00
pw = QLineEdit ( )
pw . setEchoMode ( 2 )
new_pw = QLineEdit ( )
new_pw . setEchoMode ( 2 )
conf_pw = QLineEdit ( )
conf_pw . setEchoMode ( 2 )
2012-02-13 10:12:24 -08:00
vbox = QVBoxLayout ( )
2012-02-14 01:05:38 -08:00
if parent :
2012-11-28 06:38:44 -08:00
msg = ( _ ( ' Your wallet is encrypted. Use this dialog to change your password. ' ) + ' \n ' \
+ _ ( ' To disable wallet encryption, enter an empty new password. ' ) ) \
if wallet . use_encryption else _ ( ' Your wallet keys are not encrypted ' )
2012-02-14 01:05:38 -08:00
else :
2012-11-28 06:38:44 -08:00
msg = _ ( " Please choose a password to encrypt your wallet keys. " ) + ' \n ' \
+ _ ( " Leave these fields empty if you want to disable encryption. " )
2012-02-13 10:12:24 -08:00
vbox . addWidget ( QLabel ( msg ) )
2012-02-13 05:52:59 -08:00
grid = QGridLayout ( )
grid . setSpacing ( 8 )
2012-02-14 00:52:03 -08:00
if wallet . use_encryption :
2012-05-18 06:28:55 -07:00
grid . addWidget ( QLabel ( _ ( ' Password ' ) ) , 1 , 0 )
2012-02-13 05:56:31 -08:00
grid . addWidget ( pw , 1 , 1 )
2012-02-13 05:52:59 -08:00
2012-05-18 06:28:55 -07:00
grid . addWidget ( QLabel ( _ ( ' New Password ' ) ) , 2 , 0 )
2012-02-13 05:52:59 -08:00
grid . addWidget ( new_pw , 2 , 1 )
2012-05-18 06:28:55 -07:00
grid . addWidget ( QLabel ( _ ( ' Confirm Password ' ) ) , 3 , 0 )
2012-02-13 05:52:59 -08:00
grid . addWidget ( conf_pw , 3 , 1 )
2012-02-13 10:12:24 -08:00
vbox . addLayout ( grid )
2012-02-13 05:52:59 -08:00
2012-02-14 00:52:03 -08:00
vbox . addLayout ( ok_cancel_buttons ( d ) )
2012-02-13 10:02:48 -08:00
d . setLayout ( vbox )
2012-02-13 05:52:59 -08:00
if not d . exec_ ( ) : return
2012-02-14 14:11:59 -08:00
password = unicode ( pw . text ( ) ) if wallet . use_encryption else None
new_password = unicode ( new_pw . text ( ) )
new_password2 = unicode ( conf_pw . text ( ) )
2012-02-13 05:52:59 -08:00
try :
2013-01-06 00:41:06 -08:00
seed = wallet . decode_seed ( password )
2012-02-13 05:52:59 -08:00
except :
2012-05-18 06:28:55 -07:00
QMessageBox . warning ( parent , _ ( ' Error ' ) , _ ( ' Incorrect Password ' ) , _ ( ' OK ' ) )
2012-02-13 05:52:59 -08:00
return
if new_password != new_password2 :
2012-05-18 06:28:55 -07:00
QMessageBox . warning ( parent , _ ( ' Error ' ) , _ ( ' Passwords do not match ' ) , _ ( ' OK ' ) )
2012-12-04 23:12:29 -08:00
return ElectrumWindow . change_password_dialog ( wallet , parent ) # Retry
2012-02-13 05:52:59 -08:00
2012-05-16 23:32:49 -07:00
wallet . update_password ( seed , password , new_password )
2013-03-16 16:18:46 -07:00
if parent :
icon = QIcon ( " :icons/lock.png " ) if wallet . use_encryption else QIcon ( " :icons/unlock.png " )
parent . password_button . setIcon ( icon )
2012-02-14 00:52:03 -08:00
@staticmethod
def seed_dialog ( wallet , parent = None ) :
d = QDialog ( parent )
d . setModal ( 1 )
vbox = QVBoxLayout ( )
2013-03-13 13:00:29 -07:00
msg = _ ( " Please enter your wallet seed (or your master public key if you want to create a watching-only wallet). " + ' \n ' )
2012-02-14 00:52:03 -08:00
vbox . addWidget ( QLabel ( msg ) )
grid = QGridLayout ( )
grid . setSpacing ( 8 )
seed_e = QLineEdit ( )
2013-03-13 13:00:29 -07:00
grid . addWidget ( QLabel ( _ ( ' Seed or master public key ' ) ) , 1 , 0 )
2012-02-14 00:52:03 -08:00
grid . addWidget ( seed_e , 1 , 1 )
2013-03-13 13:00:29 -07:00
grid . addWidget ( HelpButton ( _ ( " Your seed can be entered as a mnemonic (sequence of words), or as a hexadecimal string. " ) ) , 1 , 3 )
2012-02-14 00:52:03 -08:00
2013-04-06 14:34:12 -07:00
gap_e = AmountEdit ( None , True )
2012-02-14 00:52:03 -08:00
gap_e . setText ( " 5 " )
2012-05-18 06:28:55 -07:00
grid . addWidget ( QLabel ( _ ( ' Gap limit ' ) ) , 2 , 0 )
2012-02-14 00:52:03 -08:00
grid . addWidget ( gap_e , 2 , 1 )
2013-03-13 13:00:29 -07:00
grid . addWidget ( HelpButton ( _ ( ' Keep the default value unless you modified this parameter in your wallet. ' ) ) , 2 , 3 )
2012-02-14 00:52:03 -08:00
vbox . addLayout ( grid )
vbox . addLayout ( ok_cancel_buttons ( d ) )
d . setLayout ( vbox )
if not d . exec_ ( ) : return
try :
2012-02-14 14:11:59 -08:00
gap = int ( unicode ( gap_e . text ( ) ) )
2012-02-14 00:52:03 -08:00
except :
2012-05-18 06:28:55 -07:00
QMessageBox . warning ( None , _ ( ' Error ' ) , ' error ' , ' OK ' )
2013-01-08 05:29:42 -08:00
return
2012-02-14 00:52:03 -08:00
try :
2013-01-08 05:29:42 -08:00
seed = str ( seed_e . text ( ) )
2012-02-14 00:52:03 -08:00
seed . decode ( ' hex ' )
except :
2012-07-07 09:24:52 -07:00
print_error ( " Warning: Not hex, trying decode " )
2012-03-23 11:32:16 -07:00
try :
seed = mnemonic . mn_decode ( seed . split ( ' ' ) )
except :
2012-05-18 06:28:55 -07:00
QMessageBox . warning ( None , _ ( ' Error ' ) , _ ( ' I cannot decode this ' ) , _ ( ' OK ' ) )
2013-01-08 05:29:42 -08:00
return
2012-02-14 00:52:03 -08:00
if not seed :
2013-01-30 01:16:00 -08:00
QMessageBox . warning ( None , _ ( ' Error ' ) , _ ( ' No seed ' ) , _ ( ' OK ' ) )
2013-01-08 05:29:42 -08:00
return
return seed , gap
2012-02-14 00:52:03 -08:00
2013-02-28 02:16:07 -08:00
def generate_transaction_information_widget ( self , tx ) :
2013-02-27 06:58:46 -08:00
tabs = QTabWidget ( self )
tab1 = QWidget ( )
grid_ui = QGridLayout ( tab1 )
grid_ui . setColumnStretch ( 0 , 1 )
tabs . addTab ( tab1 , _ ( ' Outputs ' ) )
tree_widget = MyTreeWidget ( self )
tree_widget . setColumnCount ( 2 )
tree_widget . setHeaderLabels ( [ _ ( ' Address ' ) , _ ( ' Amount ' ) ] )
tree_widget . setColumnWidth ( 0 , 300 )
tree_widget . setColumnWidth ( 1 , 50 )
2013-03-04 08:20:38 -08:00
for address , value in tx . outputs :
2013-04-06 14:34:12 -07:00
item = QTreeWidgetItem ( [ address , " %s " % ( self . format_amount ( value ) ) ] )
2013-02-27 06:58:46 -08:00
tree_widget . addTopLevelItem ( item )
tree_widget . setMaximumHeight ( 100 )
grid_ui . addWidget ( tree_widget )
tab2 = QWidget ( )
grid_ui = QGridLayout ( tab2 )
grid_ui . setColumnStretch ( 0 , 1 )
tabs . addTab ( tab2 , _ ( ' Inputs ' ) )
tree_widget = MyTreeWidget ( self )
tree_widget . setColumnCount ( 2 )
2013-02-28 02:38:33 -08:00
tree_widget . setHeaderLabels ( [ _ ( ' Address ' ) , _ ( ' Previous output ' ) ] )
2013-02-27 06:58:46 -08:00
2013-02-28 02:38:33 -08:00
for input_line in tx . inputs :
item = QTreeWidgetItem ( [ str ( input_line [ " address " ] ) , str ( input_line [ " prevout_hash " ] ) ] )
2013-02-27 06:58:46 -08:00
tree_widget . addTopLevelItem ( item )
tree_widget . setMaximumHeight ( 100 )
grid_ui . addWidget ( tree_widget )
2013-02-28 02:16:07 -08:00
return tabs
2013-02-27 06:58:46 -08:00
2013-02-28 02:16:07 -08:00
def tx_dict_from_text ( self , txt ) :
try :
tx_dict = json . loads ( str ( txt ) )
assert " hex " in tx_dict . keys ( )
assert " complete " in tx_dict . keys ( )
if not tx_dict [ " complete " ] :
assert " input_info " in tx_dict . keys ( )
except :
2013-03-11 18:02:09 -07:00
QMessageBox . critical ( None , " Unable to parse transaction " , _ ( " Electrum was unable to parse your transaction " ) )
2013-02-28 02:16:07 -08:00
return None
return tx_dict
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 :
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-02-28 02:16:07 -08:00
return self . tx_dict_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
2013-03-08 07:30:38 -08:00
def sign_raw_transaction ( self , tx , input_info , dialog = " " , password = " " ) :
2013-02-28 02:16:07 -08:00
try :
self . wallet . signrawtransaction ( tx , input_info , [ ] , password )
2013-03-11 07:57:37 -07:00
fileName = self . getSaveFileName ( _ ( " Select where to save your signed transaction " ) , ' signed_ %s .txn ' % ( tx . hash ( ) [ 0 : 8 ] ) , " *.txn " )
2013-02-28 02:16:07 -08:00
if fileName :
with open ( fileName , " w+ " ) as f :
f . write ( json . dumps ( tx . as_dict ( ) , indent = 4 ) + ' \n ' )
2013-03-11 17:33:08 -07:00
self . show_message ( _ ( " Transaction saved successfully " ) )
2013-03-08 07:30:38 -08:00
if dialog :
dialog . done ( 0 )
2013-02-28 02:16:07 -08:00
except BaseException , e :
self . show_message ( str ( e ) )
2013-02-27 06:58:46 -08:00
2013-02-28 02:16:07 -08:00
2013-03-08 07:30:38 -08:00
def send_raw_transaction ( self , raw_tx , dialog = " " ) :
2013-02-28 02:17:15 -08:00
result , result_message = self . wallet . sendtx ( raw_tx )
2013-02-27 06:58:46 -08:00
if result :
2013-03-11 17:33:08 -07:00
self . show_message ( " Transaction successfully sent: %s " % ( result_message ) )
2013-03-08 07:30:38 -08:00
if dialog :
dialog . done ( 0 )
2013-02-27 06:58:46 -08:00
else :
self . show_message ( " There was a problem sending your transaction: \n %s " % ( result_message ) )
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
tx_dict = self . tx_dict_from_text ( text )
2013-02-28 02:16:07 -08:00
if tx_dict :
2013-03-08 07:48:40 -08:00
self . create_process_transaction_window ( tx_dict )
2013-02-27 06:58:46 -08:00
2013-03-04 08:05:26 -08:00
def do_process_from_file ( self ) :
2013-02-28 02:16:07 -08:00
tx_dict = self . read_tx_from_file ( )
2013-03-04 08:05:26 -08:00
if tx_dict :
self . create_process_transaction_window ( tx_dict )
2013-02-28 02:16:07 -08:00
2013-03-04 08:05:26 -08:00
def create_process_transaction_window ( self , tx_dict ) :
2013-02-28 02:16:07 -08:00
tx = Transaction ( tx_dict [ " hex " ] )
2013-03-08 07:30:38 -08:00
2013-02-27 06:58:46 -08:00
dialog = QDialog ( self )
dialog . setMinimumWidth ( 500 )
2013-03-04 08:05:26 -08:00
dialog . setWindowTitle ( _ ( ' Process raw transaction ' ) )
2013-02-27 06:58:46 -08:00
dialog . setModal ( 1 )
2013-03-04 08:05:26 -08:00
l = QGridLayout ( )
dialog . setLayout ( l )
2013-03-12 06:34:35 -07:00
l . addWidget ( QLabel ( _ ( " Transaction status: " ) ) , 3 , 0 )
2013-03-10 04:14:42 -07:00
l . addWidget ( QLabel ( _ ( " Actions " ) ) , 4 , 0 )
2013-02-27 06:58:46 -08:00
2013-02-28 02:16:07 -08:00
if tx_dict [ " complete " ] == False :
2013-03-10 04:14:42 -07:00
l . addWidget ( QLabel ( _ ( " Unsigned " ) ) , 3 , 1 )
2013-03-04 08:05:26 -08:00
if self . wallet . seed :
b = QPushButton ( " Sign transaction " )
2013-03-08 07:30:38 -08:00
input_info = json . loads ( tx_dict [ " input_info " ] )
b . clicked . connect ( lambda : self . sign_raw_transaction ( tx , input_info , dialog ) )
2013-03-10 04:14:42 -07:00
l . addWidget ( b , 4 , 1 )
2013-03-04 08:05:26 -08:00
else :
2013-03-10 04:14:42 -07:00
l . addWidget ( QLabel ( _ ( " Wallet is de-seeded, can ' t sign. " ) ) , 4 , 1 )
2013-02-27 06:58:46 -08:00
else :
2013-03-10 04:14:42 -07:00
l . addWidget ( QLabel ( _ ( " Signed " ) ) , 3 , 1 )
2013-03-04 08:05:26 -08:00
b = QPushButton ( " Broadcast transaction " )
2013-03-08 07:30:38 -08:00
b . clicked . connect ( lambda : self . send_raw_transaction ( tx , dialog ) )
2013-03-10 04:14:42 -07:00
l . addWidget ( b , 4 , 1 )
2013-02-27 06:58:46 -08:00
2013-03-10 04:14:42 -07:00
l . addWidget ( self . generate_transaction_information_widget ( tx ) , 0 , 0 , 2 , 3 )
cancelButton = QPushButton ( _ ( " Cancel " ) )
cancelButton . clicked . connect ( lambda : dialog . done ( 0 ) )
l . addWidget ( cancelButton , 4 , 2 )
2013-02-27 06:58:46 -08:00
2013-03-08 07:30:38 -08:00
dialog . exec_ ( )
2013-02-27 06:58:46 -08:00
2013-03-04 22:55:43 -08:00
@protected
def do_export_privkeys ( self , password ) :
2013-02-14 08:31:29 -08:00
self . show_message ( " %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. " ) ) )
try :
select_export = _ ( ' Select file to export your private keys to ' )
2013-03-11 07:57:37 -07:00
fileName = self . getSaveFileName ( select_export , ' electrum-private-keys.csv ' , " *.csv " )
2013-02-14 08:31:29 -08:00
if fileName :
with open ( fileName , " w+ " ) as csvfile :
transaction = csv . writer ( csvfile )
transaction . writerow ( [ " address " , " private_key " ] )
2013-02-26 07:29:23 -08:00
2013-03-02 02:40:17 -08:00
for addr , pk in self . wallet . get_private_keys ( self . wallet . addresses ( True ) , password ) . items ( ) :
2013-02-26 07:29:23 -08:00
transaction . writerow ( [ " %34s " % addr , pk ] )
2013-02-14 08:31:29 -08:00
self . show_message ( _ ( " Private keys exported. " ) )
except ( IOError , os . error ) , reason :
export_error_label = _ ( " Electrum was unable to produce a private key-export. " )
QMessageBox . critical ( None , " Unable to create csv " , export_error_label + " \n " + str ( reason ) )
except BaseException , e :
self . show_message ( str ( e ) )
return
2012-06-07 08:42:50 -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 ( ) :
self . wallet . labels [ key ] = value
2013-01-05 12:03:46 -08:00
self . wallet . save ( )
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-03-11 07:57:37 -07: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 )
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-01-30 01:16:00 -08: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
2013-01-05 12:03:46 -08:00
def do_export_history ( self ) :
from gui_lite import csv_transaction
csv_transaction ( self . wallet )
2012-06-07 07:07:49 -07:00
2013-03-04 22:55:43 -08:00
@protected
def do_import_privkey ( self , password ) :
2013-01-05 16:44:12 -08:00
if not self . wallet . 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 )
except BaseException as e :
badkeys . append ( key )
continue
if not addr :
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 ) )
self . update_receive_tab ( )
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 ) :
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-01-03 03:23:59 -08:00
tabs = QTabWidget ( self )
2013-03-10 09:04:00 -07:00
self . settings_tab = tabs
2013-01-03 03:23:59 -08:00
vbox . addWidget ( tabs )
2013-01-05 12:03:46 -08:00
tab1 = QWidget ( )
grid_ui = QGridLayout ( tab1 )
2013-01-03 03:23:59 -08:00
grid_ui . setColumnStretch ( 0 , 1 )
2013-01-05 12:03:46 -08:00
tabs . addTab ( tab1 , _ ( ' Display ' ) )
2012-02-13 06:22:15 -08:00
2012-10-12 09:01:35 -07:00
nz_label = QLabel ( _ ( ' Display zeros ' ) )
2013-03-11 05:49:43 -07:00
grid_ui . addWidget ( nz_label , 0 , 0 )
2013-04-06 14:34:12 -07:00
nz_e = AmountEdit ( None , True )
2012-05-02 08:40:39 -07:00
nz_e . setText ( " %d " % self . wallet . num_zeros )
2013-03-11 05:49:43 -07:00
grid_ui . addWidget ( nz_e , 0 , 1 )
2012-06-23 04:30:58 -07:00
msg = _ ( ' Number of zeros displayed after the decimal point. For example, if this is set to 2, " 1. " will be displayed as " 1.00 " ' )
2013-03-11 05:49:43 -07:00
grid_ui . addWidget ( HelpButton ( msg ) , 0 , 2 )
2012-10-12 09:01:35 -07:00
if not self . config . is_modifiable ( ' num_zeros ' ) :
for w in [ nz_e , nz_label ] : w . setEnabled ( False )
2012-10-11 03:56:57 -07:00
2013-01-02 07:57:18 -08:00
lang_label = QLabel ( _ ( ' Language ' ) + ' : ' )
2013-03-11 05:49:43 -07:00
grid_ui . addWidget ( lang_label , 1 , 0 )
2013-01-02 07:57:18 -08:00
lang_combo = QComboBox ( )
2013-01-04 06:38:22 -08:00
from 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-01-02 07:57:18 -08:00
except :
index = 0
lang_combo . setCurrentIndex ( index )
2013-03-11 05:49:43 -07:00
grid_ui . addWidget ( lang_combo , 1 , 1 )
grid_ui . addWidget ( HelpButton ( _ ( ' Select which language is used in the GUI (after restart). ' ) + ' ' ) , 1 , 2 )
2013-01-02 07:57:18 -08:00
if not self . config . is_modifiable ( ' language ' ) :
for w in [ lang_combo , lang_label ] : w . setEnabled ( False )
2013-01-05 06:23:35 -08:00
currencies = self . exchanger . get_currencies ( )
currencies . insert ( 0 , " None " )
2013-01-03 05:18:45 -08:00
2013-01-05 06:23:35 -08:00
cur_label = QLabel ( _ ( ' Currency ' ) + ' : ' )
2013-03-11 05:49:43 -07:00
grid_ui . addWidget ( cur_label , 2 , 0 )
2013-01-05 06:23:35 -08:00
cur_combo = QComboBox ( )
cur_combo . addItems ( currencies )
try :
index = currencies . index ( self . config . get ( ' currency ' , " None " ) )
except :
index = 0
cur_combo . setCurrentIndex ( index )
2013-03-11 05:49:43 -07:00
grid_ui . addWidget ( cur_combo , 2 , 1 )
grid_ui . addWidget ( HelpButton ( _ ( ' Select which currency is used for quotes. ' ) + ' ' ) , 2 , 2 )
2013-01-05 06:23:35 -08:00
2013-04-04 19:48:04 -07:00
expert_cb = QCheckBox ( _ ( ' Expert mode ' ) )
expert_cb . setChecked ( self . expert_mode )
grid_ui . addWidget ( expert_cb , 3 , 0 )
2013-04-04 19:57:06 -07:00
hh = _ ( ' In expert mode, your client will: ' ) + ' \n ' \
+ _ ( ' - Show change addresses in the Receive tab ' ) + ' \n ' \
+ _ ( ' - Display the balance of each address ' ) + ' \n ' \
+ _ ( ' - Add freeze/prioritize actions to addresses. ' )
2013-03-11 05:49:43 -07:00
grid_ui . addWidget ( HelpButton ( hh ) , 3 , 2 )
grid_ui . setRowStretch ( 4 , 1 )
2013-01-05 12:03:46 -08:00
# wallet tab
tab2 = QWidget ( )
grid_wallet = QGridLayout ( tab2 )
grid_wallet . setColumnStretch ( 0 , 1 )
tabs . addTab ( tab2 , _ ( ' Wallet ' ) )
fee_label = QLabel ( _ ( ' Transaction fee ' ) )
grid_wallet . addWidget ( fee_label , 0 , 0 )
2013-04-06 14:34:12 -07:00
fee_e = AmountEdit ( self . base_unit )
fee_e . setText ( self . format_amount ( self . wallet . fee ) . strip ( ) )
2013-03-10 04:14:42 -07:00
grid_wallet . addWidget ( fee_e , 0 , 2 )
2013-03-23 01:23:57 -07:00
msg = _ ( ' Fee per kilobyte of transaction. ' ) + ' ' \
2013-04-06 14:34:12 -07:00
+ _ ( ' Recommended value ' ) + ' : ' + self . format_amount ( 20000 )
2013-03-10 04:14:42 -07:00
grid_wallet . addWidget ( HelpButton ( msg ) , 0 , 3 )
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 )
2013-04-07 08:42:58 -07:00
usechange_cb = QCheckBox ( _ ( ' Use change addresses ' ) )
usechange_cb . setChecked ( self . wallet . use_change )
grid_wallet . addWidget ( usechange_cb , 1 , 0 )
2013-03-10 04:14:42 -07:00
grid_wallet . addWidget ( HelpButton ( _ ( ' Using change addresses makes it more difficult for other people to track your transactions. ' ) + ' ' ) , 1 , 3 )
2013-04-07 08:42:58 -07:00
if not self . config . is_modifiable ( ' use_change ' ) : usechange_cb . setEnabled ( False )
2013-01-05 12:03:46 -08:00
gap_label = QLabel ( _ ( ' Gap limit ' ) )
grid_wallet . addWidget ( gap_label , 2 , 0 )
2013-04-06 14:34:12 -07:00
gap_e = AmountEdit ( None , True )
2013-01-05 12:03:46 -08:00
gap_e . setText ( " %d " % self . wallet . gap_limit )
2013-03-10 04:14:42 -07:00
grid_wallet . addWidget ( gap_e , 2 , 2 )
2013-01-05 12:03:46 -08:00
msg = _ ( ' The gap limit is the maximal number of contiguous unused addresses in your sequence of receiving addresses. ' ) + ' \n ' \
+ _ ( ' You may increase it if you need more receiving addresses. ' ) + ' \n \n ' \
+ _ ( ' Your current gap limit is ' ) + ' : %d ' % self . wallet . gap_limit + ' \n ' \
2013-01-12 18:56:13 -08:00
+ _ ( ' Given the current status of your address sequence, the minimum gap limit you can use is: ' ) + ' ' + ' %d ' % self . wallet . min_acceptable_gap ( ) + ' \n \n ' \
2013-01-05 12:03:46 -08:00
+ _ ( ' Warning ' ) + ' : ' \
+ _ ( ' The gap limit parameter must be provided in order to recover your wallet from seed. ' ) + ' ' \
+ _ ( ' Do not modify it if you do not understand what you are doing, or if you expect to recover your wallet without knowing it! ' ) + ' \n \n '
2013-03-10 04:14:42 -07:00
grid_wallet . addWidget ( HelpButton ( msg ) , 2 , 3 )
2013-01-05 12:03:46 -08:00
if not self . config . is_modifiable ( ' gap_limit ' ) :
for w in [ gap_e , gap_label ] : w . setEnabled ( False )
2013-04-06 14:34:12 -07:00
units = [ ' BTC ' , ' mBTC ' ]
unit_label = QLabel ( _ ( ' Base unit ' ) )
grid_wallet . addWidget ( unit_label , 3 , 0 )
unit_combo = QComboBox ( )
unit_combo . addItems ( units )
unit_combo . setCurrentIndex ( units . index ( self . base_unit ( ) ) )
grid_wallet . addWidget ( unit_combo , 3 , 2 )
grid_wallet . addWidget ( HelpButton ( _ ( ' Base unit of your wallet. ' ) \
+ ' \n 1BTC=1000mBTC. \n ' \
+ _ ( ' This settings affects the fields in the Send tab ' ) + ' ' ) , 3 , 3 )
grid_wallet . setRowStretch ( 4 , 1 )
2013-01-05 12:03:46 -08:00
2013-02-01 08:45:25 -08:00
# import/export tab
2013-01-05 12:03:46 -08:00
tab3 = QWidget ( )
grid_io = QGridLayout ( tab3 )
grid_io . setColumnStretch ( 0 , 1 )
tabs . addTab ( tab3 , _ ( ' Import/Export ' ) )
2013-01-03 05:18:45 -08:00
2013-01-05 12:03:46 -08:00
grid_io . addWidget ( QLabel ( _ ( ' Labels ' ) ) , 1 , 0 )
grid_io . addWidget ( EnterButton ( _ ( " Export " ) , self . do_export_labels ) , 1 , 1 )
grid_io . addWidget ( EnterButton ( _ ( " Import " ) , self . do_import_labels ) , 1 , 2 )
2013-01-12 09:56:53 -08:00
grid_io . addWidget ( HelpButton ( _ ( ' Export your labels as json ' ) ) , 1 , 3 )
2013-01-05 12:03:46 -08:00
grid_io . addWidget ( QLabel ( _ ( ' History ' ) ) , 2 , 0 )
grid_io . addWidget ( EnterButton ( _ ( " Export " ) , self . do_export_history ) , 2 , 1 )
2013-01-12 09:56:53 -08:00
grid_io . addWidget ( HelpButton ( _ ( ' Export your transaction history as csv ' ) ) , 2 , 3 )
2013-01-05 12:03:46 -08:00
2013-02-15 08:47:56 -08:00
grid_io . addWidget ( QLabel ( _ ( ' Private keys ' ) ) , 3 , 0 )
2013-02-14 08:31:29 -08:00
grid_io . addWidget ( EnterButton ( _ ( " Export " ) , self . do_export_privkeys ) , 3 , 1 )
2013-01-05 12:58:16 -08:00
grid_io . addWidget ( EnterButton ( _ ( " Import " ) , self . do_import_privkey ) , 3 , 2 )
2013-01-12 09:56:53 -08:00
grid_io . addWidget ( HelpButton ( _ ( ' Import private key ' ) ) , 3 , 3 )
2013-01-05 12:58:16 -08:00
2013-01-16 15:22:43 -08:00
grid_io . addWidget ( QLabel ( _ ( ' Master Public Key ' ) ) , 4 , 0 )
2013-01-08 05:29:42 -08:00
grid_io . addWidget ( EnterButton ( _ ( " Show " ) , self . show_master_public_key ) , 4 , 1 )
2013-01-16 15:22:43 -08:00
grid_io . addWidget ( HelpButton ( _ ( ' Your Master Public Key can be used to create receiving addresses, but not to sign transactions. ' ) + ' ' \
2013-01-10 13:04:52 -08:00
+ _ ( ' If you give it to someone, they will be able to see your transactions, but not to spend your money. ' ) + ' ' \
+ _ ( ' If you restore your wallet from it, a watching-only (deseeded) wallet will be created. ' ) ) , 4 , 3 )
2013-01-08 05:29:42 -08:00
2013-03-11 05:45:19 -07:00
grid_io . addWidget ( QLabel ( _ ( " Load transaction " ) ) , 5 , 0 )
grid_io . addWidget ( EnterButton ( _ ( " From file " ) , self . do_process_from_file ) , 5 , 1 )
grid_io . addWidget ( EnterButton ( _ ( " From text " ) , self . do_process_from_text ) , 5 , 2 )
grid_io . addWidget ( HelpButton ( _ ( " This will give you the option to sign or broadcast a transaction based on it ' s status. " ) ) , 5 , 3 )
grid_io . setRowStretch ( 5 , 1 )
2013-02-27 06:58:46 -08:00
2013-03-03 03:00:38 -08:00
# plugins
2013-03-03 07:33:09 -08:00
if self . plugins :
2013-03-11 05:35:51 -07:00
tab5 = QScrollArea ( )
2013-03-03 07:33:09 -08:00
grid_plugins = QGridLayout ( tab5 )
grid_plugins . setColumnStretch ( 0 , 1 )
tabs . addTab ( tab5 , _ ( ' Plugins ' ) )
def mk_toggle ( cb , p ) :
2013-03-15 01:58:05 -07:00
return lambda : cb . setChecked ( p . toggle ( ) )
2013-03-03 07:33:09 -08:00
for i , p in enumerate ( self . plugins ) :
try :
name , description = p . get_info ( )
cb = QCheckBox ( name )
2013-03-11 06:30:30 -07:00
cb . setDisabled ( not p . is_available ( ) )
2013-03-03 07:33:09 -08:00
cb . setChecked ( p . is_enabled ( ) )
2013-03-11 05:35:51 -07:00
cb . clicked . connect ( mk_toggle ( cb , p ) )
2013-03-03 07:33:09 -08:00
grid_plugins . addWidget ( cb , i , 0 )
2013-03-17 03:52:58 -07:00
if p . requires_settings ( ) :
2013-03-17 03:29:01 -07:00
grid_plugins . addWidget ( EnterButton ( _ ( ' Settings ' ) , p . settings_dialog ) , i , 1 )
grid_plugins . addWidget ( HelpButton ( description ) , i , 2 )
2013-03-03 07:33:09 -08:00
except :
print_msg ( " Error: cannot display plugin " , p )
traceback . print_exc ( file = sys . stdout )
grid_plugins . setRowStretch ( i + 1 , 1 )
2013-03-03 03:00:38 -08:00
2013-03-16 15:33:49 -07:00
self . run_hook ( ' create_settings_tab ' , tabs )
2013-03-10 09:04:00 -07:00
2012-02-14 00:52:03 -08:00
vbox . addLayout ( ok_cancel_buttons ( d ) )
2012-02-13 10:02: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
2012-02-13 06:22:15 -08:00
if not d . exec_ ( ) : return
2012-02-14 14:11:59 -08:00
fee = unicode ( fee_e . text ( ) )
2012-02-13 06:22:15 -08:00
try :
2013-04-06 14:34:12 -07:00
fee = self . read_amount ( fee )
2012-02-13 06:22:15 -08:00
except :
2012-05-18 06:28:55 -07:00
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Invalid value ' ) + ' : %s ' % fee , _ ( ' OK ' ) )
2012-02-13 06:22:15 -08:00
return
2012-05-02 08:40:39 -07:00
if self . wallet . fee != fee :
self . wallet . fee = fee
self . wallet . save ( )
nz = unicode ( nz_e . text ( ) )
try :
nz = int ( nz )
if nz > 8 : nz = 8
except :
2012-05-18 06:28:55 -07:00
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Invalid value ' ) + ' : %s ' % nz , _ ( ' OK ' ) )
2012-05-02 08:40:39 -07:00
return
if self . wallet . num_zeros != nz :
self . wallet . num_zeros = nz
2012-10-12 08:40:37 -07:00
self . config . set_key ( ' num_zeros ' , nz , True )
2012-05-02 08:40:39 -07:00
self . update_history_tab ( )
2012-05-05 05:51:57 -07:00
self . update_receive_tab ( )
2012-02-13 06:22:15 -08:00
2013-04-07 08:42:58 -07:00
usechange_result = usechange_cb . isChecked ( )
2013-01-03 03:23:59 -08:00
if self . wallet . use_change != usechange_result :
self . wallet . use_change = usechange_result
2012-10-12 08:40:37 -07:00
self . config . set_key ( ' use_change ' , self . wallet . use_change , True )
2013-04-06 14:34:12 -07:00
unit_result = units [ unit_combo . currentIndex ( ) ]
if self . base_unit ( ) != unit_result :
self . decimal_point = 8 if unit_result == ' BTC ' else 5
self . config . set_key ( ' decimal_point ' , self . decimal_point , True )
self . update_history_tab ( )
self . update_status ( )
2012-10-11 03:56:57 -07:00
try :
n = int ( gap_e . text ( ) )
except :
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Invalid value ' ) , _ ( ' OK ' ) )
return
2012-10-12 08:40:37 -07:00
2012-10-11 03:56:57 -07:00
if self . wallet . gap_limit != n :
r = self . wallet . change_gap_limit ( n )
if r :
self . update_receive_tab ( )
2012-10-12 08:40:37 -07:00
self . config . set_key ( ' gap_limit ' , self . wallet . gap_limit , True )
2012-10-11 03:56:57 -07:00
else :
2012-06-23 04:58:32 -07:00
QMessageBox . warning ( self , _ ( ' Error ' ) , _ ( ' Invalid value ' ) , _ ( ' OK ' ) )
2013-01-03 05:44:48 -08:00
need_restart = False
lang_request = languages . keys ( ) [ lang_combo . currentIndex ( ) ]
if lang_request != self . config . get ( ' language ' ) :
self . config . set_key ( " language " , lang_request , True )
need_restart = True
2013-01-05 06:23:35 -08:00
cur_request = str ( currencies [ cur_combo . currentIndex ( ) ] )
if cur_request != self . config . get ( ' currency ' , " None " ) :
self . config . set_key ( ' currency ' , cur_request , True )
self . update_wallet ( )
2013-01-03 05:44:48 -08:00
2013-03-16 15:33:49 -07:00
self . run_hook ( ' close_settings_dialog ' )
2013-03-12 09:13:50 -07:00
2013-01-03 05:44:48 -08:00
if need_restart :
QMessageBox . warning ( self , _ ( ' Success ' ) , _ ( ' Please restart Electrum to activate the new GUI settings ' ) , _ ( ' OK ' ) )
2012-06-12 04:21:01 -07:00
2013-04-04 19:48:04 -07:00
self . receive_tab_set_mode ( expert_cb . isChecked ( ) )
2012-06-12 04:21:01 -07:00
2012-02-14 00:52:03 -08:00
@staticmethod
def network_dialog ( wallet , parent = None ) :
2012-03-14 08:08:23 -07:00
interface = wallet . interface
2012-02-14 01:05:38 -08:00
if parent :
2012-03-14 08:08:23 -07:00
if interface . is_connected :
2013-01-13 00:01:31 -08:00
status = _ ( " Connected to " ) + " %s \n %d " % ( interface . host , wallet . verifier . height ) + _ ( " blocks " )
2012-02-13 06:44:16 -08:00
else :
2012-05-18 06:28:55 -07:00
status = _ ( " Not connected " )
2012-11-20 06:30:46 -08:00
server = interface . server
2012-02-13 06:44:16 -08:00
else :
import random
2012-11-20 06:30:46 -08:00
status = _ ( " Please choose a server. " ) + " \n " + _ ( " Select ' Cancel ' if you are offline. " )
2012-11-20 12:46:45 -08:00
server = interface . server
2012-10-16 00:27:58 -07:00
2012-11-18 02:34:52 -08:00
plist , servers_list = interface . get_servers_list ( )
2012-03-31 05:03:30 -07:00
2012-02-14 00:52:03 -08:00
d = QDialog ( parent )
2012-02-13 06:44:16 -08:00
d . setModal ( 1 )
2012-05-24 01:04:16 -07:00
d . setWindowTitle ( _ ( ' Server ' ) )
2012-02-14 06:34:13 -08:00
d . setMinimumSize ( 375 , 20 )
2012-02-13 06:44:16 -08:00
2012-02-13 10:02:48 -08:00
vbox = QVBoxLayout ( )
2012-10-12 02:01:09 -07:00
vbox . setSpacing ( 30 )
2012-02-13 10:02:48 -08:00
2012-02-14 06:34:13 -08:00
hbox = QHBoxLayout ( )
l = QLabel ( )
l . setPixmap ( QPixmap ( " :icons/network.png " ) )
2012-10-12 02:01:09 -07:00
hbox . addStretch ( 10 )
2012-11-01 03:43:59 -07:00
hbox . addWidget ( l )
2012-02-14 06:34:13 -08:00
hbox . addWidget ( QLabel ( status ) )
2012-10-12 02:01:09 -07:00
hbox . addStretch ( 50 )
2012-02-14 06:34:13 -08:00
vbox . addLayout ( hbox )
2012-02-13 06:44:16 -08:00
2012-10-12 02:01:09 -07:00
# grid layout
grid = QGridLayout ( )
grid . setSpacing ( 8 )
vbox . addLayout ( grid )
2012-03-31 05:03:30 -07:00
2012-10-12 02:01:09 -07:00
# server
server_protocol = QComboBox ( )
server_host = QLineEdit ( )
server_host . setFixedWidth ( 200 )
server_port = QLineEdit ( )
server_port . setFixedWidth ( 60 )
2012-10-18 11:29:53 -07:00
2013-04-01 03:11:24 -07:00
protocol_names = [ ' TCP ' , ' HTTP ' , ' SSL ' , ' HTTPS ' ]
2012-10-18 11:29:53 -07:00
protocol_letters = ' thsg '
server_protocol . addItems ( protocol_names )
2012-10-12 02:01:09 -07:00
grid . addWidget ( QLabel ( _ ( ' Server ' ) + ' : ' ) , 0 , 0 )
grid . addWidget ( server_protocol , 0 , 1 )
grid . addWidget ( server_host , 0 , 2 )
grid . addWidget ( server_port , 0 , 3 )
def change_protocol ( p ) :
2012-10-18 11:29:53 -07:00
protocol = protocol_letters [ p ]
2012-10-12 02:01:09 -07:00
host = unicode ( server_host . text ( ) )
2012-11-01 03:43:59 -07:00
pp = plist . get ( host , DEFAULT_PORTS )
2012-03-31 05:03:30 -07:00
if protocol not in pp . keys ( ) :
protocol = pp . keys ( ) [ 0 ]
port = pp [ protocol ]
2012-10-12 02:01:09 -07:00
server_host . setText ( host )
server_port . setText ( port )
2012-03-31 05:03:30 -07:00
2012-10-12 02:01:09 -07:00
server_protocol . connect ( server_protocol , SIGNAL ( ' currentIndexChanged(int) ' ) , change_protocol )
2012-10-19 02:02:22 -07:00
label = _ ( ' Active Servers ' ) if wallet . interface . servers else _ ( ' Default Servers ' )
2012-10-12 02:01:09 -07:00
servers_list_widget = QTreeWidget ( parent )
2013-04-06 07:06:15 -07:00
servers_list_widget . setHeaderLabels ( [ label , _ ( ' Pruning ' ) ] )
2012-10-12 02:01:09 -07:00
servers_list_widget . setMaximumHeight ( 150 )
2012-11-24 01:32:45 -08:00
servers_list_widget . setColumnWidth ( 0 , 240 )
2012-11-20 04:33:36 -08:00
for _host in servers_list . keys ( ) :
2013-04-06 13:28:24 -07:00
pruning_level = servers_list [ _host ] . get ( ' pruning ' , ' ' )
2013-04-06 07:06:15 -07:00
servers_list_widget . addTopLevelItem ( QTreeWidgetItem ( [ _host , pruning_level ] ) )
servers_list_widget . setColumnHidden ( 1 , not parent . expert_mode if parent else True )
2012-03-31 05:03:30 -07:00
2012-10-19 01:41:20 -07:00
def change_server ( host , protocol = None ) :
2012-11-01 03:43:59 -07:00
pp = plist . get ( host , DEFAULT_PORTS )
2012-10-19 01:41:20 -07:00
if protocol :
port = pp . get ( protocol )
if not port : protocol = None
if not protocol :
2013-04-01 03:11:24 -07:00
if ' s ' in pp . keys ( ) :
protocol = ' s '
2012-10-19 02:02:22 -07:00
port = pp . get ( protocol )
2012-10-19 01:41:20 -07:00
else :
protocol = pp . keys ( ) [ 0 ]
2012-10-19 02:02:22 -07:00
port = pp . get ( protocol )
2012-10-19 01:41:20 -07:00
2012-10-12 02:01:09 -07:00
server_host . setText ( host )
server_port . setText ( port )
2012-10-18 11:29:53 -07:00
server_protocol . setCurrentIndex ( protocol_letters . index ( protocol ) )
2012-11-01 03:43:59 -07:00
if not plist : return
2012-10-18 11:29:53 -07:00
for p in protocol_letters :
i = protocol_letters . index ( p )
j = server_protocol . model ( ) . index ( i , 0 )
2013-03-16 12:37:49 -07:00
if p not in pp . keys ( ) and interface . is_connected :
2012-10-18 11:29:53 -07:00
server_protocol . model ( ) . setData ( j , QtCore . QVariant ( 0 ) , QtCore . Qt . UserRole - 1 )
else :
2013-03-19 15:01:09 -07:00
server_protocol . model ( ) . setData ( j , QtCore . QVariant ( 33 ) , QtCore . Qt . UserRole - 1 )
2012-10-18 11:29:53 -07:00
2012-03-31 05:03:30 -07:00
2012-11-20 06:30:46 -08:00
if server :
host , port , protocol = server . split ( ' : ' )
change_server ( host , protocol )
2013-04-01 03:11:24 -07:00
servers_list_widget . connect ( servers_list_widget , SIGNAL ( ' currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*) ' ) ,
lambda x , y : change_server ( unicode ( x . text ( 0 ) ) ) )
2012-10-12 02:01:09 -07:00
grid . addWidget ( servers_list_widget , 1 , 1 , 1 , 3 )
2012-10-12 02:10:58 -07:00
if not wallet . config . is_modifiable ( ' server ' ) :
for w in [ server_host , server_port , server_protocol , servers_list_widget ] : w . setEnabled ( False )
2013-01-03 08:39:51 -08:00
# auto cycle
2013-01-12 09:56:53 -08:00
autocycle_cb = QCheckBox ( _ ( ' Try random servers if disconnected ' ) )
2013-01-03 08:39:51 -08:00
autocycle_cb . setChecked ( wallet . config . get ( ' auto_cycle ' , False ) )
grid . addWidget ( autocycle_cb , 3 , 1 , 3 , 2 )
if not wallet . config . is_modifiable ( ' auto_cycle ' ) : autocycle_cb . setEnabled ( False )
2012-10-12 02:01:09 -07:00
# proxy setting
2012-09-20 02:55:28 -07:00
proxy_mode = QComboBox ( )
proxy_host = QLineEdit ( )
2012-09-20 04:24:36 -07:00
proxy_host . setFixedWidth ( 200 )
2012-09-20 02:55:28 -07:00
proxy_port = QLineEdit ( )
2012-10-12 02:01:09 -07:00
proxy_port . setFixedWidth ( 60 )
2012-09-20 02:55:28 -07:00
proxy_mode . addItems ( [ ' NONE ' , ' SOCKS4 ' , ' SOCKS5 ' , ' HTTP ' ] )
2012-10-02 03:40:08 -07:00
2012-10-09 13:07:39 -07:00
def check_for_disable ( index = False ) :
if proxy_mode . currentText ( ) != ' NONE ' :
proxy_host . setEnabled ( True )
proxy_port . setEnabled ( True )
else :
proxy_host . setEnabled ( False )
proxy_port . setEnabled ( False )
check_for_disable ( )
proxy_mode . connect ( proxy_mode , SIGNAL ( ' currentIndexChanged(int) ' ) , check_for_disable )
2012-10-12 02:10:58 -07:00
if not wallet . config . is_modifiable ( ' proxy ' ) :
for w in [ proxy_host , proxy_port , proxy_mode ] : w . setEnabled ( False )
2012-10-09 06:48:06 -07:00
proxy_config = interface . proxy if interface . proxy else { " mode " : " none " , " host " : " localhost " , " port " : " 8080 " }
proxy_mode . setCurrentIndex ( proxy_mode . findText ( str ( proxy_config . get ( " mode " ) . upper ( ) ) ) )
proxy_host . setText ( proxy_config . get ( " host " ) )
proxy_port . setText ( proxy_config . get ( " port " ) )
2012-10-12 02:01:09 -07:00
grid . addWidget ( QLabel ( _ ( ' Proxy ' ) + ' : ' ) , 2 , 0 )
grid . addWidget ( proxy_mode , 2 , 1 )
grid . addWidget ( proxy_host , 2 , 2 )
grid . addWidget ( proxy_port , 2 , 3 )
2012-02-14 05:58:38 -08:00
2012-10-12 02:01:09 -07:00
# buttons
2012-02-14 00:52:03 -08:00
vbox . addLayout ( ok_cancel_buttons ( d ) )
2012-02-13 10:02:48 -08:00
d . setLayout ( vbox )
2012-02-13 06:44:16 -08:00
if not d . exec_ ( ) : return
2012-10-18 11:29:53 -07:00
server = unicode ( server_host . text ( ) ) + ' : ' + unicode ( server_port . text ( ) ) + ' : ' + ( protocol_letters [ server_protocol . currentIndex ( ) ] )
2012-10-11 11:10:12 -07:00
if proxy_mode . currentText ( ) != ' NONE ' :
proxy = { u ' mode ' : unicode ( proxy_mode . currentText ( ) ) . lower ( ) , u ' host ' : unicode ( proxy_host . text ( ) ) , u ' port ' : unicode ( proxy_port . text ( ) ) }
else :
proxy = None
2012-10-09 06:48:06 -07:00
2012-10-11 11:10:12 -07:00
wallet . config . set_key ( " proxy " , proxy , True )
wallet . config . set_key ( " server " , server , True )
interface . set_server ( server , proxy )
2013-01-03 08:39:51 -08:00
wallet . config . set_key ( ' auto_cycle ' , autocycle_cb . isChecked ( ) , True )
2012-02-14 00:52:03 -08:00
return True
2012-02-13 06:44:16 -08:00
2012-09-20 20:53:14 -07:00
def closeEvent ( self , event ) :
g = self . geometry ( )
2012-10-11 11:10:12 -07:00
self . config . set_key ( " winpos-qt " , [ g . left ( ) , g . top ( ) , g . width ( ) , g . height ( ) ] , True )
2013-01-12 02:23:35 -08:00
self . save_column_widths ( )
2013-03-17 05:50:45 -07:00
self . config . set_key ( " column_widths " , self . column_widths , True )
2013-03-02 05:05:35 -08:00
self . config . set_key ( " console-history " , self . console . history [ - 50 : ] )
2012-09-20 20:53:14 -07:00
event . accept ( )
2012-02-13 06:44:16 -08:00
2012-07-03 16:10:04 -07:00
class ElectrumGui :
2012-02-11 04:14:12 -08:00
2012-10-11 11:10:12 -07:00
def __init__ ( self , wallet , config , app = None ) :
2012-02-11 04:14:12 -08:00
self . wallet = wallet
2012-10-11 11:10:12 -07:00
self . config = config
2012-07-03 16:10:04 -07:00
if app is None :
self . app = QApplication ( sys . argv )
2012-02-14 00:52:03 -08:00
2012-03-30 09:35:26 -07:00
2012-02-14 00:52:03 -08:00
def restore_or_create ( self ) :
2012-05-18 06:28:55 -07:00
msg = _ ( " Wallet file not found. " ) + " \n " + _ ( " Do you want to create a new wallet, or to restore an existing one? " )
2012-05-24 01:11:00 -07:00
r = QMessageBox . question ( None , _ ( ' Message ' ) , msg , _ ( ' Create ' ) , _ ( ' Restore ' ) , _ ( ' Cancel ' ) , 0 , 2 )
2012-11-20 06:30:46 -08:00
if r == 2 : return None
return ' restore ' if r == 1 else ' create '
def seed_dialog ( self ) :
return ElectrumWindow . seed_dialog ( self . wallet )
def network_dialog ( self ) :
return ElectrumWindow . network_dialog ( self . wallet , parent = None )
2012-02-14 00:52:03 -08:00
2012-11-20 12:36:06 -08:00
def show_seed ( self ) :
2013-04-05 09:54:00 -07:00
ElectrumWindow . show_seed ( self . wallet . seed , self . wallet . imported_keys )
2012-11-20 12:36:06 -08:00
def password_dialog ( self ) :
2013-03-07 07:41:43 -08:00
if self . wallet . seed :
ElectrumWindow . change_password_dialog ( self . wallet )
2012-02-14 01:05:38 -08:00
2012-11-20 06:30:46 -08:00
def restore_wallet ( self ) :
wallet = self . wallet
2012-10-22 08:31:37 -07:00
# wait until we are connected, because the user might have selected another server
if not wallet . interface . is_connected :
2013-01-29 23:52:24 -08:00
waiting = lambda : False if wallet . interface . is_connected else " %s \n " % ( _ ( " Connecting... " ) )
2012-10-22 08:31:37 -07:00
waiting_dialog ( waiting )
2013-01-29 23:52:24 -08:00
waiting = lambda : False if wallet . is_up_to_date ( ) else " %s \n %s %d \n %s %.1f " \
2013-03-02 02:40:17 -08:00
% ( _ ( " Please wait... " ) , _ ( " Addresses generated: " ) , len ( wallet . addresses ( True ) ) , _ ( " Kilobytes received: " ) , wallet . interface . bytes_received / 1024. )
2012-10-13 23:25:09 -07:00
2012-11-20 12:36:06 -08:00
wallet . set_up_to_date ( False )
2012-11-20 06:30:46 -08:00
wallet . interface . poke ( ' synchronizer ' )
waiting_dialog ( waiting )
if wallet . is_found ( ) :
2012-11-20 12:36:06 -08:00
print_error ( " Recovery successful " )
2012-02-14 00:52:03 -08:00
else :
2012-11-20 06:30:46 -08:00
QMessageBox . information ( None , _ ( ' Error ' ) , _ ( " No transactions found for this seed " ) , _ ( ' OK ' ) )
2012-02-14 00:52:03 -08:00
return True
2012-02-14 03:45:39 -08:00
def main ( self , url ) :
2012-02-14 05:05:58 -08:00
s = Timer ( )
2012-02-11 13:19:22 -08:00
s . start ( )
2012-10-11 11:10:12 -07:00
w = ElectrumWindow ( self . wallet , self . config )
2012-02-14 03:45:39 -08:00
if url : w . set_url ( url )
2012-02-14 00:52:03 -08:00
w . app = self . app
2012-02-11 13:19:22 -08:00
w . connect_slots ( s )
2012-04-07 06:13:18 -07:00
w . update_wallet ( )
2012-06-28 22:26:52 -07:00
w . show ( )
2012-04-07 06:13:18 -07:00
2012-02-14 00:52:03 -08:00
self . app . exec_ ( )
2013-03-02 07:29:14 -08:00