not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / scriptengines / python / plasmascript.py
blobf4da8780e915e10dd08a40fbb63987e4f46ca3cb
2 # Copyright 2008 Simon Edwards <simon@simonzone.com>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU Library General Public License as
6 # published by the Free Software Foundation; either version 2, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details
14 # You should have received a copy of the GNU Library General Public
15 # License along with this program; if not, write to the
16 # Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 # Plasma applet API for Python
22 from PyQt4.QtCore import QObject
23 from PyQt4.QtGui import QGraphicsWidget
24 from PyKDE4.plasma import Plasma # Plasma C++ namespace
26 #import sip
27 #import gc
29 class Applet(QObject):
30 ''' Subclass Applet in your module and return an instance of it in a global function named
31 applet(). Implement the following functions to breathe life into your applet:
32 * paint - Draw the applet given a QPainter and some options
33 It provides the same API as Plasma.Applet; it just has slightly less irritating event names. '''
34 def __init__(self, parent=None):
35 # this should be set when the applet is created
36 QObject.__init__(self, parent)
37 #sip.settracemask(0x3f)
38 self.applet = None
39 self._forward_to_applet = True
41 def __getattr__(self, key):
42 # provide transparent access to the real applet instance
43 if self._forward_to_applet:
44 return getattr(self.applet, key)
45 else:
46 raise AttributeError(key)
48 def _enableForwardToApplet(self):
49 self._forward_to_applet = True
50 def _disableForwardToApplet(self):
51 self._forward_to_applet = False
53 # Events
54 def setApplet(self,applet):
55 self.applet = applet
57 def init(self):
58 pass
60 def paintInterface(self, painter, options, rect):
61 pass
63 def constraintsEvent(self, flags):
64 pass
66 def showConfigurationInterface(self):
67 pass
69 def contextualActions(self):
70 return []
72 def setHasConfigurationInterface(self,hasInterface):
73 Plasma.AppletProtectedThunk.static_public_setHasConfigurationInterface(self.applet,hasInterface)
75 def setConfigurationRequired(self, needsConfiguring, reason):
76 Plasma.AppletProtectedThunk.static_public_setConfigurationRequired(self.applet, needsConfiguring, reason)
78 def shape(self):
79 return QGraphicsWidget.shape(self.applet)
81 ###########################################################################
82 class DataEngine(QObject):
83 def __init__(self, parent=None):
84 QObject.__init__(self, parent)
85 self.dataengine = None
87 def setDataEngineScript(self,dataEngineScript):
88 self.data_engine_script = dataEngineScript
90 def __getattr__(self, key):
91 # provide transparent access to the real dataengine instance
92 #if self._forward_to_applet:
93 return getattr(self.data_engine_script, key)
94 #else:
95 # raise AttributeError(key)
97 def init(self):
98 pass
100 def sources(self):
101 return []
103 def sourceRequestEvent(self,name):
104 return False
106 def updateSourceEvent(self,source):
107 return False
109 def serviceForSource(self,source):
110 return Plasma.DataEngineScript.serviceForSource(self.data_engine_script,source)