28 |
from Thuban import _ |
from Thuban import _ |
29 |
from Thuban.Model.session import create_empty_session |
from Thuban.Model.session import create_empty_session |
30 |
from Thuban.Model.layer import Layer, RasterLayer |
from Thuban.Model.layer import Layer, RasterLayer |
31 |
from Thuban.Model.postgisdb import PostGISShapeStore |
from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support |
32 |
# XXX: replace this by |
# XXX: replace this by |
33 |
# from wxPython.lib.dialogs import wxMultipleChoiceDialog |
# from wxPython.lib.dialogs import wxMultipleChoiceDialog |
34 |
# when Thuban does not support wxPython 2.4.0 any more. |
# when Thuban does not support wxPython 2.4.0 any more. |
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): |
972 |
"""Return whether the the session has database connections""" |
"""Return whether the the session has database connections""" |
973 |
return context.session.HasDBConnections() |
return context.session.HasDBConnections() |
974 |
|
|
975 |
|
def _has_postgis_support(context): |
976 |
|
return has_postgis_support() |
977 |
|
|
978 |
|
|
979 |
# File menu |
# File menu |
980 |
_method_command("new_session", _("&New Session"), "NewSession", |
_method_command("new_session", _("&New Session"), "NewSession", |
981 |
helptext = _("Start a new session")) |
helptext = _("Start a new session")) |
992 |
checked = _has_legend_shown, |
checked = _has_legend_shown, |
993 |
helptext = _("Toggle Legend on/off")) |
helptext = _("Toggle Legend on/off")) |
994 |
_method_command("database_management", _("&Database Connections..."), |
_method_command("database_management", _("&Database Connections..."), |
995 |
"DatabaseManagement") |
"DatabaseManagement", |
996 |
|
sensitive = _has_postgis_support) |
997 |
_method_command("exit", _("E&xit"), "Exit", |
_method_command("exit", _("E&xit"), "Exit", |
998 |
helptext = _("Finish working with Thuban")) |
helptext = _("Finish working with Thuban")) |
999 |
|
|