[hdf-compass] 205/295: Fix close events and add colormaps

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun May 8 10:35:45 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 ef386efeab94040063cc5544840dc213b6f3ab55
Author: giumas <giumas at yahoo.it>
Date:   Wed Oct 28 23:58:45 2015 -0400

    Fix close events and add colormaps
---
 hdf_compass/compass_viewer/array/plot.py | 79 +++++++++++++++++++++++++++++---
 hdf_compass/compass_viewer/frame.py      | 32 +++++++------
 2 files changed, 92 insertions(+), 19 deletions(-)

diff --git a/hdf_compass/compass_viewer/array/plot.py b/hdf_compass/compass_viewer/array/plot.py
index 93f6453..5fe1e80 100644
--- a/hdf_compass/compass_viewer/array/plot.py
+++ b/hdf_compass/compass_viewer/array/plot.py
@@ -28,10 +28,17 @@ log = logging.getLogger(__name__)
 
 from ..frame import BaseFrame
 
+ID_VIEW_CMAP_JET = wx.NewId()  # default
+ID_VIEW_CMAP_BONE = wx.NewId()
+ID_VIEW_CMAP_GIST_EARTH = wx.NewId()
+ID_VIEW_CMAP_OCEAN = wx.NewId()
+ID_VIEW_CMAP_RAINBOW = wx.NewId()
+ID_VIEW_CMAP_RDYLGN = wx.NewId()
+ID_VIEW_CMAP_WINTER = wx.NewId()
+
 
 class PlotFrame(BaseFrame):
-    """
-    Base class for Matplotlib plot windows.
+    """ Base class for Matplotlib plot windows.
 
     Override draw_figure() to plot your figure on the provided axes.
     """
@@ -81,16 +88,76 @@ class LinePlotFrame(PlotFrame):
 
 class ContourPlotFrame(PlotFrame):
     def __init__(self, data, names=None, title="Contour Plot"):
+        # need to be set before calling the parent (need for plotting)
+        self.colormap = "jet"
+
         PlotFrame.__init__(self, data, title)
 
+        self.cmap_menu = wx.Menu()
+        self.cmap_menu.Append(ID_VIEW_CMAP_JET, "Jet", kind=wx.ITEM_RADIO)
+        self.cmap_menu.Append(ID_VIEW_CMAP_BONE, "Bone", kind=wx.ITEM_RADIO)
+        self.cmap_menu.Append(ID_VIEW_CMAP_GIST_EARTH, "Gist Earth", kind=wx.ITEM_RADIO)
+        self.cmap_menu.Append(ID_VIEW_CMAP_OCEAN, "Ocean", kind=wx.ITEM_RADIO)
+        self.cmap_menu.Append(ID_VIEW_CMAP_RAINBOW, "Rainbow", kind=wx.ITEM_RADIO)
+        self.cmap_menu.Append(ID_VIEW_CMAP_RDYLGN, "Red-Yellow-Green", kind=wx.ITEM_RADIO)
+        self.cmap_menu.Append(ID_VIEW_CMAP_WINTER, "Winter", kind=wx.ITEM_RADIO)
+        self.add_menu(self.cmap_menu, "Colormap")
+
+        self.Bind(wx.EVT_MENU, self.on_cmap_jet, id=ID_VIEW_CMAP_JET)
+        self.Bind(wx.EVT_MENU, self.on_cmap_bone, id=ID_VIEW_CMAP_BONE)
+        self.Bind(wx.EVT_MENU, self.on_cmap_gist_earth, id=ID_VIEW_CMAP_GIST_EARTH)
+        self.Bind(wx.EVT_MENU, self.on_cmap_ocean, id=ID_VIEW_CMAP_OCEAN)
+        self.Bind(wx.EVT_MENU, self.on_cmap_rainbow, id=ID_VIEW_CMAP_RAINBOW)
+        self.Bind(wx.EVT_MENU, self.on_cmap_rdylgn, id=ID_VIEW_CMAP_RDYLGN)
+        self.Bind(wx.EVT_MENU, self.on_cmap_winter, id=ID_VIEW_CMAP_WINTER)
+
+    def on_cmap_jet(self, evt):
+        log.debug("cmap: jet")
+        self.colormap = "jet"
+        self._refresh_plot()
+
+    def on_cmap_bone(self, evt):
+        log.debug("cmap: bone")
+        self.colormap = "bone"
+        self._refresh_plot()
+
+    def on_cmap_gist_earth(self, evt):
+        log.debug("cmap: gist_earth")
+        self.colormap = "gist_earth"
+        self._refresh_plot()
+
+    def on_cmap_ocean(self, evt):
+        log.debug("cmap: ocean")
+        self.colormap = "ocean"
+        self._refresh_plot()
+
+    def on_cmap_rainbow(self, evt):
+        log.debug("cmap: rainbow")
+        self.colormap = "rainbow"
+        self._refresh_plot()
+
+    def on_cmap_rdylgn(self, evt):
+        log.debug("cmap: RdYlGn")
+        self.colormap = "RdYlGn"
+        self._refresh_plot()
+
+    def on_cmap_winter(self, evt):
+        log.debug("cmap: winter")
+        self.colormap = "winter"
+        self._refresh_plot()
+
+    def _refresh_plot(self):
+        self.draw_figure()
+        self.canvas.draw()
+
     def draw_figure(self):
-        maxElements = 500  # don't attempt plot more than 500x500 elements
+        max_elements = 500  # don't attempt plot more than 500x500 elements
         rows = self.data.shape[0]
         cols = self.data.shape[1]
-        row_stride = rows // maxElements + 1
-        col_stride = cols // maxElements + 1
+        row_stride = rows // max_elements + 1
+        col_stride = cols // max_elements + 1
         data = self.data[::row_stride, ::col_stride]
         xx = np.arange(0, self.data.shape[1], col_stride)
         yy = np.arange(0, self.data.shape[0], row_stride)
-        out = self.axes.contourf(xx, yy, data, 25)
+        out = self.axes.contourf(xx, yy, data, 25, cmap=plt.cm.get_cmap(self.colormap))
         plt.colorbar(out)
diff --git a/hdf_compass/compass_viewer/frame.py b/hdf_compass/compass_viewer/frame.py
index 986feb7..2c95c5a 100644
--- a/hdf_compass/compass_viewer/frame.py
+++ b/hdf_compass/compass_viewer/frame.py
@@ -39,6 +39,8 @@ from hdf_compass import compass_model
 from hdf_compass.utils import __version__, is_darwin, url2path, path2url
 from .events import CompassOpenEvent
 
+open_frames = 0  # count the open frames
+
 
 class BaseFrame(wx.Frame):
 
@@ -55,13 +57,17 @@ class BaseFrame(wx.Frame):
     """
 
     icon_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), 'icons'))
+    open_frames = 0  # count the number of frames
 
     def __init__(self, **kwds):
         """ Constructor; any keywords are passed on to wx.Frame.
         """
 
-        wx.Frame.__init__(self, None, **kwds) 
-        
+        wx.Frame.__init__(self, None, **kwds)
+
+        BaseFrame.open_frames += 1
+        log.debug("new frame -> open frames: %s" % BaseFrame.open_frames)
+
         # Frame icon
         ib = wx.IconBundle()
         icon_32 = wx.EmptyIcon()
@@ -111,17 +117,21 @@ class BaseFrame(wx.Frame):
 
         self.SetMenuBar(menubar)
 
-        self.Bind(wx.EVT_MENU, self.on_window_close, id=wx.ID_CLOSE)
         self.Bind(wx.EVT_MENU, self.on_file_open, id=wx.ID_OPEN)
         self.Bind(wx.EVT_MENU, self.on_resource_open, id=ID_OPEN_RESOURCE)
         self.Bind(wx.EVT_MENU, self.on_manual, id=wx.ID_HELP)
         self.Bind(wx.EVT_MENU, self.on_about, id=wx.ID_ABOUT)
         self.Bind(wx.EVT_MENU, self.on_exit, id=wx.ID_EXIT)
+        self.Bind(wx.EVT_CLOSE, self.on_exit)
         self.Bind(wx.EVT_MENU_RANGE, self.on_url_history, id=wx.ID_FILE1, id2=wx.ID_FILE9)
 
     def on_exit(self, evt):
         """ Called on "exit" event from the menu """
-        wx.GetApp().Exit()
+        BaseFrame.open_frames -= 1
+        log.debug("exit frame -> open frames: %s" % BaseFrame.open_frames)
+        self.Destroy()
+        if BaseFrame.open_frames == 0:
+            wx.GetApp().Exit()
 
     def on_manual(self, evt):
         """ Open the url with the online documentation """
@@ -131,7 +141,7 @@ class BaseFrame(wx.Frame):
     def on_about(self, evt):
         """ Display an "About" dialog """
         info = wx.AboutDialogInfo()
-        info.Name = "HDFCompass"
+        info.Name = "HDF Compass"
         info.Version = __version__
         info.Copyright = "(c) 2014-%d The HDF Group" % date.today().year
         icon_48 = wx.EmptyIcon()
@@ -179,10 +189,6 @@ class BaseFrame(wx.Frame):
         url = self.urlhistory.GetHistoryFile(fileNum)
         self.open_url(url, fileNum)
             
-    def on_window_close(self, evt):
-        """ Close Window file event, or cmd-W """
-        self.Destroy()
-
     def on_resource_open(self, evt):
         """ Request to open a URL via the File menu """
         dlg = wx.TextEntryDialog(self, 'Enter resource URL:')
@@ -205,7 +211,7 @@ class BaseFrame(wx.Frame):
             self.config.Flush()
             open_store(url)
         else:
-            if fileNum >= 0 and fileNum < MAX_RECENT_FILES:
+            if (fileNum >= 0) and (fileNum < MAX_RECENT_FILES):
                 self.urlhistory.RemoveFileFromHistory(fileNum)
                 self.urlhistory.Save(self.config)
                 self.config.Flush()
@@ -232,7 +238,7 @@ class InitFrame(BaseFrame):
         
         style = wx.DEFAULT_FRAME_STYLE & (~wx.RESIZE_BORDER) & (~wx.MAXIMIZE_BOX)
         title = "HDF Compass"
-        BaseFrame.__init__(self, size=(552,247), title=title, style=style)
+        super(InitFrame, self).__init__(size=(552, 247), title=title, style=style)
 
         data = wx.Bitmap(os.path.join(self.icon_folder, "logo.png"), wx.BITMAP_TYPE_ANY)
         bmp = wx.StaticBitmap(self, wx.ID_ANY, data)
@@ -276,7 +282,7 @@ class NodeFrame(BaseFrame):
     def _incref(cls, store):
         """ Record that a client is using the specified store. """
         try:
-            cls._stores[store] = cls._stores[store] + 1
+            cls._stores[store] += 1
         except KeyError:
             cls._stores[store] = 1
 
@@ -338,7 +344,7 @@ class NodeFrame(BaseFrame):
         node:   The compass_model.Node instance to display.
         """
 
-        BaseFrame.__init__(self, **kwds)
+        super(NodeFrame, self).__init__(**kwds)
 
         # Enable the "Close File" menu entry
         fm = self.GetMenuBar().GetMenu(0)

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