<s> import sys , time , datetime , re , threading <EOL> from electrum . i18n import _ , set_language <EOL> from electrum . util import print_error , print_msg <EOL> import os . path , json , ast , traceback <EOL> import shutil <EOL> import StringIO <EOL> try : <EOL> import PyQt4 <EOL> except Exception : <EOL> sys . exit ( "<STR_LIT>" ) <EOL> from PyQt4 . QtGui import * <EOL> from PyQt4 . QtCore import * <EOL> import PyQt4 . QtCore as QtCore <EOL> from electrum import transaction <EOL> from util import MyTreeWidget <EOL> class TxDialog ( QDialog ) : <EOL> def __init__ ( self , tx , parent ) : <EOL> self . tx = tx <EOL> tx_dict = tx . as_dict ( ) <EOL> self . parent = parent <EOL> self . wallet = parent . wallet <EOL> QDialog . __init__ ( self ) <EOL> self . setMinimumWidth ( <NUM_LIT> ) <EOL> self . setWindowTitle ( _ ( "<STR_LIT>" ) ) <EOL> self . setModal ( <NUM_LIT:1> ) <EOL> vbox = QVBoxLayout ( ) <EOL> self . setLayout ( vbox ) <EOL> vbox . addWidget ( QLabel ( _ ( "<STR_LIT>" ) ) ) <EOL> self . tx_hash_e = QLineEdit ( ) <EOL> self . tx_hash_e . setReadOnly ( True ) <EOL> vbox . addWidget ( self . tx_hash_e ) <EOL> self . status_label = QLabel ( ) <EOL> vbox . addWidget ( self . status_label ) <EOL> self . date_label = QLabel ( ) <EOL> vbox . addWidget ( self . date_label ) <EOL> self . amount_label = QLabel ( ) <EOL> vbox . addWidget ( self . amount_label ) <EOL> self . fee_label = QLabel ( ) <EOL> vbox . addWidget ( self . fee_label ) <EOL> self . add_io ( vbox ) <EOL> vbox . addStretch ( <NUM_LIT:1> ) <EOL> buttons = QHBoxLayout ( ) <EOL> vbox . addLayout ( buttons ) <EOL> buttons . addStretch ( <NUM_LIT:1> ) <EOL> self . sign_button = b = QPushButton ( _ ( "<STR_LIT>" ) ) <EOL> b . clicked . connect ( self . sign ) <EOL> buttons . addWidget ( b ) <EOL> self . broadcast_button = b = QPushButton ( _ ( "<STR_LIT>" ) ) <EOL> b . clicked . connect ( self . broadcast ) <EOL> b . hide ( ) <EOL> buttons . addWidget ( b ) <EOL> self . save_button = b = QPushButton ( _ ( "<STR_LIT>" ) ) <EOL> b . clicked . connect ( self . save ) <EOL> buttons . addWidget ( b ) <EOL> cancelButton = QPushButton ( _ ( "<STR_LIT>" ) ) <EOL> cancelButton . clicked . connect ( lambda : self . done ( <NUM_LIT:0> ) ) <EOL> buttons . addWidget ( cancelButton ) <EOL> cancelButton . setDefault ( True ) <EOL> self . update ( ) <EOL> def sign ( self ) : <EOL> tx_dict = self . tx . as_dict ( ) <EOL> input_info = json . loads ( tx_dict [ "<STR_LIT>" ] ) <EOL> self . parent . sign_raw_transaction ( self . tx , input_info ) <EOL> self . update ( ) <EOL> def save ( self ) : <EOL> name = '<STR_LIT>' % ( self . tx . hash ( ) [ <NUM_LIT:0> : <NUM_LIT:8> ] ) if self . tx . is_complete else '<STR_LIT>' <EOL> fileName = self . parent . getSaveFileName ( _ ( "<STR_LIT>" ) , name , "<STR_LIT>" ) <EOL> if fileName : <EOL> with open ( fileName , "<STR_LIT>" ) as f : <EOL> f . write ( json . dumps ( self . tx . as_dict ( ) , indent = <NUM_LIT:4> ) + '<STR_LIT:\n>' ) <EOL> self . show_message ( _ ( "<STR_LIT>" ) ) <EOL> def update ( self ) : <EOL> is_relevant , is_mine , v , fee = self . wallet . get_tx_value ( self . tx ) <EOL> if self . tx . is_complete : <EOL> status = _ ( "<STR_LIT>" ) <EOL> self . sign_button . hide ( ) <EOL> tx_hash = self . tx . hash ( ) <EOL> if tx_hash in self . wallet . transactions . keys ( ) : <EOL> conf , timestamp = self . wallet . verifier . get_confirmations ( tx_hash ) <EOL> if timestamp : <EOL> time_str = datetime . datetime . fromtimestamp ( timestamp ) . isoformat ( '<STR_LIT:U+0020>' ) [ : - <NUM_LIT:3> ] <EOL> else : <EOL> time_str = '<STR_LIT>' <EOL> status = _ ( "<STR_LIT>" ) % conf <EOL> self . broadcast_button . hide ( ) <EOL> else : <EOL> time_str = None <EOL> conf = <NUM_LIT:0> <EOL> self . broadcast_button . show ( ) <EOL> else : <EOL> status = _ ( "<STR_LIT>" ) <EOL> time_str = None <EOL> if not self . wallet . is_watching_only ( ) : <EOL> self . sign_button . show ( ) <EOL> else : <EOL> self . sign_button . hide ( ) <EOL> self . broadcast_button . hide ( ) <EOL> tx_hash = '<STR_LIT>' <EOL> self . tx_hash_e . setText ( tx_hash ) <EOL> self . status_label . setText ( status ) <EOL> if time_str is not None : <EOL> self . date_label . setText ( _ ( "<STR_LIT>" ) % time_str ) <EOL> self . date_label . show ( ) <EOL> else : <EOL> self . date_label . hide ( ) <EOL> if self . parent . network is None or not self . parent . network . is_running ( ) or not self . parent . network . is_connected ( ) : <EOL> return <EOL> if not self . wallet . up_to_date : <EOL> return <EOL> if is_relevant : <EOL> if is_mine : <EOL> if fee is not None : <EOL> self . amount_label . setText ( _ ( "<STR_LIT>" ) + '<STR_LIT>' % self . parent . format_amount ( v - fee ) + '<STR_LIT:U+0020>' + self . parent . base_unit ( ) ) <EOL> self . fee_label . setText ( _ ( "<STR_LIT>" ) + '<STR_LIT>' % self . parent . format_amount ( fee ) + '<STR_LIT:U+0020>' + self . parent . base_unit ( ) ) <EOL> else : <EOL> self . amount_label . setText ( _ ( "<STR_LIT>" ) + '<STR_LIT>' % self . parent . format_amount ( v ) + '<STR_LIT:U+0020>' + self . parent . base_unit ( ) ) <EOL> self . fee_label . setText ( _ ( "<STR_LIT>" ) + '<STR_LIT>' + _ ( "<STR_LIT>" ) ) <EOL> else : <EOL> self . amount_label . setText ( _ ( "<STR_LIT>" ) + '<STR_LIT>' % self . parent . format_amount ( v ) + '<STR_LIT:U+0020>' + self . parent . base_unit ( ) ) <EOL> else : <EOL> self . amount_label . setText ( _ ( "<STR_LIT>" ) ) <EOL> def exec_menu ( self , position , l ) : <EOL> item = l . itemAt ( position ) <EOL> if not item : return <EOL> addr = unicode ( item . text ( <NUM_LIT:0> ) ) <EOL> menu = QMenu ( ) <EOL> menu . addAction ( _ ( "<STR_LIT>" ) , lambda : self . parent . app . clipboard ( ) . setText ( addr ) ) <EOL> menu . exec_ ( l . viewport ( ) . mapToGlobal ( position ) ) <EOL> def add_io ( self , vbox ) : <EOL> if self . tx . locktime > <NUM_LIT:0> : <EOL> vbox . addWidget ( QLabel ( "<STR_LIT>" % self . tx . locktime ) ) <EOL> vbox . addWidget ( QLabel ( _ ( "<STR_LIT>" ) ) ) <EOL> lines = map ( lambda x : x . get ( '<STR_LIT>' ) + "<STR_LIT>" % x . get ( '<STR_LIT>' ) + u'<STR_LIT:\t>' + "<STR_LIT:%s>" % x . get ( '<STR_LIT:address>' ) , self . tx . inputs ) <EOL> i_text = QTextEdit ( ) <EOL> i_text . setText ( '<STR_LIT:\n>' . join ( lines ) ) <EOL> i_text . setReadOnly ( True ) <EOL> i_text . setMaximumHeight ( <NUM_LIT:100> ) <EOL> vbox . addWidget ( i_text ) <EOL> vbox . addWidget ( QLabel ( _ ( "<STR_LIT>" ) ) ) <EOL> lines = map ( lambda x : x [ <NUM_LIT:0> ] + u'<STR_LIT>' + self . parent . format_amount ( x [ <NUM_LIT:1> ] ) , self . tx . outputs ) <EOL> o_text = QTextEdit ( ) <EOL> o_text . setText ( '<STR_LIT:\n>' . join ( lines ) ) <EOL> o_text . setReadOnly ( True ) <EOL> o_text . setMaximumHeight ( <NUM_LIT:100> ) <EOL> vbox . addWidget ( o_text ) <EOL> def broadcast ( self ) : <EOL> result , result_message = self . wallet . sendtx ( self . tx ) <EOL> if result : <EOL> self . show_message ( _ ( "<STR_LIT>" ) + '<STR_LIT>' % ( result_message ) ) <EOL> else : <EOL> self . show_message ( _ ( "<STR_LIT>" ) + '<STR_LIT>' % ( result_message ) ) <EOL> def show_message ( self , msg ) : <EOL> QMessageBox . information ( self , _ ( '<STR_LIT>' ) , msg , _ ( '<STR_LIT:OK>' ) ) </s>
