This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgui.py
More file actions
executable file
·185 lines (124 loc) · 4.79 KB
/
gui.py
File metadata and controls
executable file
·185 lines (124 loc) · 4.79 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env python
import os
import webbrowser
from functools import partial
import importlib
from PySide import QtCore, QtGui, QtSvg
import define as DEFINE
_CURRENTPATH = os.path.dirname(os.path.realpath(__file__))
class MainWindow(QtGui.QMainWindow):
"""
Main window class of this tool.
"""
_windowName = DEFINE.windowName
_windowTitle = DEFINE.windowTitle
_windowHeight = DEFINE.windowHeight
_windowWidth = DEFINE.windowWidth
mantleIcon = QtGui.QIcon(DEFINE.mantleIconPath)
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.initGUI()
def initGUI(self):
self.createActions()
self.createTrayIcon()
self.trayIcon.show()
self.setWindowTitle(self._windowTitle)
self.setWindowIcon(self.mantleIcon)
## Generate Widgets
self.tabs = TabController(self)
self.setCentralWidget(self.tabs)
self.resetWindowSize()
# self.move(QtGui.QApplication.desktop().screen().rect().center()- self.rect().center())
def resetWindowSize(self):
self.resize(self._windowWidth, self._windowHeight)
def openGitHubButtonTriggered(self):
webbrowser.open('http://github.com/takavfx/Mantle')
def createActions(self):
self.showAction = QtGui.QAction("Show", self,
triggered=self.show)
self.hideAction = QtGui.QAction("Hide", self,
triggered=self.hide)
self.raiseAction = QtGui.QAction("Bring to Top", self,
triggered=self.raise_)
self.maximizeAction = QtGui.QAction("Maximize", self,
triggered=self.showMaximized)
self.quitAction = QtGui.QAction("Quit", self,
triggered=QtGui.qApp.quit)
self.openGitHubAction = QtGui.QAction("Mantle on GitHub", self,
triggered=self.openGitHubButtonTriggered)
def createTrayIcon(self):
trayIconMenu = QtGui.QMenu(self)
trayIconMenu.addAction(self.showAction)
trayIconMenu.addAction(self.hideAction)
trayIconMenu.addAction(self.raiseAction)
trayIconMenu.addAction(self.maximizeAction)
trayIconMenu.addSeparator()
trayIconMenu.addAction(self.openGitHubAction)
trayIconMenu.addSeparator()
trayIconMenu.addAction(self.quitAction)
self.trayIcon = QtGui.QSystemTrayIcon(self)
self.trayIcon.setContextMenu(trayIconMenu)
self.trayIcon.setIcon(self.mantleIcon)
class TabController(QtGui.QTabWidget):
"""
Tab Controller cantains get tabs from packages and set tabs.
"""
def __init__(self, parent=None):
super(TabController, self).__init__(parent)
self.createBaseTabWidget()
self.setSignals()
def createBaseTabWidget(self):
self.setCornerWidget(self.createAddButton())
self.setImportedPackageTabs()
def setSignals(self):
self.tabCloseRequested.connect(self.close_handler)
def close_handler(self, index):
if self.count() != 1:
self.removeTab(index)
def createAddButton(self):
self.addTabMenu = QtGui.QMenu(self)
button = QtGui.QPushButton()
button.setFlat(True)
button.setIcon(QtGui.QIcon(os.path.join(_CURRENTPATH, 'static', 'plus.svg')))
button.setMenu(self.addTabMenu)
return button
def setImportedPackageTabs(self):
packageNames = ['packages.%s'%x for x in os.listdir('%s/packages'%_CURRENTPATH)]
try:
packageNames.remove('packages.__init__.py')
packageNames.remove('packages.__init__.pyc')
except:
pass
for package in packageNames:
module = importlib.import_module(package)
widget, icon, title = module.getWidget(self)
self.addTabByItems(widget, icon, title)
## Add tab action
cmd = partial(self.addTabByItems, widget, icon, title)
action = QtGui.QAction(title, self,
triggered=cmd)
self.addTabMenu.addAction(action)
def addTabByItems(self, widget, icon, title):
index = self.getTabIndexByTitle(title)
if index is None:
if icon is None:
icon = QtGui.QIcon(DEFINE.defaultIconPath)
self.addTab(widget, icon, title)
else:
self.addTab(widget, icon, title)
def getTabIndexByTitle(self, title):
index = 0
while index < self.count():
if self.tabText(index) == title:
return index
index += 1
return None
def main():
import sys
app = QtGui.QApplication(sys.argv)
# app.setQuitOnLastWindowClosed(False)
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()