67 lines
2.0 KiB
Python
67 lines
2.0 KiB
Python
#!/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)
|