6 Initialization module for wxPython GRASS GUI.
7 Location/mapset management (selection, creation, etc.).
10 - gis_set::GRASSStartup
14 (C) 2006-2012 by the GRASS Development Team
16 This program is free software under the GNU General Public License
17 (>=v2). Read the file COPYING that comes with GRASS for details.
19 @author Michael Barton and Jachym Cepicky (original author)
20 @author Martin Landa <landa.martin gmail.com> (various updates)
33 gettext.install(
'grasswxpy', os.path.join(os.getenv(
"GISBASE"),
'locale'), unicode =
True)
35 if __name__ ==
"__main__":
36 sys.path.append(os.path.join(os.getenv(
'GISBASE'),
'etc',
'gui',
'wxpython'))
37 from core
import globalvar
39 import wx.lib.mixins.listctrl
as listmix
40 import wx.lib.scrolledpanel
as scrolled
43 from core.gcmd import GMessage, GError, DecodeString, RunCommand
44 from core.utils import GetListOfLocations, GetListOfMapsets
51 sys.stderr = codecs.getwriter(
'utf8')(sys.stderr)
54 """!GRASS start-up screen"""
55 def __init__(self, parent = None, id = wx.ID_ANY, style = wx.DEFAULT_FRAME_STYLE):
71 wx.Frame.__init__(self, parent = parent, id = id, style = style)
73 self.
locale = wx.Locale(language = wx.LANGUAGE_DEFAULT)
75 self.
panel = scrolled.ScrolledPanel(parent = self, id = wx.ID_ANY)
79 gettext.install(
'grasswxpy', os.path.join(os.getenv(
"GISBASE"),
'locale'), unicode =
True)
86 name = os.path.join(globalvar.ETCIMGDIR,
"startup_banner.gif")
88 wx.Bitmap(name = name,
89 type = wx.BITMAP_TYPE_GIF))
91 self.
hbitmap = wx.StaticBitmap(self.
panel, wx.ID_ANY, wx.EmptyBitmap(530,150))
95 versionFile = open(os.path.join(globalvar.ETCDIR,
"VERSIONNUMBER"))
96 grassVersion = versionFile.readline().
split(
' ')[0].rstrip(
'\n')
100 label =
" %s " % _(
"Choose project location and mapset"))
103 label =
" %s " % _(
"Manage"))
105 label = _(
"Welcome to GRASS GIS %s\n"
106 "The world's leading open source GIS") % grassVersion,
107 style = wx.ALIGN_CENTRE)
109 label = _(
"Select an existing project location and mapset\n"
110 "or define a new location"),
111 style = wx.ALIGN_CENTRE)
113 label = _(
"GIS Data Directory:"))
115 label = _(
"Project location\n(projection/coordinate system)"),
116 style = wx.ALIGN_CENTRE)
118 label = _(
"Accessible mapsets\n(directories of GIS files)"),
119 style = wx.ALIGN_CENTRE)
121 label = _(
"Create new mapset\nin selected location"),
122 style = wx.ALIGN_CENTRE)
124 label = _(
"Define new location"),
125 style = wx.ALIGN_CENTRE)
127 label = _(
"Rename/delete selected\nmapset or location"),
128 style = wx.ALIGN_CENTRE)
132 label = _(
"Start &GRASS"))
133 self.bstart.SetDefault()
135 self.bstart.SetMinSize((180, self.bexit.GetSize()[1]))
138 label = _(
"&Browse"))
140 label = _(
"&Create mapset"))
142 label = _(
"&Location wizard"))
143 self.bwizard.SetToolTipString(_(
"Start location wizard."
144 " After location is created successfully,"
145 " GRASS session is started."))
147 choices = [_(
'Rename mapset'), _(
'Rename location'),
148 _(
'Delete mapset'), _(
'Delete location')])
149 self.manageloc.SetSelection(0)
152 self.
tgisdbase = wx.TextCtrl(parent = self.
panel, id = wx.ID_ANY, value =
"", size = (300, -1),
153 style = wx.TE_PROCESS_ENTER)
157 id = wx.ID_ANY, size = (180, 200),
160 self.lblocations.SetColumnWidth(0, 180)
165 id = wx.ID_ANY, size = (180, 200),
168 self.lbmapsets.SetColumnWidth(0, 180)
175 self.bbrowse.Bind(wx.EVT_BUTTON, self.
OnBrowse)
176 self.bstart.Bind(wx.EVT_BUTTON, self.
OnStart)
177 self.bexit.Bind(wx.EVT_BUTTON, self.
OnExit)
178 self.bhelp.Bind(wx.EVT_BUTTON, self.
OnHelp)
180 self.bwizard.Bind(wx.EVT_BUTTON, self.
OnWizard)
181 self.manageloc.Bind(wx.EVT_CHOICE, self.
OnManageLoc)
183 self.lbmapsets.Bind(wx.EVT_LIST_ITEM_SELECTED, self.
OnSelectMapset)
184 self.lbmapsets.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.
OnStart)
188 def _set_properties(self):
189 """!Set frame properties"""
190 self.SetTitle(_(
"Welcome to GRASS GIS"))
191 self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR,
"grass.ico"),
194 self.lwelcome.SetForegroundColour(wx.Colour(35, 142, 35))
195 self.lwelcome.SetFont(wx.Font(13, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0,
""))
197 self.bstart.SetForegroundColour(wx.Colour(35, 142, 35))
198 self.bstart.SetToolTipString(_(
"Enter GRASS session"))
199 self.bstart.Enable(
False)
200 self.bmapset.Enable(
False)
201 self.manageloc.Enable(
False)
206 if os.path.isdir(os.getenv(
"HOME")):
211 self.tgisdbase.SetValue(self.
gisdbase)
212 except UnicodeDecodeError:
213 wx.MessageBox(parent = self, caption = _(
"Error"),
214 message = _(
"Unable to set GRASS database. "
215 "Check your locale settings."),
216 style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
220 if location ==
"<UNKNOWN>" or \
221 not os.path.isdir(os.path.join(self.
gisdbase, location)):
228 self.lblocations.SetSelection(self.listOfLocations.index(location),
230 self.lblocations.EnsureVisible(self.listOfLocations.index(location))
232 print >> sys.stderr, _(
"ERROR: Location <%s> not found") % location
239 self.lbmapsets.SetSelection(self.listOfMapsets.index(mapset),
241 self.lbmapsets.EnsureVisible(self.listOfMapsets.index(mapset))
243 self.lbmapsets.Clear()
244 print >> sys.stderr, _(
"ERROR: Mapset <%s> not found") % mapset
246 def _do_layout(self):
247 sizer = wx.BoxSizer(wx.VERTICAL)
248 dbase_sizer = wx.BoxSizer(wx.HORIZONTAL)
249 location_sizer = wx.BoxSizer(wx.HORIZONTAL)
250 select_boxsizer = wx.StaticBoxSizer(self.
select_box, wx.VERTICAL)
251 select_sizer = wx.FlexGridSizer(rows = 2, cols = 2, vgap = 4, hgap = 4)
252 select_sizer.AddGrowableRow(1)
253 select_sizer.AddGrowableCol(0)
254 select_sizer.AddGrowableCol(1)
255 manage_sizer = wx.StaticBoxSizer(self.
manage_box, wx.VERTICAL)
256 btns_sizer = wx.BoxSizer(wx.HORIZONTAL)
259 dbase_sizer.Add(item = self.
ldbase, proportion = 0,
260 flag = wx.ALIGN_CENTER_VERTICAL |
261 wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
263 dbase_sizer.Add(item = self.
tgisdbase, proportion = 1,
264 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL,
266 dbase_sizer.Add(item = self.
bbrowse, proportion = 0,
267 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL,
271 select_sizer.Add(item = self.
llocation, proportion = 0,
272 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
274 select_sizer.Add(item = self.
lmapset, proportion = 0,
275 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
277 select_sizer.Add(item = self.
lblocations, proportion = 1,
279 select_sizer.Add(item = self.
lbmapsets, proportion = 1,
282 select_boxsizer.Add(item = select_sizer, proportion = 1,
286 manage_sizer.Add(item = self.
ldefine, proportion = 0,
287 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
289 manage_sizer.Add(item = self.
bwizard, proportion = 0,
290 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM,
292 manage_sizer.Add(item = self.
lcreate, proportion = 0,
293 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
295 manage_sizer.Add(item = self.
bmapset, proportion = 0,
296 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM,
298 manage_sizer.Add(item = self.
lmanageloc, proportion = 0,
299 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
301 manage_sizer.Add(item = self.
manageloc, proportion = 0,
302 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM,
306 location_sizer.Add(item = select_boxsizer, proportion = 1,
307 flag = wx.LEFT | wx.RIGHT | wx.EXPAND,
309 location_sizer.Add(item = manage_sizer, proportion = 0,
310 flag = wx.RIGHT | wx.EXPAND,
314 btns_sizer.Add(item = self.
bstart, proportion = 0,
315 flag = wx.ALIGN_CENTER_HORIZONTAL |
316 wx.ALIGN_CENTER_VERTICAL |
319 btns_sizer.Add(item = self.
bexit, proportion = 0,
320 flag = wx.ALIGN_CENTER_HORIZONTAL |
321 wx.ALIGN_CENTER_VERTICAL |
324 btns_sizer.Add(item = self.
bhelp, proportion = 0,
325 flag = wx.ALIGN_CENTER_HORIZONTAL |
326 wx.ALIGN_CENTER_VERTICAL |
333 flag = wx.ALIGN_CENTER_VERTICAL |
334 wx.ALIGN_CENTER_HORIZONTAL |
339 flag = wx.ALIGN_CENTER_VERTICAL |
340 wx.ALIGN_CENTER_HORIZONTAL |
343 sizer.Add(item = self.
ltitle,
345 flag = wx.ALIGN_CENTER_VERTICAL |
346 wx.ALIGN_CENTER_HORIZONTAL)
347 sizer.Add(item = dbase_sizer, proportion = 0,
348 flag = wx.ALIGN_CENTER_HORIZONTAL |
349 wx.RIGHT | wx.LEFT | wx.EXPAND,
351 sizer.Add(item = location_sizer, proportion = 1,
352 flag = wx.RIGHT | wx.LEFT | wx.EXPAND,
354 sizer.Add(item = btns_sizer, proportion = 0,
355 flag = wx.ALIGN_CENTER_VERTICAL |
356 wx.ALIGN_CENTER_HORIZONTAL |
360 self.panel.SetAutoLayout(
True)
361 self.panel.SetSizer(sizer)
362 sizer.Fit(self.
panel)
363 sizer.SetSizeHints(self)
367 def _readGisRC(self):
369 Read variables from $HOME/.grassrc6 file
374 gisrc = os.getenv(
"GISRC")
376 if gisrc
and os.path.isfile(gisrc):
378 rc = open(gisrc,
"r")
379 for line
in rc.readlines():
381 key, val = line.split(
":", 1)
382 except ValueError, e:
383 sys.stderr.write(_(
'Invalid line in GISRC file (%(e)s):%(l)s\n' % \
384 {
'e': e,
'l': line}))
392 """!Return GRASS variable (read from GISRC)
394 if self.grassrc.has_key(value):
400 """!Location wizard started"""
402 gWizard = LocationWizard(parent = self,
403 grassdatabase = self.tgisdbase.GetValue())
404 if gWizard.location !=
None:
405 self.tgisdbase.SetValue(gWizard.grassdatabase)
408 self.lblocations.SetSelection(self.listOfLocations.index(gWizard.location))
409 self.lbmapsets.SetSelection(0)
411 if gWizard.georeffile:
412 message = _(
"Do you want to import data source <%(name)s> to created location?"
413 " Default region will be set to match imported map.") % {
'name': gWizard.georeffile}
414 dlg = wx.MessageDialog(parent = self,
416 caption = _(
"Import data"),
417 style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
419 if dlg.ShowModal() == wx.ID_YES:
427 dlg = TextEntryDialog(parent=self,
428 message=_(
"Do you want to create new mapset?"),
429 caption=_(
"Create new mapset"),
432 style=wx.OK | wx.CANCEL | wx.HELP)
433 help = dlg.FindWindowById(wx.ID_HELP)
434 help.Bind(wx.EVT_BUTTON, self.
OnHelp)
435 if dlg.ShowModal() == wx.ID_OK:
436 mapsetName = dlg.GetValue()
440 """!Asks to set default region."""
441 dlg = wx.MessageDialog(parent = self,
442 message = _(
"Do you want to set the default "
443 "region extents and resolution now?"),
444 caption = _(
"Location <%s> created") % location,
445 style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
447 if dlg.ShowModal() == wx.ID_YES:
449 defineRegion = RegionDef(self, location = location)
450 defineRegion.CenterOnScreen()
451 defineRegion.ShowModal()
452 defineRegion.Destroy()
457 """!Tries to import file as vector or raster.
459 If successfull sets default region from imported map.
461 returncode, stdout, messagesIfVector =
RunCommand(
'v.in.ogr', dsn = filePath, flags =
'l',
462 read =
True, getErrorMsg =
True)
466 returncode, messages =
RunCommand(
'v.in.ogr', dsn = filePath,
467 output = os.path.splitext(os.path.basename(filePath))[0],
471 message = _(
"Import of vector data source <%(name)s> failed.") % {
'name': filePath}
472 message +=
"\n" + messages
473 GError(message = message)
475 GMessage(message = _(
"Vector data source <%(name)s> imported successfully.") % {
'name': filePath})
476 stdout =
RunCommand(
'g.list', type =
'vect', read =
True)
477 maps = stdout.splitlines()
480 RunCommand(
'g.region', flags =
's', vect = maps[0])
485 returncode, messages =
RunCommand(
'r.in.gdal', input = filePath,
486 output = os.path.splitext(os.path.basename(filePath))[0],
490 message = _(
"Attempt to import data source <%(name)s> as raster or vector failed. ") % {
'name': filePath}
491 message +=
"\n\n" + messagesIfVector +
"\n" + messages
492 GError(message = message)
494 GMessage(message = _(
"Raster data source <%(name)s> imported successfully.") % {
'name': filePath})
495 stdout =
RunCommand(
'g.list', type =
'rast', read =
True)
496 maps = stdout.splitlines()
498 RunCommand(
'g.region', flags =
's', rast = maps[0])
501 """!Location management choice control handler
503 sel = event.GetSelection()
516 """!Rename selected mapset
520 if mapset ==
'PERMANENT':
521 GMessage(parent = self,
522 message = _(
'Mapset <PERMANENT> is required for valid GRASS location.\n\n'
523 'This mapset cannot be renamed.'))
526 dlg = TextEntryDialog(parent = self,
527 message = _(
'Current name: %s\n\nEnter new name:') % mapset,
528 caption = _(
'Rename selected mapset'),
531 if dlg.ShowModal() == wx.ID_OK:
532 newmapset = dlg.GetValue()
533 if newmapset == mapset:
538 wx.MessageBox(parent = self,
539 caption = _(
'Message'),
540 message = _(
'Unable to rename mapset.\n\n'
541 'Mapset <%s> already exists in location.') % newmapset,
542 style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
545 os.rename(os.path.join(self.
gisdbase, location, mapset),
546 os.path.join(self.
gisdbase, location, newmapset))
548 self.lbmapsets.SetSelection(self.listOfMapsets.index(newmapset))
549 except StandardError, e:
550 wx.MessageBox(parent = self,
551 caption = _(
'Error'),
552 message = _(
'Unable to rename mapset.\n\n%s') % e,
553 style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
558 """!Rename selected location
562 dlg = TextEntryDialog(parent = self,
563 message = _(
'Current name: %s\n\nEnter new name:') % location,
564 caption = _(
'Rename selected location'),
567 if dlg.ShowModal() == wx.ID_OK:
568 newlocation = dlg.GetValue()
569 if newlocation == location:
574 wx.MessageBox(parent = self,
575 caption = _(
'Message'),
576 message = _(
'Unable to rename location.\n\n'
577 'Location <%s> already exists in GRASS database.') % newlocation,
578 style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
581 os.rename(os.path.join(self.
gisdbase, location),
582 os.path.join(self.
gisdbase, newlocation))
584 self.lblocations.SetSelection(self.listOfLocations.index(newlocation))
586 except StandardError, e:
587 wx.MessageBox(parent = self,
588 caption = _(
'Error'),
589 message = _(
'Unable to rename location.\n\n%s') % e,
590 style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
595 """!Delete selected mapset
599 if mapset ==
'PERMANENT':
600 GMessage(parent = self,
601 message = _(
'Mapset <PERMANENT> is required for valid GRASS location.\n\n'
602 'This mapset cannot be deleted.'))
605 dlg = wx.MessageDialog(parent = self, message = _(
"Do you want to continue with deleting mapset <%(mapset)s> "
606 "from location <%(location)s>?\n\n"
607 "ALL MAPS included in this mapset will be "
608 "PERMANENTLY DELETED!") % {
'mapset' : mapset,
609 'location' : location},
610 caption = _(
"Delete selected mapset"),
611 style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
613 if dlg.ShowModal() == wx.ID_YES:
615 shutil.rmtree(os.path.join(self.
gisdbase, location, mapset))
617 self.lbmapsets.SetSelection(0)
619 wx.MessageBox(message = _(
'Unable to delete mapset'))
625 Delete selected location
630 dlg = wx.MessageDialog(parent = self, message = _(
"Do you want to continue with deleting "
632 "ALL MAPS included in this location will be "
633 "PERMANENTLY DELETED!") % (location),
634 caption = _(
"Delete selected location"),
635 style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
637 if dlg.ShowModal() == wx.ID_YES:
639 shutil.rmtree(os.path.join(self.
gisdbase, location))
641 self.lblocations.SetSelection(0)
643 self.lbmapsets.SetSelection(0)
645 wx.MessageBox(message = _(
'Unable to delete location'))
650 """!Update list of locations"""
653 except UnicodeEncodeError:
654 wx.MessageBox(parent = self, caption = _(
"Error"),
655 message = _(
"Unable to set GRASS database. "
656 "Check your locale settings."),
657 style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
659 self.lblocations.Clear()
663 self.lblocations.SetSelection(0)
665 self.lblocations.SetSelection(wx.NOT_FOUND)
670 """!Update list of mapsets"""
676 self.lbmapsets.Clear()
679 locationName = os.path.basename(location)
684 location = locationName,
688 for line
in ret.splitlines():
692 set =
"GISDBASE=%s" % self.
gisdbase)
694 set =
"LOCATION_NAME=%s" % locationName)
696 set =
"MAPSET=PERMANENT")
704 os.path.isfile(os.path.join(self.
gisdbase,
706 mapset,
".gislock")):
710 self.lbmapsets.InsertItems(self.
listOfMapsets, 0, disabled = disabled)
715 """!Location selected"""
717 self.lblocations.SetSelection(event.GetIndex())
719 if self.lblocations.GetSelection() != wx.NOT_FOUND:
734 os.path.isfile(os.path.join(self.
gisdbase,
736 mapset,
".gislock")):
740 self.lbmapsets.Clear()
741 self.lbmapsets.InsertItems(self.
listOfMapsets, 0, disabled = disabled)
744 self.lbmapsets.SetSelection(0)
748 self.bmapset.Enable()
749 self.manageloc.Enable()
751 self.lbmapsets.SetSelection(wx.NOT_FOUND)
752 self.bstart.Enable(
False)
753 self.bmapset.Enable(
False)
754 self.manageloc.Enable(
False)
757 """!Mapset selected"""
758 self.lbmapsets.SetSelection(event.GetIndex())
768 self.
gisdbase = self.tgisdbase.GetValue()
775 """'Browse' button clicked"""
777 defaultPath = os.getenv(
'HOME')
781 dlg = wx.DirDialog(parent = self, message = _(
"Choose GIS Data Directory"),
782 defaultPath = defaultPath, style = wx.DD_DEFAULT_STYLE)
784 if dlg.ShowModal() == wx.ID_OK:
786 self.tgisdbase.SetValue(self.
gisdbase)
792 """!Create new mapset"""
794 dlg = TextEntryDialog(parent = self,
795 message = _(
'Enter name for new mapset:'),
796 caption = _(
'Create new mapset'),
800 if dlg.ShowModal() == wx.ID_OK:
801 mapset = dlg.GetValue()
808 GMessage(parent = self,
809 message = _(
"Mapset <%s> already exists.") % mapset)
813 self.
gisdbase = self.tgisdbase.GetValue()
815 os.mkdir(os.path.join(self.
gisdbase, location, mapset))
817 shutil.copy(os.path.join(self.
gisdbase, location,
'PERMANENT',
'WIND'),
818 os.path.join(self.
gisdbase, location, mapset))
821 self.lbmapsets.SetSelection(self.listOfMapsets.index(mapset))
822 self.bstart.SetFocus()
824 except StandardError, e:
825 GError(parent = self,
826 message = _(
"Unable to create new mapset: %s") % e,
827 showTraceback =
False)
831 """'Start GRASS' button clicked"""
832 dbase = self.tgisdbase.GetValue()
836 lockfile = os.path.join(dbase, location, mapset,
'.gislock')
837 if os.path.isfile(lockfile):
838 dlg = wx.MessageDialog(parent = self,
839 message = _(
"GRASS is already running in selected mapset <%(mapset)s>\n"
840 "(file %(lock)s found).\n\n"
841 "Concurrent use not allowed.\n\n"
842 "Do you want to try to remove .gislock (note that you "
843 "need permission for this operation) and continue?") %
844 {
'mapset' : mapset,
'lock' : lockfile },
845 caption = _(
"Lock file found"),
846 style = wx.YES_NO | wx.NO_DEFAULT |
847 wx.ICON_QUESTION | wx.CENTRE)
849 ret = dlg.ShowModal()
852 dlg1 = wx.MessageDialog(parent = self,
853 message = _(
"ARE YOU REALLY SURE?\n\n"
854 "If you really are running another GRASS session doing this "
855 "could corrupt your data. Have another look in the processor "
856 "manager just to be sure..."),
857 caption = _(
"Lock file found"),
858 style = wx.YES_NO | wx.NO_DEFAULT |
859 wx.ICON_QUESTION | wx.CENTRE)
861 ret = dlg1.ShowModal()
868 GError(_(
"Unable to remove '%(lock)s'.\n\n"
869 "Details: %(reason)s") % {
'lock' : lockfile,
'reason' : e})
879 set =
"GISDBASE=%s" % dbase)
881 set =
"LOCATION_NAME=%s" % location)
883 set =
"MAPSET=%s" % mapset)
886 def _getDefaultMapsetName(self):
887 """!Returns default name for mapset."""
889 defaultName = getpass.getuser()
890 defaultName.encode(
'ascii')
901 """'Exit' button clicked"""
906 """'Help' button clicked"""
908 filePath = os.path.join(self.
gisbase,
"docs",
"html",
"helptext.html")
910 webbrowser.open(filePath)
913 """!Close window event"""
917 def _nameValidationFailed(self, ctrl):
918 message = _(
"Name <%(name)s> is not a valid name for location or mapset. "
919 "Please use only ASCII characters excluding %(chars)s "
920 "and space.") % {
'name': ctrl.GetValue(),
'chars':
'/"\'@,=*~'}
921 GError(parent=self, message=message, caption=_(
"Invalid name"))
923 class GListBox(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
924 """!Use wx.ListCtrl instead of wx.ListBox, different style for
925 non-selectable items (e.g. mapsets with denied permission)"""
926 def __init__(self, parent, id, size,
927 choices, disabled = []):
928 wx.ListCtrl.__init__(self, parent, id, size = size,
929 style = wx.LC_REPORT | wx.LC_NO_HEADER | wx.LC_SINGLE_SEL |
932 listmix.ListCtrlAutoWidthMixin.__init__(self)
934 self.InsertColumn(0,
'')
940 def _LoadData(self, choices, disabled = []):
941 """!Load data into list
943 @param choices list of item
944 @param disabled list of indeces of non-selectable items
948 index = self.InsertStringItem(sys.maxint, item)
949 self.SetStringItem(index, 0, item)
952 self.SetItemTextColour(idx, wx.Colour(150, 150, 150))
956 self.DeleteAllItems()
962 if item != wx.NOT_FOUND
and \
963 (platform.system() !=
'Windows' or force):
965 self.SetItemState(item, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
973 """!Start-up application"""
976 wx.InitAllImageHandlers()
978 StartUp.CenterOnScreen()
979 self.SetTopWindow(StartUp)
982 if StartUp.GetRCValue(
"LOCATION_NAME") ==
"<UNKNOWN>":
983 wx.MessageBox(parent = StartUp,
984 caption = _(
'Starting GRASS for the first time'),
985 message = _(
'GRASS needs a directory in which to store its data. '
986 'Create one now if you have not already done so. '
987 'A popular choice is "grassdata", located in '
988 'your home directory.'),
989 style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
991 StartUp.OnBrowse(
None)
995 if __name__ ==
"__main__":
996 if os.getenv(
"GISBASE")
is None:
997 sys.exit(
"Failed to start GUI, GRASS GIS is not running.")
1000 gettext.install(
'grasswxpy', os.path.join(os.getenv(
"GISBASE"),
'locale'), unicode =
True)
1003 GRASSStartUp.MainLoop()
def GetListOfLocations
Get list of GRASS locations in given dbase.
def DecodeString
Decode string using system encoding.
Location wizard - dialogs.
Location wizard - creates a new GRASS Location.
def OnSelectLocation
Location selected.
def OnSelectMapset
Mapset selected.
def GetListOfMapsets
Get list of mapsets in given GRASS location.
def _set_properties
Set frame properties.
def OnManageLoc
Location management choice control handler.
def RenameMapset
Rename selected mapset.
def OnCreateMapset
Create new mapset.
select_box
crashes when LOCATION doesn't exist
def OnWizard
Location wizard started.
def OnSetDatabase
Database set.
Various dialogs used in wxGUI.
def UpdateMapsets
Update list of mapsets.
def split
Platform spefic shlex.split.
def ImportFile
Tries to import file as vector or raster.
def _LoadData
Load data into list.
selected
Windows -> FIXME.
def GetRCValue
Return GRASS variable (read from GISRC)
def DeleteMapset
Delete selected mapset.
def SetDefaultRegion
Asks to set default region.
Misc utilities for wxGUI.
Use wx.ListCtrl instead of wx.ListBox, different style for non-selectable items (e.g.
def UpdateLocations
Update list of locations.
def OnCloseWindow
Close window event.
def _nameValidationFailed
def RenameLocation
Rename selected location.
def RunCommand
Run GRASS command.
def _getDefaultMapsetName
Returns default name for mapset.