Skip to content

Commit a37d07e

Browse files
committed
Implemented basic version
Environment: - Python 3.4.1 (Windows x64) - PyQt5 installed via MSI installer
1 parent d8f026f commit a37d07e

File tree

3 files changed

+33
-144
lines changed

3 files changed

+33
-144
lines changed

TimeCalculator.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import sys
2-
from PyQt5 import QtWidgets, QtCore
2+
from PyQt5 import QtWidgets, QtCore, QtGui
33

44

55
class TardisDiff(QtWidgets.QMainWindow):
66
def __init__(self):
77
super(TardisDiff, self).__init__()
8+
self.diff = 0
9+
10+
self.clipboard = QtWidgets.QApplication.clipboard()
11+
QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+Shift+C"), self, self.setClipboard)
812
self.initUI()
913

1014
def initUI(self):
@@ -14,17 +18,22 @@ def initUI(self):
1418
self.formLayout = QtWidgets.QFormLayout()
1519
self.label_time1 = QtWidgets.QLabel(self.centralwidget)
1620
self.label_time2 = QtWidgets.QLabel(self.centralwidget)
21+
self.label_time3 = QtWidgets.QLabel(self.centralwidget)
1722
self.timeEdit1 = QtWidgets.QTimeEdit(self.centralwidget)
1823
self.timeEdit2 = QtWidgets.QTimeEdit(self.centralwidget)
24+
self.timeEdit3 = QtWidgets.QTimeEdit(self.centralwidget)
1925
self.label_timeDiff = QtWidgets.QLabel(self.centralwidget)
2026
self.label_timeDiffOut = QtWidgets.QLabel(self.centralwidget)
2127

2228
self.label_time1.setText("Time 1:")
2329
self.label_time2.setText("Time 2:")
30+
self.label_time3.setText("Break Time:")
2431
self.label_timeDiff.setText("Difference")
2532
self.label_timeDiffOut.setText("")
2633
self.timeEdit1.setTime(QtCore.QTime(8, 0))
27-
self.timeEdit2.setTime(QtCore.QTime(17, 0))
34+
currentTime = QtCore.QTime.currentTime()
35+
currentTime.setHMS(currentTime.hour(), currentTime.minute(), 0)
36+
self.timeEdit2.setTime(currentTime)
2837

2938
#Set relations
3039
self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole,
@@ -36,8 +45,12 @@ def initUI(self):
3645
self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole,
3746
self.timeEdit2)
3847
self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole,
39-
self.label_timeDiff)
48+
self.label_time3)
4049
self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole,
50+
self.timeEdit3)
51+
self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole,
52+
self.label_timeDiff)
53+
self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole,
4154
self.label_timeDiffOut)
4255
self.gridLayout.addLayout(self.formLayout, 0, 0, 1, 1)
4356
self.setCentralWidget(self.centralwidget)
@@ -47,17 +60,31 @@ def initUI(self):
4760
#connect slots
4861
self.timeEdit1.timeChanged.connect(self.inputChanged)
4962
self.timeEdit2.timeChanged.connect(self.inputChanged)
63+
self.timeEdit3.timeChanged.connect(self.inputChanged)
5064

5165
self.setWindowTitle('TardisDiff')
5266
QtCore.QMetaObject.connectSlotsByName(self)
53-
67+
self.inputChanged()
5468
self.show()
5569

5670
def inputChanged(self):
71+
"""
72+
Checks both time inputs and the break time input to determine the difference.
73+
Then calls the method to update the ui.
74+
"""
5775
time1 = self.timeEdit1.time()
5876
time2 = self.timeEdit2.time()
59-
diff = time1.secsTo(time2)
60-
self.label_timeDiffOut.setText(str(diff/3600))
77+
breakTime = self.timeEdit3.time().secsTo(QtCore.QTime(0, 0))
78+
self.diff = (time1.secsTo(time2) + breakTime) / 3600
79+
self.diff = round(self.diff, 2)
80+
self.label_timeDiffOut.setText(str(self.diff))
81+
82+
def setClipboard(self):
83+
"""Sets the current diff text to clipboard"""
84+
self.clipboard.setText(str(self.diff))
85+
self.statusBar().showMessage("Copied to clipboard.")
86+
87+
6188

6289

6390
def main():

mainwindow.ui

Lines changed: 0 additions & 72 deletions
This file was deleted.

ui.py

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)