wxgui.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. """!
  2. @package wxgui
  3. @brief Main Python application for GRASS wxPython GUI
  4. Classes:
  5. - wxgui::GMApp
  6. - wxgui::Usage
  7. (C) 2006-2011 by the GRASS Development Team
  8. This program is free software under the GNU General Public License
  9. (>=v2). Read the file COPYING that comes with GRASS for details.
  10. @author Michael Barton (Arizona State University)
  11. @author Jachym Cepicky (Mendel University of Agriculture)
  12. @author Martin Landa <landa.martin gmail.com>
  13. @author Vaclav Petras <wenzeslaus gmail.com> (menu customization)
  14. """
  15. import os
  16. import sys
  17. import getopt
  18. if __name__ == "__main__":
  19. sys.path.append(os.path.join(os.getenv('GISBASE'), 'etc', 'gui', 'wxpython'))
  20. from core import globalvar
  21. import wx
  22. try:
  23. import wx.lib.agw.advancedsplash as SC
  24. except ImportError:
  25. SC = None
  26. from lmgr.frame import GMFrame
  27. class GMApp(wx.App):
  28. def __init__(self, workspace = None):
  29. """!Main GUI class.
  30. @param workspace path to the workspace file
  31. """
  32. self.workspaceFile = workspace
  33. # call parent class initializer
  34. wx.App.__init__(self, False)
  35. self.locale = wx.Locale(language = wx.LANGUAGE_DEFAULT)
  36. def OnInit(self):
  37. """!Initialize all available image handlers
  38. @return True
  39. """
  40. wx.InitAllImageHandlers()
  41. # create splash screen
  42. introImagePath = os.path.join(globalvar.ETCIMGDIR, "silesia_splash.png")
  43. introImage = wx.Image(introImagePath, wx.BITMAP_TYPE_PNG)
  44. introBmp = introImage.ConvertToBitmap()
  45. if SC:
  46. splash = SC.AdvancedSplash(bitmap = introBmp,
  47. timeout = 2000, parent = None, id = wx.ID_ANY)
  48. splash.SetText(_('Starting GRASS GUI...'))
  49. splash.SetTextColour(wx.Colour(45, 52, 27))
  50. splash.SetTextFont(wx.Font(pointSize = 15, family = wx.DEFAULT, style = wx.NORMAL,
  51. weight = wx.BOLD))
  52. splash.SetTextPosition((150, 430))
  53. else:
  54. wx.SplashScreen (bitmap = introBmp, splashStyle = wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
  55. milliseconds = 2000, parent = None, id = wx.ID_ANY)
  56. wx.Yield()
  57. # create and show main frame
  58. mainframe = GMFrame(parent = None, id = wx.ID_ANY,
  59. workspace = self.workspaceFile)
  60. mainframe.Show()
  61. self.SetTopWindow(mainframe)
  62. return True
  63. class Usage(Exception):
  64. def __init__(self, msg):
  65. self.msg = msg
  66. def printHelp():
  67. """!Print program help"""
  68. print >> sys.stderr, "Usage:"
  69. print >> sys.stderr, " python wxgui.py [options]"
  70. print >> sys.stderr, "%sOptions:" % os.linesep
  71. print >> sys.stderr, " -w\t--workspace file\tWorkspace file to load"
  72. sys.exit(1)
  73. def process_opt(opts, args):
  74. """!Process command-line arguments"""
  75. workspaceFile = None
  76. for o, a in opts:
  77. if o in ("-h", "--help"):
  78. printHelp()
  79. if o in ("-w", "--workspace"):
  80. if a != '':
  81. workspaceFile = str(a)
  82. else:
  83. workspaceFile = args.pop(0)
  84. return (workspaceFile,)
  85. def main(argv = None):
  86. import gettext
  87. gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
  88. if argv is None:
  89. argv = sys.argv
  90. try:
  91. try:
  92. opts, args = getopt.getopt(argv[1:], "hw:",
  93. ["help", "workspace"])
  94. except getopt.error, msg:
  95. raise Usage(msg)
  96. except Usage, err:
  97. print >> sys.stderr, err.msg
  98. print >> sys.stderr, "for help use --help"
  99. printHelp()
  100. workspaceFile = process_opt(opts, args)[0]
  101. app = GMApp(workspaceFile)
  102. # suppress wxPython logs
  103. q = wx.LogNull()
  104. app.MainLoop()
  105. if __name__ == "__main__":
  106. sys.exit(main())