|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
#-*- coding: utf-8 -*-
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
# Copyright 2012-2016 Mir Calculate. http://www.calculate-linux.org
|
|
|
|
|
#
|
|
|
|
@ -17,6 +17,7 @@
|
|
|
|
|
from PySide import QtGui, QtCore
|
|
|
|
|
import time, urllib2
|
|
|
|
|
from calculate.core.client.function import create_obj
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
from calculate.update.update_info import UpdateInfo
|
|
|
|
|
except ImportError:
|
|
|
|
@ -28,25 +29,28 @@ from calculate.consolegui.application.pid_information import client_pid_info, \
|
|
|
|
|
client_list_pid
|
|
|
|
|
from more import show_msg, get_sid, _print
|
|
|
|
|
|
|
|
|
|
#class MySignal(QtCore.QObject):
|
|
|
|
|
# class MySignal(QtCore.QObject):
|
|
|
|
|
# sig = QtCore.Signal(str, str)
|
|
|
|
|
|
|
|
|
|
class TrayUpdateSystem(QtCore.QThread):
|
|
|
|
|
mes_sig = QtCore.Signal(str, str)
|
|
|
|
|
started_sig = QtCore.Signal(str)
|
|
|
|
|
def __init__(self, target, parent = None):
|
|
|
|
|
|
|
|
|
|
def __init__(self, target, parent=None):
|
|
|
|
|
QtCore.QThread.__init__(self, parent)
|
|
|
|
|
self._parent = target
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
self.close_flag = False
|
|
|
|
|
if not hasattr(self._parent, 'localhost_ClientObj'):
|
|
|
|
|
self.mes_sig.emit(_('Connection Error'), \
|
|
|
|
|
_('You are not connected to the localhost server'))
|
|
|
|
|
_(
|
|
|
|
|
'You are not connected to the localhost server'))
|
|
|
|
|
return 1
|
|
|
|
|
if not self._parent.localhost_ClientObj.client:
|
|
|
|
|
self.mes_sig.emit(_('Connection Error'), \
|
|
|
|
|
_('You are not connected to the localhost server'))
|
|
|
|
|
_(
|
|
|
|
|
'You are not connected to the localhost server'))
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
sid = get_sid(self._parent.localhost_ClientObj.client)
|
|
|
|
@ -59,8 +63,8 @@ class TrayUpdateSystem(QtCore.QThread):
|
|
|
|
|
sid, param_object)
|
|
|
|
|
except Exception, e:
|
|
|
|
|
msg = e.message
|
|
|
|
|
if type (e.message) == tuple:
|
|
|
|
|
msg = ' '.join( map(lambda x:str(x), list(e.message)))
|
|
|
|
|
if type(e.message) == tuple:
|
|
|
|
|
msg = ' '.join(map(lambda x: str(x), list(e.message)))
|
|
|
|
|
|
|
|
|
|
self.mes_sig.emit(msg, 'cl-client-console Exception')
|
|
|
|
|
return 1
|
|
|
|
@ -72,60 +76,60 @@ class TrayUpdateSystem(QtCore.QThread):
|
|
|
|
|
res.message, res.expert))
|
|
|
|
|
if res.type == 'error':
|
|
|
|
|
error = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if error:
|
|
|
|
|
return 1
|
|
|
|
|
if meth_result[0].type == "pid":
|
|
|
|
|
# create process dict
|
|
|
|
|
self._parent.localhost_ClientObj.process_dict \
|
|
|
|
|
[meth_result[0].message] = {}
|
|
|
|
|
[meth_result[0].message] = {}
|
|
|
|
|
self._parent.localhost_ClientObj.process_dict \
|
|
|
|
|
[meth_result[0].message]['result'] = meth_result[0]
|
|
|
|
|
[meth_result[0].message]['result'] = meth_result[0]
|
|
|
|
|
self._parent.localhost_ClientObj.process_dict \
|
|
|
|
|
[meth_result[0].message]['name'] = method_name
|
|
|
|
|
[meth_result[0].message]['name'] = method_name
|
|
|
|
|
self._parent.localhost_ClientObj.process_dict \
|
|
|
|
|
[meth_result[0].message]['layout'] = QtGui.QVBoxLayout()
|
|
|
|
|
[meth_result[0].message]['layout'] = QtGui.QVBoxLayout()
|
|
|
|
|
self._parent.localhost_ClientObj.process_dict \
|
|
|
|
|
[meth_result[0].message]['layout'].setAlignment \
|
|
|
|
|
(QtCore.Qt.AlignTop)
|
|
|
|
|
[meth_result[0].message]['layout'].setAlignment \
|
|
|
|
|
(QtCore.Qt.AlignTop)
|
|
|
|
|
else:
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
#self.mes_sig.emit('', _('Update running'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# self.mes_sig.emit('', _('Update running'))
|
|
|
|
|
|
|
|
|
|
mess = meth_result[0]
|
|
|
|
|
pid = mess.message
|
|
|
|
|
self._parent.sys_update_pid = int(pid)
|
|
|
|
|
self.started_sig.emit(pid)
|
|
|
|
|
|
|
|
|
|
#self.get_update_status(sid, pid)
|
|
|
|
|
|
|
|
|
|
# self.get_update_status(sid, pid)
|
|
|
|
|
|
|
|
|
|
def get_update_status(self, sid, pid):
|
|
|
|
|
end_frame = True
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
current_frame = self._parent.localhost_ClientObj.client.\
|
|
|
|
|
service.get_entire_frame(sid, pid)
|
|
|
|
|
current_frame = self._parent.localhost_ClientObj.client. \
|
|
|
|
|
service.get_entire_frame(sid, pid)
|
|
|
|
|
except urllib2.URLError:
|
|
|
|
|
_print ('get_entire_frame in TrayIcon Exception')
|
|
|
|
|
current_frame = None
|
|
|
|
|
_print('get_entire_frame in TrayIcon Exception')
|
|
|
|
|
current_frame = None
|
|
|
|
|
while end_frame:
|
|
|
|
|
while current_frame in [None, [], ""]:
|
|
|
|
|
for i in range(5):
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
if self.close_flag:
|
|
|
|
|
#self.mes_sig.emit('', _('Update aborted'))
|
|
|
|
|
# self.mes_sig.emit('', _('Update aborted'))
|
|
|
|
|
return 0
|
|
|
|
|
try:
|
|
|
|
|
client = self._parent.localhost_ClientObj.client
|
|
|
|
|
current_frame = client.service.get_frame(sid, pid,"gui")
|
|
|
|
|
current_frame = client.service.get_frame(sid, pid, "gui")
|
|
|
|
|
except urllib2.URLError:
|
|
|
|
|
_print ('client.service.get_entire_frame in'
|
|
|
|
|
' TrayIcon Exception')
|
|
|
|
|
_print('client.service.get_entire_frame in'
|
|
|
|
|
' TrayIcon Exception')
|
|
|
|
|
current_frame = None
|
|
|
|
|
for item in range(len(current_frame[0])):
|
|
|
|
|
if current_frame[0][item].type == 'error':
|
|
|
|
|
#self.mes_sig.emit(_("Failed to update!"), \
|
|
|
|
|
# self.mes_sig.emit(_("Failed to update!"), \
|
|
|
|
|
# current_frame[0][item].message)
|
|
|
|
|
end_frame = False
|
|
|
|
|
return 1
|
|
|
|
@ -134,7 +138,7 @@ class TrayUpdateSystem(QtCore.QThread):
|
|
|
|
|
message = current_frame[0][item].message
|
|
|
|
|
else:
|
|
|
|
|
message = ''
|
|
|
|
|
#self.mes_sig.emit(_('Update successfully completed'), \
|
|
|
|
|
# self.mes_sig.emit(_('Update successfully completed'), \
|
|
|
|
|
# message)
|
|
|
|
|
end_frame = False
|
|
|
|
|
current_frame = None
|
|
|
|
@ -143,7 +147,7 @@ class TrayUpdateSystem(QtCore.QThread):
|
|
|
|
|
self.close_flag = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TrayIcon (QtGui.QSystemTrayIcon):
|
|
|
|
|
class TrayIcon(QtGui.QSystemTrayIcon):
|
|
|
|
|
default_theme_name = 'Tango'
|
|
|
|
|
|
|
|
|
|
def __init__(self, parent):
|
|
|
|
@ -166,7 +170,6 @@ class TrayIcon (QtGui.QSystemTrayIcon):
|
|
|
|
|
self.update_thread.mes_sig.connect(self.showMessage)
|
|
|
|
|
self.update_thread.started_sig.connect(self.showUpdate)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def select_icon(self, icons):
|
|
|
|
|
old_theme_name = QtGui.QIcon.themeName()
|
|
|
|
|
try:
|
|
|
|
@ -186,31 +189,31 @@ class TrayIcon (QtGui.QSystemTrayIcon):
|
|
|
|
|
_("Update System")
|
|
|
|
|
_("Exit Program")
|
|
|
|
|
self.actions = {
|
|
|
|
|
'help': {
|
|
|
|
|
'icons': ['help-about', 'help-browser'],
|
|
|
|
|
'label': "About",
|
|
|
|
|
'trigger': self.help},
|
|
|
|
|
'bug_report': {
|
|
|
|
|
'icons': ['tools-report-bug', 'system-help',
|
|
|
|
|
'help-browser'],
|
|
|
|
|
'label': "Report a Bug",
|
|
|
|
|
'trigger': self.bug_report},
|
|
|
|
|
'tools': {
|
|
|
|
|
'icons': ['preferences-other', 'preferences-system'],
|
|
|
|
|
'label': "Program settings",
|
|
|
|
|
'trigger': self.tools},
|
|
|
|
|
'update_system': {
|
|
|
|
|
'icons': ['system-software-update'],
|
|
|
|
|
'label': "Update System",
|
|
|
|
|
'trigger': self.start_update_system},
|
|
|
|
|
'exit': {
|
|
|
|
|
'icons': ["application-exit", "system-log-out"],
|
|
|
|
|
'label': "Exit Program",
|
|
|
|
|
'trigger': self.exit},
|
|
|
|
|
'show_hide': {
|
|
|
|
|
'icons': ['preferences-system-windows'],
|
|
|
|
|
'label': "Show/Hide Window",
|
|
|
|
|
'trigger': self.windowVisible}
|
|
|
|
|
'help': {
|
|
|
|
|
'icons': ['help-about', 'help-browser'],
|
|
|
|
|
'label': "About",
|
|
|
|
|
'trigger': self.help},
|
|
|
|
|
'bug_report': {
|
|
|
|
|
'icons': ['tools-report-bug', 'system-help',
|
|
|
|
|
'help-browser'],
|
|
|
|
|
'label': "Report a Bug",
|
|
|
|
|
'trigger': self.bug_report},
|
|
|
|
|
'tools': {
|
|
|
|
|
'icons': ['preferences-other', 'preferences-system'],
|
|
|
|
|
'label': "Program settings",
|
|
|
|
|
'trigger': self.tools},
|
|
|
|
|
'update_system': {
|
|
|
|
|
'icons': ['system-software-update'],
|
|
|
|
|
'label': "Update System",
|
|
|
|
|
'trigger': self.start_update_system},
|
|
|
|
|
'exit': {
|
|
|
|
|
'icons': ["application-exit", "system-log-out"],
|
|
|
|
|
'label': "Exit Program",
|
|
|
|
|
'trigger': self.exit},
|
|
|
|
|
'show_hide': {
|
|
|
|
|
'icons': ['preferences-system-windows'],
|
|
|
|
|
'label': "Show/Hide Window",
|
|
|
|
|
'trigger': self.windowVisible}
|
|
|
|
|
}
|
|
|
|
|
for action_name, action_data in self.actions.items():
|
|
|
|
|
setattr(self, '%s_action' % action_name,
|
|
|
|
@ -247,10 +250,12 @@ class TrayIcon (QtGui.QSystemTrayIcon):
|
|
|
|
|
|
|
|
|
|
if online:
|
|
|
|
|
self.setIcon(QtGui.QIcon \
|
|
|
|
|
('/usr/share/pixmaps/calculate-console-online.svg'))
|
|
|
|
|
(
|
|
|
|
|
'/usr/share/pixmaps/calculate-console-online.svg'))
|
|
|
|
|
else:
|
|
|
|
|
self.setIcon(QtGui.QIcon \
|
|
|
|
|
('/usr/share/pixmaps/calculate-console-offline.svg'))
|
|
|
|
|
(
|
|
|
|
|
'/usr/share/pixmaps/calculate-console-offline.svg'))
|
|
|
|
|
|
|
|
|
|
def translate(self):
|
|
|
|
|
for action_name, action_data in self.actions.items():
|
|
|
|
@ -259,10 +264,10 @@ class TrayIcon (QtGui.QSystemTrayIcon):
|
|
|
|
|
|
|
|
|
|
def help(self):
|
|
|
|
|
self._parent.currentWidget().help()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def bug_report(self):
|
|
|
|
|
self._parent.currentWidget().bug_report()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def tools(self):
|
|
|
|
|
self._parent.currentWidget().tools()
|
|
|
|
|
|
|
|
|
@ -304,10 +309,10 @@ class TrayIcon (QtGui.QSystemTrayIcon):
|
|
|
|
|
self._parent.show()
|
|
|
|
|
self._parent.move(self._parent.cur_pos)
|
|
|
|
|
self._parent.show()
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def exit(self):
|
|
|
|
|
#if self.update_thread.isRunning():
|
|
|
|
|
# if self.update_thread.isRunning():
|
|
|
|
|
# text = _('The system is updated')
|
|
|
|
|
# informative_text = _('Stop updating and exit?')
|
|
|
|
|
# reply = show_question(self._parent, text, informative_text)
|
|
|
|
@ -319,29 +324,29 @@ class TrayIcon (QtGui.QSystemTrayIcon):
|
|
|
|
|
# self.update_thread.close()
|
|
|
|
|
# self.update_thread.wait()
|
|
|
|
|
self._parent._closeEvent()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def activ(self, reason):
|
|
|
|
|
if reason == QtGui.QSystemTrayIcon.Trigger:
|
|
|
|
|
self.windowVisible()
|
|
|
|
|
if reason == QtGui.QSystemTrayIcon.DoubleClick:
|
|
|
|
|
self.windowVisible()
|
|
|
|
|
|
|
|
|
|
def showMessage(self, title, message, icon = 'dialog-warning'):
|
|
|
|
|
def showMessage(self, title, message, icon='dialog-warning'):
|
|
|
|
|
|
|
|
|
|
# This uses the session bus because it's session-specific.
|
|
|
|
|
bus = dbus.SessionBus()
|
|
|
|
|
proxy = bus.get_object('org.freedesktop.Notifications', \
|
|
|
|
|
'/org/freedesktop/Notifications')
|
|
|
|
|
interface = dbus.Interface(proxy,dbus_interface= \
|
|
|
|
|
'org.freedesktop.Notifications')
|
|
|
|
|
|
|
|
|
|
interface = dbus.Interface(proxy, dbus_interface= \
|
|
|
|
|
'org.freedesktop.Notifications')
|
|
|
|
|
|
|
|
|
|
interface.Notify('cl-console-gui', 1, icon, title, message, [], {}, -1)
|
|
|
|
|
|
|
|
|
|
# KDE KNotify
|
|
|
|
|
#bus = dbus.SessionBus()
|
|
|
|
|
#knotify = bus.get_object('org.kde.knotify', '/Notify')
|
|
|
|
|
# bus = dbus.SessionBus()
|
|
|
|
|
# knotify = bus.get_object('org.kde.knotify', '/Notify')
|
|
|
|
|
|
|
|
|
|
#knotify.event("warning", "kde", [], 'title', 'text', [], [], 0, 0,
|
|
|
|
|
# knotify.event("warning", "kde", [], 'title', 'text', [], [], 0, 0,
|
|
|
|
|
# dbus_interface="org.kde.KNotify")
|
|
|
|
|
|
|
|
|
|
def windowVisible(self):
|
|
|
|
@ -358,7 +363,7 @@ class TrayIcon (QtGui.QSystemTrayIcon):
|
|
|
|
|
self.show_update()
|
|
|
|
|
else:
|
|
|
|
|
self.update_thread.start()
|
|
|
|
|
#if not self.update_thread.isRunning():
|
|
|
|
|
# if not self.update_thread.isRunning():
|
|
|
|
|
|
|
|
|
|
def showUpdate(self, message):
|
|
|
|
|
self.show_update()
|
|
|
|
|