Skip to content

Commit 65af121

Browse files
committed
show_open_file_dialog() now actually allows restriction to particular formats
1 parent 9447218 commit 65af121

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/bundles/open_command/bundle_info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<BundleInfo name="ChimeraX-OpenCommand" version="1.14" package="chimerax.open_command"
1+
<BundleInfo name="ChimeraX-OpenCommand" version="1.14.1" package="chimerax.open_command"
22
minSessionVersion="1" maxSessionVersion="1">
33

44
<!-- Additional information about bundle source -->

src/bundles/open_command/src/dialog.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,14 @@ def set_use_native_open_file_dialog(use):
273273
global _use_native_open_file_dialog
274274
_use_native_open_file_dialog = use
275275

276-
def make_qt_name_filters(session, *, no_filter="All files (*)"):
276+
def make_qt_name_filters(session, *, no_filter="All files (*)", format_names=None):
277277
openable_formats = [fmt for fmt in session.open_command.open_data_formats if fmt.suffixes]
278+
if format_names is not None:
279+
openable_formats = [fmt for fmt in openable_formats if fmt.name in format_names]
278280
openable_formats.sort(key=lambda fmt: fmt.synopsis.casefold())
279281
file_filters = ["%s (%s)" % (fmt.synopsis, "*" + " *".join(fmt.suffixes))
280282
for fmt in openable_formats]
281-
if no_filter is not None:
283+
if no_filter is not None and format_names is None:
282284
file_filters = [no_filter] + file_filters
283285
return file_filters, openable_formats, no_filter
284286

@@ -293,13 +295,16 @@ def show_fetch_by_id_dialog(session, database_name=None, *, debug=False):
293295
_fetch_by_id_dialog.show()
294296
_fetch_by_id_dialog.raise_()
295297

296-
def show_open_file_dialog(session, initial_directory=None, format_name=None):
298+
def show_open_file_dialog(session, initial_directory=None, format_names=None):
297299
if initial_directory is None:
298300
initial_directory = ''
299-
file_filters, openable_formats, no_filter = make_qt_name_filters(session)
301+
file_filters, openable_formats, no_filter = make_qt_name_filters(session, format_names=format_names)
300302
fmt_name2filter = dict(zip([fmt.name for fmt in openable_formats], file_filters[1:]))
301-
filter2fmt = dict(zip(file_filters[1:], openable_formats))
302-
filter2fmt[no_filter] = None
303+
if format_names is None:
304+
filter2fmt = dict(zip(file_filters[1:], openable_formats))
305+
filter2fmt[no_filter] = None
306+
else:
307+
filter2fmt = dict(zip(file_filters, openable_formats))
303308
from Qt.QtWidgets import QFileDialog
304309
qt_filter = ";;".join(file_filters)
305310
if _use_native_open_file_dialog:

0 commit comments

Comments
 (0)