-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtime_input_dialog.py
More file actions
54 lines (41 loc) · 1.46 KB
/
time_input_dialog.py
File metadata and controls
54 lines (41 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from PyQt5.QtCore import QTime
from PyQt5.QtWidgets import (
QDialog,
QHBoxLayout,
QVBoxLayout,
QTimeEdit,
QLineEdit,
QPushButton,
)
class TimeInputDialog(QDialog):
def __init__(self, event=None, parent=None):
super().__init__(parent)
self.setWindowTitle(f"{'Add' if event else 'Edit'} Event")
mainLayout = QVBoxLayout()
inputLayout = QHBoxLayout()
self.timeEdit = QTimeEdit()
self.timeEdit.setDisplayFormat("HH:mm")
if event:
self.timeEdit.setTime(QTime(event.event_date.hour, event.event_date.minute))
else:
self.timeEdit.setTime(QTime(9, 0))
self.textField = QLineEdit()
self.textField.setPlaceholderText("Enter description:")
if event:
self.textField.setText(event.description)
inputLayout.addWidget(self.timeEdit)
inputLayout.addWidget(self.textField)
buttonLayout = QHBoxLayout()
okButton = QPushButton("OK")
cancelButton = QPushButton("Cancel")
okButton.clicked.connect(self.accept)
cancelButton.clicked.connect(self.reject)
buttonLayout.addWidget(okButton)
buttonLayout.addWidget(cancelButton)
mainLayout.addLayout(inputLayout)
mainLayout.addLayout(buttonLayout)
self.setLayout(mainLayout)
def getTime(self):
return self.timeEdit.time().toString("HH:mm")
def getText(self):
return self.textField.text()