-
Notifications
You must be signed in to change notification settings - Fork 0
/
PratTransferUtility.py
168 lines (136 loc) · 6.14 KB
/
PratTransferUtility.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
"""
Main file used to launch the prat transfer gui.
No other files should be used for launching this application.
"""
__author__ = "Corwin Perren"
__copyright__ = "None"
__credits__ = [""]
__license__ = "GPL (GNU General Public License)"
__version__ = "0.1 Alpha"
__maintainer__ = "Corwin Perren"
__email__ = "[email protected]"
__status__ = "Development"
# This file is part of "PRAT Transfer Utility".
#
# "Pick And Plate" is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# "Pick And Plate" is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with "PRAT Transfer Utility". If not, see <http://www.gnu.org/licenses/>.
#####################################
# Imports
#####################################
# Python native imports
import sys
from PyQt4 import QtCore, QtGui, uic
import signal
import logging
# Custom imports
from Framework.LoggerCore import Logger
from Framework.SettingsCore import Settings
from Interface.StatusLoggerCore import StatusLoggerTab
from Interface.SystemSettingsCore import SettingsTab
from Framework.ScheduleHandlerCore import ScheduleHandler
#####################################
# Global Variables
#####################################
form_class = uic.loadUiType("Interface/PRATTransferGui.ui")[0] # Load the UI
#####################################
# ProgramWindow Class Definition
#####################################
class ProgramWindow(QtGui.QMainWindow, form_class):
kill_all_threads = QtCore.pyqtSignal()
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
# ########## Set up QT Application Window ##########
self.setupUi(self) # Has to be first call in class in order to link gui form objects
# ########## Create the system logger and get an instance of it ##########
self.logger_core = Logger(self)
# ########## Setup and get program settings ##########
self.settings = Settings(self)
# ########## Instantiations of tab classes ##########
self.log_viewer_tab = StatusLoggerTab(self)
self.settings_tab = SettingsTab(self)
# ########## Instantiations of the scheduler class ##########
self.scheduler = ScheduleHandler(self)
# ########## Creation of the system tray icon ##########
self.tray_icon = None
self.tray_menu = None
self.setup_tray_icon()
# ########## Setup application taskbar icon ##########
self.setup_taskbar_icon()
# ########## Setup of gui elements ##########
self.main_tab_widget.setCurrentIndex(0)
# ########## Class variables ##########
self.threads_to_wait_for = []
self.threads_to_wait_for.append(self.log_viewer_tab)
self.threads_to_wait_for.append(self.scheduler)
# ########## Setup signal and slot connections ##########
self.connect_signals_to_slots()
def connect_signals_to_slots(self):
self.kill_all_threads.connect(self.scheduler.on_kill_threads_slot)
self.kill_all_threads.connect(self.log_viewer_tab.on_kill_threads_slot)
def setup_tray_icon(self):
self.tray_icon = QtGui.QSystemTrayIcon(QtGui.QIcon("Resources/app_icon.png"))
self.tray_icon.activated.connect(self.on_tray_exit_triggered_slot)
self.tray_menu = QtGui.QMenu()
self.tray_menu.addAction("Show")
self.tray_menu.addAction("Exit")
self.tray_menu.triggered.connect(self.on_tray_exit_triggered_slot)
self.tray_icon.setContextMenu(self.tray_menu)
self.tray_icon.hide()
def setup_taskbar_icon(self):
app_icon = QtGui.QIcon()
app_icon.addFile("Resources/app_icon.png", QtCore.QSize(16, 16))
app_icon.addFile("Resources/app_icon.png", QtCore.QSize(24, 24))
app_icon.addFile("Resources/app_icon.png", QtCore.QSize(32, 32))
app_icon.addFile("Resources/app_icon.png", QtCore.QSize(48, 48))
app_icon.addFile("Resources/app_icon.png", QtCore.QSize(256, 256))
self.setWindowIcon(app_icon)
def closeEvent(self, event):
if self.isHidden():
self.kill_all_threads.emit()
self.wait_for_all_threads()
event.accept()
else:
message = "Are you sure you want to exit? Press NO to hide instead."
reply = QtGui.QMessageBox.question(self, "Exit Dialog", message, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
self.kill_all_threads.emit()
self.wait_for_all_threads()
event.accept()
else:
self.hide()
self.tray_icon.show()
event.ignore()
def on_tray_exit_triggered_slot(self, event):
if event == 1:
pass
elif (event == 2) or (event == 3):
self.show()
self.tray_icon.hide()
elif event.text() == "Exit":
self.close()
elif event.text() == "Show":
self.show()
self.tray_icon.hide()
def wait_for_all_threads(self):
for thread in self.threads_to_wait_for:
thread.wait()
if __name__ == "__main__":
signal.signal(signal.SIGINT, signal.SIG_DFL) # This allows the keyboard interrupt kill to work properly
app = QtGui.QApplication(sys.argv) # Create the base qt gui application
myWindow = ProgramWindow() # Make a window in this application using the pnp MyWindowClass
myWindow.setWindowTitle("Transfer Utility")
myWindow.setWindowFlags(myWindow.windowFlags() & ~QtCore.Qt.WindowMinimizeButtonHint)
myWindow.setWindowFlags(myWindow.windowFlags() & ~QtCore.Qt.WindowMaximizeButtonHint)
myWindow.resize(1500, 800)
myWindow.show() # Show the window in the application
app.exec_() # Execute launching of the application