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

« back to all changes in this revision

Viewing changes to plasma/generic/scriptengines/python/pywallpaper.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
# Copyright 2009 Petri Damstén <damu@iki.fi>
 
5
#
 
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.
 
10
#
 
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
 
15
#
 
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.
 
20
#
 
21
from PyQt4.QtCore import *
 
22
from PyQt4.QtGui import *
 
23
from PyKDE4.plasma import Plasma
 
24
import plasma_importer
 
25
import os.path
 
26
 
 
27
class PythonWallpaperScript(Plasma.WallpaperScript):
 
28
    importer = None
 
29
 
 
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
 
35
 
 
36
    def init(self):
 
37
        self.moduleName = str(self.wallpaper().pluginName())
 
38
        self.pluginName = 'wallpaper_' + self.moduleName.replace('-','_')
 
39
 
 
40
        PythonWallpaperScript.importer.register_top_level(self.pluginName, str(self.wallpaper().package().path()))
 
41
 
 
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
 
54
        return True
 
55
 
 
56
    def __dtor__(self):
 
57
        PythonWallpaperScript.importer.unregister_top_level(self.pluginName)
 
58
        self.pywallpaper = None
 
59
 
 
60
    def paint(self, painter, exposedRect):
 
61
        self.pywallpaper.paint(painter, exposedRect)
 
62
 
 
63
    def initWallpaper(self, config):
 
64
        self.pywallpaper.init(config)
 
65
 
 
66
    def save(self, config):
 
67
        self.pywallpaper.save(config)
 
68
 
 
69
    def createConfigurationInterface(self, parent):
 
70
        self.connect(self, SIGNAL('settingsChanged(bool)'), parent, SLOT('settingsChanged(bool)'))
 
71
        return self.pywallpaper.createConfigurationInterface(parent)
 
72
 
 
73
    def settingsChanged(self, changed):
 
74
        self.emit(SIGNAL('settingsChanged(bool)'), changed)
 
75
 
 
76
    def mouseMoveEvent(self, event):
 
77
        self.pywallpaper.mouseMoveEvent(event)
 
78
 
 
79
    def mousePressEvent(self, event):
 
80
        self.pywallpaper.mousePressEvent(event)
 
81
 
 
82
    def mouseReleaseEvent(self, event):
 
83
        self.pywallpaper.mouseReleaseEvent(event)
 
84
 
 
85
    def wheelEvent(self, event):
 
86
        self.pywallpaper.wheelEvent(event)
 
87
 
 
88
    @pyqtSignature("renderCompleted(const QImage&)")
 
89
    def renderCompleted(self, image):
 
90
        self.pywallpaper.renderCompleted(image)
 
91
 
 
92
    @pyqtSignature("urlDropped(const KUrl&)")
 
93
    def urlDropped(self, url):
 
94
        self.pywallpaper.urlDropped(url)
 
95
 
 
96
def CreatePlugin(widget_parent, parent, component_data):
 
97
    return PythonWallpaperScript(parent)