~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/scriptengines/python/plasmascript.py

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# Copyright 2008 Simon Edwards <simon@simonzone.com>
 
4
#
 
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.
 
9
#
 
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
 
14
#
 
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.
 
19
#
 
20
 
 
21
# Plasma applet API for Python
 
22
 
 
23
from PyQt4.QtCore import QObject
 
24
from PyQt4.QtGui import QGraphicsWidget
 
25
from PyKDE4.plasma import Plasma # Plasma C++ namespace
 
26
 
 
27
#import sip
 
28
#import gc
 
29
 
 
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)
 
39
        self.applet = None
 
40
        self.applet_script = None
 
41
        self._forward_to_applet = True
 
42
 
 
43
    def __getattr__(self, key):
 
44
        # provide transparent access to the real applet instance
 
45
        if self._forward_to_applet:
 
46
            try:
 
47
                return getattr(self.applet_script, key)
 
48
            except:
 
49
                return getattr(self.applet, key)
 
50
        else:
 
51
            raise AttributeError(key)
 
52
 
 
53
    def _enableForwardToApplet(self):
 
54
        self._forward_to_applet = True
 
55
    def _disableForwardToApplet(self):
 
56
        self._forward_to_applet = False
 
57
 
 
58
    # Events
 
59
    def setApplet(self,applet):
 
60
        self.applet = applet
 
61
 
 
62
    def setAppletScript(self,appletScript):
 
63
        self.applet_script = appletScript
 
64
 
 
65
    def init(self):
 
66
        pass
 
67
 
 
68
    def configChanged(self):
 
69
        pass
 
70
 
 
71
    def paintInterface(self, painter, options, rect):
 
72
        pass
 
73
 
 
74
    def constraintsEvent(self, flags):
 
75
        pass
 
76
 
 
77
    def showConfigurationInterface(self):
 
78
        self.dlg = self.standardConfigurationDialog()
 
79
        self.createConfigurationInterface(self.dlg)
 
80
        self.addStandardConfigurationPages(self.dlg)
 
81
        self.dlg.show()
 
82
 
 
83
    def createConfigurationInterface(self, dlg):
 
84
        pass
 
85
 
 
86
    def contextualActions(self):
 
87
        return []
 
88
 
 
89
    def shape(self):
 
90
        return QGraphicsWidget.shape(self.applet)
 
91
 
 
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."
 
97
 
 
98
    def saveState(self, config):
 
99
        pass
 
100
 
 
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
 
107
 
 
108
    def setDataEngine(self,dataEngine):
 
109
        self.dataEngine = dataEngine
 
110
 
 
111
    def setDataEngineScript(self,dataEngineScript):
 
112
        self.data_engine_script = dataEngineScript
 
113
 
 
114
    def __getattr__(self, key):
 
115
        # provide transparent access to the real dataengine script instance
 
116
        try:
 
117
            return getattr(self.data_engine_script, key)
 
118
        except:
 
119
            return getattr(self.dataEngine, key)
 
120
 
 
121
    def init(self):
 
122
        pass
 
123
 
 
124
    def sources(self):
 
125
        return []
 
126
 
 
127
    def sourceRequestEvent(self,name):
 
128
        return False
 
129
 
 
130
    def updateSourceEvent(self,source):
 
131
        return False
 
132
 
 
133
    def serviceForSource(self,source):
 
134
        return Plasma.DataEngineScript.serviceForSource(self.data_engine_script,source)
 
135
 
 
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
 
142
 
 
143
    def setWallpaper(self,wallpaper):
 
144
        self.wallpaper = wallpaper
 
145
 
 
146
    def setWallpaperScript(self,wallpaperScript):
 
147
        self.wallpaper_script = wallpaperScript
 
148
 
 
149
    def __getattr__(self, key):
 
150
        # provide transparent access to the real wallpaper script instance
 
151
        try:
 
152
            return getattr(self.wallpaper_script, key)
 
153
        except:
 
154
            return getattr(self.wallpaper, key)
 
155
 
 
156
    def init(self, config):
 
157
        pass
 
158
 
 
159
    def paint(self,painter, exposedRect):
 
160
        pass
 
161
 
 
162
    def save(self,config):
 
163
        pass
 
164
 
 
165
    def createConfigurationInterface(self,parent):
 
166
        return None
 
167
 
 
168
    def mouseMoveEvent(self,event):
 
169
        pass
 
170
 
 
171
    def mousePressEvent(self,event):
 
172
        pass
 
173
 
 
174
    def mouseReleaseEvent(self,event):
 
175
        pass
 
176
 
 
177
    def wheelEvent(self,event):
 
178
        pass
 
179
 
 
180
    def renderCompleted(self, image):
 
181
        pass
 
182
 
 
183
    def urlDropped(self, url):
 
184
        pass
 
185
 
 
186
###########################################################################
 
187
class Runner(QObject):
 
188
    def __init__(self, parent=None):
 
189
        QObject.__init__(self, parent)
 
190
        self.runner = None
 
191
        self.runner_script = None
 
192
 
 
193
    def setRunner(self,runner):
 
194
        self.runner = runner
 
195
 
 
196
    def setRunnerScript(self,runnerScript):
 
197
        self.runner_script = runnerScript
 
198
 
 
199
    def __getattr__(self, key):
 
200
        # provide transparent access to the real runner script instance
 
201
        try:
 
202
            return getattr(self.runner_script, key)
 
203
        except:
 
204
            return getattr(self.runner, key)
 
205
 
 
206
    def init(self):
 
207
        pass
 
208
 
 
209
    def match(self, search):
 
210
        pass
 
211
 
 
212
    def run(self, search, action):
 
213
        pass
 
214
 
 
215
    def prepare():
 
216
        pass
 
217
 
 
218
    def teardown():
 
219
        pass
 
220
 
 
221
    def createRunOptions(widget):
 
222
        pass
 
223
 
 
224
    def reloadConfiguration():
 
225
        pass