<s> import re <EOL> import platform <EOL> from decimal import Decimal <EOL> from urllib import quote <EOL> from PyQt4 . QtGui import * <EOL> from PyQt4 . QtCore import * <EOL> import PyQt4 . QtCore as QtCore <EOL> import PyQt4 . QtGui as QtGui <EOL> from electrum_gui . qt . qrcodewidget import QRCodeWidget <EOL> from electrum import bmp , pyqrnative , BasePlugin <EOL> from electrum . i18n import _ <EOL> if platform . system ( ) == '<STR_LIT>' : <EOL> MONOSPACE_FONT = '<STR_LIT>' <EOL> elif platform . system ( ) == '<STR_LIT>' : <EOL> MONOSPACE_FONT = '<STR_LIT>' <EOL> else : <EOL> MONOSPACE_FONT = '<STR_LIT>' <EOL> column_index = <NUM_LIT:4> <EOL> class QR_Window ( QWidget ) : <EOL> def __init__ ( self , exchanger ) : <EOL> QWidget . __init__ ( self ) <EOL> self . exchanger = exchanger <EOL> self . setWindowTitle ( '<STR_LIT>' + _ ( '<STR_LIT>' ) ) <EOL> self . setMinimumSize ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . address = '<STR_LIT>' <EOL> self . label = '<STR_LIT>' <EOL> self . amount = <NUM_LIT:0> <EOL> self . setFocusPolicy ( QtCore . Qt . NoFocus ) <EOL> main_box = QHBoxLayout ( ) <EOL> self . qrw = QRCodeWidget ( ) <EOL> main_box . addWidget ( self . qrw , <NUM_LIT:1> ) <EOL> vbox = QVBoxLayout ( ) <EOL> main_box . addLayout ( vbox ) <EOL> self . address_label = QLabel ( "<STR_LIT>" ) <EOL> vbox . addWidget ( self . address_label ) <EOL> self . label_label = QLabel ( "<STR_LIT>" ) <EOL> vbox . addWidget ( self . label_label ) <EOL> self . amount_label = QLabel ( "<STR_LIT>" ) <EOL> vbox . addWidget ( self . amount_label ) <EOL> vbox . addStretch ( <NUM_LIT:1> ) <EOL> self . setLayout ( main_box ) <EOL> def set_content ( self , addr , label , amount , currency ) : <EOL> self . address = addr <EOL> address_text = "<STR_LIT>" % addr if addr else "<STR_LIT>" <EOL> self . address_label . setText ( address_text ) <EOL> if currency == '<STR_LIT>' : currency = None <EOL> amount_text = '<STR_LIT>' <EOL> if amount : <EOL> if currency : <EOL> try : <EOL> self . amount = Decimal ( amount ) / self . exchanger . exchange ( <NUM_LIT:1> , currency ) if currency else amount <EOL> except Exception : <EOL> self . amount = None <EOL> else : <EOL> self . amount = Decimal ( amount ) <EOL> self . amount = self . amount . quantize ( Decimal ( '<STR_LIT>' ) ) <EOL> if currency : <EOL> amount_text += "<STR_LIT>" % ( amount , currency ) <EOL> amount_text += "<STR_LIT>" % str ( self . amount ) <EOL> else : <EOL> self . amount = None <EOL> self . amount_label . setText ( amount_text ) <EOL> self . label = label <EOL> label_text = "<STR_LIT>" % label if label else "<STR_LIT>" <EOL> self . label_label . setText ( label_text ) <EOL> msg = '<STR_LIT>' + self . address <EOL> if self . amount is not None : <EOL> msg += '<STR_LIT>' % ( str ( self . amount ) ) <EOL> if self . label is not None : <EOL> encoded_label = quote ( self . label ) <EOL> msg += '<STR_LIT>' % ( encoded_label ) <EOL> elif self . label is not None : <EOL> encoded_label = quote ( self . label ) <EOL> msg += '<STR_LIT>' % ( encoded_label ) <EOL> self . qrw . set_addr ( msg ) <EOL> class Plugin ( BasePlugin ) : <EOL> def fullname ( self ) : <EOL> return '<STR_LIT>' <EOL> def description ( self ) : <EOL> return _ ( '<STR_LIT>' ) + _ ( '<STR_LIT>' ) <EOL> def init ( self ) : <EOL> self . window = self . gui . main_window <EOL> self . wallet = self . window . wallet <EOL> self . qr_window = None <EOL> self . merchant_name = self . config . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . window . expert_mode = True <EOL> self . window . receive_list . setColumnCount ( <NUM_LIT:5> ) <EOL> self . window . receive_list . setHeaderLabels ( [ _ ( '<STR_LIT>' ) , _ ( '<STR_LIT>' ) , _ ( '<STR_LIT>' ) , _ ( '<STR_LIT>' ) , _ ( '<STR_LIT>' ) ] ) <EOL> self . requested_amounts = { } <EOL> self . toggle_QR_window ( True ) <EOL> def enable ( self ) : <EOL> if not self . config . get ( '<STR_LIT>' ) : <EOL> self . gui . main_window . show_message ( "<STR_LIT>" ) <EOL> return False <EOL> return BasePlugin . enable ( self ) <EOL> def load_wallet ( self , wallet ) : <EOL> self . wallet = wallet <EOL> self . requested_amounts = self . wallet . storage . get ( '<STR_LIT>' , { } ) <EOL> def close ( self ) : <EOL> self . window . receive_list . setHeaderLabels ( [ _ ( '<STR_LIT>' ) , _ ( '<STR_LIT>' ) , _ ( '<STR_LIT>' ) , _ ( '<STR_LIT>' ) ] ) <EOL> self . window . receive_list . setColumnCount ( <NUM_LIT:4> ) <EOL> for i , width in enumerate ( self . window . column_widths [ '<STR_LIT>' ] ) : <EOL> self . window . receive_list . setColumnWidth ( i , width ) <EOL> self . toggle_QR_window ( False ) <EOL> def close_main_window ( self ) : <EOL> if self . qr_window : <EOL> self . qr_window . close ( ) <EOL> self . qr_window = None <EOL> def timer_actions ( self ) : <EOL> if self . qr_window : <EOL> self . qr_window . qrw . update_qr ( ) <EOL> def toggle_QR_window ( self , show ) : <EOL> if show and not self . qr_window : <EOL> self . qr_window = QR_Window ( self . gui . exchanger ) <EOL> self . qr_window . setVisible ( True ) <EOL> self . qr_window_geometry = self . qr_window . geometry ( ) <EOL> item = self . window . receive_list . currentItem ( ) <EOL> if item : <EOL> address = str ( item . text ( <NUM_LIT:1> ) ) <EOL> label = self . wallet . labels . get ( address ) <EOL> amount , currency = self . requested_amounts . get ( address , ( None , None ) ) <EOL> self . qr_window . set_content ( address , label , amount , currency ) <EOL> elif show and self . qr_window and not self . qr_window . isVisible ( ) : <EOL> self . qr_window . setVisible ( True ) <EOL> self . qr_window . setGeometry ( self . qr_window_geometry ) <EOL> elif not show and self . qr_window and self . qr_window . isVisible ( ) : <EOL> self . qr_window_geometry = self . qr_window . geometry ( ) <EOL> self . qr_window . setVisible ( False ) <EOL> def update_receive_item ( self , address , item ) : <EOL> try : <EOL> amount , currency = self . requested_amounts . get ( address , ( None , None ) ) <EOL> except Exception : <EOL> print "<STR_LIT>" , address , self . requested_amounts . get ( address ) <EOL> amount , currency = None , None <EOL> self . requested_amounts . pop ( address ) <EOL> amount_str = amount + ( '<STR_LIT:U+0020>' + currency if currency else '<STR_LIT>' ) if amount is not None else '<STR_LIT>' <EOL> item . setData ( column_index , <NUM_LIT:0> , amount_str ) <EOL> def current_item_changed ( self , a ) : <EOL> if not self . wallet : <EOL> return <EOL> if a is not None and self . qr_window and self . qr_window . isVisible ( ) : <EOL> address = str ( a . text ( <NUM_LIT:0> ) ) <EOL> label = self . wallet . labels . get ( address ) <EOL> try : <EOL> amount , currency = self . requested_amounts . get ( address , ( None , None ) ) <EOL> except Exception : <EOL> amount , currency = None , None <EOL> self . qr_window . set_content ( address , label , amount , currency ) <EOL> def item_changed ( self , item , column ) : <EOL> if column != column_index : <EOL> return <EOL> address = str ( item . text ( <NUM_LIT:0> ) ) <EOL> text = str ( item . text ( column ) ) <EOL> try : <EOL> seq = self . wallet . get_address_index ( address ) <EOL> index = seq [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> except Exception : <EOL> print "<STR_LIT>" <EOL> return <EOL> text = text . strip ( ) . upper ( ) <EOL> m = re . match ( '<STR_LIT>' , text ) <EOL> if m and m . group ( <NUM_LIT:1> ) and m . group ( <NUM_LIT:1> ) != '<STR_LIT:.>' : <EOL> amount = m . group ( <NUM_LIT:1> ) <EOL> currency = m . group ( <NUM_LIT:3> ) <EOL> if not currency : <EOL> currency = '<STR_LIT>' <EOL> else : <EOL> currency = currency . upper ( ) <EOL> self . requested_amounts [ address ] = ( amount , currency ) <EOL> self . wallet . storage . put ( '<STR_LIT>' , self . requested_amounts , True ) <EOL> label = self . wallet . labels . get ( address ) <EOL> if label is None : <EOL> label = self . merchant_name + '<STR_LIT>' % ( index + <NUM_LIT:1> ) <EOL> self . wallet . labels [ address ] = label <EOL> if self . qr_window : <EOL> self . qr_window . set_content ( address , label , amount , currency ) <EOL> else : <EOL> item . setText ( column , '<STR_LIT>' ) <EOL> if address in self . requested_amounts : <EOL> self . requested_amounts . pop ( address ) <EOL> self . window . update_receive_item ( self . window . receive_list . currentItem ( ) ) <EOL> def edit_amount ( self ) : <EOL> l = self . window . receive_list <EOL> item = l . currentItem ( ) <EOL> item . setFlags ( Qt . ItemIsEditable | Qt . ItemIsSelectable | Qt . ItemIsUserCheckable | Qt . ItemIsEnabled | Qt . ItemIsDragEnabled ) <EOL> l . editItem ( item , column_index ) <EOL> item . setFlags ( Qt . ItemIsSelectable | Qt . ItemIsUserCheckable | Qt . ItemIsEnabled | Qt . ItemIsDragEnabled ) <EOL> def receive_menu ( self , menu , addr ) : <EOL> menu . addAction ( _ ( "<STR_LIT>" ) , self . edit_amount ) <EOL> menu . addAction ( _ ( "<STR_LIT>" ) , lambda : self . toggle_QR_window ( True ) ) </s>
