commit 8ef165507d80c1f5e7b2747b905f3f5287f8f7ea Author: dzikie drożdże Date: Sat Nov 23 18:24:58 2013 +0100 8===D~ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dd40550 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +all: zip install view +zip: + cd hs-applet; zip -r ../hs-applet.zip . + +install: + plasmapkg -u hs-applet.zip + +view: + plasma-windowed hs-applet diff --git a/hs-applet/contents/code/main.py b/hs-applet/contents/code/main.py new file mode 100644 index 0000000..db3d8f0 --- /dev/null +++ b/hs-applet/contents/code/main.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- +from PyQt4.QtCore import Qt, pyqtSignature +from PyQt4 import QtCore +from PyQt4.QtGui import QGraphicsLinearLayout, QIcon +from PyKDE4.plasma import Plasma +from PyKDE4 import plasmascript +from urllib2 import urlopen, URLError, HTTPError +import json + + +INTERVAL = 15 + +class HelloPython(plasmascript.Applet): + def __init__(self,parent,args=None): + super(HelloPython, self).__init__(parent) + + def init(self): + self.setHasConfigurationInterface(False) + self.setAspectRatioMode(Plasma.IgnoreAspectRatio) + + self.theme = Plasma.Svg(self) + self.theme.setImagePath("widgets/background") + self.setBackgroundHints(Plasma.Applet.DefaultBackground) + + self.layout = QGraphicsLinearLayout(Qt.Horizontal, self.applet) + + hs_button = Plasma.ToolButton(); + hs_button.setIcon(QIcon(self.package().path() + "contents/images/syrenka-small.png")) + QtCore.QObject.connect(hs_button, QtCore.SIGNAL('clicked()'), self.update_list) + + self.at_list = Plasma.Label(self.applet) + self.layout.addItem(self.at_list) + self.layout.addItem(hs_button) + self.applet.setLayout(self.layout) + self.update_list() + + self.resize(125, 125) + + def get_user_list(self): + try: + api_content = urlopen("https://at.hackerspace.pl/api").read() + except (URLError, HTTPError): + pass # TODO: + users = json.loads(api_content)["users"] + return (x["login"] for x in users) + + + def connectToEngine(self): + self.timeEngine = self.dataEngine("time") + self.timeEngine.connectSource(self.currentTimezone, + self, INTERVAL*6000, Plasma.AlignToMinute) + + + def update_list(self): + self.at_list.setText("\n".join(self.get_user_list())) + + + @pyqtSignature("dataUpdated(const QString &, const Plasma::DataEngine::Data &)") + def dataUpdated(self, sourceName, data): + + self.update_list() + + +def CreateApplet(parent): + return HelloPython(parent) diff --git a/hs-applet/contents/images/syrenka-small.png b/hs-applet/contents/images/syrenka-small.png new file mode 100644 index 0000000..94715dc Binary files /dev/null and b/hs-applet/contents/images/syrenka-small.png differ diff --git a/hs-applet/metadata.desktop b/hs-applet/metadata.desktop new file mode 100644 index 0000000..ad11123 --- /dev/null +++ b/hs-applet/metadata.desktop @@ -0,0 +1,19 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=hs-applet +Type=Service +ServiceTypes=Plasma/Applet +Icon=chronometer +X-Plasma-API=python +X-Plasma-MainScript=code/main.py +X-Plasma-DefaultSize=125,125 + +X-KDE-PluginInfo-Author=Papież Polak +X-KDE-PluginInfo-Email=daz@hackerspace.pl +X-KDE-PluginInfo-Name=hs-applet2 +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-Category=Examples +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true