示例#1
0
 def create_rev_action(self, repo, *revs):
     action = QAction(self.revs_menu)
     action.revs = revs
     action.setText(', '.join(str(rev) for rev in revs))
     action.setCheckable(True)
     action.setActionGroup(self.rev_actions)
     action.triggered.connect(self._revs_action_triggered)
     return action
    def popup(self,pos):
        menu = QMenu()

        saveRepAction = QAction(self)
        saveRepAction.setText('Save representation...')
        saveRepAction.triggered.connect(lambda: self.saveRep(self.indexAt(pos)))
        menu.addAction(saveRepAction)
        action = menu.exec_(self.mapToGlobal(pos))
示例#3
0
    def __LobbyListMenu( self, position ):
        lobby_menu      = QMenu()

        rm_from_lobby   = QAction( self )
        rm_from_lobby.setText( "Remove player from lobby" )
        rm_from_lobby.triggered.connect( self._RemoveFromLobbyListAction )

        lobby_menu.addAction( rm_from_lobby )

        lobby_menu.exec_( self.window.lobby_lst.viewport().mapToGlobal( position ) )
    def showHeaderMenu( self, pos ):
        header = self.horizontalHeader()
        column = header.logicalIndexAt(pos.x())

        filterAction = QAction(self)
        filterAction.setText('Filter column')
        filterAction.triggered.connect(lambda: self.filterColumn(self.indexAt(pos)))
        symbolAction = QAction(self)
        symbolAction.setText('Symbol')
        symbolAction.triggered.connect(lambda: self.changeColumnDisplay(self.indexAt(pos),'symbol'))
        colourAction = QAction(self)
        colourAction.setText('Color')
        colourAction.triggered.connect(lambda: self.changeColumnDisplay(self.indexAt(pos),'brush'))
        sizeAction = QAction(self)
        sizeAction.setText('Size')
        sizeAction.triggered.connect(lambda: self.changeColumnDisplay(self.indexAt(pos),'size'))
        # show menu about the column
        menu = QMenu(self)
        displayMenu = menu.addMenu('Change graph display')
        displayMenu.addAction(symbolAction)
        displayMenu.addAction(colourAction)
        displayMenu.addAction(sizeAction)
        menu.addAction(filterAction)

        menu.popup(header.mapToGlobal(pos))
示例#5
0
    def __PlayersListMenu( self, position ):
        list_menu           = QMenu()

        add_player_to_lobby = QAction( self )
        add_player_to_lobby.setText( "Add player to lobby" )
        add_player_to_lobby.triggered.connect( self._AddToLobbyAction )

        rm_player           = QAction( self )
        rm_player.setText( "Remove player" )
        rm_player.triggered.connect( self._RemoveFromPlayersListAction )

        list_menu.addAction( rm_player )
        list_menu.addAction( add_player_to_lobby )

        list_menu.exec_( self.window.players_lst.viewport().mapToGlobal( position ) )
示例#6
0
 def addDeleteWidgetAction(self, widget):
     """
     Add the delete action for the given widget in the delete widget menu.
     
     Parameter:
     
     - widget: The pysumo widget which will be deleted on action triggered.
     """
     action = QAction(widget)
     action.setText(widget.windowTitle())
     callback = partial(self._deleteWidget_, widget)
     action.triggered.connect(callback)
     if not self.menuDelete.isEnabled():
         self.menuDelete.setEnabled(True)
     self.menuDelete.addAction(action)
示例#7
0
 def _customMenu(self):
     selectedItems = self.pushupsListWidget.selectedItems()
     
     if selectedItems is not None :
         selectedItem = selectedItems[0] 
         
         if selectedItem.parent() is not None : # Child Item selected
             menu = QMenu()
             
             delete = QAction(self.pushupsListWidget)
             delete.setText("Delete this pushup")
             delete.triggered.connect(self._emitDeleteSignal)
             menu.addAction(delete)
             menu.exec_(QCursor.pos())
         else : # Top level Item selected
             menu = QMenu()
          
             delete = QAction(self.pushupsListWidget)
             delete.setText("Delete this day and all of its exercises")
             delete.triggered.connect(self._emitDeleteDaySignal)
             menu.addAction(delete)
             menu.exec_(QCursor.pos())
示例#8
0
    def _customMenu(self):
        selectedItems = self.pushupsListWidget.selectedItems()

        if selectedItems is not None:
            selectedItem = selectedItems[0]

            if selectedItem.parent() is not None:  # Child Item selected
                menu = QMenu()

                delete = QAction(self.pushupsListWidget)
                delete.setText("Delete this pushup")
                delete.triggered.connect(self._emitDeleteSignal)
                menu.addAction(delete)
                menu.exec_(QCursor.pos())
            else:  # Top level Item selected
                menu = QMenu()

                delete = QAction(self.pushupsListWidget)
                delete.setText("Delete this day and all of its exercises")
                delete.triggered.connect(self._emitDeleteDaySignal)
                menu.addAction(delete)
                menu.exec_(QCursor.pos())
示例#9
0
 def addRecentOntology(self, ontology):
     count = len(self.menuRecent_Ontologies.actions())
     count = count - 2  # remove the separator action and the clear history action.
     name = str(count + 1)
     name += ". "
     name += ontology.name
     name += ".kif"
     found = False
     for a in self.menuRecent_Ontologies.actions():
         o = a.data()
         if o is None:
             continue
         if o.__eq__(ontology):
             found = True
             break
     if not found:
         befAction = self.menuRecent_Ontologies.actions()[count]
         action = QAction(self.menuRecent_Ontologies)
         action.setText(name)
         action.setData(ontology)
         callback = partial(self.addOntology, ontology)
         action.triggered.connect(callback)
         self.menuRecent_Ontologies.insertAction(befAction, action)
示例#10
0
class serverManagerWindow(QMainWindow):
    def __init__(self, _app, parent=None):
        QMainWindow.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.iTrayIcon = QSystemTrayIcon()
        self.iTrayIcon.setIcon(QIcon("drapes.ico"))
        self.iTrayIcon.show()
        self.iTrayIcon.setToolTip("One world, One dream!")
        self.iTrayIcon.activated.connect(self.iconActivated)
        self.quitAction = QAction("&Quit", self, triggered=QApplication.quit)
        self.trayIconMenu = QMenu(self)
        self.trayIconMenu.addAction(self.quitAction)
        self.iTrayIcon.setContextMenu(self.trayIconMenu)

        #选择MYSQL保留用户信息
        QObject.connect(self.ui.mysql_groupBox, SIGNAL("clicked()"), self, SLOT("choiceSql()"))
        #选择XT文件留用户信息
        QObject.connect(self.ui.text_groupBox, SIGNAL("clicked()"), self, SLOT("choiceTxt()"))
        #选择XML文件留用户信息
        QObject.connect(self.ui.xml_groupBox, SIGNAL("clicked()"), self, SLOT("choiceXml()"))                
        #节面显示英文
        QObject.connect(self.ui.actionEnglish, SIGNAL("activated()"), self, SLOT("loadEnglish()"))
        #节面显示中文
        QObject.connect(self.ui.actionChinese, SIGNAL("activated()"), self, SLOT("loadChinese()"))
        
        #加载配置文件
        QObject.connect(self.ui.actionLoad_Config, SIGNAL("activated()"), self, SLOT("loadConfig()"))
        #保留配置文件
        QObject.connect(self.ui.actionSave_Config, SIGNAL("activated()"), self, SLOT("saveConfig()"))
        #about操作
        QObject.connect(self.ui.actionAbout, SIGNAL("activated()"), self, SLOT("about()"))
        
        #选择XML文件
        QObject.connect(self.ui.openXml_pushButton, SIGNAL("clicked()"), self, SLOT("xml_open()"))
        #选择TXT文件
        QObject.connect(self.ui.openText_pushButton, SIGNAL("clicked()"), self, SLOT("txt_open()"))
        #启动服务
        QObject.connect(self.ui.startServer_pushButton, SIGNAL("clicked()"), self, SLOT("startServer()"))
        #停止服务
        QObject.connect(self.ui.stopServer_pushButton, SIGNAL("clicked()"), self, SLOT("stopServer()"))

        self.ui.sqlTypeComboBox.activated[str].connect(self.sqlServer)
                
        QObject.connect(self.ui.openSqlpushButton, SIGNAL("clicked()"), self, SLOT("database_open()"))
        

        #界面语言
        self.translator = None
        self.app = _app
        self.translator = QTranslator() 
        self.connect = None
        self.users = None
        self.ControlMediaPath = None
        self.ControlMedia = None
        self.delUsrInfo = None

        self.userModel = QStandardItemModel()
        self.userModel.setHorizontalHeaderItem(0, QStandardItem("user"))
        self.userModel.setHorizontalHeaderItem(1, QStandardItem("friends"))
        

        self.userModel.setVerticalHeaderItem(0, QStandardItem("1"))
        self.userModel.setVerticalHeaderItem(1, QStandardItem("2"))
        self.userModel.setVerticalHeaderItem(2, QStandardItem("3"))

        self.loginUserModel = QStandardItemModel()
        self.loginUserModel.setHorizontalHeaderItem(0, QStandardItem("user"))
        self.loginUserModel.setHorizontalHeaderItem(1, QStandardItem("instance"))
        
        self.messageModel = QStandardItemModel()
        self.messageModel.setHorizontalHeaderItem(0, QStandardItem("message"))

        #读取系统配置文件
        self.readConfig(configFile)
        self.statusBar().showMessage("server is stopped!")
        
        self.ui.userInfo_tableView.setModel(self.userModel)
        self.createUserInfoContextMenu()
        self.ui.loginUsers_tableView.setModel(self.loginUserModel)
        self.createloginUsersContextMenu()
        self.ui.messageLogs_listView.setModel(self.messageModel)

        #界面多语处理
        self.updateLanguage(self.language)
        
        self.center()
        
    def iconActivated(self, reason):
        if reason == QSystemTrayIcon.DoubleClick:
            self.show()
        print "iconActivated"
    
    def closeEvent(self, event):
        event.ignore()
        self.hide()
        print "closeEvent"

#    def changeEvent(self,event):
#        if (event.type() == QEvent.WindowStateChange) and (self.isMinimized()):
#            QTimer.singleShot(100, self, SLOT("close"))
#            
#        print "changeEvent"    
                
    def sqlServer(self, index):
        if index == "MySQL":
            self.ui.openSqlpushButton.setDisabled(True)
            self.ui.userLineEdit.setEnabled(True)
            self.ui.passwordlineEdit.setEnabled(True)        
            
        if  index == "Sqlite":
            self.ui.openSqlpushButton.setEnabled(True)
            self.ui.userLineEdit.setDisabled(True)
            self.ui.passwordlineEdit.setDisabled(True)        
        
    def center(self):  
        screen = QDesktopWidget().screenGeometry()  
        size = self.geometry()  
        self.move((screen.width() - size.width()) / 2,
            (screen.height() - size.height()) / 2)  
        
    def createUserInfoContextMenu(self):
        '''添加用户信息快捷菜单'''
        #pylint: disable=W0201
        self.addUserAct = QAction(self)
#        self.addUserAct.setText("add User")
        
        self.delUserAct = QAction(self)
#        self.delUserAct.setText("del User")

        self.undoDelUserAct = QAction(self)
#        self.undoDelUserAct.setText("undo del User")
        
        self.saveDataRowAct = QAction(self)
#        self.saveDataRowAct.setText("save Data")
        
        self.ui.userInfo_tableView.addAction(self.addUserAct)
        self.ui.userInfo_tableView.addAction(self.delUserAct)
        self.ui.userInfo_tableView.addAction(self.undoDelUserAct)
        self.ui.userInfo_tableView.addAction(self.saveDataRowAct)
        
        QObject.connect(self.addUserAct, SIGNAL("activated()"), self, SLOT("userInfoAddRow()"))
        QObject.connect(self.delUserAct, SIGNAL("activated()"), self, SLOT("userInfoDelRow()"))
        QObject.connect(self.undoDelUserAct, SIGNAL("activated()"), self, SLOT("userInfoUndoDelRow()"))        
        QObject.connect(self.saveDataRowAct, SIGNAL("activated()"), self, SLOT("userInfoSaveData()"))
        
        self.ui.userInfo_tableView.setContextMenuPolicy(Qt.ActionsContextMenu)

    
    def userInfoAddRow(self):
        '''添加一条用户数据'''
#        self.userModel.appendRow(QStandardItem(""))
        index = self.ui.userInfo_tableView.selectionModel().currentIndex()
        model = self.ui.userInfo_tableView.model()

        if not model.insertRow(index.row() + 1, index.parent()):
            return

        for column in range(model.columnCount(index.parent())):
            child = model.index(index.row() + 1, column, index.parent())
            model.setData(child, "[No data]", Qt.EditRole)
            
        uiDebug("userInfoAddRow")
    

    def userInfoDelRow(self):
        '''删除数据,且保留此次删除的数据'''
        model = self.ui.userInfo_tableView.model()
        index = self.ui.userInfo_tableView.selectionModel().currentIndex()
        user = model.item(index.row(), 0).index().data()
        friendlist = model.item(index.row(), 1).index().data()
        self.delUsrInfo = [index.row(), user, friendlist]
#        print self.delUsrInfo
        try:
            model.removeRow(index.row(), index.parent())
            self.users.deleteUser(user)
            self.users.userDataSave()
            #pylint: disable=W0702 
        except:    
            pass        
        uiDebug("userInfoDelRow")        

    def userInfoUndoDelRow(self):
        '''恢复前次删除的数据'''
        if self.delUsrInfo != None:
            model = self.ui.userInfo_tableView.model()
            if not model.insertRow(self.delUsrInfo[0]):
                return
            user = self.delUsrInfo[1]
            friendlist = self.delUsrInfo[2]      
            self.userModel.setItem(self.delUsrInfo[0], 0, QStandardItem(user))
            self.userModel.setItem(self.delUsrInfo[0], 1, QStandardItem(friendlist))
            if user != "[No data]":
                self.users.addUser(user, "admin")
            if friendlist != "[No data]":    
                for friend in friendlist.split(","):            
                    self.users.addUserFriend(user, friend)
            self.users.userDataSave()    
        self.delUsrInfo = None        
        uiDebug("userInfoUndoDelRow")


    def userInfoSaveData(self):
        '''保留用户数据'''
        if self.users:
            model = self.ui.userInfo_tableView.model()
            index = self.ui.userInfo_tableView.selectionModel().currentIndex()
            for row in range(model.rowCount(index.parent())):
                user = model.item(row, 0).index().data()
                friendlist = model.item(row, 1).index().data()
                if user != "[No data]":
                    self.users.addUser(user, "admin")
                if friendlist != "[No data]":
                    for friend in friendlist.split(","):
                        if friend != '':
                            self.users.addUserFriend(user, friend)   
        
            self.users.userDataSave()
            self.clearUserInfo()    
            self.showUserinfo()
        uiDebug("userInfoSaveData")        
    

    def showConfig(self):
        '''显示配置'''
#        print self.Config.getControlMedia()    
#        print self.Config.getControlMediaPath()   
#        print self.ControlMedia
#        print self.ControlMediaPath     
        self.ui.information_textBrowser.setText("Control Media: " + self.ControlMedia)
        self.ui.information_textBrowser.append("Control Media path: " + self.ControlMediaPath)

    def showUserinfo(self):
        '''显示用户信息'''
        userlist = self.users.getUsers()
        print "showUserinfo "
        print userlist
        row = 0
        for user in userlist:
            friends = userlist[user]
            self.userModel.setItem(row, 0, QStandardItem(user))
            self.userModel.setItem(row, 1, QStandardItem(friends))
            row = row + 1  
        #pylint: disable=W0201    
        self.delUsrInfo = None
    
    def clearUserInfo(self):
        '''清除用户信息'''
        self.userModel.clear()
        self.delUsrInfo = None

        
    def userConfig(self):
        self.showConfig()
        if self.users != None:
            del self.users        
        #服务器配置
        if self.ControlMedia == mediaValue[txt]:
            #txt文件保留用户信息
            self.users = txtUserControl(self.ControlMediaPath)
            self.ui.text_groupBox.setChecked(True)
            self.ui.text_lineEdit.setText(self.ControlMediaPath)
        elif self.ControlMedia == mediaValue[xml]:
            #xml文件保留用户信息
            self.users = xmlUserControl(self.ControlMediaPath)
            self.ui.xml_groupBox.setChecked(True)
            self.ui.xml_lineEdit.setText(self.ControlMediaPath)
            
        elif self.ControlMedia == mediaValue[mysql]:
            #mysql数据库保留用户信息   
            self.ui.mysql_groupBox.setChecked(True)
            self.ui.ServerLineEdit.setText(self.ControlMediaPath)
            self.ui.sqlTypeComboBox.setCurrentIndex(0)
#            print "mysql" 
            self.sqlServer(mysql)    
        elif self.ControlMedia == mediaValue[sqlite]:
            self.ui.mysql_groupBox.setChecked(True)
            self.ui.ServerLineEdit.setText(self.ControlMediaPath)
            self.ui.sqlTypeComboBox.setCurrentIndex(1)
            self.users = sqliteUserControl(self.ControlMediaPath)
            self.sqlServer(sqlite)
#            print "sqlite"
            
        #用户数据初始化
            
        try:     
            self.users.userDataInit()
#            self.showUserinfo()
            #pylint: disable=W0702
        except:
            self.users = None

        if self.users != None:
            self.clearUserInfo()
            self.showUserinfo()
                    
    def readConfig(self, _file):
        '''读取服务器端配置文件'''
        #pylint: disable=W0201
        self.Config = serverConfig(_file)
        self.ControlMedia = self.Config.getControlMedia() 
        self.ControlMediaPath = self.Config.getControlMediaPath()        
        self.language = self.Config.getLanguage()
        self.userConfig()
        uiDebug("readConfig")
                    
    def startServer(self):
        '''#启动服务'''
        self.ui.startServer_pushButton.setEnabled(False)
        self.ui.stopServer_pushButton.setEnabled(True)
        self.connect = server_twisted.serverMain(8002, self.users)
        self.saveConfig()
#        self.readConfig(configFile)
        self.userConfig()
        self.ui.mysql_groupBox.setDisabled(True)
        self.ui.text_groupBox.setDisabled(True)
        self.ui.xml_groupBox.setDisabled(True)
        self.statusBar().showMessage("server is starting!")
        
        if self.users != None:
            self.clearUserInfo()
            self.showUserinfo()
        uiDebug("startServer")

    def stopServer(self):
        ''' #停止服务'''
        if self.connect != None:
            self.ui.startServer_pushButton.setEnabled(True)
            self.ui.stopServer_pushButton.setEnabled(False)
            self.ui.mysql_groupBox.setDisabled(False)
            self.ui.text_groupBox.setDisabled(False)
            self.ui.xml_groupBox.setDisabled(False)  
            #pylint: disable=E1101          
            reactor.disconnectAll()
#            self.clearUserInfo()
            self.statusBar().showMessage("server is stopped!")
        uiDebug("stopServer")
        

    def loadChinese(self):
        '''加载中文'''
        self.updateLanguage(Chinese)

    def loadEnglish(self):
        '''加载英文'''
        self.updateLanguage(English)
        
    def updateLanguage(self, language):
        '''设置界面语言'''
        if self.translator != None:
            self.app.removeTranslator(self.translator)
            
        if language == Chinese:
            #中文处理
            self.translator.load(chineseLanguageFile)
            self.app.installTranslator(self.translator)  
            self.Config.setLanguage(Chinese)
        elif language == English:
            #英文处理
            self.Config.setLanguage(English)   
        else:
            pass
    
        #更新界面
        self.retranslateUi()
        #保留配置
        self.Config.saveServerConfig()
        
            
    def txt_open(self):
        self.fileOpen(self.ui.text_lineEdit, txt)
        
    def xml_open(self):
        self.fileOpen(self.ui.xml_lineEdit, xml)

    def database_open(self):
        self.fileOpen(self.ui.ServerLineEdit, mysql)

    def fileOpen(self, lineEdit, filters):
        openFile = QFileDialog.getOpenFileName(self, "Find Files", QDir.currentPath(), filters="*." + filters)
        uiDebug(openFile)
        if openFile != None :
            lineEdit.setText(openFile[0])
            self.setUserConfig()
            self.showConfig()
                    
    def choiceSql(self):
        uiDebug("choiceMysql")
        self.ui.text_groupBox.setChecked(False)
        self.ui.xml_groupBox.setChecked(False)
        if  self.ui.sqlTypeComboBox.currentText() == mysql:
            self.ui.openSqlpushButton.setDisabled(True)
            self.ui.userLineEdit.setEnabled(True)
            self.ui.passwordlineEdit.setEnabled(True)   
            
        if  self.ui.sqlTypeComboBox.currentText() == sqlite:
            self.ui.openSqlpushButton.setEnabled(True)
            self.ui.userLineEdit.setDisabled(True)
            self.ui.passwordlineEdit.setDisabled(True)
            
    def choiceTxt(self):
        uiDebug("choiceTxt")
        self.ui.mysql_groupBox.setChecked(False)
        self.ui.xml_groupBox.setChecked(False)

    def choiceXml(self):
        uiDebug("choiceXml")
        self.ui.mysql_groupBox.setChecked(False)
        self.ui.text_groupBox.setChecked(False)

    def setUserConfig(self):
        '''保留用户配置'''
        if self.ui.xml_groupBox.isChecked() == True:
            if self.ui.xml_lineEdit.text() != "":
                self.ControlMedia = xml
                self.ControlMediaPath = self.ui.xml_lineEdit.text()
                uiDebug("setUserConfig xml: " + xml)
         
        if self.ui.text_groupBox.isChecked() == True:
            if self.ui.text_lineEdit.text() != "":
                self.ControlMedia = txt
                self.ControlMediaPath = self.ui.text_lineEdit.text()
                uiDebug("setUserConfig txt: " + txt)
         
        if self.ui.mysql_groupBox.isChecked() == True:
            if self.ui.sqlTypeComboBox.currentText() == mysql:
                self.ControlMedia = mysql
                uiDebug("setUserConfig mysql: " + mysql)
            if self.ui.sqlTypeComboBox.currentText() == sqlite:
                self.ControlMedia = sqlite
                uiDebug("setUserConfig sqlite: " + sqlite)
            self.ControlMediaPath = self.ui.ServerLineEdit.text()

        self.Config.setContrlMedia(self.ControlMedia)
        self.Config.setControlMediaPath(self.ControlMediaPath)
        self.userConfig()    
        
    def createloginUsersContextMenu(self):
        '''添加登陆用户快捷菜单'''
        #pylint: disable=W0201
        self.killUserAct = QAction(self)
#        self.killUserAct.setText("kill user")
        
        self.messageUserAct = QAction(self)
#        self.messageUserAct.setText("message user")
        
        self.ui.loginUsers_tableView.addAction(self.killUserAct)
        self.ui.loginUsers_tableView.addAction(self.messageUserAct)
        
        QObject.connect(self.killUserAct, SIGNAL("activated()"), self, SLOT("killUser()"))
        QObject.connect(self.messageUserAct, SIGNAL("activated()"), self, SLOT("messageUser()"))
        
        self.ui.loginUsers_tableView.setContextMenuPolicy(Qt.ActionsContextMenu)

    def killUser(self):
        '''踢出一个用户'''
        try:
            index = self.ui.loginUsers_tableView.selectionModel().currentIndex()
            model = self.ui.loginUsers_tableView.model()
            user = model.item(index.row(), 0).index().data()
            self.connect.killUser(user)
            #pylint: disable=W0702
        except:
            pass    
#        model.removeRow(index.row(), index.parent())
        uiDebug("killUser")

    def messageUser(self):
        '''发送消息给用户'''
        uiDebug("messageUser")        
    
    def addUsers(self, user, instance):
        '''添加一条登陆用户数据'''

        index = self.ui.loginUsers_tableView.selectionModel().currentIndex()
        model = self.ui.loginUsers_tableView.model()
        row = model.rowCount(index.parent())
        model.setItem(row, 0, QStandardItem(user))
        model.setItem(row, 1, QStandardItem(str(instance)))
        
        uiDebug("loginUser")
    
    def removeUser(self, user):
        '''删除一条登陆用户数据'''
        index = self.ui.loginUsers_tableView.selectionModel().currentIndex()
        model = self.ui.loginUsers_tableView.model()
        maxRow = model.rowCount(index.parent())
#        print user
        for row in range(maxRow):
#            print row
#            print model.item(row, 0).index().data()
#            print type(model.item(row, 0).index().data())
            if user == model.item(row, 0).index().data():
                model.removeRow(row, index.parent())                             
                
        uiDebug("logoutUser")

    def refreshReceMessage(self, message):
        '''添加接收信息'''
        model = self.ui.messageLogs_listView.model()
#        model.setItem(model.rowCount(),QStandardItem(message))
        model.appendRow(QStandardItem(message))
        uiDebug("refreshReceMessage")        

    def refreshSendMessage(self, message):
        '''添加发送信息'''
        model = self.ui.messageLogs_listView.model()
#        model.setItem(model.rowCount(),QStandardItem(message))
        model.appendRow(QStandardItem(message))
        uiDebug("refreshSendMessage")        

    def retranslateUi(self):
        self.addUserAct.setText(QApplication.translate("MainWindow", "add User", None, QApplication.UnicodeUTF8))
        self.delUserAct.setText(QApplication.translate("MainWindow", "del User", None, QApplication.UnicodeUTF8))
        self.undoDelUserAct.setText(QApplication.translate("MainWindow", "undo del  User", None, QApplication.UnicodeUTF8))
        self.saveDataRowAct.setText(QApplication.translate("MainWindow", "save Data", None, QApplication.UnicodeUTF8))
        self.killUserAct.setText(QApplication.translate("MainWindow", "kill User", None, QApplication.UnicodeUTF8))
        self.messageUserAct.setText(QApplication.translate("MainWindow", "message User", None, QApplication.UnicodeUTF8))
        self.quitAction.setText(QApplication.translate("MainWindow", "Quit", None, QApplication.UnicodeUTF8))
        self.iTrayIcon.setToolTip(QApplication.translate("MainWindow", "One world, One dream!", None, QApplication.UnicodeUTF8))
        
        self.ui.retranslateUi(self)

    def loadConfig(self):
        '''加载配置文件'''
        configfile = QFileDialog.getOpenFileName(self, "Load Config File", QDir.currentPath(), filter="*.cfg")
        uiDebug(configfile)
        if configfile != None :
            self.readConfig(configfile)
            self.stopServer()
            self.startServer()
            self.showConfig()
        uiDebug("loadConfig") 

    def saveConfig(self):
        '''保留配置文件'''
        self.setUserConfig()
        self.Config.saveServerConfig()
        uiDebug("saveConfig") 

    def about(self):
        '''about'''
        aboutInfo = '''<HTML>
         <p>xdIm ver 0.2.0</p>
         <p>xdIm program is a software program by xd.</p>
         <p>Copy Right : "(C) 2008-2010 Programmers and Coders Everywhere"</p>
         <p><a href="http://www.xdIm.org/">http://www.xdIm.org</a></p>
         </HTML>"'''
         
        tranAboutInfo = QApplication.translate("MainWindow", aboutInfo, None, QApplication.UnicodeUTF8)
        QMessageBox.information(self, "xdIm information", tranAboutInfo)
        uiDebug("about") 
class DataInspector(QMainWindow):
    """
    DataInspector main class
    """
    def __init__(self):
        super(DataInspector, self).__init__()

        self.slider_width = +300

        self.main_widget = QWidget(self)
        self.setCentralWidget(self.main_widget)
        self.render_widget = RenderWidget()

        # Create interface actions
        self.action_load_data = QAction('Load data set',
                                        self,
                                        shortcut='Ctrl+O')
        self.action_load_data.setIcon(QIcon("images/AddButton.png"))
        self.action_load_data.triggered.connect(self.load_file)
        self.action_show_simple = QAction('Switch to simple rendering',
                                          self,
                                          shortcut='Ctrl+1')
        self.action_show_simple.setText("Simple")
        self.action_show_simple.triggered.connect(self.switch_to_simple)
        self.action_show_ct = QAction('Switch to CT rendering',
                                      self,
                                      shortcut='Ctrl+2')
        self.action_show_ct.setText("CT")
        self.action_show_ct.triggered.connect(self.switch_to_ct)
        self.action_show_mip = QAction('Switch to MIP rendering',
                                       self,
                                       shortcut='Ctrl+3')
        self.action_show_mip.setText("MIP")
        self.action_show_mip.triggered.connect(self.switch_to_mip)

        # Align the dock buttons to the right with a spacer widget
        spacer = QWidget()
        spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        # Add buttons to container on top
        self.toolbar = self.addToolBar('Main tools')
        self.toolbar.addAction(self.action_show_simple)
        self.toolbar.addAction(self.action_show_ct)
        self.toolbar.addAction(self.action_show_mip)

        self.toolbar.addWidget(spacer)
        self.toolbar.addAction(self.action_load_data)
        self.setUnifiedTitleAndToolBarOnMac(True)

        # Slider for simple visualization
        self.sliders_simple_widget = QSlider(Qt.Horizontal)
        self.sliders_simple_widget.setMinimumWidth(self.slider_width)
        self.sliders_simple_widget.setMaximumWidth(self.slider_width)
        self.sliders_simple_widget.setMinimum(0)
        self.sliders_simple_widget.setMaximum(1000)
        self.sliders_simple_widget.valueChanged.connect(
            self.simple_slider_value_changed)
        self.sliders_simple_widget.setHidden(True)

        # Create sliders for CT transfer function
        sliders_layout = QVBoxLayout()
        sliders_layout.setContentsMargins(0, 0, 0, 0)
        sliders_layout.setSpacing(0)
        self.sliders = []
        for _ in range(0, 7):
            slider = QSlider(Qt.Horizontal)
            slider.setMinimum(0)
            slider.setMaximum(1000)
            slider.valueChanged.connect(self.ct_slider_value_changed)
            self.sliders.append(slider)
            sliders_layout.addWidget(slider)

        self.sliders_ct_widget = QWidget()
        self.sliders_ct_widget.setMinimumWidth(self.slider_width)
        self.sliders_ct_widget.setMaximumWidth(self.slider_width)
        self.sliders_ct_widget.setLayout(sliders_layout)
        self.sliders_ct_widget.setHidden(True)

        self.min_slider = QSlider(Qt.Horizontal)
        self.min_slider.setMinimum(0)
        self.min_slider.setMaximum(1000)
        self.min_slider.valueChanged.connect(self.mip_slider_value_changed)

        self.max_slider = QSlider(Qt.Horizontal)
        self.max_slider.setMinimum(0)
        self.max_slider.setMaximum(1000)
        self.max_slider.setValue(1000)
        self.max_slider.valueChanged.connect(self.mip_slider_value_changed)

        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        layout.addWidget(self.min_slider)
        layout.addWidget(self.max_slider)

        self.sliders_mip_widget = QWidget()
        self.sliders_mip_widget.setMinimumWidth(self.slider_width)
        self.sliders_mip_widget.setMaximumWidth(self.slider_width)
        self.sliders_mip_widget.setLayout(layout)
        self.sliders_mip_widget.setHidden(True)

        layout = QHBoxLayout(self.main_widget)
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.render_widget)
        layout.addWidget(self.sliders_mip_widget)
        layout.addWidget(self.sliders_ct_widget)
        layout.addWidget(self.sliders_simple_widget)
        self.main_widget.setLayout(layout)

        self.resize(800, 500)

    def switch_to_simple(self):
        """
        Switch the visualization style to a simple transfer function
        """
        self.render_widget.set_render_type(RenderTypeSimple)

        self.sliders_simple_widget.setDisabled(False)
        self.sliders_ct_widget.setDisabled(True)
        self.sliders_mip_widget.setDisabled(True)

        self.sliders_simple_widget.setHidden(False)
        self.sliders_ct_widget.setHidden(True)
        self.sliders_mip_widget.setHidden(True)

    def switch_to_ct(self):
        """
        Switch to a visualization style that should work pretty ok
        for CT datasets
        """
        self.render_widget.set_render_type(RenderTypeCT)

        self.sliders_simple_widget.setDisabled(True)
        self.sliders_ct_widget.setDisabled(False)
        self.sliders_mip_widget.setDisabled(True)

        self.sliders_simple_widget.setHidden(True)
        self.sliders_ct_widget.setHidden(False)
        self.sliders_mip_widget.setHidden(True)

    def switch_to_mip(self):
        """
        Switch to Maximum intensity projection visualization type
        """
        self.render_widget.set_render_type(RenderTypeMIP)

        self.sliders_simple_widget.setDisabled(True)
        self.sliders_ct_widget.setDisabled(True)
        self.sliders_mip_widget.setDisabled(False)

        self.sliders_simple_widget.setHidden(True)
        self.sliders_ct_widget.setHidden(True)
        self.sliders_mip_widget.setHidden(False)

    def simple_slider_value_changed(self):
        """
        Callback for slider of simple visualization type
        """
        slider_value = float(self.sliders_simple_widget.value()) \
            / float(self.sliders_simple_widget.maximum())
        self.render_widget.lowerBound = self.render_widget.minimum \
            + (self.render_widget.maximum - self.render_widget.minimum) * slider_value
        self.render_widget.update()

    def mip_slider_value_changed(self):
        """
        Callback for sliders of MIP visualization
        """
        min_value = float(self.min_slider.value()) / float(
            self.min_slider.maximum())
        max_value = float(self.max_slider.value()) / float(
            self.max_slider.maximum())

        self.render_widget.mipMin = self.render_widget.minimum \
            + (self.render_widget.maximum - self.render_widget.minimum) * min_value
        self.render_widget.mipMax = self.render_widget.minimum \
            + (self.render_widget.maximum - self.render_widget.minimum) * max_value

        self.render_widget.update()

    def ct_slider_value_changed(self):
        """
        Callback for sliders of CT visualization
        """
        for (x, slider) in enumerate(self.sliders):
            # for x in range(0, len(self.sliders)):
            # slider = self.sliders[x]
            slider_value = float(slider.value()) / float(slider.maximum())
            # Use an square function for easier opacity adjustments
            converted_value = slider_value * slider_value * slider_value
            self.render_widget.sectionsOpacity[x] = converted_value

        self.render_widget.update()

    def load_file(self):
        """
        Loads a file from disk
        """
        extensions = DataReader().get_supported_extensions_as_string()
        file_name, _ = QFileDialog.getOpenFileName(
            self, "Open data set", "", "Images (" + extensions + ")")
        if not file_name:
            return

        self.render_widget.load_file(file_name)
        self.switch_to_simple()
示例#12
0
文件: truss.py 项目: nagordon/notes
class Truss(QMainWindow):
    def __init__(self, parent=None):
        super(Truss, self).__init__(parent)
        self.resize(800, 600)
        self.filename = None
        self.filetuple = None
        self.dirty = False  # Refers to Data Page only.
        centralwidget = QWidget(self)
        gridLayout = QGridLayout(centralwidget)
        self.tabWidget = QTabWidget(centralwidget)
        self.tab = QWidget()
        font = QFont()
        font.setFamily("Courier 10 Pitch")
        font.setPointSize(12)
        self.tab.setFont(font)
        gridLayout_3 = QGridLayout(self.tab)
        self.plainTextEdit = QPlainTextEdit(self.tab)
        gridLayout_3.addWidget(self.plainTextEdit, 0, 0, 1, 1)
        self.tabWidget.addTab(self.tab, "")
        self.tab_2 = QWidget()
        self.tab_2.setFont(font)
        gridLayout_2 = QGridLayout(self.tab_2)
        self.plainTextEdit_2 = QPlainTextEdit(self.tab_2)
        gridLayout_2.addWidget(self.plainTextEdit_2, 0, 0, 1, 1)
        self.tabWidget.addTab(self.tab_2, "")
        gridLayout.addWidget(self.tabWidget, 0, 0, 1, 1)
        self.setCentralWidget(centralwidget)
        menubar = QMenuBar(self)
        menubar.setGeometry(QRect(0, 0, 800, 29))
        menu_File = QMenu(menubar)
        self.menu_Solve = QMenu(menubar)
        self.menu_Help = QMenu(menubar)
        self.setMenuBar(menubar)
        self.statusbar = QStatusBar(self)
        self.setStatusBar(self.statusbar)
        self.action_New = QAction(self)
        self.actionSave_As = QAction(self)
        self.action_Save = QAction(self)
        self.action_Open = QAction(self)
        self.action_Quit = QAction(self)
        self.action_About = QAction(self)
        self.actionShow_CCPL = QAction(self)
        self.action_Solve = QAction(self)
        self.action_CCPL = QAction(self)
        self.action_Help = QAction(self)
        menu_File.addAction(self.action_New)
        menu_File.addAction(self.action_Open)
        menu_File.addAction(self.actionSave_As)
        menu_File.addAction(self.action_Save)
        menu_File.addSeparator()
        menu_File.addAction(self.action_Quit)
        self.menu_Solve.addAction(self.action_Solve)
        self.menu_Help.addAction(self.action_About)
        self.menu_Help.addAction(self.action_CCPL)
        self.menu_Help.addAction(self.action_Help)
        menubar.addAction(menu_File.menuAction())
        menubar.addAction(self.menu_Solve.menuAction())
        menubar.addAction(self.menu_Help.menuAction())
        self.setWindowTitle("Main Window")
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab),\
                                   "Data Page")
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2),\
                                   "Solution Page")
        menu_File.setTitle("&File")
        self.menu_Solve.setTitle("&Solve")
        self.menu_Help.setTitle("&Help")
        self.tabWidget.setCurrentIndex(0)
        self.action_New.setText("&New")
        self.action_Open.setText("&Open")
        self.actionSave_As.setText("Save &As")
        self.action_Save.setText("&Save")
        self.action_Quit.setText("&Quit")
        self.action_Solve.setText("&Solve")
        self.action_About.setText("&About")
        self.action_CCPL.setText("&CCPL")
        self.action_Help.setText("&Help")
        self.action_Quit.triggered.connect(self.close)
        allToolBar = self.addToolBar("AllToolBar")
        allToolBar.setObjectName("AllToolBar")
        self.addActions(allToolBar, (self.action_Open, self.actionSave_As,\
                        self.action_Save, self.action_Solve,\
                        self.action_Quit ))
        self.action_New.triggered.connect(self.fileNew)
        self.action_Open.triggered.connect(self.fileOpen)
        self.actionSave_As.triggered.connect(self.fileSaveAs)
        self.action_Save.triggered.connect(self.fileSave)
        self.action_Solve.triggered.connect(self.trussSolve)
        self.action_About.triggered.connect(self.aboutBox)
        self.action_CCPL.triggered.connect(self.displayCCPL)
        self.action_Help.triggered.connect(self.help)
        self.plainTextEdit.textChanged.connect(self.setDirty)
        self.action_New = self.editAction(self.action_New, None,\
                            'ctrl+N', 'filenew', 'New File.')
        self.action_Open = self.editAction(self.action_Open, None, 'ctrl+O',
                                           'fileopen', 'Open File.')
        self.actionSave_As = self.editAction(self.actionSave_As,\
                            None, 'ctrl+A', 'filesaveas',\
                            'Save and Name File.')
        self.action_Save = self.editAction(self.action_Save, None, 'ctrl+S',
                                           'filesave', 'Save File.')
        self.action_Solve = self.editAction(self.action_Solve, None, 'ctrl+L',
                                            'solve', 'Solve Structure.')
        self.action_About = self.editAction(self.action_About, None, 'ctrl+B',
                                            'about', 'Pop About Box.')
        self.action_CCPL = self.editAction(self.action_CCPL, None, 'ctrl+G',
                                           'licence', 'Show Licence')
        self.action_Help = self.editAction(self.action_Help, None, 'ctrl+H',
                                           'help', 'Show Help Page.')
        self.action_Quit = self.editAction(self.action_Quit, None, 'ctrl+Q',
                                           'quit', 'Quit the program.')
        self.plainTextEdit_2.setReadOnly(True)

    def setDirty(self):
        '''On change of text in textEdit window, set the flag
        "dirty" to True'''
        index = self.tabWidget.currentIndex()
        if index is not 0:
            return
        if self.dirty:
            return True
        self.dirty = True
        self.updateStatus('self.dirty set to True')

    def clearDirty(self):
        'Clear dirty flag'
        self.dirty = False

    def fileNew(self):
        '''Clear both Data Page and Solution Page.'''
        self.plainTextEdit.setPlainText(' ')
        self.plainTextEdit_2.setPlainText(' ')
        self.clearDirty(self)

    def okToContinue(self):
        if self.dirty:
            reply = QMessageBox.question(
                self, "Data Loader - Unsaved Changes", "Save unsaved changes?",
                QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
            if reply == QMessageBox.Cancel:
                return False
            elif reply == QMessageBox.Yes:
                self.clearDirty()
                return self.fileSave()
        return True

    def okRead(self):
        'Pop-up a warning message.'
        reply = QMessageBox.warning(
            self, "Warning",
            '''\nFile Open and Save is possible only in Data Page!
\n\(Use SaveAs for Solution Page)''', QMessageBox.Ok)
        return True

    def fileOpen(self):
        '''Open a file in Data Page (with index == 0)'''
        if self.tabWidget.currentIndex():
            self.okRead()
            return
        if not self.okToContinue():
            return
        dir = (os.path.dirname(self.filename)
               if self.filename is not None else ".")
        self.filetuple = QFileDialog.getOpenFileName(self,\
                        "Open File", dir, \
                        "Data (*.dat *.txt)\nAll Files (*.*)")
        self.filename = self.filetuple[0]
        fname = self.filename
        #  QFileDialog returns a tuple x with x[0] = file name and
        #  x[1] = type of filter.
        if fname:
            self.loadFile(fname)
            self.filename = fname
            self.updateStatus('New file opened.')

    def loadFile(self, fname=None):
        fl = open(fname)
        text = fl.read()
        self.plainTextEdit.setPlainText(text)
        self.dirty = False

    def fileSave(self):
        '''Save file with current file name.'''
        if self.tabWidget.currentIndex():
            self.okRead()
            return
        if self.filename is None:
            return self.fileSaveAs()
        else:
            flname = self.filename
            if flname:
                try:
                    with open(flname, 'w') as fl:
                        fl.write(tempText)
                    self.dirty = False
                    self.updateStatus('File saved.')
                except IOError:
                    self.dirty = True
                    self.updateStatus('File not saved.')
                    return False
                return True
            else:
                self.updateStatus('Failed to save... ')
                return False
        self.filename = None
        self.dirty = False

    def fileSaveAs(self):
        '''Save file with a new name.'''
        qpr = self.qprintline
        fname = self.filename if self.filename is not None else\
        "NoName"
        self.filetuple = QFileDialog.getSaveFileName(
            self, "Truss program - Save File", fname, "Data File (*.*)")
        flname = self.filetuple[0]
        index = self.tabWidget.currentIndex()
        if index == 0:
            self.filename = flname
            if flname:
                fl = open(flname, 'w')
                tempText = self.plainTextEdit.toPlainText()
                fl.write(tempText)
                fl.close()
                self.dirty = False
                self.updateStatus('File saved.')
        elif index == 1:
            if flname:
                fl = open(flname, 'w')
                tempText = self.plainTextEdit_2.toPlainText()
                fl.write(tempText)
                fl.close()

    def trussSolve(self):
        '''Solve a statically determinate truss, specified in
        Data Page and display the results in the Solution Page.
        To start, make a copy of the Data Page with a header all
        shown on the Data Page.'''
        printline = self.qprintline
        dataBall = self.plainTextEdit.toPlainText()
        self.plainTextEdit_2.clear()
        printline('================================')
        flbase = os.path.basename(self.filename)
        printline('SOLUTION FOR ' + flbase)
        printline('================================')
        dataBall = self.plainTextEdit.toPlainText()
        ncrunch.main(printline, self.filename, dataBall)

    def aboutBox(self):
        '''Popup a box with about message.'''
        QMessageBox.about(self, "About PySide, Platform and the like",
                """<b>Part of Structural Analysis.</b> v %s
                <p>Copyright &copy; 2011 Algis Kabaila. 
                All rights reserved in accordance with
                Creative Commons Attribution Licence (CCPL) v3
                or later - NO WARRANTIES!
                <p>This progam finds bar forces in 
                statically determinate trusses.                
                <p>Python %s -  PySide version %s - Qt version %s on\
                %s""" % (__version__, platform.python_version(),\
                PySide.__version__,  PySide.QtCore.__version__,
                platform.system()))

    def displayCCPL(self):
        '''Read and display CCPL licence.'''
        self.plainTextEdit.setPlainText(open('CCPL.txt').read())
        self.dirty = False
        self.filename = 'COPYING.txt'
        self.updateStatus('CCPL displayed.')

    def help(self):
        '''Read and display a help file- currently the README.txt.'''
        self.plainTextEdit.setPlainText(open('README.md').read())
        self.dirty = False
        self.filename = 'README.txt'
        self.updateStatus('README displayed.')

    def addActions(self, target, actions):
        '''Actions are added to Tool Bar.'''
        for action in actions:
            if action is None:
                target.addSeparator()
            else:
                target.addAction(action)

    def editAction(self,
                   action,
                   slot=None,
                   shortcut=None,
                   icon=None,
                   tip=None):
        '''This method adds to action: icon, shortcut, ToolTip,\
        StatusTip and can connect triggered action to slot '''
        if icon is not None:
            action.setIcon(QIcon(":/%s.png" % (icon)))
        if shortcut is not None:
            action.setShortcut(shortcut)
        if tip is not None:
            action.setToolTip(tip)
            action.setStatusTip(tip)
        if slot is not None:
            action.triggered.connect(slot)
        return action

    def qreadline(self, lineNo):
        '''Read one line from Data Page (lineNo starts with 0)'''
        return str(self.plainTextEdit.document().\
            findBlockByLineNumber(lineNo).text()).rstrip()

    def qprintline(self, line):
        '''Append one line to Solution Page.'''
        self.plainTextEdit_2.appendPlainText(line.rstrip())

    def updateStatus(self, message):
        '''Keep status current.'''
        if self.filename is not None:
            flbase = os.path.basename(self.filename)
            self.setWindowTitle(str("Truss Analysis - " +\
                                         flbase + "[*]") )
            self.statusBar().showMessage(message, 5000)
            self.setWindowModified(self.dirty)
示例#13
0
class Truss(QMainWindow):
    def __init__(self, parent=None):
        super(Truss, self).__init__(parent)        
        self.resize(800, 600)
        self.filename  = None
        self.filetuple = None
        self.dirty = False  # Refers to Data Page only.
        centralwidget = QWidget(self)
        gridLayout = QGridLayout(centralwidget)
        self.tabWidget = QTabWidget(centralwidget)
        self.tab = QWidget()
        font = QFont()
        font.setFamily("Courier 10 Pitch")
        font.setPointSize(12)
        self.tab.setFont(font)
        gridLayout_3 = QGridLayout(self.tab)
        self.plainTextEdit = QPlainTextEdit(self.tab)
        gridLayout_3.addWidget(self.plainTextEdit, 0, 0, 1, 1)
        self.tabWidget.addTab(self.tab, "")
        self.tab_2 = QWidget()
        self.tab_2.setFont(font)
        gridLayout_2 = QGridLayout(self.tab_2)
        self.plainTextEdit_2 = QPlainTextEdit(self.tab_2)
        gridLayout_2.addWidget(self.plainTextEdit_2, 0, 0, 1, 1)
        self.tabWidget.addTab(self.tab_2, "")
        gridLayout.addWidget(self.tabWidget, 0, 0, 1, 1)
        self.setCentralWidget(centralwidget)
        menubar = QMenuBar(self)
        menubar.setGeometry(QRect(0, 0, 800, 29))
        menu_File = QMenu(menubar)
        self.menu_Solve = QMenu(menubar)
        self.menu_Help = QMenu(menubar)
        self.setMenuBar(menubar)
        self.statusbar = QStatusBar(self)
        self.setStatusBar(self.statusbar)
        self.action_New = QAction(self)
        self.actionSave_As = QAction(self)
        self.action_Save = QAction(self)
        self.action_Open = QAction(self)
        self.action_Quit = QAction(self)
        self.action_About = QAction(self)
        self.actionShow_CCPL = QAction(self)
        self.action_Solve = QAction(self)
        self.action_CCPL = QAction(self)
        self.action_Help = QAction(self)
        menu_File.addAction(self.action_New)
        menu_File.addAction(self.action_Open)
        menu_File.addAction(self.actionSave_As)
        menu_File.addAction(self.action_Save)
        menu_File.addSeparator()
        menu_File.addAction(self.action_Quit)
        self.menu_Solve.addAction(self.action_Solve)
        self.menu_Help.addAction(self.action_About)
        self.menu_Help.addAction(self.action_CCPL)
        self.menu_Help.addAction(self.action_Help)
        menubar.addAction(menu_File.menuAction())
        menubar.addAction(self.menu_Solve.menuAction())
        menubar.addAction(self.menu_Help.menuAction())        
        self.setWindowTitle("Main Window")
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab),\
                                   "Data Page")
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2),\
                                   "Solution Page")        
        menu_File.setTitle("&File")        
        self.menu_Solve.setTitle("&Solve")
        self.menu_Help.setTitle("&Help")
        self.tabWidget.setCurrentIndex(0)
        self.action_New.setText("&New") 
        self.action_Open.setText("&Open")       
        self.actionSave_As.setText("Save &As")
        self.action_Save.setText("&Save")
        self.action_Quit.setText("&Quit")        
        self.action_Solve.setText("&Solve")
        self.action_About.setText("&About")
        self.action_CCPL.setText("&CCPL")
        self.action_Help.setText("&Help")
        self.action_Quit.triggered.connect(self.close)
        allToolBar = self.addToolBar("AllToolBar") 
        allToolBar.setObjectName("AllToolBar") 
        self.addActions(allToolBar, (self.action_Open, self.actionSave_As,\
                        self.action_Save, self.action_Solve,\
                        self.action_Quit ))
        self.action_New.triggered.connect(self.fileNew)
        self.action_Open.triggered.connect(self.fileOpen)
        self.actionSave_As.triggered.connect(self.fileSaveAs)
        self.action_Save.triggered.connect(self.fileSave)
        self.action_Solve.triggered.connect(self.trussSolve)
        self.action_About.triggered.connect(self.aboutBox)
        self.action_CCPL.triggered.connect(self.displayCCPL)
        self.action_Help.triggered.connect(self.help)
        self.plainTextEdit.textChanged.connect(self.setDirty)
        self.action_New = self.editAction(self.action_New, None,\
                            'ctrl+N', 'filenew', 'New File.')   
        self.action_Open = self.editAction(self.action_Open, None, 
                            'ctrl+O', 'fileopen', 'Open File.')
        self.actionSave_As = self.editAction(self.actionSave_As,\
                            None, 'ctrl+A', 'filesaveas',\
                            'Save and Name File.')
        self.action_Save = self.editAction(self.action_Save, None, 
                            'ctrl+S', 'filesave', 'Save File.')
        self.action_Solve = self.editAction(self.action_Solve, None, 
                            'ctrl+L', 'solve', 'Solve Structure.')                                   
        self.action_About = self.editAction(self.action_About, None, 
                            'ctrl+B', 'about','Pop About Box.')                                  
        self.action_CCPL = self.editAction(self.action_CCPL, None, 
                            'ctrl+G', 'licence', 'Show Licence') 
        self.action_Help = self.editAction(self.action_Help, None, 
                            'ctrl+H', 'help', 'Show Help Page.')
        self.action_Quit =  self.editAction(self.action_Quit, None, 
                            'ctrl+Q', 'quit', 'Quit the program.')                                           
        self.plainTextEdit_2.setReadOnly(True)
    
    def setDirty(self):
        '''On change of text in textEdit window, set the flag
        "dirty" to True'''
        index = self.tabWidget.currentIndex()
        if index is not 0:
            return
        if self.dirty:
            return True
        self.dirty = True
        self.updateStatus('self.dirty set to True')    
    
    def clearDirty(self):
        'Clear dirty flag'
        self.dirty = False
    
    def fileNew(self):
        '''Clear both Data Page and Solution Page.'''
        self.plainTextEdit.setPlainText(' ')
        self.plainTextEdit_2.setPlainText(' ')
        self.clearDirty(self)

    def okToContinue(self):
        if self.dirty:
            reply = QMessageBox.question(self,
                    "Data Loader - Unsaved Changes",
                    "Save unsaved changes?",
                    QMessageBox.Yes|QMessageBox.No|QMessageBox.Cancel)
            if reply == QMessageBox.Cancel:
                return False
            elif reply == QMessageBox.Yes:
                self.clearDirty()
                return self.fileSave()
        return True
    
    def okRead(self):
        'Pop-up a warning message.'
        reply = QMessageBox.warning(self,
                "Warning",
                '''\nFile Open and Save is possible only in Data Page!
\n\(Use SaveAs for Solution Page)''', QMessageBox.Ok)
        return True

    def fileOpen(self):
        '''Open a file in Data Page (with index == 0)'''
        if self.tabWidget.currentIndex():
            self.okRead()
            return
        if not self.okToContinue():
            return
        dir = (os.path.dirname(self.filename)
               if self.filename is not None else ".")
        self.filetuple = QFileDialog.getOpenFileName(self,\
                        "Open File", dir, \
                        "Data (*.dat *.txt)\nAll Files (*.*)")
        self.filename = self.filetuple[0] 
        fname = self.filename        
#  QFileDialog returns a tuple x with x[0] = file name and 
#  x[1] = type of filter.
        if fname:
            self.loadFile(fname)
            self.filename = fname
            self.updateStatus('New file opened.')
                
    def loadFile(self, fname=None):
        fl = open(fname)
        text = fl.read()
        self.plainTextEdit.setPlainText(text)
        self.dirty = False
    
    def fileSave(self):
        '''Save file with current file name.'''
        if self.tabWidget.currentIndex():
            self.okRead()
            return        
        if self.filename is None:
            return self.fileSaveAs()
        else:
            flname = self.filename
            if flname:
                with open(flname, 'w') as fl:
                    fl.write(tempText)
                self.dirty = False
                self.updateStatus('File saved.')
                return True
            else:
                self.updateStatus('Failed to save... ')
                return False
        self.filename = None
        self.dirty = False

    def fileSaveAs(self):        
        '''Save file with a new name.'''
        qpr = self.qprintline
        fname = self.filename if self.filename is not None else\
        "NoName"
        self.filetuple = QFileDialog.getSaveFileName(self,
                "Truss program - Save File", fname, "Data File (*.*)")
        flname = self.filetuple[0]        
        index = self.tabWidget.currentIndex()
        if index == 0:
            self.filename = flname 
            if flname:
                fl = open(flname, 'w')
                tempText = self.plainTextEdit.toPlainText()
                fl.write(tempText)
                fl.close()
                self.dirty = False
                self.updateStatus('File saved.')   
        elif index == 1:
            if flname:
                fl = open(flname, 'w')
                tempText = self.plainTextEdit_2.toPlainText()
                fl.write(tempText)
                fl.close()

    def trussSolve(self):
        '''Solve a statically determinate truss, specified in
        Data Page and display the results in the Solution Page.
        To start, make a copy of the Data Page with a header all
        shown on the Data Page.'''
        printline = self.qprintline
        dataBall = self.plainTextEdit.toPlainText() 
        self.plainTextEdit_2.clear()
        printline('================================') 
        flbase = os.path.basename(self.filename)
        printline('SOLUTION FOR ' + flbase)
        printline('================================') 
        dataBall = self.plainTextEdit.toPlainText()
        ncrunch.main(printline, self.filename, dataBall)

    def aboutBox(self):
        '''Popup a box with about message.'''
        QMessageBox.about(self, "About PySide, Platform and the like",
                """<b>Part of Structural Analysis.</b> v %s
                <p>Copyright &copy; 2011 Algis Kabaila. 
                All rights reserved in accordance with
                Creative Commons Attribution Licence (CCPL) v3
                or later - NO WARRANTIES!
                <p>This progam finds bar forces in 
                statically determinate trusses.                
                <p>Python %s -  PySide version %s - Qt version %s on\
                %s""" % (__version__, platform.python_version(),\
                PySide.__version__,  PySide.QtCore.__version__,
                platform.system()))
              
    def displayCCPL(self):
        '''Read and display CCPL licence.'''
        self.plainTextEdit.setPlainText(open('CCPL.txt').read())
        self.dirty = False
        self.filename = 'COPYING.txt'
        self.updateStatus('CCPL displayed.')

    def help(self):
        '''Read and display a help file- currently the README.txt.'''
        self.plainTextEdit.setPlainText(open('README.md').read())
        self.dirty = False
        self.filename = 'README.txt'
        self.updateStatus('README displayed.')
        
    def addActions(self, target, actions):
        '''Actions are added to Tool Bar.'''
        for action in actions:
            if action is None:
                target.addSeparator()
            else:
                target.addAction(action)
    
    def editAction(self, action, slot=None, shortcut=None, icon=None,
                     tip=None):
        '''This method adds to action: icon, shortcut, ToolTip,\
        StatusTip and can connect triggered action to slot '''
        if icon is not None:
            action.setIcon(QIcon(":/%s.png" % (icon)))
        if shortcut is not None:
            action.setShortcut(shortcut)
        if tip is not None:
            action.setToolTip(tip)
            action.setStatusTip(tip)
        if slot is not None:
            action.triggered.connect(slot)                        
        return action

    def qreadline(self, lineNo):
        '''Read one line from Data Page (lineNo starts with 0)'''
        return unicode(self.plainTextEdit.document().\
            findBlockByLineNumber(lineNo).text()).rstrip()

    def qprintline(self, line):        
        '''Append one line to Solution Page.'''
        self.plainTextEdit_2.appendPlainText(line.rstrip())

    def updateStatus(self, message):
        '''Keep status current.'''
        if self.filename is not None:
            flbase = os.path.basename(self.filename)
            self.setWindowTitle(unicode("Truss Analysis - " +\
                                         flbase + "[*]") )
            self.statusBar().showMessage(message, 5000)
            self.setWindowModified(self.dirty)
示例#14
0
文件: gui.py 项目: tinavas/FSERP
class Gui():
    """main gui class"""
    def __init__(self):
        self.mainwindow = QMainWindow()
        settings.get_settings()
        self.access = tuple(settings.access.items())
        self.progress = QProgressDialog("Setting up modules...", "cancel", 0,
                                        7, self.mainwindow)
        self.progress.setWindowTitle(
            QApplication.translate("MainWindow", str(settings.company), None,
                                   QApplication.UnicodeUTF8))

    def setup(self):
        """initializes the uio of the erp client"""
        self.progress.setFixedWidth(1000)
        self.progress.setCancelButton(None)
        # self.progress.setWindowModality(Qt.WindowModal)
        self.progress.setValue(1)
        self.mainwindow.setObjectName("MainWindow")
        self.mainwindow.resize(832, 668)
        self.mainwindow.setStyleSheet(
            "QToolBar{\n"
            "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,\n"
            "stop:0 rgba(0,0,0),stop:1 rgb(162, 162, 162, 162));\n"
            "border: 0px;\n"
            "}\n"
            "QToolBar > QWidget{\n"
            "color:white;\n"
            "}\n"
            "QToolBar > QWidget:hover {\n"
            "background:transparent;\n"
            " }\n"
            "QToolBar > QWidget:checked {\n"
            "background:transparent;\n"
            " }\n"
            "#MainWindow{\n"
            "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,\n"
            "stop:0 rgba(0,0,0),stop:1 rgb(162, 162, 162, 162));\n"
            "border: 0px;\n"
            "}\n"
            "")
        self.centralWidget = QWidget(self.mainwindow)
        self.centralWidget.setObjectName("centralWidget")
        self.gridLayout_2 = QGridLayout(self.centralWidget)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.stackedWidget = QStackedWidget(self.centralWidget)
        self.stackedWidget.setStyleSheet("")
        self.stackedWidget.setObjectName("stackedWidget")
        self.shortcut = NewShortcut()
        scroll = QScrollArea()
        scroll.setWidget(self.shortcut.shortcut_setting)
        self.stackedWidget.addWidget(self.shortcut.shortcut_setting)
        self.home_page = QWidget()
        self.home_page.setObjectName("home_page")
        self.gridLayout = QGridLayout(self.home_page)
        self.gridLayout.setObjectName("gridLayout")
        self.billing_frame_2 = QFrame(self.home_page)
        self.billing_frame_2.setStyleSheet(
            "background-image:url(:/images/billing_frame.png);\n"
            "background-repeat: no-repeat;\n"
            "background-position: center;\n"
            "background-color:#6CBED2;")
        self.billing_frame_2.setFrameShape(QFrame.StyledPanel)
        self.billing_frame_2.setFrameShadow(QFrame.Raised)
        self.billing_frame_2.setObjectName("billing_frame_2")
        self.verticalLayout_4 = QVBoxLayout(self.billing_frame_2)
        self.verticalLayout_4.setObjectName("verticalLayout_4")
        spacerItem = QSpacerItem(20, 217, QSizePolicy.Minimum,
                                 QSizePolicy.Expanding)
        self.verticalLayout_4.addItem(spacerItem)
        self.label_10 = QLabel(self.billing_frame_2)
        self.label_10.setStyleSheet("background:transparent;")
        self.label_10.setObjectName("label_10")
        self.verticalLayout_4.addWidget(self.label_10)
        self.gridLayout.addWidget(self.billing_frame_2, 0, 1, 1, 1)
        self.employee_frame_3 = QFrame(self.home_page)
        self.employee_frame_3.setStyleSheet(
            "background-image:url(:/images/employee_frame.png);\n"
            "background-repeat: no-repeat;\n"
            "background-position: center;\n"
            "background-color:#0099CC;")
        self.employee_frame_3.setFrameShape(QFrame.StyledPanel)
        self.employee_frame_3.setFrameShadow(QFrame.Raised)
        self.employee_frame_3.setObjectName("employee_frame_3")
        self.verticalLayout_5 = QVBoxLayout(self.employee_frame_3)
        self.verticalLayout_5.setObjectName("verticalLayout_5")
        spacerItem1 = QSpacerItem(20, 217, QSizePolicy.Minimum,
                                  QSizePolicy.Expanding)
        self.verticalLayout_5.addItem(spacerItem1)
        self.label_11 = QLabel(self.employee_frame_3)
        self.label_11.setStyleSheet("background:transparent;")
        self.label_11.setObjectName("label_11")
        self.verticalLayout_5.addWidget(self.label_11)
        self.gridLayout.addWidget(self.employee_frame_3, 0, 2, 1, 1)
        self.menu_frame_4 = QFrame(self.home_page)
        self.menu_frame_4.setStyleSheet(
            "background-image:url(:/images/menu_frame.png);\n"
            "background-repeat: no-repeat;\n"
            "background-position: center;\n"
            "background-color:#297ACC;")
        self.menu_frame_4.setFrameShape(QFrame.StyledPanel)
        self.menu_frame_4.setFrameShadow(QFrame.Raised)
        self.menu_frame_4.setObjectName("menu_frame_4")
        self.verticalLayout_3 = QVBoxLayout(self.menu_frame_4)
        self.verticalLayout_3.setObjectName("verticalLayout_3")
        spacerItem2 = QSpacerItem(20, 216, QSizePolicy.Minimum,
                                  QSizePolicy.Expanding)
        self.verticalLayout_3.addItem(spacerItem2)
        self.label_12 = QLabel(self.menu_frame_4)
        self.label_12.setStyleSheet("background:transparent;")
        self.label_12.setObjectName("label_12")
        self.verticalLayout_3.addWidget(self.label_12)
        self.gridLayout.addWidget(self.menu_frame_4, 1, 0, 1, 1)
        self.report_frame_5 = QFrame(self.home_page)
        self.report_frame_5.setStyleSheet(
            "background-image:url(:/images/report_frame.png);\n"
            "background-repeat: no-repeat;\n"
            "background-position: center;\n"
            "background-color:#006BB2;")
        self.report_frame_5.setFrameShape(QFrame.StyledPanel)
        self.report_frame_5.setFrameShadow(QFrame.Raised)
        self.report_frame_5.setObjectName("report_frame_5")
        self.verticalLayout_6 = QVBoxLayout(self.report_frame_5)
        self.verticalLayout_6.setObjectName("verticalLayout_6")
        spacerItem3 = QSpacerItem(20, 216, QSizePolicy.Minimum,
                                  QSizePolicy.Expanding)
        self.verticalLayout_6.addItem(spacerItem3)
        self.label_13 = QLabel(self.report_frame_5)
        self.label_13.setStyleSheet("background:transparent;")
        self.label_13.setObjectName("label_13")
        self.verticalLayout_6.addWidget(self.label_13)
        self.gridLayout.addWidget(self.report_frame_5, 1, 1, 1, 1)
        self.waste_frame_6 = QFrame(self.home_page)
        self.waste_frame_6.setStyleSheet(
            "background-image:url(:/images/waste_frame.png);\n"
            "background-repeat: no-repeat;\n"
            "background-position: center;\n"
            "background-color:#003D7A;")
        self.waste_frame_6.setFrameShape(QFrame.StyledPanel)
        self.waste_frame_6.setFrameShadow(QFrame.Raised)
        self.waste_frame_6.setObjectName("waste_frame_6")
        self.verticalLayout_7 = QVBoxLayout(self.waste_frame_6)
        self.verticalLayout_7.setObjectName("verticalLayout_7")
        spacerItem4 = QSpacerItem(20, 216, QSizePolicy.Minimum,
                                  QSizePolicy.Expanding)
        self.verticalLayout_7.addItem(spacerItem4)
        self.label_14 = QLabel(self.waste_frame_6)
        self.label_14.setStyleSheet("background:transparent;")
        self.label_14.setObjectName("label_14")
        self.verticalLayout_7.addWidget(self.label_14)
        self.gridLayout.addWidget(self.waste_frame_6, 1, 2, 1, 1)
        self.inventory_frame_1 = QFrame(self.home_page)
        self.inventory_frame_1.setStyleSheet(
            "background-image:url(:/images/inventory_frame.png);\n"
            "background-repeat: no-repeat;\n"
            "background-position: center;\n"
            "background-color:#ADEBFF;")
        self.inventory_frame_1.setFrameShape(QFrame.StyledPanel)
        self.inventory_frame_1.setFrameShadow(QFrame.Raised)
        self.inventory_frame_1.setObjectName("inventory_frame_1")
        self.verticalLayout_2 = QVBoxLayout(self.inventory_frame_1)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        spacerItem5 = QSpacerItem(20, 217, QSizePolicy.Minimum,
                                  QSizePolicy.Expanding)
        self.verticalLayout_2.addItem(spacerItem5)
        self.label_9 = QLabel(self.inventory_frame_1)
        self.label_9.setStyleSheet("background:transparent;")
        self.label_9.setObjectName("label_9")
        self.verticalLayout_2.addWidget(self.label_9)
        self.gridLayout.addWidget(self.inventory_frame_1, 0, 0, 1, 1)
        self.stackedWidget.addWidget(self.home_page)
        self.detail_page = QWidget()
        self.detail_page.setObjectName("detail_page")
        self.horizontalLayout_2 = QHBoxLayout(self.detail_page)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.main_tabWidget = QTabWidget(self.detail_page)
        self.main_tabWidget.setAutoFillBackground(False)
        self.main_tabWidget.setStyleSheet("")
        self.main_tabWidget.setTabPosition(QTabWidget.West)
        self.main_tabWidget.setIconSize(QSize(60, 60))
        self.main_tabWidget.setElideMode(Qt.ElideNone)
        self.main_tabWidget.setObjectName("main_tabWidget")
        ##initializes the tabs
        self.add_tabs()
        self.main_tabWidget.setFocusPolicy(Qt.StrongFocus)
        self.main_tabWidget.focusInEvent = self.change_focus
        self.main_tabWidget.currentChanged.connect(self.change_focus)
        self.stackedWidget.currentChanged.connect(self.change_focus)
        ######
        self.horizontalLayout_2.addWidget(self.main_tabWidget)
        self.stackedWidget.addWidget(self.detail_page)
        if ('Admin', True) in self.access:
            self.stackedWidget.addWidget(Admin(self.mainwindow))
        notification = NotificationTab()
        tab = notification.notificationTab_tab_4
        tab.custom_class_object = notification  # class_object is used to access the api through the
        self.stackedWidget.addWidget(tab)
        self.gridLayout_2.addWidget(self.stackedWidget, 0, 0, 1, 1)
        self.mainwindow.setCentralWidget(self.centralWidget)
        self.menuBar = QMenuBar(self.mainwindow)
        self.menuBar.setGeometry(QRect(0, 0, 832, 29))
        self.menuBar.setObjectName("menuBar")
        self.mainwindow.setMenuBar(self.menuBar)
        self.mainToolBar = QToolBar(self.mainwindow)
        self.mainToolBar.setLayoutDirection(Qt.RightToLeft)
        self.mainToolBar.setStyleSheet("")
        self.mainToolBar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.mainToolBar.setObjectName("mainToolBar")
        self.mainwindow.addToolBar(Qt.TopToolBarArea, self.mainToolBar)
        self.statusBar = QStatusBar(self.mainwindow)
        self.statusBar.setObjectName("statusBar")
        self.mainwindow.setStatusBar(self.statusBar)
        self.toolBar = QToolBar(self.mainwindow)
        self.toolBar.setLayoutDirection(Qt.RightToLeft)
        self.toolBar.setStyleSheet("")
        self.toolBar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.toolBar.setObjectName("toolBar")
        self.mainwindow.addToolBar(Qt.TopToolBarArea, self.toolBar)
        self.actionNotification = QAction(self.mainwindow)
        self.actionNotification.setCheckable(True)
        self.actionNotification.setChecked(False)
        self.actionNotification.setEnabled(True)
        icon6 = QIcon()
        icon6.addPixmap(QPixmap(":/images/notification.png"), QIcon.Normal,
                        QIcon.Off)
        self.actionNotification.setIcon(icon6)
        self.actionNotification.setAutoRepeat(True)
        self.actionNotification.setVisible(True)
        self.actionNotification.setIconVisibleInMenu(False)
        self.actionNotification.setObjectName("actionNotification")
        self.actionNotification
        self.actionAdmin = QAction(self.mainwindow)
        # self.actionAdmin.setCheckable(True)
        icon7 = QIcon()
        icon7.addPixmap(QPixmap(":/images/admin.png"), QIcon.Normal, QIcon.Off)
        self.actionAdmin.setIcon(icon7)
        self.actionAdmin.setObjectName("actionAdmin")
        self.actionRefresh = QAction(self.mainwindow)
        icon8 = QIcon()
        icon8.addPixmap(QPixmap(":/images/refresh.png"), QIcon.Normal,
                        QIcon.Off)
        self.actionRefresh.setIcon(icon8)
        self.actionRefresh.setObjectName("actionRefresh")
        self.actionHome = QAction(self.mainwindow)
        # self.actionHome.setCheckable(True)
        icon9 = QIcon()
        icon9.addPixmap(QPixmap(":/images/home.png"), QIcon.Normal, QIcon.Off)
        self.actionHome.setIcon(icon9)
        self.actionHome.setObjectName("actionHome")
        self.actionSettings = QAction(self.mainwindow)
        icon10 = QIcon()
        icon10.addPixmap(QPixmap(":/images/settings.png"), QIcon.Normal,
                         QIcon.Off)
        self.actionSettings.setIcon(icon10)
        self.actionSettings.setObjectName("actionRefresh")
        self.toolBar.addAction(self.actionNotification)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionAdmin)
        if ('Admin', True) in self.access:
            self.toolBar.addSeparator()
        else:
            self.actionAdmin.setVisible(False)
        self.toolBar.addAction(self.actionHome)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionRefresh)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionSettings)
        ##retranslates
        self.mainwindow.setWindowTitle(
            QApplication.translate("MainWindow", settings.company, None,
                                   QApplication.UnicodeUTF8))
        self.label_10.setText(
            QApplication.translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\">BILLING</p></body></html>",
                None, QApplication.UnicodeUTF8))
        self.label_11.setText(
            QApplication.translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\">EMPLOYEE</p></body></html>",
                None, QApplication.UnicodeUTF8))
        self.label_12.setText(
            QApplication.translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\">MENU</p></body></html>",
                None, QApplication.UnicodeUTF8))
        self.label_13.setText(
            QApplication.translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\">REPORT</p></body></html>",
                None, QApplication.UnicodeUTF8))
        self.label_14.setText(
            QApplication.translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\">WASTE</p></body></html>",
                None, QApplication.UnicodeUTF8))
        self.label_9.setText(
            QApplication.translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\">INVENTORY</p></body></html>",
                None, QApplication.UnicodeUTF8))
        self.inventory_frame_1.setToolTip(
            QApplication.translate("MainWindow", "Go to the Inventory Tab",
                                   None, QApplication.UnicodeUTF8))
        self.billing_frame_2.setToolTip(
            QApplication.translate("MainWindow", "Go to the Billing Tab", None,
                                   QApplication.UnicodeUTF8))
        self.employee_frame_3.setToolTip(
            QApplication.translate("MainWindow", "Go to the Employee Tab",
                                   None, QApplication.UnicodeUTF8))
        self.menu_frame_4.setToolTip(
            QApplication.translate("MainWindow", "Go to the Menu Tab", None,
                                   QApplication.UnicodeUTF8))
        self.report_frame_5.setToolTip(
            QApplication.translate("MainWindow", "Go to the Report Tab", None,
                                   QApplication.UnicodeUTF8))
        self.waste_frame_6.setToolTip(
            QApplication.translate("MainWindow", "Go to the Waste Tab", None,
                                   QApplication.UnicodeUTF8))
        self.toolBar.setWindowTitle(
            QApplication.translate("MainWindow", "toolBar", None,
                                   QApplication.UnicodeUTF8))
        self.actionNotification.setText("&&Notification")
        # QApplication.translate("MainWindow", "&Notification", None, QApplication.UnicodeUTF8))
        self.actionNotification.setToolTip(
            QApplication.translate("MainWindow",
                                   "Click to see new notifications", None,
                                   QApplication.UnicodeUTF8))
        # self.actionNotification.setShortcut(
        # QApplication.translate("MainWindow", "Ctrl+Shift+N", None, QApplication.UnicodeUTF8))
        self.actionAdmin.setText('&&Admin')
        # QApplication.translate("MainWindow", "Admin", None, QApplication.UnicodeUTF8))
        self.actionAdmin.setToolTip(
            QApplication.translate("MainWindow",
                                   "Click to go to admin interface", None,
                                   QApplication.UnicodeUTF8))
        # self.actionAdmin.setShortcut(
        # QApplication.translate("MainWindow", "Ctrl+Shift+A", None, QApplication.UnicodeUTF8))
        self.actionRefresh.setText("&&Refresh")
        # QApplication.translate("MainWindow", "Refresh", None, QApplication.UnicodeUTF8))
        self.actionRefresh.setToolTip(
            QApplication.translate("MainWindow",
                                   "refreshes the data from the server", None,
                                   QApplication.UnicodeUTF8))
        # self.actionRefresh.setShortcut(
        # QApplication.translate("MainWindow", "Ctrl+Shift+R", None, QApplication.UnicodeUTF8))
        self.actionHome.setText('&&Home')
        # QApplication.translate("MainWindow", "Home", None, QApplication.UnicodeUTF8))
        self.actionHome.setToolTip(
            QApplication.translate("MainWindow", "Go back to the home screen",
                                   None, QApplication.UnicodeUTF8))
        self.actionSettings.setText('&&Settings')
        # QApplication.translate("MainWindow", "Settings", None, QApplication.UnicodeUTF8))
        self.actionSettings.setToolTip(
            QApplication.translate("MainWindow", "Go to the settings panel",
                                   None, QApplication.UnicodeUTF8))
        # self.actionHome.setShortcut(
        #     QApplication.translate("MainWindow", "Ctrl+Shift+H", None, QApplication.UnicodeUTF8))
        self.stackedWidget.setCurrentIndex(1)
        self.main_tabWidget.setCurrentIndex(0)

        self.ob = self.main_tabWidget.tabBar()
        # self.add_tool_tip(self.ob) todo avoided due to segmentation fault error, left for future fixes
        self.tb = EventHandlerForTabBar()
        self.ob.installEventFilter(self.tb)

        QMetaObject.connectSlotsByName(self.mainwindow)

    def add_tabs(self):
        """
        adds new tabs
        """
        global logger
        if ('Inventory', True) in self.access:
            logger.info('initiating Inventory')
            icon = QIcon()
            icon.addPixmap(QPixmap(":/images/inventory.png"), QIcon.Normal,
                           QIcon.Off)
            from inventory.inventory import Inventory

            inventory = Inventory()
            # inventory.inventory_tab_1.setToolTip("Inventory Section")
            self.main_tabWidget.addTab(inventory.inventory_tab_1, icon, "")
            inventory.inventory_detail_tabWidget.setCurrentIndex(0)
        else:
            self.inventory_frame_1.setVisible(False)
        self.progress.setLabelText('Inventory Done....')
        self.progress.setValue(2)

        if ('Billing', True) in self.access:
            logger.info('initiating Billing')
            icon1 = QIcon()
            icon1.addPixmap(QPixmap(":/images/billing.png"), QIcon.Normal,
                            QIcon.Off)
            from billing.billing import Billing

            bill = Billing()
            # bill.billing_tab_2.setToolTip("Billing Section")
            self.main_tabWidget.addTab(bill.billing_tab_2, icon1, "")
            bill.billing_detail_tabWidget.setCurrentIndex(0)
        else:
            self.billing_frame_2.setVisible(False)
        self.progress.setLabelText('Billing Done...')
        self.progress.setValue(3)

        if ('Employee', True) in self.access:
            logger.info('initiating Employee')
            icon2 = QIcon()
            icon2.addPixmap(QPixmap(":/images/employee.png"), QIcon.Normal,
                            QIcon.Off)
            from employee.employee import Employee

            employee = Employee()
            # employee.employee_tab_3.setToolTip("Employee Section")
            self.main_tabWidget.addTab(employee.employee_tab_3, icon2, "")
            employee.employee_detail_tabWidget.setCurrentIndex(0)
        else:
            self.employee_frame_3.setVisible(False)
        self.progress.setLabelText('Employee Done...')
        self.progress.setValue(4)

        if ('Menu', True) in self.access:
            logger.info('initiating Menu')
            icon3 = QIcon()
            icon3.addPixmap(QPixmap(":/images/menu.png"), QIcon.Normal,
                            QIcon.Off)
            from menu.menu import Menu

            menu = Menu()
            # menu.menu_tab_4.setToolTip("Menu Section")
            self.main_tabWidget.addTab(menu.menu_tab_4, icon3, "")
            menu.menu_detail_tabWidget.setCurrentIndex(0)
        else:
            self.menu_frame_4.setVisible(False)
        self.progress.setLabelText('Menu Done....')
        self.progress.setValue(5)

        if ('Report', True) in self.access:
            logger.info('initiating Report')
            icon4 = QIcon()
            icon4.addPixmap(QPixmap(":/images/report.png"), QIcon.Normal,
                            QIcon.Off)
            from report.report import Report

            report = Report()
            # report.report_tab_5.setToolTip("Report Section")
            self.main_tabWidget.addTab(report.report_tab_5, icon4, "")
            report.report_detail_tabWidget.setCurrentIndex(0)
        else:
            self.report_frame_5.setVisible(False)
        self.progress.setLabelText('Report Done....')
        self.progress.setValue(6)

        if ('Waste', True) in self.access:
            logger.info('initiating Waste')
            icon5 = QIcon()
            icon5.addPixmap(QPixmap(":/images/waste.png"), QIcon.Normal,
                            QIcon.Off)
            from waste.waste import Waste

            waste = Waste()
            # waste.waste_tab_6.setToolTip("Waste Section")
            self.main_tabWidget.addTab(waste.waste_tab_6, icon5, "")
            waste.waste_detail_tabWidget.setCurrentIndex(0)
        else:
            self.waste_frame_6.setVisible(False)
        self.progress.setLabelText('Waste Done....')
        self.progress.setValue(7)

    def change_focus(self, event=None):
        """
        focus method to set focus to a tab to initialize the corresponding events of the tab
        """
        wid = self.main_tabWidget.currentWidget()
        if wid:
            if wid.isVisible():
                # print wid.objectName()
                # print '1y'
                wid.setFocus()

    def add_tool_tip(
        self, ob
    ):  # todo not working causing segmentation fault, avoided calling this function
        """
        method to add tool tip to the tabs
        :param ob: Tab bar
        """
        obj = ob
        count = obj.count()
        hardcode = {
            0: 'Inventory Section',
            1: "Billing Section",
            2: "Employee Section",
            3: "Menu Section",
            4: "Report Section",
            5: "Waste Section"
        }
        for i in range(count):
            obj.setTabToolTip(i, hardcode[i])
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):

        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(810, 492)

        lbMinWidth = 65
        lbMinWidthLogin = 110
        # leMinWidth = 200

        # self.centralwidget = QWidget(MainWindow)
        self.mainSplitter = QSplitter(Qt.Horizontal, MainWindow)
        self.mainSplitter.setObjectName("centralwidget")
        self.mainSplitter.setProperty("childrenCollapsible", False)
        MainWindow.setCentralWidget(self.mainSplitter)

        self.leftSplitter = QSplitter(Qt.Vertical, self.mainSplitter)
        self.leftSplitter.setProperty("childrenCollapsible", False)

        # login_gbox
        self.login_gbox = QGroupBox(self.leftSplitter)
        self.login_gbox.setFlat(True)
        self.login_gbox.setObjectName("login_gbox")

        login_gbox_layout = QVBoxLayout(self.login_gbox)
        login_gbox_presets_layout = QHBoxLayout()
        login_gbox_server_layout = QHBoxLayout()
        login_gbox_ssl_layout = QHBoxLayout()
        login_gbox_address_layout = QHBoxLayout()
        login_gbox_pass_layout = QHBoxLayout()
        login_gbox_connect_layout = QHBoxLayout()
        login_gbox_layout.addLayout(login_gbox_presets_layout)
        login_gbox_layout.addLayout(login_gbox_server_layout)
        login_gbox_layout.addLayout(login_gbox_ssl_layout)
        login_gbox_layout.addLayout(login_gbox_address_layout)
        login_gbox_layout.addLayout(login_gbox_pass_layout)
        login_gbox_layout.addLayout(login_gbox_connect_layout)

        self.lb_presets = QLabel(self.login_gbox)
        self.lb_presets.setObjectName("lb_presets")
        self.lb_presets.setMinimumWidth(lbMinWidthLogin)
        self.lb_presets.setMaximumWidth(lbMinWidthLogin)
        self.presets_cbox = QComboBox(self.login_gbox)
        self.presets_cbox.setObjectName("presets_cbox")
        self.add_preset_btn = QPushButton(self.login_gbox)
        self.add_preset_btn.setObjectName("add_preset_btn")
        self.add_preset_btn.setMaximumWidth(30)
        self.remove_preset_btn = QPushButton(self.login_gbox)
        self.remove_preset_btn.setObjectName("remove_preset_btn")
        self.remove_preset_btn.setMaximumWidth(20)
        login_gbox_presets_layout.addWidget(self.lb_presets)
        login_gbox_presets_layout.addWidget(self.presets_cbox)
        login_gbox_presets_layout.addWidget(self.add_preset_btn)
        login_gbox_presets_layout.addWidget(self.remove_preset_btn)

        self.lb_imap_server = QLabel(self.login_gbox)
        self.lb_imap_server.setObjectName("lb_imap_server")
        self.lb_imap_server.setMinimumWidth(lbMinWidthLogin)
        self.imap_server_le = QLineEdit(self.login_gbox)
        self.imap_server_le.setObjectName("imap_server_le")
        login_gbox_server_layout.addWidget(self.lb_imap_server)
        login_gbox_server_layout.addWidget(self.imap_server_le)

        self.lb_ssl = QLabel(self.login_gbox)
        self.lb_ssl.setObjectName("lb_ssl")
        self.lb_ssl.setMinimumWidth(lbMinWidthLogin)
        self.lb_ssl.setMaximumWidth(lbMinWidthLogin)
        self.ssl_cb = QCheckBox(self.login_gbox)
        self.ssl_cb.setEnabled(False)
        self.ssl_cb.setCheckable(True)
        self.ssl_cb.setChecked(True)
        self.ssl_cb.setObjectName("ssl_cb")
        login_gbox_ssl_layout.addWidget(self.lb_ssl)
        login_gbox_ssl_layout.addWidget(self.ssl_cb)

        self.lb_adress = QLabel(self.login_gbox)
        self.lb_adress.setObjectName("lb_adress")
        self.lb_adress.setMinimumWidth(lbMinWidthLogin)
        self.adress_le = QLineEdit(self.login_gbox)
        self.adress_le.setInputMethodHints(Qt.ImhNone)
        self.adress_le.setObjectName("adress_le")
        login_gbox_address_layout.addWidget(self.lb_adress)
        login_gbox_address_layout.addWidget(self.adress_le)

        self.lb_pass = QLabel(self.login_gbox)
        self.lb_pass.setObjectName("lb_pass")
        self.lb_pass.setMinimumWidth(lbMinWidthLogin)
        self.pass_le = QLineEdit(self.login_gbox)
        self.pass_le.setText("")
        self.pass_le.setEchoMode(QLineEdit.Password)
        self.pass_le.setObjectName("pass_le")
        login_gbox_pass_layout.addWidget(self.lb_pass)
        login_gbox_pass_layout.addWidget(self.pass_le)

        self.connect_btn = QPushButton(self.login_gbox)
        self.connect_btn.setObjectName("connect_btn")
        login_gbox_connect_layout.addStretch()
        login_gbox_connect_layout.addWidget(self.connect_btn)

        # search_gbox
        self.search_gbox = QGroupBox(self.leftSplitter)
        self.search_gbox.hide()
        self.search_gbox.setObjectName("search_gbox")

        search_gbox_layout = QVBoxLayout(self.search_gbox)
        search_gbox_mailbox_layout = QVBoxLayout()
        search_gbox_date_layout = QHBoxLayout()
        search_gbox_from_layout = QHBoxLayout()
        search_gbox_to_layout = QHBoxLayout()
        search_gbox_subject_layout = QHBoxLayout()
        search_gbox_threads_layout = QHBoxLayout()
        search_gbox_paramaters_layout = QHBoxLayout()

        search_gbox_layout.addLayout(search_gbox_mailbox_layout)
        search_gbox_layout.addLayout(search_gbox_date_layout)
        search_gbox_layout.addLayout(search_gbox_from_layout)
        search_gbox_layout.addLayout(search_gbox_to_layout)
        search_gbox_layout.addLayout(search_gbox_subject_layout)
        search_gbox_layout.addLayout(search_gbox_threads_layout)
        search_gbox_layout.addLayout(search_gbox_paramaters_layout)

        self.lb_select_mailbox = QLabel(self.search_gbox)
        self.lb_select_mailbox.setObjectName("lb_select_mailbox")
        self.mailboxes_lw = QListWidget(self.search_gbox)
        self.mailboxes_lw.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.mailboxes_lw.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.mailboxes_lw.setObjectName("mailboxes_lw")
        search_gbox_mailbox_layout.addWidget(self.lb_select_mailbox)
        search_gbox_mailbox_layout.addWidget(self.mailboxes_lw)

        self.since_date_cb = QCheckBox(self.search_gbox)
        self.since_date_cb.setObjectName("since_date_cb")
        self.since_date_cb.setMinimumWidth(lbMinWidth)
        self.since_date_cb.setMaximumWidth(lbMinWidth)
        self.since_date_edit = QDateEdit(self.search_gbox)
        self.since_date_edit.setCalendarPopup(True)
        self.since_date_edit.setObjectName("since_date_edit")
        self.since_date_edit.setDate(QDate.currentDate().addDays(-365))
        self.since_date_edit.setMaximumDate(QDate.currentDate())
        self.since_date_edit.setEnabled(False)
        self.before_date_cb = QCheckBox(self.search_gbox)
        self.before_date_cb.setObjectName("before_date_cb")
        self.before_date_cb.setMinimumWidth(70)
        self.before_date_cb.setMaximumWidth(70)
        self.before_date_edit = QDateEdit(self.search_gbox)
        self.before_date_edit.setCalendarPopup(True)
        self.before_date_edit.setObjectName("before_date_edit")
        self.before_date_edit.setDate(QDate.currentDate())
        self.before_date_edit.setMaximumDate(QDate.currentDate())
        self.before_date_edit.setEnabled(False)
        search_gbox_date_layout.addWidget(self.since_date_cb)
        search_gbox_date_layout.addWidget(self.since_date_edit)
        search_gbox_date_layout.addWidget(self.before_date_cb)
        search_gbox_date_layout.addWidget(self.before_date_edit)

        self.lb_from = QLabel(self.search_gbox)
        self.lb_from.setObjectName("lb_from")
        self.lb_from.setMinimumWidth(lbMinWidth)
        self.from_le = QLineEdit(self.search_gbox)
        self.from_le.setObjectName("from_le")
        search_gbox_from_layout.addWidget(self.lb_from)
        search_gbox_from_layout.addWidget(self.from_le)

        self.lb_to = QLabel(self.search_gbox)
        self.lb_to.setObjectName("lb_to")
        self.lb_to.setMinimumWidth(lbMinWidth)
        self.to_le = QLineEdit(self.search_gbox)
        self.to_le.setObjectName("to_le")
        search_gbox_to_layout.addWidget(self.lb_to)
        search_gbox_to_layout.addWidget(self.to_le)

        self.lb_subject = QLabel(self.search_gbox)
        self.lb_subject.setObjectName("lb_subject")
        self.lb_subject.setMinimumWidth(lbMinWidth)
        self.subject_le = QLineEdit(self.search_gbox)
        self.subject_le.setObjectName("subject_le")
        search_gbox_subject_layout.addWidget(self.lb_subject)
        search_gbox_subject_layout.addWidget(self.subject_le)

        # self.lb_threads = QLabel(self.search_gbox)
        # self.lb_threads.setObjectName("lb_threads")
        # self.lb_threads.setMaximumWidth(lbMinWidth)
        # self.thread_count_sb = QSpinBox(self.search_gbox)
        # self.thread_count_sb.setMinimum(1)
        # self.thread_count_sb.setMaximum(10)
        # self.thread_count_sb.setObjectName("thread_count_sb")
        self.html_radio = QRadioButton(self.search_gbox)
        self.html_radio.setObjectName("html_radio")
        self.text_radio = QRadioButton(self.search_gbox)
        self.text_radio.setObjectName("text_radio")
        self.extactTypeButtonGroup = QButtonGroup(self)
        self.extactTypeButtonGroup.addButton(self.html_radio)
        self.extactTypeButtonGroup.addButton(self.text_radio)
        self.html_radio.setChecked(True)
        self.search_btn = QPushButton(self.search_gbox)
        self.search_btn.setObjectName("search_btn")
        # search_gbox_threads_layout.addWidget(self.lb_threads)
        # search_gbox_threads_layout.addWidget(self.thread_count_sb)
        search_gbox_threads_layout.addStretch()
        search_gbox_threads_layout.addWidget(self.html_radio)
        search_gbox_threads_layout.addWidget(self.text_radio)
        # search_gbox_threads_layout.addStretch()
        search_gbox_threads_layout.addWidget(self.search_btn)

        self.parameters_cb = QCheckBox(self.search_gbox)
        self.parameters_cb.setText("")
        self.parameters_cb.setObjectName("parameters_cb")
        self.parameters_le = QLineEdit(self.search_gbox)
        self.parameters_le.setEnabled(False)
        self.parameters_le.setObjectName("parameters_le")
        search_gbox_paramaters_layout.addWidget(self.parameters_cb)
        search_gbox_paramaters_layout.addWidget(self.parameters_le)

        # log_gbox
        self.log_gbox = QGroupBox(self.leftSplitter)
        self.log_gbox.setFlat(True)
        self.log_gbox.setObjectName("log_gbox")
        log_layout = QVBoxLayout(self.log_gbox)
        self.log_te = QTextEdit(self.log_gbox)
        self.log_te.setLineWrapMode(QTextEdit.NoWrap)
        self.log_te.setReadOnly(True)
        self.log_te.setTextInteractionFlags(Qt.TextSelectableByKeyboard | Qt.TextSelectableByMouse)
        self.log_te.setObjectName("log_te")

        self.disconnect_btn = QPushButton(self.log_gbox)
        self.disconnect_btn.setObjectName("disconnect_btn")
        self.disconnect_btn.hide()
        log_layout.addWidget(self.log_te)
        log_layout_btn = QHBoxLayout()
        log_layout.addLayout(log_layout_btn)
        log_layout_btn.addWidget(self.disconnect_btn)
        log_layout_btn.addStretch()

        # links_gbox
        self.links_gbox = QGroupBox(self.mainSplitter)
        self.links_gbox.setFlat(True)
        self.links_gbox.setObjectName("links_gbox")
        links_gbox_layout = QVBoxLayout(self.links_gbox)
        links_gbox_links_layout = QVBoxLayout()
        links_gbox_buttons_layout = QHBoxLayout()
        links_gbox_layout.addLayout(links_gbox_links_layout)
        links_gbox_layout.addLayout(links_gbox_buttons_layout)

        self.links_text_edit = QTextEdit(self.links_gbox)
        self.links_text_edit.setObjectName("links_text_edit")
        links_gbox_links_layout.addWidget(self.links_text_edit)

        self.export_txt_btn = QPushButton(self.links_gbox)
        self.export_txt_btn.setObjectName("export_txt_btn")
        self.export_txt_btn.setEnabled(False)
        self.export_html_btn = QPushButton(self.links_gbox)
        self.export_html_btn.setObjectName("export_html_btn")
        self.export_html_btn.setEnabled(False)

        links_gbox_buttons_layout.addWidget(self.export_txt_btn)
        links_gbox_buttons_layout.addWidget(self.export_html_btn)

        # menubar
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setObjectName("menubar")
        self.menu_file = QMenu(self.menubar)
        self.menu_file.setObjectName("menu_file")
        self.menu_about = QMenu(self.menubar)
        self.menu_about.setObjectName("menu_about")
        MainWindow.setMenuBar(self.menubar)
        self.action_about = QAction(MainWindow)
        self.action_about.setObjectName("action_about")
        self.action_About_Qt = QAction(MainWindow)
        self.action_About_Qt.setObjectName("action_About_Qt")
        self.action_exit = QAction(MainWindow)
        self.action_exit.setObjectName("action_exit")
        self.actionSave = QAction(MainWindow)
        self.actionSave.setObjectName("actionSave")
        self.menu_file.addAction(self.action_exit)
        self.menu_about.addAction(self.action_about)
        self.menu_about.addAction(self.action_About_Qt)
        self.menubar.addAction(self.menu_file.menuAction())
        self.menubar.addAction(self.menu_about.menuAction())

        self.retranslateUi(MainWindow)
        QMetaObject.connectSlotsByName(MainWindow)
        MainWindow.setTabOrder(self.presets_cbox, self.imap_server_le)
        MainWindow.setTabOrder(self.imap_server_le, self.adress_le)
        MainWindow.setTabOrder(self.adress_le, self.pass_le)
        MainWindow.setTabOrder(self.pass_le, self.connect_btn)
        MainWindow.setTabOrder(self.connect_btn, self.log_te)
        MainWindow.setTabOrder(self.log_te, self.since_date_cb)
        MainWindow.setTabOrder(self.since_date_cb, self.since_date_edit)
        MainWindow.setTabOrder(self.since_date_edit, self.before_date_cb)
        MainWindow.setTabOrder(self.before_date_cb, self.before_date_edit)
        MainWindow.setTabOrder(self.before_date_edit, self.mailboxes_lw)
        MainWindow.setTabOrder(self.mailboxes_lw, self.from_le)
        MainWindow.setTabOrder(self.from_le, self.to_le)
        MainWindow.setTabOrder(self.to_le, self.subject_le)
        MainWindow.setTabOrder(self.subject_le, self.search_btn)
        MainWindow.setTabOrder(self.search_btn, self.links_text_edit)
        MainWindow.setTabOrder(self.links_text_edit, self.export_txt_btn)
        MainWindow.setTabOrder(self.export_txt_btn, self.export_html_btn)
        MainWindow.setTabOrder(self.export_html_btn, self.disconnect_btn)
        MainWindow.setTabOrder(self.disconnect_btn, self.add_preset_btn)
        MainWindow.setTabOrder(self.add_preset_btn, self.remove_preset_btn)
        MainWindow.setTabOrder(self.remove_preset_btn, self.ssl_cb)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QApplication.translate("MainWindow", "Email Link Extractor", None, QApplication.UnicodeUTF8))
        self.login_gbox.setTitle(QApplication.translate("MainWindow", "  Login", None, QApplication.UnicodeUTF8))
        self.lb_presets.setText(QApplication.translate("MainWindow", "Server Presets", None, QApplication.UnicodeUTF8))
        self.add_preset_btn.setText(QApplication.translate("MainWindow", "+", None, QApplication.UnicodeUTF8))
        self.remove_preset_btn.setText(QApplication.translate("MainWindow", "-", None, QApplication.UnicodeUTF8))
        self.lb_imap_server.setText(QApplication.translate("MainWindow", "IMAP Server", None, QApplication.UnicodeUTF8))
        self.lb_ssl.setText(QApplication.translate("MainWindow", "SSL", None, QApplication.UnicodeUTF8))
        self.ssl_cb.setText(QApplication.translate("MainWindow", "Port : 993", None, QApplication.UnicodeUTF8))
        self.lb_adress.setText(QApplication.translate("MainWindow", "Adress", None, QApplication.UnicodeUTF8))
        self.lb_pass.setText(QApplication.translate("MainWindow", "Password", None, QApplication.UnicodeUTF8))
        self.connect_btn.setText(QApplication.translate("MainWindow", "Connect", None, QApplication.UnicodeUTF8))
        self.lb_select_mailbox.setText(QApplication.translate("MainWindow", "Select Mailbox", None, QApplication.UnicodeUTF8))

        self.search_gbox.setTitle(QApplication.translate("MainWindow", "  Search Parameters", None, QApplication.UnicodeUTF8))
        self.since_date_cb.setText(QApplication.translate("MainWindow", "Since", None, QApplication.UnicodeUTF8))
        self.since_date_edit.setDisplayFormat(QApplication.translate("MainWindow", "dd-MMM-yyyy", None, QApplication.UnicodeUTF8))
        self.before_date_cb.setText(QApplication.translate("MainWindow", "Before", None, QApplication.UnicodeUTF8))
        self.before_date_edit.setDisplayFormat(QApplication.translate("MainWindow", "dd-MMM-yyyy", None, QApplication.UnicodeUTF8))

        self.html_radio.setText(QApplication.translate("MainWindow", "html", None, QApplication.UnicodeUTF8))
        self.text_radio.setText(QApplication.translate("MainWindow", "text", None, QApplication.UnicodeUTF8))
        # self.lb_threads.setText(QApplication.translate("MainWindow", "Threads", None, QApplication.UnicodeUTF8))

        self.lb_from.setText(QApplication.translate("MainWindow", "From", None, QApplication.UnicodeUTF8))
        self.lb_to.setText(QApplication.translate("MainWindow", "To", None, QApplication.UnicodeUTF8))
        self.lb_subject.setText(QApplication.translate("MainWindow", "Subject", None, QApplication.UnicodeUTF8))
        self.search_btn.setText(QApplication.translate("MainWindow", "Search", None, QApplication.UnicodeUTF8))

        self.links_gbox.setTitle(QApplication.translate("MainWindow", "  Links", None, QApplication.UnicodeUTF8))
        self.export_html_btn.setText(QApplication.translate("MainWindow", "Export as HTML", None, QApplication.UnicodeUTF8))
        self.export_txt_btn.setText(QApplication.translate("MainWindow", "Export as txt", None, QApplication.UnicodeUTF8))
        self.log_gbox.setTitle(QApplication.translate("MainWindow", "  Log", None, QApplication.UnicodeUTF8))
        self.disconnect_btn.setText(QApplication.translate("MainWindow", "Disconnect", None, QApplication.UnicodeUTF8))
        self.menu_file.setTitle(QApplication.translate("MainWindow", "File", None, QApplication.UnicodeUTF8))
        self.menu_about.setTitle(QApplication.translate("MainWindow", "About", None, QApplication.UnicodeUTF8))
        self.action_about.setText(QApplication.translate("MainWindow", "About", None, QApplication.UnicodeUTF8))
        self.action_About_Qt.setText(QApplication.translate("MainWindow", "About Qt", None, QApplication.UnicodeUTF8))
        self.action_exit.setText(QApplication.translate("MainWindow", "Exit", None, QApplication.UnicodeUTF8))
        self.action_exit.setShortcut(QApplication.translate("MainWindow", "Ctrl+Q", None, QApplication.UnicodeUTF8))
        self.actionSave.setText(QApplication.translate("MainWindow", "Save", None, QApplication.UnicodeUTF8))
示例#16
0
class ConfigEditor(QMainWindow):
    
    def __init__(self, app, cfg, title='Config Editor'):
        super(ConfigEditor, self).__init__()
        
        self.app = app
        self.config = cfg
        self.title = title
        
    def setup(self):
        
        self.dirty = False
        
        self.def_cfg = copy.deepcopy(self.config)
        self.config.update_from_user_file()
        self.base_cfg = copy.deepcopy(self.config)
        
        self.categories = QListWidget()
        #self.categories.setSizePolicy(QSizePolicy.Fixed,QSizePolicy.Expanding)
        self.settings = QStackedWidget()
        #self.categories.setSizePolicy(QSizePolicy.MinimumExpanding,QSizePolicy.Expanding)
        
        QObject.connect(self.categories, SIGNAL('itemSelectionChanged()'), self.category_selected)
        
        self.widget_list = {}
        for cat in self.config.get_categories():
            self.widget_list[cat] = {}
        longest_cat = 0
        for cat in self.config.get_categories():
            if len(cat) > longest_cat:
                longest_cat = len(cat)
            self.categories.addItem(cat)
            settings_layout = QGridLayout()
            r = 0
            c = 0
            for setting in self.config.get_settings(cat):
                info = self.config.get_setting(cat, setting, True)
                s = QWidget()
                s.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Fixed)
                sl = QVBoxLayout()
                label = QLabel()
                if info.has_key('alias'):
                    label.setText(info['alias'])
                else:
                    label.setText(setting)
                if info.has_key('about'):
                    label.setToolTip(info['about'])
                sl.addWidget(label)
                if info['type'] == constants.CT_LINEEDIT:
                    w = LineEdit(self, self.config,cat,setting,info)
                elif info['type'] == constants.CT_CHECKBOX:
                    w = CheckBox(self, self.config,cat,setting,info)
                elif info['type'] == constants.CT_SPINBOX:
                    w = SpinBox(self, self.config,cat,setting,info)
                elif info['type'] == constants.CT_DBLSPINBOX:
                    w = DoubleSpinBox(self, self.config,cat,setting,info)
                elif info['type'] == constants.CT_COMBO:
                    w = ComboBox(self, self.config,cat,setting,info)
                w.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Fixed)
                self.widget_list[cat][setting] = w
                sl.addWidget(w)
                s.setLayout(sl)
                c = self.config.config[cat].index(setting) % 2
                settings_layout.addWidget(s, r, c)
                if c == 1:
                    r += 1
            settings = QWidget()
            settings.setLayout(settings_layout)
            settings_scroller = QScrollArea()
            settings_scroller.setWidget(settings)
            settings_scroller.setWidgetResizable(True)
            self.settings.addWidget(settings_scroller)
            
        font = self.categories.font()
        fm = QFontMetrics(font)
        self.categories.setMaximumWidth(fm.widthChar('X')*(longest_cat+4))
        
        self.main = QWidget()
        self.main_layout = QVBoxLayout()
        
        self.config_layout = QHBoxLayout()
        self.config_layout.addWidget(self.categories)
        self.config_layout.addWidget(self.settings)
        
        self.mainButtons = QDialogButtonBox(QDialogButtonBox.RestoreDefaults | QDialogButtonBox.Reset | QDialogButtonBox.Apply)
        self.main_apply = self.mainButtons.button(QDialogButtonBox.StandardButton.Apply)
        self.main_reset = self.mainButtons.button(QDialogButtonBox.StandardButton.Reset)
        self.main_defaults = self.mainButtons.button(QDialogButtonBox.StandardButton.LastButton)
        QObject.connect(self.mainButtons, SIGNAL('clicked(QAbstractButton *)'), self.mainbutton_clicked)
        
        self.dirty_check()
        
        self.main_layout.addLayout(self.config_layout)
        self.main_layout.addWidget(self.mainButtons)
        
        self.main.setLayout(self.main_layout)
        
        self.setCentralWidget(self.main)
        self.setWindowTitle(self.title)
        self.setUnifiedTitleAndToolBarOnMac(True)
        
        self.categories.setCurrentItem(self.categories.item(0))
        
        self.menuBar = QMenuBar()
        self.filemenu = QMenu('&File')
        self.quitAction = QAction(self)
        self.quitAction.setText('&Quit')
        if platform.system() != 'Darwin':
            self.quitAction.setShortcut(QKeySequence(Qt.CTRL + Qt.Key_Q))
        QObject.connect(self.quitAction, SIGNAL('triggered()'), self.quitApp)
        self.filemenu.addAction(self.quitAction)
        self.menuBar.addMenu(self.filemenu)
        self.setMenuBar(self.menuBar)
        
        self.show()
        self.activateWindow()
        self.raise_()
        
        self.setMinimumWidth(self.geometry().width()*1.2)
        
        screen = QDesktopWidget().screenGeometry()
        size = self.geometry()
        self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)
        
    def category_selected(self):
        self.settings.setCurrentIndex(self.config.config.index(self.categories.selectedItems()[0].text()))
        
    def mainbutton_clicked(self, button):
        if button == self.main_reset:
            for cat in self.base_cfg.get_categories():
                for setting in self.base_cfg.get_settings(cat):
                    self.widget_list[cat][setting].updateValue(self.base_cfg.get_setting(cat,setting))
        elif button == self.main_defaults:
            for cat in self.def_cfg.get_categories():
                for setting in self.def_cfg.get_settings(cat):
                    self.widget_list[cat][setting].updateValue(self.def_cfg.get_setting(cat,setting))
        elif button == self.main_apply:
            bad_settings = self.validate_settings()
            if bad_settings == []:
                self.save_settings()
                self.main_apply.setEnabled(False)
                self.main_reset.setEnabled(False)
            else:
                msgBox = QMessageBox()
                msgBox.setText("Must fix the following invalid settings before quitting:")
                msgBox.setStandardButtons(QMessageBox.Ok)
                info = ''
                for setting in bad_settings:
                    new = '%s,%s<br>' % setting
                    info = '%s%s' % (info, new)
                msgBox.setInformativeText(info)
                msgBox.exec_()
            
        
    def quitApp(self):
        self.app.closeAllWindows()
        
    def get_changes(self):
        enc = MyEncoder()
        if enc.encode(self.def_cfg.config) == enc.encode(self.config.config):
            return False
        if enc.encode(self.base_cfg.config) != enc.encode(self.config.config):
            newC = Config()
            for c in self.config.config.keys():
                for s in self.config.config[c].keys():
                    if self.config.config[c][s]['value'] != self.def_cfg.config[c][s]['value']:
                        newC.add_setting(c, s, self.config.config[c][s]['value'], stub=True)    
            return json.dumps(newC.config, separators=(',',': '), indent=4, sort_keys=True)
        else:
            return None
        
    def validate_settings(self):
        ret = []
        for cat in self.config.get_categories():
            for setting in self.config.get_settings(cat):
                info = self.config.get_setting(cat, setting, True)
                if info.has_key('validate'):
                    if not info['validate'](info):
                        ret.append((cat,setting))
        return ret
    
    def dirty_check(self):
        if str(self.base_cfg) != str(self.config):
            self.dirty = True
            self.main_apply.setEnabled(True)
            self.main_reset.setEnabled(True)
        else:
            self.dirty = False
            self.main_apply.setEnabled(False)
            self.main_reset.setEnabled(False)
        if str(self.def_cfg) == str(self.config):
            self.main_defaults.setEnabled(False)
        else:
            self.main_defaults.setEnabled(True)
            
    def save_settings(self):
        config = self.get_changes()
        if config == False:
            if os.path.isfile(self.config.user_file):
                os.remove(self.config.user_file)
        elif config != None:
            with open(self.config.user_file, 'w+') as f:
                f.write(config)
        self.base_cfg = copy.deepcopy(self.config)
            
    def closeEvent(self, event=None):
        self.quitApp()
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):

        lbMinWidth = 65
        # leMinWidth = 200

        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(400, 310)

        # self.centralwidget = QWidget(MainWindow)
        self.mainSplitter = QSplitter(Qt.Horizontal, MainWindow)
        self.mainSplitter.setObjectName("centralwidget")
        self.mainSplitter.setProperty("childrenCollapsible", False)
        MainWindow.setCentralWidget(self.mainSplitter)

        self.leftSplitter = QSplitter(Qt.Vertical, self.mainSplitter)
        self.leftSplitter.setProperty("childrenCollapsible", False)
        ##### login_gbox
        self.login_gbox = QGroupBox(self.leftSplitter)
        self.login_gbox.setFlat(True)
        self.login_gbox.setObjectName("login_gbox")

        login_gbox_layout = QVBoxLayout(self.login_gbox)
        login_gbox_csf_layout = QHBoxLayout()
        login_gbox_account_layout = QHBoxLayout()
        login_gbox_connect_layout = QHBoxLayout()
        login_gbox_layout.addLayout(login_gbox_csf_layout)
        login_gbox_layout.addLayout(login_gbox_account_layout)
        login_gbox_layout.addLayout(login_gbox_connect_layout)

        self.lb_client_secrets_file_path = QLabel(self.login_gbox)
        self.lb_client_secrets_file_path.setObjectName("lb_client_secrets_file_path")
        self.lb_client_secrets_file_path.setMinimumWidth(lbMinWidth)

        self.client_secrets_file_path_le = QLineEdit(self.login_gbox)
        self.client_secrets_file_path_le.setObjectName("client_secrets_file_path_le")

        self.client_secret_file_path_tBtn = QToolButton(self.login_gbox)
        self.client_secret_file_path_tBtn.setObjectName("client_secret_file_path_tBtn")

        login_gbox_csf_layout.addWidget(self.lb_client_secrets_file_path)
        login_gbox_csf_layout.addWidget(self.client_secrets_file_path_le)
        login_gbox_csf_layout.addWidget(self.client_secret_file_path_tBtn)

        self.lb_account = QLabel(self.login_gbox)
        self.lb_account.setMaximumWidth(lbMinWidth)
        self.lb_account.setObjectName("lb_account")

        self.remove_account_btn = QToolButton(self.login_gbox)
        self.remove_account_btn.setObjectName("remove_account_btn")
        self.remove_account_btn.setMinimumWidth(20)
        self.remove_account_btn.setEnabled(False)

        self.add_account_btn = QToolButton(self.login_gbox)
        self.add_account_btn.setObjectName("add_account_btn")
        self.add_account_btn.setMinimumWidth(20)

        self.accounts_cb = QComboBox(self.login_gbox)
        self.accounts_cb.setObjectName("accounts_cb")

        login_gbox_account_layout.addWidget(self.lb_account)
        login_gbox_account_layout.addWidget(self.remove_account_btn)
        login_gbox_account_layout.addWidget(self.add_account_btn)
        login_gbox_account_layout.addWidget(self.accounts_cb)

        self.lb_decryption_key = QLabel(self.login_gbox)
        self.lb_decryption_key.setObjectName("lb_decryption_key")
        self.lb_decryption_key.setMinimumWidth(lbMinWidth)
        self.lb_decryption_key.hide()

        self.decryption_key_le = QLineEdit(self.login_gbox)
        self.decryption_key_le.setEchoMode(QLineEdit.Password)
        self.decryption_key_le.setObjectName("decryption_key_le")
        self.decryption_key_le.hide()

        self.connect_btn = QPushButton(self.login_gbox)
        self.connect_btn.setEnabled(False)
        self.connect_btn.setObjectName("connect_btn")

        login_gbox_connect_layout.addWidget(self.lb_decryption_key)
        login_gbox_connect_layout.addWidget(self.decryption_key_le)
        login_gbox_connect_layout.addWidget(self.connect_btn)

        #### search_gbox
        self.search_gbox = QGroupBox(self.leftSplitter)
        self.search_gbox.setFlat(True)
        self.search_gbox.setObjectName("search_gbox")
        self.search_gbox.hide()

        search_gbox_layout = QVBoxLayout(self.search_gbox)
        search_gbox_mailbox_layout = QVBoxLayout()
        search_gbox_date_layout = QHBoxLayout()
        search_gbox_from_layout = QHBoxLayout()
        search_gbox_to_layout = QHBoxLayout()
        search_gbox_subject_layout = QHBoxLayout()
        search_gbox_threads_layout = QHBoxLayout()
        search_gbox_paramaters_layout = QHBoxLayout()

        search_gbox_layout.addLayout(search_gbox_mailbox_layout)
        search_gbox_layout.addLayout(search_gbox_date_layout)
        search_gbox_layout.addLayout(search_gbox_from_layout)
        search_gbox_layout.addLayout(search_gbox_to_layout)
        search_gbox_layout.addLayout(search_gbox_subject_layout)
        search_gbox_layout.addLayout(search_gbox_threads_layout)
        search_gbox_layout.addLayout(search_gbox_paramaters_layout)

        self.lb_select_mailbox = QLabel(self.search_gbox)
        self.lb_select_mailbox.setObjectName("lb_select_mailbox")
        self.mailboxes_lw = QListWidget(self.search_gbox)
        self.mailboxes_lw.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.mailboxes_lw.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.mailboxes_lw.setObjectName("mailboxes_lw")
        search_gbox_mailbox_layout.addWidget(self.lb_select_mailbox)
        search_gbox_mailbox_layout.addWidget(self.mailboxes_lw)

        self.after_date_cb = QCheckBox(self.search_gbox)
        self.after_date_cb.setObjectName("after_date_cb")
        self.after_date_cb.setMinimumWidth(lbMinWidth)
        self.after_date_cb.setMaximumWidth(lbMinWidth)
        self.after_date_edit = QDateEdit(self.search_gbox)
        self.after_date_edit.setCalendarPopup(True)
        self.after_date_edit.setObjectName("after_date_edit")
        self.after_date_edit.setDate(QDate.currentDate().addDays(-365))
        self.after_date_edit.setMaximumDate(QDate.currentDate())
        self.after_date_edit.setEnabled(False)
        self.before_date_cb = QCheckBox(self.search_gbox)
        self.before_date_cb.setObjectName("before_date_cb")
        self.before_date_cb.setMinimumWidth(70)
        self.before_date_cb.setMaximumWidth(70)
        self.before_date_edit = QDateEdit(self.search_gbox)
        self.before_date_edit.setCalendarPopup(True)
        self.before_date_edit.setObjectName("before_date_edit")
        self.before_date_edit.setDate(QDate.currentDate())
        self.before_date_edit.setMaximumDate(QDate.currentDate())
        self.before_date_edit.setEnabled(False)
        search_gbox_date_layout.addWidget(self.after_date_cb)
        search_gbox_date_layout.addWidget(self.after_date_edit)
        search_gbox_date_layout.addWidget(self.before_date_cb)
        search_gbox_date_layout.addWidget(self.before_date_edit)

        self.lb_from = QLabel(self.search_gbox)
        self.lb_from.setObjectName("lb_from")
        self.lb_from.setMinimumWidth(lbMinWidth)
        self.from_le = QLineEdit(self.search_gbox)
        self.from_le.setObjectName("from_le")
        search_gbox_from_layout.addWidget(self.lb_from)
        search_gbox_from_layout.addWidget(self.from_le)

        self.lb_to = QLabel(self.search_gbox)
        self.lb_to.setObjectName("lb_to")
        self.lb_to.setMinimumWidth(lbMinWidth)
        self.to_le = QLineEdit(self.search_gbox)
        self.to_le.setObjectName("to_le")
        search_gbox_to_layout.addWidget(self.lb_to)
        search_gbox_to_layout.addWidget(self.to_le)

        self.lb_subject = QLabel(self.search_gbox)
        self.lb_subject.setObjectName("lb_subject")
        self.lb_subject.setMinimumWidth(lbMinWidth)
        self.subject_le = QLineEdit(self.search_gbox)
        self.subject_le.setObjectName("subject_le")
        search_gbox_subject_layout.addWidget(self.lb_subject)
        search_gbox_subject_layout.addWidget(self.subject_le)

        self.lb_threads = QLabel(self.search_gbox)
        self.lb_threads.setObjectName("lb_threads")
        self.lb_threads.setMaximumWidth(lbMinWidth)
        self.thread_count_sb = QSpinBox(self.search_gbox)
        self.thread_count_sb.setMinimum(1)
        self.thread_count_sb.setMaximum(10)
        self.thread_count_sb.setObjectName("thread_count_sb")
        self.html_radio = QRadioButton(self.search_gbox)
        self.html_radio.setObjectName("html_radio")
        self.text_radio = QRadioButton(self.search_gbox)
        self.text_radio.setObjectName("text_radio")
        self.extactTypeButtonGroup = QButtonGroup(self)
        self.extactTypeButtonGroup.addButton(self.html_radio)
        self.extactTypeButtonGroup.addButton(self.text_radio)
        self.html_radio.setChecked(True)
        self.search_btn = QPushButton(self.search_gbox)
        self.search_btn.setObjectName("search_btn")
        search_gbox_threads_layout.addWidget(self.lb_threads)
        search_gbox_threads_layout.addWidget(self.thread_count_sb)
        search_gbox_threads_layout.addWidget(self.html_radio)
        search_gbox_threads_layout.addWidget(self.text_radio)
        search_gbox_threads_layout.addWidget(self.search_btn)

        self.parameters_cb = QCheckBox(self.search_gbox)
        self.parameters_cb.setText("")
        self.parameters_cb.setObjectName("parameters_cb")
        self.parameters_le = QLineEdit(self.search_gbox)
        self.parameters_le.setEnabled(False)
        self.parameters_le.setObjectName("parameters_le")
        search_gbox_paramaters_layout.addWidget(self.parameters_cb)
        search_gbox_paramaters_layout.addWidget(self.parameters_le)

        #### log_gbox
        self.log_gbox = QGroupBox(self.leftSplitter)
        self.log_gbox.setFlat(True)
        self.log_gbox.setObjectName("log_gbox")
        log_layout = QVBoxLayout(self.log_gbox)
        self.log_te = QTextEdit(self.log_gbox)
        self.log_te.setLineWrapMode(QTextEdit.NoWrap)
        self.log_te.setReadOnly(True)
        self.log_te.setTextInteractionFlags(Qt.TextSelectableByKeyboard | Qt.TextSelectableByMouse)
        self.log_te.setObjectName("log_te")

        self.disconnect_btn = QPushButton(self.log_gbox)
        self.disconnect_btn.setObjectName("disconnect_btn")
        self.disconnect_btn.hide()
        log_layout.addWidget(self.log_te)
        log_layout_btn = QHBoxLayout()
        log_layout.addLayout(log_layout_btn)
        log_layout_btn.addWidget(self.disconnect_btn)
        log_layout_btn.addStretch()

        #### links_gbox
        self.links_gbox = QGroupBox(self.mainSplitter)
        self.links_gbox.setFlat(True)
        self.links_gbox.setObjectName("links_gbox")
        self.links_gbox.hide()
        links_gbox_layout = QVBoxLayout(self.links_gbox)
        links_gbox_links_layout = QVBoxLayout()
        links_gbox_buttons_layout = QHBoxLayout()
        links_gbox_layout.addLayout(links_gbox_links_layout)
        links_gbox_layout.addLayout(links_gbox_buttons_layout)

        self.links_text_edit = QTextEdit(self.links_gbox)
        self.links_text_edit.setObjectName("links_text_edit")
        links_gbox_links_layout.addWidget(self.links_text_edit)

        self.export_txt_btn = QPushButton(self.links_gbox)
        self.export_txt_btn.setObjectName("export_txt_btn")
        self.export_txt_btn.setEnabled(False)
        self.export_html_btn = QPushButton(self.links_gbox)
        self.export_html_btn.setObjectName("export_html_btn")
        self.export_html_btn.setEnabled(False)

        links_gbox_buttons_layout.addWidget(self.export_txt_btn)
        links_gbox_buttons_layout.addWidget(self.export_html_btn)
        
        ### menubar
        self.menubar = QMenuBar(MainWindow)
        # self.menubar.setGeometry(QRect(0, 0, 860, 21))
        self.menubar.setObjectName("menubar")
        self.menu_file = QMenu(self.menubar)
        self.menu_file.setObjectName("menu_file")
        self.menu_help = QMenu(self.menubar)
        self.menu_help.setObjectName("menu_help")
        MainWindow.setMenuBar(self.menubar)
        self.action_about = QAction(MainWindow)
        self.action_about.setObjectName("action_about")
        self.action_About_Qt = QAction(MainWindow)
        self.action_About_Qt.setObjectName("action_About_Qt")
        self.action_exit = QAction(MainWindow)
        self.action_exit.setObjectName("action_exit")
        self.actionSave = QAction(MainWindow)
        self.actionSave.setObjectName("actionSave")
        self.action_Gmail_Advanced_Search_Syntax = QAction(MainWindow)
        self.action_Gmail_Advanced_Search_Syntax.setObjectName("action_Gmail_Advanced_Search_Syntax")
        self.menu_file.addAction(self.action_exit)
        self.menu_help.addAction(self.action_Gmail_Advanced_Search_Syntax)
        self.menu_help.addSeparator()
        self.menu_help.addAction(self.action_about)
        self.menu_help.addAction(self.action_About_Qt)
        self.menubar.addAction(self.menu_file.menuAction())
        self.menubar.addAction(self.menu_help.menuAction())
        
        self.retranslateUi(MainWindow)
        QMetaObject.connectSlotsByName(MainWindow)
        MainWindow.setTabOrder(self.client_secrets_file_path_le, self.client_secret_file_path_tBtn)
        MainWindow.setTabOrder(self.client_secret_file_path_tBtn, self.remove_account_btn)
        MainWindow.setTabOrder(self.remove_account_btn, self.add_account_btn)
        MainWindow.setTabOrder(self.add_account_btn, self.accounts_cb)
        MainWindow.setTabOrder(self.decryption_key_le, self.connect_btn)
        MainWindow.setTabOrder(self.connect_btn, self.log_te)
        MainWindow.setTabOrder(self.log_te, self.mailboxes_lw)
        MainWindow.setTabOrder(self.mailboxes_lw, self.after_date_cb)
        MainWindow.setTabOrder(self.after_date_cb, self.after_date_edit)
        MainWindow.setTabOrder(self.after_date_edit, self.before_date_cb)
        MainWindow.setTabOrder(self.before_date_cb, self.before_date_edit)
        MainWindow.setTabOrder(self.before_date_edit, self.from_le)
        MainWindow.setTabOrder(self.from_le, self.to_le)
        MainWindow.setTabOrder(self.to_le, self.subject_le)
        MainWindow.setTabOrder(self.subject_le, self.thread_count_sb)
        MainWindow.setTabOrder(self.thread_count_sb, self.html_radio)
        MainWindow.setTabOrder(self.html_radio, self.text_radio)
        MainWindow.setTabOrder(self.text_radio, self.search_btn)
        MainWindow.setTabOrder(self.search_btn, self.parameters_cb)
        MainWindow.setTabOrder(self.parameters_cb, self.parameters_le)
        MainWindow.setTabOrder(self.parameters_le, self.disconnect_btn)
        MainWindow.setTabOrder(self.disconnect_btn, self.links_text_edit)
        MainWindow.setTabOrder(self.links_text_edit, self.export_txt_btn)
        MainWindow.setTabOrder(self.export_txt_btn, self.export_html_btn)
        MainWindow.setTabOrder(self.export_html_btn, self.mailboxes_lw)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QApplication.translate("MainWindow", "Gmail URL Parser", None, QApplication.UnicodeUTF8))
        self.login_gbox.setTitle(QApplication.translate("MainWindow", "  Client secrets file path  ", None, QApplication.UnicodeUTF8))
        self.client_secrets_file_path_le.setPlaceholderText(QApplication.translate("MainWindow", "Please select your client secrets file", None, QApplication.UnicodeUTF8))
        self.lb_client_secrets_file_path.setText(QApplication.translate("MainWindow", "Path", None, QApplication.UnicodeUTF8))
        self.connect_btn.setText(QApplication.translate("MainWindow", "Connect", None, QApplication.UnicodeUTF8))
        self.client_secret_file_path_tBtn.setText(QApplication.translate("MainWindow", "...", None, QApplication.UnicodeUTF8))
        self.lb_account.setText(QApplication.translate("MainWindow", "Account", None, QApplication.UnicodeUTF8))
        self.add_account_btn.setText(QApplication.translate("MainWindow", "+", None, QApplication.UnicodeUTF8))
        self.remove_account_btn.setText(QApplication.translate("MainWindow", "-", None, QApplication.UnicodeUTF8))
        self.decryption_key_le.setPlaceholderText(QApplication.translate("MainWindow", "Decryption key", None, QApplication.UnicodeUTF8))
        self.lb_decryption_key.setText(QApplication.translate("MainWindow", "Key", None, QApplication.UnicodeUTF8))
        self.log_gbox.setTitle(QApplication.translate("MainWindow", "  Log  ", None, QApplication.UnicodeUTF8))
        self.search_gbox.setTitle(QApplication.translate("MainWindow", "  Search Parameters  ", None, QApplication.UnicodeUTF8))
        self.lb_to.setText(QApplication.translate("MainWindow", "To", None, QApplication.UnicodeUTF8))
        self.lb_from.setText(QApplication.translate("MainWindow", "From", None, QApplication.UnicodeUTF8))
        self.lb_subject.setText(QApplication.translate("MainWindow", "Subject", None, QApplication.UnicodeUTF8))
        self.search_btn.setText(QApplication.translate("MainWindow", "Search", None, QApplication.UnicodeUTF8))
        self.after_date_edit.setDisplayFormat(QApplication.translate("MainWindow", "yyyy-MM-dd", None, QApplication.UnicodeUTF8))
        self.before_date_edit.setDisplayFormat(QApplication.translate("MainWindow", "yyyy-MM-dd", None, QApplication.UnicodeUTF8))
        self.lb_select_mailbox.setToolTip(QApplication.translate("MainWindow", "<html><head/><body><p>Select multiple items to select labels</p></body></html>", None, QApplication.UnicodeUTF8))
        self.lb_select_mailbox.setText(QApplication.translate("MainWindow", "Select Mailbox or Labels", None, QApplication.UnicodeUTF8))
        self.after_date_cb.setText(QApplication.translate("MainWindow", "After", None, QApplication.UnicodeUTF8))
        self.before_date_cb.setText(QApplication.translate("MainWindow", "Before", None, QApplication.UnicodeUTF8))
        self.html_radio.setText(QApplication.translate("MainWindow", "html", None, QApplication.UnicodeUTF8))
        self.text_radio.setText(QApplication.translate("MainWindow", "text", None, QApplication.UnicodeUTF8))
        self.lb_threads.setText(QApplication.translate("MainWindow", "Threads", None, QApplication.UnicodeUTF8))
        self.links_gbox.setTitle(QApplication.translate("MainWindow", "  Links  ", None, QApplication.UnicodeUTF8))
        self.disconnect_btn.setText(QApplication.translate("MainWindow", "Disconnect", None, QApplication.UnicodeUTF8))
        self.export_txt_btn.setText(QApplication.translate("MainWindow", "Export as txt", None, QApplication.UnicodeUTF8))
        self.export_html_btn.setText(QApplication.translate("MainWindow", "Export as HTML", None, QApplication.UnicodeUTF8))
        self.menu_file.setTitle(QApplication.translate("MainWindow", "File", None, QApplication.UnicodeUTF8))
        self.menu_help.setTitle(QApplication.translate("MainWindow", "Help", None, QApplication.UnicodeUTF8))
        self.action_about.setText(QApplication.translate("MainWindow", "About", None, QApplication.UnicodeUTF8))
        self.action_About_Qt.setText(QApplication.translate("MainWindow", "About Qt", None, QApplication.UnicodeUTF8))
        self.action_exit.setText(QApplication.translate("MainWindow", "Exit", None, QApplication.UnicodeUTF8))
        self.action_exit.setShortcut(QApplication.translate("MainWindow", "Ctrl+Q", None, QApplication.UnicodeUTF8))
        self.actionSave.setText(QApplication.translate("MainWindow", "Save", None, QApplication.UnicodeUTF8))
        self.action_Gmail_Advanced_Search_Syntax.setText(QApplication.translate("MainWindow", "Gmail Advanced Search Syntax", None, QApplication.UnicodeUTF8))