gis_set.py 46 KB

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