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