|
|
@ -1,15 +1,43 @@ |
|
|
|
import datetime |
|
|
|
import datetime |
|
|
|
import logging |
|
|
|
import logging |
|
|
|
|
|
|
|
from typing import Tuple |
|
|
|
|
|
|
|
|
|
|
|
from PyQt5 import QtGui |
|
|
|
from PyQt5 import QtGui |
|
|
|
from PyQt5.QtCore import QTimer, QObject, pyqtSignal, QThread, Qt |
|
|
|
from PyQt5.QtCore import QTimer, QObject, pyqtSignal, QThread, Qt |
|
|
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QLabel, QMessageBox, QInputDialog, QLineEdit, QHBoxLayout |
|
|
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QLabel, QMessageBox, QLineEdit, \ |
|
|
|
|
|
|
|
QHBoxLayout, QCheckBox, QDialogButtonBox, QFormLayout, QDialog |
|
|
|
|
|
|
|
|
|
|
|
from timebot.timebot import TimeBot, TimebotObtainPasswordError |
|
|
|
from timebot.timebot import TimeBot, TimebotObtainPasswordError |
|
|
|
|
|
|
|
|
|
|
|
package_logger = logging.getLogger(__name__) |
|
|
|
package_logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MyPasswordDialog(QDialog): |
|
|
|
|
|
|
|
def __init__(self, parent=None): |
|
|
|
|
|
|
|
super().__init__(parent) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.setWindowTitle("Timebot Password") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) |
|
|
|
|
|
|
|
self.buttonBox.accepted.connect(self.accept) |
|
|
|
|
|
|
|
self.buttonBox.rejected.connect(self.reject) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.first = QLineEdit(self) |
|
|
|
|
|
|
|
self.first.setEchoMode(QLineEdit.Password) |
|
|
|
|
|
|
|
self.second = QCheckBox(self) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.layout = QFormLayout() |
|
|
|
|
|
|
|
self.layout.addRow("Enter your password:", self.first) |
|
|
|
|
|
|
|
self.layout.addRow("Cache password:", self.second) |
|
|
|
|
|
|
|
self.layout.addWidget(self.buttonBox) |
|
|
|
|
|
|
|
self.setLayout(self.layout) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_password(self) -> Tuple[bool, str, bool]: |
|
|
|
|
|
|
|
if self.exec(): |
|
|
|
|
|
|
|
return True, self.first.text(), self.second.isChecked() |
|
|
|
|
|
|
|
return False, "", False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HoursPresentLabelArea(QWidget): |
|
|
|
class HoursPresentLabelArea(QWidget): |
|
|
|
def __init__(self, parent=None): |
|
|
|
def __init__(self, parent=None): |
|
|
|
super().__init__(parent) |
|
|
|
super().__init__(parent) |
|
|
@ -66,8 +94,6 @@ class TimebotMainWindow(QWidget): |
|
|
|
self.error_msg.setIcon(QMessageBox.Critical) |
|
|
|
self.error_msg.setIcon(QMessageBox.Critical) |
|
|
|
self.error_msg.finished.connect(self.error_msg_finished) |
|
|
|
self.error_msg.finished.connect(self.error_msg_finished) |
|
|
|
|
|
|
|
|
|
|
|
self.password_dialog = QInputDialog() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.update_status_running = False |
|
|
|
self.update_status_running = False |
|
|
|
self.update_status() |
|
|
|
self.update_status() |
|
|
|
|
|
|
|
|
|
|
@ -98,15 +124,17 @@ class TimebotMainWindow(QWidget): |
|
|
|
self.update_status_started() |
|
|
|
self.update_status_started() |
|
|
|
|
|
|
|
|
|
|
|
def get_password(self, callback: callable = None): |
|
|
|
def get_password(self, callback: callable = None): |
|
|
|
|
|
|
|
if self.timebot.mobatime_api.password is not None: |
|
|
|
|
|
|
|
return |
|
|
|
self.status_timer.stop() |
|
|
|
self.status_timer.stop() |
|
|
|
password, ok = self.password_dialog.getText(self, "Timebot Password", 'Enter your password:', |
|
|
|
ok, password, keep = MyPasswordDialog(self).get_password() |
|
|
|
QLineEdit.Password) |
|
|
|
|
|
|
|
if ok: |
|
|
|
if ok: |
|
|
|
self.timebot.mobatime_api.password = password |
|
|
|
self.timebot.mobatime_api.password = password |
|
|
|
try: |
|
|
|
try: |
|
|
|
_ = self.timebot.mobatime_api.session |
|
|
|
_ = self.timebot.mobatime_api.session |
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
|
self.error_msg_show(str(e)) |
|
|
|
self.error_msg_show(str(e)) |
|
|
|
|
|
|
|
if not keep: |
|
|
|
self.timebot.mobatime_api.password = None |
|
|
|
self.timebot.mobatime_api.password = None |
|
|
|
if callback is not None: |
|
|
|
if callback is not None: |
|
|
|
callback() |
|
|
|
callback() |
|
|
|