/[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 1084 by jan, Wed May 28 10:25:09 2003 UTC revision 1309 by jonathan, Thu Jun 26 17:00:44 2003 UTC
# Line 13  The main window Line 13  The main window
13    
14  __version__ = "$Revision$"  __version__ = "$Revision$"
15    
16  __ThubanVersion__ = "0.2" #"$THUBAN_0_2$"  __ThubanVersion__ = "0.8" #"$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 40  from menu import Menu Line 44  from menu import Menu
44  from context import Context  from context import Context
45  from command import registry, Command, ToolCommand  from command import registry, Command, ToolCommand
46  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION
47    from about import About
48    
49  from Thuban.UI.dock import DockFrame  from Thuban.UI.dock import DockFrame
50  from Thuban.UI.join import JoinDialog  from Thuban.UI.join import JoinDialog
51    
52  import resource  import resource
53    import Thuban.Model.resource
54    
55  import projdialog  import projdialog
56    
57    
   
58  class MainWindow(DockFrame):  class MainWindow(DockFrame):
59    
60      # Some messages that can be subscribed/unsubscribed directly through      # Some messages that can be subscribed/unsubscribed directly through
# Line 104  class MainWindow(DockFrame): Line 109  class MainWindow(DockFrame):
109    
110          self.init_dialogs()          self.init_dialogs()
111    
112            self.ShowLegend()
113    
114          EVT_CLOSE(self, self.OnClose)          EVT_CLOSE(self, self.OnClose)
115    
116      def Subscribe(self, channel, *args):      def Subscribe(self, channel, *args):
# Line 439  class MainWindow(DockFrame): Line 446  class MainWindow(DockFrame):
446          return self.get_open_dialog("session_tree") is not None          return self.get_open_dialog("session_tree") is not None
447    
448      def About(self):      def About(self):
449          self.RunMessageBox(_("About"),          dlg = About(self)
450                             _("Thuban %s\n"          dlg.ShowModal()
451                              #"Build Date: %s\n"          dlg.Destroy()
                             "using:\n"  
                             "  %s\n"  
                             "  %s\n\n"  
                             "Thuban is a program for\n"  
                             "exploring geographic data.\n"  
                             "Copyright (C) 2001-2003 Intevation GmbH.\n"  
                             "Thuban is licensed under the GNU GPL"  
                             % (Thuban.version.longversion,  
                                "wxPython %s" % wxPython_version,  
                                "Python %d.%d.%d" % sys.version_info[:3]  
                               )),  
 #                           % __ThubanVersion__), #__BuildDate__)),  
                            wxOK | wxICON_INFORMATION)  
452    
453      def AddLayer(self):      def AddLayer(self):
454          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",
# Line 548  class MainWindow(DockFrame): Line 542  class MainWindow(DockFrame):
542          layer = self.current_layer()          layer = self.current_layer()
543          if layer is not None:          if layer is not None:
544              layer.SetVisible(0)              layer.SetVisible(0)
545            
546      def ShowLayer(self):      def ShowLayer(self):
547          layer = self.current_layer()          layer = self.current_layer()
548          if layer is not None:          if layer is not None:
549              layer.SetVisible(1)              layer.SetVisible(1)
550    
551        def DuplicateLayer(self):
552            """Ceate a new layer above the selected layer with the same shapestore
553            """
554            layer = self.current_layer()
555            if layer is not None and hasattr(layer, "ShapeStore"):
556                new_layer = Layer(_("Copy of `%s'") % layer.Title(),
557                                  layer.ShapeStore(),
558                                  projection = layer.GetProjection())
559                new_classification = copy.deepcopy(layer.GetClassification())
560                new_layer.SetClassification(new_classification)
561                self.Map().AddLayer(new_layer)
562    
563        def CanDuplicateLayer(self):
564            """Return whether the DuplicateLayer method can create a duplicate"""
565            layer = self.current_layer()
566            return layer is not None and hasattr(layer, "ShapeStore")
567    
568      def LayerShowTable(self):      def LayerShowTable(self):
569          layer = self.current_layer()          layer = self.current_layer()
570          if layer is not None:          if layer is not None:
571              table = layer.table              table = layer.ShapeStore().Table()
572              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
573              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
574              if dialog is None:              if dialog is None:
# Line 614  class MainWindow(DockFrame): Line 625  class MainWindow(DockFrame):
625          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
626    
627          if dialog is None:          if dialog is None:
628              dialog = Classifier(self, name, layer, group)              dialog = Classifier(self, name, self.Map(), layer, group)
629              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
630              dialog.Show()              dialog.Show()
631          dialog.Raise()          dialog.Raise()
# Line 652  class MainWindow(DockFrame): Line 663  class MainWindow(DockFrame):
663          else:          else:
664              dialog.Show(not dialog.IsShown())              dialog.Show(not dialog.IsShown())
665    
666            self.canvas.FitMapToWindow()
667    
668      def LegendShown(self):      def LegendShown(self):
669          """Return true iff the legend is currently open"""          """Return true iff the legend is currently open"""
670          dialog = self.FindRegisteredDock("legend")          dialog = self.FindRegisteredDock("legend")
# Line 729  class MainWindow(DockFrame): Line 742  class MainWindow(DockFrame):
742              dialog.Show(True)              dialog.Show(True)
743          # FIXME: else bring dialog to front          # FIXME: else bring dialog to front
744    
745        def TableRename(self):
746            """Let the user rename a table"""
747    
748            # First, let the user select a table
749            tables = self.application.session.Tables()
750            lst = [(t.Title(), t) for t in tables]
751            lst.sort()
752            titles = [i[0] for i in lst]
753            dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"),
754                                         _("Rename Table"), titles,
755                                         size = (400,300),
756                                         style = wxDEFAULT_DIALOG_STYLE |
757                                                 wxRESIZE_BORDER)
758            if (dlg.ShowModal() == wxID_OK):
759                to_rename = [lst[i][1] for i in dlg.GetValue()]
760                dlg.Destroy()
761            else:
762                to_rename = []
763    
764            # Second, let the user rename the layers
765            for table in to_rename:
766                dlg = wxTextEntryDialog(self, "Table Title: ", "Rename Table",
767                                        table.Title())
768                try:
769                    if dlg.ShowModal() == wxID_OK:
770                        title = dlg.GetValue()
771                        if title != "":
772                            table.SetTitle(title)
773    
774                            # Make sure the session is marked as modified.
775                            # FIXME: This should be handled automatically,
776                            # but that requires more changes to the tables
777                            # than I have time for currently.
778                            self.application.session.changed()
779                finally:
780                    dlg.Destroy()
781    
782    
783      def ZoomInTool(self):      def ZoomInTool(self):
784          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
785    
# Line 771  class MainWindow(DockFrame): Line 822  class MainWindow(DockFrame):
822    
823          dlg.Destroy()          dlg.Destroy()
824    
825        def RenameLayer(self):
826            """Let the user rename the currently selected layer"""
827            layer = self.current_layer()
828            if layer is not None:
829                dlg = wxTextEntryDialog(self, "Layer Title: ", "Rename Layer",
830                                        layer.Title())
831                try:
832                    if dlg.ShowModal() == wxID_OK:
833                        title = dlg.GetValue()
834                        if title != "":
835                            layer.SetTitle(title)
836                finally:
837                    dlg.Destroy()
838    
839      def identify_view_on_demand(self, layer, shapes):      def identify_view_on_demand(self, layer, shapes):
840          """Subscribed to the canvas' SHAPES_SELECTED message          """Subscribed to the canvas' SHAPES_SELECTED message
841    
# Line 864  def _has_legend_shown(context): Line 929  def _has_legend_shown(context):
929      """Return true if the legend window is shown"""      """Return true if the legend window is shown"""
930      return context.mainwindow.LegendShown()      return context.mainwindow.LegendShown()
931    
932    def _has_gdal_support(context):
933        """Return True if the GDAL is available"""
934        return Thuban.Model.resource.has_gdal_support()
935    
936  # File menu  # File menu
937  _method_command("new_session", _("&New Session"), "NewSession")  _method_command("new_session", _("&New Session"), "NewSession",
938  _method_command("open_session", _("&Open Session..."), "OpenSession")                  helptext = _("Start a new session"))
939  _method_command("save_session", _("&Save Session"), "SaveSession")  _method_command("open_session", _("&Open Session..."), "OpenSession",
940  _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs")                  helptext = _("Open a session file"))
941    _method_command("save_session", _("&Save Session"), "SaveSession",
942                    helptext =_("Save this session to the file it was opened from"))
943    _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs",
944                    helptext = _("Save this session to a new file"))
945  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
946                  checked = _has_tree_window_shown)                  checked = _has_tree_window_shown,
947                    helptext = _("Toggle on/off the session tree analysis window"))
948  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
949                  checked = _has_legend_shown)                  checked = _has_legend_shown,
950  _method_command("exit", _("E&xit"), "Exit")                  helptext = _("Toggle Legend on/off"))
951    _method_command("exit", _("E&xit"), "Exit",
952                    helptext = _("Finish working with Thuban"))
953    
954  # Help menu  # Help menu
955  _method_command("help_about", _("&About..."), "About")  _method_command("help_about", _("&About..."), "About",
956                    helptext = _("Info about Thuban authors, version and modules"))
957    
958    
959  # Map menu  # Map menu
960  _method_command("map_projection", _("Pro&jection..."), "MapProjection")  _method_command("map_projection", _("Pro&jection..."), "MapProjection",
961                    helptext = _("Set or change the map projection"))
962    
963  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
964                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
# Line 900  _tool_command("map_label_tool", _("&Labe Line 977  _tool_command("map_label_tool", _("&Labe
977                helptext = _("Add/Remove labels"), icon = "label",                helptext = _("Add/Remove labels"), icon = "label",
978                sensitive = _has_visible_map)                sensitive = _has_visible_map)
979  _method_command("map_full_extent", _("&Full extent"), "FullExtent",  _method_command("map_full_extent", _("&Full extent"), "FullExtent",
980                 helptext = _("Full Extent"), icon = "fullextent",                 helptext = _("Zoom to the full map extent"), icon = "fullextent",
981                sensitive = _has_visible_map)                sensitive = _has_visible_map)
982  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",
983                 helptext = _("Full Layer Extent"), icon = "fulllayerextent",                  helptext = _("Zoom to the full layer extent"),
984                sensitive = _has_selected_layer)                  icon = "fulllayerextent", sensitive = _has_selected_layer)
985  _method_command("selected_full_extent", _("&Full selection extent"), "FullSelectionExtent",  _method_command("selected_full_extent", _("&Full selection extent"),
986                 helptext = _("Full Selection Extent"), icon = "fullselextent",                  "FullSelectionExtent",
987                sensitive = _has_selected_shapes)                  helptext = _("Zoom to the full selection extent"),
988                    icon = "fullselextent", sensitive = _has_selected_shapes)
989  _method_command("map_export", _("E&xport"), "ExportMap",  _method_command("map_export", _("E&xport"), "ExportMap",
990                      helptext = _("Export the map to file"))                  helptext = _("Export the map to file"))
991  _method_command("map_print", _("Prin&t"), "PrintMap",  _method_command("map_print", _("Prin&t"), "PrintMap",
992                  helptext = _("Print the map"))                  helptext = _("Print the map"))
993  _method_command("map_rename", _("&Rename..."), "RenameMap",  _method_command("map_rename", _("&Rename..."), "RenameMap",
994                  helptext = _("Rename the map"))                  helptext = _("Rename the map"))
995  _method_command("layer_add", _("&Add Layer..."), "AddLayer",  _method_command("layer_add", _("&Add Layer..."), "AddLayer",
996                  helptext = _("Add a new layer to active map"))                  helptext = _("Add a new layer to the map"))
997  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
998                  helptext = _("Add a new image layer to active map"))                  helptext = _("Add a new image layer to the map"),
999                    sensitive = _has_gdal_support)
1000  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
1001                  helptext = _("Remove selected layer(s)"),                  helptext = _("Remove selected layer"),
1002                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
1003    
1004  # Layer menu  # Layer menu
1005  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
1006                    sensitive = _has_selected_layer,
1007                    helptext = _("Specify projection for selected layer"))
1008    _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
1009                    helptext = _("Duplicate selected layer"),
1010              sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
1011    _method_command("layer_rename", _("Re&name ..."), "RenameLayer",
1012                    helptext = _("Rename selected layer"),
1013                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1014  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
1015                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer"),
1016                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1017  _method_command("layer_lower", _("&Lower"), "LowerLayer",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
1018                  helptext = _("Lower selected layer(s)"),                  helptext = _("Lower selected layer"),
1019                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1020  _method_command("layer_show", _("&Show"), "ShowLayer",  _method_command("layer_show", _("&Show"), "ShowLayer",
1021                  helptext = _("Make selected layer(s) visible"),                  helptext = _("Make selected layer visible"),
1022                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1023  _method_command("layer_hide", _("&Hide"), "HideLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
1024                  helptext = _("Make selected layer(s) unvisible"),                  helptext = _("Make selected layer unvisible"),
1025                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1026  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
1027                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
1028                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1029  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
1030                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1031                    helptext = _("Edit the properties of the selected layer"))
1032  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1033                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1034                    helptext = _("Join and attach a table to the selected layer"))
1035    
1036  def _can_unjoin(context):  def _can_unjoin(context):
1037      """Return whether the Layer/Unjoin command can be executed.      """Return whether the Layer/Unjoin command can be executed.
# Line 960  def _can_unjoin(context): Line 1048  def _can_unjoin(context):
1048      else:      else:
1049          return 0          return 0
1050  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
1051                  sensitive = _can_unjoin)                  sensitive = _can_unjoin,
1052                    helptext = _("Undo the last join operation"))
1053    
1054    
1055    def _has_tables(context):
1056        return bool(context.session.Tables())
1057    
1058  # Table menu  # Table menu
1059  _method_command("table_open", _("&Open..."), "TableOpen")  _method_command("table_open", _("&Open..."), "TableOpen",
1060  _method_command("table_close", _("&Close"), "TableClose",                  helptext = _("Open a DBF-table from a file"))
1061         sensitive = lambda context: bool(context.session.UnreferencedTables()))  _method_command("table_close", _("&Close..."), "TableClose",
1062  _method_command("table_show", _("&Show"), "TableShow")         sensitive = lambda context: bool(context.session.UnreferencedTables()),
1063  _method_command("table_join", _("&Join..."), "TableJoin")                  helptext = _("Close one or more tables from a list"))
1064    _method_command("table_rename", _("&Rename..."), "TableRename",
1065                    sensitive = _has_tables,
1066                    helptext = _("Rename one or more tables"))
1067    _method_command("table_show", _("&Show..."), "TableShow",
1068                    sensitive = _has_tables,
1069                    helptext = _("Show one or more tables in a dialog"))
1070    _method_command("table_join", _("&Join..."), "TableJoin",
1071                    sensitive = _has_tables,
1072                    helptext = _("Join two tables creating a new one"))
1073    
1074  #  Export only under Windows ...  #  Export only under Windows ...
1075  map_menu = ["layer_add", "rasterlayer_add", "layer_remove", "map_rename",  map_menu = ["layer_add", "rasterlayer_add", "layer_remove",
1076                          None,                          None,
1077                            "map_rename",
1078                          "map_projection",                          "map_projection",
1079                          None,                          None,
1080                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
# Line 997  main_menu = Menu("<main>", "<main>", Line 1100  main_menu = Menu("<main>", "<main>",
1100                          "exit"]),                          "exit"]),
1101                    Menu("map", _("&Map"), map_menu),                    Menu("map", _("&Map"), map_menu),
1102                    Menu("layer", _("&Layer"),                    Menu("layer", _("&Layer"),
1103                          ["layer_raise", "layer_lower",                         ["layer_rename", "layer_duplicate",
1104                            None,
1105                            "layer_raise", "layer_lower",
1106                          None,                          None,
1107                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
1108                          None,                          None,
# Line 1009  main_menu = Menu("<main>", "<main>", Line 1114  main_menu = Menu("<main>", "<main>",
1114                          None,                          None,
1115                          "layer_properties"]),                          "layer_properties"]),
1116                    Menu("table", _("&Table"),                    Menu("table", _("&Table"),
1117                         ["table_open", "table_close",                         ["table_open", "table_close", "table_rename",
1118                         None,                         None,
1119                         "table_show",                         "table_show",
1120                         None,                         None,
# Line 1026  main_toolbar = Menu("<toolbar>", "<toolb Line 1131  main_toolbar = Menu("<toolbar>", "<toolb
1131                       "selected_full_extent",                       "selected_full_extent",
1132                       None,                       None,
1133                       "map_identify_tool", "map_label_tool"])                       "map_identify_tool", "map_label_tool"])
1134    

Legend:
Removed from v.1084  
changed lines
  Added in v.1309

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26