File: dclock.py

package info (click to toggle)
python-qt3 3.13-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,096 kB
  • ctags: 2,039
  • sloc: python: 12,973; cpp: 7,752; sql: 195; makefile: 108; ansic: 26
file content (58 lines) | stat: -rwxr-xr-x 1,378 bytes parent folder | download | duplicates (15)
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
#!/usr/bin/env python

# A port to PyQt of the dclock example from Qt v2.x.


import sys, string
from qt import *


class DigitalClock(QLCDNumber):
  def __init__(self, parent=None, name=None):
    QLCDNumber.__init__(self, parent, name)
    self.showingColon = 0
    self.setFrameStyle(QFrame.Panel | QFrame.Raised)
    self.setLineWidth(2)
    self.showTime()
    self.normalTimer = self.startTimer(500)
    self.showDateTimer = -1

  def timerEvent(self, e):
    if e.timerId() == self.showDateTimer:
      self.stopDate()
    else:
      if self.showDateTimer == -1:
        self.showTime()
  
  def mousePressEvent(self, e):
    if e.button() == Qt.LeftButton:
      self.showDate()

  def showDate(self):
    if self.showDateTimer != -1:
      return
    d = QDate.currentDate()
    self.display('%2d %2d' % (d.month(), d.day()))
    self.showDateTimer = self.startTimer(2000)

  def stopDate(self):
    self.killTimer(self.showDateTimer)
    self.showDateTimer = -1
    self.showTime()

  def showTime(self):
    self.showingColon = not self.showingColon
    s = list(str(QTime.currentTime().toString())[:5]) #.left(5)
    if not self.showingColon:
      s[2] = ' '
    if s[0] == '0':
      s[0] = ' '
    s = string.join(s,'')
    self.display(s)

a = QApplication(sys.argv)
clock = DigitalClock()
clock.resize(170,80)
a.setMainWidget(clock)
clock.show()
a.exec_loop()