瀏覽代碼

g.gui.*: define common GuiModuleMain fn

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@57388 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 11 年之前
父節點
當前提交
b2ff6d0e0d

+ 4 - 8
gui/wxpython/animation/g.gui.animation.py

@@ -63,12 +63,10 @@ if __name__ == '__main__':
 from core.settings import UserSettings
 from core.settings import UserSettings
 from core.globalvar import CheckWxVersion
 from core.globalvar import CheckWxVersion
 from core.giface import StandaloneGrassInterface
 from core.giface import StandaloneGrassInterface
-from core.utils import _
+from core.utils import _, GuiModuleMain
 from animation.frame import AnimationFrame, MAX_COUNT
 from animation.frame import AnimationFrame, MAX_COUNT
 
 
 def main():
 def main():
-    options, flags = grass.parser()
-
     rast = options['rast']
     rast = options['rast']
     vect = options['vect']
     vect = options['vect']
     strds = options['strds']
     strds = options['strds']
@@ -114,8 +112,6 @@ def main():
     app.MainLoop()
     app.MainLoop()
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
-    # launch GUI in the background
-    child_pid = os.fork()
-    if child_pid == 0:
-        main()
-    os._exit(0)
+    options, flags = grass.parser()
+    
+    GuiModuleMain(main)

+ 12 - 1
gui/wxpython/core/utils.py

@@ -3,7 +3,7 @@
 
 
 @brief Misc utilities for wxGUI
 @brief Misc utilities for wxGUI
 
 
-(C) 2007-2009, 2011-2012 by the GRASS Development Team
+(C) 2007-2013 by the GRASS Development Team
 
 
 This program is free software under the GNU General Public License
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
 (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -1044,3 +1044,14 @@ def GetGEventAttribsForHandler(method, event):
             missing_args.append(a)
             missing_args.append(a)
 
 
     return kwargs, missing_args
     return kwargs, missing_args
+
+def GuiModuleMain(mainfn):
+    """!Main function for g.gui.* modules
+
+    @param module's main function
+    """
+    # launch GUI in the background
+    child_pid = os.fork()
+    if child_pid == 0:
+        mainfn()
+    os._exit(0)

+ 3 - 7
gui/wxpython/dbmgr/g.gui.dbmgr.py

@@ -4,7 +4,7 @@
 # MODULE:    g.gui.dbmgr
 # MODULE:    g.gui.dbmgr
 # AUTHOR(S): Martin Landa <landa.martin gmail.com>
 # AUTHOR(S): Martin Landa <landa.martin gmail.com>
 # PURPOSE:   Attribute Table Manager
 # PURPOSE:   Attribute Table Manager
-# COPYRIGHT: (C) 2012 by Martin Landa, and the GRASS Development Team
+# COPYRIGHT: (C) 2012-2013 by Martin Landa, and the GRASS Development Team
 #
 #
 #  This program is free software; you can 1redistribute it and/or
 #  This program is free software; you can 1redistribute it and/or
 #  modify it under the terms of the GNU General Public License as
 #  modify it under the terms of the GNU General Public License as
@@ -39,7 +39,7 @@ gui_wx_path = os.path.join(os.getenv('GISBASE'), 'etc', 'gui', 'wxpython')
 if gui_wx_path not in sys.path:
 if gui_wx_path not in sys.path:
     sys.path.append(gui_wx_path)
     sys.path.append(gui_wx_path)
 
 
-from core.utils import _
+from core.utils import _, GuiModuleMain
 from dbmgr.manager import AttributeManager
 from dbmgr.manager import AttributeManager
 
 
 def main():
 def main():
@@ -61,8 +61,4 @@ def main():
 if __name__ == "__main__":
 if __name__ == "__main__":
     options, flags = grass.parser()
     options, flags = grass.parser()
     
     
-    # launch GUI in the background
-    child_pid = os.fork()
-    if child_pid == 0:
-        main()
-    os._exit(0)
+    GuiModuleMain(main)

+ 5 - 10
gui/wxpython/gcp/g.gui.gcp.py

@@ -47,9 +47,9 @@ if __name__ == '__main__':
 from core.settings import UserSettings
 from core.settings import UserSettings
 from core.globalvar import CheckWxVersion
 from core.globalvar import CheckWxVersion
 from core.giface import StandaloneGrassInterface
 from core.giface import StandaloneGrassInterface
+from core.utils import GuiModuleMain
 from gcp.manager import GCPWizard
 from gcp.manager import GCPWizard
 
 
-
 def main():
 def main():
     """!Sets the GRASS display driver
     """!Sets the GRASS display driver
 
 
@@ -60,9 +60,7 @@ def main():
         os.environ['GRASS_RENDER_IMMEDIATE'] = 'png'
         os.environ['GRASS_RENDER_IMMEDIATE'] = 'png'
     else:
     else:
         os.environ['GRASS_RENDER_IMMEDIATE'] = 'cairo'
         os.environ['GRASS_RENDER_IMMEDIATE'] = 'cairo'
-
-    options, flags = grass.parser()
-
+    
     app = wx.PySimpleApp()
     app = wx.PySimpleApp()
     if not CheckWxVersion([2, 9]):
     if not CheckWxVersion([2, 9]):
         wx.InitAllImageHandlers()
         wx.InitAllImageHandlers()
@@ -71,10 +69,7 @@ def main():
 
 
     app.MainLoop()
     app.MainLoop()
 
 
-
 if __name__ == '__main__':
 if __name__ == '__main__':
-    # launch GUI in the background
-    child_pid = os.fork()
-    if child_pid == 0:
-        main()
-    os._exit(0)
+    options, flags = grass.parser()
+    
+    GuiModuleMain(main)

+ 2 - 7
gui/wxpython/gmodeler/g.gui.gmodeler.py

@@ -47,11 +47,10 @@ if gui_wx_path not in sys.path:
 
 
 from core.giface import StandaloneGrassInterface
 from core.giface import StandaloneGrassInterface
 from core.globalvar import CheckWxVersion
 from core.globalvar import CheckWxVersion
-from core.utils import _
+from core.utils import _, GuiModuleMain
 from gmodeler.frame import ModelFrame
 from gmodeler.frame import ModelFrame
 
 
 def main():
 def main():
-    
     app = wx.PySimpleApp()
     app = wx.PySimpleApp()
     if not CheckWxVersion([2, 9]):
     if not CheckWxVersion([2, 9]):
         wx.InitAllImageHandlers()
         wx.InitAllImageHandlers()
@@ -65,8 +64,4 @@ def main():
 if __name__ == "__main__":
 if __name__ == "__main__":
     options, flags = grass.parser()
     options, flags = grass.parser()
     
     
-    # launch GUI in the background
-    child_pid = os.fork()
-    if child_pid == 0:
-        main()
-    os._exit(0)
+    GuiModuleMain(main)

+ 2 - 6
gui/wxpython/iclass/g.gui.iclass.py

@@ -62,7 +62,7 @@ if __name__ == '__main__':
 from core.settings  import UserSettings
 from core.settings  import UserSettings
 from core.globalvar import CheckWxVersion
 from core.globalvar import CheckWxVersion
 from core.giface    import StandaloneGrassInterface
 from core.giface    import StandaloneGrassInterface
-from core.utils import _
+from core.utils     import _, GuiModuleMain
 from iclass.frame   import IClassMapFrame
 from iclass.frame   import IClassMapFrame
 
 
 def main():
 def main():
@@ -116,8 +116,4 @@ if __name__ == '__main__':
     grass.set_raise_on_error(False)
     grass.set_raise_on_error(False)
     options, flags = grass.parser()
     options, flags = grass.parser()
     
     
-    # launch GUI in the background
-    child_pid = os.fork()
-    if child_pid == 0:
-        main()
-    os._exit(0)
+    GuiModuleMain(main)

+ 5 - 10
gui/wxpython/mapswipe/g.gui.mapswipe.py

@@ -60,7 +60,7 @@ if __name__ == '__main__':
 from core.settings import UserSettings
 from core.settings import UserSettings
 from core.globalvar import CheckWxVersion
 from core.globalvar import CheckWxVersion
 from core.giface import StandaloneGrassInterface
 from core.giface import StandaloneGrassInterface
-from core.utils import _
+from core.utils import _, GuiModuleMain
 from mapswipe.frame import SwipeMapFrame
 from mapswipe.frame import SwipeMapFrame
 
 
 
 
@@ -70,9 +70,7 @@ def main():
         os.environ['GRASS_RENDER_IMMEDIATE'] = 'png'
         os.environ['GRASS_RENDER_IMMEDIATE'] = 'png'
     else:
     else:
         os.environ['GRASS_RENDER_IMMEDIATE'] = 'cairo'
         os.environ['GRASS_RENDER_IMMEDIATE'] = 'cairo'
-
-    options, flags = grass.parser()
-
+    
     first = options['first']
     first = options['first']
     second = options['second']
     second = options['second']
     mode = options['mode']
     mode = options['mode']
@@ -101,10 +99,7 @@ def main():
 
 
     app.MainLoop()
     app.MainLoop()
 
 
-
 if __name__ == '__main__':
 if __name__ == '__main__':
-    # launch GUI in the background
-    child_pid = os.fork()
-    if child_pid == 0:
-        main()
-    os._exit(0)
+    options, flags = grass.parser()
+    
+    GuiModuleMain(main)

+ 2 - 9
gui/wxpython/psmap/g.gui.psmap.py

@@ -44,13 +44,11 @@ if wxbase not in sys.path:
     sys.path.append(wxbase)
     sys.path.append(wxbase)
 
 
 from core.globalvar import CheckWxVersion
 from core.globalvar import CheckWxVersion
-from core.utils import _
+from core.utils     import _, GuiModuleMain
 from psmap.frame        import PsMapFrame
 from psmap.frame        import PsMapFrame
 from psmap.instructions import Instruction
 from psmap.instructions import Instruction
 
 
 def main():
 def main():
-    gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
-    
     app = wx.PySimpleApp()
     app = wx.PySimpleApp()
     if not CheckWxVersion([2, 9]):
     if not CheckWxVersion([2, 9]):
         wx.InitAllImageHandlers()
         wx.InitAllImageHandlers()
@@ -65,9 +63,4 @@ def main():
 if __name__ == "__main__":
 if __name__ == "__main__":
     options, flags = grass.parser()
     options, flags = grass.parser()
     
     
-    # launch GUI in the background
-    child_pid = os.fork()
-    if child_pid == 0:
-        main()
-    os._exit(0)
-
+    GuiModuleMain(main)

+ 4 - 8
gui/wxpython/rlisetup/g.gui.rlisetup.py

@@ -36,9 +36,9 @@ wxbase = os.path.join(os.getenv('GISBASE'), 'etc', 'gui', 'wxpython')
 if wxbase not in sys.path:
 if wxbase not in sys.path:
     sys.path.append(wxbase)
     sys.path.append(wxbase)
 
 
-from core.giface import StandaloneGrassInterface
+from core.giface    import StandaloneGrassInterface
 from core.globalvar import CheckWxVersion
 from core.globalvar import CheckWxVersion
-from core.utils import _
+from core.utils     import _, GuiModuleMain
 from rlisetup.frame import RLiSetupFrame
 from rlisetup.frame import RLiSetupFrame
 
 
 
 
@@ -53,9 +53,5 @@ def main():
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
     options, flags = grass.parser()
     options, flags = grass.parser()
-    
-    # launch GUI in the background
-    child_pid = os.fork()
-    if child_pid == 0:
-        main()
-    os._exit(0)
+
+    GuiModuleMain(main)

+ 15 - 18
gui/wxpython/vdigit/g.gui.vdigit.py

@@ -4,7 +4,7 @@
 # MODULE:    g.gui.vdigit
 # MODULE:    g.gui.vdigit
 # AUTHOR(S): Martin Landa <landa.martin gmail.com>
 # AUTHOR(S): Martin Landa <landa.martin gmail.com>
 # PURPOSE:   wxGUI Vector Digitizer
 # PURPOSE:   wxGUI Vector Digitizer
-# COPYRIGHT: (C) 2007-2012 by Martin Landa, and the GRASS Development Team
+# COPYRIGHT: (C) 2007-2013 by Martin Landa, and the GRASS Development Team
 #
 #
 #  This program is free software; you can 1redistribute it and/or
 #  This program is free software; you can 1redistribute it and/or
 #  modify it under the terms of the GNU General Public License as
 #  modify it under the terms of the GNU General Public License as
@@ -43,11 +43,11 @@ if __name__ == '__main__':
         sys.path.append(gui_wx_path)
         sys.path.append(gui_wx_path)
 
 
 from core.globalvar import CheckWxVersion
 from core.globalvar import CheckWxVersion
-from core.utils import _
-from mapdisp.frame import MapFrame
-from core.giface   import StandaloneGrassInterface
-from core.settings import UserSettings
-from vdigit.main   import haveVDigit, errorMsg
+from core.utils     import _, GuiModuleMain
+from mapdisp.frame  import MapFrame
+from core.giface    import StandaloneGrassInterface
+from core.settings  import UserSettings
+from vdigit.main    import haveVDigit, errorMsg
 
 
 class VDigitMapFrame(MapFrame):
 class VDigitMapFrame(MapFrame):
     def __init__(self, vectorMap):
     def __init__(self, vectorMap):
@@ -67,13 +67,6 @@ class VDigitMapFrame(MapFrame):
         self.toolbars['vdigit'].StartEditing(mapLayer)
         self.toolbars['vdigit'].StartEditing(mapLayer)
 
 
 def main():
 def main():
-    if not haveVDigit:
-        grass.fatal(_("Vector digitizer not available. %s") % errorMsg)
-    
-    if not grass.find_file(name = options['map'], element = 'vector',
-                           mapset = grass.gisenv()['MAPSET'])['fullname']:
-        grass.fatal(_("Vector map <%s> not found in current mapset") % options['map'])
-
     # allow immediate rendering
     # allow immediate rendering
     driver = UserSettings.Get(group = 'display', key = 'driver', subkey = 'type')
     driver = UserSettings.Get(group = 'display', key = 'driver', subkey = 'type')
     if driver == 'png':
     if driver == 'png':
@@ -91,10 +84,14 @@ def main():
     
     
 if __name__ == "__main__":
 if __name__ == "__main__":
     grass.set_raise_on_error(False)
     grass.set_raise_on_error(False)
+    
     options, flags = grass.parser()
     options, flags = grass.parser()
     
     
-    # launch GUI in the background
-    child_pid = os.fork()
-    if child_pid == 0:
-        main()
-    os._exit(0)
+    if not haveVDigit:
+        grass.fatal(_("Vector digitizer not available. %s") % errorMsg)
+    
+    if not grass.find_file(name = options['map'], element = 'vector',
+                           mapset = grass.gisenv()['MAPSET'])['fullname']:
+        grass.fatal(_("Vector map <%s> not found in current mapset") % options['map'])
+    
+    GuiModuleMain(main)