[GRASS-SVN] r60690 - grass/branches/releasebranch_7_0/gui/wxpython/gui_core

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 3 06:38:48 PDT 2014


Author: annakrat
Date: 2014-06-03 06:38:48 -0700 (Tue, 03 Jun 2014)
New Revision: 60690

Modified:
   grass/branches/releasebranch_7_0/gui/wxpython/gui_core/forms.py
   grass/branches/releasebranch_7_0/gui/wxpython/gui_core/widgets.py
Log:
wxGUI: backport fixes for #2026

Modified: grass/branches/releasebranch_7_0/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/gui_core/forms.py	2014-06-03 13:36:37 UTC (rev 60689)
+++ grass/branches/releasebranch_7_0/gui/wxpython/gui_core/forms.py	2014-06-03 13:38:48 UTC (rev 60690)
@@ -437,8 +437,9 @@
             module_desc = self.task.label + ' ' + self.task.description
         else:
             module_desc = self.task.description
-        self.description = StaticWrapText(parent = self.panel,
-                                          label = module_desc)
+        
+        self.description = StaticWrapText(parent=self.panel,
+                                          label=module_desc)
         topsizer.Add(item = self.description, proportion = 1, border = 5,
                      flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
         

Modified: grass/branches/releasebranch_7_0/gui/wxpython/gui_core/widgets.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/gui_core/widgets.py	2014-06-03 13:36:37 UTC (rev 60689)
+++ grass/branches/releasebranch_7_0/gui/wxpython/gui_core/widgets.py	2014-06-03 13:38:48 UTC (rev 60690)
@@ -40,6 +40,8 @@
 import wx
 import wx.lib.mixins.listctrl as listmix
 import wx.lib.scrolledpanel as SP
+from wx.lib.stattext import GenStaticText
+from wx.lib.wordwrap import wordwrap
 import wx.combo
 try:
     import wx.lib.agw.flatnotebook   as FN
@@ -443,36 +445,45 @@
         dc.DrawRectangle(0, 0, 2 * size[0] / 5, size[1])
         dc.DrawRectangle(3 * size[0] / 5, 0, 2 * size[0] / 5, size[1])
 
-class StaticWrapText(wx.StaticText):
-    """!A Static Text field that wraps its text to fit its width,
-    enlarging its height if necessary.
-    """
-    def __init__(self, parent, id = wx.ID_ANY, label = '', *args, **kwds):
-        self.parent        = parent
-        self.originalLabel = label
-        
-        wx.StaticText.__init__(self, parent, id, label = '', *args, **kwds)
-        
-        self.SetLabel(label)
-        self.Bind(wx.EVT_SIZE, self.OnResize)
-    
+
+class StaticWrapText(GenStaticText):
+    """!A Static Text widget that wraps its text to fit parents width,
+    enlarging its height if necessary."""
+
+    def __init__(self, parent, id=wx.ID_ANY, label='', margin=0, *args, **kwds):
+        self._margin = margin
+        self._initialLabel = label
+        self.init = False
+        GenStaticText.__init__(self, parent, id, label, *args, **kwds)
+        self.Bind(wx.EVT_SIZE, self.OnSize)
+
+    def DoGetBestSize(self):
+        """!Overriden method which reports widget's best size."""
+        if not self.init:
+            self._updateLabel()
+            self.init = True
+        parent = self.GetParent()
+        newExtent = wx.ClientDC(parent).GetMultiLineTextExtent(self.GetLabel())
+        # when starting, width is very small and height is big which creates very high windows
+        if newExtent[0] < newExtent[1]:
+            return (0, 0)
+        return newExtent[:2]
+
+    def OnSize(self, event):
+        self._updateLabel()
+        event.Skip()
+
+    def _updateLabel(self):
+        """!Calculates size of wrapped label"""
+        parent = self.GetParent()
+        newLabel = wordwrap(text=self._initialLabel, width=parent.GetSize()[0],
+                            dc=wx.ClientDC(parent), breakLongWords=True, margin=self._margin)
+        GenStaticText.SetLabel(self, newLabel)
+
     def SetLabel(self, label):
-        self.originalLabel = label
-        self.wrappedSize = None
-        self.OnResize(None)
+        self._initialLabel = label
+        self._updateLabel()
 
-    def OnResize(self, event):
-        if not getattr(self, "resizing", False):
-            self.resizing = True
-            newSize = wx.Size(self.parent.GetSize().width - 50,
-                              self.GetSize().height)
-            if self.wrappedSize != newSize:
-                wx.StaticText.SetLabel(self, self.originalLabel)
-                self.Wrap(newSize.width)
-                self.wrappedSize = newSize
-                
-                self.SetSize(self.wrappedSize)
-            del self.resizing
 
 class BaseValidator(wx.PyValidator):
     def __init__(self):



More information about the grass-commit mailing list