add more spacing
[personal-kdebase.git] / workspace / plasma / scriptengines / python / examples / dataengines / pytime / contents / code / main.py
blobede71fe01c7329b6292b1ea76c64c74365e9b749
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)
30 def init(self):
31 self.setMinimumPollingInterval(333)
33 def sources(self):
34 sources = ["Local"]
35 sources.extend(KSystemTimeZones.zones().keys())
36 return sources
38 def sourceRequestEvent(self, name):
39 return self.updateSourceEvent(name)
41 def updateSourceEvent(self, tz):
42 localName = "Local"
43 if tz == localName:
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()
48 else:
49 newTz = KSystemTimeZones.zone(tz)
50 if not newTz.isValid():
51 return False
52 dt = KDateTime.currentDateTime(KDateTime.Spec(newTz))
53 self.setData(tz, "Time", QVariant(dt.time()))
54 self.setData(tz, "Date", QVariant(dt.date()))
55 timezone = tz
57 trTimezone = timezone
58 self.setData(tz, "Timezone", QVariant(trTimezone));
59 tzParts = str(trTimezone).split("/")
60 if len(tzParts)>=2:
61 self.setData(tz, "Timezone Continent", QVariant(tzParts[0]))
62 self.setData(tz, "Timezone City", QVariant(tzParts[1]))
64 return True
66 def CreateDataEngine(parent):
67 return PyTimeEngine(parent)