[GRASS-SVN] r40964 - grass/branches/develbranch_6/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Feb 13 01:06:15 EST 2010


Author: cmbarton
Date: 2010-02-13 01:06:15 -0500 (Sat, 13 Feb 2010)
New Revision: 40964

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
Log:
Backport from trunk r40962: fix for output font dialog so that it works on all platforms again (Mac bug in wxPython has broken standard font dialog)

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2010-02-13 06:04:51 UTC (rev 40963)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2010-02-13 06:06:15 UTC (rev 40964)
@@ -1770,7 +1770,8 @@
         """'Set font' button pressed"""
         dlg = DefaultFontDialog(parent=self, id=wx.ID_ANY,
                                 title=_('Select default display font'),
-                                style=wx.DEFAULT_DIALOG_STYLE)
+                                style=wx.DEFAULT_DIALOG_STYLE,
+                                type='font')
         
         if dlg.ShowModal() == wx.ID_OK:
             # set default font and encoding environmental variables
@@ -1790,28 +1791,43 @@
         event.Skip()
 
     def OnSetOutputFont(self, event):
-        """'Set font' button pressed"""
+        """'Set output font' button pressed"""
+        
+        dlg = DefaultFontDialog(parent=self, id=wx.ID_ANY,
+                                title=_('Select output font'),
+                                style=wx.DEFAULT_DIALOG_STYLE,
+                                type='outputfont')
+        
+        if dlg.ShowModal() == wx.ID_OK:
+            # set output font and font size variables
+            if dlg.font:
+                self.settings.Set(group='display', value=dlg.font,
+                                  key='outputfont', subkey='type')
 
-        type = self.settings.Get(group='display', key='outputfont', subkey='type')   
+                self.settings.Set(group='display', value=dlg.fontsize,
+                                  key='outputfont', subkey='size')
+
+# Standard font dialog broken for Mac in OS X 10.6
+#        type = self.settings.Get(group='display', key='outputfont', subkey='type')   
                            
-        size = self.settings.Get(group='display', key='outputfont', subkey='size')
-        if size == None or size == 0: size = 10
-        size = float(size)
+#        size = self.settings.Get(group='display', key='outputfont', subkey='size')
+#        if size == None or size == 0: size = 10
+#        size = float(size)
         
-        data = wx.FontData()
-        data.EnableEffects(True)
-        data.SetInitialFont(wx.Font(pointSize=size, family=wx.FONTFAMILY_MODERN, faceName=type, style=wx.NORMAL, weight=0))
+#        data = wx.FontData()
+#        data.EnableEffects(True)
+#        data.SetInitialFont(wx.Font(pointSize=size, family=wx.FONTFAMILY_MODERN, faceName=type, style=wx.NORMAL, weight=0))
 
-        dlg = wx.FontDialog(self, data)
+#        dlg = wx.FontDialog(self, data)
 
-        if dlg.ShowModal() == wx.ID_OK:
-            data = dlg.GetFontData()
-            font = data.GetChosenFont()
+#        if dlg.ShowModal() == wx.ID_OK:
+#            data = dlg.GetFontData()
+#            font = data.GetChosenFont()
 
-            self.settings.Set(group='display', value=font.GetFaceName(),
-                                  key='outputfont', subkey='type')
-            self.settings.Set(group='display', value=font.GetPointSize(),
-                                  key='outputfont', subkey='size')
+#            self.settings.Set(group='display', value=font.GetFaceName(),
+#                                  key='outputfont', subkey='type')
+#            self.settings.Set(group='display', value=font.GetPointSize(),
+#                                  key='outputfont', subkey='size')
                 
         dlg.Destroy()
 
@@ -1924,25 +1940,19 @@
     """
     def __init__(self, parent, id, title,
                  pos=wx.DefaultPosition, size=wx.DefaultSize,
-                 style=wx.DEFAULT_DIALOG_STYLE,
-                 settings=globalSettings):
+                 style=wx.DEFAULT_DIALOG_STYLE |
+                 wx.RESIZE_BORDER,
+                 settings=globalSettings,
+                 type='font'):
         
         self.settings = settings
+        self.type = type
         
         wx.Dialog.__init__(self, parent, id, title, pos, size, style)
 
         panel = wx.Panel(parent=self, id=wx.ID_ANY)
         
-        if "GRASS_FONT" in os.environ:
-            self.font = os.environ["GRASS_FONT"]
-        else:
-            self.font = self.settings.Get(group='display',
-                                          key='font', subkey='type')
-
         self.fontlist = self.GetFonts()
-
-        self.encoding = self.settings.Get(group='display',
-                                          key='font', subkey='encoding')
         
         border = wx.BoxSizer(wx.VERTICAL)
         box   = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Font settings"))
@@ -1962,24 +1972,57 @@
                                  style=wx.LB_SINGLE|wx.LB_SORT)
         self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.fontlb)
         self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, self.fontlb)
-        if self.font:
-            self.fontlb.SetStringSelection(self.font, True)
 
         gridSizer.Add(item=self.fontlb,
-                flag=wx.EXPAND, pos=(0, 1))
+                flag=wx.EXPAND, pos=(1, 0))
 
-        label = wx.StaticText(parent=panel, id=wx.ID_ANY,
-                              label=("Character encoding:"))
-        gridSizer.Add(item=label,
+        if self.type == 'font':
+            if "GRASS_FONT" in os.environ:
+                self.font = os.environ["GRASS_FONT"]
+            else:
+                self.font = self.settings.Get(group='display',
+                                              key='font', subkey='type')
+            self.encoding = self.settings.Get(group='display',
+                                          key='font', subkey='encoding')
+
+            label = wx.StaticText(parent=panel, id=wx.ID_ANY,
+                                  label=("Character encoding:"))
+            gridSizer.Add(item=label,
+                          flag=wx.ALIGN_CENTER_VERTICAL,
+                          pos=(2, 0))
+
+            self.textentry = wx.TextCtrl(parent=panel, id=wx.ID_ANY,
+                                         value=self.encoding)
+            gridSizer.Add(item=self.textentry,
+                    flag=wx.EXPAND, pos=(3, 0))
+
+            self.textentry.Bind(wx.EVT_TEXT, self.OnEncoding)
+
+        elif self.type == 'outputfont':
+            self.font = self.settings.Get(group='display',
+                                              key='outputfont', subkey='type')
+            self.fontsize = self.settings.Get(group='display',
+                                          key='outputfont', subkey='size')
+            label = wx.StaticText(parent=panel, id=wx.ID_ANY,
+                              label=("Font size:"))
+            gridSizer.Add(item=label,
                       flag=wx.ALIGN_CENTER_VERTICAL,
-                      pos=(1, 0))
+                      pos=(2, 0))
+                      
+            self.spin = wx.SpinCtrl(parent=panel, id=wx.ID_ANY)
+            if self.fontsize:
+                self.spin.SetValue(self.fontsize)
+            self.spin.Bind(wx.EVT_SPINCTRL, self.OnSizeSpin)
+            self.spin.Bind(wx.EVT_TEXT, self.OnSizeSpin)
+            gridSizer.Add(item=self.spin,
+                      flag=wx.ALIGN_CENTER_VERTICAL,
+                      pos=(3, 0))
 
-        self.textentry = wx.TextCtrl(parent=panel, id=wx.ID_ANY,
-                                     value=self.encoding)
-        gridSizer.Add(item=self.textentry,
-                flag=wx.EXPAND, pos=(1, 1))
+        else: 
+            return
 
-        self.textentry.Bind(wx.EVT_TEXT, self.OnEncoding)
+        if self.font:
+            self.fontlb.SetStringSelection(self.font, True)
 
         sizer.Add(item=gridSizer, proportion=1,
                   flag=wx.EXPAND | wx.ALL,
@@ -2026,7 +2069,11 @@
     def EvtListBoxDClick(self, event):
         self.font = event.GetString()
         event.Skip()
-
+        
+    def OnSizeSpin(self, event):
+        self.fontsize = self.spin.GetValue()
+        event.Skip()
+    
     def GetFonts(self):
         """
         parses fonts directory or fretypecap file to get a list of fonts for the listbox



More information about the grass-commit mailing list