add simple smart-punch button in gui

master
Maximilian Zettler 3 years ago
parent eb0e89c387
commit 45089f16db
  1. 5
      timebot/app.py
  2. 14
      timebot/gui.py
  3. 6
      timebot/timebot.py

@ -96,10 +96,9 @@ def run():
getattr(tb, args.t)(punch_datetime) getattr(tb, args.t)(punch_datetime)
elif args.subparser_name == "smart-punch": elif args.subparser_name == "smart-punch":
if args.s == "now": if args.s == "now":
punch_datetime = datetime.datetime.now() tb.smart_punch()
else: else:
punch_datetime = parse_user_time_input(args.s) tb.smart_punch(parse_user_time_input(args.s))
tb.smart_punch(punch_datetime)
elif args.subparser_name == "list-entries": elif args.subparser_name == "list-entries":
end_date = None end_date = None
if args.end_date: if args.end_date:

@ -74,14 +74,17 @@ class TimebotMainWindow(QWidget):
self.text_box_status = QLabel() self.text_box_status = QLabel()
self.text_box_hours_present_area = HoursPresentLabelArea(parent=self) self.text_box_hours_present_area = HoursPresentLabelArea(parent=self)
self.btn_update_status = QPushButton("Refresh Status") self.btn_update_status = QPushButton("Refresh Status")
self.btn_smart_punch = QPushButton("Smart Punch")
layout = QVBoxLayout() layout = QVBoxLayout()
layout.addWidget(self.text_box_status) layout.addWidget(self.text_box_status)
layout.addWidget(self.text_box_hours_present_area) layout.addWidget(self.text_box_hours_present_area)
layout.addWidget(self.btn_update_status) layout.addWidget(self.btn_update_status)
layout.addWidget(self.btn_smart_punch)
self.setLayout(layout) self.setLayout(layout)
self.btn_update_status.clicked.connect(self.update_status) self.btn_update_status.clicked.connect(self.update_status)
self.btn_smart_punch.clicked.connect(self.smart_punch)
self.status_timer_time = timeparse(refresh_interval) * 1000 self.status_timer_time = timeparse(refresh_interval) * 1000
self.status_timer = QTimer() self.status_timer = QTimer()
@ -117,7 +120,7 @@ class TimebotMainWindow(QWidget):
self.status_thread = QThread() self.status_thread = QThread()
self.status_worker = TimebotApiWorker(self, self.timebot) self.status_worker = TimebotApiWorker(self, self.timebot)
self.status_worker.moveToThread(self.status_thread) self.status_worker.moveToThread(self.status_thread)
self.status_thread.started.connect(self.status_worker.run) self.status_thread.started.connect(self.status_worker.run_status)
self.status_worker.finished.connect(self.status_thread.quit) self.status_worker.finished.connect(self.status_thread.quit)
self.status_worker.finished.connect(self.status_worker.deleteLater) self.status_worker.finished.connect(self.status_worker.deleteLater)
self.status_thread.finished.connect(self.status_thread.deleteLater) self.status_thread.finished.connect(self.status_thread.deleteLater)
@ -127,6 +130,13 @@ class TimebotMainWindow(QWidget):
self.status_thread.start() self.status_thread.start()
self.update_status_started() self.update_status_started()
def smart_punch(self):
try:
self.timebot.smart_punch()
self.update_status()
except Exception as e:
self.error_msg_show(str(e))
def get_password(self, callback: callable = None): def get_password(self, callback: callable = None):
if self.timebot.mobatime_api.password is not None: if self.timebot.mobatime_api.password is not None:
return return
@ -182,7 +192,7 @@ class TimebotApiWorker(QObject):
self.tmw = tmw self.tmw = tmw
self.timebot = timebot self.timebot = timebot
def run(self): def run_status(self):
try: try:
self.tmw.present = self.timebot.present self.tmw.present = self.timebot.present
self.tmw.update_hours_present(override=self.timebot.get_hours_present()) self.tmw.update_hours_present(override=self.timebot.get_hours_present())

@ -307,15 +307,17 @@ class TimeBot:
""" """
self.mobatime_api.save_entry(punch_datetime, PunchCodes.BREAK_END.value, note="pause ende").raise_for_status() self.mobatime_api.save_entry(punch_datetime, PunchCodes.BREAK_END.value, note="pause ende").raise_for_status()
def smart_punch(self, punch_datetime: datetime.datetime) -> None: def smart_punch(self, punch_datetime: datetime.datetime = None) -> None:
""" """
Perform smart punch for today. Perform smart punch for today.
This tries to detect your last action and will create entries in to following order: This tries to detect your last action and will create entries in to following order:
punch_in -> break_start -> break_end -> punch_out punch_in -> break_start -> break_end -> punch_out
:param datetime.datetime punch_datetime: a datetime object to identify the current day aka. today :param datetime.datetime punch_datetime: a datetime object to identify the current day aka. today (default: now)
""" """
if punch_datetime is None:
punch_datetime = datetime.datetime.now()
last_punch = self.mobatime_api.get_entries( last_punch = self.mobatime_api.get_entries(
1, 1,
start_date=punch_datetime.replace(hour=0, minute=0, second=0, microsecond=0), start_date=punch_datetime.replace(hour=0, minute=0, second=0, microsecond=0),

Loading…
Cancel
Save