Skip to content

Commit

Permalink
#187 Basic functionality of open file - does now actually open the lo…
Browse files Browse the repository at this point in the history
…g file(s)
  • Loading branch information
dmh23 committed Mar 13, 2023
1 parent 946dabc commit 9621178
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
31 changes: 23 additions & 8 deletions src/prototype_ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QMainWindow, QApplication, QProgressBar, QFileDialog

from src.log.log import Log
from src.configuration.config_manager import ConfigManager
from src.ui.actions import Actions
from src.ui.menubar import MenuBarManager
Expand All @@ -18,7 +19,7 @@ class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
#
# First of all, get config manager up and running so we have access to any settings that it manages for us
# First of all, get config manager up and running so that we have access to any settings that it manages for us
#
self._config_manager = ConfigManager()

Expand Down Expand Up @@ -46,6 +47,13 @@ def __init__(self):
self._actions.set_file_options.triggered.connect(self._action_set_file_options)
self._actions.exit.triggered.connect(self._action_exit)

# Internal variable(s) to communicate from dialogs to main after they are closed
self._open_file_dialog_chosen_files = None

# Main variables to keep details of current open logs etc.
self._log = None
self._log_file_names = None

# Canvas etc. comments TODO

self.canvas = TrackAnalysisCanvas()
Expand Down Expand Up @@ -78,13 +86,20 @@ def make_status_bar_tall_enough_to_contain_progress_bar(self):

def _action_open_file(self):
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)
if not dlg.exec():
print("Cancelled dialog")
return

self.setWindowTitle(self._open_file_dialog_chosen_model_title)
self._log_file_names = self._open_file_dialog_chosen_files
self._log = Log(self._config_manager.get_log_directory())
self._log.load_all(self._log_file_names, self._please_wait, self._current_track,
self._config_manager.get_calculate_new_reward(),
self._config_manager.get_calculate_alternate_discount_factors())

def _chosen_open_file_callback(self, file_names, model_title):
self._open_file_dialog_chosen_files = file_names
self._open_file_dialog_chosen_model_title = model_title

def _action_file_info(self):
print("File Info - NOT IMPLEMENTED YET IN VERSION 4")
Expand Down
7 changes: 4 additions & 3 deletions src/ui/open_file_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def __init__(self, parent: QMainWindow, please_wait: PleaseWait, current_track:

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

log_layout.addWidget(_make_centred_label(log_meta.race_type.get().name), row, 1)
Expand Down Expand Up @@ -113,8 +114,8 @@ 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)
def _callback_open_file(self, file_names, model_title):
self._chosen_file_callback(file_names, model_title)
self.accept()

@staticmethod
Expand Down

0 comments on commit 9621178

Please sign in to comment.