|
|
@ -10,30 +10,6 @@ from timebot.timebot import TimeBot, TimebotObtainPasswordError |
|
|
|
package_logger = logging.getLogger(__name__) |
|
|
|
package_logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TimebotApiWorker(QObject): |
|
|
|
|
|
|
|
status_msg = pyqtSignal(object) |
|
|
|
|
|
|
|
hours_present_msg = pyqtSignal(object) |
|
|
|
|
|
|
|
error = pyqtSignal(object) |
|
|
|
|
|
|
|
obtain_password = pyqtSignal() |
|
|
|
|
|
|
|
finished = pyqtSignal() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, timebot: TimeBot): |
|
|
|
|
|
|
|
super().__init__() |
|
|
|
|
|
|
|
self.timebot = timebot |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(self): |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
hours_present = self.timebot.get_hours_present() |
|
|
|
|
|
|
|
hours_present = hours_present - datetime.timedelta(microseconds=hours_present.microseconds) |
|
|
|
|
|
|
|
self.hours_present_msg.emit(hours_present) |
|
|
|
|
|
|
|
self.status_msg.emit(self.timebot.status()) |
|
|
|
|
|
|
|
except TimebotObtainPasswordError as e: |
|
|
|
|
|
|
|
self.obtain_password.emit() |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
|
|
self.error.emit(e) |
|
|
|
|
|
|
|
self.finished.emit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HoursPresentLabelArea(QWidget): |
|
|
|
class HoursPresentLabelArea(QWidget): |
|
|
|
def __init__(self, parent=None): |
|
|
|
def __init__(self, parent=None): |
|
|
|
super().__init__(parent) |
|
|
|
super().__init__(parent) |
|
|
@ -50,7 +26,7 @@ class HoursPresentLabelArea(QWidget): |
|
|
|
self.setLayout(layout) |
|
|
|
self.setLayout(layout) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TimebotMain(QWidget): |
|
|
|
class TimebotMainWindow(QWidget): |
|
|
|
def __init__(self, timebot: TimeBot, parent=None): |
|
|
|
def __init__(self, timebot: TimeBot, parent=None): |
|
|
|
super().__init__(parent) |
|
|
|
super().__init__(parent) |
|
|
|
|
|
|
|
|
|
|
@ -97,15 +73,30 @@ class TimebotMain(QWidget): |
|
|
|
|
|
|
|
|
|
|
|
def update_main_window(self): |
|
|
|
def update_main_window(self): |
|
|
|
self.main_window_info_thread = QThread() |
|
|
|
self.main_window_info_thread = QThread() |
|
|
|
self.main_window_info_worker = MainWindowInfoWorker() |
|
|
|
self.main_window_info_worker = MainWindowInfoWorker(self) |
|
|
|
self.main_window_info_worker.moveToThread(self.main_window_info_thread) |
|
|
|
self.main_window_info_worker.moveToThread(self.main_window_info_thread) |
|
|
|
self.main_window_info_thread.started.connect(self.main_window_info_worker.run) |
|
|
|
self.main_window_info_thread.started.connect(self.main_window_info_worker.run) |
|
|
|
self.main_window_info_worker.finished.connect(self.main_window_info_thread.quit) |
|
|
|
self.main_window_info_worker.finished.connect(self.main_window_info_thread.quit) |
|
|
|
self.main_window_info_worker.finished.connect(self.main_window_info_worker.deleteLater) |
|
|
|
self.main_window_info_worker.finished.connect(self.main_window_info_worker.deleteLater) |
|
|
|
self.main_window_info_thread.finished.connect(self.main_window_info_thread.deleteLater) |
|
|
|
self.main_window_info_thread.finished.connect(self.main_window_info_thread.deleteLater) |
|
|
|
self.main_window_info_worker.finished.connect(self.update_hours_present) |
|
|
|
|
|
|
|
self.main_window_info_thread.start() |
|
|
|
self.main_window_info_thread.start() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_status(self): |
|
|
|
|
|
|
|
if self.update_status_running: |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
self.status_thread = QThread() |
|
|
|
|
|
|
|
self.status_worker = TimebotApiWorker(self, self.timebot) |
|
|
|
|
|
|
|
self.status_worker.moveToThread(self.status_thread) |
|
|
|
|
|
|
|
self.status_thread.started.connect(self.status_worker.run) |
|
|
|
|
|
|
|
self.status_worker.finished.connect(self.status_thread.quit) |
|
|
|
|
|
|
|
self.status_worker.finished.connect(self.status_worker.deleteLater) |
|
|
|
|
|
|
|
self.status_thread.finished.connect(self.status_thread.deleteLater) |
|
|
|
|
|
|
|
self.status_thread.finished.connect(self.update_status_finished) |
|
|
|
|
|
|
|
self.status_worker.error.connect(lambda exp, *args: self.error_msg_show(str(exp))) |
|
|
|
|
|
|
|
self.status_worker.obtain_password.connect(lambda *args: self.get_password(self.update_status)) |
|
|
|
|
|
|
|
self.status_thread.start() |
|
|
|
|
|
|
|
self.update_status_started() |
|
|
|
|
|
|
|
|
|
|
|
def get_password(self, callback: callable = None): |
|
|
|
def get_password(self, callback: callable = None): |
|
|
|
self.status_timer.stop() |
|
|
|
self.status_timer.stop() |
|
|
|
password, ok = self.password_dialog.getText(self, "Timebot Password", 'Enter your password:', |
|
|
|
password, ok = self.password_dialog.getText(self, "Timebot Password", 'Enter your password:', |
|
|
@ -117,7 +108,8 @@ class TimebotMain(QWidget): |
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
|
self.error_msg_show(str(e)) |
|
|
|
self.error_msg_show(str(e)) |
|
|
|
self.timebot.mobatime_api.password = None |
|
|
|
self.timebot.mobatime_api.password = None |
|
|
|
callback() |
|
|
|
if callback is not None: |
|
|
|
|
|
|
|
callback() |
|
|
|
self.status_timer.start(self.status_timer_time) |
|
|
|
self.status_timer.start(self.status_timer_time) |
|
|
|
|
|
|
|
|
|
|
|
def error_msg_show(self, error_text: str): |
|
|
|
def error_msg_show(self, error_text: str): |
|
|
@ -143,29 +135,38 @@ class TimebotMain(QWidget): |
|
|
|
self.hours_present: datetime.timedelta = override |
|
|
|
self.hours_present: datetime.timedelta = override |
|
|
|
elif self.hours_present > datetime.timedelta(seconds=self.main_window_timer_time / 100): |
|
|
|
elif self.hours_present > datetime.timedelta(seconds=self.main_window_timer_time / 100): |
|
|
|
self.hours_present = self.hours_present + datetime.timedelta(seconds=1) |
|
|
|
self.hours_present = self.hours_present + datetime.timedelta(seconds=1) |
|
|
|
self.text_box_hours_present_area.text_box_hours_present.setText(str(self.hours_present)) |
|
|
|
hp = self.hours_present - datetime.timedelta(microseconds=self.hours_present.microseconds) |
|
|
|
|
|
|
|
self.text_box_hours_present_area.text_box_hours_present.setText(str(hp)) |
|
|
|
|
|
|
|
|
|
|
|
def update_status(self): |
|
|
|
|
|
|
|
if self.update_status_running: |
|
|
|
class TimebotApiWorker(QObject): |
|
|
|
return |
|
|
|
error = pyqtSignal(object) |
|
|
|
self.status_thread = QThread() |
|
|
|
obtain_password = pyqtSignal() |
|
|
|
self.status_worker = TimebotApiWorker(self.timebot) |
|
|
|
finished = pyqtSignal() |
|
|
|
self.status_worker.moveToThread(self.status_thread) |
|
|
|
|
|
|
|
self.status_thread.started.connect(self.status_worker.run) |
|
|
|
def __init__(self, tmw: TimebotMainWindow, timebot: TimeBot): |
|
|
|
self.status_worker.finished.connect(self.status_thread.quit) |
|
|
|
super().__init__() |
|
|
|
self.status_worker.finished.connect(self.status_worker.deleteLater) |
|
|
|
self.tmw = tmw |
|
|
|
self.status_thread.finished.connect(self.status_thread.deleteLater) |
|
|
|
self.timebot = timebot |
|
|
|
self.status_thread.finished.connect(self.update_status_finished) |
|
|
|
|
|
|
|
self.status_worker.status_msg.connect(self.text_box_status.setText) |
|
|
|
def run(self): |
|
|
|
self.status_worker.hours_present_msg.connect(lambda hp, *args: self.update_hours_present(override=hp)) |
|
|
|
try: |
|
|
|
self.status_worker.error.connect(lambda exp, *args: self.error_msg_show(str(exp))) |
|
|
|
self.tmw.update_hours_present(override=self.timebot.get_hours_present()) |
|
|
|
self.status_worker.obtain_password.connect(lambda *args: self.get_password(self.update_status)) |
|
|
|
self.tmw.text_box_status.setText(self.timebot.status()) |
|
|
|
self.status_thread.start() |
|
|
|
except TimebotObtainPasswordError: |
|
|
|
self.update_status_started() |
|
|
|
self.obtain_password.emit() |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
|
|
self.error.emit(e) |
|
|
|
|
|
|
|
self.finished.emit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MainWindowInfoWorker(QObject): |
|
|
|
class MainWindowInfoWorker(QObject): |
|
|
|
finished = pyqtSignal() |
|
|
|
finished = pyqtSignal() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, tmw: TimebotMainWindow): |
|
|
|
|
|
|
|
super().__init__() |
|
|
|
|
|
|
|
self.tmw = tmw |
|
|
|
|
|
|
|
|
|
|
|
def run(self): |
|
|
|
def run(self): |
|
|
|
|
|
|
|
self.tmw.update_hours_present() |
|
|
|
self.finished.emit() |
|
|
|
self.finished.emit() |
|
|
|