not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / scriptengines / python / examples / applets / pyclock / contents / code / clockapplet.py
blob5278744cb2e27c5b03be1432a0427e624bd73231
2 from PyQt4.QtCore import *
3 from PyQt4.QtGui import *
4 from PyKDE4.kdecore import *
5 from PyKDE4.kdeui import *
6 import plasma
7 from timezonesConfig_ui import *
8 from calendar_ui import *
10 class ClockApplet(plasma.Applet):
11 def __init__(self,parent,args=None):
12 plasma.Applet.__init__(self,parent)
14 self.calendar = None
15 self.currentTimezone = "Local"
17 self.calendarUi = Ui_calendar()
18 self.timezonesUi = Ui_timezonesConfig()
19 self.clicked = QPoint()
20 self.timeZones = []
22 def updateToolTipContent(self):
23 pass
25 def createConfigurationInterface(self,parent):
26 self.createClockConfigurationInterface(parent)
28 #widget = QWidget(parent)
29 #self.timezonesUi.setupUi(widget)
31 #parent.addPage(widget, i18n("Time Zones"), self.icon())
33 #self.timezonesUi.localTimeZone.checked = self.isLocalTimezone()
34 #self.timezonesUi.timeZones.setSelected(self.currentTimezone, True)
35 #self.timezonesUi.timeZones.setEnabled(not self.isLocalTimezone())
37 parent.setButtons(KDialog.ButtonCodes(KDialog.ButtonCode(KDialog.Ok | KDialog.Cancel | KDialog.Apply)))
38 self.connect(parent, SIGNAL("applyClicked"), self.configAccepted)
39 self.connect(parent, SIGNAL("okClicked"), self.configAccepted)
41 def createClockConfigurationInterface(self,parent):
42 pass
44 def clockConfigAccepted(self):
45 pass
47 def configAccepted(self):
48 cg = self.config()
50 self.timeZones = self.timezonesUi.timeZones.selection()
51 cg.writeEntry("timeZones", self.timeZones)
53 newTimezone = self.localTimezone()
55 if not self.timezonesUi.localTimeZone.isChecked() and not self.timeZones.isEmpty():
56 newTimezone = self.timeZones[0]
58 self.changeEngineTimezone(self.currentTimezone, newTimezone)
60 self.currentTimezone = newTimezone
61 cg.writeEntry("currentTimezone", newTimezone)
63 self.clockConfigAccepted()
65 self.constraintsEvent(Plasma.SizeConstraint)
66 self.update()
67 self.emit(SIGNAL("configNeedsSaving()"))
69 def changeEngineTimezone(self, oldTimezone, newTimezone):
70 pass
72 def mousePressEvent(self,event):
73 if event.buttons() == Qt.LeftButton:
74 self.clicked = self.scenePos.toPoint()
75 event.setAccepted(True)
76 return
77 plasma.Applet.mousePressEvent(self,event)
79 def mouseReleaseEvent(self,event):
80 if (self.clicked - self.scenePos.toPoint()).manhattanLength() < \
81 KGlobalSettings.dndEventDelay():
82 self.showCalendar(event)
84 def showCalendar(self,event):
85 if self.calendar is None:
86 self.calendar = Plasma.Dialog()
87 self.calendarUi.setupUi(self.calendar)
88 self.calendar.setWindowFlags(Qt.Popup)
89 self.calendar.adjustSize()
91 if self.calendar.isVisible():
92 self.calendar.hide()
93 else:
94 data = self.dataEngine("time").query(self.currentTimezone)
95 self.calendarUi.kdatepicker.date = data[QString("Date")].toDate()
96 self.calendar.move(self.popupPosition(self.calendar.sizeHint()))
97 self.calendar.show()
99 def isLocalTimezone(self):
100 return self.currentTimezone == self.localTimezone()
102 def localTimezone(self):
103 return "Local"