<s> from PySide import QtCore , QtGui <EOL> from androguard . session import Session <EOL> from androguard . core import androconf <EOL> from androguard . gui . fileloading import FileLoadingThread <EOL> from androguard . gui . treewindow import TreeWindow <EOL> from androguard . gui . sourcewindow import SourceWindow <EOL> from androguard . gui . stringswindow import StringsWindow <EOL> from androguard . gui . helpers import class2func <EOL> import os <EOL> class MainWindow ( QtGui . QMainWindow ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , parent = None , session = Session ( ) , input_file = None ) : <EOL> super ( MainWindow , self ) . __init__ ( parent ) <EOL> self . session = session <EOL> self . setupSession ( ) <EOL> self . setupFileMenu ( ) <EOL> self . setupViewMenu ( ) <EOL> self . setupHelpMenu ( ) <EOL> self . setupCentral ( ) <EOL> self . setupEmptyTree ( ) <EOL> self . setupDock ( ) <EOL> self . setWindowTitle ( "<STR_LIT>" ) <EOL> self . showStatus ( "<STR_LIT>" ) <EOL> if input_file != None : <EOL> self . openFile ( input_file ) <EOL> def showStatus ( self , msg ) : <EOL> '''<STR_LIT>''' <EOL> androconf . debug ( msg ) <EOL> self . statusBar ( ) . showMessage ( msg ) <EOL> def about ( self ) : <EOL> '''<STR_LIT>''' <EOL> QtGui . QMessageBox . about ( self , "<STR_LIT>" , <EOL> "<STR_LIT>" "<STR_LIT>" ) <EOL> def setupSession ( self ) : <EOL> self . fileLoadingThread = FileLoadingThread ( self . session ) <EOL> self . connect ( self . fileLoadingThread , QtCore . SIGNAL ( "<STR_LIT>" ) , <EOL> self . loadedFile ) <EOL> def loadedFile ( self , success ) : <EOL> if not success : <EOL> self . showStatus ( "<STR_LIT>" % <EOL> str ( self . fileLoadingThread . file_path ) ) <EOL> return <EOL> self . updateDockWithTree ( ) <EOL> self . cleanCentral ( ) <EOL> self . showStatus ( "<STR_LIT>" % <EOL> str ( self . fileLoadingThread . file_path ) ) <EOL> def openFile ( self , path = None ) : <EOL> '''<STR_LIT>''' <EOL> self . session . reset ( ) <EOL> if not path : <EOL> path = QtGui . QFileDialog . getOpenFileName ( <EOL> self , "<STR_LIT>" , '<STR_LIT>' , <EOL> "<STR_LIT>" ) <EOL> path = str ( path [ <NUM_LIT:0> ] ) <EOL> if path : <EOL> self . setupTree ( ) <EOL> self . showStatus ( "<STR_LIT>" % str ( path ) ) <EOL> self . fileLoadingThread . load ( path ) <EOL> def addFile ( self , path = None ) : <EOL> '''<STR_LIT>''' <EOL> if not self . session . isOpen ( ) : <EOL> return <EOL> if not path : <EOL> path = QtGui . QFileDialog . getOpenFileName ( <EOL> self , "<STR_LIT>" , '<STR_LIT>' , <EOL> "<STR_LIT>" ) <EOL> path = str ( path [ <NUM_LIT:0> ] ) <EOL> if path : <EOL> self . showStatus ( "<STR_LIT>" % str ( path ) ) <EOL> self . fileLoadingThread . load ( path ) <EOL> def saveFile ( self , path = None ) : <EOL> '''<STR_LIT>''' <EOL> if not path : <EOL> path = QtGui . QFileDialog . getSaveFileName ( <EOL> self , "<STR_LIT>" , '<STR_LIT>' , "<STR_LIT>" ) <EOL> path = str ( path [ <NUM_LIT:0> ] ) <EOL> if path : <EOL> self . showStatus ( "<STR_LIT>" % str ( path ) ) <EOL> self . saveSession ( path ) <EOL> def saveSession ( self , path ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> self . session . save ( path ) <EOL> except RuntimeError , e : <EOL> androconf . error ( str ( e ) ) <EOL> androconf . error ( "<STR_LIT>" ) <EOL> os . remove ( path ) <EOL> androconf . warning ( "<STR_LIT>" ) <EOL> def quit ( self ) : <EOL> '''<STR_LIT>''' <EOL> QtGui . qApp . quit ( ) <EOL> def closeEvent ( self , event ) : <EOL> '''<STR_LIT>''' <EOL> event . accept ( ) <EOL> def setupEmptyTree ( self ) : <EOL> '''<STR_LIT>''' <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> del self . tree <EOL> self . tree = QtGui . QTreeWidget ( self ) <EOL> self . tree . header ( ) . close ( ) <EOL> def setupDock ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . dock = QtGui . QDockWidget ( "<STR_LIT>" , self ) <EOL> self . dock . setWidget ( self . tree ) <EOL> self . dock . setFeatures ( QtGui . QDockWidget . NoDockWidgetFeatures ) <EOL> self . addDockWidget ( QtCore . Qt . LeftDockWidgetArea , self . dock ) <EOL> def setupTree ( self ) : <EOL> androconf . debug ( "<STR_LIT>" ) <EOL> self . tree = TreeWindow ( win = self , session = self . session ) <EOL> self . tree . setWindowTitle ( "<STR_LIT>" ) <EOL> self . dock . setWidget ( self . tree ) <EOL> def setupCentral ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . central = QtGui . QTabWidget ( ) <EOL> self . central . setTabsClosable ( True ) <EOL> self . central . tabCloseRequested . connect ( self . tabCloseRequestedHandler ) <EOL> self . central . currentChanged . connect ( self . currentTabChanged ) <EOL> self . setCentralWidget ( self . central ) <EOL> def tabCloseRequestedHandler ( self , index ) : <EOL> self . central . removeTab ( index ) <EOL> def currentTabChanged ( self , index ) : <EOL> androconf . debug ( "<STR_LIT>" % index ) <EOL> if index == - <NUM_LIT:1> : <EOL> return <EOL> def cleanCentral ( self ) : <EOL> self . central . clear ( ) <EOL> def setupFileMenu ( self ) : <EOL> fileMenu = QtGui . QMenu ( "<STR_LIT>" , self ) <EOL> self . menuBar ( ) . addMenu ( fileMenu ) <EOL> fileMenu . addAction ( "<STR_LIT>" , self . openFile , "<STR_LIT>" ) <EOL> fileMenu . addAction ( "<STR_LIT>" , self . addFile , "<STR_LIT>" ) <EOL> fileMenu . addAction ( "<STR_LIT>" , self . saveFile , "<STR_LIT>" ) <EOL> fileMenu . addAction ( "<STR_LIT>" , self . quit , "<STR_LIT>" ) <EOL> def setupViewMenu ( self ) : <EOL> viewMenu = QtGui . QMenu ( "<STR_LIT>" , self ) <EOL> self . menuBar ( ) . addMenu ( viewMenu ) <EOL> viewMenu . addAction ( "<STR_LIT>" , self . openStringsWindow ) <EOL> def setupHelpMenu ( self ) : <EOL> helpMenu = QtGui . QMenu ( "<STR_LIT>" , self ) <EOL> self . menuBar ( ) . addMenu ( helpMenu ) <EOL> helpMenu . addAction ( "<STR_LIT>" , self . about ) <EOL> helpMenu . addAction ( "<STR_LIT>" , QtGui . qApp . aboutQt ) <EOL> def updateDockWithTree ( self , empty = False ) : <EOL> '''<STR_LIT>''' <EOL> self . setupTree ( ) <EOL> self . tree . fill ( ) <EOL> def openStringsWindow ( self ) : <EOL> stringswin = StringsWindow ( win = self , session = self . session ) <EOL> self . central . addTab ( stringswin , stringswin . title ) <EOL> self . central . setTabToolTip ( self . central . indexOf ( stringswin ) , <EOL> stringswin . title ) <EOL> self . central . setCurrentWidget ( stringswin ) <EOL> def openBytecodeWindow ( self , current_class , method = None ) : <EOL> pass <EOL> def openSourceWindow ( self , current_class , method = None ) : <EOL> '''<STR_LIT>''' <EOL> androconf . debug ( "<STR_LIT>" % current_class ) <EOL> sourcewin = self . getMeSourceWindowIfExists ( current_class ) <EOL> if not sourcewin : <EOL> current_filename = self . session . get_filename_by_class ( current_class ) <EOL> current_digest = self . session . get_digest_by_class ( current_class ) <EOL> sourcewin = SourceWindow ( win = self , <EOL> current_class = current_class , <EOL> current_title = current_class . current_title , <EOL> current_filename = current_filename , <EOL> current_digest = current_digest , <EOL> session = self . session ) <EOL> sourcewin . reload_java_sources ( ) <EOL> self . central . addTab ( sourcewin , sourcewin . title ) <EOL> self . central . setTabToolTip ( self . central . indexOf ( sourcewin ) , <EOL> current_class . get_name ( ) ) <EOL> if method : <EOL> sourcewin . browse_to_method ( method ) <EOL> self . central . setCurrentWidget ( sourcewin ) <EOL> def getMeSourceWindowIfExists ( self , current_class ) : <EOL> '''<STR_LIT>''' <EOL> for idx in range ( self . central . count ( ) ) : <EOL> if current_class . get_name ( ) == self . central . tabToolTip ( idx ) : <EOL> androconf . debug ( "<STR_LIT>" % <EOL> ( current_class . get_name ( ) , idx ) ) <EOL> return self . central . widget ( idx ) <EOL> return None <EOL> def doesClassExist ( self , path ) : <EOL> arg = class2func ( path ) <EOL> try : <EOL> getattr ( self . d , arg ) <EOL> except AttributeError : <EOL> return False <EOL> return True </s>
