2 |
# Authors: |
# Authors: |
3 |
# Jan-Oliver Wagner <[email protected]> |
# Jan-Oliver Wagner <[email protected]> |
4 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
5 |
|
# Frank Koormann <[email protected]> |
6 |
# |
# |
7 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
8 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
40 |
from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION |
from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION |
41 |
|
|
42 |
from Thuban.UI.dock import DockFrame |
from Thuban.UI.dock import DockFrame |
43 |
|
from Thuban.UI.join import JoinDialog |
44 |
|
|
45 |
import resource |
import resource |
46 |
|
|
62 |
# implemented in the __getattr__ method. |
# implemented in the __getattr__ method. |
63 |
delegated_methods = {"SelectLayer": "canvas", |
delegated_methods = {"SelectLayer": "canvas", |
64 |
"SelectShapes": "canvas", |
"SelectShapes": "canvas", |
65 |
|
"SelectedShapes": "canvas", |
66 |
} |
} |
67 |
|
|
68 |
def __init__(self, parent, ID, title, application, interactor, |
def __init__(self, parent, ID, title, application, interactor, |
366 |
|
|
367 |
def OpenSession(self): |
def OpenSession(self): |
368 |
self.save_modified_session() |
self.save_modified_session() |
369 |
dlg = wxFileDialog(self, _("Open Session"), ".", "", "*.thuban", wxOPEN) |
dlg = wxFileDialog(self, _("Open Session"), ".", "", |
370 |
|
"Thuban Session File (*.thuban)|*.thuban", wxOPEN) |
371 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
372 |
self.prepare_new_session() |
self.prepare_new_session() |
373 |
self.application.OpenSession(dlg.GetPath()) |
self.application.OpenSession(dlg.GetPath()) |
381 |
|
|
382 |
def SaveSessionAs(self): |
def SaveSessionAs(self): |
383 |
dlg = wxFileDialog(self, _("Save Session As"), ".", "", |
dlg = wxFileDialog(self, _("Save Session As"), ".", "", |
384 |
"*.thuban", wxOPEN) |
"Thuban Session File (*.thuban)|*.thuban", |
385 |
|
wxSAVE|wxOVERWRITE_PROMPT) |
386 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
387 |
self.application.session.SetFilename(dlg.GetPath()) |
self.application.session.SetFilename(dlg.GetPath()) |
388 |
self.application.SaveSession() |
self.application.SaveSession() |
406 |
def SetMap(self, map): |
def SetMap(self, map): |
407 |
self.canvas.SetMap(map) |
self.canvas.SetMap(map) |
408 |
self.__SetTitle(map.Title()) |
self.__SetTitle(map.Title()) |
409 |
#self.legendPanel.SetMap(map) |
|
410 |
|
dialog = self.FindRegisteredDock("legend") |
411 |
|
if dialog is not None: |
412 |
|
dialog.GetPanel().SetMap(self.Map()) |
413 |
|
|
414 |
def Map(self): |
def Map(self): |
415 |
"""Return the map displayed by this mainwindow""" |
"""Return the map displayed by this mainwindow""" |
416 |
|
|
|
# sanity check |
|
|
#assert(self.canvas.Map() is self.legendPanel.GetMap()) |
|
|
|
|
417 |
return self.canvas.Map() |
return self.canvas.Map() |
418 |
|
|
419 |
def ToggleSessionTree(self): |
def ToggleSessionTree(self): |
449 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
450 |
filename = dlg.GetPath() |
filename = dlg.GetPath() |
451 |
title = os.path.splitext(os.path.basename(filename))[0] |
title = os.path.splitext(os.path.basename(filename))[0] |
452 |
layer = Layer(title, filename) |
store = self.application.Session().OpenShapefile(filename) |
453 |
|
layer = Layer(title, store) |
454 |
map = self.canvas.Map() |
map = self.canvas.Map() |
455 |
has_layers = map.HasLayers() |
has_layers = map.HasLayers() |
456 |
try: |
try: |
505 |
"""Return true if a layer is currently selected""" |
"""Return true if a layer is currently selected""" |
506 |
return self.canvas.HasSelectedLayer() |
return self.canvas.HasSelectedLayer() |
507 |
|
|
508 |
def choose_color(self): |
def has_selected_shapes(self): |
509 |
"""Run the color selection dialog and return the selected color. |
"""Return true if a shape is currently selected""" |
510 |
|
return self.canvas.HasSelectedShapes() |
|
If the user cancels, return None. |
|
|
""" |
|
|
dlg = wxColourDialog(self) |
|
|
color = None |
|
|
if dlg.ShowModal() == wxID_OK: |
|
|
data = dlg.GetColourData() |
|
|
wxc = data.GetColour() |
|
|
color = Color(wxc.Red() / 255.0, |
|
|
wxc.Green() / 255.0, |
|
|
wxc.Blue() / 255.0) |
|
|
dlg.Destroy() |
|
|
return color |
|
511 |
|
|
512 |
def HideLayer(self): |
def HideLayer(self): |
513 |
layer = self.current_layer() |
layer = self.current_layer() |
535 |
# FIXME: bring dialog to front here |
# FIXME: bring dialog to front here |
536 |
pass |
pass |
537 |
|
|
538 |
def Projection(self): |
def MapProjection(self): |
539 |
|
|
540 |
|
name = "map_projection" |
541 |
|
dialog = self.get_open_dialog(name) |
542 |
|
|
543 |
|
if dialog is None: |
544 |
|
map = self.canvas.Map() |
545 |
|
dialog = projdialog.ProjFrame(self, name, |
546 |
|
_("Map Projection: %s") % map.Title(), map) |
547 |
|
self.add_dialog(name, dialog) |
548 |
|
dialog.Show() |
549 |
|
dialog.Raise() |
550 |
|
|
551 |
|
def LayerProjection(self): |
552 |
|
|
553 |
name = "projection" |
layer = self.current_layer() |
554 |
|
|
555 |
|
name = "layer_projection" + str(id(layer)) |
556 |
dialog = self.get_open_dialog(name) |
dialog = self.get_open_dialog(name) |
557 |
|
|
558 |
if dialog is None: |
if dialog is None: |
559 |
map = self.canvas.Map() |
map = self.canvas.Map() |
560 |
dialog = projdialog.ProjFrame(self, name, map) |
dialog = projdialog.ProjFrame(self, name, |
561 |
|
_("Layer Projection: %s") % layer.Title(), layer) |
562 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
563 |
dialog.Show() |
dialog.Show() |
564 |
dialog.Raise() |
dialog.Raise() |
584 |
dialog.Show() |
dialog.Show() |
585 |
dialog.Raise() |
dialog.Raise() |
586 |
|
|
587 |
|
def LayerJoinTable(self): |
588 |
|
print "LayerJoinTable" |
589 |
|
|
590 |
|
def LayerUnjoinTable(self): |
591 |
|
print "LayerUnjoinTable" |
592 |
|
|
593 |
def ShowLegend(self): |
def ShowLegend(self): |
594 |
if not self.LegendShown(): |
if not self.LegendShown(): |
613 |
dialog = self.FindRegisteredDock("legend") |
dialog = self.FindRegisteredDock("legend") |
614 |
return dialog is not None and dialog.IsShown() |
return dialog is not None and dialog.IsShown() |
615 |
|
|
616 |
|
def TableOpen(self): |
617 |
|
print "TableOpen" |
618 |
|
dlg = wxFileDialog(self, _("Open Table"), ".", "", |
619 |
|
"DBF Files (*.dbf)|*.dbf|" + |
620 |
|
"CSV Files (*.csv)|*.csv|" + |
621 |
|
"All Files (*.*)|*.*", |
622 |
|
wxOPEN) |
623 |
|
if dlg.ShowModal() == wxID_OK: |
624 |
|
#self.application.session.OpenTable(dlg.GetPath()) |
625 |
|
pass |
626 |
|
|
627 |
|
dlg.Destroy() |
628 |
|
|
629 |
|
def TableClose(self): |
630 |
|
print "TableClose" |
631 |
|
|
632 |
|
def TableShow(self): |
633 |
|
print "TableShow" |
634 |
|
|
635 |
|
def TableHide(self): |
636 |
|
print "TableHide" |
637 |
|
|
638 |
|
def TableJoin(self): |
639 |
|
print "TableJoin" |
640 |
|
dlg = JoinDialog(self, _("Join Tables"), self.application.session) |
641 |
|
if dlg.ShowModal() == wxID_OK: |
642 |
|
print "OK" |
643 |
|
|
644 |
def ZoomInTool(self): |
def ZoomInTool(self): |
645 |
self.canvas.ZoomInTool() |
self.canvas.ZoomInTool() |
646 |
|
|
660 |
def FullExtent(self): |
def FullExtent(self): |
661 |
self.canvas.FitMapToWindow() |
self.canvas.FitMapToWindow() |
662 |
|
|
663 |
|
def FullLayerExtent(self): |
664 |
|
self.canvas.FitLayerToWindow(self.current_layer()) |
665 |
|
|
666 |
|
def FullSelectionExtent(self): |
667 |
|
self.canvas.FitSelectedToWindow() |
668 |
|
|
669 |
|
def ExportMap(self): |
670 |
|
self.canvas.Export() |
671 |
|
|
672 |
def PrintMap(self): |
def PrintMap(self): |
673 |
self.canvas.Print() |
self.canvas.Print() |
674 |
|
|
684 |
dlg.Destroy() |
dlg.Destroy() |
685 |
|
|
686 |
def identify_view_on_demand(self, layer, shapes): |
def identify_view_on_demand(self, layer, shapes): |
687 |
|
"""Subscribed to the canvas' SHAPES_SELECTED message |
688 |
|
|
689 |
|
If the current tool is the identify tool, at least one shape is |
690 |
|
selected and the identify dialog is not shown, show the dialog. |
691 |
|
""" |
692 |
|
# If the selection has become empty we don't need to do |
693 |
|
# anything. Otherwise it could happen that the dialog was popped |
694 |
|
# up when the selection became empty, e.g. when a new selection |
695 |
|
# is opened while the identify tool is active and dialog had |
696 |
|
# been closed |
697 |
|
if not shapes: |
698 |
|
return |
699 |
|
|
700 |
name = "identify_view" |
name = "identify_view" |
701 |
if self.canvas.CurrentTool() == "IdentifyTool": |
if self.canvas.CurrentTool() == "IdentifyTool": |
702 |
if not self.dialog_open(name): |
if not self.dialog_open(name): |
750 |
"""Return true if a layer is selected in the context""" |
"""Return true if a layer is selected in the context""" |
751 |
return context.mainwindow.has_selected_layer() |
return context.mainwindow.has_selected_layer() |
752 |
|
|
753 |
|
def _has_selected_shapes(context): |
754 |
|
"""Return true if a layer is selected in the context""" |
755 |
|
return context.mainwindow.has_selected_shapes() |
756 |
|
|
757 |
def _can_remove_layer(context): |
def _can_remove_layer(context): |
758 |
return context.mainwindow.CanRemoveLayer() |
return context.mainwindow.CanRemoveLayer() |
759 |
|
|
779 |
|
|
780 |
# File menu |
# File menu |
781 |
_method_command("new_session", _("&New Session"), "NewSession") |
_method_command("new_session", _("&New Session"), "NewSession") |
782 |
_method_command("open_session", _("&Open Session"), "OpenSession") |
_method_command("open_session", _("&Open Session..."), "OpenSession") |
783 |
_method_command("save_session", _("&Save Session"), "SaveSession") |
_method_command("save_session", _("&Save Session"), "SaveSession") |
784 |
_method_command("save_session_as", _("Save Session &As"), "SaveSessionAs") |
_method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs") |
785 |
_method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree", |
_method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree", |
786 |
checked = _has_tree_window_shown) |
checked = _has_tree_window_shown) |
787 |
_method_command("toggle_legend", _("Legend"), "ToggleLegend", |
_method_command("toggle_legend", _("Legend"), "ToggleLegend", |
789 |
_method_command("exit", _("E&xit"), "Exit") |
_method_command("exit", _("E&xit"), "Exit") |
790 |
|
|
791 |
# Help menu |
# Help menu |
792 |
_method_command("help_about", _("&About"), "About") |
_method_command("help_about", _("&About..."), "About") |
793 |
|
|
794 |
|
|
795 |
# Map menu |
# Map menu |
796 |
_method_command("map_projection", _("Pro&jection"), "Projection") |
_method_command("map_projection", _("Pro&jection..."), "MapProjection") |
797 |
|
|
798 |
_tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool", |
_tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool", |
799 |
helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in", |
helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in", |
814 |
_method_command("map_full_extent", _("&Full extent"), "FullExtent", |
_method_command("map_full_extent", _("&Full extent"), "FullExtent", |
815 |
helptext = _("Full Extent"), icon = "fullextent", |
helptext = _("Full Extent"), icon = "fullextent", |
816 |
sensitive = _has_visible_map) |
sensitive = _has_visible_map) |
817 |
|
_method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent", |
818 |
|
helptext = _("Full Layer Extent"), icon = "fulllayerextent", |
819 |
|
sensitive = _has_selected_layer) |
820 |
|
_method_command("selected_full_extent", _("&Full selection extent"), "FullSelectionExtent", |
821 |
|
helptext = _("Full Selection Extent"), icon = "fullselextent", |
822 |
|
sensitive = _has_selected_shapes) |
823 |
|
_method_command("map_export", _("E&xport"), "ExportMap", |
824 |
|
helptext = _("Export the map to file")) |
825 |
_method_command("map_print", _("Prin&t"), "PrintMap", |
_method_command("map_print", _("Prin&t"), "PrintMap", |
826 |
helptext = _("Print the map")) |
helptext = _("Print the map")) |
827 |
_method_command("map_rename", _("&Rename"), "RenameMap", |
_method_command("map_rename", _("&Rename..."), "RenameMap", |
828 |
helptext = _("Rename the map")) |
helptext = _("Rename the map")) |
829 |
|
_method_command("layer_add", _("&Add Layer..."), "AddLayer", |
|
# Layer menu |
|
|
_method_command("layer_add", _("&Add Layer"), "AddLayer", |
|
830 |
helptext = _("Add a new layer to active map")) |
helptext = _("Add a new layer to active map")) |
831 |
_method_command("layer_remove", _("&Remove Layer"), "RemoveLayer", |
_method_command("layer_remove", _("&Remove Layer"), "RemoveLayer", |
832 |
helptext = _("Remove selected layer(s)"), |
helptext = _("Remove selected layer(s)"), |
833 |
sensitive = _can_remove_layer) |
sensitive = _can_remove_layer) |
834 |
|
|
835 |
|
# Layer menu |
836 |
|
_method_command("layer_projection", _("Pro&jection..."), "LayerProjection", |
837 |
|
sensitive = _has_selected_layer) |
838 |
_method_command("layer_raise", _("&Raise"), "RaiseLayer", |
_method_command("layer_raise", _("&Raise"), "RaiseLayer", |
839 |
helptext = _("Raise selected layer(s)"), |
helptext = _("Raise selected layer(s)"), |
840 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
850 |
_method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable", |
_method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable", |
851 |
helptext = _("Show the selected layer's table"), |
helptext = _("Show the selected layer's table"), |
852 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
853 |
_method_command("layer_properties", _("Properties"), "LayerEditProperties", |
_method_command("layer_properties", _("&Properties..."), "LayerEditProperties", |
854 |
|
sensitive = _has_selected_layer) |
855 |
|
_method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable", |
856 |
|
sensitive = _has_selected_layer) |
857 |
|
_method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable", |
858 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
859 |
|
|
860 |
# the menu structure |
# Table menu |
861 |
main_menu = Menu("<main>", "<main>", |
_method_command("table_open", _("&Open..."), "TableOpen") |
862 |
[Menu("file", _("&File"), |
_method_command("table_close", _("&Close"), "TableClose") |
863 |
["new_session", "open_session", None, |
_method_command("table_show", _("&Show"), "TableShow") |
864 |
"save_session", "save_session_as", None, |
_method_command("table_hide", _("&Hide"), "TableHide") |
865 |
"toggle_session_tree", None, |
_method_command("table_join", _("&Join..."), "TableJoin") |
866 |
"exit"]), |
|
867 |
Menu("map", _("&Map"), |
# Export only under Windows ... |
868 |
["layer_add", "layer_remove", |
map_menu = ["layer_add", "layer_remove", "map_rename", |
869 |
None, |
None, |
870 |
"map_projection", |
"map_projection", |
871 |
None, |
None, |
872 |
"map_zoom_in_tool", "map_zoom_out_tool", |
"map_zoom_in_tool", "map_zoom_out_tool", |
873 |
"map_pan_tool", "map_identify_tool", "map_label_tool", |
"map_pan_tool", |
874 |
|
"map_full_extent", |
875 |
|
"layer_full_extent", |
876 |
|
"selected_full_extent", |
877 |
None, |
None, |
878 |
"map_full_extent", |
"map_identify_tool", "map_label_tool", |
879 |
None, |
None, |
880 |
"toggle_legend", |
"toggle_legend", |
881 |
None, |
None] |
882 |
"map_print", |
if wxPlatform == '__WXMSW__': |
883 |
None, |
map_menu.append("map_export") |
884 |
"map_rename"]), |
map_menu.append("map_print") |
885 |
|
|
886 |
|
# the menu structure |
887 |
|
main_menu = Menu("<main>", "<main>", |
888 |
|
[Menu("file", _("&File"), |
889 |
|
["new_session", "open_session", None, |
890 |
|
"save_session", "save_session_as", None, |
891 |
|
"toggle_session_tree", None, |
892 |
|
"exit"]), |
893 |
|
Menu("map", _("&Map"), map_menu), |
894 |
Menu("layer", _("&Layer"), |
Menu("layer", _("&Layer"), |
895 |
["layer_raise", "layer_lower", |
["layer_raise", "layer_lower", |
896 |
None, |
None, |
897 |
"layer_show", "layer_hide", |
"layer_show", "layer_hide", |
898 |
None, |
None, |
899 |
|
"layer_projection", |
900 |
|
None, |
901 |
"layer_show_table", |
"layer_show_table", |
902 |
|
"layer_jointable", |
903 |
|
"layer_unjointable", |
904 |
None, |
None, |
905 |
"layer_properties"]), |
"layer_properties"]), |
906 |
|
Menu("table", _("&Table"), |
907 |
|
["table_open", "table_close", |
908 |
|
None, |
909 |
|
"table_show", "table_hide", |
910 |
|
None, |
911 |
|
"table_join"]), |
912 |
Menu("help", _("&Help"), |
Menu("help", _("&Help"), |
913 |
["help_about"])]) |
["help_about"])]) |
914 |
|
|
916 |
|
|
917 |
main_toolbar = Menu("<toolbar>", "<toolbar>", |
main_toolbar = Menu("<toolbar>", "<toolbar>", |
918 |
["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
919 |
"map_full_extent", None, |
"map_full_extent", |
920 |
|
"layer_full_extent", |
921 |
|
"selected_full_extent", |
922 |
|
None, |
923 |
"map_identify_tool", "map_label_tool"]) |
"map_identify_tool", "map_label_tool"]) |