[GRASS-SVN] r39846 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 28 14:03:32 EST 2009


Author: cmbarton
Date: 2009-11-28 14:03:32 -0500 (Sat, 28 Nov 2009)
New Revision: 39846

Modified:
   grass/trunk/gui/wxpython/gui_modules/goutput.py
   grass/trunk/gui/wxpython/gui_modules/preferences.py
Log:
Backport from develbranch_6 r39845. Added ability for user to set font (typface and size) for command output console.

Modified: grass/trunk/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/goutput.py	2009-11-28 18:57:33 UTC (rev 39845)
+++ grass/trunk/gui/wxpython/gui_modules/goutput.py	2009-11-28 19:03:32 UTC (rev 39846)
@@ -34,6 +34,7 @@
 import globalvar
 import gcmd
 import utils
+import preferences
 import menuform
 from debug import Debug as Debug
 from preferences import globalSettings as UserSettings
@@ -257,6 +258,9 @@
         @param style text style (see GMStc)
         @param stdout write to stdout or stderr
         """
+
+        self.cmd_output.SetStyle()
+
         if switchPage and \
                 self._notebook.GetSelection() != self.parent.goutput.pageid:
             self._notebook.SetSelection(self.parent.goutput.pageid)
@@ -749,35 +753,9 @@
 
         #
         # styles
-        #
-        self.StyleDefault     = 0
-        self.StyleDefaultSpec = "face:Courier New,size:10,fore:#000000,back:#FFFFFF"
-        self.StyleCommand     = 1
-        self.StyleCommandSpec = "face:Courier New,size:10,fore:#000000,back:#bcbcbc"
-        self.StyleOutput      = 2
-        self.StyleOutputSpec  = "face:Courier New,size:10,fore:#000000,back:#FFFFFF"
-        # fatal error
-        self.StyleError       = 3
-        self.StyleErrorSpec   = "face:Courier New,size:10,fore:#7F0000,back:#FFFFFF"
-        # warning
-        self.StyleWarning     = 4
-        self.StyleWarningSpec = "face:Courier New,size:10,fore:#0000FF,back:#FFFFFF"
-        # message
-        self.StyleMessage     = 5
-        self.StyleMessageSpec = "face:Courier New,size:10,fore:#000000,back:#FFFFFF"
-        # unknown
-        self.StyleUnknown     = 6
-        self.StyleUnknownSpec = "face:Courier New,size:10,fore:#000000,back:#FFFFFF"
+        #                
+        self.SetStyle()
         
-        # default and clear => init
-        self.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, self.StyleDefaultSpec)
-        self.StyleClearAll()
-        self.StyleSetSpec(self.StyleCommand, self.StyleCommandSpec)
-        self.StyleSetSpec(self.StyleOutput,  self.StyleOutputSpec)
-        self.StyleSetSpec(self.StyleError,   self.StyleErrorSpec)
-        self.StyleSetSpec(self.StyleWarning, self.StyleWarningSpec)
-        self.StyleSetSpec(self.StyleMessage, self.StyleMessageSpec)
-        self.StyleSetSpec(self.StyleUnknown, self.StyleUnknownSpec)
 
         #
         # line margins
@@ -805,7 +783,48 @@
         # bindins
         #
         self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
+        
+    def SetStyle(self):
+        """!Set styles for styled text output windows with type face 
+        and point size selected by user (Courier New 10 is default)"""
 
+        settings = preferences.Settings()
+        
+        self.typeface = settings.Get(group='display', key='outputfont', subkey='type')   
+        if self.typeface == "": self.typeface = "Courier New"
+                           
+        self.typesize = settings.Get(group='display', key='outputfont', subkey='size')
+        if self.typesize == None or self.typesize <= 0: self.typesize = 10
+
+        self.StyleDefault     = 0
+        self.StyleDefaultSpec = "face:%s,size:%d,fore:#000000,back:#FFFFFF" % (self.typeface, self.typesize)
+        self.StyleCommand     = 1
+        self.StyleCommandSpec = "face:%s,size:%d,,fore:#000000,back:#bcbcbc" % (self.typeface, self.typesize)
+        self.StyleOutput      = 2
+        self.StyleOutputSpec  = "face:%s,size:%d,,fore:#000000,back:#FFFFFF" % (self.typeface, self.typesize)
+        # fatal error
+        self.StyleError       = 3
+        self.StyleErrorSpec   = "face:%s,size:%d,,fore:#7F0000,back:#FFFFFF" % (self.typeface, self.typesize)
+        # warning
+        self.StyleWarning     = 4
+        self.StyleWarningSpec = "face:%s,size:%d,,fore:#0000FF,back:#FFFFFF" % (self.typeface, self.typesize)
+        # message
+        self.StyleMessage     = 5
+        self.StyleMessageSpec = "face:%s,size:%d,,fore:#000000,back:#FFFFFF" % (self.typeface, self.typesize)
+        # unknown
+        self.StyleUnknown     = 6
+        self.StyleUnknownSpec = "face:%s,size:%d,,fore:#000000,back:#FFFFFF" % (self.typeface, self.typesize)
+        
+        # default and clear => init
+        self.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, self.StyleDefaultSpec)
+        self.StyleClearAll()
+        self.StyleSetSpec(self.StyleCommand, self.StyleCommandSpec)
+        self.StyleSetSpec(self.StyleOutput,  self.StyleOutputSpec)
+        self.StyleSetSpec(self.StyleError,   self.StyleErrorSpec)
+        self.StyleSetSpec(self.StyleWarning, self.StyleWarningSpec)
+        self.StyleSetSpec(self.StyleMessage, self.StyleMessageSpec)
+        self.StyleSetSpec(self.StyleUnknown, self.StyleUnknownSpec)        
+
     def OnDestroy(self, evt):
         """!The clipboard contents can be preserved after
         the app has exited"""

Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2009-11-28 18:57:33 UTC (rev 39845)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2009-11-28 19:03:32 UTC (rev 39846)
@@ -95,6 +95,10 @@
                     'type' : '',
                     'encoding': 'ISO-8859-1',
                     },
+                'outputfont' : {
+                    'type' : 'Courier New',
+                    'size': '10',
+                    },
                 'driver': {
                     'type': 'cairo'
                     },
@@ -850,7 +854,7 @@
 
         # dict for window ids
         self.winId = {}
-
+        
         # create notebook pages
         self.__CreateGeneralPage(notebook)
         self.__CreateDisplayPage(notebook)
@@ -997,6 +1001,7 @@
 
     def __CreateDisplayPage(self, notebook):
         """!Create notebook page for display settings"""
+   
         panel = wx.Panel(parent=notebook, id=wx.ID_ANY)
         notebook.AddPage(page=panel, text=_("Display"))
 
@@ -1027,6 +1032,19 @@
         sizer.Add(item=gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
         border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
 
+        row = 1
+        gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
+                                         label=_("Font for command output:")),
+                      flag=wx.ALIGN_LEFT |
+                      wx.ALIGN_CENTER_VERTICAL,
+                      pos=(row, 0))
+        outfontButton = wx.Button(parent=panel, id=wx.ID_ANY,
+                               label=_("Set font"), size=(100, -1))
+        gridSizer.Add(item=outfontButton,
+                      flag=wx.ALIGN_RIGHT |
+                      wx.ALIGN_CENTER_VERTICAL,
+                      pos=(row, 1))
+
         #
         # display settings
         #
@@ -1138,9 +1156,10 @@
         border.Add(item=sizer, proportion=0, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
         
         panel.SetSizer(border)
-        
+                
         # bindings
         fontButton.Bind(wx.EVT_BUTTON, self.OnSetFont)
+        outfontButton.Bind(wx.EVT_BUTTON, self.OnSetOutputFont)
         
         return panel
 
@@ -1753,7 +1772,34 @@
         dlg.Destroy()
         
         event.Skip()
+
+    def OnSetOutputFont(self, event):
+        """'Set font' button pressed"""
+
+        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 = 9
         
+        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)
+
+        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')
+                
+        dlg.Destroy()
+
+        event.Skip()
+        
     def OnSave(self, event):
         """!Button 'Save' pressed"""
         if self.__UpdateSettings():
@@ -1764,6 +1810,7 @@
     def OnApply(self, event):
         """!Button 'Apply' pressed"""
         if self.__UpdateSettings():
+            self.parent.goutput.WriteLog(_('Settings applied to current session but not saved'))
             self.Close()
 
     def OnCloseWindow(self, event):



More information about the grass-commit mailing list