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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jul 1 08:29:22 EDT 2009


Author: martinl
Date: 2009-07-01 08:29:20 -0400 (Wed, 01 Jul 2009)
New Revision: 38141

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
Log:
wxGUI: statusbar projection settings (part 1)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py	2009-07-01 11:54:40 UTC (rev 38140)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py	2009-07-01 12:29:20 UTC (rev 38141)
@@ -1412,38 +1412,21 @@
         
     def OnBrowseCodes(self, event, search=None):
         """!Browse EPSG codes"""
-#        try:
-        if True:
-            data = []
-            self.epsgCodeDict = {}
-            f = open(self.tfile.GetValue(), "r")
-            i = 0
-            code = None
-            for line in f.readlines():
-                line = line.strip()
-                if len(line) < 1:
-                    continue
-                
-                if line[0] == '#':
-                    descr = line[1:].strip()
-                elif line[0] == '<':
-                    code, params = line.split(" ", 1)
-                    code = int(code.replace('<', '').replace('>', ''))
+        self.epsgCodeDict = utils.ReadEpsgCodes(self.tfile.GetValue())
+        if type(self.epsgCodeDict) == type(''):
+            wx.MessageBox(parent=self,
+                          message=_("Unable to read EPGS codes: %s") % self.epsgCodeDict,
+                          caption=_("Error"),  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+            self.epsglist.Populate([], update=True)
+            return
 
-                if code is not None:
-                    data.append((code, descr, params))
-                    self.epsgCodeDict[code] = (descr, params)
-                    code = None
-                i += 1
-            f.close()
-
-            self.epsglist.Populate(data, update=True)
-#         except StandardError, e:
-#             wx.MessageBox(parent=self,
-#                           message=_("Unable to read EPGS codes: %s") % e,
-#                           caption=_("Error"),  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
-#             self.epsglist.Populate([], update=True)
-
+        data = []
+        for code, val in self.epsgCodeDict.iteritems():
+            if code is not None:
+                data.append((code, val[0], val[1]))
+                
+        self.epsglist.Populate(data, update=True)
+        
 class CustomPage(TitledPage):
     """
     Wizard page for entering custom PROJ.4 string

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2009-07-01 11:54:40 UTC (rev 38140)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2009-07-01 12:29:20 UTC (rev 38141)
@@ -549,11 +549,39 @@
                 self.statusbar.SetStatusText("%.2f, %.2f (seg: %.2f; tot: %.2f)" % \
                                                  (e, n, distance_seg, distance_tot), 0)
             else:
-                if self.Map.projinfo['proj'] == 'll':
-                    self.statusbar.SetStatusText("%s" % utils.Deg2DMS(e, n), 0)
+                if UserSettings.Get(group='display', key='projection', subkey='enabled') and \
+                        UserSettings.Get(group='display', key='projection', subkey='proj4'):
+                    projIn = gcmd.RunCommand('g.proj',
+                                             flags = 'jf',
+                                             read = True)
+                    projOut = UserSettings.Get(group='display',
+                                               key='projection',
+                                               subkey='proj4').replace('<>', '').strip()
+                    coors = gcmd.RunCommand('m.proj',
+                                            proj_in = projIn,
+                                            proj_out = projOut,
+                                            stdin = '%f|%f' % (e, n),
+                                            read = True)
+                    if coors:
+                        coors = coors.split('\t')
+                        e = coors[0]
+                        n = coors[1].split(' ')[0].strip()
+                        try:
+                            proj = projOut.split(' ')[0].split('=')[1]
+                        except IndexError:
+                            proj = ''
+                        if proj in ('ll', 'latlong', 'longlat'):
+                            self.statusbar.SetStatusText("%s %s" % (e, n), 0)
+                        else:
+                            self.statusbar.SetStatusText("%.2f, %.2f" % (float(e), float(n)), 0)
+                    else:
+                        self.statusbar.SetStatusText(_("Error in projection"), 0)
                 else:
-                    self.statusbar.SetStatusText("%.2f, %.2f" % (e, n), 0)
-        
+                    if self.Map.projinfo['proj'] == 'll':
+                        self.statusbar.SetStatusText("%s" % utils.Deg2DMS(e, n), 0)
+                    else:
+                        self.statusbar.SetStatusText("%.2f, %.2f" % (e, n), 0)
+                
         event.Skip()
 
     def OnDraw(self, event):

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2009-07-01 11:54:40 UTC (rev 38140)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2009-07-01 12:29:20 UTC (rev 38141)
@@ -112,7 +112,12 @@
                     },
                 'bgcolor': {
                     'color' : (255, 255, 255, 255),
-                    }
+                    },
+                'projection' : {
+                    'enabled' : False,
+                    'proj4'   : '',
+                    'epsg'    : '',
+                    },
                 },
             #
             # advanced
@@ -1007,6 +1012,9 @@
         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)
 
+        #
+        # display settings
+        #
         box   = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Default display settings"))
         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
 
@@ -1122,11 +1130,94 @@
 
         sizer.Add(item=gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
         border.Add(item=sizer, proportion=0, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
+
+        #
+        # projections statusbar settings
+        #
+        box   = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Projection statusbar settings"))
+        sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
+
+        gridSizer = wx.GridBagSizer (hgap=3, vgap=3)
+        gridSizer.AddGrowableCol(1)
+
+        row = 0
+        useProj = wx.CheckBox(parent=panel, id=wx.ID_ANY,
+                              label=_("Use defined projection"),
+                              name="IsChecked")
+        useProj.SetValue(self.settings.Get(group='display', key='projection', subkey='enabled'))
+        self.winId['display:projection:enabled'] = useProj.GetId()
+
+        gridSizer.Add(item=useProj,
+                      pos=(row, 0), span=(1, 3))
+
+        # epsg
+        row += 1
+        label = wx.StaticText(parent=panel, id=wx.ID_ANY,
+                              label=_("EPSG code:"))
+        epsgCode = wx.ComboBox(parent=panel, id=wx.ID_ANY,
+                               name="GetStringSelection",
+                               size = (150, -1))
+        self.epsgCodeDict = dict()
+        epsgCode.SetStringSelection(self.settings.Get(group='display', key='projection', subkey='epsg'))
+        self.winId['display:projection:epgs'] = epsgCode.GetId()
         
+        gridSizer.Add(item=label,
+                      pos=(row, 0),
+                      flag = wx.ALIGN_CENTER_VERTICAL)
+        gridSizer.Add(item=epsgCode,
+                      pos=(row, 1), span=(1, 2))
+        
+        # proj
+        row += 1
+        label = wx.StaticText(parent=panel, id=wx.ID_ANY,
+                              label=_("Proj.4 string:"))
+        projString = wx.TextCtrl(parent=panel, id=wx.ID_ANY,
+                                 value=self.settings.Get(group='display', key='projection', subkey='proj4'),
+                                 name="GetValue", size=(400, -1))
+        self.winId['display:projection:proj4'] = projString.GetId()
+
+        gridSizer.Add(item=label,
+                      pos=(row, 0),
+                      flag = wx.ALIGN_CENTER_VERTICAL)
+        gridSizer.Add(item=projString,
+                      pos=(row, 1), span=(1, 2),
+                      flag = wx.ALIGN_CENTER_VERTICAL)
+        
+        # epsg file
+        row += 1
+        label = wx.StaticText(parent=panel, id=wx.ID_ANY,
+                              label=_("EPSG file:"))
+        projFile = wx.TextCtrl(parent=panel, id=wx.ID_ANY,
+                               value=utils.PathJoin(os.environ["GRASS_PROJSHARE"], 'epsg'),
+                               name="GetValue", size=(400, -1))
+        epsgLoad = wx.Button(parent=panel, id=wx.ID_ANY,
+                             label=_("&Load EPSG codes"))
+        self.winId['display:projection:projFile'] = projFile.GetId()
+        
+        if not useProj.IsChecked():
+            projString.Enable(False)
+            epsgCode.Enable(False)
+
+        gridSizer.Add(item=label,
+                      pos=(row, 0),
+                      flag = wx.ALIGN_CENTER_VERTICAL)
+        gridSizer.Add(item=projFile,
+                      pos=(row, 1),
+                      flag = wx.ALIGN_CENTER_VERTICAL)
+        gridSizer.Add(item=epsgLoad,
+                      pos=(row, 2))
+        
+        sizer.Add(item=gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
+        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)
+        epsgLoad.Bind(wx.EVT_BUTTON, self.OnLoadEpsgCodes)
+        epsgCode.Bind(wx.EVT_COMBOBOX, self.OnSetEpsgCode)
+        epsgCode.Bind(wx.EVT_TEXT_ENTER, self.OnSetEpsgCode)
+        useProj.Bind(wx.EVT_CHECKBOX, self.OnSetProj)
         
         return panel
 
@@ -1489,6 +1580,71 @@
         
         return panel
 
+    def OnLoadEpsgCodes(self, event):
+        """!Load EPSG codes from the file"""
+        win = self.FindWindowById(self.winId['display:projection:projFile'])
+        path = win.GetValue()
+
+        self.epsgCodeDict = utils.ReadEpsgCodes(path)
+        list = self.FindWindowById(self.winId['display:projection:epgs'])
+        if type(self.epsgCodeDict) == type(''):
+            wx.MessageBox(parent=self,
+                          message=_("Unable to read EPGS codes: %s") % self.epsgCodeDict,
+                          caption=_("Error"),  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+            self.epsgCodeDict = dict()
+            list.SetItems([])
+            list.SetValue('')
+            self.FindWindowById(self.winId['display:projection:proj4']).SetValue('')
+            return
+        
+        choices = map(str, self.epsgCodeDict.keys())
+
+        list.SetItems(choices)
+        list.SetSelection(0)
+        code = int(list.GetStringSelection())
+        win = self.FindWindowById(self.winId['display:projection:proj4'])
+        win.SetValue(self.epsgCodeDict[code][1])
+
+    def OnSetProj(self, event):
+        """!Enable mapdisplay window statusbar projection"""
+        checked = event.IsChecked()
+
+        winCode = self.FindWindowById(self.winId['display:projection:epgs'])
+        winString = self.FindWindowById(self.winId['display:projection:proj4'])
+        
+        winCode.Enable(checked)
+        winString.Enable(checked)
+        
+    def OnSetEpsgCode(self, event):
+        """!EPSG code selected"""
+        winCode = self.FindWindowById(event.GetId())
+        win = self.FindWindowById(self.winId['display:projection:proj4'])
+        if not self.epsgCodeDict:
+            wx.MessageBox(parent=self,
+                          message=_("EPSG code %s not found") % str(code),
+                          caption=_("Error"),  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+            winCode.SetValue('')
+            win.SetValue('')
+        
+        try:
+            code = int(event.GetString())
+        except ValueError:
+            wx.MessageBox(parent=self,
+                          message=_("EPSG code %s not found") % str(code),
+                          caption=_("Error"),  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+            winCode.SetValue('')
+            win.SetValue('')
+        
+        
+        try:
+            win.SetValue(self.epsgCodeDict[code][1])
+        except KeyError:
+            wx.MessageBox(parent=self,
+                          message=_("EPSG code %s not found") % str(code),
+                          caption=_("Error"),  style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+            winCode.SetValue('')
+            win.SetValue('')
+        
     def OnSetFont(self, event):
         """'Set font' button pressed"""
         dlg = DefaultFontDialog(parent=self, id=wx.ID_ANY,

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2009-07-01 11:54:40 UTC (rev 38140)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2009-07-01 12:29:20 UTC (rev 38141)
@@ -375,3 +375,37 @@
             not sys.executable.endswith('MacOS/Python'):
         print >> sys.stderr, 're-executing using pythonw'
         os.execvp('pythonw', ['pythonw', __file__] + sys.argv[1:])
+
+def ReadEpsgCodes(path):
+    """!Read EPSG code from the file
+
+    @param path full path to the file with EPSG codes
+
+    @return dictionary of EPSG code
+    @return string on error
+    """
+    epsgCodeDict = dict()
+    try:
+        f = open(path, "r")
+        i = 0
+        code = None
+        for line in f.readlines():
+            line = line.strip()
+            if len(line) < 1:
+                continue
+                
+            if line[0] == '#':
+                descr = line[1:].strip()
+            elif line[0] == '<':
+                code, params = line.split(" ", 1)
+                code = int(code.replace('<', '').replace('>', ''))
+
+            if code is not None:
+                epsgCodeDict[code] = (descr, params)
+                code = None
+            i += 1
+        f.close()
+    except StandardError, e:
+        return str(e)
+    
+    return epsgCodeDict



More information about the grass-commit mailing list