Skip to content

Commit

Permalink
#187 Wire up open file dialog to pash chosen file name(s) back to the…
Browse files Browse the repository at this point in the history
… main app
  • Loading branch information
dmh23 committed Mar 13, 2023
1 parent 4a83a93 commit 946dabc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/prototype_ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,15 @@ def make_status_bar_tall_enough_to_contain_progress_bar(self):
self.statusBar().setMinimumHeight(h)

def _action_open_file(self):
dlg = OpenFileDialog(self, self._please_wait, self._current_track, self._config_manager.get_log_directory())
dlg = OpenFileDialog(self, self._please_wait, self._current_track, self._config_manager.get_log_directory(), self._chosen_open_file_callback)
if dlg.exec():
print("Success!")
else:
print("Cancel!")

def _chosen_open_file_callback(self, file_names):
print("Will open file(s): ", file_names)

def _action_file_info(self):
print("File Info - NOT IMPLEMENTED YET IN VERSION 4")

Expand Down
15 changes: 10 additions & 5 deletions src/ui/open_file_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@


class OpenFileDialog(QDialog):
def __init__(self, parent: QMainWindow, please_wait: PleaseWait, current_track: Track, log_directory: str):
def __init__(self, parent: QMainWindow, please_wait: PleaseWait, current_track: Track, log_directory: str, chosen_file_callback: callable):
super().__init__(parent)

self._chosen_file_callback = chosen_file_callback

log_info, hidden_log_count = get_model_info_for_open_model_dialog(current_track, log_directory, please_wait)

all_best_times = []
Expand Down Expand Up @@ -76,16 +78,15 @@ def __init__(self, parent: QMainWindow, please_wait: PleaseWait, current_track:
else:
file_names = log.source_files

# TODO equivalent:
# def callback(f=file_names): self._callback_open_file(f)

log_meta = log.log_meta

progress_percent = self._get_progress_percent(log_meta)
success_percent = self._get_success_percent(log_meta)

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

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

self.setLayout(layout)

def _callback_open_file(self, file_names):
self._chosen_file_callback(file_names)
self.accept()

@staticmethod
def _get_progress_percent(log_meta):
return log_meta.average_percent_complete.get()
Expand Down

0 comments on commit 946dabc

Please sign in to comment.