mpldr

Untitled

Jan 23rd, 2021
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.27 KB | None | 0 0
  1. import sys
  2.  
  3. from PyQt5.QtGui import QIcon
  4. from PyQt5.QtWidgets import QApplication, QMainWindow, QDialog, QInputDialog, QLineEdit, QSystemTrayIcon, QAction, QMenu
  5.  
  6. import resources.Interface
  7. import resources.ConfiGUI
  8. import modules.ui
  9. from classes.Config import Config
  10. from classes.Logger import Logger
  11.  
  12. log = Config()
  13. config = Logger()
  14. class MainGUI(QMainWindow, resources.Interface.Ui_Interface):
  15.     exitForReal = False
  16.  
  17.     def __init__(self, parent=None):
  18.         super(MainGUI, self).__init__(parent)
  19.         log.debug("ui initialised")
  20.  
  21.         self.setupUi(self)
  22.         self.setWindowIcon(QIcon('resources/icon.ico'))
  23.         log.debug("setup ui")
  24.  
  25.         self.Overview_Button_Retest.clicked.connect(lambda: self.Retest())
  26.         self.Overview_Combo_Retesttype.currentTextChanged.connect(
  27.             lambda: self.Overview_Button_Retest.setText(self.Overview_Combo_Retesttype.currentText()))
  28.         self.General_TreeView.currentItemChanged.connect(
  29.             lambda: self.UpdateDetails(self.General_TreeView.selectedIndexes()))
  30.         self.Server_Button_Configure.clicked.connect(lambda: self.ShowConfigWindow())
  31.         self.General_Button_AddServer.clicked.connect(lambda: self.AddServer())
  32.         log.debug("connected buttons")
  33.  
  34.         self.tray_icon = QSystemTrayIcon(self)
  35.         self.showhide_action = QAction("Hide", self)
  36.         quit_action = QAction("Exit", self)
  37.         self.showhide_action.triggered.connect(lambda: self.ShowHideTrigger())
  38.         quit_action.triggered.connect(lambda: self.RealExit())
  39.         tray_menu = QMenu()
  40.         tray_menu.addAction(self.showhide_action)
  41.         tray_menu.addAction(quit_action)
  42.         self.tray_icon.setIcon(QIcon('resources/icon.ico'))
  43.         self.tray_icon.setContextMenu(tray_menu)
  44.         self.tray_icon.show()
  45.  
  46.         log.info("ui ready")
  47.         self.show()
  48.  
  49.     def ShowConfigWindow(self):
  50.         log.info("open config window")
  51.         self.dialog = resources.ConfiGUI.ConfiGUI(self)
  52.         self.dialog.show()
  53.  
  54.     def Retest(self):
  55.         pass
  56.  
  57.     def AddGroup(self):
  58.         log.info("add group pressed")
  59.         text, okPressed = QInputDialog.getText(self, "Add Group", "Name of the Group:", QLineEdit.Normal, "")
  60.         if okPressed and text != '':
  61.             log.debug("received groupname \"{}\"".format(text))
  62.  
  63.     def AddServer(self):
  64.         log.info("add server pressed")
  65.         text, okPressed = QInputDialog.getText(self, "Add Server", "Serveradress to be contacted:", QLineEdit.Normal, "")
  66.         if okPressed and text != '':
  67.             log.debug("received serveraddress \"{}\"".format(text))
  68.  
  69.     def UpdateDetails(self, index):
  70.         if len(index) == 0:
  71.             return
  72.         item = self.General_TreeView.itemFromIndex(index[0])
  73.         log.info("show details of \"{}\"".format(str(item.text(0))))
  74.  
  75.     def RealExit(self):
  76.         self.exitForReal = True
  77.         self.close()
  78.  
  79.     def ShowHideTrigger(self):
  80.         if self.isHidden():
  81.             self.showhide_action.setText("Hide")
  82.             self.show()
  83.         else:
  84.             self.showhide_action.setText("Show")
  85.             self.hide()
  86.  
  87.  
  88.  
  89.     def closeEvent(self, event):
  90.         log.info("close")
  91.         if not self.exitForReal:
  92.             log.debug("caught")
  93.             event.ignore()
  94.             self.hide()
  95.             self.showhide_action.setText("Show")
  96.             if config.getboolean("Interaction", "NotifyClose"):
  97.                 modules.ui.SendNotification(self, "TSar Background Notification",
  98.                                             "TSar has been minimised to the tray, "
  99.                                             "right-click the icon for more options.")
  100.  
  101. def show():
  102.     app = QApplication(sys.argv)
  103.     window = MainGUI()
  104.     sys.exit(app.exec_())
  105.  
Advertisement
Add Comment
Please, Sign In to add comment