• R/O
  • SSH
  • HTTPS

twitturn: Commit


Commit MetaInfo

Revision78 (tree)
Zeit2010-02-27 15:05:38
Autoryoucharmanums

Log Message

* ticker2 (Qt Animation Framework independent ticker interface) initial commit.

Ändern Zusammenfassung

Diff

--- trunk/twitturn.py (revision 77)
+++ trunk/twitturn.py (revision 78)
@@ -677,13 +677,16 @@
677677 if not self.progressBarLoading.isVisible(): return
678678 self.pushButtonUpdate.setEnabled(True)
679679 self.progressBarLoading.setVisible(False)
680- if not self.settings.value("notification/popup/disabled").toBool():
681- keys = self.systemTrayIconMessageDictionary.keys()
682- if 0 < len(keys):
683- message = ""
684- keys.sort()
685- for key in keys:
686- message += self.systemTrayIconMessageDictionary[key] + '\n'
680+
681+ keys = self.systemTrayIconMessageDictionary.keys()
682+ if 0 < len(keys):
683+ message = ""
684+ keys.sort()
685+ for key in keys:
686+ message += self.systemTrayIconMessageDictionary[key] + '\n'
687+
688+ if not self.settings.value(
689+ "notification/popup/disabled").toBool():
687690 if not notificationInterface == None:
688691 print str
689692 n = pynotify.Notification(
@@ -695,7 +698,7 @@
695698 QtCore.QString(),
696699 message,
697700 self.systemTrayIcon.NoIcon)
698- self.emit(QtCore.SIGNAL("notificated"), message)
701+ self.emit(QtCore.SIGNAL("notificated"), message)
699702 self.systemTrayIconMessageDictionary.clear()
700703
701704 self.complList.sort()
--- trunk/ticker2.py (nonexistent)
+++ trunk/ticker2.py (revision 78)
@@ -0,0 +1,158 @@
1+#!/usr/bin/env python
2+
3+import sys, os
4+
5+from PyQt4.QtCore import *
6+from PyQt4.QtGui import *
7+from PyQt4.QtNetwork import *
8+
9+from ticker import IpcOutputClient
10+
11+import signal
12+signal.signal(signal.SIGINT, signal.SIG_DFL)
13+
14+class IpcOutputClientGUI2(QWidget, IpcOutputClient):
15+ def __init__(self, parent=None):
16+ QWidget.__init__(self, parent)
17+ IpcOutputClient.__init__(self, self)
18+ self.tweetsQueue = []
19+
20+ self.dragPosition = QPoint()
21+
22+ quitAction = QAction(self.tr("E&xit"), self)
23+ quitAction.setShortcut(self.tr("Ctrl+Q"))
24+ quitAction.triggered.connect(app.quit)
25+ self.addAction(quitAction)
26+ self.setContextMenuPolicy(Qt.ActionsContextMenu)
27+
28+ self.indicatorRect = QRect(3,3,5,5)
29+
30+ self.displayString = ""
31+ self.displayStringPosition = 0
32+ self.displayStringBoundRect = QRect(
33+ 10,
34+ 2,
35+ self.width() - 15,
36+ self.height() - 4
37+ )
38+ self.timer = QBasicTimer()
39+
40+ def paintEvent(self, event):
41+ QWidget.paintEvent(self, event)
42+
43+ p = QPainter(self)
44+ p.setRenderHint(QPainter.Antialiasing)
45+
46+ p.fillRect(self.rect(), Qt.transparent)
47+
48+ p.setPen( QPen( Qt.black, 1, Qt.SolidLine))
49+ p.setBrush( QColor(0,0,0,64))
50+ p.drawRoundedRect(self.rect(), 5, 5)
51+
52+ if self.sock.state() == QAbstractSocket.ConnectedState:
53+ paintActiveIndicator(p, self.indicatorRect)
54+ else:
55+ paintEnactiveIndicator(p, self.indicatorRect)
56+ pass
57+
58+ if self.shouldTextScroll():
59+ paintText(
60+ p,
61+ self.displayString,
62+ self.displayStringBoundRect,
63+ self.displayStringPosition
64+ )
65+
66+ p.end()
67+
68+ def shouldTextScroll(self):
69+ if 0 < len(self.displayString):
70+ if self.displayStringPosition < self.fontMetrics().width( self.displayString):
71+ return True
72+
73+ return False
74+
75+ def timerEvent(self, event):
76+ if event.timerId() == self.timer.timerId():
77+ self.update()
78+ self.displayStringPosition += 1
79+ if not self.shouldTextScroll():
80+ self.timer.stop()
81+ self.tickerNext()
82+ else:
83+ QWidget.timerEvent()
84+ pass
85+
86+ def mousePressEvent(self, event):
87+ if event.button() == Qt.LeftButton:
88+ self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()
89+ event.accept()
90+ def mouseMoveEvent(self, event):
91+ if event.buttons() & Qt.LeftButton:
92+ self.move(event.globalPos() - self.dragPosition)
93+ event.accept()
94+
95+ def slotConnected(self):
96+ self.repaint(self.indicatorRect)
97+ pass
98+ def slotDisconnected(self):
99+ self.repaint(self.indicatorRect)
100+ pass
101+
102+ def read(self):
103+ self.tweetsQueue.append(
104+ QString.fromUtf8( self.sock.readAll()).replace( '\n' , ' '))
105+
106+ if not self.timer.isActive():
107+ self.tickerNext()
108+ pass
109+
110+ def tickerNext(self):
111+ if 0 < len(self.tweetsQueue):
112+ text = self.tweetsQueue.pop(0)
113+ self.displayString = text
114+ self.displayStringPosition = -self.width()
115+ self.displayStringBoundRect.setWidth(
116+ self.fontMetrics().width(
117+ self.displayString))
118+ self.timer.start(30, self)
119+
120+def paintEnactiveIndicator(p, rect):
121+ p.setPen( QPen( Qt.black, 1, Qt.SolidLine))
122+ p.setBrush(Qt.red)
123+ p.drawEllipse(rect)
124+ pass
125+def paintActiveIndicator(p, rect):
126+ p.setPen( QPen( Qt.black, 1, Qt.SolidLine))
127+ p.setBrush(Qt.green)
128+ p.drawEllipse(rect)
129+ pass
130+
131+def paintText(p, text, rect, x):
132+ p.setPen(Qt.white)
133+ p.setBrush(Qt.white)
134+ p.drawText(
135+ QRect(
136+ rect.x() - x,
137+ rect.y(),
138+ rect.width(),
139+ rect.height()
140+ ),
141+ Qt.AlignLeft,
142+ text
143+ )
144+ pass
145+
146+if __name__=="__main__":
147+ app = QApplication(sys.argv)
148+ client = IpcOutputClientGUI2()
149+ client.setAttribute( Qt.WA_TranslucentBackground)
150+ client.setWindowFlags( Qt.ToolTip
151+ | Qt.FramelessWindowHint
152+ | Qt.WindowStaysOnTopHint
153+ | Qt.WindowSystemMenuHint
154+ )
155+ #client.setWindowOpacity(0.8)
156+ client.resize(400,20)
157+ client.show()
158+ sys.exit(app.exec_())
--- trunk/ticker.py (revision 77)
+++ trunk/ticker.py (revision 78)
@@ -37,24 +37,24 @@
3737 IpcOutputClient.__init__(self, self)
3838 self.tweetsQueue = []
3939
40- scrollTimer = QTimer(self)
41- scrollTimer.setSingleShot(False)
42- scrollTimer.setInterval(3000)
43- scrollTimer.timeout.connect(self.tickerNext)
44- scrollTimer.start()
45-
4640 self.textLabel = QLabel(self)
47- self.textLabel.resize(800,20)
4841
4942 self.dragPosition = QPoint()
5043
44+ self.anim = QPropertyAnimation(self.textLabel, 'geometry')
45+ self.anim.finished.connect(self.tickerNext)
46+
5147 quitAction = QAction(self.tr("E&xit"), self)
5248 quitAction.setShortcut(self.tr("Ctrl+Q"))
5349 quitAction.triggered.connect(app.quit)
5450 self.addAction(quitAction)
55-
5651 self.setContextMenuPolicy(Qt.ActionsContextMenu)
5752
53+ pl = self.palette()
54+ pl.setColor(QPalette.Background, Qt.black)
55+ pl.setColor(QPalette.Foreground, Qt.white)
56+ self.setPalette(pl)
57+
5858 def mousePressEvent(self, event):
5959 if event.button() == Qt.LeftButton:
6060 self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()
@@ -66,9 +66,26 @@
6666
6767 def tickerNext(self):
6868 if 0 < len(self.tweetsQueue):
69- self.textLabel.setText(QString.fromUtf8(self.tweetsQueue.pop(0)))
69+ if not self.isVisible():
70+ self.show()
71+ text = self.tweetsQueue.pop(0)
72+ self.textLabel.setFixedWidth(self.textLabel.fontMetrics().width(text))
73+ self.textLabel.setText(text)
74+ self.setStartValue(
75+ self.width(), 0,
76+ self.textLabel.width(), self.textLabel.height()
77+ )
78+ self.setEndValue(
79+ self.width()+self.textLabel.widht(), 0,
80+ self.textLabel.width(), self.textLabel.height()
81+ )
82+ else:
83+ if self.isVisible():
84+ self.hide()
7085 def read(self):
71- self.tweetsQueue = self.tweetsQueue + str(self.sock.readAll()).split('\n', )
86+ self.tweetsQueue.append(QString.fromUtf8(self.sock.readAll()).replace('\n', ' '))
87+ if not self.anim.state == QAbstractAnimation.Running:
88+ self.tickerNext()
7289
7390 if __name__=="__main__":
7491 app = QApplication(sys.argv)
@@ -79,6 +96,7 @@
7996 | Qt.WindowStaysOnTopHint
8097 | Qt.WindowSystemMenuHint
8198 )
99+ client.setWindowOpacity(0.8)
82100 client.resize(400,20)
83101 client.show()
84102 sys.exit(app.exec_())
Show on old repository browser