2 from PyQt4
.QtCore
import *
3 from PyQt4
.QtGui
import *
4 from PyKDE4
.kdecore
import *
5 from PyKDE4
.kdeui
import *
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
)
15 self
.currentTimezone
= "Local"
17 self
.calendarUi
= Ui_calendar()
18 self
.timezonesUi
= Ui_timezonesConfig()
19 self
.clicked
= QPoint()
22 def updateToolTipContent(self
):
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
):
44 def clockConfigAccepted(self
):
47 def configAccepted(self
):
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
)
67 self
.emit(SIGNAL("configNeedsSaving()"))
69 def changeEngineTimezone(self
, oldTimezone
, newTimezone
):
72 def mousePressEvent(self
,event
):
73 if event
.buttons() == Qt
.LeftButton
:
74 self
.clicked
= self
.scenePos
.toPoint()
75 event
.setAccepted(True)
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():
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()))
99 def isLocalTimezone(self
):
100 return self
.currentTimezone
== self
.localTimezone()
102 def localTimezone(self
):