/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/mainwindow.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/mainwindow.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1070 by bh, Tue May 27 15:09:31 2003 UTC revision 1142 by bh, Tue Jun 10 09:41:57 2003 UTC
# Line 17  __ThubanVersion__ = "0.2" #"$THUBAN_0_2$ Line 17  __ThubanVersion__ = "0.2" #"$THUBAN_0_2$
17  #__BuildDate__ = "$Date$"  #__BuildDate__ = "$Date$"
18    
19  import os  import os
20    import copy
21    
22  from wxPython.wx import *  from wxPython.wx import *
23  from wxPython.wx import __version__ as wxPython_version  from wxPython.wx import __version__ as wxPython_version
# Line 64  class MainWindow(DockFrame): Line 65  class MainWindow(DockFrame):
65      # implemented in the __getattr__ method.      # implemented in the __getattr__ method.
66      delegated_methods = {"SelectLayer": "canvas",      delegated_methods = {"SelectLayer": "canvas",
67                           "SelectShapes": "canvas",                           "SelectShapes": "canvas",
68                             "SelectedLayer": "canvas",
69                           "SelectedShapes": "canvas",                           "SelectedShapes": "canvas",
70                           }                           }
71    
# Line 547  class MainWindow(DockFrame): Line 549  class MainWindow(DockFrame):
549          layer = self.current_layer()          layer = self.current_layer()
550          if layer is not None:          if layer is not None:
551              layer.SetVisible(0)              layer.SetVisible(0)
552            
553      def ShowLayer(self):      def ShowLayer(self):
554          layer = self.current_layer()          layer = self.current_layer()
555          if layer is not None:          if layer is not None:
556              layer.SetVisible(1)              layer.SetVisible(1)
557    
558        def DuplicateLayer(self):
559            """Ceate a new layer above the selected layer with the same shapestore
560            """
561            layer = self.current_layer()
562            if layer is not None and hasattr(layer, "ShapeStore"):
563                new_layer = Layer(_("Copy of `%s'") % layer.Title(),
564                                  layer.ShapeStore(),
565                                  projection = layer.GetProjection())
566                new_classification = copy.deepcopy(layer.GetClassification())
567                new_layer.SetClassification(new_classification)
568                self.Map().AddLayer(new_layer)
569    
570        def CanDuplicateLayer(self):
571            """Return whether the DuplicateLayer method can create a duplicate"""
572            layer = self.current_layer()
573            return layer is not None and hasattr(layer, "ShapeStore")
574    
575      def LayerShowTable(self):      def LayerShowTable(self):
576          layer = self.current_layer()          layer = self.current_layer()
577          if layer is not None:          if layer is not None:
# Line 613  class MainWindow(DockFrame): Line 632  class MainWindow(DockFrame):
632          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
633    
634          if dialog is None:          if dialog is None:
635              dialog = Classifier(self, name, layer, group)              dialog = Classifier(self, name, self.Map(), layer, group)
636              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
637              dialog.Show()              dialog.Show()
638          dialog.Raise()          dialog.Raise()
639    
640      def LayerJoinTable(self):      def LayerJoinTable(self):
641          print "LayerJoinTable: Not implemented."          layer = self.canvas.SelectedLayer()
642            if layer is not None:
643                dlg = JoinDialog(self, _("Join Layer with Table"),
644                                 self.application.session,
645                                 layer = layer)
646                dlg.ShowModal()
647    
648      def LayerUnjoinTable(self):      def LayerUnjoinTable(self):
649          print "LayerUnjoinTable: Not implemented."          layer = self.canvas.SelectedLayer()
650            if layer is not None:
651                orig_store = layer.ShapeStore().OrigShapeStore()
652                if orig_store:
653                    layer.SetShapeStore(orig_store)
654    
655      def ShowLegend(self):      def ShowLegend(self):
656          if not self.LegendShown():          if not self.LegendShown():
# Line 642  class MainWindow(DockFrame): Line 670  class MainWindow(DockFrame):
670          else:          else:
671              dialog.Show(not dialog.IsShown())              dialog.Show(not dialog.IsShown())
672    
673            self.canvas.FitMapToWindow()
674    
675      def LegendShown(self):      def LegendShown(self):
676          """Return true iff the legend is currently open"""          """Return true iff the legend is currently open"""
677          dialog = self.FindRegisteredDock("legend")          dialog = self.FindRegisteredDock("legend")
# Line 668  class MainWindow(DockFrame): Line 698  class MainWindow(DockFrame):
698      def TableClose(self):      def TableClose(self):
699          tables = self.application.session.UnreferencedTables()          tables = self.application.session.UnreferencedTables()
700    
701            lst = [(t.Title(), t) for t in tables]
702            lst.sort()
703            titles = [i[0] for i in lst]
704          dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"),          dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"),
705                                       _("Close Table"),                                       _("Close Table"), titles,
706                                       [t.Title() for t in tables],                                       size = (400, 300),
707                                       size = (400, 300), style=wxRESIZE_BORDER)                                       style = wxDEFAULT_DIALOG_STYLE |
708                                                 wxRESIZE_BORDER)
709          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
710              for i in dlg.GetValue():              for i in dlg.GetValue():
711                  self.application.session.RemoveTable(tables[i])                  self.application.session.RemoveTable(lst[i][1])
712    
713    
714      def TableShow(self):      def TableShow(self):
# Line 685  class MainWindow(DockFrame): Line 719  class MainWindow(DockFrame):
719          """          """
720          tables = self.application.session.Tables()          tables = self.application.session.Tables()
721    
722            lst = [(t.Title(), t) for t in tables]
723            lst.sort()
724            titles = [i[0] for i in lst]
725          dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"),          dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"),
726                                       _("Show Table"),                                       _("Show Table"), titles,
727                                       [t.Title() for t in tables],                                       size = (400,300),
728                                       size = (400,300), style = wxRESIZE_BORDER)                                       style = wxDEFAULT_DIALOG_STYLE |
729                                                 wxRESIZE_BORDER)
730          if (dlg.ShowModal() == wxID_OK):          if (dlg.ShowModal() == wxID_OK):
731              for i in dlg.GetValue():              for i in dlg.GetValue():
732                  # XXX: if the table belongs to a layer, open a                  # XXX: if the table belongs to a layer, open a
733                  # LayerTableFrame instead of QueryTableFrame                  # LayerTableFrame instead of QueryTableFrame
734                  self.ShowTableView(tables[i])                  self.ShowTableView(lst[i][1])
735    
736      def TableJoin(self):      def TableJoin(self):
737          dlg = JoinDialog(self, _("Join Tables"), self.application.session)          dlg = JoinDialog(self, _("Join Tables"), self.application.session)
# Line 711  class MainWindow(DockFrame): Line 749  class MainWindow(DockFrame):
749              dialog.Show(True)              dialog.Show(True)
750          # FIXME: else bring dialog to front          # FIXME: else bring dialog to front
751    
752        def TableRename(self):
753            """Let the user rename a table"""
754    
755            # First, let the user select a table
756            tables = self.application.session.Tables()
757            lst = [(t.Title(), t) for t in tables]
758            lst.sort()
759            titles = [i[0] for i in lst]
760            dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"),
761                                         _("Rename Table"), titles,
762                                         size = (400,300),
763                                         style = wxDEFAULT_DIALOG_STYLE |
764                                                 wxRESIZE_BORDER)
765            if (dlg.ShowModal() == wxID_OK):
766                to_rename = [lst[i][1] for i in dlg.GetValue()]
767                dlg.Destroy()
768            else:
769                to_rename = []
770    
771            # Second, let the user rename the layers
772            for table in to_rename:
773                dlg = wxTextEntryDialog(self, "Table Title: ", "Rename Table",
774                                        table.Title())
775                try:
776                    if dlg.ShowModal() == wxID_OK:
777                        title = dlg.GetValue()
778                        if title != "":
779                            table.SetTitle(title)
780    
781                            # Make sure the session is marked as modified.
782                            # FIXME: This should be handled automatically,
783                            # but that requires more changes to the tables
784                            # than I have time for currently.
785                            self.application.session.changed()
786                finally:
787                    dlg.Destroy()
788    
789    
790      def ZoomInTool(self):      def ZoomInTool(self):
791          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
792    
# Line 753  class MainWindow(DockFrame): Line 829  class MainWindow(DockFrame):
829    
830          dlg.Destroy()          dlg.Destroy()
831    
832        def RenameLayer(self):
833            """Let the user rename the currently selected layer"""
834            layer = self.current_layer()
835            if layer is not None:
836                dlg = wxTextEntryDialog(self, "Layer Title: ", "Rename Layer",
837                                        layer.Title())
838                try:
839                    if dlg.ShowModal() == wxID_OK:
840                        title = dlg.GetValue()
841                        if title != "":
842                            layer.SetTitle(title)
843                finally:
844                    dlg.Destroy()
845    
846      def identify_view_on_demand(self, layer, shapes):      def identify_view_on_demand(self, layer, shapes):
847          """Subscribed to the canvas' SHAPES_SELECTED message          """Subscribed to the canvas' SHAPES_SELECTED message
848    
# Line 848  def _has_legend_shown(context): Line 938  def _has_legend_shown(context):
938    
939    
940  # File menu  # File menu
941  _method_command("new_session", _("&New Session"), "NewSession")  _method_command("new_session", _("&New Session"), "NewSession",
942  _method_command("open_session", _("&Open Session..."), "OpenSession")                  helptext = _("Start a new session"))
943  _method_command("save_session", _("&Save Session"), "SaveSession")  _method_command("open_session", _("&Open Session..."), "OpenSession",
944  _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs")                  helptext = _("Open a session file"))
945    _method_command("save_session", _("&Save Session"), "SaveSession",
946                    helptext =_("Save this session to the file it was opened from"))
947    _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs",
948                    helptext = _("Save this session to a new file"))
949  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
950                  checked = _has_tree_window_shown)                  checked = _has_tree_window_shown,
951                    helptext = _("Toggle on/off the session tree analysis window"))
952  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
953                  checked = _has_legend_shown)                  checked = _has_legend_shown,
954  _method_command("exit", _("E&xit"), "Exit")                  helptext = _("Toggle Legend on/off"))
955    _method_command("exit", _("E&xit"), "Exit",
956                    helptext = _("Finish working with Thuban"))
957    
958  # Help menu  # Help menu
959  _method_command("help_about", _("&About..."), "About")  _method_command("help_about", _("&About..."), "About",
960                    helptext = _("Info about Thuban authors, version and modules"))
961    
962    
963  # Map menu  # Map menu
964  _method_command("map_projection", _("Pro&jection..."), "MapProjection")  _method_command("map_projection", _("Pro&jection..."), "MapProjection",
965                    helptext = _("Set or change the map projection"))
966    
967  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
968                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
# Line 882  _tool_command("map_label_tool", _("&Labe Line 981  _tool_command("map_label_tool", _("&Labe
981                helptext = _("Add/Remove labels"), icon = "label",                helptext = _("Add/Remove labels"), icon = "label",
982                sensitive = _has_visible_map)                sensitive = _has_visible_map)
983  _method_command("map_full_extent", _("&Full extent"), "FullExtent",  _method_command("map_full_extent", _("&Full extent"), "FullExtent",
984                 helptext = _("Full Extent"), icon = "fullextent",                 helptext = _("Zoom to the full map extent"), icon = "fullextent",
985                sensitive = _has_visible_map)                sensitive = _has_visible_map)
986  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",
987                 helptext = _("Full Layer Extent"), icon = "fulllayerextent",                  helptext = _("Zoom to the full layer extent"),
988                sensitive = _has_selected_layer)                  icon = "fulllayerextent", sensitive = _has_selected_layer)
989  _method_command("selected_full_extent", _("&Full selection extent"), "FullSelectionExtent",  _method_command("selected_full_extent", _("&Full selection extent"),
990                 helptext = _("Full Selection Extent"), icon = "fullselextent",                  "FullSelectionExtent",
991                sensitive = _has_selected_shapes)                  helptext = _("Zoom to the full selection extent"),
992                    icon = "fullselextent", sensitive = _has_selected_shapes)
993  _method_command("map_export", _("E&xport"), "ExportMap",  _method_command("map_export", _("E&xport"), "ExportMap",
994                      helptext = _("Export the map to file"))                  helptext = _("Export the map to file"))
995  _method_command("map_print", _("Prin&t"), "PrintMap",  _method_command("map_print", _("Prin&t"), "PrintMap",
996                  helptext = _("Print the map"))                  helptext = _("Print the map"))
997  _method_command("map_rename", _("&Rename..."), "RenameMap",  _method_command("map_rename", _("&Rename..."), "RenameMap",
998                  helptext = _("Rename the map"))                  helptext = _("Rename the map"))
999  _method_command("layer_add", _("&Add Layer..."), "AddLayer",  _method_command("layer_add", _("&Add Layer..."), "AddLayer",
1000                  helptext = _("Add a new layer to active map"))                  helptext = _("Add a new layer to the map"))
1001  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
1002                  helptext = _("Add a new image layer to active map"))                  helptext = _("Add a new image layer to the map"))
1003  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
1004                  helptext = _("Remove selected layer(s)"),                  helptext = _("Remove selected layer"),
1005                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
1006    
1007  # Layer menu  # Layer menu
1008  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
1009                    sensitive = _has_selected_layer,
1010                    helptext = _("Specify projection for selected layer"))
1011    _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
1012                    helptext = _("Duplicate selected layer"),
1013              sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
1014    _method_command("layer_rename", _("Re&name ..."), "RenameLayer",
1015                    helptext = _("Rename selected layer"),
1016                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1017  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
1018                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer"),
1019                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1020  _method_command("layer_lower", _("&Lower"), "LowerLayer",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
1021                  helptext = _("Lower selected layer(s)"),                  helptext = _("Lower selected layer"),
1022                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1023  _method_command("layer_show", _("&Show"), "ShowLayer",  _method_command("layer_show", _("&Show"), "ShowLayer",
1024                  helptext = _("Make selected layer(s) visible"),                  helptext = _("Make selected layer visible"),
1025                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1026  _method_command("layer_hide", _("&Hide"), "HideLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
1027                  helptext = _("Make selected layer(s) unvisible"),                  helptext = _("Make selected layer unvisible"),
1028                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1029  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
1030                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
1031                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1032  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
1033                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1034                    helptext = _("Edit the properties of the selected layer"))
1035  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1036                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1037                    helptext = _("Join and attach a table to the selected layer"))
1038    
1039    def _can_unjoin(context):
1040        """Return whether the Layer/Unjoin command can be executed.
1041    
1042        This is the case if a layer is selected and that layer has a
1043        shapestore that has an original shapestore.
1044        """
1045        layer = context.mainwindow.SelectedLayer()
1046        if layer is None:
1047            return 0
1048        getstore = getattr(layer, "ShapeStore", None)
1049        if getstore is not None:
1050            return getstore().OrigShapeStore() is not None
1051        else:
1052            return 0
1053  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
1054                  sensitive = _has_selected_layer)                  sensitive = _can_unjoin,
1055                    helptext = _("Undo the last join operation"))
1056    
1057    
1058    def _has_tables(context):
1059        return bool(context.session.Tables())
1060    
1061  # Table menu  # Table menu
1062  _method_command("table_open", _("&Open..."), "TableOpen")  _method_command("table_open", _("&Open..."), "TableOpen",
1063  _method_command("table_close", _("&Close"), "TableClose",                  helptext = _("Open a DBF-table from a file"))
1064         sensitive = lambda context: bool(context.session.UnreferencedTables()))  _method_command("table_close", _("&Close..."), "TableClose",
1065  _method_command("table_show", _("&Show"), "TableShow")         sensitive = lambda context: bool(context.session.UnreferencedTables()),
1066  _method_command("table_join", _("&Join..."), "TableJoin")                  helptext = _("Close one or more tables from a list"))
1067    _method_command("table_rename", _("&Rename..."), "TableRename",
1068                    sensitive = _has_tables,
1069                    helptext = _("Rename one or more tables"))
1070    _method_command("table_show", _("&Show..."), "TableShow",
1071                    sensitive = _has_tables,
1072                    helptext = _("Show one or more tables in a dialog"))
1073    _method_command("table_join", _("&Join..."), "TableJoin",
1074                    sensitive = _has_tables,
1075                    helptext = _("Join two tables creating a new one"))
1076    
1077  #  Export only under Windows ...  #  Export only under Windows ...
1078  map_menu = ["layer_add", "rasterlayer_add", "layer_remove", "map_rename",  map_menu = ["layer_add", "rasterlayer_add", "layer_remove", "map_rename",
# Line 964  main_menu = Menu("<main>", "<main>", Line 1102  main_menu = Menu("<main>", "<main>",
1102                          "exit"]),                          "exit"]),
1103                    Menu("map", _("&Map"), map_menu),                    Menu("map", _("&Map"), map_menu),
1104                    Menu("layer", _("&Layer"),                    Menu("layer", _("&Layer"),
1105                          ["layer_raise", "layer_lower",                         ["layer_rename", "layer_duplicate",
1106                            None,
1107                            "layer_raise", "layer_lower",
1108                          None,                          None,
1109                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
1110                          None,                          None,
# Line 976  main_menu = Menu("<main>", "<main>", Line 1116  main_menu = Menu("<main>", "<main>",
1116                          None,                          None,
1117                          "layer_properties"]),                          "layer_properties"]),
1118                    Menu("table", _("&Table"),                    Menu("table", _("&Table"),
1119                         ["table_open", "table_close",                         ["table_open", "table_close", "table_rename",
1120                         None,                         None,
1121                         "table_show",                         "table_show",
1122                         None,                         None,

Legend:
Removed from v.1070  
changed lines
  Added in v.1142

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26