<s> import collections <EOL> from PyQt4 import QtGui , uic <EOL> from wallet import wallet <EOL> from decimal import Decimal <EOL> from ngcccbase import sanitize <EOL> class SendcoinsEntry ( QtGui . QFrame ) : <EOL> def __init__ ( self , page ) : <EOL> QtGui . QFrame . __init__ ( self ) <EOL> uic . loadUi ( uic . getUiPath ( '<STR_LIT>' ) , self ) <EOL> self . page = page <EOL> for wname in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> def clearBackground ( event , wname = wname ) : <EOL> widget = getattr ( self , wname ) <EOL> widget . setStyleSheet ( '<STR_LIT>' ) <EOL> widget . __class__ . focusInEvent ( widget , event ) <EOL> getattr ( self , wname ) . focusInEvent = clearBackground <EOL> self . cbMoniker . activated . connect ( self . updateAvailableBalance ) <EOL> self . btnPaste . clicked . connect ( self . btnPasteClicked ) <EOL> self . btnDelete . clicked . connect ( self . btnDeleteClicked ) <EOL> self . update ( ) <EOL> def update ( self ) : <EOL> monikers = wallet . get_all_monikers ( ) <EOL> monikers . remove ( '<STR_LIT>' ) <EOL> monikers = [ '<STR_LIT>' ] + monikers <EOL> comboList = self . cbMoniker <EOL> currentMoniker = str ( comboList . currentText ( ) ) <EOL> comboList . clear ( ) <EOL> comboList . addItems ( monikers ) <EOL> if currentMoniker and currentMoniker in monikers : <EOL> comboList . setCurrentIndex ( monikers . index ( currentMoniker ) ) <EOL> self . updateAvailableBalance ( ) <EOL> def updateAvailableBalance ( self ) : <EOL> moniker = str ( self . cbMoniker . currentText ( ) ) <EOL> if moniker : <EOL> asset = wallet . get_asset_definition ( moniker ) <EOL> balance = wallet . get_available_balance ( moniker ) <EOL> self . edtAmount . setMaximum ( balance ) <EOL> self . lblAvailaleBalance . setText ( <EOL> '<STR_LIT>' % ( asset . format_value ( balance ) , moniker ) ) <EOL> def btnPasteClicked ( self ) : <EOL> self . edtAddress . setText ( QtGui . QApplication . clipboard ( ) . text ( ) ) <EOL> def btnDeleteClicked ( self ) : <EOL> self . close ( ) <EOL> self . page . entries . takeAt ( self . page . entries . indexOf ( self ) ) <EOL> self . page . entries . itemAt ( <NUM_LIT:0> ) . widget ( ) . btnDelete . setEnabled ( <EOL> self . page . entries . count ( ) > <NUM_LIT:1> ) <EOL> def edtAddressValidate ( self ) : <EOL> valid = True <EOL> if len ( str ( self . edtAddress . text ( ) ) ) < <NUM_LIT:30> : <EOL> valid = False <EOL> self . edtAddress . setStyleSheet ( '<STR_LIT>' ) <EOL> else : <EOL> self . edtAddress . setStyleSheet ( '<STR_LIT>' ) <EOL> return valid <EOL> def edtAmountValidate ( self ) : <EOL> valid = True <EOL> if self . edtAmount . value ( ) == <NUM_LIT:0> : <EOL> valid = False <EOL> self . edtAmount . setStyleSheet ( '<STR_LIT>' ) <EOL> else : <EOL> self . edtAmount . setStyleSheet ( '<STR_LIT>' ) <EOL> return valid <EOL> def isValid ( self ) : <EOL> return all ( [ self . edtAddressValidate ( ) , self . edtAmountValidate ( ) ] ) <EOL> def getData ( self ) : <EOL> moniker = str ( self . cbMoniker . currentText ( ) ) <EOL> asset = wallet . get_asset_definition ( moniker ) <EOL> value = asset . parse_value ( str ( self . edtAmount . value ( ) ) ) <EOL> return { <EOL> '<STR_LIT:address>' : str ( self . edtAddress . text ( ) ) , <EOL> '<STR_LIT:value>' : value , <EOL> '<STR_LIT>' : moniker , <EOL> } <EOL> class SendcoinsPage ( QtGui . QWidget ) : <EOL> def __init__ ( self , parent ) : <EOL> QtGui . QWidget . __init__ ( self , parent ) <EOL> uic . loadUi ( uic . getUiPath ( '<STR_LIT>' ) , self ) <EOL> self . btnClearAll . clicked . connect ( self . btnClearAllClicked ) <EOL> self . btnSend . clicked . connect ( self . btnSendClicked ) <EOL> self . btnBatchSendCSV . clicked . connect ( self . btnBatchSendCSVClicked ) <EOL> self . btnAddRecipientClicked ( ) <EOL> def update ( self ) : <EOL> for i in xrange ( self . entries . count ( ) ) : <EOL> self . entries . itemAt ( i ) . widget ( ) . update ( ) <EOL> def btnAddRecipientClicked ( self ) : <EOL> self . entries . addWidget ( SendcoinsEntry ( self ) ) <EOL> self . entries . itemAt ( <NUM_LIT:0> ) . widget ( ) . btnDelete . setEnabled ( <EOL> self . entries . count ( ) > <NUM_LIT:1> ) <EOL> def btnClearAllClicked ( self ) : <EOL> while True : <EOL> layout = self . entries . takeAt ( <NUM_LIT:0> ) <EOL> if layout is None : <EOL> break <EOL> layout . widget ( ) . close ( ) <EOL> self . btnAddRecipientClicked ( ) <EOL> def btnBatchSendCSVClicked ( self ) : <EOL> wc = wallet . controller <EOL> QMB = QtGui . QMessageBox <EOL> msg = '<STR_LIT>' <EOL> path = QtGui . QFileDialog . getOpenFileName ( self , msg ) <EOL> if not path : <EOL> return <EOL> options = QMB . Yes | QMB . Cancel <EOL> title = '<STR_LIT>' <EOL> msg = '<STR_LIT>' <EOL> entries = sanitize . sendmanycsv ( wc . model , path ) <EOL> for asset , amount in wc . sendmany_sums ( entries ) . items ( ) : <EOL> msg += "<STR_LIT>" . format ( ** { <EOL> '<STR_LIT:value>' : asset . format_value ( amount ) , <EOL> '<STR_LIT>' : asset . get_monikers ( ) [ <NUM_LIT:0> ] , <EOL> } ) <EOL> if QMB . question ( self , title , msg , options , QMB . Cancel ) != QMB . Yes : <EOL> return <EOL> wc . sendmany_coins ( entries ) <EOL> def btnSendClicked ( self ) : <EOL> entries = [ self . entries . itemAt ( i ) . widget ( ) <EOL> for i in xrange ( self . entries . count ( ) ) ] <EOL> if not all ( [ entry . isValid ( ) for entry in entries ] ) : <EOL> return <EOL> data = [ entry . getData ( ) for entry in entries ] <EOL> message = '<STR_LIT>' <EOL> for recipient in data : <EOL> asset = wallet . get_asset_definition ( recipient [ '<STR_LIT>' ] ) <EOL> value = asset . format_value ( recipient [ '<STR_LIT:value>' ] ) <EOL> message += '<STR_LIT>' . format ( ** { <EOL> '<STR_LIT:value>' : value , <EOL> '<STR_LIT>' : '<STR_LIT>' if recipient [ '<STR_LIT>' ] == '<STR_LIT>' else recipient [ '<STR_LIT>' ] , <EOL> '<STR_LIT:address>' : recipient [ '<STR_LIT:address>' ] , <EOL> } ) <EOL> message += '<STR_LIT:?>' <EOL> retval = QtGui . QMessageBox . question ( <EOL> self , '<STR_LIT>' , <EOL> message , <EOL> QtGui . QMessageBox . Yes | QtGui . QMessageBox . Cancel , <EOL> QtGui . QMessageBox . Cancel ) <EOL> if retval != QtGui . QMessageBox . Yes : <EOL> return <EOL> currency = collections . defaultdict ( Decimal ) <EOL> for recipient in data : <EOL> currency [ recipient [ '<STR_LIT>' ] ] += recipient [ '<STR_LIT:value>' ] <EOL> for moniker , value in currency . items ( ) : <EOL> if value > wallet . get_available_balance ( moniker ) : <EOL> QtGui . QMessageBox . warning ( <EOL> self , '<STR_LIT>' , <EOL> '<STR_LIT>' % moniker , <EOL> QtGui . QMessageBox . Ok ) <EOL> return <EOL> wallet . send_coins ( data ) <EOL> self . parent ( ) . parent ( ) . parent ( ) . update ( ) </s>
