Dir mem working

master
Griffiths Lott 3 years ago
parent 5efa83f8db
commit cee42cccf5
  1. 2
      config.json
  2. 31
      main.py
  3. 2
      todo.txt

@ -1 +1 @@
{"loggingLevel": "DEBUG"}
{"loggingLevel": "ERROR", "directories": {"ASSET": null, "CUST": null, "DOB": null, "FIN": null, "output": null}}

@ -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}")

@ -1,4 +1,4 @@
[X] Working log level button
[X] Open file button
[X] Error Dialog
[ ] Directory memory
[X] Directory memory
Loading…
Cancel
Save