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
2012-05-18 06:28:55 -07:00
from i18n import _
2012-07-07 11:53:54 -07:00
from util import print_error
2012-02-11 04:14:12 -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
2012-03-31 05:20:25 -07:00
from interface import DEFAULT_SERVERS
2012-02-11 04:14:12 -08:00
2012-02-14 06:56:01 -08:00
try :
import icons_rc
except :
2012-08-19 19:59:05 -07:00
sys . exit ( " Error: Could not import icons_rc.py, please generate it with: ' pyrcc4 icons.qrc -o lib/icons_rc.py ' " )
2012-02-14 02:33:09 -08:00
2012-02-11 13:19:22 -08:00
from wallet import format_satoshis
2012-08-02 06:18:31 -07:00
import bmp , mnemonic , pyqrnative , qrscanner
2012-05-30 07:46:04 -07:00
2012-02-13 06:22:15 -08:00
from decimal import Decimal
2012-02-11 13:19:22 -08:00
2012-03-31 07:46:32 -07:00
import platform
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 '
2012-06-09 03:23:01 -07:00
ALIAS_REGEXP = ' ^(|([ \ w \ - \ .]+)@)(( \ w[ \ w \ -]+ \ .)+[ \ w \ -]+)$ '
2012-02-14 00:52:03 -08:00
2012-02-14 05:34:19 -08:00
def numbify ( entry , is_int = False ) :
2012-02-14 14:11:59 -08:00
text = unicode ( entry . text ( ) ) . strip ( )
2012-09-04 10:54:01 -07:00
pos = entry . cursorPosition ( )
2012-02-14 05:34:19 -08:00
chars = ' 0123456789 '
if not is_int : chars + = ' . '
s = ' ' . join ( [ i for i in text if i in chars ] )
if not is_int :
if ' . ' in s :
p = s . find ( ' . ' )
s = s . replace ( ' . ' , ' ' )
s = s [ : p ] + ' . ' + s [ p : p + 8 ]
try :
amount = int ( Decimal ( s ) * 100000000 )
except :
amount = None
else :
try :
amount = int ( s )
except :
amount = None
entry . setText ( s )
2012-09-04 10:54:01 -07:00
entry . setCursorPosition ( pos )
2012-02-14 05:34:19 -08:00
return amount
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-02-14 07:41:09 -08:00
class QRCodeWidget ( QWidget ) :
def __init__ ( self , addr ) :
super ( QRCodeWidget , self ) . __init__ ( )
2012-11-28 09:08:54 -08:00
self . setMinimumSize ( 210 , 210 )
2012-05-01 08:06:14 -07:00
self . set_addr ( addr )
def set_addr ( self , addr ) :
self . addr = addr
self . qr = pyqrnative . QRCode ( 4 , pyqrnative . QRErrorCorrectLevel . L )
2012-11-28 12:07:35 -08:00
self . qr . addData ( self . addr )
2012-02-14 07:41:09 -08:00
self . qr . make ( )
def paintEvent ( self , e ) :
2012-11-28 06:38:44 -08:00
if not self . addr : return
2012-02-14 07:41:09 -08:00
qp = QtGui . QPainter ( )
qp . begin ( self )
2012-08-01 12:22:07 -07:00
boxsize = 6
2012-02-14 07:41:09 -08:00
size = self . qr . getModuleCount ( ) * boxsize
k = self . qr . getModuleCount ( )
black = QColor ( 0 , 0 , 0 , 255 )
white = QColor ( 255 , 255 , 255 , 255 )
for r in range ( k ) :
for c in range ( k ) :
if self . qr . isDark ( r , c ) :
qp . setBrush ( black )
qp . setPen ( black )
else :
qp . setBrush ( white )
qp . setPen ( white )
qp . drawRect ( c * boxsize , r * boxsize , boxsize , boxsize )
qp . end ( )
2012-11-28 06:38:44 -08:00
class QR_Window ( QWidget ) :
def __init__ ( self ) :
QWidget . __init__ ( self )
2012-11-28 10:05:58 -08:00
self . setWindowTitle ( ' Electrum - Invoice ' )
2012-11-28 06:38:44 -08:00
self . setMinimumSize ( 800 , 250 )
self . address = ' '
self . labe = ' '
self . amount = 0
self . setFocusPolicy ( QtCore . Qt . NoFocus )
main_box = QHBoxLayout ( )
self . qrw = QRCodeWidget ( ' ' )
main_box . addWidget ( self . qrw )
vbox = QVBoxLayout ( )
main_box . addLayout ( vbox )
main_box . addStretch ( 1 )
self . address_label = QLabel ( " " )
2012-11-28 09:08:54 -08:00
self . address_label . setFont ( QFont ( MONOSPACE_FONT ) )
2012-11-28 06:38:44 -08:00
vbox . addWidget ( self . address_label )
self . label_label = QLabel ( " " )
vbox . addWidget ( self . label_label )
self . amount_label = QLabel ( " " )
vbox . addWidget ( self . amount_label )
vbox . addStretch ( 1 )
self . setLayout ( main_box )
def do_save ( self ) :
self . filename = " qrcode.bmp "
bmp . save_qrcode ( self . qrw . qr , self . filename )
def set_content ( self , addr , label , amount ) :
self . address = addr
2012-11-28 09:08:54 -08:00
address_text = " <span style= ' font-size: 21pt ' > %s </span> " % addr if addr else " "
2012-11-28 06:38:44 -08:00
self . address_label . setText ( address_text )
self . amount = amount
2012-11-28 09:08:54 -08:00
amount_text = " <span style= ' font-size: 21pt ' > %s </span> <span style= ' font-size: 16pt ' >BTC</span> " % format_satoshis ( amount ) if amount else " "
2012-11-28 06:38:44 -08:00
self . amount_label . setText ( amount_text )
self . label = label
2012-11-28 09:08:54 -08:00
label_text = " <span style= ' font-size: 21pt ' > %s </span> " % label if label else " "
2012-11-28 06:38:44 -08:00
self . label_label . setText ( label_text )
msg = ' bitcoin: ' + self . address
if self . amount is not None :
msg + = ' ?amount= %s ' % ( str ( Decimal ( self . amount ) / 100000000 ) )
2012-11-28 08:50:45 -08:00
if self . label is not None :
msg + = ' &label= %s ' % ( self . label )
elif self . label is not None :
msg + = ' ?label= %s ' % ( self . label )
2012-11-28 06:38:44 -08:00
self . qrw . set_addr ( msg )
2012-11-28 12:07:35 -08:00
self . qrw . update ( )
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
2012-02-14 00:52:03 -08:00
def ok_cancel_buttons ( dialog ) :
hbox = QHBoxLayout ( )
hbox . addStretch ( 1 )
b = QPushButton ( " OK " )
hbox . addWidget ( b )
b . clicked . connect ( dialog . accept )
b = QPushButton ( " Cancel " )
hbox . addWidget ( b )
b . clicked . connect ( dialog . reject )
return hbox
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 )
2012-02-11 04:14:12 -08:00
self . wallet = wallet
2012-10-11 11:10:12 -07:00
self . config = config
2012-10-22 02:34:21 -07:00
self . wallet . interface . register_callback ( ' updated ' , self . update_callback )
2012-10-22 03:58:57 -07:00
self . wallet . interface . register_callback ( ' connected ' , self . update_callback )
self . wallet . interface . register_callback ( ' disconnected ' , self . update_callback )
2012-10-22 06:15:52 -07:00
self . wallet . interface . register_callback ( ' disconnecting ' , self . update_callback )
2012-04-07 06:13:18 -07:00
2012-10-11 11:10:12 -07:00
self . detailed_view = config . get ( ' qt_detailed_view ' , False )
2012-11-28 06:38:44 -08:00
self . qr_window = None
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 )
2012-05-18 06:28:55 -07:00
tabs . addTab ( self . create_history_tab ( ) , _ ( ' History ' ) )
2012-05-13 02:05:26 -07:00
if self . wallet . seed :
2012-05-18 06:28:55 -07:00
tabs . addTab ( self . create_send_tab ( ) , _ ( ' Send ' ) )
tabs . addTab ( self . create_receive_tab ( ) , _ ( ' Receive ' ) )
tabs . addTab ( self . create_contacts_tab ( ) , _ ( ' Contacts ' ) )
tabs . addTab ( self . create_wall_tab ( ) , _ ( ' Wall ' ) )
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-02-11 08:38:44 -08:00
self . create_status_bar ( )
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
2012-05-13 02:09:31 -07:00
if not self . wallet . seed : title + = ' [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
self . connect ( self , QtCore . SIGNAL ( ' updatesignal ' ) , self . update_wallet )
2012-11-28 06:38:44 -08:00
#self.connect(self, SIGNAL('editamount'), self.edit_amount)
2012-06-09 15:16:09 -07:00
self . history_list . setFocus ( True )
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 )
2012-11-28 12:14:12 -08:00
def close ( self ) :
QMainWindow . close ( self )
if self . qr_window :
self . qr_window . close ( )
self . qr_window = None
2012-02-12 00:52:26 -08:00
2012-02-11 13:19:22 -08:00
def connect_slots ( self , sender ) :
2012-05-13 02:05:26 -07:00
if self . wallet . seed :
self . connect ( sender , QtCore . SIGNAL ( ' timersignal ' ) , self . check_recipient )
self . previous_payto_e = ' '
2012-02-14 05:05:58 -08:00
def check_recipient ( self ) :
if self . payto_e . hasFocus ( ) :
return
2012-02-14 14:11:59 -08:00
r = unicode ( self . payto_e . text ( ) )
2012-02-14 05:05:58 -08:00
if r != self . previous_payto_e :
self . previous_payto_e = r
r = r . strip ( )
if re . match ( ' ^(|([ \ w \ - \ .]+)@)(( \ w[ \ w \ -]+ \ .)+[ \ w \ -]+)$ ' , r ) :
try :
2012-02-15 02:35:22 -08:00
to_address = self . wallet . get_alias ( r , True , self . show_message , self . question )
2012-02-14 05:05:58 -08:00
except :
return
if to_address :
2012-06-09 13:31:42 -07:00
s = r + ' < ' + to_address + ' > '
2012-02-14 05:05:58 -08:00
self . payto_e . setText ( s )
2012-02-11 13:19:22 -08:00
2012-02-12 00:52:26 -08:00
2012-04-07 06:13:18 -07:00
def update_callback ( self ) :
self . emit ( QtCore . SIGNAL ( ' updatesignal ' ) )
2012-02-11 13:19:22 -08:00
def update_wallet ( 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 :
2012-05-18 06:28:55 -07: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 :
c , u = self . wallet . get_balance ( )
2012-05-18 06:28:55 -07:00
text = _ ( " Balance " ) + " : %s " % ( format_satoshis ( c , False , self . wallet . num_zeros ) )
2012-05-02 08:40:39 -07:00
if u : text + = " [ %s unconfirmed] " % ( format_satoshis ( u , True , self . wallet . num_zeros ) . strip ( ) )
2012-02-14 02:33:09 -08:00
icon = QIcon ( " :icons/status_connected.png " )
2012-02-11 13:19:22 -08:00
else :
2012-05-18 06:28:55 -07: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
2012-02-14 05:34:19 -08:00
if self . funds_error :
2012-05-18 06:28:55 -07:00
text = _ ( " Not enough funds " )
2012-02-14 05:34:19 -08:00
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
2012-11-20 12:36:06 -08:00
if self . wallet . up_to_date or not self . wallet . interface . is_connected :
2012-03-23 08:34:34 -07:00
self . textbox . setText ( self . wallet . banner )
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
2012-02-11 04:14:12 -08:00
2012-02-11 08:02:28 -08:00
def create_history_tab ( self ) :
2012-06-09 13:23:56 -07:00
self . history_list = l = MyTreeWidget ( self )
2012-06-09 08:49:44 -07:00
l . setColumnCount ( 5 )
l . setColumnWidth ( 0 , 40 )
l . setColumnWidth ( 1 , 140 )
l . setColumnWidth ( 2 , 350 )
l . setColumnWidth ( 3 , 140 )
l . setColumnWidth ( 4 , 140 )
2012-10-27 23:49:15 -07: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
2012-06-10 12:32:07 -07:00
tx_hash = str ( item . toolTip ( 0 ) )
2012-11-16 05:39:31 -08:00
if not tx_hash : return
2012-06-09 08:49:44 -07:00
menu = QMenu ( )
2012-06-10 06:57:38 -07:00
menu . addAction ( _ ( " Copy ID to Clipboard " ) , lambda : self . app . clipboard ( ) . setText ( tx_hash ) )
menu . addAction ( _ ( " Details " ) , lambda : self . tx_details ( 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
2012-11-16 05:39:31 -08:00
def tx_details ( self , tx_hash ) :
tx_details = self . wallet . get_tx_details ( tx_hash )
2012-02-12 09:02:11 -08:00
QMessageBox . information ( self , ' Details ' , tx_details , ' OK ' )
2012-02-12 12:41:42 -08:00
def tx_label_clicked ( self , item , column ) :
if column == 2 and item . isSelected ( ) :
tx_hash = str ( item . toolTip ( 0 ) )
self . is_edit = True
#if not self.wallet.labels.get(tx_hash): item.setText(2,'')
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
tx_hash = str ( item . toolTip ( 0 ) )
2012-11-03 01:17:40 -07:00
tx = self . wallet . transactions . get ( tx_hash )
2012-02-12 12:41:42 -08:00
s = self . wallet . labels . get ( tx_hash )
2012-02-14 14:11:59 -08:00
text = unicode ( item . text ( 2 ) )
2012-02-12 15:00:33 -08:00
if text :
2012-02-12 12:41:42 -08:00
self . wallet . labels [ tx_hash ] = text
item . setForeground ( 2 , QBrush ( QColor ( ' black ' ) ) )
else :
if s : self . wallet . labels . pop ( tx_hash )
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
c = 2 if is_recv else 1
item = l . currentItem ( )
item . setFlags ( Qt . ItemIsEditable | Qt . ItemIsSelectable | Qt . ItemIsUserCheckable | Qt . ItemIsEnabled | Qt . ItemIsDragEnabled )
l . editItem ( item , c )
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 ( ) :
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 ) )
if label in self . wallet . aliases . keys ( ) :
2012-04-20 02:50:19 -07:00
return
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 ) )
changed = False
if text :
if text not in self . wallet . aliases . keys ( ) :
old_addr = self . wallet . labels . get ( text )
if old_addr != addr :
self . wallet . labels [ addr ] = text
changed = True
else :
print_error ( " Error: This is one of your aliases " )
label = self . wallet . labels . get ( addr , ' ' )
item . setText ( column_label , QString ( label ) )
2012-06-09 03:23:01 -07:00
else :
2012-11-28 06:38:44 -08:00
s = self . wallet . labels . get ( addr )
if s :
self . wallet . labels . pop ( addr )
changed = True
2012-10-16 22:18:48 -07:00
2012-11-28 06:38:44 -08:00
if changed :
self . update_history_tab ( )
self . update_completions ( )
self . recv_changed ( item )
def recv_changed ( self , a ) :
" current item changed "
2012-11-28 12:07:35 -08:00
if a is not None and self . qr_window and self . qr_window . isVisible ( ) :
2012-11-28 06:38:44 -08:00
address = str ( a . text ( 1 ) )
label = self . wallet . labels . get ( address )
amount = self . wallet . requested_amounts . get ( address )
self . qr_window . set_content ( address , label , amount )
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 ( )
2012-11-16 05:39:31 -08:00
for item in self . wallet . get_tx_history ( ) :
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 :
v_str = format_satoshis ( value , True , self . wallet . num_zeros )
else :
v_str = ' -- '
balance_str = format_satoshis ( balance , False , self . wallet . num_zeros )
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 ) )
2012-11-16 05:39:31 -08:00
if tx_hash :
item . setToolTip ( 0 , 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
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 )
2012-08-02 06:18:31 -07:00
def fill_from_qr ( ) :
qrcode = qrscanner . scan_qr ( )
if ' address ' in qrcode :
self . payto_e . setText ( qrcode [ ' address ' ] )
if ' amount ' in qrcode :
self . amount_e . setText ( str ( qrcode [ ' amount ' ] ) )
if ' label ' in qrcode :
self . message_e . setText ( qrcode [ ' label ' ] )
if ' message ' in qrcode :
self . message_e . setText ( " %s ( %s ) " % ( self . message_e . text ( ) , qrcode [ ' message ' ] ) )
if qrscanner . is_available ( ) :
b = QPushButton ( _ ( " Scan QR code " ) )
b . clicked . connect ( fill_from_qr )
grid . addWidget ( b , 1 , 5 )
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
2012-02-14 04:38:47 -08:00
self . amount_e = QLineEdit ( )
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 ' \
+ _ ( ' 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. ' ) ) , 3 , 3 )
2012-02-11 22:27:32 -08:00
2012-02-14 04:38:47 -08:00
self . fee_e = QLineEdit ( )
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 )
2012-05-18 06:28:55 -07:00
b = EnterButton ( _ ( " Send " ) , 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
amount = numbify ( self . amount_e )
fee = numbify ( self . fee_e )
if not is_fee : fee = None
if amount is None :
return
inputs , total , fee = self . wallet . choose_tx_inputs ( amount , fee )
if not is_fee :
self . fee_e . setText ( str ( Decimal ( fee ) / 100000000 ) )
if inputs :
palette = QPalette ( )
palette . setColor ( self . amount_e . foregroundRole ( ) , QColor ( ' black ' ) )
else :
palette = QPalette ( )
palette . setColor ( self . amount_e . foregroundRole ( ) , QColor ( ' red ' ) )
self . funds_error = True
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 ) )
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 + ' > ' )
l = l + self . wallet . aliases . keys ( )
self . completions . setStringList ( l )
2012-02-14 04:38:47 -08:00
def do_send ( self ) :
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
# alias
m1 = re . match ( ALIAS_REGEXP , r )
# label or alias, with address in brackets
m2 = re . match ( ' (.*?) \ s* \ <([1-9A-HJ-NP-Za-km-z] { 26,}) \ > ' , r )
2012-02-13 07:49:20 -08:00
if m1 :
2012-02-14 00:52:03 -08:00
to_address = self . wallet . get_alias ( r , True , self . show_message , self . question )
2012-02-13 07:49:20 -08:00
if not to_address :
return
elif m2 :
2012-06-09 03:23:01 -07:00
to_address = m2 . group ( 2 )
2012-02-13 07:49:20 -08:00
else :
to_address = r
if not self . wallet . 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 :
2012-02-14 14:11:59 -08:00
amount = int ( Decimal ( unicode ( self . amount_e . text ( ) ) ) * 100000000 )
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 :
2012-02-14 14:11:59 -08:00
fee = int ( Decimal ( unicode ( self . fee_e . text ( ) ) ) * 100000000 )
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
if self . wallet . use_encryption :
password = self . password_dialog ( )
if not password :
return
else :
password = None
try :
2012-06-16 09:45:17 -07:00
tx = self . wallet . mktx ( to_address , amount , label , password , fee )
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
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 )
2012-02-13 07:49:20 -08:00
if status :
2012-05-18 06:28:55 -07:00
QMessageBox . information ( self , ' ' , _ ( ' Payment sent. ' ) + ' \n ' + msg , _ ( ' OK ' ) )
2012-02-14 04:38:47 -08:00
self . do_clear ( )
2012-02-13 07:49:20 -08:00
self . update_contacts_tab ( )
else :
2012-05-18 06:28:55 -07:00
QMessageBox . warning ( self , _ ( ' Error ' ) , msg , _ ( ' OK ' ) )
2012-02-13 07:49:20 -08:00
2012-02-14 04:38:47 -08:00
def set_url ( self , url ) :
2012-02-14 04:49:05 -08:00
payto , amount , label , message , signature , identity , url = self . wallet . parse_url ( url , self . show_message , self . question )
2012-02-14 04:38:47 -08:00
self . tabs . setCurrentIndex ( 1 )
2012-06-09 03:23:01 -07:00
label = self . wallet . labels . get ( payto )
2012-06-09 13:31:42 -07:00
m_addr = label + ' < ' + payto + ' > ' if label else payto
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 ) :
2012-11-28 06:38:44 -08:00
l , w , hbox = self . create_list_tab ( [ _ ( ' Flags ' ) , _ ( ' Address ' ) , _ ( ' Label ' ) , _ ( ' Requested ' ) , _ ( ' Balance ' ) , _ ( ' Tx ' ) ] )
2012-06-07 08:36:39 -07:00
l . setContextMenuPolicy ( Qt . CustomContextMenu )
l . customContextMenuRequested . connect ( self . create_receive_menu )
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 , 1 , 2 ) )
self . connect ( l , SIGNAL ( ' itemChanged(QTreeWidgetItem*, int) ' ) , lambda a , b : self . address_label_changed ( a , b , l , 1 , 2 ) )
2012-11-28 06:38:44 -08:00
self . connect ( l , SIGNAL ( ' currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*) ' ) , lambda a , b : self . recv_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-11-28 06:38:44 -08:00
self . qr_button = EnterButton ( self . qr_button_text ( ) , self . toggle_QR_window )
hbox . addWidget ( self . qr_button )
self . print_button = EnterButton ( _ ( " Print QR " ) , self . print_qr )
self . print_button . setHidden ( True )
hbox . addWidget ( self . print_button )
2012-10-11 03:56:57 -07:00
self . details_button = EnterButton ( self . details_button_text ( ) , self . toggle_detailed_view )
hbox . addWidget ( self . details_button )
hbox . addStretch ( 1 )
2012-02-12 15:00:33 -08:00
return w
2012-11-28 06:38:44 -08:00
def print_qr ( self ) :
if self . qr_window :
self . qr_window . do_save ( )
self . show_message ( _ ( " QR code saved to file " ) + " " + self . qr_window . filename )
def request_amount_dialog ( self , address ) :
# pick the first unused address
# print "please wait" in qr window
# enter amount in usd
d = QDialog ( )
d . setWindowTitle ( ' Request payment ' )
2012-11-28 13:52:35 -08:00
d . setModal ( 1 )
2012-11-28 06:38:44 -08:00
vbox = QVBoxLayout ( )
vbox . addWidget ( QLabel ( address ) )
grid = QGridLayout ( )
grid . setSpacing ( 8 )
vbox . addLayout ( grid )
try :
index = self . wallet . addresses . index ( address )
except :
return
label = self . wallet . labels . get ( address , ' invoice %04d ' % ( index + 1 ) )
grid . addWidget ( QLabel ( _ ( ' Label ' ) ) , 0 , 0 )
label_e = QLineEdit ( )
label_e . setText ( label )
grid . addWidget ( label_e , 0 , 1 )
amount_e = QLineEdit ( )
amount_e . textChanged . connect ( lambda : numbify ( amount_e ) )
grid . addWidget ( QLabel ( _ ( ' Amount ' ) ) , 1 , 0 )
grid . addWidget ( amount_e , 1 , 1 , 1 , 3 )
vbox . addLayout ( ok_cancel_buttons ( d ) )
d . setLayout ( vbox )
amount_e . setFocus ( )
if not d . exec_ ( ) : return
try :
amount = int ( Decimal ( unicode ( amount_e . text ( ) ) ) * 100000000 )
except :
return
self . wallet . requested_amounts [ address ] = amount
label = unicode ( label_e . text ( ) )
if label :
self . wallet . labels [ address ] = label
self . update_receive_item ( self . receive_list . currentItem ( ) )
if self . qr_window :
self . qr_window . set_content ( address , label , amount )
2012-11-28 13:52:35 -08:00
2012-11-28 06:38:44 -08:00
2012-10-11 03:56:57 -07:00
def details_button_text ( self ) :
2012-10-11 11:10:12 -07:00
return _ ( ' Hide details ' ) if self . detailed_view else _ ( ' Show details ' )
2012-10-11 03:56:57 -07:00
2012-11-28 06:38:44 -08:00
def qr_button_text ( self ) :
2012-11-28 10:05:58 -08:00
return _ ( ' Hide QR ' ) if self . qr_window and self . qr_window . isVisible ( ) else _ ( ' Show QR ' )
2012-11-28 06:38:44 -08:00
2012-10-11 03:56:57 -07:00
def toggle_detailed_view ( self ) :
2012-10-11 11:10:12 -07:00
self . detailed_view = not self . detailed_view
self . config . set_key ( ' qt_detailed_view ' , self . detailed_view , True )
2012-10-11 03:56:57 -07:00
self . details_button . setText ( self . details_button_text ( ) )
self . wallet . save ( )
self . update_receive_tab ( )
self . update_contacts_tab ( )
2012-06-07 08:36:39 -07: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 )
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
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
2012-06-09 14:58:20 -07:00
addr = unicode ( item . text ( 1 ) )
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 ) )
if self . qr_window and self . qr_window . isVisible ( ) :
menu . addAction ( _ ( " Request amount " ) , lambda : self . request_amount_dialog ( addr ) )
2012-06-09 08:18:53 -07:00
menu . addAction ( _ ( " Edit label " ) , lambda : self . edit_label ( True ) )
2012-11-24 23:28:10 -08:00
menu . addAction ( _ ( " Sign message " ) , lambda : self . sign_message ( addr ) )
2012-10-11 11:10:12 -07: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 ) )
2012-06-07 08:36:39 -07:00
menu . exec_ ( self . receive_list . viewport ( ) . mapToGlobal ( position ) )
2012-06-09 23:33:34 -07:00
def payto ( self , x , is_alias ) :
if not x : return
if is_alias :
label = x
2012-06-12 02:43:05 -07:00
m_addr = label
2012-06-09 23:33:34 -07:00
else :
addr = x
label = self . wallet . labels . get ( addr )
2012-06-12 02:43:05 -07:00
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 ( )
2012-06-09 23:33:34 -07:00
def delete_contact ( self , x , is_alias ) :
if self . question ( " Do you want to remove %s from your list of contacts? " % x ) :
if not is_alias and x in self . wallet . addressbook :
self . wallet . addressbook . remove ( x )
if x in self . wallet . labels . keys ( ) :
self . wallet . labels . pop ( x )
elif is_alias and x in self . wallet . aliases :
self . wallet . aliases . pop ( x )
2012-06-09 08:18:53 -07:00
self . update_history_tab ( )
self . update_contacts_tab ( )
self . update_completions ( )
2012-06-07 08:36:39 -07:00
def create_contact_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.contacts_list.selectedIndexes()
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 ) )
is_alias = label in self . wallet . aliases . keys ( )
x = label if is_alias else addr
2012-06-07 08:36:39 -07:00
menu = QMenu ( )
menu . addAction ( _ ( " Copy to Clipboard " ) , lambda : self . app . clipboard ( ) . setText ( addr ) )
2012-06-10 06:59:36 -07:00
menu . addAction ( _ ( " Pay to " ) , lambda : self . payto ( x , is_alias ) )
2012-06-07 08:54:40 -07:00
menu . addAction ( _ ( " View QR code " ) , lambda : self . show_address_qrcode ( addr ) )
2012-06-09 23:33:34 -07:00
if not is_alias :
2012-06-09 08:18:53 -07:00
menu . addAction ( _ ( " Edit label " ) , lambda : self . edit_label ( False ) )
2012-06-09 08:32:52 -07:00
else :
2012-06-09 14:52:45 -07:00
menu . addAction ( _ ( " View alias details " ) , lambda : self . show_contact_details ( label ) )
2012-06-09 23:33:34 -07:00
menu . addAction ( _ ( " Delete " ) , lambda : self . delete_contact ( x , is_alias ) )
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 ) :
address = str ( item . data ( 1 , 0 ) . toString ( ) )
flags = self . wallet . get_address_flags ( address )
item . setData ( 0 , 0 , flags )
label = self . wallet . labels . get ( address , ' ' )
item . setData ( 2 , 0 , label )
2012-11-28 13:52:35 -08:00
amount = self . wallet . requested_amounts . get ( address , None )
amount_str = format_satoshis ( amount , False , self . wallet . num_zeros ) if amount is not None else " -- "
2012-11-28 06:38:44 -08:00
item . setData ( 3 , 0 , amount_str )
c , u = self . wallet . get_addr_balance ( address )
balance = format_satoshis ( c + u , False , self . wallet . num_zeros )
item . setData ( 4 , 0 , balance )
if address in self . wallet . frozen_addresses :
item . setBackgroundColor ( 1 , QColor ( ' lightblue ' ) )
elif address in self . wallet . prioritized_addresses :
item . setBackgroundColor ( 1 , QColor ( ' lightgreen ' ) )
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 ( )
2012-11-28 06:38:44 -08:00
l . setColumnHidden ( 0 , not self . detailed_view )
2012-11-28 10:05:58 -08:00
l . setColumnHidden ( 3 , self . qr_window is None or not self . qr_window . isVisible ( ) )
2012-11-28 06:38:44 -08:00
l . setColumnHidden ( 4 , not self . detailed_view )
l . setColumnHidden ( 5 , not self . detailed_view )
l . setColumnWidth ( 0 , 50 )
2012-06-07 07:07:49 -07:00
l . setColumnWidth ( 1 , 310 )
2012-11-28 06:38:44 -08:00
l . setColumnWidth ( 2 , 200 )
l . setColumnWidth ( 3 , 130 )
l . setColumnWidth ( 4 , 130 )
l . setColumnWidth ( 5 , 10 )
2012-06-07 08:36:39 -07:00
2012-06-06 06:20:20 -07:00
gap = 0
2012-06-06 07:08:29 -07:00
is_red = False
2012-02-11 22:45:18 -08:00
for address in self . wallet . all_addresses ( ) :
2012-06-07 07:07:49 -07:00
2012-10-11 11:10:12 -07:00
if self . wallet . is_change ( address ) and not self . detailed_view :
2012-06-07 07:07:49 -07:00
continue
2012-06-06 05:55:11 -07:00
2012-02-11 22:45:18 -08:00
n = 0
h = self . wallet . history . get ( address , [ ] )
2012-11-14 06:33:44 -08:00
2012-11-15 00:14:24 -08:00
if h != [ ' * ' ] :
for tx_hash , tx_height in h :
tx = self . wallet . transactions . get ( tx_hash )
if tx : n + = 1
num_tx = " %d " % n
else :
n = - 1
num_tx = " * "
2012-06-06 06:20:20 -07:00
if n == 0 :
2012-06-06 07:52:39 -07:00
if address in self . wallet . addresses :
2012-06-06 06:20:20 -07:00
gap + = 1
2012-06-06 07:08:29 -07:00
if gap > self . wallet . gap_limit :
is_red = True
2012-06-06 06:20:20 -07:00
else :
2012-06-06 07:52:39 -07:00
if address in self . wallet . addresses :
2012-06-06 06:20:20 -07:00
gap = 0
2012-05-05 02:33:53 -07:00
2012-11-28 06:38:44 -08:00
item = QTreeWidgetItem ( [ ' ' , address , ' ' , ' ' , ' ' , num_tx ] )
2012-06-07 07:14:08 -07:00
item . setFont ( 0 , QFont ( MONOSPACE_FONT ) )
2012-06-07 07:07:49 -07:00
item . setFont ( 1 , QFont ( MONOSPACE_FONT ) )
2012-06-10 07:04:27 -07:00
item . setFont ( 3 , QFont ( MONOSPACE_FONT ) )
2012-11-28 06:38:44 -08:00
self . update_receive_item ( item )
2012-06-06 07:52:39 -07:00
if is_red and address in self . wallet . addresses :
2012-06-07 07:07:49 -07:00
item . setBackgroundColor ( 1 , QColor ( ' red ' ) )
2012-06-09 14:26:41 -07:00
l . addTopLevelItem ( item )
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-06-09 14:52:45 -07:00
def show_contact_details ( self , m ) :
2012-02-12 12:41:42 -08:00
a = self . wallet . aliases . get ( m )
if a :
if a [ 0 ] in self . wallet . authorities . keys ( ) :
s = self . wallet . authorities . get ( a [ 0 ] )
else :
s = " self-signed "
msg = ' Alias: ' + m + ' \n Target address: ' + a [ 1 ] + ' \n \n Signed by: ' + s + ' \n Signing address: ' + a [ 0 ]
QMessageBox . information ( self , ' Alias ' , msg , ' OK ' )
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-10-11 11:10:12 -07:00
l . setColumnHidden ( 2 , not self . detailed_view )
2012-06-07 08:36:39 -07:00
l . setColumnWidth ( 0 , 350 )
l . setColumnWidth ( 1 , 330 )
l . setColumnWidth ( 2 , 100 )
2012-05-05 02:51:06 -07:00
2012-06-09 03:23:01 -07:00
alias_targets = [ ]
2012-02-11 22:45:18 -08:00
for alias , v in self . wallet . aliases . items ( ) :
s , target = v
2012-06-09 03:23:01 -07:00
alias_targets . append ( target )
2012-04-20 02:50:19 -07:00
item = QTreeWidgetItem ( [ target , alias , ' - ' ] )
2012-06-10 08:53:41 -07:00
item . setBackgroundColor ( 0 , QColor ( ' lightgray ' ) )
2012-06-09 14:26:41 -07:00
l . addTopLevelItem ( item )
2012-02-11 22:45:18 -08:00
for address in self . wallet . addressbook :
2012-06-09 03:23:01 -07:00
if address in alias_targets : continue
2012-02-11 22:45:18 -08:00
label = self . wallet . labels . get ( address , ' ' )
n = 0
2012-11-03 01:17:40 -07:00
for item in self . wallet . transactions . values ( ) :
2012-02-11 22:45:18 -08:00
if address in item [ ' outputs ' ] : n = n + 1
2012-06-16 09:24:36 -07:00
tx = " %d " % n
2012-02-11 22:45:18 -08:00
item = QTreeWidgetItem ( [ address , label , tx ] )
2012-03-30 14:44:54 -07:00
item . setFont ( 0 , QFont ( MONOSPACE_FONT ) )
2012-06-09 14:26:41 -07:00
l . addTopLevelItem ( item )
2012-02-11 22:45:18 -08:00
2012-06-09 14:26:41 -07:00
l . setCurrentItem ( l . topLevelItem ( 0 ) )
2012-02-11 22:45:18 -08:00
2012-02-11 08:02:28 -08:00
def create_wall_tab ( self ) :
2012-02-11 13:19:22 -08:00
self . textbox = textbox = QTextEdit ( self )
2012-03-30 14:44:54 -07:00
textbox . setFont ( QFont ( MONOSPACE_FONT ) )
2012-02-11 13:19:22 -08:00
textbox . setReadOnly ( True )
return textbox
2012-02-11 08:02:28 -08:00
2012-02-11 08:38:44 -08:00
def create_status_bar ( self ) :
sb = QStatusBar ( )
2012-02-12 08:19:16 -08:00
sb . setFixedHeight ( 35 )
2012-05-13 01:54:03 -07:00
if self . wallet . seed :
sb . addPermanentWidget ( StatusBarButton ( QIcon ( " :icons/lock.png " ) , " Password " , lambda : self . change_password_dialog ( self . wallet , self ) ) )
2012-02-14 02:33:09 -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 :
sb . addPermanentWidget ( StatusBarButton ( QIcon ( " :icons/seed.png " ) , " Seed " , lambda : self . show_seed_dialog ( self . wallet , self ) ) )
2012-02-14 02:33:09 -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 )
2012-02-11 08:38:44 -08:00
self . setStatusBar ( sb )
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 :
if self . wallet . is_valid ( address ) :
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
2012-02-14 00:52:03 -08:00
@staticmethod
def show_seed_dialog ( wallet , parent = None ) :
2012-05-12 15:43:22 -07:00
if not wallet . seed :
2012-08-16 15:31:46 -07:00
QMessageBox . information ( parent , _ ( ' Message ' ) ,
_ ( ' No seed ' ) , _ ( ' OK ' ) )
2012-05-12 15:43:22 -07:00
return
2012-02-14 00:52:03 -08:00
if wallet . use_encryption :
2012-02-14 02:10:06 -08:00
password = parent . password_dialog ( )
2012-08-16 15:31:46 -07:00
if not password :
return
2012-02-13 06:11:31 -08:00
else :
password = None
try :
2012-08-16 15:31:46 -07:00
seed = wallet . pw_decode ( wallet . seed , password )
2012-02-13 06:11:31 -08:00
except :
2012-08-16 15:31:46 -07:00
QMessageBox . warning ( parent , _ ( ' Error ' ) ,
_ ( ' Incorrect Password ' ) , _ ( ' OK ' ) )
2012-02-13 06:11:31 -08:00
return
2012-02-12 15:00:33 -08:00
2012-08-16 15:31:46 -07:00
dialog = QDialog ( None )
dialog . setModal ( 1 )
2012-10-22 08:36:52 -07:00
dialog . setWindowTitle ( " Electrum " )
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
2012-10-02 04:41:38 -07:00
msg = _ ( " Your wallet generation seed is " ) + " :<p> \" " + brainwallet + " \" <p> " \
+ _ ( " Please write down or memorize these 12 words (order is important). " ) + " " \
+ _ ( " This seed will allow you to recover your wallet in case of computer failure. " ) + " <p> " \
+ _ ( " WARNING: Never disclose your seed. Never type it on a website. " ) + " <p> "
2012-08-16 15:31:46 -07:00
main_text = QLabel ( msg )
main_text . 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 ) )
2012-05-05 07:42:42 -07:00
if parent :
app = parent . app
else :
app = QApplication
2012-08-16 15:31:46 -07:00
copy_function = lambda : app . clipboard ( ) . setText ( brainwallet )
copy_button = QPushButton ( _ ( " Copy to Clipboard " ) )
copy_button . clicked . connect ( copy_function )
2012-05-05 07:42:42 -07:00
2012-08-16 15:31:46 -07:00
show_qr_function = lambda : ElectrumWindow . show_seed_qrcode ( seed )
qr_button = QPushButton ( _ ( " View as QR Code " ) )
qr_button . clicked . connect ( show_qr_function )
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 )
main_layout = QGridLayout ( )
main_layout . addWidget ( logo , 0 , 0 )
main_layout . addWidget ( main_text , 0 , 1 , 1 , - 1 )
main_layout . addWidget ( copy_button , 1 , 1 )
main_layout . addWidget ( qr_button , 1 , 2 )
main_layout . addWidget ( ok_button , 1 , 3 )
dialog . setLayout ( main_layout )
dialog . exec_ ( )
2012-02-13 06:11:31 -08:00
2012-04-09 12:02:59 -07:00
@staticmethod
2012-05-01 08:06:14 -07:00
def show_seed_qrcode ( seed ) :
if not seed : return
d = QDialog ( None )
d . setModal ( 1 )
2012-05-18 06:28:55 -07:00
d . setWindowTitle ( _ ( " Seed " ) )
2012-05-01 08:06:14 -07:00
d . setMinimumSize ( 270 , 300 )
vbox = QVBoxLayout ( )
vbox . addWidget ( QRCodeWidget ( seed ) )
hbox = QHBoxLayout ( )
hbox . addStretch ( 1 )
2012-05-18 06:28:55 -07:00
b = QPushButton ( _ ( " OK " ) )
2012-05-01 08:06:14 -07:00
hbox . addWidget ( b )
b . clicked . connect ( d . accept )
vbox . addLayout ( hbox )
d . setLayout ( vbox )
d . exec_ ( )
2012-11-24 23:28:10 -08:00
def sign_message ( self , address ) :
if not address : return
d = QDialog ( self )
d . setModal ( 1 )
d . setWindowTitle ( ' Sign Message ' )
d . setMinimumSize ( 270 , 350 )
tab_widget = QTabWidget ( )
tab = QWidget ( )
layout = QGridLayout ( tab )
sign_address = QLineEdit ( )
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 )
layout . addWidget ( sign_message , 2 , 1 , 2 , 1 )
sign_signature = QLineEdit ( )
layout . addWidget ( QLabel ( _ ( ' Signature ' ) ) , 3 , 0 )
layout . addWidget ( sign_signature , 3 , 1 )
def do_sign ( ) :
if self . wallet . use_encryption :
password = self . password_dialog ( )
if not password :
return
else :
password = None
try :
signature = self . wallet . sign_message ( sign_address . text ( ) , sign_message . toPlainText ( ) , password )
sign_signature . setText ( signature )
except BaseException , e :
self . show_message ( str ( e ) )
return
hbox = QHBoxLayout ( )
b = QPushButton ( _ ( " Sign " ) )
hbox . addWidget ( b )
b . clicked . connect ( do_sign )
b = QPushButton ( _ ( " Close " ) )
b . clicked . connect ( d . accept )
hbox . addWidget ( b )
layout . addLayout ( hbox , 4 , 1 )
tab_widget . addTab ( tab , " Sign " )
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 )
layout . addWidget ( verify_message , 2 , 1 , 2 , 1 )
verify_signature = QLineEdit ( )
layout . addWidget ( QLabel ( _ ( ' Signature ' ) ) , 3 , 0 )
layout . addWidget ( verify_signature , 3 , 1 )
def do_verify ( ) :
try :
self . wallet . verify_message ( verify_address . text ( ) , verify_signature . text ( ) , verify_message . toPlainText ( ) )
self . show_message ( " Signature verified " )
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 )
tab_widget . addTab ( tab , " Verify " )
vbox = QVBoxLayout ( )
vbox . addWidget ( tab_widget )
d . setLayout ( vbox )
d . exec_ ( )
2012-11-28 06:38:44 -08:00
def toggle_QR_window ( self ) :
2012-11-28 10:05:58 -08:00
if not self . qr_window :
2012-11-28 06:38:44 -08:00
self . qr_window = QR_Window ( )
2012-11-28 10:05:58 -08:00
self . qr_window . setVisible ( True )
#print self.qr_window.isVisible()
self . qr_window_geometry = self . qr_window . geometry ( )
2012-11-28 06:38:44 -08:00
item = self . receive_list . currentItem ( )
if item :
address = str ( item . text ( 1 ) )
label = self . wallet . labels . get ( address )
amount = self . wallet . requested_amounts . get ( address )
self . qr_window . set_content ( address , label , amount )
2012-11-28 10:05:58 -08:00
self . update_receive_tab ( )
else :
if self . qr_window . isVisible ( ) :
self . qr_window_geometry = self . qr_window . geometry ( )
self . qr_window . setVisible ( False )
else :
self . qr_window . setVisible ( True )
self . qr_window . setGeometry ( self . qr_window_geometry )
2012-11-28 06:38:44 -08:00
self . qr_button . setText ( self . qr_button_text ( ) )
2012-11-28 10:05:58 -08:00
self . print_button . setHidden ( self . qr_window is None or not self . qr_window . isVisible ( ) )
self . receive_list . setColumnHidden ( 3 , self . qr_window is None or not self . qr_window . isVisible ( ) )
self . receive_list . setColumnWidth ( 2 , 200 )
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 ) )
2012-02-13 10:02:48 -08:00
d . setLayout ( vbox )
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 :
2012-02-14 00:52:03 -08:00
seed = wallet . pw_decode ( wallet . 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-02-13 05:52:59 -08:00
return
2012-05-16 23:32:49 -07:00
wallet . update_password ( seed , password , new_password )
2012-02-14 00:52:03 -08:00
@staticmethod
def seed_dialog ( wallet , parent = None ) :
d = QDialog ( parent )
d . setModal ( 1 )
vbox = QVBoxLayout ( )
2012-05-18 06:28:55 -07:00
msg = _ ( " Please enter your wallet seed or the corresponding mnemonic list of words, and the gap limit of your wallet. " )
2012-02-14 00:52:03 -08:00
vbox . addWidget ( QLabel ( msg ) )
grid = QGridLayout ( )
grid . setSpacing ( 8 )
seed_e = QLineEdit ( )
2012-05-18 06:28:55 -07:00
grid . addWidget ( QLabel ( _ ( ' Seed or mnemonic ' ) ) , 1 , 0 )
2012-02-14 00:52:03 -08:00
grid . addWidget ( seed_e , 1 , 1 )
gap_e = QLineEdit ( )
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 )
2012-02-14 05:34:19 -08:00
gap_e . textChanged . connect ( lambda : numbify ( gap_e , True ) )
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 ' )
2012-03-23 11:17:44 -07:00
sys . exit ( 0 )
2012-02-14 00:52:03 -08:00
try :
2012-02-14 14:11:59 -08:00
seed = unicode ( 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 ' ) )
2012-03-23 11:32:16 -07:00
sys . exit ( 0 )
2012-02-14 00:52:03 -08:00
if not seed :
2012-05-18 06:28:55 -07:00
QMessageBox . warning ( None , _ ( ' Error ' ) , _ ( ' No seed ' ) , ' OK ' )
2012-03-23 11:17:44 -07:00
sys . exit ( 0 )
2012-02-14 00:52:03 -08:00
2012-03-14 10:00:24 -07:00
wallet . seed = str ( seed )
#print repr(wallet.seed)
2012-02-14 00:52:03 -08:00
wallet . gap_limit = gap
return True
2012-06-07 08:42:50 -07:00
2012-06-07 07:07:49 -07:00
2012-02-13 06:22:15 -08:00
def settings_dialog ( self ) :
d = QDialog ( self )
d . setModal ( 1 )
2012-02-13 10:02:48 -08:00
vbox = QVBoxLayout ( )
2012-06-12 04:21:01 -07:00
msg = _ ( ' Here are the settings of your wallet. ' ) + ' \n ' \
+ _ ( ' For more explanations, click on the help buttons next to each field. ' )
2012-02-13 06:22:15 -08:00
2012-06-12 04:21:01 -07:00
label = QLabel ( msg )
label . setFixedWidth ( 250 )
label . setWordWrap ( True )
label . setAlignment ( Qt . AlignJustify )
vbox . addWidget ( label )
2012-02-13 10:02:48 -08:00
grid = QGridLayout ( )
grid . setSpacing ( 8 )
2012-05-02 08:40:39 -07:00
vbox . addLayout ( grid )
2012-02-13 06:22:15 -08:00
2012-10-12 09:01:35 -07:00
fee_label = QLabel ( _ ( ' Transaction fee ' ) )
grid . addWidget ( fee_label , 2 , 0 )
2012-02-14 05:34:19 -08:00
fee_e = QLineEdit ( )
fee_e . setText ( " %s " % str ( Decimal ( self . wallet . fee ) / 100000000 ) )
grid . addWidget ( fee_e , 2 , 1 )
2012-06-23 04:30:58 -07:00
msg = _ ( ' Fee per transaction input. Transactions involving multiple inputs tend to require a higher fee. ' ) + ' ' \
+ _ ( ' Recommended value ' ) + ' : 0.001 '
2012-06-23 04:58:32 -07:00
grid . addWidget ( HelpButton ( msg ) , 2 , 2 )
2012-02-14 05:34:19 -08:00
fee_e . textChanged . connect ( lambda : numbify ( fee_e , False ) )
2012-10-12 09:01:35 -07:00
if not self . config . is_modifiable ( ' fee ' ) :
for w in [ fee_e , fee_label ] : w . setEnabled ( False )
2012-02-13 06:22:15 -08:00
2012-10-12 09:01:35 -07:00
nz_label = QLabel ( _ ( ' Display zeros ' ) )
grid . addWidget ( nz_label , 3 , 0 )
2012-05-02 08:40:39 -07:00
nz_e = QLineEdit ( )
nz_e . setText ( " %d " % self . wallet . num_zeros )
2012-10-12 09:01:35 -07:00
grid . addWidget ( nz_e , 3 , 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 " ' )
grid . addWidget ( HelpButton ( msg ) , 3 , 2 )
2012-05-02 08:40:39 -07:00
nz_e . textChanged . connect ( lambda : numbify ( nz_e , True ) )
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-05-02 08:40:39 -07:00
2012-10-11 03:56:57 -07:00
usechange_cb = QCheckBox ( _ ( ' Use change addresses ' ) )
grid . addWidget ( usechange_cb , 5 , 0 )
usechange_cb . setChecked ( self . wallet . use_change )
2012-10-12 00:41:49 -07:00
grid . addWidget ( HelpButton ( _ ( ' Using change addresses makes it more difficult for other people to track your transactions. ' ) ) , 5 , 2 )
2012-10-12 08:40:37 -07:00
if not self . config . is_modifiable ( ' use_change ' ) : usechange_cb . setEnabled ( False )
2012-10-11 03:56:57 -07:00
2012-10-12 09:01:35 -07:00
gap_label = QLabel ( _ ( ' Gap limit ' ) )
grid . addWidget ( gap_label , 6 , 0 )
gap_e = QLineEdit ( )
gap_e . setText ( " %d " % self . wallet . gap_limit )
grid . addWidget ( gap_e , 6 , 1 )
2012-10-11 03:56:57 -07: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 ' \
+ _ ( ' Given the current status of your address sequence, the minimum gap limit you can use is: ' ) + ' %d ' % self . wallet . min_acceptable_gap ( ) + ' \n \n ' \
+ _ ( ' 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 '
grid . addWidget ( HelpButton ( msg ) , 6 , 2 )
gap_e . textChanged . connect ( lambda : numbify ( nz_e , True ) )
2012-10-12 09:01:35 -07:00
if not self . config . is_modifiable ( ' gap_limit ' ) :
for w in [ gap_e , gap_label ] : w . setEnabled ( False )
2012-10-11 03:56:57 -07:00
2012-10-12 09:01:35 -07:00
gui_label = QLabel ( _ ( ' Default GUI ' ) + ' : ' )
grid . addWidget ( gui_label , 7 , 0 )
2012-10-12 08:40:37 -07:00
gui_combo = QComboBox ( )
2012-10-30 10:36:09 -07:00
gui_combo . addItems ( [ ' Lite ' , ' Classic ' , ' Gtk ' , ' Text ' ] )
2012-10-26 16:19:27 -07:00
index = gui_combo . findText ( self . config . get ( " gui " , " classic " ) . capitalize ( ) )
if index == - 1 : index = 1
gui_combo . setCurrentIndex ( index )
2012-10-12 08:40:37 -07:00
grid . addWidget ( gui_combo , 7 , 1 )
2012-10-11 03:56:57 -07:00
grid . addWidget ( HelpButton ( _ ( ' Select which GUI mode to use at start up. ' ) ) , 7 , 2 )
2012-10-12 09:01:35 -07:00
if not self . config . is_modifiable ( ' gui ' ) :
for w in [ gui_combo , gui_label ] : w . setEnabled ( False )
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 :
fee = int ( 100000000 * Decimal ( fee ) )
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
2012-10-12 08:40:37 -07:00
if self . wallet . use_change != usechange_cb . isChecked ( ) :
self . wallet . use_change = usechange_cb . isChecked ( )
self . config . set_key ( ' use_change ' , self . wallet . use_change , True )
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 ' ) )
2012-09-20 18:47:56 -07:00
2012-10-12 08:40:37 -07:00
self . config . set_key ( " gui " , str ( gui_combo . currentText ( ) ) . lower ( ) , True )
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 :
2012-10-25 15:40:19 -07:00
status = _ ( " Connected to " ) + " %s \n %d blocks " % ( interface . host , wallet . verifier . height )
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
protocol_names = [ ' TCP ' , ' HTTP ' , ' TCP/SSL ' , ' HTTPS ' ]
protocol_letters = ' thsg '
2012-11-01 03:43:59 -07:00
DEFAULT_PORTS = { ' t ' : ' 50001 ' , ' s ' : ' 50002 ' , ' h ' : ' 8081 ' , ' g ' : ' 8082 ' }
2012-10-18 11:29:53 -07:00
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 )
2012-11-20 04:33:36 -08:00
servers_list_widget . setHeaderLabels ( [ label , _ ( ' Type ' ) ] )
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 ( ) :
_type = ' pruning ' if servers_list [ _host ] . get ( ' pruning ' ) else ' full '
servers_list_widget . addTopLevelItem ( QTreeWidgetItem ( [ _host , _type ] ) )
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 :
2012-11-01 03:43:59 -07:00
if ' t ' in pp . keys ( ) :
2012-10-19 01:41:20 -07:00
protocol = ' t '
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 )
if p not in pp . keys ( ) :
server_protocol . model ( ) . setData ( j , QtCore . QVariant ( 0 ) , QtCore . Qt . UserRole - 1 )
else :
server_protocol . model ( ) . setData ( j , QtCore . QVariant ( 0 , False ) , QtCore . Qt . UserRole - 1 )
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 )
2012-10-19 01:41:20 -07:00
servers_list_widget . connect ( servers_list_widget , SIGNAL ( ' itemClicked(QTreeWidgetItem*, int) ' ) , lambda x : 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 )
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 )
2012-10-02 03:52:47 -07:00
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 )
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 ) :
ElectrumWindow . show_seed_dialog ( self . wallet )
def password_dialog ( self ) :
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 :
waiting = lambda : False if wallet . interface . is_connected else " connecting... \n "
waiting_dialog ( waiting )
2012-11-20 12:36:06 -08:00
waiting = lambda : False if wallet . is_up_to_date ( ) else " Please wait... \n Addresses generated: %d \n Kilobytes received: %.1f " \
2012-10-13 23:25:09 -07:00
% ( len ( wallet . all_addresses ( ) ) , wallet . interface . bytes_received / 1024. )
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_ ( )