[hdf-compass] 20/295: Initial file wildcard support

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun May 8 10:35:21 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/master
in repository hdf-compass.

commit 54ded8fdf3b4ce28d3b1f0f6990495785ae8bc72
Author: Andrew Collette <andrew.collette at gmail.com>
Date:   Mon Jul 21 08:45:21 2014 -0600

    Initial file wildcard support
---
 compass_model/__init__.py |   5 +++++
 compass_viewer/frame.py   |  16 +++++++++++++++-
 docs/.DS_Store            | Bin 12292 -> 6148 bytes
 docs/index.rst            |   6 ++++++
 hdf5_model/__init__.py    |   2 ++
 5 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/compass_model/__init__.py b/compass_model/__init__.py
index 7b9e8ab..84ee92c 100644
--- a/compass_model/__init__.py
+++ b/compass_model/__init__.py
@@ -134,6 +134,11 @@ class Store(object):
     # -------------------------------------------------------------------------
 
 
+    # For plugins which support local files, this is a dictionary mapping
+    # file kinds to lists of extensions, e.g. {'HDF5 File': ['*.hdf5', '*.h5']}
+    file_extensions = {}
+    
+    
     @property
     def url(self):
         """ Identifies the file or Web resource (string).
diff --git a/compass_viewer/frame.py b/compass_viewer/frame.py
index 1cbcae0..f987379 100644
--- a/compass_viewer/frame.py
+++ b/compass_viewer/frame.py
@@ -94,8 +94,22 @@ class BaseFrame(wx.Frame):
 
     def on_file_open(self, evt):
         """ Request to open a file via the Open entry in the File menu """
+        import compass_model
+        
+        def make_filter_string(dct):
+            """ Make a wxPython dialog filter string segment from dict """
+            filter_string = []
+            for key, value in dct.iteritems():
+                s = "{name} ({pattern})|{pattern}".format(name=key, pattern="".join(value))
+                filter_string.append(s)
+            return "|".join(filter_string)
+            
+        # The wxPython wildcard string is a bunch of filter strings pasted together
+        wc_string = [s.file_extensions for s in compass_model.getstores() if len(s.file_extensions) != 0]
+        wc_string = "|".join([make_filter_string(x) for x in wc_string])
+        
         from . import open_store
-        dlg = wx.FileDialog(self, "Open Local File", style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)
+        dlg = wx.FileDialog(self, "Open Local File", wildcard=wc_string)#, style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST)
         if dlg.ShowModal() != wx.ID_OK:
             return
         path = dlg.GetPath()
diff --git a/docs/.DS_Store b/docs/.DS_Store
index 61c868c..5008ddf 100644
Binary files a/docs/.DS_Store and b/docs/.DS_Store differ
diff --git a/docs/index.rst b/docs/index.rst
index 7a61015..3ec5c0e 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -148,7 +148,13 @@ Other methods & properties
     For hierarchical formats, this would be the root container.  For scalar
     formats (FITS, for example), this could be e.g. an Array or Image instance.
 
+.. attribute:: Store.file_extensions
 
+    For plugins that support local file access, this is a dictionary mapping
+    file kinds to lists of extensions in "glob" format, e.g. 
+    ``{'HDF5 File': ['.h5', '.hdf5']}``.  This will be used to populate the
+    filter in the file-open dialog, among other things.
+    
 Nodes
 -----
 
diff --git a/hdf5_model/__init__.py b/hdf5_model/__init__.py
index 3a064fb..d637929 100644
--- a/hdf5_model/__init__.py
+++ b/hdf5_model/__init__.py
@@ -38,6 +38,8 @@ class HDF5Store(compass_model.Store):
     Keys are the full names of objects in the file.
     """
 
+    file_extensions = {'HDF5 File': ['*.hdf5', '*.h5']}
+    
     def __contains__(self, key):
         return key in self.f
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/hdf-compass.git



More information about the debian-science-commits mailing list