Skip to content

Commit 946dabc

Browse files
committed
#187 Wire up open file dialog to pash chosen file name(s) back to the main app
1 parent 4a83a93 commit 946dabc

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/prototype_ui/main.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,15 @@ def make_status_bar_tall_enough_to_contain_progress_bar(self):
7777
self.statusBar().setMinimumHeight(h)
7878

7979
def _action_open_file(self):
80-
dlg = OpenFileDialog(self, self._please_wait, self._current_track, self._config_manager.get_log_directory())
80+
dlg = OpenFileDialog(self, self._please_wait, self._current_track, self._config_manager.get_log_directory(), self._chosen_open_file_callback)
8181
if dlg.exec():
8282
print("Success!")
8383
else:
8484
print("Cancel!")
8585

86+
def _chosen_open_file_callback(self, file_names):
87+
print("Will open file(s): ", file_names)
88+
8689
def _action_file_info(self):
8790
print("File Info - NOT IMPLEMENTED YET IN VERSION 4")
8891

src/ui/open_file_dialog.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121

2222

2323
class OpenFileDialog(QDialog):
24-
def __init__(self, parent: QMainWindow, please_wait: PleaseWait, current_track: Track, log_directory: str):
24+
def __init__(self, parent: QMainWindow, please_wait: PleaseWait, current_track: Track, log_directory: str, chosen_file_callback: callable):
2525
super().__init__(parent)
2626

27+
self._chosen_file_callback = chosen_file_callback
28+
2729
log_info, hidden_log_count = get_model_info_for_open_model_dialog(current_track, log_directory, please_wait)
2830

2931
all_best_times = []
@@ -76,16 +78,15 @@ def __init__(self, parent: QMainWindow, please_wait: PleaseWait, current_track:
7678
else:
7779
file_names = log.source_files
7880

79-
# TODO equivalent:
80-
# def callback(f=file_names): self._callback_open_file(f)
81-
8281
log_meta = log.log_meta
8382

8483
progress_percent = self._get_progress_percent(log_meta)
8584
success_percent = self._get_success_percent(log_meta)
8685

8786
# self._place_in_grid(row, 0, tk.Button(master, text=log.display_name, command=callback), "E")
88-
log_layout.addWidget(QPushButton(log.display_name), row, 0)
87+
button = QPushButton(log.display_name)
88+
button.clicked.connect(lambda state, x=file_names: self._callback_open_file(x)) # Magic ?!!?!?!
89+
log_layout.addWidget(button, row, 0)
8990

9091
log_layout.addWidget(_make_centred_label(log_meta.race_type.get().name), row, 1)
9192
log_layout.addWidget(_make_centred_label(log_meta.job_type.get().name), row, 2)
@@ -112,6 +113,10 @@ def __init__(self, parent: QMainWindow, please_wait: PleaseWait, current_track:
112113

113114
self.setLayout(layout)
114115

116+
def _callback_open_file(self, file_names):
117+
self._chosen_file_callback(file_names)
118+
self.accept()
119+
115120
@staticmethod
116121
def _get_progress_percent(log_meta):
117122
return log_meta.average_percent_complete.get()

0 commit comments

Comments
 (0)