Browse Source

wxGUI: clean up - gettext and __main__

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@47386 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 years ago
parent
commit
03e35c7f3f

+ 9 - 15
gui/wxpython/gui_modules/dbm.py

@@ -35,10 +35,6 @@ import tempfile
 import copy
 import types
 
-### i18N
-import gettext
-gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
-
 import globalvar
 import wx
 import wx.lib.mixins.listctrl as listmix
@@ -3049,30 +3045,28 @@ class LayerBook(wx.Notebook):
 
         event.Skip()
 
-def main(argv=None):
+def main(argv = None):
+    import gettext
+    gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
+    
     if argv is None:
         argv = sys.argv
-
+    
     if len(argv) != 2:
         print >> sys.stderr, __doc__
         sys.exit()
-
-    # Command line arguments of the script to be run are preserved by the
-    # hotswap.py wrapper but hotswap.py and its options are removed that
-    # sys.argv looks as if no wrapper was present.
-    #print "argv:", `argv`
-
+    
     #some applications might require image handlers
     wx.InitAllImageHandlers()
-
+    
     app = wx.PySimpleApp()
     f = AttributeManager(parent=None, id=wx.ID_ANY,
                          title="%s - <%s>" % (_("GRASS GIS Attribute Table Manager"),
                                               argv[1]),
                          size=(900,600), vectorName=argv[1])
     f.Show()
-
+    
     app.MainLoop()
-
+    
 if __name__ == '__main__':
     main()

+ 2 - 1
gui/wxpython/gui_modules/ghelp.py

@@ -23,6 +23,7 @@ This program is free software under the GNU General Public License
 """
 
 import os
+import codecs
 
 import wx
 try:
@@ -667,7 +668,7 @@ class AboutWindow(wx.Frame):
         """Contributors info"""
         contribfile = os.path.join(os.getenv("GISBASE"), "contributors.csv")
         if os.path.exists(contribfile):
-            contribFile = open(contribfile, 'r')
+            contribFile = codecs.open(contribfile, encoding = 'utf-8', mode = 'r')
             contribs = dict()
             errLines = list()
             for line in contribFile.readlines():

+ 0 - 3
gui/wxpython/gui_modules/globalvar.py

@@ -20,9 +20,6 @@ import locale
 
 if not os.getenv("GISBASE"):
     sys.exit("GRASS is not running. Exiting...")
-### i18N
-import gettext
-gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
 
 # path to python scripts
 ETCDIR = os.path.join(os.getenv("GISBASE"), "etc")

+ 3 - 0
gui/wxpython/gui_modules/gmodeler.py

@@ -4546,6 +4546,9 @@ if __name__ == "__main__":
 
         
 def main():
+    import gettext
+    gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
+    
     app = wx.PySimpleApp()
     wx.InitAllImageHandlers()
     frame = ModelFrame(parent = None)

+ 0 - 8
gui/wxpython/gui_modules/location_wizard.py

@@ -2668,11 +2668,3 @@ class SelectTransformDialog(wx.Dialog):
         self.transnum = self.translist.GetSelection()
         self.transnum = self.transnum - 1
         return self.transnum
-
-if __name__ == "__main__":
-    import gettext
-    gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
-    app = wx.PySimpleApp()
-    gWizard = RegionDef(None)
-    gWizzard.Show()
-    app.MainLoop()

+ 3 - 1
gui/wxpython/gui_modules/mcalc_builder.py

@@ -578,8 +578,10 @@ class MapCalcFrame(wx.Frame):
         menuform.GUI(parent = self).ParseCommand(cmd = [self.cmd, 'expression=' + expr])
         
 if __name__ == "__main__":
+    import gettext
+    gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
+    
     app = wx.App(0)
     frame = MapCalcFrame(parent = None, cmd = 'r.mapcalc')
     frame.Show()
     app.MainLoop()
-

+ 4 - 5
gui/wxpython/gui_modules/menuform.py

@@ -57,10 +57,6 @@ from threading import Thread
 import Queue
 import tempfile
 
-### i18N
-import gettext
-gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
-
 import globalvar
 import wx
 import wx.html
@@ -2083,9 +2079,12 @@ class GNotebook(FN.FlatNotebook):
         return self.GetPageIndex(self.notebookPages[page])
     
 if __name__ ==  "__main__":
-
+    import gettext
+    gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
+    
     if len(sys.argv) ==  1:
         sys.exit(_("usage: %s <grass command>") % sys.argv[0])
+    
     if sys.argv[1] !=  'test':
         q = wx.LogNull()
         cmd = utils.split(sys.argv[1])

+ 0 - 4
gui/wxpython/gui_modules/preferences.py

@@ -37,10 +37,6 @@ try:
 except ImportError:
     havePwd = False
 
-### i18N
-import gettext
-gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
-
 import wx
 import wx.lib.filebrowsebutton as filebrowse
 import wx.lib.colourselect as csel

+ 3 - 0
gui/wxpython/gui_modules/psmap.py

@@ -1647,6 +1647,9 @@ class PsMapBufferedWindow(wx.Window):
                        rect.GetSize()[0]*scale, rect.GetSize()[1]*scale)   
     
 def main():
+    import gettext
+    gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
+    
     app = wx.PySimpleApp()
     wx.InitAllImageHandlers()
     frame = PsMapFrame()

+ 10 - 18
gui/wxpython/gui_modules/render.py

@@ -1328,30 +1328,22 @@ class Map(object):
                 layer.Render()
                 
 if __name__ == "__main__":
-    """!Test of Display class.
-    Usage: display=Render()
-    """
     import gettext
     gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
     
-    print "Initializing..."
-    grass.run_command("g.region", flags = "d")
-    
-    map = Map()
-    map.width = 640
-    map.height = 480
+    Map = Map()
+    Map.GetRegion(update = True)
     
-    map.AddLayer(type = "raster",
-                 name = "elevation.dem",
-                 command = ["d.rast", "elevation.dem@PERMANENT", "catlist=1000-1500", "-i"],
+    Map.AddLayer(type = "raster",
+                 name = "elevation",
+                 command = ["d.rast", "map=elevation@PERMANENT"],
                  l_opacity = .7)
     
-    map.AddLayer(type = "vector",
-                 name = "streams",
-                 command = ["d.vect", "streams@PERMANENT", "color=red", "width=3", "type=line"])
+    Map.AddLayer(type = "vector",
+                 name = "roadsmajor",
+                 command = ["d.vect", "map=roadsmajor@PERMANENT", "color=red", "width=3", "type=line"])
     
-    image = map.Render(force = True)
+    image = Map.Render(force = True)
     
     if image:
-        os.system("display %s" % image)
-    
+        grass.call(["display", image])

+ 5 - 6
gui/wxpython/gui_modules/sqlbuilder.py

@@ -13,7 +13,7 @@ Usage:
 python sqlbuilder.py vector_map
 @endcode
 
-(C) 2007-2009 by the GRASS Development Team
+(C) 2007-2009, 2011 by the GRASS Development Team
 
 This program is free software under the GNU General Public
 License (>=v2). Read the file COPYING that comes with GRASS
@@ -28,10 +28,6 @@ import os
 import sys
 import time
 
-### i18N
-import gettext
-gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
-
 import globalvar
 import wx
 
@@ -58,7 +54,7 @@ class SQLFrame(wx.Frame):
         #
         self.vectmap = vectmap # fullname
         if not "@" in self.vectmap:
-            self.vectmap = self.vectmap + "@" + grass.gisenv()['MAPSET']
+            self.vectmap = grass.find_file(self.vectmap, element = 'vector')['fullname']
         self.mapname, self.mapset = self.vectmap.split("@")
         
         # db info
@@ -446,6 +442,9 @@ if __name__ == "__main__":
         print >>sys.stderr, __doc__
         sys.exit()
     
+    import gettext
+    gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
+    
     app = wx.App(0)
     sqlb = SQLFrame(parent = None, title = _('SQL Builder'), vectmap = sys.argv[1])
     sqlb.Show()

+ 1 - 1
gui/wxpython/icons/grass_icons.py

@@ -7,7 +7,7 @@ __author__ = "Robert Szczepanek"
 
 import os
 
-from gui_modules import globalvar
+import globalvar
 
 iconPath = os.path.join(globalvar.ETCDIR, "gui", "icons", "grass")
 

+ 4 - 3
gui/wxpython/icons/icon.py

@@ -22,11 +22,11 @@ for details.
 import os
 import sys
 
-sys.path.append(os.path.join(os.getenv("GISBASE"), "etc", "wxpython", "gui_modules"))
+sys.path.append(os.path.join(os.getenv("GISBASE"), "etc", "gui", "wxpython", "gui_modules"))
 
 import wx
 
-from gui_modules.preferences import globalSettings as UserSettings
+from preferences import globalSettings as UserSettings
 
 # default icon set
 import grass_icons
@@ -445,4 +445,5 @@ Icons = {
 # testing ...
 if __name__ == '__main__':
     for k, v in Icons.iteritems():
-        print v.GetImageName()
+        for kk, vv in v.iteritems():
+            print k, kk, vv.GetImageName()

+ 7 - 14
gui/wxpython/wxgui.py

@@ -28,17 +28,11 @@ import getopt
 import platform
 import signal
 import tempfile
-
-### XML
 try:
     import xml.etree.ElementTree as etree
 except ImportError:
     import elementtree.ElementTree as etree # Python <= 2.4
 
-### i18N
-import gettext
-gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
-
 from gui_modules import globalvar
 import wx
 import wx.aui
@@ -1715,9 +1709,9 @@ def process_opt(opts, args):
     return (workspaceFile,)
 
 def main(argv = None):
-    #
-    # process command-line arguments
-    #
+    import gettext
+    gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
+    
     if argv is None:
         argv = sys.argv
     try:
@@ -1726,19 +1720,18 @@ def main(argv = None):
                                        ["help", "workspace"])
         except getopt.error, msg:
             raise Usage(msg)
-
+    
     except Usage, err:
         print >> sys.stderr, err.msg
         print >> sys.stderr, "for help use --help"
         printHelp()
-
+    
     workspaceFile = process_opt(opts, args)[0]
-
-    # run application
+    
     app = GMApp(workspaceFile)
     # suppress wxPython logs
     q = wx.LogNull()
-
+    
     app.MainLoop()
     
 if __name__ == "__main__":