[hdf-compass] 161/295: Fix __init__.py for compass_viewer package

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun May 8 10:35:39 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 40052cbe9bdd8fbe995e4723809e23f17910db50
Author: giumas <giumas at yahoo.it>
Date:   Tue Oct 20 16:10:24 2015 +0200

    Fix __init__.py for compass_viewer package
---
 hdf_compass/compass_viewer/__init__.py             | 222 +-----------
 hdf_compass/compass_viewer/array/__init__.py       | 396 +--------------------
 .../compass_viewer/array/{__init__.py => frame.py} |   7 +-
 hdf_compass/compass_viewer/container/__init__.py   | 191 +---------
 .../container/{__init__.py => frame.py}            |  10 +-
 hdf_compass/compass_viewer/image/__init__.py       |  53 +--
 .../compass_viewer/image/{__init__.py => frame.py} |   2 +-
 hdf_compass/compass_viewer/keyvalue/__init__.py    |  86 +----
 .../keyvalue/{__init__.py => frame.py}             |   0
 .../compass_viewer/{__init__.py => viewer.py}      |  13 +-
 10 files changed, 24 insertions(+), 956 deletions(-)

diff --git a/hdf_compass/compass_viewer/__init__.py b/hdf_compass/compass_viewer/__init__.py
index 436ec64..bd720f9 100644
--- a/hdf_compass/compass_viewer/__init__.py
+++ b/hdf_compass/compass_viewer/__init__.py
@@ -9,230 +9,10 @@
 # distribution tree.  If you do not have access to this file, you may        #
 # request a copy from help at hdfgroup.org.                                     #
 ##############################################################################
-
-"""
-Main module for HDFCompass.
-
-Defines the App class, along with supporting infrastructure.
-"""
 from __future__ import absolute_import, division, print_function, unicode_literals
 
-# Must be at the top, to ensure we're the first to call matplotlib.use.
-import matplotlib
-matplotlib.use('WXAgg')
-
-import wx
+from .viewer import run, can_open_store, open_store, CompassApp
 
 import logging
 log = logging.getLogger(__name__)
 log.addHandler(logging.NullHandler())
-
-from hdf_compass import compass_model
-from hdf_compass import utils
-
-from .events import ID_COMPASS_OPEN
-from . import container, array, keyvalue, image, frame, text
-
-__version__ = utils.__version__
-
-
-class CompassImageList(wx.ImageList):
-
-    """
-    A specialized type of image list, to support icons from Node subclasses.
-
-    Instances of this class hold only square icons, of the size specified
-    when created.  The appropriate icon index for a particular Node subclass is
-    retrieved using get_index(nodeclass).
-
-    Image addition and indexing is completely bootstrapped; there's no need
-    to manually add or register Node classes with this class.  Just call
-    get_index and the object will figure it out.
-    """
-
-    def __init__(self, size):
-        """ Create a new list holding square icons of the given size. """
-        wx.ImageList.__init__(self, size, size)
-        self._indices = {}
-        self._size = size
-
-    def get_index(self, node_class):
-        """ Retrieve an index appropriate for the given Node subclass. """
-
-        if node_class not in self._indices:
-            png = wx.Bitmap(node_class.icons[self._size], wx.BITMAP_TYPE_ANY)
-            idx = self.Add(png)
-            self._indices[node_class] = idx
-
-        return self._indices[node_class]
-
-
-class CompassApp(wx.App):
-
-    """
-    The main application object for HDFCompass.
-
-    This mainly handles ID_COMPASS_OPEN events, which are requests to launch
-    a new window viewing a particular node.  Also contains a dict of
-    CompassImageLists, indexed by image width.
-    """
-
-    def __init__(self, redirect):
-        """ Constructor.  If *redirect*, show a windows with console output.
-        """
-        wx.App.__init__(self, redirect)
-
-        self.imagelists = {}
-        for size in (16, 24, 32, 48, 64):
-            self.imagelists[size] = CompassImageList(size)
-
-        self.Bind(wx.EVT_MENU, self.on_compass_open, id=ID_COMPASS_OPEN)
-
-        self.SetAppName("HDFCompass")
-
-    def on_compass_open(self, evt):
-        """ A request has been made to open a node from somewhere in the GUI
-        """
-        open_node(evt.node, evt.kwds.get('pos'))
-
-    def MacOpenFile(self, filename):
-        """ A file has been dropped onto the app icon """
-        url = 'file://' + filename
-        open_store(url)
-
-
-def open_node(node, pos=None):
-    """ Open a viewer frame appropriate for the given Node instance.
-    
-    node:   Node instance to open
-    pos:    2-tuple with current window position (used to avoid overlap).
-    """
-    
-    if pos is not None:
-        # The thing we get from GetPosition isn't really a tuple, so
-        # you have to manually cast entries to int or it silently fails.
-        new_pos =(int(pos[0])+40, int(pos[1])+40)
-    else:
-        new_pos = None
-
-    log.debug("Top-level open called for %s" % node)
-
-    if isinstance(node, compass_model.Container):
-        f = container.ContainerFrame(node, pos=new_pos)
-        f.Show()
-
-    elif isinstance(node, compass_model.Array):
-        f = array.ArrayFrame(node, pos=new_pos)
-        f.Show()
-
-    elif isinstance(node, compass_model.Xml):
-        f = text.XmlFrame(node, pos=new_pos)
-        f.Show()
-
-    elif isinstance(node, compass_model.Text):
-        f = text.TextFrame(node, pos=new_pos)
-        f.Show()
-
-    elif isinstance(node, compass_model.KeyValue):
-        f = keyvalue.KeyValueFrame(node, pos=new_pos)
-        f.Show()
-
-    elif isinstance(node, compass_model.Image):
-        f = image.ImageFrame(node, pos=pos)
-        f.Show()
-    else:
-        pass
-
-        
-def open_store(url):
-    """ Open the url using the first matching registered Store class.
-
-    Returns True if the url was successfully opened, False otherwise.
-    """
-    stores = [x for x in compass_model.get_stores() if x.can_handle(url)]
-
-    if len(stores) > 0:
-        instance = stores[0](url)
-        open_node(instance.root)
-        return True
-
-    return False
-
-
-def can_open_store(url):
-    """ checks url for first matching registered Store class.
-
-    Returns True if the url can be successfully opened, False otherwise.
-    """
-    stores = [x for x in compass_model.get_stores() if x.can_handle(url)]
-
-    if len(stores) > 0:
-        instance = stores[0](url)
-        return True
-
-    return False
-
-
-def load_plugins():
-    """ Helper function that attempts to load all the plugins """
-
-    from hdf_compass import compass_model
-
-    try:
-        from hdf_compass import filesystem_model
-    except ImportError:
-        log.info("Filesystem plugin not loaded")
-
-    try:
-        from hdf_compass import array_model
-    except ImportError:
-        log.info("Array plugin not loaded")
-
-    try:
-        from hdf_compass import hdf5_model
-    except ImportError:
-        log.info("HDF plugin not loaded")
-
-    try:
-        from hdf_compass import bag_model
-    except ImportError:
-        log.info("BAG plugin not loaded")
-
-    try:
-        from hdf_compass import asc_model
-    except ImportError:
-        log.info("Ascii grid plugin not loaded")
-
-    try:
-        from hdf_compass import opendap_model
-    except ImportError:
-        log.info("Opendap plugin not loaded")
-
-
-def run():
-    """ Run HDFCompass.  Handles all command-line arguments, etc. """
-
-    import sys
-    import os.path as op
-
-    app = CompassApp(False)
-
-    load_plugins()
-
-    urls = sys.argv[1:]
-    
-    for url in urls:
-        if "://" not in url:
-            # assumed to be file path
-            url = utils.path2url(op.abspath(url))
-        if not open_store(url):
-            log.warning('Failed to open "%s"; no handlers' % url)
-
-    f = frame.InitFrame()
-    
-    if utils.is_darwin:
-        wx.MenuBar.MacSetCommonMenuBar(f.GetMenuBar())
-    else:
-        f.Show()
-        
-    app.MainLoop()
diff --git a/hdf_compass/compass_viewer/array/__init__.py b/hdf_compass/compass_viewer/array/__init__.py
index e577eab..cf400ae 100644
--- a/hdf_compass/compass_viewer/array/__init__.py
+++ b/hdf_compass/compass_viewer/array/__init__.py
@@ -9,402 +9,10 @@
 # distribution tree.  If you do not have access to this file, you may        #
 # request a copy from help at hdfgroup.org.                                     #
 ##############################################################################
-"""
-Implements a viewer frame for compass_model.Array.
-"""
 from __future__ import absolute_import, division, print_function, unicode_literals
 
-import wx
-import wx.grid
-from wx.lib.newevent import NewCommandEvent
+from .frame import ArrayFrame
 
-import os
 import logging
 log = logging.getLogger(__name__)
-
-from ..frame import NodeFrame
-from .plot import LinePlotFrame, ContourPlotFrame
-
-
-# Indicates that the slicing selection may have changed.
-# These events are emitted by the SlicerPanel.
-ArraySlicedEvent, EVT_ARRAY_SLICED = NewCommandEvent()
-
-# Menu and button IDs
-ID_VIS_MENU_PLOT = wx.NewId()
-
-
-class ArrayFrame(NodeFrame):
-    """
-    Top-level frame displaying objects of type compass_model.Array.
-
-    From top to bottom, has:
-
-    1. Toolbar (see ArrayFrame.init_toolbar)
-    2. SlicerPanel, with controls for changing what's displayed.
-    3. An ArrayGrid, which displays the data in a spreadsheet-like view.
-    """
-
-    def __init__(self, node, pos=None):
-        """ Create a new array viewer, to display *node*. """
-        NodeFrame.__init__(self, node, size=(800, 400), title=node.display_name, pos=pos)
-
-        self.node = node
-
-        # The Slicer is the panel with indexing controls
-        self.slicer = SlicerPanel(self, node.shape, node.dtype.fields is not None)
-        self.grid = ArrayGrid(self, node, self.slicer)
-
-        vis_menu = wx.Menu()
-        vis_menu.Append(ID_VIS_MENU_PLOT, "Plot Data\tCtrl-D")
-        self.add_menu(vis_menu, "Visualize")
-
-        self.init_toolbar()
-
-        gridsizer = wx.BoxSizer(wx.VERTICAL)
-        gridsizer.Add(self.slicer, 0, wx.EXPAND)
-        gridsizer.Add(self.grid, 1, wx.EXPAND)
-
-        self.view = gridsizer
-
-        self.Bind(EVT_ARRAY_SLICED, self.on_sliced)
-        self.Bind(wx.EVT_MENU, self.on_plot, id=ID_VIS_MENU_PLOT)
-
-        # Workaround for wxPython bug (see SlicerPanel.enable_spinctrls)
-        ID_WORKAROUND_TIMER = wx.NewId()
-        self.Bind(wx.EVT_TIMER, self.on_workaround_timer, id=ID_WORKAROUND_TIMER)
-        self.timer = wx.Timer(self, ID_WORKAROUND_TIMER)
-        self.timer.Start(100)
-
-    def on_workaround_timer(self, evt):
-        """ See slicer.enable_spinctrls docs """
-        self.timer.Destroy()
-        self.slicer.enable_spinctrls()
-
-    def init_toolbar(self):
-        """ Set up the toolbar at the top of the window. """
-        tsize = (24, 24)
-        plot_bmp = wx.Bitmap(os.path.join(self.icon_folder, "viz_plot_24.png"), wx.BITMAP_TYPE_ANY)
-
-        self.toolbar = self.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT | wx.TB_TEXT)
-
-        self.toolbar.SetToolBitmapSize(tsize)
-        self.toolbar.AddStretchableSpace()
-        self.toolbar.AddLabelTool(ID_VIS_MENU_PLOT, "Plot Data", plot_bmp, shortHelp="Plot data in a popup window",
-                                  longHelp="Long help for 'New'")
-        self.toolbar.Realize()
-
-    def on_sliced(self, evt):
-        """ User has chosen to display a different part of the dataset. """
-        self.grid.Refresh()
-
-    def on_plot(self, evt):
-        """ User has chosen to plot the current selection """
-        cols = self.grid.GetSelectedCols()
-        rows = self.grid.GetSelectedRows()
-
-        # Scalar data can't be line-plotted.
-        if len(self.node.shape) == 0:
-            return
-
-        # Columns in the view are selected
-        if len(cols) != 0:
-
-            # The data is compound
-            if self.node.dtype.names is not None:
-                names = [self.grid.GetColLabelValue(x) for x in cols]
-                data = self.node[self.slicer.indices]  # -> 1D compound array
-                data = [data[n] for n in names]
-                f = LinePlotFrame(data, names)
-                f.Show()
-
-            # Plot multiple columns independently
-            else:
-                if len(self.node.shape) == 1:
-                    data = [self.node[self.slicer.indices]]
-                else:
-                    data = [self.node[self.slicer.indices + (c,)] for c in cols]
-
-                names = ["Col %d" % c for c in cols] if len(data) > 1 else None
-
-                f = LinePlotFrame(data, names)
-                f.Show()
-
-
-        # Rows in view are selected
-        elif len(rows) != 0:
-
-            data = [self.node[self.slicer.indices + (slice(None, None, None), r)] for r in rows]
-            names = ["Row %d" % r for r in rows] if len(data) > 1 else None
-
-            f = LinePlotFrame(data, names)
-            f.Show()
-
-
-        # No row or column selection.  Plot everything
-        else:
-
-            data = self.node[self.slicer.indices]
-
-            # The data is compound
-            if self.node.dtype.names is not None:
-                names = [self.grid.GetColLabelValue(x) for x in xrange(self.grid.GetNumberCols())]
-                data = [data[n] for n in names]
-                f = LinePlotFrame(data, names)
-                f.Show()
-
-            # Plot 1D
-            elif len(self.node.shape) == 1:
-                f = LinePlotFrame([data])
-                f.Show()
-
-            # Plot 2D
-            else:
-                f = ContourPlotFrame(data)
-                f.Show()
-
-
-class SlicerPanel(wx.Panel):
-    """
-    Holds controls for data access.
-
-    Consult the "indices" property, which returns a tuple of indices that
-    prefix the array.  This will be RANK-2 elements long, unless hasfields
-    is true, in which case it will be RANK-1 elements long.
-    """
-
-    @property
-    def indices(self):
-        """ A tuple of integer indices appropriate for slicing.
-
-        Will be RANK-2 elements long, RANK-1 if compound data is in use
-        (hasfields == True).
-        """
-        return tuple([x.GetValue() for x in self.spincontrols])
-
-    def __init__(self, parent, shape, hasfields):
-        """ Create a new slicer panel.
-
-        parent:     The wxPython parent window
-        shape:      Shape of the data to visualize
-        hasfields:  If True, the data is compound and the grid can only
-                    display one axis.  So, we should display an extra spinbox.
-        """
-        wx.Panel.__init__(self, parent)
-
-        self.shape = shape
-        self.hasfields = hasfields
-        self.spincontrols = []
-
-        # Rank of the underlying array
-        rank = len(shape)
-
-        # Rank displayable in the grid.  If fields are present, they occupy
-        # the columns, so the data displayed is actually 1-D.
-        visible_rank = 1 if hasfields else 2
-
-        sizer = wx.BoxSizer(wx.HORIZONTAL)  # Will arrange the SpinCtrls
-
-        if rank > visible_rank:
-            infotext = wx.StaticText(self, wx.ID_ANY, "Array Indexing: ")
-            sizer.Add(infotext, 0, flag=wx.EXPAND | wx.ALL, border=10)
-
-            for idx in xrange(rank - visible_rank):
-                sc = wx.SpinCtrl(self, max=shape[idx] - 1, value="0", min=0)
-                sizer.Add(sc, 0, flag=wx.EXPAND | wx.ALL, border=10)
-                sc.Disable()
-                self.spincontrols.append(sc)
-
-        self.SetSizer(sizer)
-
-        self.Bind(wx.EVT_SPINCTRL, self.on_spin)
-
-    def enable_spinctrls(self):
-        """ Unlock the spin controls.
-
-        Because of a bug in wxPython on Mac, by default the first spin control
-        has bizarre contents (and control focus) when the panel starts up.
-        Call this after a short delay (e.g. 100 ms) to enable indexing.
-        """
-        for sc in self.spincontrols:
-            sc.Enable()
-
-    def on_spin(self, evt):
-        """ Spinbox value changed; notify parent to refresh the grid. """
-        wx.PostEvent(self, ArraySlicedEvent(self.GetId()))
-
-
-class ArrayGrid(wx.grid.Grid):
-    """
-    Grid class to display the Array.
-    
-    Cell contents and appearance are handled by the table model in ArrayTable.
-    """
-
-    def __init__(self, parent, node, slicer):
-        wx.grid.Grid.__init__(self, parent)
-        table = ArrayTable(node, slicer)
-        self.SetTable(table, True)
-
-        # Column selection is always allowed
-        selmode = wx.grid.Grid.wxGridSelectColumns
-
-        # Row selection is forbidden for compound types, and for
-        # scalar/1-D datasets
-        if node.dtype.names is None and len(node.shape) > 1:
-            selmode |= wx.grid.Grid.wxGridSelectRows
-
-        self.SetSelectionMode(selmode)
-
-
-class LRUTileCache(object):
-    """
-        Simple tile-based LRU cache which goes between the Grid and
-        the Array object.  Caches tiles along the last 1 or 2 dimensions
-        of a dataset.
-        
-        Access is via __getitem__.  Because this class exists specifically
-        to support point-based callbacks for the Grid, arguments may
-        only be indices, not slices.
-    """
-
-    TILESIZE = 100  # Tiles will have shape (100,) or (100, 100)
-    MAXTILES = 50  # Max number of tiles to retain in the cache
-
-    def __init__(self, arr):
-        """ *arr* is anything implementing compass_model.Array """
-        import collections
-        self.cache = collections.OrderedDict()
-        self.arr = arr
-
-    def __getitem__(self, args):
-        """ Restricted to an index or tuple of indices. """
-
-        if not isinstance(args, tuple):
-            args = (args,)
-
-        # Split off the last 1 or 2 dimensions
-        coarse_position, fine_position = args[0:-2], args[-2:]
-
-        def clip(x):
-            """ Round down to nearest TILESIZE; takes e.g. 181 -> 100 """
-            return (x // self.TILESIZE) * self.TILESIZE
-
-        # Tuple with index of tile corner
-        tile_key = coarse_position + tuple(clip(x) for x in fine_position)
-
-        # Slice which will be applied to dataset to retrieve tile
-        tile_slice = coarse_position + tuple(slice(clip(x), clip(x) + self.TILESIZE) for x in fine_position)
-
-        # Index applied to tile to retrieve the desired data point
-        tile_data_index = tuple(x % self.TILESIZE for x in fine_position)
-
-        # Case 1: Add tile to cache, ejecting oldest tile if needed
-        if not tile_key in self.cache:
-
-            if len(self.cache) >= self.MAXTILES:
-                self.cache.popitem(last=False)
-
-            tile = self.arr[tile_slice]
-            self.cache[tile_key] = tile
-
-        # Case 2: Mark the tile as recently accessed            
-        else:
-            tile = self.cache.pop(tile_key)
-            self.cache[tile_key] = tile
-
-        return tile[tile_data_index]
-
-
-class ArrayTable(wx.grid.PyGridTableBase):
-    """
-    "Table" class which provides data and metadata for the grid to display.
-
-    The methods defined here define the contents of the table, as well as
-    the number of rows, columns and their values.
-    """
-
-    def __init__(self, node, slicer):
-        """ Create a new Table instance for use with a grid control.
-
-        node:     An compass_model.Array implementation instance.
-        slicer:   An instance of SlicerPanel, so we can see what indices the
-                  user has requested.
-        """
-        wx.grid.PyGridTableBase.__init__(self)
-
-        self.node = node
-        self.slicer = slicer
-
-        self.rank = len(node.shape)
-        self.names = node.dtype.names
-
-        self.cache = LRUTileCache(self.node)
-
-    def GetNumberRows(self):
-        """ Callback for number of rows displayed by the grid control """
-        if self.rank == 0:
-            return 1
-        return self.node.shape[-1]
-
-    def GetNumberCols(self):
-        """ Callback for number of columns displayed by the grid control.
-
-        Note that if compound data is in use, columns display the field names.
-        """
-        if self.names is not None:
-            return len(self.names)
-        if self.rank < 2:
-            return 1
-        return self.node.shape[-2]
-
-    def GetValue(self, row, col):
-        """ Callback which provides data to the Grid.
-
-        row, col:   Integers giving row and column position (0-based).
-        """
-        # Scalar case
-        if self.rank == 0:
-            data = self.node[()]
-            if self.names is None:
-                return data
-            return data[col]
-
-        # 1D case
-        if self.rank == 1:
-            data = self.cache[row]
-            if self.names is None:
-                return data
-            return data[self.names[col]]
-
-        # ND case.  Watch out for compound mode!
-        if self.names is None:
-            args = self.slicer.indices + (col, row)
-        else:
-            args = self.slicer.indices + (row,)
-
-        data = self.cache[args]
-        if self.names is None:
-            return data
-        return data[self.names[col]]
-
-    def GetRowLabelValue(self, row):
-        """ Callback for row labels.
-
-        Row number is used unless the data is scalar.
-        """
-        if self.rank == 0:
-            return "Value"
-        return str(row)
-
-    def GetColLabelValue(self, col):
-        """ Callback for column labels.
-
-        Column number is used, except for scalar or 1D data, or if we're
-        displaying field names in the columns.
-        """
-        if self.names is not None:
-            return self.names[col]
-        if self.rank == 0 or self.rank == 1:
-            return "Value"
-        return str(col)
+log.addHandler(logging.NullHandler())
\ No newline at end of file
diff --git a/hdf_compass/compass_viewer/array/__init__.py b/hdf_compass/compass_viewer/array/frame.py
similarity index 99%
copy from hdf_compass/compass_viewer/array/__init__.py
copy to hdf_compass/compass_viewer/array/frame.py
index e577eab..8e18765 100644
--- a/hdf_compass/compass_viewer/array/__init__.py
+++ b/hdf_compass/compass_viewer/array/frame.py
@@ -20,7 +20,6 @@ from wx.lib.newevent import NewCommandEvent
 
 import os
 import logging
-log = logging.getLogger(__name__)
 
 from ..frame import NodeFrame
 from .plot import LinePlotFrame, ContourPlotFrame
@@ -237,7 +236,7 @@ class SlicerPanel(wx.Panel):
 class ArrayGrid(wx.grid.Grid):
     """
     Grid class to display the Array.
-    
+
     Cell contents and appearance are handled by the table model in ArrayTable.
     """
 
@@ -262,7 +261,7 @@ class LRUTileCache(object):
         Simple tile-based LRU cache which goes between the Grid and
         the Array object.  Caches tiles along the last 1 or 2 dimensions
         of a dataset.
-        
+
         Access is via __getitem__.  Because this class exists specifically
         to support point-based callbacks for the Grid, arguments may
         only be indices, not slices.
@@ -308,7 +307,7 @@ class LRUTileCache(object):
             tile = self.arr[tile_slice]
             self.cache[tile_key] = tile
 
-        # Case 2: Mark the tile as recently accessed            
+        # Case 2: Mark the tile as recently accessed
         else:
             tile = self.cache.pop(tile_key)
             self.cache[tile_key] = tile
diff --git a/hdf_compass/compass_viewer/container/__init__.py b/hdf_compass/compass_viewer/container/__init__.py
index c4076cc..ce2da9d 100644
--- a/hdf_compass/compass_viewer/container/__init__.py
+++ b/hdf_compass/compass_viewer/container/__init__.py
@@ -9,197 +9,10 @@
 # distribution tree.  If you do not have access to this file, you may        #
 # request a copy from help at hdfgroup.org.                                     #
 ##############################################################################
-
-"""
-Implements a viewer for compass_model.Container instances.
-
-This frame is a simple browser view with back/forward/up controls.
-
-Currently list and icon views are supported.
-"""
 from __future__ import absolute_import, division, print_function, unicode_literals
 
-import wx
-import os
+from .frame import ContainerFrame
 
 import logging
 log = logging.getLogger(__name__)
-
-from hdf_compass import compass_model
-from ..frame import NodeFrame
-from ..events import ID_COMPASS_OPEN
-from ..events import EVT_CONTAINER_SELECTION
-from .list import ContainerReportList, ContainerIconList
-
-ID_GO_MENU_BACK = wx.NewId()
-ID_GO_MENU_NEXT = wx.NewId()
-ID_GO_MENU_UP = wx.NewId()
-ID_GO_MENU_TOP = wx.NewId()
-
-ID_VIEW_MENU_LIST = wx.NewId()
-ID_VIEW_MENU_ICON = wx.NewId()
-
-
-class ContainerFrame(NodeFrame):
-    """
-    A frame to display a Container class, and browse its contents.
-    """
-
-    def __init__(self, node, pos=None):
-        """ Create a new frame.
-
-        node:   Container instance to display.
-        pos:    Screen position at which to display the window.
-        """
-        NodeFrame.__init__(self, node, size=(800, 400), title=node.display_title, pos=pos)
-
-        view_menu = wx.Menu()
-        view_menu.Append(ID_VIEW_MENU_LIST, "List view")
-        view_menu.Append(ID_VIEW_MENU_ICON, "Icon view")
-        self.add_menu(view_menu, "View")
-        self.view_menu = view_menu
-
-        go_menu = wx.Menu()
-        go_menu.Append(ID_GO_MENU_BACK, "Back\tCtrl-[")
-        go_menu.Append(ID_GO_MENU_NEXT, "Next\tCtrl-]")
-        go_menu.Append(ID_GO_MENU_UP, "Up\tCtrl-Up")
-        go_menu.Append(ID_GO_MENU_TOP, "Top\tCtrl-/")
-        self.add_menu(go_menu, "Go")
-        self.go_menu = go_menu
-
-        self.Bind(wx.EVT_MENU, self.on_open, id=ID_COMPASS_OPEN)
-        self.Bind(EVT_CONTAINER_SELECTION, lambda evt: self.update_info())
-
-        self.Bind(wx.EVT_MENU, lambda evt: self.go_back(), id=ID_GO_MENU_BACK)
-        self.Bind(wx.EVT_MENU, lambda evt: self.go_next(), id=ID_GO_MENU_NEXT)
-        self.Bind(wx.EVT_MENU, lambda evt: self.go_up(), id=ID_GO_MENU_UP)
-        self.Bind(wx.EVT_MENU, lambda evt: self.go_top(), id=ID_GO_MENU_TOP)
-        self.Bind(wx.EVT_MENU, lambda evt: self.list_view(), id=ID_VIEW_MENU_LIST)
-        self.Bind(wx.EVT_MENU, lambda evt: self.icon_view(), id=ID_VIEW_MENU_ICON)
-
-        self.toolbar = self.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT | wx.TB_TEXT)
-
-        tsize = (24, 24)
-        back_bmp = wx.Bitmap(os.path.join(self.icon_folder, "go_back_24.png"), wx.BITMAP_TYPE_ANY)
-        next_bmp = wx.Bitmap(os.path.join(self.icon_folder, "go_next_24.png"), wx.BITMAP_TYPE_ANY)
-        up_bmp = wx.Bitmap(os.path.join(self.icon_folder, "go_up_24.png"), wx.BITMAP_TYPE_ANY)
-        top_bmp = wx.Bitmap(os.path.join(self.icon_folder, "go_top_24.png"), wx.BITMAP_TYPE_ANY)
-        icon_bmp = wx.Bitmap(os.path.join(self.icon_folder, "view_icon_24.png"), wx.BITMAP_TYPE_ANY)
-        list_bmp = wx.Bitmap(os.path.join(self.icon_folder, "view_list_24.png"), wx.BITMAP_TYPE_ANY)
-
-        self.toolbar.SetToolBitmapSize(tsize)
-        self.toolbar.AddLabelTool(ID_GO_MENU_BACK, "Back", back_bmp, shortHelp="New", longHelp="Long help for 'New'")
-        self.toolbar.AddLabelTool(ID_GO_MENU_NEXT, "Next", next_bmp, shortHelp="New", longHelp="Long help for 'New'")
-        self.toolbar.AddSeparator()
-        self.toolbar.AddLabelTool(ID_GO_MENU_UP, "Up", up_bmp, shortHelp="New", longHelp="Long help for 'New'")
-        self.toolbar.AddLabelTool(ID_GO_MENU_TOP, "Top", top_bmp, shortHelp="New", longHelp="Long help for 'New'")
-        self.toolbar.AddStretchableSpace()
-        self.toolbar.AddLabelTool(ID_VIEW_MENU_LIST, "List View", list_bmp, shortHelp="New",
-                                  longHelp="Long help for 'New'")
-        self.toolbar.AddLabelTool(ID_VIEW_MENU_ICON, "Icon View", icon_bmp, shortHelp="New",
-                                  longHelp="Long help for 'New'")
-
-        self.toolbar.Realize()
-
-        self.view = ContainerReportList(self, node)
-
-        self.history = [node]
-        self.history_ptr = 0
-        self.update_view()
-
-    def list_view(self):
-        """ Switch to list view """
-        if not isinstance(self.view, ContainerReportList):
-            self.view = ContainerReportList(self, self.history[self.history_ptr])
-
-    def icon_view(self):
-        """ Switch to icon view """
-        if not isinstance(self.view, ContainerIconList):
-            self.view = ContainerIconList(self, self.history[self.history_ptr])
-
-    # --- Begin history support functions -------------------------------------
-
-    @property
-    def node(self):
-        return self.history[self.history_ptr]
-
-    def go_back(self):
-        """ Go to the previously displayed item """
-        if self.history_ptr > 0:
-            self.history_ptr -= 1
-        self.update_view()
-
-    def go_next(self):
-        """ Go to the next displayed item """
-        if self.history_ptr < (len(self.history) - 1):
-            self.history_ptr += 1
-        self.update_view()
-
-    def go_up(self):
-        """ Go to the enclosing container """
-        node = self.history[self.history_ptr]
-        parent = node.store.get_parent(node.key)
-        if parent.key != node.key:  # at the root item
-            self.go(parent)
-            
-    def go_top(self):
-        """ Go to the root node """
-        node = self.history[self.history_ptr]
-        parent = node.store.root
-        if parent.key != node.key:  # at the root item
-            self.go(parent)
-
-    def go(self, newnode):
-        """ Go to a particular node.
-
-        Adds the node to the history.
-        """
-        del self.history[self.history_ptr + 1:]
-        self.history.append(newnode)
-        self.history_ptr += 1
-        self.update_view()
-
-    # --- End history support functions ---------------------------------------
-
-    def update_view(self):
-        """ Refresh the entire contents of the frame according to self.node. """
-        self.SetTitle(self.node.display_title)
-        self.view = type(self.view)(self, self.node)
-        self.update_info()
-
-        can_go_back = self.history_ptr > 0
-        can_go_next = self.history_ptr < (len(self.history) - 1)
-        can_go_up = self.node.store.get_parent(self.node.key) is not None
-        can_go_top = self.node.key != self.node.store.root.key
-        self.go_menu.Enable(ID_GO_MENU_BACK, can_go_back)
-        self.go_menu.Enable(ID_GO_MENU_NEXT, can_go_next)
-        self.go_menu.Enable(ID_GO_MENU_UP, can_go_up)
-        self.go_menu.Enable(ID_GO_MENU_TOP, can_go_top)
-        self.toolbar.EnableTool(ID_GO_MENU_BACK, can_go_back)
-        self.toolbar.EnableTool(ID_GO_MENU_NEXT, can_go_next)
-        self.toolbar.EnableTool(ID_GO_MENU_UP, can_go_up)
-        self.toolbar.EnableTool(ID_GO_MENU_TOP, can_go_top)
-
-        icon_view_allowed = len(self.node) <= 1000
-        self.view_menu.Enable(ID_VIEW_MENU_ICON, icon_view_allowed)
-        self.toolbar.EnableTool(ID_VIEW_MENU_ICON, icon_view_allowed)
-
-    def update_info(self):
-        """ Refresh the left-hand side information panel, according to the
-        current selection in the view.
-        """
-        node = self.view.selection
-        if node is None:
-            node = self.node  # Nothing selected; show this node's info
-        self.info.display(node)
-
-    def on_open(self, evt):
-        """ Trap Container open events, so we can browse instead of launching
-        new windows.
-        """
-        newnode = evt.node
-        log.debug("Got request to open node: %s" % newnode.key)
-        if isinstance(newnode, compass_model.Container):
-            self.go(newnode)
-        else:
-            evt.Skip()
+log.addHandler(logging.NullHandler())
\ No newline at end of file
diff --git a/hdf_compass/compass_viewer/container/__init__.py b/hdf_compass/compass_viewer/container/frame.py
similarity index 97%
copy from hdf_compass/compass_viewer/container/__init__.py
copy to hdf_compass/compass_viewer/container/frame.py
index c4076cc..79cbd06 100644
--- a/hdf_compass/compass_viewer/container/__init__.py
+++ b/hdf_compass/compass_viewer/container/frame.py
@@ -141,7 +141,7 @@ class ContainerFrame(NodeFrame):
         parent = node.store.get_parent(node.key)
         if parent.key != node.key:  # at the root item
             self.go(parent)
-            
+
     def go_top(self):
         """ Go to the root node """
         node = self.history[self.history_ptr]
@@ -197,9 +197,9 @@ class ContainerFrame(NodeFrame):
         """ Trap Container open events, so we can browse instead of launching
         new windows.
         """
-        newnode = evt.node
-        log.debug("Got request to open node: %s" % newnode.key)
-        if isinstance(newnode, compass_model.Container):
-            self.go(newnode)
+        new_node = evt.node
+        log.debug("Got request to open node: %s" % new_node.key)
+        if isinstance(new_node, compass_model.Container):
+            self.go(new_node)
         else:
             evt.Skip()
diff --git a/hdf_compass/compass_viewer/image/__init__.py b/hdf_compass/compass_viewer/image/__init__.py
index d77b87d..daf4533 100644
--- a/hdf_compass/compass_viewer/image/__init__.py
+++ b/hdf_compass/compass_viewer/image/__init__.py
@@ -9,59 +9,10 @@
 # distribution tree.  If you do not have access to this file, you may        #
 # request a copy from help at hdfgroup.org.                                     #
 ##############################################################################
-
-"""
-Implements a simple true-color image viewer.
-"""
 from __future__ import absolute_import, division, print_function, unicode_literals
 
-import wx
-import wx.grid
+from .frame import ImageFrame
 
 import logging
 log = logging.getLogger(__name__)
-
-from ..frame import NodeFrame
-
-
-class ImageFrame(NodeFrame):
-
-    """
-        Top-level frame displaying objects of type compass_model.Image.
-    """
-
-    def __init__(self, node, **kwds):
-        """ Create a new array viewer, to display *node*. """
-        NodeFrame.__init__(self, node, title=node.display_name, size=(800, 400), **kwds)
-        self.node = node
-
-        p = ImagePanel(self, node)
-        self.view = p
-
-
-class ImagePanel(wx.Panel):
-
-    """
-    Panel inside the image viewer pane which displays the image.
-    """
-
-    def __init__(self, parent, node):
-        """ Display a truecolor, pixel-interlaced (not pixel-planar) image
-        """
-        wx.Panel.__init__(self, parent)
-        b = wx.BitmapFromBuffer(node.width, node.height, node.data)
-        b.CopyFromBuffer(node.data)
-
-        sizer = wx.BoxSizer(wx.HORIZONTAL)
-
-        sb = wx.StaticBitmap(self, wx.ID_ANY, b)
-        sizer.AddStretchSpacer()
-        sizer.Add(sb, 1, wx.EXPAND | wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
-        sizer.AddStretchSpacer()
-
-        sizer2 = wx.BoxSizer(wx.VERTICAL)
-        sizer2.AddStretchSpacer()
-        sizer2.Add(sizer, 1)
-        sizer2.AddStretchSpacer()
-
-        self.SetSizer(sizer2)
+log.addHandler(logging.NullHandler())
\ No newline at end of file
diff --git a/hdf_compass/compass_viewer/image/__init__.py b/hdf_compass/compass_viewer/image/frame.py
similarity index 96%
copy from hdf_compass/compass_viewer/image/__init__.py
copy to hdf_compass/compass_viewer/image/frame.py
index d77b87d..0d6057b 100644
--- a/hdf_compass/compass_viewer/image/__init__.py
+++ b/hdf_compass/compass_viewer/image/frame.py
@@ -46,7 +46,7 @@ class ImagePanel(wx.Panel):
     """
 
     def __init__(self, parent, node):
-        """ Display a truecolor, pixel-interlaced (not pixel-planar) image
+        """ Display a true color, pixel-interlaced (not pixel-planar) image
         """
         wx.Panel.__init__(self, parent)
         b = wx.BitmapFromBuffer(node.width, node.height, node.data)
diff --git a/hdf_compass/compass_viewer/keyvalue/__init__.py b/hdf_compass/compass_viewer/keyvalue/__init__.py
index 65eadee..cb22768 100644
--- a/hdf_compass/compass_viewer/keyvalue/__init__.py
+++ b/hdf_compass/compass_viewer/keyvalue/__init__.py
@@ -9,92 +9,10 @@
 # distribution tree.  If you do not have access to this file, you may        #
 # request a copy from help at hdfgroup.org.                                     #
 ##############################################################################
-
-"""
-Implements a viewer for key-value stores (instances of compass_model.KeyValue).
-
-Keys are strings, values are any data type HDFCompass can understand.
-Presently this means all NumPy types, plus Python str/unicode.
-"""
 from __future__ import absolute_import, division, print_function, unicode_literals
 
-import wx
+from .frame import KeyValueFrame
 
 import logging
 log = logging.getLogger(__name__)
-
-from ..frame import NodeFrame
-
-
-class KeyValueFrame(NodeFrame):
-
-    """
-    A frame to display a list of key/value pairs, their types and shapes.
-    """
-
-    def __init__(self, node, pos=None):
-        """ Create a new frame.
-
-        node:   Container instance to display.
-        """
-        title = 'Attributes of "%s"' % node.display_name
-        NodeFrame.__init__(self, node, size=(800, 400), title=title, pos=pos)
-
-        self.list = KeyValueList(self, node)
-        self.view = self.list
-
-
-class KeyValueList(wx.ListCtrl):
-
-    """
-    A simple list view of key/value attributes
-    """
-
-    def __init__(self, parent, node):
-        """ Create a new attribute list view.
-
-        parent: wxPython parent object
-        node:   compass_model.KeyValue instance
-        """
-
-        wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.BORDER_NONE | wx.LC_HRULES)
-
-        self.node = node
-
-        self.InsertColumn(0, "Name")
-        self.InsertColumn(1, "Value")
-        self.InsertColumn(2, "Type")
-        self.InsertColumn(3, "Shape")
-
-        names = node.keys
-        values = [self.node[n] for n in names]
-
-        def itemtext(item, col_id):
-            name = names[item]
-            data = values[item]
-            text = ""
-            if col_id == 0:
-                text = name
-            elif col_id == 1:
-                text = str(data)
-            elif col_id == 2:
-                if hasattr(data, 'dtype'):
-                    text = str(data.dtype)
-                else:
-                    text = str(type(data))
-            elif col_id == 3:
-                if hasattr(data, 'shape'):
-                    text = str(data.shape)
-                else:
-                    text = "()"
-            return text
-
-        for n in names:
-            row = self.InsertStringItem(9999, n)
-            for col in xrange(1, 4):
-                self.SetStringItem(row, col, itemtext(row, col))
-
-        self.SetColumnWidth(0, 200)
-        self.SetColumnWidth(1, wx.LIST_AUTOSIZE)
-        self.SetColumnWidth(2, wx.LIST_AUTOSIZE)
-        self.SetColumnWidth(3, wx.LIST_AUTOSIZE)
+log.addHandler(logging.NullHandler())
diff --git a/hdf_compass/compass_viewer/keyvalue/__init__.py b/hdf_compass/compass_viewer/keyvalue/frame.py
similarity index 100%
copy from hdf_compass/compass_viewer/keyvalue/__init__.py
copy to hdf_compass/compass_viewer/keyvalue/frame.py
diff --git a/hdf_compass/compass_viewer/__init__.py b/hdf_compass/compass_viewer/viewer.py
similarity index 98%
copy from hdf_compass/compass_viewer/__init__.py
copy to hdf_compass/compass_viewer/viewer.py
index 436ec64..3df4ce3 100644
--- a/hdf_compass/compass_viewer/__init__.py
+++ b/hdf_compass/compass_viewer/viewer.py
@@ -25,7 +25,6 @@ import wx
 
 import logging
 log = logging.getLogger(__name__)
-log.addHandler(logging.NullHandler())
 
 from hdf_compass import compass_model
 from hdf_compass import utils
@@ -103,11 +102,11 @@ class CompassApp(wx.App):
 
 def open_node(node, pos=None):
     """ Open a viewer frame appropriate for the given Node instance.
-    
+
     node:   Node instance to open
     pos:    2-tuple with current window position (used to avoid overlap).
     """
-    
+
     if pos is not None:
         # The thing we get from GetPosition isn't really a tuple, so
         # you have to manually cast entries to int or it silently fails.
@@ -143,7 +142,7 @@ def open_node(node, pos=None):
     else:
         pass
 
-        
+
 def open_store(url):
     """ Open the url using the first matching registered Store class.
 
@@ -220,7 +219,7 @@ def run():
     load_plugins()
 
     urls = sys.argv[1:]
-    
+
     for url in urls:
         if "://" not in url:
             # assumed to be file path
@@ -229,10 +228,10 @@ def run():
             log.warning('Failed to open "%s"; no handlers' % url)
 
     f = frame.InitFrame()
-    
+
     if utils.is_darwin:
         wx.MenuBar.MacSetCommonMenuBar(f.GetMenuBar())
     else:
         f.Show()
-        
+
     app.MainLoop()

-- 
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