asfjghdszdvcxvcxi dsai saljcxzv fds;oj vcxzo vcxzoi xz
parent
b92f36bbb2
commit
a9dc8ee50a
|
@ -10,7 +10,12 @@ import json
|
|||
|
||||
|
||||
INTERVAL = 15
|
||||
|
||||
|
||||
LABEL_TEMPLATE = """\
|
||||
{users}
|
||||
unknown:{unknown}\
|
||||
"""
|
||||
|
||||
class HelloPython(plasmascript.Applet):
|
||||
|
||||
def init(self):
|
||||
|
@ -26,23 +31,24 @@ class HelloPython(plasmascript.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.connect_to_engine()
|
||||
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)
|
||||
json_dict = json.loads(api_content)
|
||||
users = json_dict["users"]
|
||||
unknown = json_dict["unknown"]
|
||||
return (x["login"] for x in users), unknown
|
||||
|
||||
def connect_to_engine(self):
|
||||
self.timeEngine = self.dataEngine("time")
|
||||
|
@ -50,7 +56,9 @@ class HelloPython(plasmascript.Applet):
|
|||
self, INTERVAL*6000, Plasma.AlignToMinute)
|
||||
|
||||
def update_list(self):
|
||||
self.at_list.setText("\n".join(self.get_user_list()))
|
||||
users, unknown = self.get_user_list()
|
||||
users = "\n".join(users)
|
||||
self.at_list.setText(LABEL_TEMPLATE.format(users=users, unknown=unknown))
|
||||
|
||||
@pyqtSignature("dataUpdated(const QString &, const Plasma::DataEngine::Data &)")
|
||||
def dataUpdated(self, sourceName, data):
|
||||
|
|
Loading…
Reference in New Issue