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
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)
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
)
46 raise AttributeError(key
)
48 def _enableForwardToApplet(self
):
49 self
._forward
_to
_applet
= True
50 def _disableForwardToApplet(self
):
51 self
._forward
_to
_applet
= False
54 def setApplet(self
,applet
):
60 def paintInterface(self
, painter
, options
, rect
):
63 def constraintsEvent(self
, flags
):
66 def showConfigurationInterface(self
):
69 def contextualActions(self
):
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
)
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
)
95 # raise AttributeError(key)
103 def sourceRequestEvent(self
,name
):
106 def updateSourceEvent(self
,source
):
109 def serviceForSource(self
,source
):
110 return Plasma
.DataEngineScript
.serviceForSource(self
.data_engine_script
,source
)