1 |
# Copyright (C) 2001, 2002, 2003 by Intevation GmbH |
# Copyright (C) 2001, 2002, 2003, 2004 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Jan-Oliver Wagner <[email protected]> |
# Jan-Oliver Wagner <[email protected]> |
4 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
349 |
""" |
""" |
350 |
self.SetStatusText(text) |
self.SetStatusText(text) |
351 |
|
|
352 |
|
def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw): |
353 |
|
""" |
354 |
|
Open or raise a dialog. |
355 |
|
|
356 |
|
If a dialog with the denoted name does already exist it is |
357 |
|
raised. Otherwise a new dialog, an instance of dialog_class, |
358 |
|
is created, inserted into the main list and displayed. |
359 |
|
""" |
360 |
|
dialog = self.get_open_dialog(name) |
361 |
|
|
362 |
|
if dialog is None: |
363 |
|
dialog = dialog_class(self, name, *args, **kw) |
364 |
|
self.add_dialog(name, dialog) |
365 |
|
dialog.Show(True) |
366 |
|
else: |
367 |
|
dialog.Raise() |
368 |
|
|
369 |
def save_modified_session(self, can_veto = 1): |
def save_modified_session(self, can_veto = 1): |
370 |
"""If the current session has been modified, ask the user |
"""If the current session has been modified, ask the user |
371 |
whether to save it and do so if requested. Return the outcome of |
whether to save it and do so if requested. Return the outcome of |
395 |
|
|
396 |
def OpenSession(self): |
def OpenSession(self): |
397 |
if self.save_modified_session() != wxID_CANCEL: |
if self.save_modified_session() != wxID_CANCEL: |
398 |
dlg = wxFileDialog(self, _("Open Session"), ".", "", |
dlg = wxFileDialog(self, _("Open Session"), |
399 |
|
self.application.Path("data"), "", |
400 |
"Thuban Session File (*.thuban)|*.thuban", |
"Thuban Session File (*.thuban)|*.thuban", |
401 |
wxOPEN) |
wxOPEN) |
402 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
403 |
self.application.OpenSession(dlg.GetPath(), |
self.application.OpenSession(dlg.GetPath(), |
404 |
self.run_db_param_dialog) |
self.run_db_param_dialog) |
405 |
|
self.application.SetPath("data", dlg.GetPath()) |
406 |
dlg.Destroy() |
dlg.Destroy() |
407 |
|
|
408 |
def run_db_param_dialog(self, parameters, message): |
def run_db_param_dialog(self, parameters, message): |
417 |
self.application.SaveSession() |
self.application.SaveSession() |
418 |
|
|
419 |
def SaveSessionAs(self): |
def SaveSessionAs(self): |
420 |
dlg = wxFileDialog(self, _("Save Session As"), ".", "", |
dlg = wxFileDialog(self, _("Save Session As"), |
421 |
|
self.application.Path("data"), "", |
422 |
"Thuban Session File (*.thuban)|*.thuban", |
"Thuban Session File (*.thuban)|*.thuban", |
423 |
wxSAVE|wxOVERWRITE_PROMPT) |
wxSAVE|wxOVERWRITE_PROMPT) |
424 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
425 |
self.application.session.SetFilename(dlg.GetPath()) |
self.application.session.SetFilename(dlg.GetPath()) |
426 |
self.application.SaveSession() |
self.application.SaveSession() |
427 |
|
self.application.SetPath("data",dlg.GetPath()) |
428 |
dlg.Destroy() |
dlg.Destroy() |
429 |
|
|
430 |
def Exit(self): |
def Exit(self): |
489 |
dialog.Raise() |
dialog.Raise() |
490 |
|
|
491 |
def AddLayer(self): |
def AddLayer(self): |
492 |
dlg = wxFileDialog(self, _("Select one or more data files"), ".", "", |
dlg = wxFileDialog(self, _("Select one or more data files"), |
493 |
|
self.application.Path("data"), "", |
494 |
_("Shapefiles (*.shp)") + "|*.shp;*.SHP|" + |
_("Shapefiles (*.shp)") + "|*.shp;*.SHP|" + |
495 |
_("All Files (*.*)") + "|*.*", |
_("All Files (*.*)") + "|*.*", |
496 |
wxOPEN | wxMULTIPLE) |
wxOPEN | wxMULTIPLE) |
513 |
# if we're adding a layer to an empty map, fit the |
# if we're adding a layer to an empty map, fit the |
514 |
# new map to the window |
# new map to the window |
515 |
self.canvas.FitMapToWindow() |
self.canvas.FitMapToWindow() |
516 |
|
self.application.SetPath("data",filename) |
517 |
dlg.Destroy() |
dlg.Destroy() |
518 |
|
|
519 |
def AddRasterLayer(self): |
def AddRasterLayer(self): |
520 |
dlg = wxFileDialog(self, _("Select an image file"), ".", "", "*.*", |
dlg = wxFileDialog(self, _("Select an image file"), |
521 |
|
self.application.Path("data"), "", "*.*", |
522 |
wxOPEN) |
wxOPEN) |
523 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
524 |
filename = dlg.GetPath() |
filename = dlg.GetPath() |
537 |
# if we're adding a layer to an empty map, fit the |
# if we're adding a layer to an empty map, fit the |
538 |
# new map to the window |
# new map to the window |
539 |
self.canvas.FitMapToWindow() |
self.canvas.FitMapToWindow() |
540 |
|
self.application.SetPath("data", filename) |
541 |
dlg.Destroy() |
dlg.Destroy() |
542 |
|
|
543 |
def AddDBLayer(self): |
def AddDBLayer(self): |
546 |
dlg = ChooseDBTableDialog(self, self.application.Session()) |
dlg = ChooseDBTableDialog(self, self.application.Session()) |
547 |
|
|
548 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
549 |
dbconn, dbtable = dlg.GetTable() |
dbconn, dbtable, id_column, geo_column = dlg.GetTable() |
550 |
try: |
try: |
551 |
title = str(dbtable) |
title = str(dbtable) |
552 |
|
|
553 |
# Chose the correct Interface for the database type |
# Chose the correct Interface for the database type |
554 |
store = PostGISShapeStore(dbconn, dbtable) |
store = session.OpenDBShapeStore(dbconn, dbtable, |
555 |
session.AddShapeStore(store) |
id_column = id_column, |
556 |
|
geometry_column = geo_column) |
557 |
layer = Layer(title, store) |
layer = Layer(title, store) |
558 |
except: |
except: |
559 |
# Some error occured while initializing the layer |
# Some error occured while initializing the layer |
560 |
self.RunMessageBox(_("Add Layer from database"), |
self.RunMessageBox(_("Add Layer from database"), |
561 |
_("Can't open the database table '%s'") |
_("Can't open the database table '%s'") |
562 |
% dbtable) |
% dbtable) |
563 |
|
return |
564 |
|
|
565 |
map = self.canvas.Map() |
map = self.canvas.Map() |
566 |
|
|
589 |
return self.canvas.Map().CanRemoveLayer(layer) |
return self.canvas.Map().CanRemoveLayer(layer) |
590 |
return False |
return False |
591 |
|
|
592 |
|
def LayerToTop(self): |
593 |
|
layer = self.current_layer() |
594 |
|
if layer is not None: |
595 |
|
self.canvas.Map().MoveLayerToTop(layer) |
596 |
|
|
597 |
def RaiseLayer(self): |
def RaiseLayer(self): |
598 |
layer = self.current_layer() |
layer = self.current_layer() |
599 |
if layer is not None: |
if layer is not None: |
604 |
if layer is not None: |
if layer is not None: |
605 |
self.canvas.Map().LowerLayer(layer) |
self.canvas.Map().LowerLayer(layer) |
606 |
|
|
607 |
|
def LayerToBottom(self): |
608 |
|
layer = self.current_layer() |
609 |
|
if layer is not None: |
610 |
|
self.canvas.Map().MoveLayerToBottom(layer) |
611 |
|
|
612 |
def current_layer(self): |
def current_layer(self): |
613 |
"""Return the currently selected layer. |
"""Return the currently selected layer. |
614 |
|
|
631 |
def HideLayer(self): |
def HideLayer(self): |
632 |
layer = self.current_layer() |
layer = self.current_layer() |
633 |
if layer is not None: |
if layer is not None: |
634 |
layer.SetVisible(0) |
layer.SetVisible(False) |
635 |
|
|
636 |
def ShowLayer(self): |
def ShowLayer(self): |
637 |
layer = self.current_layer() |
layer = self.current_layer() |
638 |
if layer is not None: |
if layer is not None: |
639 |
layer.SetVisible(1) |
layer.SetVisible(True) |
640 |
|
|
641 |
|
def ToggleLayerVisibility(self): |
642 |
|
layer = self.current_layer() |
643 |
|
layer.SetVisible(not layer.Visible()) |
644 |
|
|
645 |
def DuplicateLayer(self): |
def DuplicateLayer(self): |
646 |
"""Ceate a new layer above the selected layer with the same shapestore |
"""Ceate a new layer above the selected layer with the same shapestore |
660 |
return layer is not None and hasattr(layer, "ShapeStore") |
return layer is not None and hasattr(layer, "ShapeStore") |
661 |
|
|
662 |
def LayerShowTable(self): |
def LayerShowTable(self): |
663 |
|
""" |
664 |
|
Present a TableView Window for the current layer. |
665 |
|
In case the window is already open, bring it to the front. |
666 |
|
In case, there is no active layer, do nothing. |
667 |
|
In case, the layer has no ShapeStore, do nothing. |
668 |
|
""" |
669 |
layer = self.current_layer() |
layer = self.current_layer() |
670 |
if layer is not None: |
if layer is not None: |
671 |
|
if not hasattr(layer, "ShapeStore"): |
672 |
|
return |
673 |
table = layer.ShapeStore().Table() |
table = layer.ShapeStore().Table() |
674 |
name = "table_view" + str(id(table)) |
name = "table_view" + str(id(table)) |
675 |
dialog = self.get_open_dialog(name) |
dialog = self.get_open_dialog(name) |
680 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
681 |
dialog.Show(True) |
dialog.Show(True) |
682 |
else: |
else: |
683 |
# FIXME: bring dialog to front here |
dialog.Raise() |
|
pass |
|
684 |
|
|
685 |
def MapProjection(self): |
def MapProjection(self): |
686 |
|
|
722 |
self.OpenLayerProperties(layer) |
self.OpenLayerProperties(layer) |
723 |
|
|
724 |
def OpenLayerProperties(self, layer, group = None): |
def OpenLayerProperties(self, layer, group = None): |
725 |
name = "layer_properties" + str(id(layer)) |
""" |
726 |
dialog = self.get_open_dialog(name) |
Open or raise the properties dialog. |
|
|
|
|
if dialog is None: |
|
|
dialog = Classifier(self, name, self.Map(), layer, group) |
|
|
self.add_dialog(name, dialog) |
|
|
dialog.Show() |
|
|
dialog.Raise() |
|
727 |
|
|
728 |
|
This method opens or raises the properties dialog for the |
729 |
|
currently selected layer if one is defined for this layer |
730 |
|
type. |
731 |
|
""" |
732 |
|
name = "layer_properties" + str(id(layer)) |
733 |
|
self.OpenOrRaiseDialog(name, Classifier, layer, group = group) |
734 |
|
|
735 |
def LayerJoinTable(self): |
def LayerJoinTable(self): |
736 |
layer = self.canvas.SelectedLayer() |
layer = self.canvas.SelectedLayer() |
737 |
if layer is not None: |
if layer is not None: |
771 |
return dialog is not None and dialog.IsShown() |
return dialog is not None and dialog.IsShown() |
772 |
|
|
773 |
def TableOpen(self): |
def TableOpen(self): |
774 |
dlg = wxFileDialog(self, _("Open Table"), ".", "", |
dlg = wxFileDialog(self, _("Open Table"), |
775 |
|
self.application.Path("data"), "", |
776 |
_("DBF Files (*.dbf)") + "|*.dbf|" + |
_("DBF Files (*.dbf)") + "|*.dbf|" + |
777 |
#_("CSV Files (*.csv)") + "|*.csv|" + |
#_("CSV Files (*.csv)") + "|*.csv|" + |
778 |
_("All Files (*.*)") + "|*.*", |
_("All Files (*.*)") + "|*.*", |
788 |
_("Can't open the file '%s'.") % filename) |
_("Can't open the file '%s'.") % filename) |
789 |
else: |
else: |
790 |
self.ShowTableView(table) |
self.ShowTableView(table) |
791 |
|
self.application.SetPath("data",filename) |
792 |
|
|
793 |
def TableClose(self): |
def TableClose(self): |
794 |
tables = self.application.session.UnreferencedTables() |
tables = self.application.session.UnreferencedTables() |
865 |
|
|
866 |
# Second, let the user rename the layers |
# Second, let the user rename the layers |
867 |
for table in to_rename: |
for table in to_rename: |
868 |
dlg = wxTextEntryDialog(self, "Table Title: ", "Rename Table", |
dlg = wxTextEntryDialog(self, _("Table Title:"), _("Rename Table"), |
869 |
table.Title()) |
table.Title()) |
870 |
try: |
try: |
871 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
914 |
self.canvas.Print() |
self.canvas.Print() |
915 |
|
|
916 |
def RenameMap(self): |
def RenameMap(self): |
917 |
dlg = wxTextEntryDialog(self, "Map Title: ", "Rename Map", |
dlg = wxTextEntryDialog(self, _("Map Title:"), _("Rename Map"), |
918 |
self.Map().Title()) |
self.Map().Title()) |
919 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
920 |
title = dlg.GetValue() |
title = dlg.GetValue() |
927 |
"""Let the user rename the currently selected layer""" |
"""Let the user rename the currently selected layer""" |
928 |
layer = self.current_layer() |
layer = self.current_layer() |
929 |
if layer is not None: |
if layer is not None: |
930 |
dlg = wxTextEntryDialog(self, "Layer Title: ", "Rename Layer", |
dlg = wxTextEntryDialog(self, _("Layer Title:"), _("Rename Layer"), |
931 |
layer.Title()) |
layer.Title()) |
932 |
try: |
try: |
933 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
1026 |
"""Return true if a layer is selected in the context""" |
"""Return true if a layer is selected in the context""" |
1027 |
return context.mainwindow.has_selected_layer() |
return context.mainwindow.has_selected_layer() |
1028 |
|
|
1029 |
|
def _has_selected_layer_visible(context): |
1030 |
|
"""Return true if a layer is selected in the context which is |
1031 |
|
visible.""" |
1032 |
|
if context.mainwindow.has_selected_layer(): |
1033 |
|
layer = context.mainwindow.current_layer() |
1034 |
|
if layer.Visible(): return True |
1035 |
|
return False |
1036 |
|
|
1037 |
def _has_selected_shape_layer(context): |
def _has_selected_shape_layer(context): |
1038 |
"""Return true if a shape layer is selected in the context""" |
"""Return true if a shape layer is selected in the context""" |
1039 |
return context.mainwindow.has_selected_shape_layer() |
return context.mainwindow.has_selected_shape_layer() |
1057 |
if map is not None: |
if map is not None: |
1058 |
for layer in map.Layers(): |
for layer in map.Layers(): |
1059 |
if layer.Visible(): |
if layer.Visible(): |
1060 |
return 1 |
return True |
1061 |
return 0 |
return False |
1062 |
|
|
1063 |
def _has_legend_shown(context): |
def _has_legend_shown(context): |
1064 |
"""Return true if the legend window is shown""" |
"""Return true if the legend window is shown""" |
1182 |
sensitive = _has_selected_shape_layer, |
sensitive = _has_selected_shape_layer, |
1183 |
helptext = _("Join and attach a table to the selected layer")) |
helptext = _("Join and attach a table to the selected layer")) |
1184 |
|
|
1185 |
|
# further layer methods: |
1186 |
|
_method_command("layer_to_top", _("&Top"), "LayerToTop", |
1187 |
|
helptext = _("Put selected layer to the top"), |
1188 |
|
sensitive = _has_selected_layer) |
1189 |
|
_method_command("layer_to_bottom", _("&Bottom"), "LayerToBottom", |
1190 |
|
helptext = _("Put selected layer to the bottom"), |
1191 |
|
sensitive = _has_selected_layer) |
1192 |
|
_method_command("layer_visibility", _("&Visible"), "ToggleLayerVisibility", |
1193 |
|
checked = _has_selected_layer_visible, |
1194 |
|
helptext = _("Toggle visibility of selected layer"), |
1195 |
|
sensitive = _has_selected_layer) |
1196 |
|
|
1197 |
def _can_unjoin(context): |
def _can_unjoin(context): |
1198 |
"""Return whether the Layer/Unjoin command can be executed. |
"""Return whether the Layer/Unjoin command can be executed. |
1199 |
|
|