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
45 from core.gcmd import GMessage, GError, DecodeString, RunCommand, GWarning
46 from core.utils import GetListOfLocations, GetListOfMapsets
53 sys.stderr = codecs.getwriter(
'utf8')(sys.stderr)
56 """!GRASS start-up screen"""
57 def __init__(self, parent = None, id = wx.ID_ANY, style = wx.DEFAULT_FRAME_STYLE):
73 wx.Frame.__init__(self, parent = parent, id = id, style = style)
75 self.
locale = wx.Locale(language = wx.LANGUAGE_DEFAULT)
77 self.
panel = scrolled.ScrolledPanel(parent = self, id = wx.ID_ANY)
81 gettext.install(
'grasswxpy', os.path.join(os.getenv(
"GISBASE"),
'locale'), unicode =
True)
88 name = os.path.join(globalvar.ETCIMGDIR,
"startup_banner.gif")
90 wx.Bitmap(name = name,
91 type = wx.BITMAP_TYPE_GIF))
93 self.
hbitmap = wx.StaticBitmap(self.
panel, wx.ID_ANY, wx.EmptyBitmap(530,150))
97 versionFile = open(os.path.join(globalvar.ETCDIR,
"VERSIONNUMBER"))
98 grassVersion = versionFile.readline().
split(
' ')[0].rstrip(
'\n')
102 label =
" %s " % _(
"Choose project location and mapset"))
105 label =
" %s " % _(
"Manage"))
107 label = _(
"Welcome to GRASS GIS %s\n"
108 "The world's leading open source GIS") % grassVersion,
109 style = wx.ALIGN_CENTRE)
111 label = _(
"Select an existing project location and mapset\n"
112 "or define a new location"),
113 style = wx.ALIGN_CENTRE)
115 label = _(
"GIS Data Directory:"))
117 label = _(
"Project location\n(projection/coordinate system)"),
118 style = wx.ALIGN_CENTRE)
120 label = _(
"Accessible mapsets\n(directories of GIS files)"),
121 style = wx.ALIGN_CENTRE)
123 label = _(
"Create new mapset\nin selected location"),
124 style = wx.ALIGN_CENTRE)
126 label = _(
"Define new location"),
127 style = wx.ALIGN_CENTRE)
129 label = _(
"Rename/delete selected\nmapset or location"),
130 style = wx.ALIGN_CENTRE)
134 label = _(
"Start &GRASS"))
135 self.bstart.SetDefault()
137 self.bstart.SetMinSize((180, self.bexit.GetSize()[1]))
140 label = _(
"&Browse"))
142 label = _(
"&Create mapset"))
144 label = _(
"&Location wizard"))
145 self.bwizard.SetToolTipString(_(
"Start location wizard."
146 " After location is created successfully,"
147 " GRASS session is started."))
149 choices = [_(
'Rename mapset'), _(
'Rename location'),
150 _(
'Delete mapset'), _(
'Delete location')])
151 self.manageloc.SetSelection(0)
154 self.
tgisdbase = wx.TextCtrl(parent = self.
panel, id = wx.ID_ANY, value =
"", size = (300, -1),
155 style = wx.TE_PROCESS_ENTER)
159 id = wx.ID_ANY, size = (180, 200),
162 self.lblocations.SetColumnWidth(0, 180)
167 id = wx.ID_ANY, size = (180, 200),
170 self.lbmapsets.SetColumnWidth(0, 180)
177 self.bbrowse.Bind(wx.EVT_BUTTON, self.
OnBrowse)
178 self.bstart.Bind(wx.EVT_BUTTON, self.
OnStart)
179 self.bexit.Bind(wx.EVT_BUTTON, self.
OnExit)
180 self.bhelp.Bind(wx.EVT_BUTTON, self.
OnHelp)
182 self.bwizard.Bind(wx.EVT_BUTTON, self.
OnWizard)
183 self.manageloc.Bind(wx.EVT_CHOICE, self.
OnManageLoc)
185 self.lbmapsets.Bind(wx.EVT_LIST_ITEM_SELECTED, self.
OnSelectMapset)
186 self.lbmapsets.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.
OnStart)
190 def _set_properties(self):
191 """!Set frame properties"""
192 self.SetTitle(_(
"Welcome to GRASS GIS"))
193 self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR,
"grass.ico"),
196 self.lwelcome.SetForegroundColour(wx.Colour(35, 142, 35))
197 self.lwelcome.SetFont(wx.Font(13, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0,
""))
199 self.bstart.SetForegroundColour(wx.Colour(35, 142, 35))
200 self.bstart.SetToolTipString(_(
"Enter GRASS session"))
201 self.bstart.Enable(
False)
202 self.bmapset.Enable(
False)
203 self.manageloc.Enable(
False)
208 if os.path.isdir(os.getenv(
"HOME")):
213 self.tgisdbase.SetValue(self.
gisdbase)
214 except UnicodeDecodeError:
215 wx.MessageBox(parent = self, caption = _(
"Error"),
216 message = _(
"Unable to set GRASS database. "
217 "Check your locale settings."),
218 style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
222 if location ==
"<UNKNOWN>":
224 if not os.path.isdir(os.path.join(self.
gisdbase, location)):
230 self.lblocations.SetSelection(self.listOfLocations.index(location),
232 self.lblocations.EnsureVisible(self.listOfLocations.index(location))
234 sys.stderr.write(_(
"ERROR: Location <%s> not found\n") % self.
GetRCValue(
"LOCATION_NAME"))
236 self.lblocations.SetSelection(0, force =
True)
237 self.lblocations.EnsureVisible(0)
247 self.lbmapsets.SetSelection(self.listOfMapsets.index(mapset),
249 self.lbmapsets.EnsureVisible(self.listOfMapsets.index(mapset))
251 sys.stderr.write(_(
"ERROR: Mapset <%s> not found\n") % mapset)
252 self.lbmapsets.SetSelection(0, force =
True)
253 self.lbmapsets.EnsureVisible(0)
255 def _do_layout(self):
256 sizer = wx.BoxSizer(wx.VERTICAL)
257 dbase_sizer = wx.BoxSizer(wx.HORIZONTAL)
258 location_sizer = wx.BoxSizer(wx.HORIZONTAL)
259 select_boxsizer = wx.StaticBoxSizer(self.
select_box, wx.VERTICAL)
260 select_sizer = wx.FlexGridSizer(rows = 2, cols = 2, vgap = 4, hgap = 4)
261 select_sizer.AddGrowableRow(1)
262 select_sizer.AddGrowableCol(0)
263 select_sizer.AddGrowableCol(1)
264 manage_sizer = wx.StaticBoxSizer(self.
manage_box, wx.VERTICAL)
265 btns_sizer = wx.BoxSizer(wx.HORIZONTAL)
268 dbase_sizer.Add(item = self.
ldbase, proportion = 0,
269 flag = wx.ALIGN_CENTER_VERTICAL |
270 wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
272 dbase_sizer.Add(item = self.
tgisdbase, proportion = 1,
273 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL,
275 dbase_sizer.Add(item = self.
bbrowse, proportion = 0,
276 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL,
280 select_sizer.Add(item = self.
llocation, proportion = 0,
281 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
283 select_sizer.Add(item = self.
lmapset, proportion = 0,
284 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
286 select_sizer.Add(item = self.
lblocations, proportion = 1,
288 select_sizer.Add(item = self.
lbmapsets, proportion = 1,
291 select_boxsizer.Add(item = select_sizer, proportion = 1,
295 manage_sizer.Add(item = self.
ldefine, proportion = 0,
296 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
298 manage_sizer.Add(item = self.
bwizard, proportion = 0,
299 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM,
301 manage_sizer.Add(item = self.
lcreate, proportion = 0,
302 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
304 manage_sizer.Add(item = self.
bmapset, proportion = 0,
305 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM,
307 manage_sizer.Add(item = self.
lmanageloc, proportion = 0,
308 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
310 manage_sizer.Add(item = self.
manageloc, proportion = 0,
311 flag = wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM,
315 location_sizer.Add(item = select_boxsizer, proportion = 1,
316 flag = wx.LEFT | wx.RIGHT | wx.EXPAND,
318 location_sizer.Add(item = manage_sizer, proportion = 0,
319 flag = wx.RIGHT | wx.EXPAND,
323 btns_sizer.Add(item = self.
bstart, proportion = 0,
324 flag = wx.ALIGN_CENTER_HORIZONTAL |
325 wx.ALIGN_CENTER_VERTICAL |
328 btns_sizer.Add(item = self.
bexit, proportion = 0,
329 flag = wx.ALIGN_CENTER_HORIZONTAL |
330 wx.ALIGN_CENTER_VERTICAL |
333 btns_sizer.Add(item = self.
bhelp, proportion = 0,
334 flag = wx.ALIGN_CENTER_HORIZONTAL |
335 wx.ALIGN_CENTER_VERTICAL |
342 flag = wx.ALIGN_CENTER_VERTICAL |
343 wx.ALIGN_CENTER_HORIZONTAL |
348 flag = wx.ALIGN_CENTER_VERTICAL |
349 wx.ALIGN_CENTER_HORIZONTAL |
352 sizer.Add(item = self.
ltitle,
354 flag = wx.ALIGN_CENTER_VERTICAL |
355 wx.ALIGN_CENTER_HORIZONTAL)
356 sizer.Add(item = dbase_sizer, proportion = 0,
357 flag = wx.ALIGN_CENTER_HORIZONTAL |
358 wx.RIGHT | wx.LEFT | wx.EXPAND,
360 sizer.Add(item = location_sizer, proportion = 1,
361 flag = wx.RIGHT | wx.LEFT | wx.EXPAND,
363 sizer.Add(item = btns_sizer, proportion = 0,
364 flag = wx.ALIGN_CENTER_VERTICAL |
365 wx.ALIGN_CENTER_HORIZONTAL |
369 self.panel.SetAutoLayout(
True)
370 self.panel.SetSizer(sizer)
371 sizer.Fit(self.
panel)
372 sizer.SetSizeHints(self)
376 def _readGisRC(self):
378 Read variables from $HOME/.grassrc6 file
383 gisrc = os.getenv(
"GISRC")
385 if gisrc
and os.path.isfile(gisrc):
387 rc = open(gisrc,
"r")
388 for line
in rc.readlines():
390 key, val = line.split(
":", 1)
391 except ValueError, e:
392 sys.stderr.write(_(
'Invalid line in GISRC file (%s):%s\n' % \
401 """!Return GRASS variable (read from GISRC)
403 if self.grassrc.has_key(value):
409 """!Location wizard started"""
411 gWizard = LocationWizard(parent = self,
412 grassdatabase = self.tgisdbase.GetValue())
413 if gWizard.location !=
None:
414 self.tgisdbase.SetValue(gWizard.grassdatabase)
417 self.lblocations.SetSelection(self.listOfLocations.index(gWizard.location))
418 self.lbmapsets.SetSelection(0)
420 if gWizard.georeffile:
421 message = _(
"Do you want to import <%(name)s> to the newly created location? "
422 "The location's default region will be set from this imported "
423 "map.") % {
'name': gWizard.georeffile}
424 dlg = wx.MessageDialog(parent = self,
426 caption = _(
"Import data?"),
427 style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
429 if dlg.ShowModal() == wx.ID_YES:
437 dlg = TextEntryDialog(parent=self,
438 message=_(
"Do you want to create new mapset?"),
439 caption=_(
"Create new mapset"),
442 style=wx.OK | wx.CANCEL | wx.HELP)
443 help = dlg.FindWindowById(wx.ID_HELP)
444 help.Bind(wx.EVT_BUTTON, self.
OnHelp)
445 if dlg.ShowModal() == wx.ID_OK:
446 mapsetName = dlg.GetValue()
450 """!Asks to set default region."""
451 dlg = wx.MessageDialog(parent = self,
452 message = _(
"Do you want to set the default "
453 "region extents and resolution now?"),
454 caption = _(
"Location <%s> created") % location,
455 style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
457 if dlg.ShowModal() == wx.ID_YES:
459 defineRegion = RegionDef(self, location = location)
460 defineRegion.CenterOnScreen()
461 defineRegion.ShowModal()
462 defineRegion.Destroy()
467 """!Tries to import file as vector or raster.
469 If successfull sets default region from imported map.
471 mapName = os.path.splitext(os.path.basename(filePath))[0]
472 vectors =
RunCommand(
'v.in.ogr', dsn = filePath, flags =
'l',
477 if mapName
in vectors:
479 returncode, error =
RunCommand(
'v.in.ogr', dsn = filePath, output = mapName,
482 returncode, error =
RunCommand(
'r.in.gdal', input = filePath, output = mapName,
487 GError(parent = self,
488 message = _(
"Import of <%(name)s> failed.\n"
489 "Reason: %(msg)s") % ({
'name': filePath,
'msg': error}))
491 GMessage(message = _(
"Data file <%(name)s> imported successfully.") % {
'name': filePath},
493 if not grass.find_file(element =
'cell', name = mapName)[
'fullname']
and \
494 not grass.find_file(element =
'vector', name = mapName)[
'fullname']:
495 GError(parent = self,
496 message = _(
"Map <%s> not found.") % mapName)
498 if mapName
in vectors:
499 args = {
'vect' : mapName}
501 args = {
'rast' : mapName}
502 RunCommand(
'g.region', flags =
's', parent = self, **args)
505 """!Location management choice control handler
507 sel = event.GetSelection()
520 """!Rename selected mapset
524 if mapset ==
'PERMANENT':
525 GMessage(parent = self,
526 message = _(
'Mapset <PERMANENT> is required for valid GRASS location.\n\n'
527 'This mapset cannot be renamed.'))
530 dlg = TextEntryDialog(parent = self,
531 message = _(
'Current name: %s\n\nEnter new name:') % mapset,
532 caption = _(
'Rename selected mapset'),
535 if dlg.ShowModal() == wx.ID_OK:
536 newmapset = dlg.GetValue()
537 if newmapset == mapset:
542 wx.MessageBox(parent = self,
543 caption = _(
'Message'),
544 message = _(
'Unable to rename mapset.\n\n'
545 'Mapset <%s> already exists in location.') % newmapset,
546 style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
549 os.rename(os.path.join(self.
gisdbase, location, mapset),
550 os.path.join(self.
gisdbase, location, newmapset))
552 self.lbmapsets.SetSelection(self.listOfMapsets.index(newmapset))
553 except StandardError, e:
554 wx.MessageBox(parent = self,
555 caption = _(
'Error'),
556 message = _(
'Unable to rename mapset.\n\n%s') % e,
557 style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
562 """!Rename selected location
566 dlg = TextEntryDialog(parent = self,
567 message = _(
'Current name: %s\n\nEnter new name:') % location,
568 caption = _(
'Rename selected location'),
571 if dlg.ShowModal() == wx.ID_OK:
572 newlocation = dlg.GetValue()
573 if newlocation == location:
578 wx.MessageBox(parent = self,
579 caption = _(
'Message'),
580 message = _(
'Unable to rename location.\n\n'
581 'Location <%s> already exists in GRASS database.') % newlocation,
582 style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
585 os.rename(os.path.join(self.
gisdbase, location),
586 os.path.join(self.
gisdbase, newlocation))
588 self.lblocations.SetSelection(self.listOfLocations.index(newlocation))
590 except StandardError, e:
591 wx.MessageBox(parent = self,
592 caption = _(
'Error'),
593 message = _(
'Unable to rename location.\n\n%s') % e,
594 style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
599 """!Delete selected mapset
603 if mapset ==
'PERMANENT':
604 GMessage(parent = self,
605 message = _(
'Mapset <PERMANENT> is required for valid GRASS location.\n\n'
606 'This mapset cannot be deleted.'))
609 dlg = wx.MessageDialog(parent = self, message = _(
"Do you want to continue with deleting mapset <%(mapset)s> "
610 "from location <%(location)s>?\n\n"
611 "ALL MAPS included in this mapset will be "
612 "PERMANENTLY DELETED!") % {
'mapset' : mapset,
613 'location' : location},
614 caption = _(
"Delete selected mapset"),
615 style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
617 if dlg.ShowModal() == wx.ID_YES:
619 shutil.rmtree(os.path.join(self.
gisdbase, location, mapset))
621 self.lbmapsets.SetSelection(0)
623 wx.MessageBox(message = _(
'Unable to delete mapset'))
629 Delete selected location
634 dlg = wx.MessageDialog(parent = self, message = _(
"Do you want to continue with deleting "
636 "ALL MAPS included in this location will be "
637 "PERMANENTLY DELETED!") % (location),
638 caption = _(
"Delete selected location"),
639 style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
641 if dlg.ShowModal() == wx.ID_YES:
643 shutil.rmtree(os.path.join(self.
gisdbase, location))
645 self.lblocations.SetSelection(0)
647 self.lbmapsets.SetSelection(0)
649 wx.MessageBox(message = _(
'Unable to delete location'))
654 """!Update list of locations"""
657 except UnicodeEncodeError:
658 wx.MessageBox(parent = self, caption = _(
"Error"),
659 message = _(
"Unable to set GRASS database. "
660 "Check your locale settings."),
661 style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
663 self.lblocations.Clear()
667 self.lblocations.SetSelection(0)
669 self.lblocations.SetSelection(wx.NOT_FOUND)
674 """!Update list of mapsets"""
680 self.lbmapsets.Clear()
683 locationName = os.path.basename(location)
688 location = locationName,
692 for line
in ret.splitlines():
696 set =
"GISDBASE=%s" % self.
gisdbase)
698 set =
"LOCATION_NAME=%s" % locationName)
700 set =
"MAPSET=PERMANENT")
708 os.path.isfile(os.path.join(self.
gisdbase,
710 mapset,
".gislock")):
714 self.lbmapsets.InsertItems(self.
listOfMapsets, 0, disabled = disabled)
719 """!Location selected"""
721 self.lblocations.SetSelection(event.GetIndex())
723 if self.lblocations.GetSelection() != wx.NOT_FOUND:
738 os.path.isfile(os.path.join(self.
gisdbase,
740 mapset,
".gislock")):
744 self.lbmapsets.Clear()
745 self.lbmapsets.InsertItems(self.
listOfMapsets, 0, disabled = disabled)
748 self.lbmapsets.SetSelection(0)
752 self.bmapset.Enable()
753 self.manageloc.Enable()
755 self.lbmapsets.SetSelection(wx.NOT_FOUND)
756 self.bstart.Enable(
False)
757 self.bmapset.Enable(
False)
758 self.manageloc.Enable(
False)
761 """!Mapset selected"""
762 self.lbmapsets.SetSelection(event.GetIndex())
772 self.
gisdbase = self.tgisdbase.GetValue()
779 """'Browse' button clicked"""
781 defaultPath = os.getenv(
'HOME')
785 dlg = wx.DirDialog(parent = self, message = _(
"Choose GIS Data Directory"),
786 defaultPath = defaultPath, style = wx.DD_DEFAULT_STYLE)
788 if dlg.ShowModal() == wx.ID_OK:
790 self.tgisdbase.SetValue(self.
gisdbase)
796 """!Create new mapset"""
798 dlg = TextEntryDialog(parent = self,
799 message = _(
'Enter name for new mapset:'),
800 caption = _(
'Create new mapset'),
804 if dlg.ShowModal() == wx.ID_OK:
805 mapset = dlg.GetValue()
812 GMessage(parent = self,
813 message = _(
"Mapset <%s> already exists.") % mapset)
817 self.
gisdbase = self.tgisdbase.GetValue()
819 os.mkdir(os.path.join(self.
gisdbase, location, mapset))
821 shutil.copy(os.path.join(self.
gisdbase, location,
'PERMANENT',
'WIND'),
822 os.path.join(self.
gisdbase, location, mapset))
825 self.lbmapsets.SetSelection(self.listOfMapsets.index(mapset))
826 self.bstart.SetFocus()
828 except StandardError, e:
829 GError(parent = self,
830 message = _(
"Unable to create new mapset: %s") % e,
831 showTraceback =
False)
835 """'Start GRASS' button clicked"""
836 dbase = self.tgisdbase.GetValue()
840 lockfile = os.path.join(dbase, location, mapset,
'.gislock')
841 if os.path.isfile(lockfile):
842 dlg = wx.MessageDialog(parent = self,
843 message = _(
"GRASS is already running in selected mapset <%(mapset)s>\n"
844 "(file %(lock)s found).\n\n"
845 "Concurrent use not allowed.\n\n"
846 "Do you want to try to remove .gislock (note that you "
847 "need permission for this operation) and continue?") %
848 {
'mapset' : mapset,
'lock' : lockfile },
849 caption = _(
"Lock file found"),
850 style = wx.YES_NO | wx.NO_DEFAULT |
851 wx.ICON_QUESTION | wx.CENTRE)
853 ret = dlg.ShowModal()
856 dlg1 = wx.MessageDialog(parent = self,
857 message = _(
"ARE YOU REALLY SURE?\n\n"
858 "If you really are running another GRASS session doing this "
859 "could corrupt your data. Have another look in the processor "
860 "manager just to be sure..."),
861 caption = _(
"Lock file found"),
862 style = wx.YES_NO | wx.NO_DEFAULT |
863 wx.ICON_QUESTION | wx.CENTRE)
865 ret = dlg1.ShowModal()
872 GError(_(
"Unable to remove '%(lock)s'.\n\n"
873 "Details: %(reason)s") % {
'lock' : lockfile,
'reason' : e})
883 set =
"GISDBASE=%s" % dbase)
885 set =
"LOCATION_NAME=%s" % location)
887 set =
"MAPSET=%s" % mapset)
890 def _getDefaultMapsetName(self):
891 """!Returns default name for mapset."""
893 defaultName = getpass.getuser()
894 defaultName.encode(
'ascii')
905 """'Exit' button clicked"""
910 """'Help' button clicked"""
912 filePath = os.path.join(self.
gisbase,
"docs",
"html",
"helptext.html")
914 webbrowser.open(filePath)
917 """!Close window event"""
921 def _nameValidationFailed(self, ctrl):
922 message = _(
"Name <%(name)s> is not a valid name for location or mapset. "
923 "Please use only ASCII characters excluding %(chars)s "
924 "and space.") % {
'name': ctrl.GetValue(),
'chars':
'/"\'@,=*~'}
925 GError(parent=self, message=message, caption=_(
"Invalid name"))
927 class GListBox(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
928 """!Use wx.ListCtrl instead of wx.ListBox, different style for
929 non-selectable items (e.g. mapsets with denied permission)"""
930 def __init__(self, parent, id, size,
931 choices, disabled = []):
932 wx.ListCtrl.__init__(self, parent, id, size = size,
933 style = wx.LC_REPORT | wx.LC_NO_HEADER | wx.LC_SINGLE_SEL |
936 listmix.ListCtrlAutoWidthMixin.__init__(self)
938 self.InsertColumn(0,
'')
944 def _LoadData(self, choices, disabled = []):
945 """!Load data into list
947 @param choices list of item
948 @param disabled list of indeces of non-selectable items
952 index = self.InsertStringItem(sys.maxint, item)
953 self.SetStringItem(index, 0, item)
956 self.SetItemTextColour(idx, wx.Colour(150, 150, 150))
960 self.DeleteAllItems()
966 if item != wx.NOT_FOUND
and \
967 (platform.system() !=
'Windows' or force):
969 self.SetItemState(item, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
977 """!Start-up application"""
981 wx.InitAllImageHandlers()
983 StartUp.CenterOnScreen()
984 self.SetTopWindow(StartUp)
987 if StartUp.GetRCValue(
"LOCATION_NAME") ==
"<UNKNOWN>":
988 wx.MessageBox(parent = StartUp,
989 caption = _(
'Starting GRASS for the first time'),
990 message = _(
'GRASS needs a directory in which to store its data. '
991 'Create one now if you have not already done so. '
992 'A popular choice is "grassdata", located in '
993 'your home directory.'),
994 style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
996 StartUp.OnBrowse(
None)
1000 if __name__ ==
"__main__":
1001 if os.getenv(
"GISBASE")
is None:
1002 sys.exit(
"Failed to start GUI, GRASS GIS is not running.")
1005 gettext.install(
'grasswxpy', os.path.join(os.getenv(
"GISBASE"),
'locale'), unicode =
True)
1008 GRASSStartUp.MainLoop()
def GetListOfLocations
Get list of GRASS locations in given dbase.
def DecodeString
Decode string using system encoding.
def CheckWxVersion
Check wx version.
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.