-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.py
More file actions
90 lines (64 loc) · 3.03 KB
/
examples.py
File metadata and controls
90 lines (64 loc) · 3.03 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
from PyQt5.QtCore import QSize, Qt, QPoint
from PyQt5.Qt import QApplication
from PyQt5.QtWidgets import QWidget, QLineEdit, QLabel, QPushButton, QComboBox
import logging, sys
from adjustableWidget import AdjustableMixin, DragButtons, AdjustModes, ImgAdjustable, widget_images
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
class DeleteableMixin():
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def keyPressEvent(self, QKeyEvent):
if QKeyEvent.key() == Qt.Key_Delete:
self.deleteLater()
else:
super(type(self), self).keyPressEvent(QKeyEvent)
class Button(QPushButton, AdjustableMixin, DeleteableMixin):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.clicked.connect(self.showClick)
def showClick(self):
logging.info(self.name + ':Button Clicked')
class EditBox(QLineEdit, AdjustableMixin):
def __init__(self, parent=None, **kwargs):
aArgs = AdjustableMixin.popArgs(kwargs)
super().__init__(parent, **kwargs)
aArgs['defaultCursor'] = Qt.IBeamCursor
AdjustableMixin.__init__(self, **aArgs)
class Label(QLabel, AdjustableMixin):
# pass
def __init__(self, parent=None, *args, **kwargs):
aArgs = AdjustableMixin.popArgs(kwargs)
super().__init__(parent, **kwargs)
AdjustableMixin.__init__(self, **aArgs)
class Combo(QComboBox, AdjustableMixin, DeleteableMixin):
def __init__(self, parent=None, **kwargs):
aArgs = AdjustableMixin.popArgs(kwargs)
super().__init__(parent, **kwargs)
AdjustableMixin.__init__(self, **aArgs)
self.addItems(['RClick']+[*'1234567890'])
class Window(QWidget, AdjustableMixin):
def __init__(self, parent=None, **kwargs):
aArgs = AdjustableMixin.popArgs(kwargs)
super().__init__(parent, **kwargs)
AdjustableMixin.__init__(self, **aArgs)
if __name__ == '__main__':
app = QApplication([])
win = Window(adjustButtons=[DragButtons.MID, DragButtons.SHIFT], objectName='win')
win.setGeometry(200,200,400,500)
QLabel(parent=win, text="Shift+MidClick").move(100,200)
E = EditBox(win, adjustButtons=DragButtons.MID, objectName='E', pos=QPoint(50,100), text='MidClick')
E.setMinimumSize(QSize(50,20))
B = Button(win, objectName='B', adjustButtons=[DragButtons.RIGHT, DragButtons.SHIFT],
text='Shift+RClick', size=QSize(100, 80))
L = Label(B, objectName='L', adjustButtons=[DragButtons.RIGHT, DragButtons.CTRL],
text='Ctrl+RClick')
L.setFrameStyle(1)
C = Combo(E, adjustButtons=DragButtons.RIGHT, objectName='C', pos=QPoint(72, 0), size=QSize(70, 25),
allowedAdjustments=AdjustModes.ANCHOR_TOP)
I = ImgAdjustable(win, allowedAdjustments=AdjustModes.ANCHOR_BOTTOM, img=widget_images['arrow_red'],
size=QSize(100, 150), pos=QPoint(100, 250), objectName='I')
I.setMaximumSize(QSize(300, 300))
I.setMinimumSize(10, 20)
I.setFrameStyle(1)
win.show()
app.exec_()