<s> from PyQt4 import QtGui , QtCore <EOL> import sys <EOL> from threading import Thread <EOL> from LLAMA import Ui_Lake_Level_UI <EOL> from plot_water_levelui import * <EOL> from lake_measure import * <EOL> class ProgressPopup ( QtGui . QWidget ) : <EOL> update_signal = QtCore . pyqtSignal ( int , int , str , str , int , int ) <EOL> def __init__ ( self , cancel_function ) : <EOL> QtGui . QWidget . __init__ ( self ) <EOL> self . update_signal . connect ( self . apply_update , QtCore . Qt . QueuedConnection ) <EOL> self . cancel_function = cancel_function <EOL> self . lake_totals = None <EOL> self . lake_counts = None <EOL> self . progressBar = QtGui . QProgressBar ( self ) <EOL> self . progressBar . setMinimumSize ( <NUM_LIT> , <NUM_LIT:50> ) <EOL> self . progressBar . setMaximumSize ( <NUM_LIT> , <NUM_LIT:50> ) <EOL> self . progressBar . setRange ( <NUM_LIT:0> , <NUM_LIT:100> ) <EOL> self . progressBar . setValue ( <NUM_LIT:0> ) <EOL> self . status = QtGui . QLabel ( self ) <EOL> self . status . setText ( "<STR_LIT>" ) <EOL> self . cancelButton = QtGui . QPushButton ( '<STR_LIT>' , self ) <EOL> self . cancelButton . setMinimumSize ( <NUM_LIT:50> , <NUM_LIT:30> ) <EOL> self . cancelButton . setMaximumSize ( <NUM_LIT:100> , <NUM_LIT:50> ) <EOL> self . cancelButton . clicked [ bool ] . connect ( self . _cancel ) <EOL> vbox = QtGui . QVBoxLayout ( self ) <EOL> vbox . addWidget ( self . progressBar ) <EOL> vbox . addWidget ( self . status ) <EOL> vbox . addWidget ( self . cancelButton ) <EOL> vbox . addStretch ( <NUM_LIT:1> ) <EOL> self . setLayout ( vbox ) <EOL> def update_function ( self , lakes_number , lakes_total , lake_name , lake_date , lake_image , lake_image_total ) : <EOL> self . update_signal . emit ( lakes_number , lakes_total , lake_name , lake_date , lake_image , lake_image_total ) <EOL> def apply_update ( self , lakes_number , lakes_total , lake_name , lake_date , lake_image , lake_image_total ) : <EOL> if self . lake_totals == None : <EOL> self . lake_totals = [ <NUM_LIT:10> ] * lakes_total <EOL> self . lake_counts = [ <NUM_LIT:0> ] * lakes_total <EOL> self . lake_totals [ lakes_number ] = lake_image_total <EOL> self . lake_counts [ lakes_number ] = lake_image <EOL> total = sum ( self . lake_totals ) <EOL> progress = sum ( self . lake_counts ) <EOL> self . status . setText ( '<STR_LIT>' % ( lake_name , lake_date ) ) <EOL> self . progressBar . setValue ( float ( progress ) / total * <NUM_LIT:100> ) <EOL> def closeEvent ( self , event ) : <EOL> if self . cancel_function != None : <EOL> self . cancel_function ( ) <EOL> event . accept ( ) <EOL> def _cancel ( self ) : <EOL> self . close ( ) <EOL> class Lake_Level_App ( QtGui . QMainWindow , Ui_Lake_Level_UI ) : <EOL> def __init__ ( self ) : <EOL> super ( self . __class__ , self ) . __init__ ( ) <EOL> self . setupUi ( self ) <EOL> self . start_date = '<STR_LIT>' <EOL> self . end_date = str ( ( QtCore . QDate . currentDate ( ) ) . toString ( '<STR_LIT>' ) ) <EOL> self . selected_lake = '<STR_LIT>' <EOL> self . selectlakeDropMenu . activated [ str ] . connect ( self . selectLakeHandle ) <EOL> self . okBtn . clicked . connect ( self . okHandle ) <EOL> self . endDate . setDate ( QtCore . QDate . currentDate ( ) ) <EOL> self . endDate . dateChanged [ QtCore . QDate ] . connect ( self . endHandle ) <EOL> self . startDate . dateChanged [ QtCore . QDate ] . connect ( self . startHandle ) <EOL> self . faiState = False <EOL> self . ndtiState = False <EOL> def selectLakeHandle ( self , text ) : <EOL> self . selected_lake = str ( text ) <EOL> def startHandle ( self , date ) : <EOL> self . start_date = str ( date . toString ( '<STR_LIT>' ) ) <EOL> def endHandle ( self , date ) : <EOL> self . end_date = str ( date . toString ( '<STR_LIT>' ) ) <EOL> def okHandle ( self ) : <EOL> if self . algaeCheckbox . isChecked ( ) : <EOL> self . faiState = True <EOL> else : <EOL> self . faiState = False <EOL> if self . turbidityCheckbox . isChecked ( ) : <EOL> self . ndtiState = True <EOL> else : <EOL> self . ndtiState = False <EOL> self . popup = ProgressPopup ( Lake_Level_Cancel ) <EOL> self . lake_thread = Thread ( target = Lake_Level_Run , args = ( self . selected_lake , self . start_date , self . end_date , '<STR_LIT>' , self . faiState , self . ndtiState , self . popup . update_function , self . popup . close ) ) <EOL> self . popup . show ( ) <EOL> self . lake_thread . start ( ) <EOL> if self . tableCheckbox . isChecked ( ) : <EOL> table_water_level ( self . selected_lake , self . start_date , self . end_date , result_dir = '<STR_LIT>' ) <EOL> if self . graphCheckbox . isChecked ( ) : <EOL> plot_water_level ( self . selected_lake , self . start_date , self . end_date , result_dir = '<STR_LIT>' ) <EOL> def main ( ) : <EOL> app = QtGui . QApplication ( sys . argv ) <EOL> form = Lake_Level_App ( ) <EOL> form . show ( ) <EOL> app . exec_ ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
