statics server handle about failing and can register QAction

This commit is contained in:
Jakub Trllo 2019-04-27 14:50:58 +02:00
parent 18f11d8f97
commit 460bd8fff0

View file

@ -132,11 +132,11 @@ class StaticsServer(QtCore.QThread):
Idle time resets on keyboard/mouse input.
Is able to emit signals at specific time idle.
"""
def __init__(self):
super(StaticsServer, self).__init__()
self.qaction = None
self.failed_icon = None
self._is_running = False
self._failed = False
self.log = Logger().get_logger(self.__class__.__name__)
try:
self.presets = config.get_presets().get(
@ -146,6 +146,10 @@ class StaticsServer(QtCore.QThread):
self.port = self.find_port()
def set_qaction(self, qaction, failed_icon):
self.qaction = qaction
self.failed_icon = failed_icon
def tray_start(self):
self.start()
@ -153,10 +157,6 @@ class StaticsServer(QtCore.QThread):
def is_running(self):
return self._is_running
@property
def failed(self):
return self._failed
def stop(self):
self._is_running = False
@ -167,8 +167,12 @@ class StaticsServer(QtCore.QThread):
while self._is_running:
httpd.handle_request()
except Exception:
self._failed = True
self._is_running = False
self.log.warning(
'Statics Server service has failed', exc_info=True
)
self._is_running = False
if self.qaction and self.failed_icon:
self.qaction.setIcon(self.failed_icon)
def find_port(self):
start_port = self.presets['default_port']