Hello,

as I'm starting to get my feet wet with Applets, I did so by "porting" the 
example "Hello, world" in the Techbase tutorial to Python (if anyone is 
interested I could put it somewhere, or create a TechBase page perahps?). 
Aside for icon names, which have changed ("document" in the tutorial is now 
"x-office-document"), the transition was smooth and the plasmoid works as 
expected, minus for one thing. 

There's a small, green square behind the top left corner of the plasmoid (see 
the attached screenshot), and I don't know if it's expected behavior or not. 
(this is with KDE 4.1.87, and a fresher kdebindings checkout) 

The listing, in Python, is also attached. If needed I can also provide the 
Plasma package, since it's very small (2K). 

Thanks!

<<attachment: helloworld.png>>

#
# Copyright 2009 Luca Beltrame ei...@heavensinferno.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as
# published by the Free Software Foundation; either version 2, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details
#
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyKDE4.kdecore import *
from PyKDE4.kdeui import *
from PyKDE4.plasma import Plasma
from PyKDE4 import plasmascript


class HelloWorldApplet(plasmascript.Applet):

    def __init__(self,parent,args=None):
        
        plasmascript.Applet.__init__(self,parent)
        self.icon = KIcon("x-office-document")

    def init(self):

        if self.icon.isNull():
            self.setHasFailedToLaunch(True,"No world to say hello")

        self.theme = Plasma.Svg(self)
        self.theme.setImagePath("widgets/background")
        self.setBackgroundHints(Plasma.Applet.DefaultBackground)
        self.resize(200,200)

    def paintInterface(self, painter, option, contentsRect):

        painter.setRenderHint(QPainter.SmoothPixmapTransform)
        painter.setRenderHint(QPainter.Antialiasing)

        self.theme.resize(contentsRect.width(), contentsRect.height())
        self.theme.paint(painter, contentsRect.left(), contentsRect.top())

        painter.drawPixmap(7, 0, self.icon.pixmap(contentsRect.width(),
            contentsRect.width()-14))
        painter.save()
        painter.setPen(Qt.white)
        painter.drawText(contentsRect, Qt.AlignBottom|Qt.AlignCenter,"Hello Plasmoid")
        painter.restore()

def CreateApplet(parent):
    return HelloWorldApplet(parent)

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to