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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Sep 6 08:59:12 EDT 2008


Author: martinl
Date: 2008-09-06 08:59:12 -0400 (Sat, 06 Sep 2008)
New Revision: 33299

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/histogram.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
Log:
wxGUI: bugfix - trac #291 - font settings not saved


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/histogram.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/histogram.py	2008-09-06 12:08:37 UTC (rev 33298)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/histogram.py	2008-09-06 12:59:12 UTC (rev 33299)
@@ -36,7 +36,7 @@
 import menuform
 import disp_print
 import utils
-from gui_modules.preferences import SetDefaultFont as SetDefaultFont
+from gui_modules.preferences import DefaultFontDialog as DefaultFontDialog
 from debug import Debug as Debug
 from icon import Icons as Icons
 
@@ -413,11 +413,12 @@
         set, font will be default display font.
         """
 
-        dlg = SetDefaultFont(self, wx.ID_ANY, 'Select font for histogram text',
-                             pos=wx.DefaultPosition, size=wx.DefaultSize,
-                             style=wx.DEFAULT_DIALOG_STYLE,
-                             encoding=self.encoding)
+        dlg = DefaultFontDialog(parent=self, id=wx.ID_ANY,
+                                title=_('Select font for histogram text'),
+                                encoding=self.encoding)
+        
         dlg.fontlb.SetStringSelection(self.font, True)
+        
         if dlg.ShowModal() == wx.ID_CANCEL:
             dlg.Destroy()
             return

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2008-09-06 12:08:37 UTC (rev 33298)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2008-09-06 12:59:12 UTC (rev 33299)
@@ -7,7 +7,7 @@
 
 Classes:
  - PreferencesDialog
- - SetDefaultFont
+ - DefaultFontDialog
  - MapsetAccess
 
 (C) 2007-2008 by the GRASS Development Team
@@ -84,8 +84,9 @@
             # display
             #
             'display': {
-                'displayFont' : {
-                    'value' : ''
+                'font' : {
+                    'type' : '',
+                    'encoding': 'ISO-8859-1',
                     },
                 'driver': {
                     'type': 'default'
@@ -564,6 +565,12 @@
         if self.filePath:
             self.__ReadFile(self.filePath, settings)
         
+        # set environment variables
+        os.environ["GRASS_FONT"] = self.Get(group='display',
+                                            key='font', subkey='type')
+        os.environ["GRASS_ENCODING"] = self.Get(group='display',
+                                                key='font', subkey='encoding')
+        
     def __ReadFile(self, filename, settings=None):
         """Read settings from file to dict"""
         if settings is None:
@@ -1443,30 +1450,27 @@
 
     def OnSetFont(self, event):
         """'Set font' button pressed"""
-        dlg = SetDefaultFont(parent=self, id=wx.ID_ANY,
-                             title=_('Select default display font'),
-                             pos=wx.DefaultPosition, size=wx.DefaultSize,
-                             style=wx.DEFAULT_DIALOG_STYLE,
-                             encoding=self.parent.encoding)
-        if dlg.ShowModal() == wx.ID_CANCEL:
-            dlg.Destroy()
-            return
+        dlg = DefaultFontDialog(parent=self, id=wx.ID_ANY,
+                                title=_('Select default display font'),
+                                style=wx.DEFAULT_DIALOG_STYLE)
+        
+        if dlg.ShowModal() == wx.ID_OK:
+            # set default font and encoding environmental variables
+            if dlg.font:
+                os.environ["GRASS_FONT"] = dlg.font
+                self.settings.Set(group='display', value=dlg.font,
+                                  key='font', subkey='type')
 
-        # set default font type, font, and encoding to whatever selected in dialog
-        if dlg.font != None:
-            self.font = dlg.font
-        if dlg.encoding != None:
-            self.encoding = dlg.encoding
-
+            if dlg.encoding and \
+                    dlg.encoding != "ISO-8859-1":
+                os.environ["GRASS_ENCODING"] = dlg.encoding
+                self.settings.Set(group='display', value=dlg.encoding,
+                                  key='font', subkey='encoding')
+                
         dlg.Destroy()
-
-        # set default font and encoding environmental variables
-        os.environ["GRASS_FONT"] = self.font
-        if self.encoding != None and self.encoding != "ISO-8859-1":
-            os.environ["GRASS_ENCODING"] = self.encoding
-
+        
         event.Skip()
-
+        
     def OnSave(self, event):
         """Button 'Save' pressed"""
         if self.__UpdateSettings():
@@ -1563,66 +1567,96 @@
 
         return True
 
-class SetDefaultFont(wx.Dialog):
+class DefaultFontDialog(wx.Dialog):
     """
     Opens a file selection dialog to select default font
     to use in all GRASS displays
     """
-    def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize,
-            style=wx.DEFAULT_DIALOG_STYLE, encoding='ISO-8859-1'):
+    def __init__(self, parent, id, title,
+                 pos=wx.DefaultPosition, size=wx.DefaultSize,
+                 style=wx.DEFAULT_DIALOG_STYLE,
+                 settings=globalSettings):
+        
+        self.settings = settings
+        
         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 = None
+            self.font = self.settings.Get(group='display',
+                                          key='font', subkey='type')
 
         self.fontlist = self.GetFonts()
 
-        self.encoding = encoding
+        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"))
+        sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
 
-        sizer = wx.BoxSizer(wx.VERTICAL)
+        gridSizer = wx.GridBagSizer (hgap=5, vgap=5)
+        gridSizer.AddGrowableCol(0)
 
-        box = wx.BoxSizer(wx.HORIZONTAL)
-        label = wx.StaticText(self, -1, "Select Font:", (15, 50))
-        box.Add(label, 0, wx.EXPAND|wx.GROW|wx.ALIGN_TOP|wx.RIGHT, 5)
-        self.fontlb = wx.ListBox(self, wx.ID_ANY, pos=wx.DefaultPosition,
-                                 size=(280,150), choices=self.fontlist,
+        label = wx.StaticText(parent=panel, id=wx.ID_ANY,
+                              label=_("Select font:"))
+        gridSizer.Add(item=label,
+                      flag=wx.ALIGN_TOP,
+                      pos=(0,0))
+        
+        self.fontlb = wx.ListBox(parent=panel, id=wx.ID_ANY, pos=wx.DefaultPosition,
+                                 choices=self.fontlist,
                                  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)
-        box.Add(self.fontlb, 0, wx.EXPAND|wx.GROW|wx.ALIGN_RIGHT)
-        sizer.Add(box, 0, wx.EXPAND|wx.GROW|wx.ALIGN_RIGHT|wx.ALL, 8)
 
-        box = wx.BoxSizer(wx.HORIZONTAL)
-        label = wx.StaticText(self, -1, "Character encoding:")
-        box.Add(label, 0, wx.ALIGN_RIGHT|wx.RIGHT, 5)
-        self.textentry = wx.TextCtrl(self, -1, "", size=(200,-1))
-        self.textentry.SetValue(self.encoding)
-        box.Add(self.textentry, 0, wx.ALIGN_LEFT)
+        gridSizer.Add(item=self.fontlb,
+                flag=wx.EXPAND, pos=(0, 1))
+
+        label = wx.StaticText(parent=panel, id=wx.ID_ANY,
+                              label=("Character encoding:"))
+        gridSizer.Add(item=label,
+                      flag=wx.ALIGN_CENTER_VERTICAL,
+                      pos=(1, 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))
+
         self.textentry.Bind(wx.EVT_TEXT, self.OnEncoding)
-        sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 8)
 
-        line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
-        sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 10)
+        sizer.Add(item=gridSizer, proportion=1,
+                  flag=wx.EXPAND | wx.ALL,
+                  border=5)
 
+        border.Add(item=sizer, proportion=1,
+                   flag=wx.ALL | wx.EXPAND, border=3)
+        
         btnsizer = wx.StdDialogButtonSizer()
 
-        btn = wx.Button(self, wx.ID_OK)
+        btn = wx.Button(parent=panel, id=wx.ID_OK)
         btn.SetDefault()
         btnsizer.AddButton(btn)
 
-        btn = wx.Button(self, wx.ID_CANCEL)
+        btn = wx.Button(parent=panel, id=wx.ID_CANCEL)
         btnsizer.AddButton(btn)
         btnsizer.Realize()
 
-        sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
-
-        self.SetSizer(sizer)
-        sizer.Fit(self)
-
+        border.Add(item=btnsizer, proportion=0,
+                   flag=wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border=5)
+        
+        panel.SetAutoLayout(True)
+        panel.SetSizer(border)
+        border.Fit(self)
+        
+        self.Layout()
+        
     def EvtRadioBox(self, event):
         if event.GetInt() == 0:
             self.fonttype = 'grassfont'



More information about the grass-commit mailing list