/[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 1080 by bh, Wed May 28 09:12:21 2003 UTC revision 1219 by bh, Mon Jun 16 17:42:54 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
24    
 from wxPython.lib.dialogs import wxMultipleChoiceDialog  
   
25  import Thuban  import Thuban
26  import Thuban.version  import Thuban.version
27    
# Line 30  from Thuban import _ Line 29  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    
32    # XXX: replace this by
33    # from wxPython.lib.dialogs import wxMultipleChoiceDialog
34    # when Thuban does not support wxPython 2.4.0 any more.
35    from Thuban.UI.multiplechoicedialog import wxMultipleChoiceDialog
36    
37  import view  import view
38  import tree  import tree
39  import tableview, identifyview  import tableview, identifyview
# Line 45  from Thuban.UI.dock import DockFrame Line 49  from Thuban.UI.dock import DockFrame
49  from Thuban.UI.join import JoinDialog  from Thuban.UI.join import JoinDialog
50    
51  import resource  import resource
52    import Thuban.Model.resource
53    
54  import projdialog  import projdialog
55    
   
   
56  class MainWindow(DockFrame):  class MainWindow(DockFrame):
57    
58      # Some messages that can be subscribed/unsubscribed directly through      # Some messages that can be subscribed/unsubscribed directly through
# Line 548  class MainWindow(DockFrame): Line 551  class MainWindow(DockFrame):
551          layer = self.current_layer()          layer = self.current_layer()
552          if layer is not None:          if layer is not None:
553              layer.SetVisible(0)              layer.SetVisible(0)
554            
555      def ShowLayer(self):      def ShowLayer(self):
556          layer = self.current_layer()          layer = self.current_layer()
557          if layer is not None:          if layer is not None:
558              layer.SetVisible(1)              layer.SetVisible(1)
559    
560        def DuplicateLayer(self):
561            """Ceate a new layer above the selected layer with the same shapestore
562            """
563            layer = self.current_layer()
564            if layer is not None and hasattr(layer, "ShapeStore"):
565                new_layer = Layer(_("Copy of `%s'") % layer.Title(),
566                                  layer.ShapeStore(),
567                                  projection = layer.GetProjection())
568                new_classification = copy.deepcopy(layer.GetClassification())
569                new_layer.SetClassification(new_classification)
570                self.Map().AddLayer(new_layer)
571    
572        def CanDuplicateLayer(self):
573            """Return whether the DuplicateLayer method can create a duplicate"""
574            layer = self.current_layer()
575            return layer is not None and hasattr(layer, "ShapeStore")
576    
577      def LayerShowTable(self):      def LayerShowTable(self):
578          layer = self.current_layer()          layer = self.current_layer()
579          if layer is not None:          if layer is not None:
580              table = layer.table              table = layer.ShapeStore().Table()
581              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
582              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
583              if dialog is None:              if dialog is None:
# Line 614  class MainWindow(DockFrame): Line 634  class MainWindow(DockFrame):
634          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
635    
636          if dialog is None:          if dialog is None:
637              dialog = Classifier(self, name, layer, group)              dialog = Classifier(self, name, self.Map(), layer, group)
638              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
639              dialog.Show()              dialog.Show()
640          dialog.Raise()          dialog.Raise()
# Line 652  class MainWindow(DockFrame): Line 672  class MainWindow(DockFrame):
672          else:          else:
673              dialog.Show(not dialog.IsShown())              dialog.Show(not dialog.IsShown())
674    
675            self.canvas.FitMapToWindow()
676    
677      def LegendShown(self):      def LegendShown(self):
678          """Return true iff the legend is currently open"""          """Return true iff the legend is currently open"""
679          dialog = self.FindRegisteredDock("legend")          dialog = self.FindRegisteredDock("legend")
# Line 678  class MainWindow(DockFrame): Line 700  class MainWindow(DockFrame):
700      def TableClose(self):      def TableClose(self):
701          tables = self.application.session.UnreferencedTables()          tables = self.application.session.UnreferencedTables()
702    
703            lst = [(t.Title(), t) for t in tables]
704            lst.sort()
705            titles = [i[0] for i in lst]
706          dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"),          dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"),
707                                       _("Close Table"),                                       _("Close Table"), titles,
708                                       [t.Title() for t in tables],                                       size = (400, 300),
709                                       size = (400, 300), style=wxRESIZE_BORDER)                                       style = wxDEFAULT_DIALOG_STYLE |
710                                                 wxRESIZE_BORDER)
711          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
712              for i in dlg.GetValue():              for i in dlg.GetValue():
713                  self.application.session.RemoveTable(tables[i])                  self.application.session.RemoveTable(lst[i][1])
714    
715    
716      def TableShow(self):      def TableShow(self):
# Line 695  class MainWindow(DockFrame): Line 721  class MainWindow(DockFrame):
721          """          """
722          tables = self.application.session.Tables()          tables = self.application.session.Tables()
723    
724            lst = [(t.Title(), t) for t in tables]
725            lst.sort()
726            titles = [i[0] for i in lst]
727          dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"),          dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"),
728                                       _("Show Table"),                                       _("Show Table"), titles,
                                      [t.Title() for t in tables],  
729                                       size = (400,300),                                       size = (400,300),
730                                       style = wxDEFAULT_DIALOG_STYLE |                                       style = wxDEFAULT_DIALOG_STYLE |
731                                               wxRESIZE_BORDER)                                               wxRESIZE_BORDER)
# Line 705  class MainWindow(DockFrame): Line 733  class MainWindow(DockFrame):
733              for i in dlg.GetValue():              for i in dlg.GetValue():
734                  # XXX: if the table belongs to a layer, open a                  # XXX: if the table belongs to a layer, open a
735                  # LayerTableFrame instead of QueryTableFrame                  # LayerTableFrame instead of QueryTableFrame
736                  self.ShowTableView(tables[i])                  self.ShowTableView(lst[i][1])
737    
738      def TableJoin(self):      def TableJoin(self):
739          dlg = JoinDialog(self, _("Join Tables"), self.application.session)          dlg = JoinDialog(self, _("Join Tables"), self.application.session)
# Line 723  class MainWindow(DockFrame): Line 751  class MainWindow(DockFrame):
751              dialog.Show(True)              dialog.Show(True)
752          # FIXME: else bring dialog to front          # FIXME: else bring dialog to front
753    
754        def TableRename(self):
755            """Let the user rename a table"""
756    
757            # First, let the user select a table
758            tables = self.application.session.Tables()
759            lst = [(t.Title(), t) for t in tables]
760            lst.sort()
761            titles = [i[0] for i in lst]
762            dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"),
763                                         _("Rename Table"), titles,
764                                         size = (400,300),
765                                         style = wxDEFAULT_DIALOG_STYLE |
766                                                 wxRESIZE_BORDER)
767            if (dlg.ShowModal() == wxID_OK):
768                to_rename = [lst[i][1] for i in dlg.GetValue()]
769                dlg.Destroy()
770            else:
771                to_rename = []
772    
773            # Second, let the user rename the layers
774            for table in to_rename:
775                dlg = wxTextEntryDialog(self, "Table Title: ", "Rename Table",
776                                        table.Title())
777                try:
778                    if dlg.ShowModal() == wxID_OK:
779                        title = dlg.GetValue()
780                        if title != "":
781                            table.SetTitle(title)
782    
783                            # Make sure the session is marked as modified.
784                            # FIXME: This should be handled automatically,
785                            # but that requires more changes to the tables
786                            # than I have time for currently.
787                            self.application.session.changed()
788                finally:
789                    dlg.Destroy()
790    
791    
792      def ZoomInTool(self):      def ZoomInTool(self):
793          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
794    
# Line 765  class MainWindow(DockFrame): Line 831  class MainWindow(DockFrame):
831    
832          dlg.Destroy()          dlg.Destroy()
833    
834        def RenameLayer(self):
835            """Let the user rename the currently selected layer"""
836            layer = self.current_layer()
837            if layer is not None:
838                dlg = wxTextEntryDialog(self, "Layer Title: ", "Rename Layer",
839                                        layer.Title())
840                try:
841                    if dlg.ShowModal() == wxID_OK:
842                        title = dlg.GetValue()
843                        if title != "":
844                            layer.SetTitle(title)
845                finally:
846                    dlg.Destroy()
847    
848      def identify_view_on_demand(self, layer, shapes):      def identify_view_on_demand(self, layer, shapes):
849          """Subscribed to the canvas' SHAPES_SELECTED message          """Subscribed to the canvas' SHAPES_SELECTED message
850    
# Line 858  def _has_legend_shown(context): Line 938  def _has_legend_shown(context):
938      """Return true if the legend window is shown"""      """Return true if the legend window is shown"""
939      return context.mainwindow.LegendShown()      return context.mainwindow.LegendShown()
940    
941    def _has_gdal_support(context):
942        """Return True if the GDAL is available"""
943        return Thuban.Model.resource.has_gdal_support()
944    
945  # File menu  # File menu
946  _method_command("new_session", _("&New Session"), "NewSession")  _method_command("new_session", _("&New Session"), "NewSession",
947  _method_command("open_session", _("&Open Session..."), "OpenSession")                  helptext = _("Start a new session"))
948  _method_command("save_session", _("&Save Session"), "SaveSession")  _method_command("open_session", _("&Open Session..."), "OpenSession",
949  _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs")                  helptext = _("Open a session file"))
950    _method_command("save_session", _("&Save Session"), "SaveSession",
951                    helptext =_("Save this session to the file it was opened from"))
952    _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs",
953                    helptext = _("Save this session to a new file"))
954  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
955                  checked = _has_tree_window_shown)                  checked = _has_tree_window_shown,
956                    helptext = _("Toggle on/off the session tree analysis window"))
957  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
958                  checked = _has_legend_shown)                  checked = _has_legend_shown,
959  _method_command("exit", _("E&xit"), "Exit")                  helptext = _("Toggle Legend on/off"))
960    _method_command("exit", _("E&xit"), "Exit",
961                    helptext = _("Finish working with Thuban"))
962    
963  # Help menu  # Help menu
964  _method_command("help_about", _("&About..."), "About")  _method_command("help_about", _("&About..."), "About",
965                    helptext = _("Info about Thuban authors, version and modules"))
966    
967    
968  # Map menu  # Map menu
969  _method_command("map_projection", _("Pro&jection..."), "MapProjection")  _method_command("map_projection", _("Pro&jection..."), "MapProjection",
970                    helptext = _("Set or change the map projection"))
971    
972  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
973                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
# Line 894  _tool_command("map_label_tool", _("&Labe Line 986  _tool_command("map_label_tool", _("&Labe
986                helptext = _("Add/Remove labels"), icon = "label",                helptext = _("Add/Remove labels"), icon = "label",
987                sensitive = _has_visible_map)                sensitive = _has_visible_map)
988  _method_command("map_full_extent", _("&Full extent"), "FullExtent",  _method_command("map_full_extent", _("&Full extent"), "FullExtent",
989                 helptext = _("Full Extent"), icon = "fullextent",                 helptext = _("Zoom to the full map extent"), icon = "fullextent",
990                sensitive = _has_visible_map)                sensitive = _has_visible_map)
991  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",
992                 helptext = _("Full Layer Extent"), icon = "fulllayerextent",                  helptext = _("Zoom to the full layer extent"),
993                sensitive = _has_selected_layer)                  icon = "fulllayerextent", sensitive = _has_selected_layer)
994  _method_command("selected_full_extent", _("&Full selection extent"), "FullSelectionExtent",  _method_command("selected_full_extent", _("&Full selection extent"),
995                 helptext = _("Full Selection Extent"), icon = "fullselextent",                  "FullSelectionExtent",
996                sensitive = _has_selected_shapes)                  helptext = _("Zoom to the full selection extent"),
997                    icon = "fullselextent", sensitive = _has_selected_shapes)
998  _method_command("map_export", _("E&xport"), "ExportMap",  _method_command("map_export", _("E&xport"), "ExportMap",
999                      helptext = _("Export the map to file"))                  helptext = _("Export the map to file"))
1000  _method_command("map_print", _("Prin&t"), "PrintMap",  _method_command("map_print", _("Prin&t"), "PrintMap",
1001                  helptext = _("Print the map"))                  helptext = _("Print the map"))
1002  _method_command("map_rename", _("&Rename..."), "RenameMap",  _method_command("map_rename", _("&Rename..."), "RenameMap",
1003                  helptext = _("Rename the map"))                  helptext = _("Rename the map"))
1004  _method_command("layer_add", _("&Add Layer..."), "AddLayer",  _method_command("layer_add", _("&Add Layer..."), "AddLayer",
1005                  helptext = _("Add a new layer to active map"))                  helptext = _("Add a new layer to the map"))
1006  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
1007                  helptext = _("Add a new image layer to active map"))                  helptext = _("Add a new image layer to the map"),
1008                    sensitive = _has_gdal_support)
1009  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
1010                  helptext = _("Remove selected layer(s)"),                  helptext = _("Remove selected layer"),
1011                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
1012    
1013  # Layer menu  # Layer menu
1014  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
1015                    sensitive = _has_selected_layer,
1016                    helptext = _("Specify projection for selected layer"))
1017    _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
1018                    helptext = _("Duplicate selected layer"),
1019              sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
1020    _method_command("layer_rename", _("Re&name ..."), "RenameLayer",
1021                    helptext = _("Rename selected layer"),
1022                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1023  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
1024                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer"),
1025                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1026  _method_command("layer_lower", _("&Lower"), "LowerLayer",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
1027                  helptext = _("Lower selected layer(s)"),                  helptext = _("Lower selected layer"),
1028                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1029  _method_command("layer_show", _("&Show"), "ShowLayer",  _method_command("layer_show", _("&Show"), "ShowLayer",
1030                  helptext = _("Make selected layer(s) visible"),                  helptext = _("Make selected layer visible"),
1031                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1032  _method_command("layer_hide", _("&Hide"), "HideLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
1033                  helptext = _("Make selected layer(s) unvisible"),                  helptext = _("Make selected layer unvisible"),
1034                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1035  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
1036                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
1037                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1038  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
1039                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1040                    helptext = _("Edit the properties of the selected layer"))
1041  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1042                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1043                    helptext = _("Join and attach a table to the selected layer"))
1044    
1045  def _can_unjoin(context):  def _can_unjoin(context):
1046      """Return whether the Layer/Unjoin command can be executed.      """Return whether the Layer/Unjoin command can be executed.
# Line 954  def _can_unjoin(context): Line 1057  def _can_unjoin(context):
1057      else:      else:
1058          return 0          return 0
1059  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
1060                  sensitive = _can_unjoin)                  sensitive = _can_unjoin,
1061                    helptext = _("Undo the last join operation"))
1062    
1063    
1064    def _has_tables(context):
1065        return bool(context.session.Tables())
1066    
1067  # Table menu  # Table menu
1068  _method_command("table_open", _("&Open..."), "TableOpen")  _method_command("table_open", _("&Open..."), "TableOpen",
1069  _method_command("table_close", _("&Close"), "TableClose",                  helptext = _("Open a DBF-table from a file"))
1070         sensitive = lambda context: bool(context.session.UnreferencedTables()))  _method_command("table_close", _("&Close..."), "TableClose",
1071  _method_command("table_show", _("&Show"), "TableShow")         sensitive = lambda context: bool(context.session.UnreferencedTables()),
1072  _method_command("table_join", _("&Join..."), "TableJoin")                  helptext = _("Close one or more tables from a list"))
1073    _method_command("table_rename", _("&Rename..."), "TableRename",
1074                    sensitive = _has_tables,
1075                    helptext = _("Rename one or more tables"))
1076    _method_command("table_show", _("&Show..."), "TableShow",
1077                    sensitive = _has_tables,
1078                    helptext = _("Show one or more tables in a dialog"))
1079    _method_command("table_join", _("&Join..."), "TableJoin",
1080                    sensitive = _has_tables,
1081                    helptext = _("Join two tables creating a new one"))
1082    
1083  #  Export only under Windows ...  #  Export only under Windows ...
1084  map_menu = ["layer_add", "rasterlayer_add", "layer_remove", "map_rename",  map_menu = ["layer_add", "rasterlayer_add", "layer_remove",
1085                          None,                          None,
1086                            "map_rename",
1087                          "map_projection",                          "map_projection",
1088                          None,                          None,
1089                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
# Line 991  main_menu = Menu("<main>", "<main>", Line 1109  main_menu = Menu("<main>", "<main>",
1109                          "exit"]),                          "exit"]),
1110                    Menu("map", _("&Map"), map_menu),                    Menu("map", _("&Map"), map_menu),
1111                    Menu("layer", _("&Layer"),                    Menu("layer", _("&Layer"),
1112                          ["layer_raise", "layer_lower",                         ["layer_rename", "layer_duplicate",
1113                            None,
1114                            "layer_raise", "layer_lower",
1115                          None,                          None,
1116                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
1117                          None,                          None,
# Line 1003  main_menu = Menu("<main>", "<main>", Line 1123  main_menu = Menu("<main>", "<main>",
1123                          None,                          None,
1124                          "layer_properties"]),                          "layer_properties"]),
1125                    Menu("table", _("&Table"),                    Menu("table", _("&Table"),
1126                         ["table_open", "table_close",                         ["table_open", "table_close", "table_rename",
1127                         None,                         None,
1128                         "table_show",                         "table_show",
1129                         None,                         None,

Legend:
Removed from v.1080  
changed lines
  Added in v.1219

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26