Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 918e1b4642b299f61b06eaa7c01112db > files > 6

PyQt-examples-3.18.1-9.fc15.i686.rpm

#!/usr/bin/env python

import os, sys, string
from qt import *


if QT_VERSION < 0x030100:
    print "This example requires Qt v3.1.0 or later."
    sys.exit(1)


FALSE = 0
TRUE  = 1

hasmail_bmp_data = [
"48 48 3 1",
" 	c None",
".	c #000000",
"+	c #FFFFFF",
"................................................",
".............................++++++++++.........",
".............................++++++++++.........",
"........................++++.+++.+.+.++.........",
"......................++++.++++.+.+.+++.........",
".....................+++.....+++.+.+.++.........",
"....................++.......++.+.+.+++.........",
"...................++........++++++++++.........",
"..................++.........++++++++++.........",
".................++..........+++..+.............",
"................++...........+++..+.............",
"...............++............+++.++.............",
"..............+++++++........++++++.............",
".............++++++++++......++++++.............",
"............+++......+++.....++++.+.............",
"...........+++.........++....+++..+.............",
"...........++..........++...++++..+.............",
"..........++............++.+++++..+.............",
"..........++............++++++++..+.............",
".........++....++++++....+++.+++..+.............",
".........++......++......++..+++..+.............",
".........++..............++..+++..+.............",
".........++..............++..+++..+.............",
".........++..............++..++...+.............",
"+++++++..++.+.+..+..+.+..++.......+..+++++++++++",
".........++.+++.+.+.+.+..++.......+.............",
".........++.+.+.+++.+.+..++.......+.............",
".........++.+.+.+.+.+.+..++......++.............",
".........++.+.+.+.+.+.++.++.....++..............",
".........++..............++....++...............",
"..+.+.+..++..............++...++..+.+.+.+.+.+.+.",
".+.+.+.+.++..............++..++..+.+.+.+.+.+.+..",
"..+.+.+..++..............++.++..+.+.+.+.+.+.+.+.",
".+.+.+.+.++..............+++++.+.+.+.+.+.+.+.+..",
"..+.+.+..+++++++++++++++++++.++.+.+.+.+.+.+.+.+.",
".+.+.+.+..+++++++++++++++++..+.+.+.+.+.+.+.+.+..",
"..+.+.+.+..........+...+.....++.+.+.+.+.+.+.+.+.",
".+.+.+.+.+.+.+.+.+.+...+.....+.+.+.+.+.+.+.+.+..",
"..+.+.+.+.+.+.+.+.++...+.....++.+.+.+.+.+.+.+.+.",
".+.+.+.+.+.+.+.+.+.+...+.....+.+.+.+.+.+.+.+.+..",
"..+.+.+.+.+.+.+.+.++...+.....++.+.+.+.+.+.+.+.+.",
".+.+.+.+.+.+.+.+.+.+...+.....+.+.+.+.+.+.+.+.+..",
"..+.+.+.+.+.+.+.+.++...+....+.+.+.+.+.+.+.+.+.+.",
".+.+.+.+.+.+.+.+.+.+...+...+.+.+.+.+.+.+.+.+.+..",
"..+.+.+.+.+.+.+.+.+.+..+..+.+.+.+.+.+.+.+.+.+.+.",
".+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+..",
"..+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+...",
"................................................"
]

nomail_bmp_data = [
"48 48 3 1",
" 	c None",
".	c #FFFFFF",
"+	c #000000",
"................................................",
"................................................",
"................................................",
".........................++++...................",
".......................++++++++.................",
".....................++++....+++................",
"....................+++........++...............",
"...................++...........++..............",
"..................++............++..............",
".................++..............++.......+.....",
"................++...............++......++.....",
"...............++................++.....+++.....",
"..............+++++++...........+++....++++.....",
".............++++++++++........++++...+++++.....",
"............+++......+++......+++.+..++++++.....",
"...........+++.........++....+++..+.+++.+++.....",
"...........++..........++...+++...++++..+++.....",
"..........++............++.+++...++++...++......",
"..........++............+++++...++++............",
".........++....++++++....+++...++++.............",
".........++......++......++...+++.+.............",
".........++..............++...+++.+.............",
".........++..............++...++..+.............",
".........++..............++.......+.............",
"+++++++..++..............++.......+..+++++++++++",
".........++..............++.......+.............",
".........++..............++.......+.............",
".........++..............++......++.............",
".........++..............++.....++..............",
".........++..............++....++...............",
".........++..............++...++................",
".........++..............++..++.................",
".........++..............++.++..................",
".........++..............+++++..................",
".........+++++++++++++++++++.+..................",
"..........+++++++++++++++++..+..................",
"...................+...+.....+..................",
"...................+...+.....+..................",
"...................+...+.....+..................",
"...................+...+.....+..................",
"...................+...+.....+..................",
"...................+...+.....+..................",
"...................+...+.....+..................",
"...................+...+.....+..................",
"+++.++++++++++.+.+++...+..+++++++++++.++...+++++",
"+.+++..+++.+.+++++.++..+.++.+++..+..+.++.+.++++.",
".++...+.....++...+...+++++++....+....++++++...+.",
"++++++++++++++++++++++++++++++++++++++++++++++++"
]

class Biff(QWidget):
	def __init__(self):
		QWidget.__init__(self, None, "Biff - example application")
	
		mail = os.getenv("MAIL")
		fi = QFileInfo(mail);
		if not fi.exists():
			s = "/var/spool/mail/"+os.getenv("USER") 
			fi.setFile(s)

		if fi.exists():
			self.mailbox = fi.absFilePath()
			self.startTimer(1000)

		self.setMinimumSize(48, 48)
		self.setMaximumSize(48, 48)
		self.resize(48, 48)

		self.hasNewMail = QPixmap(hasmail_bmp_data)
		self.noNewMail = QPixmap(nomail_bmp_data)

		self.gotMail = FALSE
		self.lastModified = fi.lastModified()

	def timerEvent(self, te):
		fi = QFileInfo(self.mailbox)
		newState = ( fi.lastModified().toTime_t() != self.lastModified.toTime_t() and fi.lastModified().toTime_t() > fi.lastRead().toTime_t())
		if newState != self.gotMail:
			if self.gotMail == TRUE:
				self.lastModified = fi.lastModified()
			self.gotMail = newState
			self.repaint(FALSE)

	def paintEvent(self, pe):
		if self.gotMail:
			bitBlt(self, 0, 0, self.hasNewMail)
		else:
			bitBlt(self, 0, 0, self.noNewMail)

	def mousePressEvent(self, me):
		fi = QFileInfo(self.mailbox)
		lastModified = fi.lastModified()


a = QApplication(sys.argv)
b = Biff()
a.setMainWidget(b)
b.show()
a.exec_loop()