-
Notifications
You must be signed in to change notification settings - Fork 0
/
practice_log_screen.py
135 lines (111 loc) · 4.99 KB
/
practice_log_screen.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from PySide2 import QtWidgets
from widgets import (
AddAchievementToSessionDialog, AddExerciseToSessionDialog, AddLightBulbMomentDialog, AddSongToSessionDialog,
LayoutWithTable
)
from practice_log_controller import PracticeLogController
class PracticeLogScreen(QtWidgets.QDialog):
def __init__(self, practice_log_controller: PracticeLogController, parent=None):
QtWidgets.QDialog.__init__(self, parent)
self.practice_log_controller = practice_log_controller
self.init_layouts()
def init_layouts(self):
self.layouts = [
self.init_time_layout(),
LayoutWithTable(
label_text='exercises',
add_action=self.add_exercise,
table_headers=['name', 'category', 'how it felt?', 'comment'],
table_content=self.practice_log_controller.get_exercises(),
),
LayoutWithTable(
label_text='songs',
add_action=self.add_song,
table_headers=['artist', 'title', 'how it felt?', 'comment'],
table_content=self.practice_log_controller.get_songs(),
),
LayoutWithTable(
label_text='achievements',
add_action=self.add_achievement,
table_headers=['name', 'value', 'unit'],
table_content=self.practice_log_controller.get_achievements(),
),
LayoutWithTable(
label_text='light bulb moments',
add_action=self.add_light_bulb_moment,
table_headers=['effect', 'clue'],
table_content=self.practice_log_controller.get_light_bulb_moments(),
),
self.init_notes_layout(),
]
full_layout = QtWidgets.QVBoxLayout()
for i, layout in enumerate(self.layouts):
full_layout.addLayout(layout, i)
self.setLayout(full_layout)
def init_time_layout(self):
self.time_picker = QtWidgets.QDateTimeEdit()
self.time_picker.setDateTime(self.practice_log_controller.get_start())
self.time_picker.setCalendarPopup(True)
save_start_button = QtWidgets.QPushButton('Save start time')
save_start_button.clicked.connect(self.save_start)
time_layout = QtWidgets.QHBoxLayout()
time_layout.addWidget(QtWidgets.QLabel('start'))
time_layout.addWidget(self.time_picker)
time_layout.addWidget(save_start_button)
return time_layout
def save_start(self):
new_time = self.time_picker.dateTime().toPython()
self.practice_log_controller.save_start(start=new_time)
def init_notes_layout(self):
self.notes = QtWidgets.QTextEdit()
self.notes.insertPlainText(self.practice_log_controller.get_notes())
# TODO: button active only if notes changed?
save_notes_button = QtWidgets.QPushButton('Save notes')
save_notes_button.clicked.connect(self.save_notes)
notes_layout = QtWidgets.QVBoxLayout()
notes_layout.addWidget(QtWidgets.QLabel('notes'))
notes_layout.addWidget(self.notes)
notes_layout.addWidget(save_notes_button)
return notes_layout
def save_notes(self):
new_notes = self.notes.toPlainText()
self.practice_log_controller.save_notes(new_notes)
def add_exercise(self):
exercise_choices = self.practice_log_controller.get_exercise_choices()
# TODO: error dialog if no exercises to select from
dialog = AddExerciseToSessionDialog(exercise_choices=exercise_choices, parent=self)
dialog.show()
if dialog.exec_():
data = dialog.get_data()
self.practice_log_controller.add_exercise(data=data)
# TODO: refresh the table to show newly added exercise
def add_song(self):
dialog = AddSongToSessionDialog(
artists=self.practice_log_controller.get_existing_artists(),
titles=self.practice_log_controller.get_existing_titles(),
parent=self,
)
dialog.show()
if dialog.exec_():
data = dialog.get_data()
self.practice_log_controller.add_song(**data)
# TODO: refresh the table to show newly added song
def add_achievement(self):
achievement_choices = self.practice_log_controller.get_achievement_choices()
dialog = AddAchievementToSessionDialog(achievement_choices=achievement_choices, parent=self)
dialog.show()
if dialog.exec_():
data = dialog.get_data()
self.practice_log_controller.add_achievement(**data)
def add_light_bulb_moment(self):
dialog = AddLightBulbMomentDialog(self)
dialog.show()
if dialog.exec_():
data = dialog.get_data()
self.practice_log_controller.add_light_bulb_moment(**data)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
window = PracticeLogScreen(practice_log_controller=PracticeLogController(1))
window.show()
sys.exit(app.exec_())