-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomControl.py
More file actions
329 lines (258 loc) · 9.17 KB
/
CustomControl.py
File metadata and controls
329 lines (258 loc) · 9.17 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import (
QCalendarWidget, QDateTimeEdit, QDoubleSpinBox, QLabel, QLCDNumber,
QLineEdit, QMessageBox, QPushButton, QSpinBox, QTabWidget)
class CalendarWidget(QCalendarWidget):
'''Basic calendar widget type.'''
def __init__(self, parent=None):
super(CalendarWidget, self).__init__(parent)
self.setStyleSheet(self.styleSheet() + '''
QCalendarWidget * {
font-family: Verdana, Geneva, sans-serif;
font-size: 10pt;
}
''')
class DateTimeEdit (QDateTimeEdit):
'''Basic date time edit type.'''
def __init__(self, parent=None):
super(DateTimeEdit, self).__init__(parent)
self.setStyleSheet(self.styleSheet() + '''
QDateTimeEdit {
font-family: Verdana, Geneva, sans-serif;
font-size: 10pt;
padding: 0.3em;
border-style: solid;
border-width: 1px;
border-color: rgb(206, 206, 206);
border-radius: 8px;
}
QDateTimeEdit:hover {
border-width: 2px;
}
QDateTimeEdit:focus {
border-width: 2px;
border-color: rgb(138, 186, 224);
}
''')
class DoubleSpinBox(QDoubleSpinBox):
'''Basic spin box type.'''
def __init__(self, parent=None):
super(DoubleSpinBox, self).__init__(parent)
self.setSingleStep(0.05)
self.setStyleSheet(self.styleSheet() + '''
QDoubleSpinBox {
font-family: Verdana, Geneva, sans-serif;
font-size: 10pt;
padding: 0.3em;
border-style: solid;
border-width: 1px;
border-color: rgb(206, 206, 206);
border-radius: 8px;
}
QDoubleSpinBox:hover {
border-width: 2px;
}
QDoubleSpinBox:focus {
border-width: 2px;
border-color: rgb(138, 186, 224);
}
''')
class Label(QLabel):
'''Basic label type.'''
def __init__(self, text, parent=None):
super(Label, self).__init__(text, parent)
self.setStyleSheet(self.styleSheet() + '''
QLabel {
font-family: Verdana, Geneva, sans-serif;
font-size: 10pt;
}
''')
class LCDNumber(QLCDNumber):
'''Basic LCD number type.'''
def __init__(self, numDigits, parent=None):
super(LCDNumber, self).__init__(numDigits, parent)
self.setSegmentStyle(QLCDNumber.Flat)
self.setStyleSheet(self.styleSheet() + '''
QLCDNumber {
min-height: 5em;
min-width: 10em;
background-color: rgb(247, 247, 247);
border-style: solid;
border-width: 1px;
border-color: rgb(206, 206, 206);
border-radius: 8px;
}
QLCDNumber:hover {
border-width: 2px;
}
''')
class LineEdit(QLineEdit):
'''Basic line edit type.'''
def __init__(self, parent=None):
super(LineEdit, self).__init__(parent)
self.setStyleSheet(self.styleSheet() + '''
QLineEdit {
font-family: Verdana, Geneva, sans-serif;
font-size: 10pt;
padding: 0.3em;
border-style: solid;
border-width: 1px;
border-color: rgb(206, 206, 206);
border-radius: 8px;
}
QLineEdit:hover {
border-width: 2px;
}
QLineEdit:focus {
border-width: 2px;
border-color: rgb(138, 186, 224);
}
''')
class MessageBox(QMessageBox):
'''Basic message box type without specifying an icon.'''
def __init__(self, icon, title, text, buttons, parent=None):
super(MessageBox, self).__init__(icon, title, text, buttons, parent)
self.setStyleSheet(self.styleSheet() + '''
QMessageBox {
font-family: Verdana, Geneva, sans-serif;
font-size: 10pt;
}
QMessageBox QPushButton {
font-family: Verdana, Geneva, sans-serif;
border: none;
font-size: 10pt;
min-width: 5em;
height: 2em;
border-radius: 8px;
}
QMessageBox QPushButton {
background-color: rgb(138, 186, 224);
}
QMessageBox QPushButton:hover {
background-color: rgb(69, 153, 219);
}
QMessageBox QPushButton:pressed {
background-color: rgb(0, 120, 215);
}
''')
class WarningBox(MessageBox):
'''Warning message box type.'''
def __init__(self, title, text, parent=None):
super(WarningBox, self).__init__(
WarningBox.Warning, title, text, WarningBox.Ok)
self.setWindowIcon(QIcon(self.iconPixmap()))
class PushButton(QPushButton):
'''Basic button type without coloring.'''
def __init__(self, text, parent=None):
super(PushButton, self).__init__(text, parent)
self.setStyleSheet(self.styleSheet() + '''
QPushButton {
font-family: Verdana, Geneva, sans-serif;
border: none;
font-size: 10pt;
min-width: 5em;
height: 2em;
border-radius: 8px;
}
''')
def setForeground(self, color):
'''Set foreground color (i.e. text color).'''
self.setStyleSheet(self.styleSheet() + '''
QPushButton {
color: {};
}
'''.format(color))
def setBackground(self, color, hover, pressed):
'''Set background colors at normal time, when hovered, and when
pressed.'''
self.setStyleSheet(self.styleSheet() + '''
QPushButton {{
background-color: {};
}}
QPushButton:hover {{
background-color: {};
}}
QPushButton:pressed {{
background-color: {};
}}
'''.format(color, hover, pressed))
class NormalPushButton(PushButton):
'''Normal push button with gray color.'''
def __init__(self, text, parent=None):
super(NormalPushButton, self).__init__(text, parent)
self.setBackground('rgb(240, 240, 240)',
'rgb(209, 209, 209)',
'rgb(187, 187, 187)')
class ImportantPushButton(PushButton):
'''Important push button with blue color.'''
def __init__(self, text, parent=None):
super(ImportantPushButton, self).__init__(text, parent)
self.setBackground('rgb(138, 186, 224)',
'rgb(69, 153, 219)',
'rgb(0, 120, 215)')
class SpinBox(QSpinBox):
'''Basic spin box type.'''
def __init__(self, parent=None):
super(SpinBox, self).__init__(parent)
self.setStyleSheet(self.styleSheet() + '''
QSpinBox {
font-family: Verdana, Geneva, sans-serif;
font-size: 10pt;
padding: 0.3em;
border-style: solid;
border-width: 1px;
border-color: rgb(206, 206, 206);
border-radius: 8px;
}
QSpinBox:hover {
border-width: 2px;
}
QSpinBox:focus {
border-width: 2px;
border-color: rgb(138, 186, 224);
}
''')
class TabWidget(QTabWidget):
def __init__(self, parent=None):
super(TabWidget, self).__init__(parent)
self.setStyleSheet(self.styleSheet() + '''
QTabWidget {
background: transparent;
}
QTabBar::tab {
font-family: Verdana, Geneva, sans-serif;
border: none;
font-size: 10pt;
width: 8em;
height: 2em;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
QTabBar::tab:selected {
border-style: solid;
}
''')
self.setBackground('rgb(206, 206, 206)',
'rgb(219, 219, 219)',
'rgb(247, 247, 247)')
def setForeground(self, color):
'''Set foreground color (i.e. text color).'''
self.setStyleSheet(self.styleSheet() + '''
QTabBar::tab {
color: {}
}
'''.format(color))
def setBackground(self, color, hover, selected):
'''Set background colors at normal time, when hovered, and when
selected.'''
self.setStyleSheet(self.styleSheet() + '''
QTabBar::tab {{
background-color: {}
}}
QTabBar::tab:hover {{
background-color: {}
}}
QTabBar::tab:selected {{
background-color: {}
}}
'''.format(color, hover, selected))