2 # Copyright 2007 Aaron Seigo <aseigo@kde.org>
3 # Copyright 2008 Alex Merry <alex.merry@kdemail.net>
4 # Copyright 2008 Simon Edwards <simon@simonzone.com> (Translated to Python)
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU Library General Public License as
8 # published by the Free Software Foundation; either version 2, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details
16 # You should have received a copy of the GNU Library General Public
17 # License along with this program; if not, write to the
18 # Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 from PyQt4
.QtCore
import *
23 from PyKDE4
.kdecore
import *
24 from PyKDE4
import plasmascript
26 class PyTimeEngine(plasmascript
.DataEngine
):
27 def __init__(self
,parent
,args
=None):
28 plasmascript
.DataEngine
.__init
__(self
,parent
)
31 self
.setMinimumPollingInterval(333)
35 sources
.extend(KSystemTimeZones
.zones().keys())
38 def sourceRequestEvent(self
, name
):
39 return self
.updateSourceEvent(name
)
41 def updateSourceEvent(self
, tz
):
44 self
.setData(localName
, "Time", QVariant(QTime
.currentTime()))
45 self
.setData(localName
, "Date", QVariant(QDate
.currentDate()))
46 # this is relatively cheap - KSTZ::local() is cached
47 timezone
= KSystemTimeZones
.local().name()
49 newTz
= KSystemTimeZones
.zone(tz
)
50 if not newTz
.isValid():
52 dt
= KDateTime
.currentDateTime(KDateTime
.Spec(newTz
))
53 self
.setData(tz
, "Time", QVariant(dt
.time()))
54 self
.setData(tz
, "Date", QVariant(dt
.date()))
58 self
.setData(tz
, "Timezone", QVariant(trTimezone
));
59 tzParts
= str(trTimezone
).split("/")
61 self
.setData(tz
, "Timezone Continent", QVariant(tzParts
[0]))
62 self
.setData(tz
, "Timezone City", QVariant(tzParts
[1]))
66 def CreateDataEngine(parent
):
67 return PyTimeEngine(parent
)