diff --git a/config.json b/config.json index dd72863..2e877ac 100644 --- a/config.json +++ b/config.json @@ -1 +1 @@ -{"loggingLevel": "DEBUG"} \ No newline at end of file +{"loggingLevel": "ERROR", "directories": {"ASSET": null, "CUST": null, "DOB": null, "FIN": null, "output": null}} \ No newline at end of file diff --git a/main.py b/main.py index 74db68a..6816555 100644 --- a/main.py +++ b/main.py @@ -36,6 +36,7 @@ def open_error_dialog(errorLabel: str, errorDescription: str, errorText: str): # Used to easily record uniform timestamps now = lambda : dt.now().strftime("%H:%M-%S.%f") +fileRoot = lambda filePath : '/'.join(filePath.split('/')[:-1]) # This class is responable for managing the UI of the application # and connection it to the functionality of ILParser.py @@ -94,12 +95,16 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): self.processButton.setEnabled(ready) def _set_file(self, lineEdit: QtWidgets.QLineEdit, selfFile: Literal["ASSET", "CUST", "DOB", "FIN"]) -> Optional[str] : - selectedFile: list[str] = QtWidgets.QFileDialog.getOpenFileName(self, "OpenFile") + defaultLocation = self._default_location(selfFile) + selectedFile: list[str] = QtWidgets.QFileDialog.getOpenFileName(self, "OpenFile", directory=defaultLocation) debug(f"Selected file: {selectedFile}") lineEdit.setText(selectedFile[0]) file = selectedFile[0] if selectedFile[0] != '' else None + if file!= None: + self._default_location(selfFile, set=fileRoot(file)) if file != None and self.outputLocation == None: - self._auto_output_set(fileRoot='/'.join(file.split('/')[:-1])) + # Output will may be from memory, or based on file root + self._auto_output_set(fileRootStr=fileRoot(file)) if selfFile == "ASSET": self.assetFile = file elif selfFile == "CUST": @@ -113,10 +118,28 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): def _set_output(self): self.outputLocation = QtWidgets.QFileDialog.getSaveFileName(self, "Output file name") if QtWidgets.QFileDialog.getSaveFileName(self, "Output file name") != '' else None self.outputLE.setText(self.outputLocation if self.outputLocation != None else '') + self._default_location("output", set=fileRoot(self.outputLocation), overwrite=True) debug(f"Output Location: {self.outputLocation}") - def _auto_output_set(self, fileRoot): - self.outputLocation = fileRoot + f"/Portfolio Contracts - {dt.now().strftime('%Y-%m-%d')}.xlsx" + def _default_location(self, file: Literal["ASSET", "CUST", "DOB", "FIN", "output"], set: str = None, overwrite: bool = False) -> Optional[str]: + # Gets the default location for the a file + # Set if set provided and default location is not set + # Will always overwrite the default location if overwrite is True + defaultLocation = config["directories"][file] + debug(f"Default location: {defaultLocation}") + if set != None: + debug(f"Setting default location to: {set} | ({(overwrite | (defaultLocation == None))})") + config["directories"][file] = set if (overwrite | (defaultLocation == None)) else defaultLocation + with open("config.json", 'w') as configFile: + dump(config, configFile) + return set + else: + return defaultLocation + + def _auto_output_set(self, fileRootStr): + # Check the config for a saved output location + self.outputLocation = fileRootStr + f"/Portfolio Contracts - {dt.now().strftime('%Y-%m-%d')}.xlsx" + self._default_location("output", set=fileRoot(self.outputLocation), overwrite=False) self.outputLE.setText(self.outputLocation if self.outputLocation != None else '') debug(f"Auto set output: {self.outputLocation}") diff --git a/todo.txt b/todo.txt index 897a710..5579448 100644 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,4 @@ [X] Working log level button [X] Open file button [X] Error Dialog -[ ] Directory memory \ No newline at end of file +[X] Directory memory \ No newline at end of file