usr bin env python coding UTF-8 import sys os from PyQt4 QtCore import

 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
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys, os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
########################################################################
class MyWidget(QWidget):
""""""
#----------------------------------------------------------------------
def __init__(self, parent=None):
"""Constructor"""
super(MyWidget, self).__init__(parent)
self.title = QString()
self.connect(self, SIGNAL("mouseMovedRight"), self.movedRight)
self.connect(self, SIGNAL("mouseMovedLeft"), self.movedLeft)
self.connect(self, SIGNAL("mouseNotMoved"), self.notMoved)
self.setWindowFlags(Qt.Dialog)
#----------------------------------------------------------------------
def event (self, event):
""""""
if event.type() == QEvent.MouseButtonPress:
self.x_coord = event.pos().x()
event.accept()
elif event.type() == QEvent.MouseButtonRelease:
if self.x_coord < event.pos().x():
self.emit(SIGNAL("mouseMovedRight"))
elif self.x_coord > event.pos().x():
self.emit(SIGNAL("mouseMovedLeft"))
else:
self.emit(SIGNAL("mouseNotMoved"))
event.accept()
elif event.type() == QEvent.Paint:
self.title = os.popen('mpc').read()
painter = QPainter(self)
painter.setRenderHint(QPainter.TextAntialiasing)
painter.drawText(self.rect(), Qt.AlignCenter, self.title)
event.accept()
return QWidget.event(self, event)
#----------------------------------------------------------------------
def movedRight(self):
""""""
os.system('mpc next')
self.update()
#----------------------------------------------------------------------
def movedLeft(self):
""""""
os.system('mpc prev')
self.update()
#----------------------------------------------------------------------
def notMoved(self):
""""""
os.system('mpc toggle')
self.update()
if __name__ == "__main__":
app = QApplication(sys.argv)
form = MyWidget()
form.show()
app.exec_()