1
# -*- coding: utf-8 -*-
3
# Copyright 2008 Simon Edwards <simon@simonzone.com>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU Library General Public License as
7
# published by the Free Software Foundation; either version 2, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details
15
# You should have received a copy of the GNU Library General Public
16
# License along with this program; if not, write to the
17
# Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
# Plasma applet API for Python
23
from PyQt4.QtCore import QObject
24
from PyQt4.QtGui import QGraphicsWidget
25
from PyKDE4.plasma import Plasma # Plasma C++ namespace
30
class Applet(QObject):
31
''' Subclass Applet in your module and return an instance of it in a global function named
32
applet(). Implement the following functions to breathe life into your applet:
33
* paint - Draw the applet given a QPainter and some options
34
It provides the same API as Plasma.Applet; it just has slightly less irritating event names. '''
35
def __init__(self, parent=None):
36
# this should be set when the applet is created
37
QObject.__init__(self, parent)
38
#sip.settracemask(0x3f)
40
self.applet_script = None
41
self._forward_to_applet = True
43
def __getattr__(self, key):
44
# provide transparent access to the real applet instance
45
if self._forward_to_applet:
47
return getattr(self.applet_script, key)
49
return getattr(self.applet, key)
51
raise AttributeError(key)
53
def _enableForwardToApplet(self):
54
self._forward_to_applet = True
55
def _disableForwardToApplet(self):
56
self._forward_to_applet = False
59
def setApplet(self,applet):
62
def setAppletScript(self,appletScript):
63
self.applet_script = appletScript
68
def configChanged(self):
71
def paintInterface(self, painter, options, rect):
74
def constraintsEvent(self, flags):
77
def showConfigurationInterface(self):
78
self.dlg = self.standardConfigurationDialog()
79
self.createConfigurationInterface(self.dlg)
80
self.addStandardConfigurationPages(self.dlg)
83
def createConfigurationInterface(self, dlg):
86
def contextualActions(self):
90
return QGraphicsWidget.shape(self.applet)
92
def initExtenderItem(self, item):
93
print "Missing implementation of initExtenderItem in the applet " + \
94
item.config().readEntry('SourceAppletPluginName', '').toString() + \
95
"!\nAny applet that uses extenders should implement initExtenderItem to " + \
96
"instantiate a widget."
98
def saveState(self, config):
101
###########################################################################
102
class DataEngine(QObject):
103
def __init__(self, parent=None):
104
QObject.__init__(self, parent)
105
self.dataengine = None
106
self.dataengine_script = None
108
def setDataEngine(self,dataEngine):
109
self.dataEngine = dataEngine
111
def setDataEngineScript(self,dataEngineScript):
112
self.data_engine_script = dataEngineScript
114
def __getattr__(self, key):
115
# provide transparent access to the real dataengine script instance
117
return getattr(self.data_engine_script, key)
119
return getattr(self.dataEngine, key)
127
def sourceRequestEvent(self,name):
130
def updateSourceEvent(self,source):
133
def serviceForSource(self,source):
134
return Plasma.DataEngineScript.serviceForSource(self.data_engine_script,source)
136
###########################################################################
137
class Wallpaper(QObject):
138
def __init__(self, parent=None):
139
QObject.__init__(self, parent)
140
self.wallpaper = None
141
self.wallpaper_script = None
143
def setWallpaper(self,wallpaper):
144
self.wallpaper = wallpaper
146
def setWallpaperScript(self,wallpaperScript):
147
self.wallpaper_script = wallpaperScript
149
def __getattr__(self, key):
150
# provide transparent access to the real wallpaper script instance
152
return getattr(self.wallpaper_script, key)
154
return getattr(self.wallpaper, key)
156
def init(self, config):
159
def paint(self,painter, exposedRect):
162
def save(self,config):
165
def createConfigurationInterface(self,parent):
168
def mouseMoveEvent(self,event):
171
def mousePressEvent(self,event):
174
def mouseReleaseEvent(self,event):
177
def wheelEvent(self,event):
180
def renderCompleted(self, image):
183
def urlDropped(self, url):
186
###########################################################################
187
class Runner(QObject):
188
def __init__(self, parent=None):
189
QObject.__init__(self, parent)
191
self.runner_script = None
193
def setRunner(self,runner):
196
def setRunnerScript(self,runnerScript):
197
self.runner_script = runnerScript
199
def __getattr__(self, key):
200
# provide transparent access to the real runner script instance
202
return getattr(self.runner_script, key)
204
return getattr(self.runner, key)
209
def match(self, search):
212
def run(self, search, action):
221
def createRunOptions(widget):
224
def reloadConfiguration():