|
|
|
@ -2,15 +2,16 @@ import datetime |
|
|
|
|
|
|
|
|
|
from PyQt5 import QtGui |
|
|
|
|
from PyQt5.QtCore import QTimer, QObject, pyqtSignal, QThread |
|
|
|
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QLabel, QMessageBox |
|
|
|
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QLabel, QMessageBox, QInputDialog, QLineEdit |
|
|
|
|
|
|
|
|
|
from timebot.timebot import TimeBot |
|
|
|
|
from timebot.timebot import TimeBot, TimebotObtainPasswordError |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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): |
|
|
|
@ -23,6 +24,8 @@ class TimebotApiWorker(QObject): |
|
|
|
|
hours_present = hours_present - datetime.timedelta(microseconds=hours_present.microseconds) |
|
|
|
|
self.hours_present_msg.emit(str(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() |
|
|
|
@ -54,24 +57,46 @@ class TimebotMain(QWidget): |
|
|
|
|
self.btn_update_status.clicked.connect(self.update_status) |
|
|
|
|
self.btnPress2.clicked.connect(self.btnPress2_Clicked) |
|
|
|
|
|
|
|
|
|
self.status_timer_time = 29000 |
|
|
|
|
self.status_timer = QTimer() |
|
|
|
|
self.status_timer.timeout.connect(self.update_status) |
|
|
|
|
self.status_timer.start(29999) |
|
|
|
|
self.status_timer.start(self.status_timer_time) |
|
|
|
|
|
|
|
|
|
# Timer to refresh the main window ... is needed to react on Ctrl+C |
|
|
|
|
self.main_window_timer = QTimer() |
|
|
|
|
self.main_window_timer.timeout.connect(lambda: None) |
|
|
|
|
self.main_window_timer.start(500) |
|
|
|
|
|
|
|
|
|
self.error_msg = QMessageBox() |
|
|
|
|
self.error_msg.setWindowTitle("Timebot ERROR") |
|
|
|
|
self.error_msg.setIcon(QMessageBox.Critical) |
|
|
|
|
self.error_msg.finished.connect(self.error_msg_finished) |
|
|
|
|
|
|
|
|
|
self.password_dialog = QInputDialog() |
|
|
|
|
|
|
|
|
|
self.update_status_running = False |
|
|
|
|
self.update_status() |
|
|
|
|
|
|
|
|
|
def get_password(self, callback: callable = None): |
|
|
|
|
self.status_timer.stop() |
|
|
|
|
password, ok = self.password_dialog.getText(self, "Timebot Password", 'Enter your password:', QLineEdit.Password) |
|
|
|
|
if ok: |
|
|
|
|
self.timebot.mobatime_api.password = password |
|
|
|
|
try: |
|
|
|
|
_ = self.timebot.mobatime_api.session |
|
|
|
|
except Exception as e: |
|
|
|
|
self.error_msg_show(str(e)) |
|
|
|
|
self.timebot.mobatime_api.password = None |
|
|
|
|
callback() |
|
|
|
|
self.status_timer.start(self.status_timer_time) |
|
|
|
|
|
|
|
|
|
def error_msg_show(self, error_text: str): |
|
|
|
|
self.error_msg.setText(error_text) |
|
|
|
|
self.status_timer.stop() |
|
|
|
|
self.error_msg.exec_() |
|
|
|
|
|
|
|
|
|
def error_msg_finished(self): |
|
|
|
|
self.status_timer.start(29999) |
|
|
|
|
self.status_timer.start(self.status_timer_time) |
|
|
|
|
|
|
|
|
|
def update_status_started(self): |
|
|
|
|
self.btn_update_status.setEnabled(False) |
|
|
|
@ -96,7 +121,8 @@ class TimebotMain(QWidget): |
|
|
|
|
self.status_thread.finished.connect(self.update_status_finished) |
|
|
|
|
self.status_worker.status_msg.connect(self.text_box_status.setText) |
|
|
|
|
self.status_worker.hours_present_msg.connect(self.text_box_hours_present.setText) |
|
|
|
|
self.status_worker.error.connect(lambda exp: self.error_msg_show(str(exp))) |
|
|
|
|
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() |
|
|
|
|
|
|
|
|
|