1
# -*- coding: utf-8 -*-
3
# Copyright 2008 Simon Edwards <simon@simonzone.com>
4
# Copyright 2009 Petri Damstén <damu@iki.fi>
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.
21
from PyQt4.QtCore import *
22
from PyQt4.QtGui import *
23
from PyKDE4.plasma import Plasma
24
import plasma_importer
27
class PythonWallpaperScript(Plasma.WallpaperScript):
30
def __init__(self, parent):
31
Plasma.WallpaperScript.__init__(self,parent)
32
if PythonWallpaperScript.importer is None:
33
PythonWallpaperScript.importer = plasma_importer.PlasmaImporter()
34
self.initialized = False
37
self.moduleName = str(self.wallpaper().pluginName())
38
self.pluginName = 'wallpaper_' + self.moduleName.replace('-','_')
40
PythonWallpaperScript.importer.register_top_level(self.pluginName, str(self.wallpaper().package().path()))
42
# import the code at the file name reported by mainScript()
43
relpath = os.path.relpath(str(self.mainScript()),str(self.wallpaper().package().path()))
44
if relpath.startswith("contents/code/"):
45
relpath = relpath[14:]
46
if relpath.endswith(".py"):
47
relpath = relpath[:-3]
48
relpath = relpath.replace("/",".")
49
self.module = __import__(self.pluginName+'.'+relpath)
50
self.pywallpaper = self.module.main.CreateWallpaper(None)
51
self.pywallpaper.setWallpaper(self.wallpaper())
52
self.pywallpaper.setWallpaperScript(self)
53
self.initialized = True
57
PythonWallpaperScript.importer.unregister_top_level(self.pluginName)
58
self.pywallpaper = None
60
def paint(self, painter, exposedRect):
61
self.pywallpaper.paint(painter, exposedRect)
63
def initWallpaper(self, config):
64
self.pywallpaper.init(config)
66
def save(self, config):
67
self.pywallpaper.save(config)
69
def createConfigurationInterface(self, parent):
70
self.connect(self, SIGNAL('settingsChanged(bool)'), parent, SLOT('settingsChanged(bool)'))
71
return self.pywallpaper.createConfigurationInterface(parent)
73
def settingsChanged(self, changed):
74
self.emit(SIGNAL('settingsChanged(bool)'), changed)
76
def mouseMoveEvent(self, event):
77
self.pywallpaper.mouseMoveEvent(event)
79
def mousePressEvent(self, event):
80
self.pywallpaper.mousePressEvent(event)
82
def mouseReleaseEvent(self, event):
83
self.pywallpaper.mouseReleaseEvent(event)
85
def wheelEvent(self, event):
86
self.pywallpaper.wheelEvent(event)
88
@pyqtSignature("renderCompleted(const QImage&)")
89
def renderCompleted(self, image):
90
self.pywallpaper.renderCompleted(image)
92
@pyqtSignature("urlDropped(const KUrl&)")
93
def urlDropped(self, url):
94
self.pywallpaper.urlDropped(url)
96
def CreatePlugin(widget_parent, parent, component_data):
97
return PythonWallpaperScript(parent)