|
демон батарейки
[ Скачать с сервера (2.9 Kb)
]
| 04.02.2009, 22:59 |
#!/usr/bin/python # simple.py
import sys import os import re import linecache from PyQt4 import QtGui,QtCore
class BatInfoToolTip(QtGui.QFrame): def __init__(self): QtGui.QFrame.__init__(self) self.setWindowFlags(QtCore.Qt.ToolTip) self.setFrameShape(QtGui.QFrame.StyledPanel) desktop = QtGui.qApp.desktop(); width=desktop.width() height=desktop.height(); print str(width) print str(height) self.setGeometry(width-200,height-115,175,80) self.text=QtCore.QString() self.pixmap=QtGui.QPixmap() self.ruText=QtCore.QString(QtGui.qApp.translate("GraphicWidget","\320\225\320\274\320\272\320\276\321\201\321\202\321\214 \320\261\320\260\321\202\320\260\321\200\320\265\320\270", "", QtGui.qApp.UnicodeUTF8)) def paintEvent(self,event): painter=QtGui.QPainter() painter.begin(self) pen=QtGui.QPen() pen.setStyle(QtCore.Qt.SolidLine) pen.setColor(QtCore.Qt.black) pen.setJoinStyle (QtCore.Qt.RoundJoin) painter.setPen(pen) painter.drawPixmap(QtCore.QRect(10,10,30,60),self.pixmap) #painter.setBrash painter.drawText(40,20,self.ruText) painter.drawText(40,40,self.text+QtCore.QString(" %")) painter.drawRect(0,0,174,69) painter.end() def setPixmap(self,pixmap): self.pixmap=pixmap def setText(self,text): self.text=text class Systray(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.toolTipFrame = BatInfoToolTip() self.toolTipFrame.setPixmap(QtGui.QPixmap("/var/batdemon/Battery18.png")) self.createTrayIcon(); self.connect(self.trayIcon, QtCore.SIGNAL('activated(QSystemTrayIcon::ActivationReason)'), self.iconActivated) self.trayIcon.show(); self.startTimer(3000); self.allCapacity=float(re.search('\d+',linecache.getline("/proc/acpi/battery/BAT0/info", 3)).group(0)); self.index=18 def createTrayIcon(self): self.trayIcon = QtGui.QSystemTrayIcon(self) self.trayIcon.setIcon(QtGui.QIcon("/var/batdemon/Battery18.png")) def timerEvent(self,event): self.toolTipFrame.hide() fileHandle = open ( '/proc/acpi/battery/BAT0/state' ) buf=fileHandle.readlines()[4]; fileHandle.close() #print "time" self.nowCapacity=float(re.search('\d+',buf).group(0)); Capacity = self.nowCapacity / self.allCapacity * 100 currentIndex=(int(Capacity/5)) self.trayIcon.setToolTip(str(Capacity)) self.toolTipFrame.setText(QtCore.QString(str(Capacity))) if self.index != currentIndex: self.trayIcon.setIcon(QtGui.QIcon("/var/batdemon/Battery%2d.png"%(currentIndex))) self.toolTipFrame.setPixmap(QtGui.QPixmap("/var/batdemon/Battery%2d.png"%(currentIndex))) self.index=currentIndex if Capacity<10: self.trayIcon.showMessage("warning", "low Capacity", self.trayIcon.Warning) if Capacity<5: self.trayIcon.showMessage("warning", "low Capacity", self.trayIcon.Critical) def iconActivated(self,reason): self.toolTipFrame.show() app = QtGui.QApplication(sys.argv) x = Systray() sys.exit(app.exec_())
|
Категория: PyQt | Добавил: ir4y
|
Просмотров: 700 | Загрузок: 118
| Комментарии: 2
| Рейтинг: 3.0/1 |
|
Всего комментариев: 2 | |
2
ir4y
(05.02.2009 12:46)
0
я как будет время оформлю как статью)
|
|
|
|
|
Статистика |
Онлайн всего: 1 Гостей: 1 Пользователей: 0 |
|