Skip to content

Commit

Permalink
MTN comment out directory argument
Browse files Browse the repository at this point in the history
  • Loading branch information
rodolakis committed Jun 12, 2024
1 parent 2c34c66 commit 3768e68
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
58 changes: 28 additions & 30 deletions mdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,26 @@
"""

import logging
import pathlib
import sys
from PyQt5 import QtWidgets
from .mainwindow import MainWindow
import argparse


def gui(directory):
def gui():
"""Display the main window"""
from PyQt5 import QtWidgets

from .mainwindow import MainWindow

app = QtWidgets.QApplication(sys.argv)
main_window = MainWindow(directory=directory)
main_window = MainWindow()
main_window.setStatus(
f"Application started, loading {pathlib.Path(directory).absolute()} ..."
f"Application started ..."
)
main_window.show()
sys.exit(app.exec())


def command_line_interface():
import argparse


from . import __version__

Expand All @@ -50,41 +49,40 @@ def command_line_interface():
)
# fmt: on

parser.add_argument(
"directory",
help=("Directory loaded at start up. This argument is required."),
type=str,
)
# parser.add_argument(
# "directory",
# help=("Directory loaded at start up. This argument is required."),
# type=str,
# )

parser.add_argument("-v", "--version", action="version", version=__version__)

return parser.parse_args()


def main(): # for future command-line options
from pathlib import Path

global logger

options = command_line_interface()

# Resolve the directory to an absolute path and remove trailing slash
directory_path = Path(options.directory).resolve()
directory = directory_path.as_posix().rstrip("/")
# # Resolve the directory to an absolute path and remove trailing slash
# directory_path = Path(options.directory).resolve()
# directory = directory_path.as_posix().rstrip("/")

# Ensure the path is absolute (starts with a "/")
if not directory.startswith("/"):
print(
f"\n\nERROR: The specified directory is not an absolute path:\n\t{directory}\n"
)
sys.exit(1)
# # Ensure the path is absolute (starts with a "/")
# if not directory.startswith("/"):
# print(
# f"\n\nERROR: The specified directory is not an absolute path:\n\t{directory}\n"
# )
# sys.exit(1)

# Check if the directory exists
if not directory_path.exists() or not directory_path.is_dir():
print(
f"\n\nERROR: The specified directory does not exist or is not a directory:\n\t{directory}\n"
)
sys.exit(1)
# # Check if the directory exists
# if not directory_path.exists() or not directory_path.is_dir():
# print(
# f"\n\nERROR: The specified directory does not exist or is not a directory:\n\t{directory}\n"
# )
# sys.exit(1)

logging.basicConfig(level=options.log.upper())
logger = logging.getLogger(__name__)
Expand All @@ -94,7 +92,7 @@ def main(): # for future command-line options
for package in "httpcore httpx PyQt5 tiled".split():
logging.getLogger(package).setLevel(logging.WARNING)

gui(directory)
gui()


if __name__ == "__main__":
Expand Down
14 changes: 8 additions & 6 deletions mdaviz/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,19 @@ class MainWindow(QtWidgets.QMainWindow):
~_updateRecentFolders
"""

def __init__(self, directory):
def __init__(self):
super().__init__()
utils.myLoadUi(UI_FILE, baseinstance=self)
self.setWindowTitle(APP_TITLE)

self.directory = directory
# self.directory = directory
self.mvc_folder = None
self.setDataPath() # the combined data path obj
self.setFolderList() # the list of recent folders in folder QCombobox
self.setMdaFileList() # the list of mda file NAME str (name only)
self.setMdaInfoList() # the list of mda file Info (all the data necessary to fill the table view)

self.connect()
self.onFolderSelected(directory)

settings.restoreWindowGeometry(self, "mainwindow_geometry")
print("Settings are saved in:", settings.fileName())
Expand Down Expand Up @@ -186,7 +185,9 @@ def setFolderList(self, folder_list=None):

def onFolderSelected(self, folder_name):
"""A folder was selected (from the open dialog or pull down menu)."""
if folder_name == "Open...":
if folder_name == Path("."):
print("FUCK")
elif folder_name == "Open...":
self.doOpen()
elif folder_name == "Clear Recently Open...":
settings.setKey(DIR_SETTINGS_KEY, "")
Expand All @@ -195,7 +196,8 @@ def onFolderSelected(self, folder_name):
else:
folder_path = Path(folder_name)
if folder_path.exists() and folder_path.is_dir(): # folder exists
n_files = len([*folder_path.iterdir()])
n_files = len([folder_path.iterdir()])
print(f"{folder_path=}")
answer = True
if n_files > MAX_FILES:
answer = self.doPopUp(
Expand Down Expand Up @@ -270,7 +272,7 @@ def _buildFolderList(self, folder_list=None):
list: list of folders to be populated in the QComboBox
"""
unique_paths = set()
candidate_paths = [self.directory]
candidate_paths = [""]
if not folder_list:
recent_dirs = self._getRecentFolders()
if recent_dirs:
Expand Down

0 comments on commit 3768e68

Please sign in to comment.