<s> import sys <EOL> try : <EOL> from PyQt4 . QtCore import * <EOL> from PyQt4 . QtGui import * <EOL> from PyQt4 . Qt import Qt <EOL> import PyQt4 . QtCore as QtCore <EOL> except ImportError : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> from decimal import Decimal as D <EOL> from electrum . util import get_resource_path as rsrc <EOL> from electrum . bitcoin import is_valid <EOL> from electrum . i18n import _ <EOL> import decimal <EOL> import json <EOL> import os . path <EOL> import random <EOL> import re <EOL> import time <EOL> from electrum . wallet import Wallet , WalletStorage <EOL> import webbrowser <EOL> import history_widget <EOL> import receiving_widget <EOL> from electrum import util <EOL> import csv <EOL> import datetime <EOL> from electrum . version import ELECTRUM_VERSION as electrum_version <EOL> from electrum . util import format_satoshis , age <EOL> from main_window import ElectrumWindow <EOL> import shutil <EOL> from util import * <EOL> bitcoin = lambda v : v * <NUM_LIT> <EOL> def IconButton ( filename , parent = None ) : <EOL> pixmap = QPixmap ( filename ) <EOL> icon = QIcon ( pixmap ) <EOL> return QPushButton ( icon , "<STR_LIT>" , parent ) <EOL> class Timer ( QThread ) : <EOL> def run ( self ) : <EOL> while True : <EOL> self . emit ( SIGNAL ( '<STR_LIT>' ) ) <EOL> time . sleep ( <NUM_LIT:0.5> ) <EOL> def resize_line_edit_width ( line_edit , text_input ) : <EOL> metrics = QFontMetrics ( qApp . font ( ) ) <EOL> text_input += "<STR_LIT:A>" <EOL> line_edit . setMinimumWidth ( metrics . width ( text_input ) ) <EOL> def load_theme_name ( theme_path ) : <EOL> try : <EOL> with open ( os . path . join ( theme_path , "<STR_LIT>" ) ) as name_cfg_file : <EOL> return name_cfg_file . read ( ) . rstrip ( "<STR_LIT:\n>" ) . strip ( ) <EOL> except IOError : <EOL> return None <EOL> def theme_dirs_from_prefix ( prefix ) : <EOL> if not os . path . exists ( prefix ) : <EOL> return [ ] <EOL> theme_paths = { } <EOL> for potential_theme in os . listdir ( prefix ) : <EOL> theme_full_path = os . path . join ( prefix , potential_theme ) <EOL> theme_css = os . path . join ( theme_full_path , "<STR_LIT>" ) <EOL> if not os . path . exists ( theme_css ) : <EOL> continue <EOL> theme_name = load_theme_name ( theme_full_path ) <EOL> if theme_name is None : <EOL> continue <EOL> theme_paths [ theme_name ] = prefix , potential_theme <EOL> return theme_paths <EOL> def load_theme_paths ( ) : <EOL> theme_paths = { } <EOL> prefixes = ( util . local_data_dir ( ) , util . appdata_dir ( ) ) <EOL> for prefix in prefixes : <EOL> theme_paths . update ( theme_dirs_from_prefix ( prefix ) ) <EOL> return theme_paths <EOL> def csv_transaction ( wallet ) : <EOL> try : <EOL> select_export = _ ( '<STR_LIT>' ) <EOL> fileName = QFileDialog . getSaveFileName ( QWidget ( ) , select_export , os . path . expanduser ( '<STR_LIT>' ) , "<STR_LIT>" ) <EOL> if fileName : <EOL> with open ( fileName , "<STR_LIT>" ) as csvfile : <EOL> transaction = csv . writer ( csvfile ) <EOL> transaction . writerow ( [ "<STR_LIT>" , "<STR_LIT:label>" , "<STR_LIT>" , "<STR_LIT:value>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> for item in wallet . get_tx_history ( ) : <EOL> tx_hash , confirmations , is_mine , value , fee , balance , timestamp = item <EOL> if confirmations : <EOL> if timestamp is not None : <EOL> try : <EOL> time_string = datetime . datetime . fromtimestamp ( timestamp ) . isoformat ( '<STR_LIT:U+0020>' ) [ : - <NUM_LIT:3> ] <EOL> except [ RuntimeError , TypeError , NameError ] as reason : <EOL> time_string = "<STR_LIT>" <EOL> pass <EOL> else : <EOL> time_string = "<STR_LIT>" <EOL> else : <EOL> time_string = "<STR_LIT>" <EOL> if value is not None : <EOL> value_string = format_satoshis ( value , True ) <EOL> else : <EOL> value_string = '<STR_LIT>' <EOL> if fee is not None : <EOL> fee_string = format_satoshis ( fee , True ) <EOL> else : <EOL> fee_string = '<STR_LIT:0>' <EOL> if tx_hash : <EOL> label , is_default_label = wallet . get_label ( tx_hash ) <EOL> label = label . encode ( '<STR_LIT:utf-8>' ) <EOL> else : <EOL> label = "<STR_LIT>" <EOL> balance_string = format_satoshis ( balance , False ) <EOL> transaction . writerow ( [ tx_hash , label , confirmations , value_string , fee_string , balance_string , time_string ] ) <EOL> QMessageBox . information ( None , _ ( "<STR_LIT>" ) , _ ( "<STR_LIT>" ) ) <EOL> except ( IOError , os . error ) , reason : <EOL> export_error_label = _ ( "<STR_LIT>" ) <EOL> QMessageBox . critical ( None , _ ( "<STR_LIT>" ) , export_error_label + "<STR_LIT:\n>" + str ( reason ) ) <EOL> class TransactionWindow ( QDialog ) : <EOL> def set_label ( self ) : <EOL> label = unicode ( self . label_edit . text ( ) ) <EOL> self . parent . wallet . labels [ self . tx_id ] = label <EOL> super ( TransactionWindow , self ) . accept ( ) <EOL> def __init__ ( self , transaction_id , parent ) : <EOL> super ( TransactionWindow , self ) . __init__ ( ) <EOL> self . tx_id = str ( transaction_id ) <EOL> self . parent = parent <EOL> self . setModal ( True ) <EOL> self . resize ( <NUM_LIT:200> , <NUM_LIT:100> ) <EOL> self . setWindowTitle ( _ ( "<STR_LIT>" ) ) <EOL> self . layout = QGridLayout ( self ) <EOL> history_label = "<STR_LIT>" % ( _ ( "<STR_LIT>" ) , _ ( "<STR_LIT>" ) ) <EOL> self . layout . addWidget ( QLabel ( history_label ) ) <EOL> self . label_edit = QLineEdit ( ) <EOL> self . label_edit . setPlaceholderText ( _ ( "<STR_LIT>" ) ) <EOL> self . label_edit . setObjectName ( "<STR_LIT>" ) <EOL> self . label_edit . setAttribute ( Qt . WA_MacShowFocusRect , <NUM_LIT:0> ) <EOL> self . label_edit . setFocusPolicy ( Qt . ClickFocus ) <EOL> self . layout . addWidget ( self . label_edit ) <EOL> self . save_button = QPushButton ( _ ( "<STR_LIT>" ) ) <EOL> self . layout . addWidget ( self . save_button ) <EOL> self . save_button . clicked . connect ( self . set_label ) <EOL> self . exec_ ( ) <EOL> class MiniWindow ( QDialog ) : <EOL> def __init__ ( self , actuator , expand_callback , config ) : <EOL> super ( MiniWindow , self ) . __init__ ( ) <EOL> self . actuator = actuator <EOL> self . config = config <EOL> self . btc_balance = None <EOL> self . use_exchanges = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . quote_currencies = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . actuator . set_configured_currency ( self . set_quote_currency ) <EOL> self . actuator . set_configured_exchange ( self . set_exchange ) <EOL> self . connect ( self , SIGNAL ( "<STR_LIT>" ) , self . refresh_balance ) <EOL> self . balance_label = BalanceLabel ( self . change_quote_currency , self ) <EOL> self . balance_label . setObjectName ( "<STR_LIT>" ) <EOL> self . address_input = QLineEdit ( ) <EOL> self . address_input . setPlaceholderText ( _ ( "<STR_LIT>" ) ) <EOL> self . address_input . setObjectName ( "<STR_LIT>" ) <EOL> self . address_input . setFocusPolicy ( Qt . ClickFocus ) <EOL> self . address_input . textChanged . connect ( self . address_field_changed ) <EOL> resize_line_edit_width ( self . address_input , <EOL> "<STR_LIT>" ) <EOL> self . address_completions = QStringListModel ( ) <EOL> address_completer = QCompleter ( self . address_input ) <EOL> address_completer . setCaseSensitivity ( False ) <EOL> address_completer . setModel ( self . address_completions ) <EOL> self . address_input . setCompleter ( address_completer ) <EOL> address_layout = QHBoxLayout ( ) <EOL> address_layout . addWidget ( self . address_input ) <EOL> self . amount_input = QLineEdit ( ) <EOL> self . amount_input . setPlaceholderText ( _ ( "<STR_LIT>" ) + "<STR_LIT>" % self . actuator . g . base_unit ( ) ) <EOL> self . amount_input . setObjectName ( "<STR_LIT>" ) <EOL> self . amount_input . setFocusPolicy ( Qt . ClickFocus ) <EOL> self . amount_validator = QDoubleValidator ( self . amount_input ) <EOL> self . amount_validator . setNotation ( QDoubleValidator . StandardNotation ) <EOL> self . amount_validator . setDecimals ( <NUM_LIT:8> ) <EOL> self . amount_input . setValidator ( self . amount_validator ) <EOL> self . address_input . setAttribute ( Qt . WA_MacShowFocusRect , <NUM_LIT:0> ) <EOL> self . amount_input . setAttribute ( Qt . WA_MacShowFocusRect , <NUM_LIT:0> ) <EOL> self . amount_input . textChanged . connect ( self . amount_input_changed ) <EOL> self . send_button = QPushButton ( _ ( "<STR_LIT>" ) ) <EOL> self . send_button . setObjectName ( "<STR_LIT>" ) <EOL> self . send_button . setDisabled ( True ) ; <EOL> self . send_button . clicked . connect ( self . send ) <EOL> self . switch_button = QPushButton ( QIcon ( "<STR_LIT>" ) , '<STR_LIT>' ) <EOL> self . switch_button . setMaximumWidth ( <NUM_LIT> ) <EOL> self . switch_button . setFlat ( True ) <EOL> self . switch_button . clicked . connect ( expand_callback ) <EOL> main_layout = QGridLayout ( self ) <EOL> main_layout . addWidget ( self . balance_label , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> main_layout . addWidget ( self . switch_button , <NUM_LIT:0> , <NUM_LIT:3> ) <EOL> main_layout . addWidget ( self . address_input , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> ) <EOL> main_layout . addWidget ( self . amount_input , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> main_layout . addWidget ( self . send_button , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> self . send_button . setMaximumWidth ( <NUM_LIT> ) <EOL> self . history_list = history_widget . HistoryWidget ( ) <EOL> self . history_list . setObjectName ( "<STR_LIT>" ) <EOL> self . history_list . hide ( ) <EOL> self . history_list . setAlternatingRowColors ( True ) <EOL> main_layout . addWidget ( self . history_list , <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> ) <EOL> self . receiving = receiving_widget . ReceivingWidget ( self ) <EOL> self . receiving . setObjectName ( "<STR_LIT>" ) <EOL> self . receiving_box = QGroupBox ( _ ( "<STR_LIT>" ) ) <EOL> extra_layout = QGridLayout ( ) <EOL> hide_used = QCheckBox ( _ ( '<STR_LIT>' ) ) <EOL> hide_used . setChecked ( True ) <EOL> hide_used . stateChanged . connect ( self . receiving . toggle_used ) <EOL> self . receiving . clicked . connect ( self . receiving . copy_address ) <EOL> self . receiving . itemDoubleClicked . connect ( self . receiving . edit_label ) <EOL> self . receiving . itemChanged . connect ( self . receiving . update_label ) <EOL> extra_layout . addWidget ( QLabel ( _ ( '<STR_LIT>' ) + '<STR_LIT:\n>' + _ ( '<STR_LIT>' ) ) , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> extra_layout . addWidget ( self . receiving , <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> extra_layout . addWidget ( hide_used , <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> extra_layout . setColumnMinimumWidth ( <NUM_LIT:0> , <NUM_LIT:200> ) <EOL> self . receiving_box . setLayout ( extra_layout ) <EOL> main_layout . addWidget ( self . receiving_box , <NUM_LIT:0> , <NUM_LIT:4> , - <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> self . receiving_box . hide ( ) <EOL> self . main_layout = main_layout <EOL> quit_shortcut = QShortcut ( QKeySequence ( "<STR_LIT>" ) , self ) <EOL> quit_shortcut . activated . connect ( self . close ) <EOL> close_shortcut = QShortcut ( QKeySequence ( "<STR_LIT>" ) , self ) <EOL> close_shortcut . activated . connect ( self . close ) <EOL> g = self . config . get ( "<STR_LIT>" , [ <NUM_LIT:4> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> self . setGeometry ( g [ <NUM_LIT:0> ] , g [ <NUM_LIT:1> ] , g [ <NUM_LIT:2> ] , g [ <NUM_LIT:3> ] ) <EOL> show_hist = self . config . get ( "<STR_LIT>" , False ) <EOL> self . show_history ( show_hist ) <EOL> show_hist = self . config . get ( "<STR_LIT>" , False ) <EOL> self . toggle_receiving_layout ( show_hist ) <EOL> self . setWindowIcon ( QIcon ( "<STR_LIT>" ) ) <EOL> self . setWindowTitle ( "<STR_LIT>" ) <EOL> self . setWindowFlags ( Qt . Window | Qt . MSWindowsFixedSizeDialogHint ) <EOL> self . layout ( ) . setSizeConstraint ( QLayout . SetFixedSize ) <EOL> self . setObjectName ( "<STR_LIT>" ) <EOL> def context_menu ( self ) : <EOL> view_menu = QMenu ( ) <EOL> themes_menu = view_menu . addMenu ( _ ( "<STR_LIT>" ) ) <EOL> selected_theme = self . actuator . selected_theme ( ) <EOL> theme_group = QActionGroup ( self ) <EOL> for theme_name in self . actuator . theme_names ( ) : <EOL> theme_action = themes_menu . addAction ( theme_name ) <EOL> theme_action . setCheckable ( True ) <EOL> if selected_theme == theme_name : <EOL> theme_action . setChecked ( True ) <EOL> class SelectThemeFunctor : <EOL> def __init__ ( self , theme_name , toggle_theme ) : <EOL> self . theme_name = theme_name <EOL> self . toggle_theme = toggle_theme <EOL> def __call__ ( self , checked ) : <EOL> if checked : <EOL> self . toggle_theme ( self . theme_name ) <EOL> delegate = SelectThemeFunctor ( theme_name , self . toggle_theme ) <EOL> theme_action . toggled . connect ( delegate ) <EOL> theme_group . addAction ( theme_action ) <EOL> view_menu . addSeparator ( ) <EOL> show_receiving = view_menu . addAction ( _ ( "<STR_LIT>" ) ) <EOL> show_receiving . setCheckable ( True ) <EOL> show_receiving . toggled . connect ( self . toggle_receiving_layout ) <EOL> show_receiving . setChecked ( self . config . get ( "<STR_LIT>" , False ) ) <EOL> show_history = view_menu . addAction ( _ ( "<STR_LIT>" ) ) <EOL> show_history . setCheckable ( True ) <EOL> show_history . toggled . connect ( self . show_history ) <EOL> show_history . setChecked ( self . config . get ( "<STR_LIT>" , False ) ) <EOL> return view_menu <EOL> def toggle_theme ( self , theme_name ) : <EOL> self . actuator . change_theme ( theme_name ) <EOL> qApp . style ( ) . unpolish ( self ) <EOL> qApp . style ( ) . polish ( self ) <EOL> def closeEvent ( self , event ) : <EOL> g = self . geometry ( ) <EOL> self . config . set_key ( "<STR_LIT>" , [ g . left ( ) , g . top ( ) , g . width ( ) , g . height ( ) ] , True ) <EOL> self . actuator . g . closeEvent ( event ) <EOL> qApp . quit ( ) <EOL> def set_payment_fields ( self , dest_address , amount ) : <EOL> self . address_input . setText ( dest_address ) <EOL> self . address_field_changed ( dest_address ) <EOL> self . amount_input . setText ( amount ) <EOL> def activate ( self ) : <EOL> pass <EOL> def deactivate ( self ) : <EOL> pass <EOL> def set_exchange ( self , use_exchange ) : <EOL> if use_exchange not in self . use_exchanges : <EOL> return <EOL> self . use_exchanges . remove ( use_exchange ) <EOL> self . use_exchanges . insert ( <NUM_LIT:0> , use_exchange ) <EOL> self . refresh_balance ( ) <EOL> def set_quote_currency ( self , currency ) : <EOL> """<STR_LIT>""" <EOL> if currency not in self . quote_currencies : <EOL> return <EOL> self . quote_currencies . remove ( currency ) <EOL> self . quote_currencies . insert ( <NUM_LIT:0> , currency ) <EOL> self . refresh_balance ( ) <EOL> def change_quote_currency ( self , forward = True ) : <EOL> if forward : <EOL> self . quote_currencies = self . quote_currencies [ <NUM_LIT:1> : ] + self . quote_currencies [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> else : <EOL> self . quote_currencies = self . quote_currencies [ - <NUM_LIT:1> : ] + self . quote_currencies [ <NUM_LIT:0> : - <NUM_LIT:1> ] <EOL> self . actuator . set_config_currency ( self . quote_currencies [ <NUM_LIT:0> ] ) <EOL> self . refresh_balance ( ) <EOL> def refresh_balance ( self ) : <EOL> if self . btc_balance is None : <EOL> return <EOL> self . set_balances ( self . btc_balance ) <EOL> self . amount_input_changed ( self . amount_input . text ( ) ) <EOL> def set_balances ( self , btc_balance ) : <EOL> """<STR_LIT>""" <EOL> self . btc_balance = btc_balance <EOL> quote_text = self . create_quote_text ( btc_balance ) <EOL> if quote_text : <EOL> quote_text = "<STR_LIT>" % quote_text <EOL> amount = self . actuator . g . format_amount ( btc_balance ) <EOL> unit = self . actuator . g . base_unit ( ) <EOL> self . balance_label . set_balance_text ( amount , unit , quote_text ) <EOL> self . setWindowTitle ( "<STR_LIT>" % ( electrum_version , amount , unit ) ) <EOL> def amount_input_changed ( self , amount_text ) : <EOL> """<STR_LIT>""" <EOL> self . check_button_status ( ) <EOL> try : <EOL> amount = D ( str ( amount_text ) ) * ( <NUM_LIT:10> ** self . actuator . g . decimal_point ) <EOL> except decimal . InvalidOperation : <EOL> self . balance_label . show_balance ( ) <EOL> else : <EOL> quote_text = self . create_quote_text ( amount ) <EOL> if quote_text : <EOL> self . balance_label . set_amount_text ( quote_text ) <EOL> self . balance_label . show_amount ( ) <EOL> else : <EOL> self . balance_label . show_balance ( ) <EOL> def create_quote_text ( self , btc_balance ) : <EOL> """<STR_LIT>""" <EOL> from electrum . plugins import run_hook <EOL> r = { } <EOL> run_hook ( '<STR_LIT>' , btc_balance , r ) <EOL> return r . get ( <NUM_LIT:0> , '<STR_LIT>' ) <EOL> def send ( self ) : <EOL> if self . actuator . send ( self . address_input . text ( ) , <EOL> self . amount_input . text ( ) , self ) : <EOL> self . address_input . setText ( "<STR_LIT>" ) <EOL> self . amount_input . setText ( "<STR_LIT>" ) <EOL> def check_button_status ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> value = D ( str ( self . amount_input . text ( ) ) ) * ( <NUM_LIT:10> ** self . actuator . g . decimal_point ) <EOL> except decimal . InvalidOperation : <EOL> value = None <EOL> if ( self . address_input . property ( "<STR_LIT>" ) == True and <EOL> value is not None and <NUM_LIT:0> < value <= self . btc_balance ) : <EOL> self . send_button . setDisabled ( False ) <EOL> else : <EOL> self . send_button . setDisabled ( True ) <EOL> def address_field_changed ( self , address ) : <EOL> match2 = re . match ( "<STR_LIT>" , <EOL> address ) <EOL> if match2 : <EOL> address = match2 . group ( <NUM_LIT:2> ) <EOL> self . address_input . setText ( address ) <EOL> if is_valid ( address ) : <EOL> self . check_button_status ( ) <EOL> self . address_input . setProperty ( "<STR_LIT>" , True ) <EOL> self . recompute_style ( self . address_input ) <EOL> else : <EOL> self . send_button . setDisabled ( True ) <EOL> self . address_input . setProperty ( "<STR_LIT>" , False ) <EOL> self . recompute_style ( self . address_input ) <EOL> if len ( address ) == <NUM_LIT:0> : <EOL> self . address_input . setProperty ( "<STR_LIT>" , None ) <EOL> self . recompute_style ( self . address_input ) <EOL> def recompute_style ( self , element ) : <EOL> self . style ( ) . unpolish ( element ) <EOL> self . style ( ) . polish ( element ) <EOL> def copy_address ( self ) : <EOL> receive_popup = ReceivePopup ( self . receive_button ) <EOL> self . actuator . copy_address ( receive_popup ) <EOL> def update_completions ( self , completions ) : <EOL> self . address_completions . setStringList ( completions ) <EOL> def update_history ( self , tx_history ) : <EOL> self . history_list . empty ( ) <EOL> for item in tx_history [ - <NUM_LIT:10> : ] : <EOL> tx_hash , conf , is_mine , value , fee , balance , timestamp = item <EOL> label = self . actuator . g . wallet . get_label ( tx_hash ) [ <NUM_LIT:0> ] <EOL> v_str = self . actuator . g . format_amount ( value , True ) <EOL> self . history_list . append ( label , v_str , age ( timestamp ) ) <EOL> def the_website ( self ) : <EOL> webbrowser . open ( "<STR_LIT>" ) <EOL> def toggle_receiving_layout ( self , toggle_state ) : <EOL> if toggle_state : <EOL> self . receiving_box . show ( ) <EOL> else : <EOL> self . receiving_box . hide ( ) <EOL> self . config . set_key ( "<STR_LIT>" , toggle_state ) <EOL> def show_history ( self , toggle_state ) : <EOL> if toggle_state : <EOL> self . main_layout . setRowMinimumHeight ( <NUM_LIT:3> , <NUM_LIT:200> ) <EOL> self . history_list . show ( ) <EOL> else : <EOL> self . main_layout . setRowMinimumHeight ( <NUM_LIT:3> , <NUM_LIT:0> ) <EOL> self . history_list . hide ( ) <EOL> self . config . set_key ( "<STR_LIT>" , toggle_state ) <EOL> class BalanceLabel ( QLabel ) : <EOL> SHOW_CONNECTING = <NUM_LIT:1> <EOL> SHOW_BALANCE = <NUM_LIT:2> <EOL> SHOW_AMOUNT = <NUM_LIT:3> <EOL> def __init__ ( self , change_quote_currency , parent = None ) : <EOL> super ( QLabel , self ) . __init__ ( _ ( "<STR_LIT>" ) , parent ) <EOL> self . change_quote_currency = change_quote_currency <EOL> self . state = self . SHOW_CONNECTING <EOL> self . balance_text = "<STR_LIT>" <EOL> self . amount_text = "<STR_LIT>" <EOL> self . parent = parent <EOL> def mousePressEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if self . state != self . SHOW_CONNECTING : <EOL> if event . button ( ) == Qt . LeftButton : <EOL> self . change_quote_currency ( ) <EOL> else : <EOL> position = event . globalPos ( ) <EOL> menu = self . parent . context_menu ( ) <EOL> menu . exec_ ( position ) <EOL> def set_balance_text ( self , amount , unit , quote_text ) : <EOL> """<STR_LIT>""" <EOL> if self . state == self . SHOW_CONNECTING : <EOL> self . state = self . SHOW_BALANCE <EOL> self . balance_text = "<STR_LIT>" % amount + "<STR_LIT>" % unit + "<STR_LIT>" % quote_text <EOL> if self . state == self . SHOW_BALANCE : <EOL> self . setText ( self . balance_text ) <EOL> def set_amount_text ( self , quote_text ) : <EOL> self . amount_text = "<STR_LIT>" % quote_text <EOL> if self . state == self . SHOW_AMOUNT : <EOL> self . setText ( self . amount_text ) <EOL> def show_balance ( self ) : <EOL> if self . state == self . SHOW_AMOUNT : <EOL> self . state = self . SHOW_BALANCE <EOL> self . setText ( self . balance_text ) <EOL> def show_amount ( self ) : <EOL> if self . state == self . SHOW_BALANCE : <EOL> self . state = self . SHOW_AMOUNT <EOL> self . setText ( self . amount_text ) <EOL> def ok_cancel_buttons ( dialog ) : <EOL> row_layout = QHBoxLayout ( ) <EOL> row_layout . addStretch ( <NUM_LIT:1> ) <EOL> ok_button = QPushButton ( _ ( "<STR_LIT:OK>" ) ) <EOL> row_layout . addWidget ( ok_button ) <EOL> ok_button . clicked . connect ( dialog . accept ) <EOL> cancel_button = QPushButton ( _ ( "<STR_LIT>" ) ) <EOL> row_layout . addWidget ( cancel_button ) <EOL> cancel_button . clicked . connect ( dialog . reject ) <EOL> return row_layout <EOL> class PasswordDialog ( QDialog ) : <EOL> def __init__ ( self , parent ) : <EOL> super ( QDialog , self ) . __init__ ( parent ) <EOL> self . setModal ( True ) <EOL> self . password_input = QLineEdit ( ) <EOL> self . password_input . setEchoMode ( QLineEdit . Password ) <EOL> main_layout = QVBoxLayout ( self ) <EOL> message = _ ( '<STR_LIT>' ) <EOL> main_layout . addWidget ( QLabel ( message ) ) <EOL> grid = QGridLayout ( ) <EOL> grid . setSpacing ( <NUM_LIT:8> ) <EOL> grid . addWidget ( QLabel ( _ ( '<STR_LIT>' ) ) , <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> grid . addWidget ( self . password_input , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> main_layout . addLayout ( grid ) <EOL> main_layout . addLayout ( ok_cancel_buttons ( self ) ) <EOL> self . setLayout ( main_layout ) <EOL> def run ( self ) : <EOL> if not self . exec_ ( ) : <EOL> return <EOL> return unicode ( self . password_input . text ( ) ) <EOL> class ReceivePopup ( QDialog ) : <EOL> def leaveEvent ( self , event ) : <EOL> self . close ( ) <EOL> def setup ( self , address ) : <EOL> label = QLabel ( _ ( "<STR_LIT>" ) ) <EOL> address_display = QLineEdit ( address ) <EOL> address_display . setReadOnly ( True ) <EOL> resize_line_edit_width ( address_display , address ) <EOL> main_layout = QVBoxLayout ( self ) <EOL> main_layout . addWidget ( label ) <EOL> main_layout . addWidget ( address_display ) <EOL> self . setMouseTracking ( True ) <EOL> self . setWindowTitle ( "<STR_LIT>" + _ ( "<STR_LIT>" ) ) <EOL> self . setWindowFlags ( Qt . Window | Qt . FramelessWindowHint | <EOL> Qt . MSWindowsFixedSizeDialogHint ) <EOL> self . layout ( ) . setSizeConstraint ( QLayout . SetFixedSize ) <EOL> def popup ( self ) : <EOL> parent = self . parent ( ) <EOL> top_left_pos = parent . mapToGlobal ( parent . rect ( ) . bottomLeft ( ) ) <EOL> self . move ( top_left_pos ) <EOL> center_mouse_pos = self . mapToGlobal ( self . rect ( ) . center ( ) ) <EOL> QCursor . setPos ( center_mouse_pos ) <EOL> self . show ( ) <EOL> class MiniActuator : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , main_window ) : <EOL> """<STR_LIT>""" <EOL> self . g = main_window <EOL> self . theme_name = self . g . config . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . themes = load_theme_paths ( ) <EOL> self . load_theme ( ) <EOL> def load_theme ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> theme_prefix , theme_path = self . themes [ self . theme_name ] <EOL> except KeyError : <EOL> util . print_error ( "<STR_LIT>" , self . theme_name ) <EOL> return <EOL> full_theme_path = "<STR_LIT>" % ( theme_prefix , theme_path ) <EOL> with open ( full_theme_path ) as style_file : <EOL> qApp . setStyleSheet ( style_file . read ( ) ) <EOL> def theme_names ( self ) : <EOL> """<STR_LIT>""" <EOL> return sorted ( self . themes . keys ( ) ) <EOL> def selected_theme ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . theme_name <EOL> def change_theme ( self , theme_name ) : <EOL> """<STR_LIT>""" <EOL> self . theme_name = theme_name <EOL> self . g . config . set_key ( '<STR_LIT>' , theme_name ) <EOL> self . load_theme ( ) <EOL> def set_configured_exchange ( self , set_exchange ) : <EOL> use_exchange = self . g . config . get ( '<STR_LIT>' ) <EOL> if use_exchange is not None : <EOL> set_exchange ( use_exchange ) <EOL> def set_configured_currency ( self , set_quote_currency ) : <EOL> """<STR_LIT>""" <EOL> currency = self . g . config . get ( '<STR_LIT>' ) <EOL> if currency is not None : <EOL> set_quote_currency ( currency ) <EOL> def set_config_exchange ( self , conversion_exchange ) : <EOL> self . g . config . set_key ( '<STR_LIT>' , conversion_exchange , True ) <EOL> self . g . update_status ( ) <EOL> def set_config_currency ( self , conversion_currency ) : <EOL> """<STR_LIT>""" <EOL> self . g . config . set_key ( '<STR_LIT>' , conversion_currency , True ) <EOL> self . g . update_status ( ) <EOL> def copy_address ( self , receive_popup ) : <EOL> """<STR_LIT>""" <EOL> addrs = [ addr for addr in self . g . wallet . addresses ( True ) <EOL> if not self . g . wallet . is_change ( addr ) ] <EOL> addrs = addrs [ - self . g . wallet . gap_limit : ] <EOL> copied_address = random . choice ( addrs ) <EOL> qApp . clipboard ( ) . setText ( copied_address ) <EOL> receive_popup . setup ( copied_address ) <EOL> receive_popup . popup ( ) <EOL> def waiting_dialog ( self , f ) : <EOL> s = Timer ( ) <EOL> s . start ( ) <EOL> w = QDialog ( ) <EOL> w . resize ( <NUM_LIT:200> , <NUM_LIT> ) <EOL> w . setWindowTitle ( '<STR_LIT>' ) <EOL> l = QLabel ( _ ( '<STR_LIT>' ) ) <EOL> vbox = QVBoxLayout ( ) <EOL> vbox . addWidget ( l ) <EOL> w . setLayout ( vbox ) <EOL> w . show ( ) <EOL> def ff ( ) : <EOL> s = f ( ) <EOL> if s : l . setText ( s ) <EOL> else : w . close ( ) <EOL> w . connect ( s , QtCore . SIGNAL ( '<STR_LIT>' ) , ff ) <EOL> w . exec_ ( ) <EOL> w . destroy ( ) <EOL> def send ( self , address , amount , parent_window ) : <EOL> """<STR_LIT>""" <EOL> dest_address = self . fetch_destination ( address ) <EOL> if dest_address is None or not is_valid ( dest_address ) : <EOL> QMessageBox . warning ( parent_window , _ ( '<STR_LIT>' ) , <EOL> _ ( '<STR_LIT>' ) + '<STR_LIT>' + address , _ ( '<STR_LIT:OK>' ) ) <EOL> return False <EOL> amount = D ( unicode ( amount ) ) * ( <NUM_LIT:10> * self . g . decimal_point ) <EOL> print "<STR_LIT>" , amount <EOL> return <EOL> if self . g . wallet . use_encryption : <EOL> password_dialog = PasswordDialog ( parent_window ) <EOL> password = password_dialog . run ( ) <EOL> if not password : <EOL> return <EOL> else : <EOL> password = None <EOL> fee = <NUM_LIT:0> <EOL> if amount < bitcoin ( <NUM_LIT:1> ) / <NUM_LIT:10> : <EOL> fee = bitcoin ( <NUM_LIT:1> ) / <NUM_LIT:1000> <EOL> try : <EOL> tx = self . g . wallet . mktx ( [ ( dest_address , amount ) ] , password , fee ) <EOL> except Exception as error : <EOL> QMessageBox . warning ( parent_window , _ ( '<STR_LIT>' ) , str ( error ) , _ ( '<STR_LIT:OK>' ) ) <EOL> return False <EOL> if tx . is_complete : <EOL> h = self . g . wallet . send_tx ( tx ) <EOL> self . waiting_dialog ( lambda : False if self . g . wallet . tx_event . isSet ( ) else _ ( "<STR_LIT>" ) ) <EOL> status , message = self . g . wallet . receive_tx ( h , tx ) <EOL> if not status : <EOL> import tempfile <EOL> dumpf = tempfile . NamedTemporaryFile ( delete = False ) <EOL> dumpf . write ( tx ) <EOL> dumpf . close ( ) <EOL> print "<STR_LIT>" , dumpf . name <EOL> QMessageBox . warning ( parent_window , _ ( '<STR_LIT>' ) , message , _ ( '<STR_LIT:OK>' ) ) <EOL> return False <EOL> TransactionWindow ( message , self ) <EOL> else : <EOL> filename = '<STR_LIT>' % ( time . mktime ( time . gmtime ( ) ) ) <EOL> try : <EOL> fileName = QFileDialog . getSaveFileName ( QWidget ( ) , _ ( "<STR_LIT>" ) , os . path . expanduser ( '<STR_LIT>' % ( filename ) ) ) <EOL> with open ( fileName , '<STR_LIT:w>' ) as f : <EOL> f . write ( json . dumps ( tx . as_dict ( ) , indent = <NUM_LIT:4> ) + '<STR_LIT:\n>' ) <EOL> QMessageBox . information ( QWidget ( ) , _ ( '<STR_LIT>' ) , _ ( "<STR_LIT>" ) + "<STR_LIT:U+0020>" + fileName , _ ( '<STR_LIT:OK>' ) ) <EOL> except Exception as e : <EOL> QMessageBox . warning ( QWidget ( ) , _ ( '<STR_LIT>' ) , _ ( '<STR_LIT>' % e ) , _ ( '<STR_LIT:OK>' ) ) <EOL> return True <EOL> def fetch_destination ( self , address ) : <EOL> recipient = unicode ( address ) . strip ( ) <EOL> match1 = re . match ( "<STR_LIT>" , <EOL> recipient ) <EOL> match2 = re . match ( "<STR_LIT>" , <EOL> recipient ) <EOL> if match1 : <EOL> dest_address = self . g . wallet . get_alias ( recipient , True , <EOL> self . show_message , self . question ) <EOL> return dest_address <EOL> elif match2 : <EOL> return match2 . group ( <NUM_LIT:2> ) <EOL> else : <EOL> return recipient <EOL> class MiniDriver ( QObject ) : <EOL> INITIALIZING = <NUM_LIT:0> <EOL> CONNECTING = <NUM_LIT:1> <EOL> SYNCHRONIZING = <NUM_LIT:2> <EOL> READY = <NUM_LIT:3> <EOL> def __init__ ( self , main_window , mini_window ) : <EOL> super ( QObject , self ) . __init__ ( ) <EOL> self . g = main_window <EOL> self . network = main_window . network <EOL> self . window = mini_window <EOL> if self . network : <EOL> self . network . register_callback ( '<STR_LIT>' , self . update_callback ) <EOL> self . network . register_callback ( '<STR_LIT>' , self . update_callback ) <EOL> self . network . register_callback ( '<STR_LIT>' , self . update_callback ) <EOL> self . state = None <EOL> self . initializing ( ) <EOL> self . connect ( self , SIGNAL ( "<STR_LIT>" ) , self . update ) <EOL> self . update_callback ( ) <EOL> def update_callback ( self ) : <EOL> self . emit ( SIGNAL ( "<STR_LIT>" ) ) <EOL> def update ( self ) : <EOL> if not self . network : <EOL> self . initializing ( ) <EOL> elif not self . network . interface : <EOL> self . initializing ( ) <EOL> elif not self . network . interface . is_connected : <EOL> self . connecting ( ) <EOL> if self . g . wallet is None : <EOL> self . ready ( ) <EOL> elif not self . g . wallet . up_to_date : <EOL> self . synchronizing ( ) <EOL> else : <EOL> self . ready ( ) <EOL> self . update_balance ( ) <EOL> self . update_completions ( ) <EOL> self . update_history ( ) <EOL> self . window . receiving . update_list ( ) <EOL> def initializing ( self ) : <EOL> if self . state == self . INITIALIZING : <EOL> return <EOL> self . state = self . INITIALIZING <EOL> self . window . deactivate ( ) <EOL> def connecting ( self ) : <EOL> if self . state == self . CONNECTING : <EOL> return <EOL> self . state = self . CONNECTING <EOL> self . window . deactivate ( ) <EOL> def synchronizing ( self ) : <EOL> if self . state == self . SYNCHRONIZING : <EOL> return <EOL> self . state = self . SYNCHRONIZING <EOL> self . window . deactivate ( ) <EOL> def ready ( self ) : <EOL> if self . state == self . READY : <EOL> return <EOL> self . state = self . READY <EOL> self . window . activate ( ) <EOL> def update_balance ( self ) : <EOL> conf_balance , unconf_balance = self . g . wallet . get_balance ( ) <EOL> balance = D ( conf_balance + unconf_balance ) <EOL> self . window . set_balances ( balance ) <EOL> def update_completions ( self ) : <EOL> completions = [ ] <EOL> for addr , label in self . g . wallet . labels . items ( ) : <EOL> if addr in self . g . wallet . addressbook : <EOL> completions . append ( "<STR_LIT>" % ( label , addr ) ) <EOL> self . window . update_completions ( completions ) <EOL> def update_history ( self ) : <EOL> tx_history = self . g . wallet . get_tx_history ( ) <EOL> self . window . update_history ( tx_history ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> app = QApplication ( sys . argv ) <EOL> with open ( rsrc ( "<STR_LIT>" ) ) as style_file : <EOL> app . setStyleSheet ( style_file . read ( ) ) <EOL> mini = MiniWindow ( ) <EOL> sys . exit ( app . exec_ ( ) ) </s>
