-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_widgets.py
80 lines (58 loc) · 2.42 KB
/
custom_widgets.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
from PyQt5.QtWidgets import *
from PyQt5.Qt import Qt
class ObjectWithIdAndLinkAndValue:
def __init__(self, id_=None, link=None, value=None):
self.id_ = id_
self.link = link
self.value = value
def get_id(self):
return self.id_
def get_link(self):
return self.link
def get_value(self):
return self.value
def set_id(self, id_):
self.id_ = id_
class TurningObject:
def __init__(self):
self.side = 0
def turn(self):
self.side ^= 1
return self.side
class ListWidgetItemWithId(QListWidgetItem, ObjectWithIdAndLinkAndValue):
def __init__(self, text, id_=None):
QListWidgetItem.__init__(self, text)
ObjectWithIdAndLinkAndValue.__init__(self, id_=id_)
class ListWidgetItemWithLinkAndValue(QListWidgetItem, ObjectWithIdAndLinkAndValue):
def __init__(self, text, link=None, value=None):
QListWidgetItem.__init__(self, text)
ObjectWithIdAndLinkAndValue.__init__(self, link=link, value=value)
class PushButtonWithId(QPushButton, ObjectWithIdAndLinkAndValue, TurningObject):
def __init__(self, *args, id_=None, **kwargs):
QPushButton.__init__(self, *args, **kwargs)
ObjectWithIdAndLinkAndValue.__init__(self, id_=id_)
TurningObject.__init__(self)
class LabelWithId(QLabel, ObjectWithIdAndLinkAndValue, TurningObject):
def __init__(self, *args, id_=None, **kwargs):
QLabel.__init__(self, *args, **kwargs)
ObjectWithIdAndLinkAndValue.__init__(self, id_=id_)
TurningObject.__init__(self)
class HorizontalTabBar(QTabBar):
def paintEvent(self, event):
painter = QStylePainter(self)
option = QStyleOptionTab()
for index in range(self.count()):
self.initStyleOption(option, index)
painter.drawControl(QStyle.CE_TabBarTabShape, option)
painter.drawText(self.tabRect(index),
Qt.AlignCenter | Qt.TextDontClip,
self.tabText(index))
def tabSizeHint(self, index):
size = QTabBar.tabSizeHint(self, index)
if size.width() < size.height():
size.transpose()
return size
class TabWidget(QTabWidget):
def __init__(self, parent=None, **kwargs):
QTabWidget.__init__(self, parent, **kwargs)
self.setTabBar(HorizontalTabBar())