ii2t_gis_set.py 44 KB

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