Skip to content

Commit 9621178

Browse files
committed
#187 Basic functionality of open file - does now actually open the log file(s)
1 parent 946dabc commit 9621178

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/prototype_ui/main.py

+23-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from PyQt6.QtCore import Qt
44
from PyQt6.QtWidgets import QMainWindow, QApplication, QProgressBar, QFileDialog
55

6+
from src.log.log import Log
67
from src.configuration.config_manager import ConfigManager
78
from src.ui.actions import Actions
89
from src.ui.menubar import MenuBarManager
@@ -18,7 +19,7 @@ class MainWindow(QMainWindow):
1819
def __init__(self):
1920
super().__init__()
2021
#
21-
# First of all, get config manager up and running so we have access to any settings that it manages for us
22+
# First of all, get config manager up and running so that we have access to any settings that it manages for us
2223
#
2324
self._config_manager = ConfigManager()
2425

@@ -46,6 +47,13 @@ def __init__(self):
4647
self._actions.set_file_options.triggered.connect(self._action_set_file_options)
4748
self._actions.exit.triggered.connect(self._action_exit)
4849

50+
# Internal variable(s) to communicate from dialogs to main after they are closed
51+
self._open_file_dialog_chosen_files = None
52+
53+
# Main variables to keep details of current open logs etc.
54+
self._log = None
55+
self._log_file_names = None
56+
4957
# Canvas etc. comments TODO
5058

5159
self.canvas = TrackAnalysisCanvas()
@@ -78,13 +86,20 @@ def make_status_bar_tall_enough_to_contain_progress_bar(self):
7886

7987
def _action_open_file(self):
8088
dlg = OpenFileDialog(self, self._please_wait, self._current_track, self._config_manager.get_log_directory(), self._chosen_open_file_callback)
81-
if dlg.exec():
82-
print("Success!")
83-
else:
84-
print("Cancel!")
85-
86-
def _chosen_open_file_callback(self, file_names):
87-
print("Will open file(s): ", file_names)
89+
if not dlg.exec():
90+
print("Cancelled dialog")
91+
return
92+
93+
self.setWindowTitle(self._open_file_dialog_chosen_model_title)
94+
self._log_file_names = self._open_file_dialog_chosen_files
95+
self._log = Log(self._config_manager.get_log_directory())
96+
self._log.load_all(self._log_file_names, self._please_wait, self._current_track,
97+
self._config_manager.get_calculate_new_reward(),
98+
self._config_manager.get_calculate_alternate_discount_factors())
99+
100+
def _chosen_open_file_callback(self, file_names, model_title):
101+
self._open_file_dialog_chosen_files = file_names
102+
self._open_file_dialog_chosen_model_title = model_title
88103

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

src/ui/open_file_dialog.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def __init__(self, parent: QMainWindow, please_wait: PleaseWait, current_track:
8585

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

9192
log_layout.addWidget(_make_centred_label(log_meta.race_type.get().name), row, 1)
@@ -113,8 +114,8 @@ def __init__(self, parent: QMainWindow, please_wait: PleaseWait, current_track:
113114

114115
self.setLayout(layout)
115116

116-
def _callback_open_file(self, file_names):
117-
self._chosen_file_callback(file_names)
117+
def _callback_open_file(self, file_names, model_title):
118+
self._chosen_file_callback(file_names, model_title)
118119
self.accept()
119120

120121
@staticmethod

0 commit comments

Comments
 (0)