[GRASS-SVN] r52689 - in grass/branches/develbranch_6/gui/wxpython: gui_core lmgr

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 17 04:42:55 PDT 2012


Author: annakrat
Date: 2012-08-17 04:42:55 -0700 (Fri, 17 Aug 2012)
New Revision: 52689

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_core/dialogs.py
   grass/branches/develbranch_6/gui/wxpython/lmgr/layertree.py
Log:
wxGUI/lmgr: add apply button to opacity dialog (merge from trunk, r52687)

Modified: grass/branches/develbranch_6/gui/wxpython/gui_core/dialogs.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_core/dialogs.py	2012-08-17 10:13:50 UTC (rev 52688)
+++ grass/branches/develbranch_6/gui/wxpython/gui_core/dialogs.py	2012-08-17 11:42:55 UTC (rev 52689)
@@ -37,6 +37,7 @@
 import wx
 import wx.lib.filebrowsebutton as filebrowse
 import wx.lib.mixins.listctrl as listmix
+from wx.lib.newevent import NewEvent
 
 from grass.script import core as grass
 from grass.script import task as gtask
@@ -50,6 +51,8 @@
 from core.settings    import UserSettings
 from core.debug       import Debug
 
+wxApplyOpacity, EVT_APPLY_OPACITY = NewEvent()
+
 class ElementDialog(wx.Dialog):
     def __init__(self, parent, title, label, id = wx.ID_ANY,
                  etype = False, style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
@@ -2048,6 +2051,10 @@
 
         btnCancel = wx.Button(parent = panel, id = wx.ID_CANCEL)
         btnsizer.AddButton(btnCancel)
+
+        btnApply = wx.Button(parent = panel, id = wx.ID_APPLY)
+        btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
+        btnsizer.AddButton(btnApply)
         btnsizer.Realize()
 
         sizer.Add(item = btnsizer, proportion = 0,
@@ -2066,6 +2073,10 @@
         opacity = float(self.value.GetValue()) / 100
         return opacity
 
+    def OnApply(self, event):
+        event = wxApplyOpacity(value = self.GetOpacity())
+        wx.PostEvent(self, event)
+
 def GetImageHandlers(image):
     """!Get list of supported image handlers"""
     lext = list()

Modified: grass/branches/develbranch_6/gui/wxpython/lmgr/layertree.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/lmgr/layertree.py	2012-08-17 10:13:50 UTC (rev 52688)
+++ grass/branches/develbranch_6/gui/wxpython/lmgr/layertree.py	2012-08-17 11:42:55 UTC (rev 52689)
@@ -30,7 +30,7 @@
 from grass.script import core as grass
 
 from core                import globalvar
-from gui_core.dialogs    import SetOpacityDialog
+from gui_core.dialogs    import SetOpacityDialog, EVT_APPLY_OPACITY
 from gui_core.forms      import GUI
 from mapdisp.frame       import MapFrame
 from core.render         import Map
@@ -644,23 +644,38 @@
         dlg = SetOpacityDialog(self, opacity = current_opacity,
                                title = _("Set opacity of <%s>") % maplayer.GetName())
         dlg.CentreOnParent()
+        dlg.Bind(EVT_APPLY_OPACITY, self.OnApplyLayerOpacity)
 
         if dlg.ShowModal() == wx.ID_OK:
-            new_opacity = dlg.GetOpacity() # string
-            self.Map.ChangeOpacity(maplayer, new_opacity)
-            maplayer.SetOpacity(new_opacity)
-            self.SetItemText(self.layer_selected,
-                             self._getLayerName(self.layer_selected))
+            self.ChangeLayerOpacity(layer = self.layer_selected, value = dlg.GetOpacity())
+        dlg.Destroy()
+
+    def OnApplyLayerOpacity(self, event):
+        """!Handles EVT_APPLY_OPACITY event."""
+        self.ChangeLayerOpacity(layer = self.layer_selected, value = event.value)
+
+    def ChangeLayerOpacity(self, layer, value):
+        """!Change opacity value of layer
+        @param layer layer for which to change (item in layertree)
+        @param value opacity value (float between 0 and 1)
+        """
+        maplayer = self.GetPyData(layer)[0]['maplayer']
+        self.Map.ChangeOpacity(maplayer, value)
+        maplayer.SetOpacity(value)
+        self.SetItemText(layer,
+                         self._getLayerName(layer))
+        
+        # vector layer currently edited
+        if self.GetMapDisplay().GetToolbar('vdigit') and \
+                self.GetMapDisplay().GetToolbar('vdigit').GetLayer() == maplayer:
+            alpha = int(value * 255)
+            self.GetMapDisplay().GetWindow().digit.GetDisplay().UpdateSettings(alpha = alpha)
             
-            # vector layer currently edited
-            if self.mapdisplay.GetToolbar('vdigit') and \
-                    self.mapdisplay.GetToolbar('vdigit').GetLayer() == maplayer:   
-                alpha = int(new_opacity * 255)
-                self.mapdisplay.GetWindow().digit.GetDisplay().UpdateSettings(alpha = alpha)
-                
-            # redraw map if auto-rendering is enabled
-            self.rerender = True
-            self.reorder = True
+        # redraw map if auto-rendering is enabled
+        renderVector = False
+        if self.GetMapDisplay().GetToolbar('vdigit'):
+            renderVector = True
+        self.GetMapDisplay().GetWindow().UpdateMap(render = False, renderVector = renderVector)
 
     def OnNvizProperties(self, event):
         """!Nviz-related properties (raster/vector/volume)



More information about the grass-commit mailing list