236 lines
7.9 KiB
Python
236 lines
7.9 KiB
Python
# Import Krita
|
|
from krita import *
|
|
from PyQt5 import QtWidgets, QtCore, QtGui, uic, QtMultimedia
|
|
import os, os.path
|
|
import time
|
|
import datetime
|
|
import xml
|
|
|
|
# Set Window Title Name (and docker name in Krita)
|
|
DOCKER_NAME = 'Timer'
|
|
# Alarm QMessageBox
|
|
message = "Time is Over"
|
|
|
|
|
|
class MainWindow(QtWidgets.QWidget):
|
|
def eventFilter(self, object, event):
|
|
if event.type() == QEvent.Enter:
|
|
print("Mouse is over the label")
|
|
self.stop = True
|
|
print('program stop is', self.stop)
|
|
return True
|
|
elif event.type() == QEvent.Leave:
|
|
print("Mouse is not over the label")
|
|
self.stop = False
|
|
print('program stop is', self.stop)
|
|
return False
|
|
cooldown = 0
|
|
|
|
# Docker Class
|
|
class TimerWatchDocker(DockWidget):
|
|
"""Control amount of work time spent or see the current time"""
|
|
|
|
def __init__(self):
|
|
super(TimerWatchDocker, self).__init__()
|
|
|
|
# Window Title
|
|
self.setWindowTitle(DOCKER_NAME)
|
|
# Widget
|
|
self.window = QtWidgets.QWidget()
|
|
self.layout = uic.loadUi(os.path.dirname(os.path.realpath(__file__)) + '/timer_watch.ui', self.window)
|
|
self.audio_path = os.path.dirname(os.path.realpath(__file__)) + '/Mypdie04.wav'
|
|
self.setWidget(self.window)
|
|
self.setStyleSheet("""
|
|
* {
|
|
background-color: rgba(128, 128, 128, .1);
|
|
}
|
|
|
|
QWidget {
|
|
background-color: rgba(128, 128, 128, .01);
|
|
}
|
|
|
|
.QScrollArea {
|
|
background-color: #00000000;
|
|
}
|
|
|
|
QScrollArea * {
|
|
background-color: #00000000;
|
|
}
|
|
|
|
QScrollArea QToolTip {
|
|
background-color: #ffffff;
|
|
}
|
|
|
|
QAbstractButton {
|
|
background-color: #77000000;
|
|
border: none;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
QAbstractButton:checked {
|
|
background-color: #aa306fa8;
|
|
}
|
|
|
|
QAbstractButton:hover {
|
|
background-color: #1c1c1c;
|
|
}
|
|
|
|
QAbstractButton:pressed {
|
|
background-color: #53728e;
|
|
}
|
|
""")
|
|
|
|
self.timer_sw = QtCore.QTimer(self)
|
|
self.timer_sw.timeout.connect(self.SW_Display)
|
|
self.timer_sw.start(1000)
|
|
|
|
# Inictialize Variables
|
|
self.counter = 900
|
|
self.switch = 0 # 0=Pause, 1=Play
|
|
self.isreset = True
|
|
|
|
# Start up Connection
|
|
self.Connect()
|
|
|
|
# Connect Funtions to Buttons
|
|
def Connect(self):
|
|
# Clean First Start
|
|
self.SW_Reset()
|
|
|
|
# Stopwatch buttons
|
|
self.layout.pushButton_startpause.clicked.connect(self.SW_StartPause)
|
|
self.layout.pushButton_reset.clicked.connect(self.SW_Reset)
|
|
self.layout.pushButton_short.clicked.connect(self.SW_StartShort)
|
|
self.layout.pushButton_long.clicked.connect(self.SW_StartLong)
|
|
self.layout.pushButton_break.clicked.connect(self.SW_StartBreak)
|
|
self.layout.pushButton_smallbreak.clicked.connect(self.SW_StartSmallBreak)
|
|
# self.layout.pushButton_alarm.toggled.connect(self.SW_Alarm)
|
|
|
|
# Functions
|
|
def HM_Display(self):
|
|
self.currentTime = QtCore.QTime.currentTime()
|
|
self.layout.lcdNumber_1.setDigitCount(5) # 5=hh:mm 8=hh:mm:ss
|
|
self.strCurrentTime = self.currentTime.toString('hh:mm') # 'hh:mm' 'hh:mm:ss'
|
|
self.layout.lcdNumber_1.display(self.strCurrentTime)
|
|
|
|
def SW_Display(self):
|
|
self.counter -= 1
|
|
self.SW_Tick(self.counter)
|
|
|
|
def SW_Tick(self, counter):
|
|
self.layout.lcdNumber_2.setDigitCount(8)
|
|
self.strProgressTime = time.strftime('%H:%M:%S', time.gmtime(self.counter))
|
|
if not self.isreset:
|
|
self.layout.lcdNumber_2.display(self.strProgressTime)
|
|
self.layout.progressBar_2.setValue(self.counter)
|
|
# if (self.layout.pushButton_alarm.isChecked() == True and self.counter <= 0):
|
|
# self.SW_Alarm()
|
|
if self.counter <= 0:
|
|
self.SW_Alarm()
|
|
self.SW_Pause()
|
|
self.SW_Reset()
|
|
else:
|
|
self.layout.lcdNumber_2.display('00:00:00')
|
|
|
|
def SW_Time(self):
|
|
# Convert Input Time
|
|
hh = self.layout.timeEdit.time().hour()
|
|
mm = self.layout.timeEdit.time().minute()
|
|
ss = self.layout.timeEdit.time().second()
|
|
conv = datetime.timedelta(hours=hh, minutes=mm)
|
|
tsec = conv.total_seconds() + ss
|
|
return tsec
|
|
|
|
def SW_StartShort(self):
|
|
self.layout.timeEdit.setTime(QtCore.QTime.fromString("45", "m"))
|
|
self.setWindowTitle("Short Session")
|
|
self.SW_Start()
|
|
|
|
def SW_StartLong(self):
|
|
self.layout.timeEdit.setTime(QtCore.QTime.fromString("1:30", "h:m"))
|
|
self.setWindowTitle("Long Session")
|
|
self.SW_Start()
|
|
|
|
def SW_StartBreak(self):
|
|
self.layout.timeEdit.setTime(QtCore.QTime.fromString("15", "m"))
|
|
self.setWindowTitle("Food Break")
|
|
self.SW_Start()
|
|
|
|
def SW_StartSmallBreak(self):
|
|
self.layout.timeEdit.setTime(QtCore.QTime.fromString("8", "m"))
|
|
self.setWindowTitle("Break")
|
|
self.SW_Start()
|
|
|
|
def SW_StartPause(self):
|
|
# Select Operation
|
|
if self.switch == 0:
|
|
self.SW_Start() # 0=Pause change to Start
|
|
elif self.switch == 1:
|
|
self.SW_Pause() # 1=Start change to Pause
|
|
else:
|
|
self.SW_Reset()
|
|
|
|
def SW_Start(self):
|
|
# Start Ready
|
|
self.counter = int(self.SW_Time())
|
|
self.maximum = int(self.SW_Time())
|
|
self.layout.progressBar_2.setMaximum(self.maximum)
|
|
# Commands
|
|
self.timer_sw.start()
|
|
# UI
|
|
self.switch = 1
|
|
self.isreset = False
|
|
if self.maximum == 0: # if User time == Zero
|
|
self.layout.pushButton_startpause.setText("Pause:Zero")
|
|
self.layout.timeEdit.setEnabled(False)
|
|
self.layout.progressBar_2.setEnabled(False)
|
|
else: # if User time is NOT Zero
|
|
self.layout.pushButton_startpause.setText("Pause")
|
|
self.layout.timeEdit.setEnabled(False)
|
|
self.layout.progressBar_2.setEnabled(True)
|
|
|
|
def SW_Pause(self):
|
|
# Commands
|
|
self.timer_sw.stop()
|
|
# UI
|
|
self.switch = 0
|
|
self.isreset = False
|
|
self.layout.pushButton_startpause.setText("Start")
|
|
self.layout.timeEdit.setEnabled(False)
|
|
self.layout.progressBar_2.setEnabled(True)
|
|
c = time.strftime('%H:%M:%S', time.gmtime(self.counter))
|
|
self.layout.timeEdit.setTime(QtCore.QTime.fromString(c, "h:m:s"))
|
|
|
|
def SW_Reset(self):
|
|
global cooldown
|
|
# Variables
|
|
self.counter = int(self.SW_Time())
|
|
# Commands
|
|
self.timer_sw.stop()
|
|
self.SW_Tick(self.counter)
|
|
# UI
|
|
cooldown = 0
|
|
self.switch = 0
|
|
self.isreset = True
|
|
self.layout.pushButton_startpause.setText("Start")
|
|
self.layout.timeEdit.setEnabled(True)
|
|
self.layout.progressBar_2.setEnabled(True)
|
|
self.layout.progressBar_2.setValue(0)
|
|
self.layout.lcdNumber_2.display("00:15:00")
|
|
self.layout.timeEdit.setTime(QtCore.QTime.fromString("15", "m"))
|
|
self.setWindowTitle("Timer")
|
|
|
|
def SW_Alarm(self):
|
|
global cooldown
|
|
# os.system(f'aplay {self.audio_path} &')
|
|
if not cooldown:
|
|
os.system("kdialog --msgbox \"FINISHED\" &")
|
|
cooldown = 1
|
|
# QMessageBox.information(QWidget(), i18n("Warning"), i18n(message))
|
|
self.SW_Pause()
|
|
self.SW_Reset()
|
|
|
|
# Change the Canvas
|
|
def canvasChanged(self, canvas):
|
|
pass
|