Skip to content

Commit

Permalink
Replace all the wxWidget-style file format strings with Qt equivalents
Browse files Browse the repository at this point in the history
  • Loading branch information
MBartkowiakSTFC committed May 2, 2024
1 parent f963a46 commit a83659c
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AseInputFileConfigurator(InputFileConfigurator):
_default = ""
_allowed_formats = ["guess"] + [str(x) for x in all_formats.keys()]

def __init__(self, name, wildcard="All files|*", **kwargs):
def __init__(self, name, wildcard="All files (*)", **kwargs):
"""
Initializes the configurator object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def parse_unit_cell(inputs):
unit_cell = np.zeros(9)

xlo, xhi, xy = inputs[0], inputs[1], inputs[2]
ylo, yhi, yz = inputs[3], inputs[4], inputs[5]
zlo, zhi, xz = inputs[6], inputs[7], inputs[8]
ylo, yhi, xz = inputs[3], inputs[4], inputs[5]
zlo, zhi, yz = inputs[6], inputs[7], inputs[8]
# The ax component.
unit_cell[0] = xhi - xlo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(
self,
name,
variables=None,
wildcard="MDA analysis results (*.mda)|*.mda|HDF5 files (*.h5)|*.h5|All files|*",
wildcard="MDA analysis results (*.mda);;HDF5 files (*.h5);;All files (*)",
**kwargs,
):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InputFileConfigurator(IConfigurator):

_default = ""

def __init__(self, name, wildcard="All files|*", **kwargs):
def __init__(self, name, wildcard="All files (*)", **kwargs):
"""
Initializes the configurator object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MDMCTrajectoryConfigurator(IConfigurator):

_default = None

def __init__(self, name, wildcard="All files|*", **kwargs):
def __init__(self, name, wildcard="All files (*)", **kwargs):
"""
Initializes the configurator object.
Expand Down
2 changes: 1 addition & 1 deletion MDANSE/Src/MDANSE/Framework/Converters/CASTEP.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CASTEP(Converter):
settings["castep_file"] = (
"MDFileConfigurator",
{
"wildcard": "MD files (*.md)|*.md|All files|*",
"wildcard": "MD files (*.md);;All files (*)",
"default": "INPUT_FILENAME.md",
"label": "Input MD file",
},
Expand Down
6 changes: 3 additions & 3 deletions MDANSE/Src/MDANSE/Framework/Converters/CP2K.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ class CP2K(Converter):
settings["pos_file"] = (
"XYZFileConfigurator",
{
"wildcard": "XYZ files (*.xyz)|*.xyz|All files|*",
"wildcard": "XYZ files (*.xyz);;All files (*)",
"default": "INPUT_FILENAME.xyz",
"label": "Positions file (XYZ)",
},
)
settings["vel_file"] = (
"XYZFileConfigurator",
{
"wildcard": "XYZ files (*.xyz)|*.xyz|All files|*",
"wildcard": "XYZ files (*.xyz);;All files (*)",
"default": "INPUT_FILENAME.xyz",
"optional": True,
"label": "Velocity file (XYZ, optional)",
Expand All @@ -128,7 +128,7 @@ class CP2K(Converter):
settings["cell_file"] = (
"InputFileConfigurator",
{
"wildcard": "Cell files (*.cell)|*.cell|All files|*",
"wildcard": "Cell files (*.cell);;All files (*)",
"default": "INPUT_FILENAME.cell",
"label": "CP2K unit cell file (.cell)",
},
Expand Down
4 changes: 2 additions & 2 deletions MDANSE/Src/MDANSE/Framework/Converters/DCD.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ class DCD(Converter):
settings["pdb_file"] = (
"InputFileConfigurator",
{
"wildcard": "PDB files (*.pdb)|*.pdb|All files|*",
"wildcard": "PDB files (*.pdb);;All files (*)",
"default": "INPUT_FILENAME.pdb",
"label": "Input PDB file",
},
)
settings["dcd_file"] = (
"InputFileConfigurator",
{
"wildcard": "DCD files (*.dcd)|*.dcd|All files|*",
"wildcard": "DCD files (*.dcd);;All files (*)",
"default": "INPUT_FILENAME.dcd",
"label": "Input DCD file",
},
Expand Down
4 changes: 2 additions & 2 deletions MDANSE/Src/MDANSE/Framework/Converters/DFTB.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class DFTB(Forcite):
settings["xtd_file"] = (
"XTDFileConfigurator",
{
"wildcard": "XTD files (*.xtd)|*.xtd|All files|*",
"wildcard": "XTD files (*.xtd);;All files (*)",
"default": "INPUT_FILENAME.xtd",
"label": "The XTD file",
},
)
settings["trj_file"] = (
"InputFileConfigurator",
{
"wildcard": "TRJ files (*.trj)|*.trj|All files|*",
"wildcard": "TRJ files (*.trj);;All files (*)",
"default": "INPUT_FILENAME.trj",
"label": "The TRJ file",
},
Expand Down
4 changes: 2 additions & 2 deletions MDANSE/Src/MDANSE/Framework/Converters/DL_POLY.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ class DL_POLY(Converter):
settings["field_file"] = (
"FieldFileConfigurator",
{
"wildcard": "FIELD files (FIELD*)|FIELD*|All files|*",
"wildcard": "FIELD files (FIELD*);;All files (*)",
"default": "INPUT_FILENAME",
"label": "Input FIELD file",
},
)
settings["history_file"] = (
"InputFileConfigurator",
{
"wildcard": "HISTORY files (HISTORY*)|HISTORY*|All files|*",
"wildcard": "HISTORY files (HISTORY*);;All files (*)",
"default": "INPUT_FILENAME",
"label": "Input HISTORY file",
},
Expand Down
4 changes: 2 additions & 2 deletions MDANSE/Src/MDANSE/Framework/Converters/Discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ class Discover(Converter):
settings["xtd_file"] = (
"XTDFileConfigurator",
{
"wildcard": "XTD files (*.xtd)|*.xtd|All files|*",
"wildcard": "XTD files (*.xtd);;All files (*)",
"default": "INPUT_FILENAME.xtd",
"label": "Input XTD file",
},
)
settings["his_file"] = (
"InputFileConfigurator",
{
"wildcard": "HIS files (*.his)|*.his|All files|*",
"wildcard": "HIS files (*.his);;All files (*)",
"default": "INPUT_FILENAME.his",
"label": "Input HIS file",
},
Expand Down
4 changes: 2 additions & 2 deletions MDANSE/Src/MDANSE/Framework/Converters/Forcite.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,15 @@ class Forcite(Converter):
settings["xtd_file"] = (
"XTDFileConfigurator",
{
"wildcard": "XTD files (*.xtd)|*.xtd|All files|*",
"wildcard": "XTD files (*.xtd);;All files (*)",
"default": "INPUT_FILENAME.xtd",
"label": "Input XTD file",
},
)
settings["trj_file"] = (
"InputFileConfigurator",
{
"wildcard": "TRJ files (*.trj)|*.trj|All files|*",
"wildcard": "TRJ files (*.trj);;All files (*)",
"default": "INPUT_FILENAME.trj",
"label": "Input TRJ file",
},
Expand Down
4 changes: 2 additions & 2 deletions MDANSE/Src/MDANSE/Framework/Converters/Gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ class Gromacs(Converter):
settings["pdb_file"] = (
"InputFileConfigurator",
{
"wildcard": "PDB files (*.pdb)|*.pdb|All files|*",
"wildcard": "PDB files (*.pdb);;All files (*)",
"default": "INPUT_FILENAME.pdb",
"label": "Input PDB file",
},
)
settings["xtc_file"] = (
"InputFileConfigurator",
{
"wildcard": "XTC files (*.xtc)|*.xtc|TRR files (*.trr)|*.trr|All files|*",
"wildcard": "XTC files (*.xtc);;TRR files (*.trr);;All files (*)",
"default": "INPUT_FILENAME.xtc",
"label": "xtc or trr file",
},
Expand Down
4 changes: 2 additions & 2 deletions MDANSE/Src/MDANSE/Framework/Converters/LAMMPS.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,15 +647,15 @@ class LAMMPS(Converter):
"ConfigFileConfigurator",
{
"label": "LAMMPS configuration file",
"wildcard": "Config files (*.config)|*.config|All files|*",
"wildcard": "All files (*);;Config files (*.config)",
"default": "INPUT_FILENAME.config",
},
)
settings["trajectory_file"] = (
"InputFileConfigurator",
{
"label": "LAMMPS trajectory file",
"wildcard": "lammps files (*.lammps)|*.lammps|All files|*",
"wildcard": "All files (*);;XYZ files (*.xyz);;H5MD files (*.h5);;lammps files (*.lammps)",
"default": "INPUT_FILENAME.lammps",
},
)
Expand Down
2 changes: 1 addition & 1 deletion MDANSE/Src/MDANSE/Framework/Converters/VASP.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class VASP(Converter):
settings["xdatcar_file"] = (
"XDATCARFileConfigurator",
{
"wildcard": "XDATCAR files (XDATCAR*)|XDATCAR*|All files|*",
"wildcard": "XDATCAR files (XDATCAR*);;All files (*)",
"default": "INPUT_FILENAME",
"label": "Input XDATCAR file",
},
Expand Down
4 changes: 1 addition & 3 deletions MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/AseInputFileWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
)

from MDANSE_GUI.InputWidgets.WidgetBase import WidgetBase
from MDANSE_GUI.Widgets.GeneralWidgets import translate_file_associations


class AseInputFileWidget(WidgetBase):
Expand All @@ -48,8 +47,7 @@ def __init__(self, *args, **kwargs):
tooltip_text = self._tooltip
else:
tooltip_text = "Specify a path to an existing file."
file_association = kwargs.get("wildcard", "")
self._qt_file_association = translate_file_associations(file_association)
self._qt_file_association = kwargs.get("wildcard", "")
combo = QComboBox(self._base)
combo.addItems(AseInputFileConfigurator._allowed_formats)
combo.setEditable(False)
Expand Down
3 changes: 1 addition & 2 deletions MDANSE_GUI/Src/MDANSE_GUI/InputWidgets/InputFileWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from qtpy.QtCore import Slot

from MDANSE_GUI.InputWidgets.WidgetBase import WidgetBase
from MDANSE_GUI.Widgets.GeneralWidgets import translate_file_associations


class InputFileWidget(WidgetBase):
Expand Down Expand Up @@ -55,7 +54,7 @@ def __init__(self, *args, **kwargs):
file_association = configurator.wildcard
except AttributeError:
file_association = kwargs.get("wildcard", "")
self._qt_file_association = translate_file_associations(file_association)
self._qt_file_association = file_association
field = QLineEdit(self._base)
self._field = field
field.textChanged.connect(self.updateValue)
Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/Plotter/widgets/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def on_close_plot(self, index):

def on_open_file(self):
"""Callback called when a file is opened."""
extensions = " ".join([f"*{k}" for k in DATA_ITEMS.keys()])
extensions = ";;".join([f"*{k}" for k in DATA_ITEMS.keys()])
filter_mask = f"Data files {extensions}"
filenames, _ = QtWidgets.QFileDialog.getOpenFileNames(
self, "Open Data File(s)", "", filter_mask
Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/TabbedWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def loadTrajectory(self):
self,
"Load an MD trajectory",
self.workdir,
"MDT files (*.mdt);;HDF5 files (*.h5 *.hdf);;All files(*.*)",
"MDT files (*.mdt);;HDF5 files (*.h5 *.hdf);;All files (*)",
)
ic(fname)
if len(fname[0]) > 0:
Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/Tabs/TrajectoryTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def load_trajectories(self):
self._core,
"Load an MD trajectory",
self._session.get_path("root_directory"),
"MDANSE trajectory files (*.mdt);;HDF5 files (*.h5);;HDF5 files(*.hdf);;All files(*.*)",
"MDANSE trajectory files (*.mdt);;HDF5 files (*.h5);;HDF5 files(*.hdf);;All files (*)",
)
for fname in fnames[0]:
self.load_trajectory(fname)
Expand Down
24 changes: 2 additions & 22 deletions MDANSE_GUI/Src/MDANSE_GUI/Widgets/GeneralWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,24 +234,6 @@ def returnValue(self):
return result


def translate_file_associations(input_str: str):
"""Takes the string describing valid file formats, as specified for
wxWidgets in the MDANSE framework, and converts it to an equivalent
string for Qt.
Arguments:
input_str -- string specifying the file formats for the FileDialog,
in the text format from wxWidgets
Returns:
String of the valid file formats in the FileDialog, in the format
valid for Qt.
"""
toks = input_str.split("|")[::2]
basic_replacement = ";;".join(toks[:-1] + ["All files (*.*)"])
return basic_replacement


class InputFactory:
"""Factory generating input fields for Dialogs. It is meant to standardise
the way inputs are hanlded, so that any kind of variable can be processed
Expand Down Expand Up @@ -350,8 +332,7 @@ def createFile(*args, direction="in", **kwargs):
kind = kwargs.get("kind", "String")
default_value = kwargs.get("default", "")
tooltip_text = kwargs.get("tooltip", "Specify a path to an existing file.")
file_association = kwargs.get("wildcard", "")
qt_file_association = translate_file_associations(file_association)
qt_file_association = file_association = kwargs.get("wildcard", "")
ic(kind)
ic(default_value)
ic(tooltip_text)
Expand Down Expand Up @@ -388,8 +369,7 @@ def createTrajectory(*args, direction="out", **kwargs):
tooltip_text = kwargs.get(
"tooltip", "Specify the name of the output trajectory."
)
file_association = kwargs.get("wildcard", "")
qt_file_association = translate_file_associations(file_association)
qt_file_association = kwargs.get("wildcard", "")
base, layout = InputFactory.createBase(*args, **kwargs)
field = QLineEdit(base)
main_handler = InputGroup(base)
Expand Down

0 comments on commit a83659c

Please sign in to comment.