456 |
dialog.Raise() |
dialog.Raise() |
457 |
|
|
458 |
def AddLayer(self): |
def AddLayer(self): |
459 |
dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*", |
dlg = wxFileDialog(self, _("Select one or more data files"), ".", "", |
460 |
wxOPEN) |
_("Shapefiles (*.shp)") + "|*.shp|" + |
461 |
|
_("All Files (*.*)") + "|*.*", |
462 |
|
wxOPEN | wxMULTIPLE) |
463 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
464 |
filename = dlg.GetPath() |
filenames = dlg.GetPaths() |
465 |
title = os.path.splitext(os.path.basename(filename))[0] |
for filename in filenames: |
466 |
map = self.canvas.Map() |
title = os.path.splitext(os.path.basename(filename))[0] |
467 |
has_layers = map.HasLayers() |
map = self.canvas.Map() |
468 |
try: |
has_layers = map.HasLayers() |
469 |
store = self.application.Session().OpenShapefile(filename) |
try: |
470 |
except IOError: |
store = self.application.Session().OpenShapefile(filename) |
471 |
# the layer couldn't be opened |
except IOError: |
472 |
self.RunMessageBox(_("Add Layer"), |
# the layer couldn't be opened |
473 |
_("Can't open the file '%s'.") % filename) |
self.RunMessageBox(_("Add Layer"), |
474 |
else: |
_("Can't open the file '%s'.")%filename) |
475 |
layer = Layer(title, store) |
else: |
476 |
map.AddLayer(layer) |
layer = Layer(title, store) |
477 |
if not has_layers: |
map.AddLayer(layer) |
478 |
# if we're adding a layer to an empty map, fit the |
if not has_layers: |
479 |
# new map to the window |
# if we're adding a layer to an empty map, fit the |
480 |
self.canvas.FitMapToWindow() |
# new map to the window |
481 |
|
self.canvas.FitMapToWindow() |
482 |
dlg.Destroy() |
dlg.Destroy() |
483 |
|
|
484 |
def AddRasterLayer(self): |
def AddRasterLayer(self): |