forked from wn0112/PPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mybuttons.py
160 lines (125 loc) · 3.82 KB
/
mybuttons.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
from PyQt4 import QtGui, QtCore
class Button(QtGui.QPushButton):
def __init__(self,parent = None):
super(Button,self).__init__(parent)
self.status = 0
def loadPixmap(self, pic_name):
self.pixmap = QtGui.QPixmap(pic_name)
self.btn_width = self.pixmap.width()
self.btn_height = self.pixmap.height()/6
self.setFixedSize(self.btn_width, self.btn_height)
def mousePressEvent(self,event):
if event.button() == QtCore.Qt.LeftButton:
self.status = 2
self.update()
self.clicked.emit(True)
def mouseReleaseEvent(self,event):
if event.button() == QtCore.Qt.LeftButton:
self.status = 0
self.update()
self.released.emit()
def rst(self):
self.status = 0
self.update()
def rbReleased(self):
self.status = 0
self.update()
def rbPressed(self):
self.status = 4
self.update()
def lbPressed(self):
self.status = 3
self.update()
def lbReleased(self):
self.status = 0
self.update()
def bothPressed(self):
self.status = 5
self.update()
def bothReleased(self):
self.status = 0
self.update()
def paintEvent(self,event):
self.painter = QtGui.QPainter()
self.painter.begin(self)
self.painter.drawPixmap(self.rect(), self.pixmap.copy(0, self.btn_height * self.status, self.btn_width, self.btn_height))
self.painter.end()
class PlayButton(Button):
def __init__(self,parent = None):
super(PlayButton,self).__init__(parent)
self.setCheckable(True)
def mouseReleaseEvent(self, event):
self.released.emit()
class SRButton(PlayButton):
def __init__(self,parent = None):
super(SRButton,self).__init__(parent)
self.syn = 0
def mousePressEvent(self,event):
if event.button() == QtCore.Qt.LeftButton:
self.status = 2
self.update()
if not self.isChecked():
self.syn = 1
self.clicked.emit(True)
def mouseReleaseEvent(self, event):
if self.isChecked() and self.syn != 1:
self.clicked.emit(True)
self.released.emit()
else:
self.syn = 0
class PushButton(QtGui.QPushButton):
def __init__(self,parent = None):
super(PushButton,self).__init__(parent)
self.status = 0
def loadPixmap(self, pic_name):
self.pixmap = QtGui.QPixmap(pic_name)
self.btn_width = self.pixmap.width()/4
self.btn_height = self.pixmap.height()
self.setFixedSize(self.btn_width, self.btn_height)
def enterEvent(self,event):
if not self.isChecked() and self.isEnabled():
self.status = 1
self.update()
def setDisabled(self, bool):
super(PushButton,self).setDisabled(bool)
if not self.isEnabled():
self.status = 2
self.update()
else:
self.status = 0
self.update()
def mousePressEvent(self,event):
if event.button() == QtCore.Qt.LeftButton:
self.status = 2
self.update()
def mouseReleaseEvent(self,event):
if event.button() == QtCore.Qt.LeftButton:
self.clicked.emit(True)
if not self.isChecked():
self.status = 3
if self.menu():
self.menu().exec_(event.globalPos())
self.update()
def leaveEvent(self,event):
if not self.isChecked() and self.isEnabled():
self.status = 0
self.update()
def paintEvent(self,event):
self.painter = QtGui.QPainter()
self.painter.begin(self)
self.painter.drawPixmap(self.rect(), self.pixmap.copy(self.btn_width * self.status, 0, self.btn_width, self.btn_height))
self.painter.end()
class PushButton2(QtGui.QPushButton):
def __init__(self,parent = None):
super(PushButton2,self).__init__(parent)
# self.status = 0
def loadPixmap(self, pic_name):
self.pixmap = QtGui.QPixmap(pic_name)
self.btn_width = self.pixmap.width()
self.btn_height = self.pixmap.height()
self.setFixedSize(self.btn_width, self.btn_height)
def paintEvent(self,event):
self.painter = QtGui.QPainter()
self.painter.begin(self)
self.painter.drawPixmap(self.rect(), self.pixmap.copy(0, 0, self.btn_width, self.btn_height))
self.painter.end()