Explorar el Código

wxGUI/start up: use normal StaticText instead of StaticTextWrap for error message since it causes emitting events continually on wxPython 3

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@64571 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová hace 10 años
padre
commit
104d3d4992
Se han modificado 2 ficheros con 74 adiciones y 16 borrados
  1. 6 15
      gui/wxpython/gis_set.py
  2. 68 1
      gui/wxpython/gui_core/widgets.py

+ 6 - 15
gui/wxpython/gis_set.py

@@ -110,18 +110,7 @@ class GRASSStartup(wx.Frame):
         self.mapset_box = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
         self.mapset_box = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
                                          label=" %s " % _("3. Select GRASS Mapset"))
                                          label=" %s " % _("3. Select GRASS Mapset"))
 
 
-        # no message at the beginning but a dummy text is needed to do
-        # the layout right (the lenght should be similar to maximal message)
-        self.lmessage = StaticWrapText(
-            parent=self.panel, id=wx.ID_ANY,
-            label=("This is a placeholer text to workaround layout issues."
-                   " Without this (long) text the widgets will not align"
-                   " when a message is shown."
-                   " This text is not translatable and users should never"
-                   " see it because it will be replaced by nothing or a real"
-                   " message after initial checks. If you are an user"
-                   " and you see this text, it is probably some minor issue."
-                   " Please, contact GRASS developers to tell them about it."))
+        self.lmessage = wx.StaticText(parent=self.panel)
         # It is not clear if all wx versions supports color, so try-except.
         # It is not clear if all wx versions supports color, so try-except.
         # The color itself may not be correct for all platforms/system settings
         # The color itself may not be correct for all platforms/system settings
         # but in http://xoomer.virgilio.it/infinity77/wxPython/Widgets/wx.SystemSettings.html
         # but in http://xoomer.virgilio.it/infinity77/wxPython/Widgets/wx.SystemSettings.html
@@ -199,14 +188,14 @@ class GRASSStartup(wx.Frame):
 
 
         # Locations
         # Locations
         self.lblocations = GListBox(parent = self.location_panel,
         self.lblocations = GListBox(parent = self.location_panel,
-                                    id=wx.ID_ANY, size=(180, 120),
+                                    id=wx.ID_ANY, size=(180, 200),
                                     choices = self.listOfLocations)
                                     choices = self.listOfLocations)
         self.lblocations.SetColumnWidth(0, 180)
         self.lblocations.SetColumnWidth(0, 180)
 
 
         # TODO: sort; but keep PERMANENT on top of list
         # TODO: sort; but keep PERMANENT on top of list
         # Mapsets
         # Mapsets
         self.lbmapsets = GListBox(parent = self.mapset_panel,
         self.lbmapsets = GListBox(parent = self.mapset_panel,
-                                  id=wx.ID_ANY, size=(180, 120),
+                                  id=wx.ID_ANY, size=(180, 200),
                                   choices = self.listOfMapsets)
                                   choices = self.listOfMapsets)
         self.lbmapsets.SetColumnWidth(0, 180)
         self.lbmapsets.SetColumnWidth(0, 180)
 
 
@@ -423,7 +412,7 @@ class GRASSStartup(wx.Frame):
         sizer.Add(item=self.lmessage,
         sizer.Add(item=self.lmessage,
                   proportion=0,
                   proportion=0,
                   flag=wx.ALIGN_CENTER_VERTICAL |
                   flag=wx.ALIGN_CENTER_VERTICAL |
-                  wx.ALIGN_LEFT | wx.ALL | wx.EXPAND, border=8)
+                  wx.ALIGN_LEFT | wx.ALL | wx.EXPAND, border=5)
         sizer.Add(item=location_mapset_sizer, proportion=1,
         sizer.Add(item=location_mapset_sizer, proportion=1,
                   flag = wx.RIGHT | wx.LEFT | wx.EXPAND,
                   flag = wx.RIGHT | wx.LEFT | wx.EXPAND,
                   border = 1)
                   border = 1)
@@ -472,6 +461,7 @@ class GRASSStartup(wx.Frame):
             you know that there is everything correct now.
             you know that there is everything correct now.
         """
         """
         self.lmessage.SetLabel(text)
         self.lmessage.SetLabel(text)
+        self.lmessage.Wrap(self.GetClientSize()[0])
         self.sizer.Layout()
         self.sizer.Layout()
 
 
     def _showError(self, text):
     def _showError(self, text):
@@ -485,6 +475,7 @@ class GRASSStartup(wx.Frame):
             you know that there is everything correct now.
             you know that there is everything correct now.
         """
         """
         self.lmessage.SetLabel(_("Error: {text}").format(text=text))
         self.lmessage.SetLabel(_("Error: {text}").format(text=text))
+        self.lmessage.Wrap(self.GetClientSize()[0])
         self.sizer.Layout()
         self.sizer.Layout()
 
 
     def _hideMessage(self):
     def _hideMessage(self):

+ 68 - 1
gui/wxpython/gui_core/widgets.py

@@ -466,7 +466,69 @@ class SymbolButton(BitmapTextButton):
         dc.DrawRectangle(0, 0, 2 * size[0] / 5, size[1])
         dc.DrawRectangle(0, 0, 2 * size[0] / 5, size[1])
         dc.DrawRectangle(3 * size[0] / 5, 0, 2 * size[0] / 5, size[1])
         dc.DrawRectangle(3 * size[0] / 5, 0, 2 * size[0] / 5, size[1])
 
 
+class AutoWrapStaticText(GenStaticText):
+    def __init__(self, parent, label):
+        GenStaticText.__init__(self, parent, -1, label)
+        self._label = label
+        self.init = False
+        self.Bind(wx.EVT_SIZE, self.OnSize)
+
+    def OnSize(self, event):
+        self.Wrap(event.GetSize()[0])
+        event.Skip()
+        
+    def DoGetBestSize(self):
+        """Overriden method which reports widget's best size."""
+        print 'do get 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 Wrap(self, width):
+        if width < 0:
+            return
 
 
+        dc = wx.ClientDC(self)
+        dc.SetFont(self.GetFont())
+        text = wordwrap(self._label, width, dc)
+        GenStaticText.SetLabel(self, text)
+
+    def SetLabel(self, label, wrapped=False):
+        if not wrapped:
+            self._label = label
+
+        self.Wrap(self.GetSize()[0])
+        
+class StaticWrapText2(wx.PyControl):
+   def __init__(self, parent, id=wx.ID_ANY, label='', pos=wx.DefaultPosition,
+                size=wx.DefaultSize, style=wx.NO_BORDER,
+                validator=wx.DefaultValidator, name='StaticWrapText'):
+      wx.PyControl.__init__(self, parent, id, pos, size, style, validator, name)
+      self.statictext = wx.StaticText(self, wx.ID_ANY, label, style=style)
+      self.wraplabel = label
+      #self.wrap()
+   def wrap(self):
+ 
+      self.statictext.SetLabel(self.wraplabel)
+      self.statictext.Wrap(self.GetParent().GetSize().width)#self.statictext.Wrap(self.GetSize().width)
+
+   def DoGetBestSize(self):
+      self.wrap()
+      #print self.statictext.GetSize()
+      self.SetSize(self.statictext.GetSize())
+      return self.GetSize()
+      
+   def SetLabel(self, label):
+       self.wraplabel = label
+       self.wrap()
+       
+      
 class StaticWrapText(GenStaticText):
 class StaticWrapText(GenStaticText):
     """A Static Text widget that wraps its text to fit parents width,
     """A Static Text widget that wraps its text to fit parents width,
     enlarging its height if necessary."""
     enlarging its height if necessary."""
@@ -492,7 +554,8 @@ class StaticWrapText(GenStaticText):
 
 
     def OnSize(self, event):
     def OnSize(self, event):
         self._updateLabel()
         self._updateLabel()
-        event.Skip()
+        print event.GetSize()
+        #event.Skip()
 
 
     def _updateLabel(self):
     def _updateLabel(self):
         """Calculates size of wrapped label"""
         """Calculates size of wrapped label"""
@@ -500,11 +563,15 @@ class StaticWrapText(GenStaticText):
         newLabel = wordwrap(text=self._initialLabel, width=parent.GetSize()[0],
         newLabel = wordwrap(text=self._initialLabel, width=parent.GetSize()[0],
                             dc=wx.ClientDC(parent), breakLongWords=True,
                             dc=wx.ClientDC(parent), breakLongWords=True,
                             margin=self._margin)
                             margin=self._margin)
+        print parent.GetSize()[0], newLabel
+        print self.Unbind(wx.EVT_SIZE)
         GenStaticText.SetLabel(self, newLabel)
         GenStaticText.SetLabel(self, newLabel)
+        self.Bind(wx.EVT_SIZE, self.OnSize)
 
 
     def SetLabel(self, label):
     def SetLabel(self, label):
         self._initialLabel = label
         self._initialLabel = label
         self._updateLabel()
         self._updateLabel()
+        print 'setlabel'
 
 
 
 
 class BaseValidator(wx.PyValidator):
 class BaseValidator(wx.PyValidator):