gis_set.py 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  1. """
  2. @package gis_set
  3. GRASS start-up screen.
  4. Initialization module for wxPython GRASS GUI.
  5. Location/mapset management (selection, creation, etc.).
  6. Classes:
  7. - gis_set::GRASSStartup
  8. - gis_set::GListBox
  9. - gis_set::StartUp
  10. (C) 2006-2014 by the GRASS Development Team
  11. This program is free software under the GNU General Public License
  12. (>=v2). Read the file COPYING that comes with GRASS for details.
  13. @author Michael Barton and Jachym Cepicky (original author)
  14. @author Martin Landa <landa.martin gmail.com> (various updates)
  15. """
  16. import os
  17. import sys
  18. import shutil
  19. import copy
  20. import platform
  21. import codecs
  22. import getpass
  23. from core import globalvar
  24. from core.utils import _
  25. import wx
  26. import wx.lib.mixins.listctrl as listmix
  27. from grass.script import core as grass
  28. from gui_core.ghelp import HelpFrame
  29. from core.gcmd import GMessage, GError, DecodeString, RunCommand, GWarning
  30. from core.utils import GetListOfLocations, GetListOfMapsets, _
  31. from location_wizard.dialogs import RegionDef
  32. from gui_core.dialogs import TextEntryDialog
  33. from gui_core.widgets import GenericValidator, StaticWrapText
  34. sys.stderr = codecs.getwriter('utf8')(sys.stderr)
  35. class GRASSStartup(wx.Frame):
  36. """GRASS start-up screen"""
  37. def __init__(self, parent = None, id = wx.ID_ANY, style = wx.DEFAULT_FRAME_STYLE):
  38. #
  39. # GRASS variables
  40. #
  41. self.gisbase = os.getenv("GISBASE")
  42. self.grassrc = self._readGisRC()
  43. self.gisdbase = self.GetRCValue("GISDBASE")
  44. #
  45. # list of locations/mapsets
  46. #
  47. self.listOfLocations = []
  48. self.listOfMapsets = []
  49. self.listOfMapsetsSelectable = []
  50. wx.Frame.__init__(self, parent = parent, id = id, style = style)
  51. self.locale = wx.Locale(language = wx.LANGUAGE_DEFAULT)
  52. # scroll panel was used here but not properly and is probably not need
  53. # as long as it is not high too much
  54. self.panel = wx.Panel(parent=self, id=wx.ID_ANY)
  55. # i18N
  56. #
  57. # graphical elements
  58. #
  59. # image
  60. try:
  61. if os.getenv('ISISROOT'):
  62. name = os.path.join(globalvar.GUIDIR, "images", "startup_banner_isis.png")
  63. else:
  64. name = os.path.join(globalvar.GUIDIR, "images", "startup_banner.png")
  65. self.hbitmap = wx.StaticBitmap(self.panel, wx.ID_ANY,
  66. wx.Bitmap(name = name,
  67. type = wx.BITMAP_TYPE_PNG))
  68. except:
  69. self.hbitmap = wx.StaticBitmap(self.panel, wx.ID_ANY, wx.BitmapFromImage(wx.EmptyImage(530,150)))
  70. # labels
  71. ### crashes when LOCATION doesn't exist
  72. # get version & revision
  73. versionFile = open(os.path.join(globalvar.ETCDIR, "VERSIONNUMBER"))
  74. versionLine = versionFile.readline().rstrip('\n')
  75. versionFile.close()
  76. try:
  77. grassVersion, grassRevision = versionLine.split(' ', 1)
  78. if grassVersion.endswith('svn'):
  79. grassRevisionStr = ' (%s)' % grassRevision
  80. else:
  81. grassRevisionStr = ''
  82. except ValueError:
  83. grassVersion = versionLine
  84. grassRevisionStr = ''
  85. self.gisdbase_box = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
  86. label=" %s " % _("Select GRASS GIS data directory"))
  87. self.location_box = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
  88. label=" %s " % _("Select GRASS Location"))
  89. self.mapset_box = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
  90. label=" %s " % _("Select GRASS Mapset"))
  91. # no message at the beginning
  92. self.lmessage = wx.StaticText(parent=self.panel, id=wx.ID_ANY,
  93. label=_(""))
  94. # It is not clear if all wx versions supports color, so try-except.
  95. # The color itself may not be correct for all platforms/system settings
  96. # but in http://xoomer.virgilio.it/infinity77/wxPython/Widgets/wx.SystemSettings.html
  97. # there is no 'warning' color.
  98. try:
  99. self.lmessage.SetForegroundColour(wx.Colour(255, 0, 0))
  100. except AttributeError:
  101. pass
  102. self.gisdbase_panel = wx.Panel(parent=self.panel)
  103. self.location_panel = wx.Panel(parent=self.panel)
  104. self.mapset_panel = wx.Panel(parent=self.panel)
  105. self.ldbase = StaticWrapText(
  106. parent = self.gisdbase_panel, id = wx.ID_ANY,
  107. label = _("GRASS GIS data directory contains Locations."
  108. " There can be one or more directories like this on one machine."))
  109. self.llocation = StaticWrapText(
  110. parent = self.location_panel, id = wx.ID_ANY,
  111. label=_("Location represents a project."
  112. " All data in one Location is in the same coordinate reference system (projection)."
  113. " Location contains Mapsets."),
  114. style = wx.ALIGN_LEFT)
  115. #self.llocation.SetForegroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_GRAYTEXT))
  116. self.lmapset = StaticWrapText(
  117. parent = self.mapset_panel, id = wx.ID_ANY,
  118. label = _("Mapset contains GIS data related"
  119. " to one task within one project,"
  120. " or to one subregion or user."
  121. " PERMANENT Mapset is in each Location and usually contains common data."),
  122. style = wx.ALIGN_LEFT)
  123. # buttons
  124. self.bstart = wx.Button(parent = self.panel, id = wx.ID_ANY,
  125. label = _("Start &GRASS session"))
  126. self.bstart.SetDefault()
  127. self.bexit = wx.Button(parent = self.panel, id = wx.ID_EXIT)
  128. self.bstart.SetMinSize((180, self.bexit.GetSize()[1]))
  129. self.bhelp = wx.Button(parent = self.panel, id = wx.ID_HELP)
  130. self.bbrowse = wx.Button(parent = self.gisdbase_panel, id = wx.ID_ANY,
  131. label = _("&Browse"))
  132. self.bmapset = wx.Button(parent = self.mapset_panel, id = wx.ID_ANY,
  133. label = _("&New"))
  134. self.bwizard = wx.Button(parent = self.location_panel, id = wx.ID_ANY,
  135. label = _("N&ew"))
  136. self.bwizard.SetToolTipString(_("Create a new location using location wizard."
  137. " After location is created successfully,"
  138. " GRASS session is started."))
  139. self.rename_location_button = wx.Button(parent=self.location_panel, id=wx.ID_ANY,
  140. label=_("Ren&ame"))
  141. self.rename_location_button.SetToolTipString(_("Rename selected location"))
  142. self.delete_location_button = wx.Button(parent=self.location_panel, id=wx.ID_ANY,
  143. label=_("De&lete"))
  144. self.delete_location_button.SetToolTipString(_("Delete selected location"))
  145. self.rename_mapset_button = wx.Button(parent=self.mapset_panel, id=wx.ID_ANY,
  146. label=_("&Rename"))
  147. self.rename_mapset_button.SetToolTipString(_("Rename selected mapset"))
  148. self.delete_mapset_button = wx.Button(parent=self.mapset_panel, id=wx.ID_ANY,
  149. label=_("&Delete"))
  150. self.delete_mapset_button.SetToolTipString(_("Delete selected mapset"))
  151. # textinputs
  152. self.tgisdbase = wx.TextCtrl(parent = self.gisdbase_panel, id = wx.ID_ANY, value = "", size = (300, -1),
  153. style = wx.TE_PROCESS_ENTER)
  154. # Locations
  155. self.lblocations = GListBox(parent = self.location_panel,
  156. id = wx.ID_ANY, size = (180, 200),
  157. choices = self.listOfLocations)
  158. self.lblocations.SetColumnWidth(0, 180)
  159. # TODO: sort; but keep PERMANENT on top of list
  160. # Mapsets
  161. self.lbmapsets = GListBox(parent = self.mapset_panel,
  162. id = wx.ID_ANY, size = (180, 200),
  163. choices = self.listOfMapsets)
  164. self.lbmapsets.SetColumnWidth(0, 180)
  165. # layout & properties
  166. self._set_properties(grassVersion, grassRevisionStr)
  167. self._do_layout()
  168. # events
  169. self.bbrowse.Bind(wx.EVT_BUTTON, self.OnBrowse)
  170. self.bstart.Bind(wx.EVT_BUTTON, self.OnStart)
  171. self.bexit.Bind(wx.EVT_BUTTON, self.OnExit)
  172. self.bhelp.Bind(wx.EVT_BUTTON, self.OnHelp)
  173. self.bmapset.Bind(wx.EVT_BUTTON, self.OnCreateMapset)
  174. self.bwizard.Bind(wx.EVT_BUTTON, self.OnWizard)
  175. self.rename_location_button.Bind(wx.EVT_BUTTON, self.RenameLocation)
  176. self.delete_location_button.Bind(wx.EVT_BUTTON, self.DeleteLocation)
  177. self.rename_mapset_button.Bind(wx.EVT_BUTTON, self.RenameMapset)
  178. self.delete_mapset_button.Bind(wx.EVT_BUTTON, self.DeleteMapset)
  179. self.lblocations.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectLocation)
  180. self.lbmapsets.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectMapset)
  181. self.lbmapsets.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnStart)
  182. self.tgisdbase.Bind(wx.EVT_TEXT_ENTER, self.OnSetDatabase)
  183. self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
  184. def _set_properties(self, version, revision):
  185. """Set frame properties"""
  186. self.SetTitle(_("GRASS GIS %s startup%s") % (version, revision))
  187. self.SetIcon(wx.Icon(os.path.join(globalvar.ICONDIR, "grass.ico"),
  188. wx.BITMAP_TYPE_ICO))
  189. self.bstart.SetForegroundColour(wx.Colour(35, 142, 35))
  190. self.bstart.SetToolTipString(_("Enter GRASS session"))
  191. self.bstart.Enable(False)
  192. self.bmapset.Enable(False)
  193. # this all was originally a choice, perhaps just mapset needed
  194. self.rename_location_button.Enable(False)
  195. self.delete_location_button.Enable(False)
  196. self.rename_mapset_button.Enable(False)
  197. self.delete_mapset_button.Enable(False)
  198. # set database
  199. if not self.gisdbase:
  200. # sets an initial path for gisdbase if nothing in GISRC
  201. if os.path.isdir(os.getenv("HOME")):
  202. self.gisdbase = os.getenv("HOME")
  203. else:
  204. self.gisdbase = os.getcwd()
  205. try:
  206. self.tgisdbase.SetValue(self.gisdbase)
  207. except UnicodeDecodeError:
  208. wx.MessageBox(parent = self, caption = _("Error"),
  209. message = _("Unable to set GRASS database. "
  210. "Check your locale settings."),
  211. style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  212. self.OnSetDatabase(None)
  213. location = self.GetRCValue("LOCATION_NAME")
  214. if location == "<UNKNOWN>":
  215. return
  216. if not os.path.isdir(os.path.join(self.gisdbase, location)):
  217. location = None
  218. # list of locations
  219. self.UpdateLocations(self.gisdbase)
  220. try:
  221. self.lblocations.SetSelection(self.listOfLocations.index(location),
  222. force = True)
  223. self.lblocations.EnsureVisible(self.listOfLocations.index(location))
  224. except ValueError:
  225. sys.stderr.write(_("ERROR: Location <%s> not found\n") % self.GetRCValue("LOCATION_NAME"))
  226. if len(self.listOfLocations) > 0:
  227. self.lblocations.SetSelection(0, force = True)
  228. self.lblocations.EnsureVisible(0)
  229. location = self.listOfLocations[0]
  230. else:
  231. return
  232. # list of mapsets
  233. self.UpdateMapsets(os.path.join(self.gisdbase, location))
  234. mapset = self.GetRCValue("MAPSET")
  235. if mapset:
  236. try:
  237. self.lbmapsets.SetSelection(self.listOfMapsets.index(mapset),
  238. force = True)
  239. self.lbmapsets.EnsureVisible(self.listOfMapsets.index(mapset))
  240. except ValueError:
  241. sys.stderr.write(_("ERROR: Mapset <%s> not found\n") % mapset)
  242. self.lbmapsets.SetSelection(0, force = True)
  243. self.lbmapsets.EnsureVisible(0)
  244. def _do_layout(self):
  245. sizer = wx.BoxSizer(wx.VERTICAL)
  246. dbase_sizer = wx.BoxSizer(wx.HORIZONTAL)
  247. location_mapset_sizer = wx.BoxSizer(wx.HORIZONTAL)
  248. gisdbase_panel_sizer = wx.BoxSizer(wx.VERTICAL)
  249. gisdbase_boxsizer = wx.StaticBoxSizer(self.gisdbase_box, wx.VERTICAL)
  250. location_panel_sizer = wx.BoxSizer(wx.VERTICAL)
  251. location_sizer = wx.BoxSizer(wx.HORIZONTAL)
  252. location_boxsizer = wx.StaticBoxSizer(self.location_box, wx.VERTICAL)
  253. location_buttons_sizer = wx.BoxSizer(wx.VERTICAL)
  254. mapset_panel_sizer = wx.BoxSizer(wx.VERTICAL)
  255. mapset_sizer = wx.BoxSizer(wx.HORIZONTAL)
  256. mapset_boxsizer = wx.StaticBoxSizer(self.mapset_box, wx.VERTICAL)
  257. mapset_buttons_sizer = wx.BoxSizer(wx.VERTICAL)
  258. btns_sizer = wx.BoxSizer(wx.HORIZONTAL)
  259. self.gisdbase_panel.SetSizer(gisdbase_panel_sizer)
  260. gisdbase_panel_sizer.Fit(self.gisdbase_panel)
  261. self.location_panel.SetSizer(location_panel_sizer)
  262. location_panel_sizer.Fit(self.location_panel)
  263. self.mapset_panel.SetSizer(mapset_panel_sizer)
  264. mapset_panel_sizer.Fit(self.mapset_panel)
  265. # gis data directory
  266. gisdbase_boxsizer.Add(item=self.gisdbase_panel, proportion=1,
  267. flag=wx.EXPAND | wx.ALL,
  268. border=3)
  269. gisdbase_panel_sizer.Add(item=dbase_sizer, proportion=1,
  270. flag=wx.EXPAND | wx.ALL,
  271. border=3)
  272. gisdbase_panel_sizer.Add(item=self.ldbase, proportion=1,
  273. flag=wx.EXPAND | wx.ALL,
  274. border=3)
  275. dbase_sizer.Add(item = self.tgisdbase, proportion = 1,
  276. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  277. border = 3)
  278. dbase_sizer.Add(item = self.bbrowse, proportion = 0,
  279. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  280. border = 3)
  281. location_boxsizer.Add(item=self.location_panel, proportion=1,
  282. flag=wx.EXPAND | wx.ALL,
  283. border=3)
  284. location_sizer.Add(item = self.lblocations, proportion = 1,
  285. flag=wx.EXPAND | wx.ALL,
  286. border=3)
  287. location_sizer.Add(item = location_buttons_sizer, proportion=0,
  288. flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
  289. border=3)
  290. location_buttons_sizer.Add(item=self.bwizard, proportion=0,
  291. flag=wx.EXPAND | wx.ALL,
  292. border=3)
  293. location_buttons_sizer.Add(item=self.rename_location_button, proportion=0,
  294. flag=wx.EXPAND | wx.ALL,
  295. border=3)
  296. location_buttons_sizer.Add(item=self.delete_location_button, proportion=0,
  297. flag=wx.EXPAND | wx.ALL,
  298. border=3)
  299. location_panel_sizer.Add(item=location_sizer, proportion=1,
  300. flag=wx.EXPAND | wx.ALL,
  301. border=3)
  302. location_panel_sizer.Add(item=self.llocation, proportion=0,
  303. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  304. border=3)
  305. mapset_sizer.Add(item=self.lbmapsets, proportion=1,
  306. flag=wx.EXPAND | wx.ALL,
  307. border=3)
  308. mapset_sizer.Add(item=mapset_buttons_sizer, proportion=0,
  309. flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
  310. border=3)
  311. mapset_buttons_sizer.Add(item=self.bmapset, proportion=0,
  312. flag=wx.EXPAND | wx.ALL,
  313. border=3)
  314. mapset_buttons_sizer.Add(item=self.rename_mapset_button, proportion=0,
  315. flag=wx.EXPAND | wx.ALL,
  316. border=3)
  317. mapset_buttons_sizer.Add(item=self.delete_mapset_button, proportion=0,
  318. flag=wx.EXPAND | wx.ALL,
  319. border=3)
  320. mapset_boxsizer.Add(item=self.mapset_panel, proportion=1,
  321. flag=wx.EXPAND | wx.ALL,
  322. border=3)
  323. mapset_panel_sizer.Add(item=mapset_sizer, proportion=1,
  324. flag=wx.EXPAND | wx.ALL,
  325. border=3)
  326. mapset_panel_sizer.Add(item=self.lmapset, proportion=0,
  327. flag=wx.EXPAND | wx.ALL,
  328. border=3)
  329. # location sizer
  330. location_mapset_sizer.Add(item=location_boxsizer, proportion=1,
  331. flag = wx.LEFT | wx.RIGHT | wx.EXPAND,
  332. border = 3)
  333. location_mapset_sizer.Add(item=mapset_boxsizer, proportion=1,
  334. flag = wx.RIGHT | wx.EXPAND,
  335. border = 3)
  336. # buttons
  337. btns_sizer.Add(item = self.bstart, proportion = 0,
  338. flag = wx.ALIGN_CENTER_HORIZONTAL |
  339. wx.ALIGN_CENTER_VERTICAL |
  340. wx.ALL,
  341. border = 5)
  342. btns_sizer.Add(item = self.bexit, proportion = 0,
  343. flag = wx.ALIGN_CENTER_HORIZONTAL |
  344. wx.ALIGN_CENTER_VERTICAL |
  345. wx.ALL,
  346. border = 5)
  347. btns_sizer.Add(item = self.bhelp, proportion = 0,
  348. flag = wx.ALIGN_CENTER_HORIZONTAL |
  349. wx.ALIGN_CENTER_VERTICAL |
  350. wx.ALL,
  351. border = 5)
  352. # main sizer
  353. sizer.Add(item = self.hbitmap,
  354. proportion = 0,
  355. flag = wx.ALIGN_CENTER_VERTICAL |
  356. wx.ALIGN_CENTER_HORIZONTAL |
  357. wx.ALL,
  358. border = 3) # image
  359. sizer.Add(item=gisdbase_boxsizer, proportion=0,
  360. flag = wx.ALIGN_CENTER_HORIZONTAL |
  361. wx.RIGHT | wx.LEFT | wx.EXPAND,
  362. border=3) # GISDBASE setting
  363. # warning/error message
  364. sizer.Add(item=self.lmessage,
  365. proportion=0,
  366. flag=wx.ALIGN_CENTER_VERTICAL |
  367. wx.ALIGN_LEFT| wx.LEFT | wx.RIGHT | wx.BOTTOM, border=8)
  368. sizer.Add(item=location_mapset_sizer, proportion=1,
  369. flag = wx.RIGHT | wx.LEFT | wx.EXPAND,
  370. border = 1)
  371. sizer.Add(item = btns_sizer, proportion = 0,
  372. flag = wx.ALIGN_CENTER_VERTICAL |
  373. wx.ALIGN_CENTER_HORIZONTAL |
  374. wx.RIGHT | wx.LEFT,
  375. border = 1)
  376. self.panel.SetAutoLayout(True)
  377. self.panel.SetSizer(sizer)
  378. sizer.Fit(self.panel)
  379. sizer.SetSizeHints(self)
  380. self.Layout()
  381. def _readGisRC(self):
  382. """Read variables from $HOME/.grass7/rc file
  383. """
  384. grassrc = {}
  385. gisrc = os.getenv("GISRC")
  386. if gisrc and os.path.isfile(gisrc):
  387. try:
  388. rc = open(gisrc, "r")
  389. for line in rc.readlines():
  390. try:
  391. key, val = line.split(":", 1)
  392. except ValueError as e:
  393. sys.stderr.write(_('Invalid line in GISRC file (%s):%s\n' % \
  394. (e, line)))
  395. grassrc[key.strip()] = DecodeString(val.strip())
  396. finally:
  397. rc.close()
  398. return grassrc
  399. def _showWarning(self, text):
  400. """Displays a warning message to the user.
  401. There is no cleaning procedure. You should call _hideMessage when
  402. you know that there is everything correct now.
  403. """
  404. self.lmessage.SetLabel(_("Warning: ") + text)
  405. def _showError(self, text):
  406. """Displays a error message to the user.
  407. There is no cleaning procedure. You should call _hideMessage when
  408. you know that there is everything correct now.
  409. """
  410. self.lmessage.SetLabel(_("Error: ") + text)
  411. def _hideMessage(self):
  412. """Clears/hides the error message."""
  413. # we do no hide widget
  414. # because we do not want the dialog to change the size
  415. self.lmessage.SetLabel("")
  416. def GetRCValue(self, value):
  417. """Return GRASS variable (read from GISRC)
  418. """
  419. if self.grassrc.has_key(value):
  420. return self.grassrc[value]
  421. else:
  422. return None
  423. def OnWizard(self, event):
  424. """Location wizard started"""
  425. from location_wizard.wizard import LocationWizard
  426. gWizard = LocationWizard(parent = self,
  427. grassdatabase = self.tgisdbase.GetValue())
  428. if gWizard.location != None:
  429. self.tgisdbase.SetValue(gWizard.grassdatabase)
  430. self.OnSetDatabase(None)
  431. self.UpdateMapsets(os.path.join(self.gisdbase, gWizard.location))
  432. self.lblocations.SetSelection(self.listOfLocations.index(gWizard.location))
  433. self.lbmapsets.SetSelection(0)
  434. self.SetLocation(self.gisdbase, gWizard.location, 'PERMANENT')
  435. if gWizard.georeffile:
  436. message = _("Do you want to import <%(name)s> to the newly created location? "
  437. "The location's default region will be set from this imported "
  438. "map.") % {'name': gWizard.georeffile}
  439. dlg = wx.MessageDialog(parent = self,
  440. message = message,
  441. caption = _("Import data?"),
  442. style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  443. dlg.CenterOnScreen()
  444. if dlg.ShowModal() == wx.ID_YES:
  445. self.ImportFile(gWizard.georeffile)
  446. else:
  447. self.SetDefaultRegion(location = gWizard.location)
  448. dlg.Destroy()
  449. else:
  450. self.SetDefaultRegion(location = gWizard.location)
  451. dlg = TextEntryDialog(parent=self,
  452. message=_("Do you want to create new mapset?"),
  453. caption=_("Create new mapset"),
  454. defaultValue=self._getDefaultMapsetName(),
  455. validator=GenericValidator(grass.legal_name, self._nameValidationFailed),
  456. style=wx.OK | wx.CANCEL | wx.HELP)
  457. help = dlg.FindWindowById(wx.ID_HELP)
  458. help.Bind(wx.EVT_BUTTON, self.OnHelp)
  459. if dlg.ShowModal() == wx.ID_OK:
  460. mapsetName = dlg.GetValue()
  461. self.CreateNewMapset(mapsetName)
  462. def SetDefaultRegion(self, location):
  463. """Asks to set default region."""
  464. caption = _("Location <%s> created") % location
  465. message = _("Do you want to set the default "
  466. "region extents and resolution now?")
  467. dlg = wx.MessageDialog(parent = self,
  468. message = "%(caption)s.\n\n%(extent)s" % ({'caption': caption,
  469. 'extent': message}),
  470. caption = caption,
  471. style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
  472. dlg.CenterOnScreen()
  473. if dlg.ShowModal() == wx.ID_YES:
  474. dlg.Destroy()
  475. defineRegion = RegionDef(self, location = location)
  476. defineRegion.CenterOnScreen()
  477. defineRegion.ShowModal()
  478. defineRegion.Destroy()
  479. else:
  480. dlg.Destroy()
  481. def ImportFile(self, filePath):
  482. """Tries to import file as vector or raster.
  483. If successfull sets default region from imported map.
  484. """
  485. RunCommand('db.connect', flags='c')
  486. mapName = os.path.splitext(os.path.basename(filePath))[0]
  487. vectors = RunCommand('v.in.ogr', input = filePath, flags = 'l',
  488. read = True)
  489. wx.BeginBusyCursor()
  490. wx.Yield()
  491. if mapName in vectors:
  492. # vector detected
  493. returncode, error = RunCommand('v.in.ogr', input = filePath, output = mapName,
  494. getErrorMsg = True)
  495. else:
  496. returncode, error = RunCommand('r.in.gdal', input = filePath, output = mapName,
  497. getErrorMsg = True)
  498. wx.EndBusyCursor()
  499. if returncode != 0:
  500. GError(parent = self,
  501. message = _("Import of <%(name)s> failed.\n"
  502. "Reason: %(msg)s") % ({'name': filePath, 'msg': error}))
  503. else:
  504. GMessage(message = _("Data file <%(name)s> imported successfully.") % {'name': filePath},
  505. parent = self)
  506. if not grass.find_file(element = 'cell', name = mapName)['fullname'] and \
  507. not grass.find_file(element = 'vector', name = mapName)['fullname']:
  508. GError(parent = self,
  509. message = _("Map <%s> not found.") % mapName)
  510. else:
  511. if mapName in vectors:
  512. args = {'vector' : mapName}
  513. else:
  514. args = {'raster' : mapName}
  515. RunCommand('g.region', flags = 's', parent = self, **args)
  516. # the event can be refactored out by using lambda in bind
  517. def RenameMapset(self, event):
  518. """Rename selected mapset
  519. """
  520. location = self.listOfLocations[self.lblocations.GetSelection()]
  521. mapset = self.listOfMapsets[self.lbmapsets.GetSelection()]
  522. if mapset == 'PERMANENT':
  523. GMessage(parent = self,
  524. message = _('Mapset <PERMANENT> is required for valid GRASS location.\n\n'
  525. 'This mapset cannot be renamed.'))
  526. return
  527. dlg = TextEntryDialog(parent = self,
  528. message = _('Current name: %s\n\nEnter new name:') % mapset,
  529. caption = _('Rename selected mapset'),
  530. validator = GenericValidator(grass.legal_name, self._nameValidationFailed))
  531. if dlg.ShowModal() == wx.ID_OK:
  532. newmapset = dlg.GetValue()
  533. if newmapset == mapset:
  534. dlg.Destroy()
  535. return
  536. if newmapset in self.listOfMapsets:
  537. wx.MessageBox(parent = self,
  538. caption = _('Message'),
  539. message = _('Unable to rename mapset.\n\n'
  540. 'Mapset <%s> already exists in location.') % newmapset,
  541. style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
  542. else:
  543. try:
  544. os.rename(os.path.join(self.gisdbase, location, mapset),
  545. os.path.join(self.gisdbase, location, newmapset))
  546. self.OnSelectLocation(None)
  547. self.lbmapsets.SetSelection(self.listOfMapsets.index(newmapset))
  548. except StandardError as e:
  549. wx.MessageBox(parent = self,
  550. caption = _('Error'),
  551. message = _('Unable to rename mapset.\n\n%s') % e,
  552. style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  553. dlg.Destroy()
  554. def RenameLocation(self, event):
  555. """Rename selected location
  556. """
  557. location = self.listOfLocations[self.lblocations.GetSelection()]
  558. dlg = TextEntryDialog(parent = self,
  559. message = _('Current name: %s\n\nEnter new name:') % location,
  560. caption = _('Rename selected location'),
  561. validator = GenericValidator(grass.legal_name, self._nameValidationFailed))
  562. if dlg.ShowModal() == wx.ID_OK:
  563. newlocation = dlg.GetValue()
  564. if newlocation == location:
  565. dlg.Destroy()
  566. return
  567. if newlocation in self.listOfLocations:
  568. wx.MessageBox(parent = self,
  569. caption = _('Message'),
  570. message = _('Unable to rename location.\n\n'
  571. 'Location <%s> already exists in GRASS database.') % newlocation,
  572. style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
  573. else:
  574. try:
  575. os.rename(os.path.join(self.gisdbase, location),
  576. os.path.join(self.gisdbase, newlocation))
  577. self.UpdateLocations(self.gisdbase)
  578. self.lblocations.SetSelection(self.listOfLocations.index(newlocation))
  579. self.UpdateMapsets(newlocation)
  580. except StandardError as e:
  581. wx.MessageBox(parent = self,
  582. caption = _('Error'),
  583. message = _('Unable to rename location.\n\n%s') % e,
  584. style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  585. dlg.Destroy()
  586. def DeleteMapset(self, event):
  587. """Delete selected mapset
  588. """
  589. location = self.listOfLocations[self.lblocations.GetSelection()]
  590. mapset = self.listOfMapsets[self.lbmapsets.GetSelection()]
  591. if mapset == 'PERMANENT':
  592. GMessage(parent = self,
  593. message = _('Mapset <PERMANENT> is required for valid GRASS location.\n\n'
  594. 'This mapset cannot be deleted.'))
  595. return
  596. dlg = wx.MessageDialog(parent = self, message = _("Do you want to continue with deleting mapset <%(mapset)s> "
  597. "from location <%(location)s>?\n\n"
  598. "ALL MAPS included in this mapset will be "
  599. "PERMANENTLY DELETED!") % {'mapset' : mapset,
  600. 'location' : location},
  601. caption = _("Delete selected mapset"),
  602. style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
  603. if dlg.ShowModal() == wx.ID_YES:
  604. try:
  605. shutil.rmtree(os.path.join(self.gisdbase, location, mapset))
  606. self.OnSelectLocation(None)
  607. self.lbmapsets.SetSelection(0)
  608. except:
  609. wx.MessageBox(message = _('Unable to delete mapset'))
  610. dlg.Destroy()
  611. def DeleteLocation(self, event):
  612. """
  613. Delete selected location
  614. """
  615. location = self.listOfLocations[self.lblocations.GetSelection()]
  616. dlg = wx.MessageDialog(parent = self, message = _("Do you want to continue with deleting "
  617. "location <%s>?\n\n"
  618. "ALL MAPS included in this location will be "
  619. "PERMANENTLY DELETED!") % (location),
  620. caption = _("Delete selected location"),
  621. style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
  622. if dlg.ShowModal() == wx.ID_YES:
  623. try:
  624. shutil.rmtree(os.path.join(self.gisdbase, location))
  625. self.UpdateLocations(self.gisdbase)
  626. self.lblocations.SetSelection(0)
  627. self.OnSelectLocation(None)
  628. self.lbmapsets.SetSelection(0)
  629. except:
  630. wx.MessageBox(message = _('Unable to delete location'))
  631. dlg.Destroy()
  632. def UpdateLocations(self, dbase):
  633. """Update list of locations"""
  634. try:
  635. self.listOfLocations = GetListOfLocations(dbase)
  636. except UnicodeEncodeError:
  637. GError(parent = self,
  638. message = _("Unable to set GRASS database. "
  639. "Check your locale settings."))
  640. self.lblocations.Clear()
  641. self.lblocations.InsertItems(self.listOfLocations, 0)
  642. if len(self.listOfLocations) > 0:
  643. self._hideMessage()
  644. self.lblocations.SetSelection(0)
  645. else:
  646. self.lblocations.SetSelection(wx.NOT_FOUND)
  647. self._showWarning(_("No GRASS location found in '%s'.")
  648. % self.gisdbase)
  649. return self.listOfLocations
  650. def UpdateMapsets(self, location):
  651. """Update list of mapsets"""
  652. self.FormerMapsetSelection = wx.NOT_FOUND # for non-selectable item
  653. self.listOfMapsetsSelectable = list()
  654. self.listOfMapsets = GetListOfMapsets(self.gisdbase, location)
  655. self.lbmapsets.Clear()
  656. # disable mapset with denied permission
  657. locationName = os.path.basename(location)
  658. ret = RunCommand('g.mapset',
  659. read = True,
  660. flags = 'l',
  661. location = locationName,
  662. gisdbase = self.gisdbase)
  663. if ret:
  664. for line in ret.splitlines():
  665. self.listOfMapsetsSelectable += line.split(' ')
  666. else:
  667. RunCommand("g.gisenv",
  668. set = "GISDBASE=%s" % self.gisdbase)
  669. RunCommand("g.gisenv",
  670. set = "LOCATION_NAME=%s" % locationName)
  671. RunCommand("g.gisenv",
  672. set = "MAPSET=PERMANENT")
  673. # first run only
  674. self.listOfMapsetsSelectable = copy.copy(self.listOfMapsets)
  675. disabled = []
  676. idx = 0
  677. for mapset in self.listOfMapsets:
  678. if mapset not in self.listOfMapsetsSelectable or \
  679. os.path.isfile(os.path.join(self.gisdbase,
  680. locationName,
  681. mapset, ".gislock")):
  682. disabled.append(idx)
  683. idx += 1
  684. self.lbmapsets.InsertItems(self.listOfMapsets, 0, disabled = disabled)
  685. return self.listOfMapsets
  686. def OnSelectLocation(self, event):
  687. """Location selected"""
  688. if event:
  689. self.lblocations.SetSelection(event.GetIndex())
  690. if self.lblocations.GetSelection() != wx.NOT_FOUND:
  691. self.UpdateMapsets(os.path.join(self.gisdbase,
  692. self.listOfLocations[self.lblocations.GetSelection()]))
  693. else:
  694. self.listOfMapsets = []
  695. disabled = []
  696. idx = 0
  697. try:
  698. locationName = self.listOfLocations[self.lblocations.GetSelection()]
  699. except IndexError:
  700. locationName = ''
  701. for mapset in self.listOfMapsets:
  702. if mapset not in self.listOfMapsetsSelectable or \
  703. os.path.isfile(os.path.join(self.gisdbase,
  704. locationName,
  705. mapset, ".gislock")):
  706. disabled.append(idx)
  707. idx += 1
  708. self.lbmapsets.Clear()
  709. self.lbmapsets.InsertItems(self.listOfMapsets, 0, disabled = disabled)
  710. if len(self.listOfMapsets) > 0:
  711. self.lbmapsets.SetSelection(0)
  712. if locationName:
  713. # enable start button when location and mapset is selected
  714. self.bstart.Enable()
  715. self.bstart.SetFocus()
  716. self.bmapset.Enable()
  717. # replacing disabled choice, perhaps just mapset needed
  718. self.rename_location_button.Enable()
  719. self.delete_location_button.Enable()
  720. self.rename_mapset_button.Enable()
  721. self.delete_mapset_button.Enable()
  722. else:
  723. self.lbmapsets.SetSelection(wx.NOT_FOUND)
  724. self.bstart.Enable(False)
  725. self.bmapset.Enable(False)
  726. # this all was originally a choice, perhaps just mapset needed
  727. self.rename_location_button.Enable(False)
  728. self.delete_location_button.Enable(False)
  729. self.rename_mapset_button.Enable(False)
  730. self.delete_mapset_button.Enable(False)
  731. def OnSelectMapset(self, event):
  732. """Mapset selected"""
  733. self.lbmapsets.SetSelection(event.GetIndex())
  734. if event.GetText() not in self.listOfMapsetsSelectable:
  735. self.lbmapsets.SetSelection(self.FormerMapsetSelection)
  736. else:
  737. self.FormerMapsetSelection = event.GetIndex()
  738. event.Skip()
  739. def OnSetDatabase(self, event):
  740. """Database set"""
  741. gisdbase = self.tgisdbase.GetValue()
  742. self._hideMessage()
  743. if not os.path.exists(gisdbase):
  744. self._showError(_("Path '%s' doesn't exist.") % gisdbase)
  745. return
  746. self.gisdbase = self.tgisdbase.GetValue()
  747. self.UpdateLocations(self.gisdbase)
  748. self.OnSelectLocation(None)
  749. def OnBrowse(self, event):
  750. """'Browse' button clicked"""
  751. if not event:
  752. defaultPath = os.getenv('HOME')
  753. else:
  754. defaultPath = ""
  755. dlg = wx.DirDialog(parent = self, message = _("Choose GIS Data Directory"),
  756. defaultPath = defaultPath, style = wx.DD_DEFAULT_STYLE)
  757. if dlg.ShowModal() == wx.ID_OK:
  758. self.gisdbase = dlg.GetPath()
  759. self.tgisdbase.SetValue(self.gisdbase)
  760. self.OnSetDatabase(event)
  761. dlg.Destroy()
  762. def OnCreateMapset(self, event):
  763. """Create new mapset"""
  764. dlg = TextEntryDialog(parent = self,
  765. message = _('Enter name for new mapset:'),
  766. caption = _('Create new mapset'),
  767. defaultValue = self._getDefaultMapsetName(),
  768. validator = GenericValidator(grass.legal_name, self._nameValidationFailed))
  769. if dlg.ShowModal() == wx.ID_OK:
  770. mapset = dlg.GetValue()
  771. return self.CreateNewMapset(mapset = mapset)
  772. else:
  773. return False
  774. def CreateNewMapset(self, mapset):
  775. if mapset in self.listOfMapsets:
  776. GMessage(parent = self,
  777. message = _("Mapset <%s> already exists.") % mapset)
  778. return False
  779. if mapset.lower() == 'ogr':
  780. dlg1 = wx.MessageDialog(parent = self,
  781. message = _("Mapset <%s> is reserved for direct "
  782. "read access to OGR layers. Please consider to use "
  783. "another name for your mapset.\n\n"
  784. "Are you really sure that you want to create this mapset?") % mapset,
  785. caption = _("Reserved mapset name"),
  786. style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
  787. ret = dlg1.ShowModal()
  788. dlg1.Destroy()
  789. if ret == wx.ID_NO:
  790. dlg.Destroy()
  791. return False
  792. try:
  793. self.gisdbase = self.tgisdbase.GetValue()
  794. location = self.listOfLocations[self.lblocations.GetSelection()]
  795. os.mkdir(os.path.join(self.gisdbase, location, mapset))
  796. # copy WIND file and its permissions from PERMANENT and set permissions to u+rw,go+r
  797. shutil.copy(os.path.join(self.gisdbase, location, 'PERMANENT', 'WIND'),
  798. os.path.join(self.gisdbase, location, mapset))
  799. # os.chmod(os.path.join(database,location,mapset,'WIND'), 0644)
  800. self.OnSelectLocation(None)
  801. self.lbmapsets.SetSelection(self.listOfMapsets.index(mapset))
  802. self.bstart.SetFocus()
  803. return True
  804. except StandardError as e:
  805. GError(parent = self,
  806. message = _("Unable to create new mapset: %s") % e,
  807. showTraceback = False)
  808. return False
  809. def OnStart(self, event):
  810. """'Start GRASS' button clicked"""
  811. dbase = self.tgisdbase.GetValue()
  812. location = self.listOfLocations[self.lblocations.GetSelection()]
  813. mapset = self.listOfMapsets[self.lbmapsets.GetSelection()]
  814. lockfile = os.path.join(dbase, location, mapset, '.gislock')
  815. if os.path.isfile(lockfile):
  816. dlg = wx.MessageDialog(parent = self,
  817. message = _("GRASS is already running in selected mapset <%(mapset)s>\n"
  818. "(file %(lock)s found).\n\n"
  819. "Concurrent use not allowed.\n\n"
  820. "Do you want to try to remove .gislock (note that you "
  821. "need permission for this operation) and continue?") %
  822. { 'mapset' : mapset, 'lock' : lockfile },
  823. caption = _("Lock file found"),
  824. style = wx.YES_NO | wx.NO_DEFAULT |
  825. wx.ICON_QUESTION | wx.CENTRE)
  826. ret = dlg.ShowModal()
  827. dlg.Destroy()
  828. if ret == wx.ID_YES:
  829. dlg1 = wx.MessageDialog(parent = self,
  830. message = _("ARE YOU REALLY SURE?\n\n"
  831. "If you really are running another GRASS session doing this "
  832. "could corrupt your data. Have another look in the processor "
  833. "manager just to be sure..."),
  834. caption = _("Lock file found"),
  835. style = wx.YES_NO | wx.NO_DEFAULT |
  836. wx.ICON_QUESTION | wx.CENTRE)
  837. ret = dlg1.ShowModal()
  838. dlg1.Destroy()
  839. if ret == wx.ID_YES:
  840. try:
  841. os.remove(lockfile)
  842. except IOError as e:
  843. GError(_("Unable to remove '%(lock)s'.\n\n"
  844. "Details: %(reason)s") % { 'lock' : lockfile, 'reason' : e})
  845. else:
  846. return
  847. else:
  848. return
  849. self.SetLocation(dbase, location, mapset)
  850. self.ExitSuccessfully()
  851. def SetLocation(self, dbase, location, mapset):
  852. RunCommand("g.gisenv",
  853. set = "GISDBASE=%s" % dbase)
  854. RunCommand("g.gisenv",
  855. set = "LOCATION_NAME=%s" % location)
  856. RunCommand("g.gisenv",
  857. set = "MAPSET=%s" % mapset)
  858. def _getDefaultMapsetName(self):
  859. """Returns default name for mapset."""
  860. try:
  861. defaultName = getpass.getuser()
  862. defaultName.encode('ascii') # raise error if not ascii (not valid mapset name)
  863. except: # whatever might go wrong
  864. defaultName = 'user'
  865. return defaultName
  866. def ExitSuccessfully(self):
  867. self.Destroy()
  868. sys.exit(0)
  869. def OnExit(self, event):
  870. """'Exit' button clicked"""
  871. self.Destroy()
  872. sys.exit(2)
  873. def OnHelp(self, event):
  874. """'Help' button clicked"""
  875. # help text in lib/init/helptext.html
  876. RunCommand('g.manual', entry = 'helptext')
  877. def OnCloseWindow(self, event):
  878. """Close window event"""
  879. event.Skip()
  880. sys.exit(2)
  881. def _nameValidationFailed(self, ctrl):
  882. message = _("Name <%(name)s> is not a valid name for location or mapset. "
  883. "Please use only ASCII characters excluding %(chars)s "
  884. "and space.") % {'name': ctrl.GetValue(), 'chars': '/"\'@,=*~'}
  885. GError(parent=self, message=message, caption=_("Invalid name"))
  886. class GListBox(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
  887. """Use wx.ListCtrl instead of wx.ListBox, different style for
  888. non-selectable items (e.g. mapsets with denied permission)"""
  889. def __init__(self, parent, id, size,
  890. choices, disabled = []):
  891. wx.ListCtrl.__init__(self, parent, id, size = size,
  892. style = wx.LC_REPORT | wx.LC_NO_HEADER | wx.LC_SINGLE_SEL |
  893. wx.BORDER_SUNKEN)
  894. listmix.ListCtrlAutoWidthMixin.__init__(self)
  895. self.InsertColumn(0, '')
  896. self.selected = wx.NOT_FOUND
  897. self._LoadData(choices, disabled)
  898. def _LoadData(self, choices, disabled = []):
  899. """Load data into list
  900. :param choices: list of item
  901. :param disabled: list of indeces of non-selectable items
  902. """
  903. idx = 0
  904. for item in choices:
  905. index = self.InsertStringItem(sys.maxint, item)
  906. self.SetStringItem(index, 0, item)
  907. if idx in disabled:
  908. self.SetItemTextColour(idx, wx.Colour(150, 150, 150))
  909. idx += 1
  910. def Clear(self):
  911. self.DeleteAllItems()
  912. def InsertItems(self, choices, pos, disabled = []):
  913. self._LoadData(choices, disabled)
  914. def SetSelection(self, item, force = False):
  915. if item != wx.NOT_FOUND and \
  916. (platform.system() != 'Windows' or force):
  917. ### Windows -> FIXME
  918. self.SetItemState(item, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
  919. self.selected = item
  920. def GetSelection(self):
  921. return self.selected
  922. class StartUp(wx.App):
  923. """Start-up application"""
  924. def OnInit(self):
  925. if not globalvar.CheckWxVersion([2, 9]):
  926. wx.InitAllImageHandlers()
  927. StartUp = GRASSStartup()
  928. StartUp.CenterOnScreen()
  929. self.SetTopWindow(StartUp)
  930. StartUp.Show()
  931. if StartUp.GetRCValue("LOCATION_NAME") == "<UNKNOWN>":
  932. wx.MessageBox(parent = StartUp,
  933. caption = _('Starting GRASS for the first time'),
  934. message = _('GRASS needs a directory in which to store its data. '
  935. 'Create one now if you have not already done so. '
  936. 'A popular choice is "grassdata", located in '
  937. 'your home directory.'),
  938. style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  939. StartUp.OnBrowse(None)
  940. return 1
  941. if __name__ == "__main__":
  942. if os.getenv("GISBASE") is None:
  943. sys.exit("Failed to start GUI, GRASS GIS is not running.")
  944. GRASSStartUp = StartUp(0)
  945. GRASSStartUp.MainLoop()