/[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 1126 by bh, Mon Jun 2 14:15:43 2003 UTC revision 1620 by bh, Wed Aug 20 13:14:22 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
# Line 22  import copy Line 22  import copy
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    
28  from Thuban import _  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    from Thuban.Model.postgisdb import PostGISShapeStore
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
# Line 40  from menu import Menu Line 43  from menu import Menu
43    
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         MAP_REPLACED
48    from about import About
49    
50  from Thuban.UI.dock import DockFrame  from Thuban.UI.dock import DockFrame
51  from Thuban.UI.join import JoinDialog  from Thuban.UI.join import JoinDialog
52    from Thuban.UI.dbdialog import DBFrame, ChooseDBTableDialog
53  import resource  import resource
54    import Thuban.Model.resource
55    
56  import projdialog  import projdialog
57    
58    
   
59  class MainWindow(DockFrame):  class MainWindow(DockFrame):
60    
61      # Some messages that can be subscribed/unsubscribed directly through      # Some messages that can be subscribed/unsubscribed directly through
# Line 59  class MainWindow(DockFrame): Line 64  class MainWindow(DockFrame):
64      # actually come from. This delegation is implemented in the      # actually come from. This delegation is implemented in the
65      # Subscribe and unsubscribed methods      # Subscribe and unsubscribed methods
66      delegated_messages = {LAYER_SELECTED: "canvas",      delegated_messages = {LAYER_SELECTED: "canvas",
67                            SHAPES_SELECTED: "canvas"}                            SHAPES_SELECTED: "canvas",
68                              MAP_REPLACED: "canvas"}
69    
70      # Methods delegated to some instance variables. The delegation is      # Methods delegated to some instance variables. The delegation is
71      # implemented in the __getattr__ method.      # implemented in the __getattr__ method.
# Line 105  class MainWindow(DockFrame): Line 111  class MainWindow(DockFrame):
111    
112          self.init_dialogs()          self.init_dialogs()
113    
114            self.ShowLegend()
115    
116          EVT_CLOSE(self, self.OnClose)          EVT_CLOSE(self, self.OnClose)
117    
118      def Subscribe(self, channel, *args):      def Subscribe(self, channel, *args):
# Line 358  class MainWindow(DockFrame): Line 366  class MainWindow(DockFrame):
366              result = wxID_NO              result = wxID_NO
367          return result          return result
368    
     def prepare_new_session(self):  
         for d in self.dialogs.values():  
             if not isinstance(d, tree.SessionTreeView):  
                 d.Close()  
   
369      def NewSession(self):      def NewSession(self):
370          if self.save_modified_session() != wxID_CANCEL:          if self.save_modified_session() != wxID_CANCEL:
             self.prepare_new_session()  
371              self.application.SetSession(create_empty_session())              self.application.SetSession(create_empty_session())
372    
373      def OpenSession(self):      def OpenSession(self):
# Line 374  class MainWindow(DockFrame): Line 376  class MainWindow(DockFrame):
376                                 "Thuban Session File (*.thuban)|*.thuban",                                 "Thuban Session File (*.thuban)|*.thuban",
377                                 wxOPEN)                                 wxOPEN)
378              if dlg.ShowModal() == wxID_OK:              if dlg.ShowModal() == wxID_OK:
                 self.prepare_new_session()  
379                  self.application.OpenSession(dlg.GetPath())                  self.application.OpenSession(dlg.GetPath())
380              dlg.Destroy()              dlg.Destroy()
381    
# Line 440  class MainWindow(DockFrame): Line 441  class MainWindow(DockFrame):
441          return self.get_open_dialog("session_tree") is not None          return self.get_open_dialog("session_tree") is not None
442    
443      def About(self):      def About(self):
444          self.RunMessageBox(_("About"),          dlg = About(self)
445                             _("Thuban %s\n"          dlg.ShowModal()
446                              #"Build Date: %s\n"          dlg.Destroy()
447                              "using:\n"  
448                              "  %s\n"      def DatabaseManagement(self):
449                              "  %s\n\n"          name = "dbmanagement"
450                              "Thuban is a program for\n"          dialog = self.get_open_dialog(name)
451                              "exploring geographic data.\n"          if dialog is None:
452                              "Copyright (C) 2001-2003 Intevation GmbH.\n"              map = self.canvas.Map()
453                              "Thuban is licensed under the GNU GPL"              dialog = DBFrame(self, name, self.application.Session())
454                              % (Thuban.version.longversion,              self.add_dialog(name, dialog)
455                                 "wxPython %s" % wxPython_version,              dialog.Show()
456                                 "Python %d.%d.%d" % sys.version_info[:3]          dialog.Raise()
                               )),  
 #                           % __ThubanVersion__), #__BuildDate__)),  
                            wxOK | wxICON_INFORMATION)  
457    
458      def AddLayer(self):      def AddLayer(self):
459          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",
# Line 502  class MainWindow(DockFrame): Line 500  class MainWindow(DockFrame):
500                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
501          dlg.Destroy()          dlg.Destroy()
502    
503        def AddDBLayer(self):
504            """Add a layer read from a database"""
505            session = self.application.Session()
506            dlg = ChooseDBTableDialog(self.application.Session(), self,-1, "")
507    
508            if dlg.ShowModal() == wxID_OK:
509                dbconn, dbtable = dlg.GetTable()
510                try:
511                    title = str(dbtable)
512    
513                    # Chose the correct Interface for the database type
514                    store = PostGISShapeStore(dbconn, dbtable)
515                    session.AddShapeStore(store)
516                    layer = Layer(title, store)
517                except:
518                    # Some error occured while initializing the layer
519                    self.RunMessageBox(_("Add Layer from database"),
520                                       _("Can't open the database table '%s'")
521                                       % dbtable)
522    
523                map = self.canvas.Map()
524    
525                has_layers = map.HasLayers()
526                map.AddLayer(layer)
527                if not has_layers:
528                    self.canvas.FitMapToWindow()
529    
530            dlg.Destroy()
531    
532      def RemoveLayer(self):      def RemoveLayer(self):
533          layer = self.current_layer()          layer = self.current_layer()
534          if layer is not None:          if layer is not None:
# Line 575  class MainWindow(DockFrame): Line 602  class MainWindow(DockFrame):
602      def LayerShowTable(self):      def LayerShowTable(self):
603          layer = self.current_layer()          layer = self.current_layer()
604          if layer is not None:          if layer is not None:
605              table = layer.table              table = layer.ShapeStore().Table()
606              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
607              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
608              if dialog is None:              if dialog is None:
# Line 632  class MainWindow(DockFrame): Line 659  class MainWindow(DockFrame):
659          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
660    
661          if dialog is None:          if dialog is None:
662              dialog = Classifier(self, name, layer, group)              dialog = Classifier(self, name, self.Map(), layer, group)
663              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
664              dialog.Show()              dialog.Show()
665          dialog.Raise()          dialog.Raise()
# Line 670  class MainWindow(DockFrame): Line 697  class MainWindow(DockFrame):
697          else:          else:
698              dialog.Show(not dialog.IsShown())              dialog.Show(not dialog.IsShown())
699    
         self.canvas.FitMapToWindow()  
   
700      def LegendShown(self):      def LegendShown(self):
701          """Return true iff the legend is currently open"""          """Return true iff the legend is currently open"""
702          dialog = self.FindRegisteredDock("legend")          dialog = self.FindRegisteredDock("legend")
# Line 747  class MainWindow(DockFrame): Line 772  class MainWindow(DockFrame):
772                                                 table)                                                 table)
773              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
774              dialog.Show(True)              dialog.Show(True)
775          # FIXME: else bring dialog to front          dialog.Raise()
776    
777      def TableRename(self):      def TableRename(self):
778          """Let the user rename a table"""          """Let the user rename a table"""
# Line 936  def _has_legend_shown(context): Line 961  def _has_legend_shown(context):
961      """Return true if the legend window is shown"""      """Return true if the legend window is shown"""
962      return context.mainwindow.LegendShown()      return context.mainwindow.LegendShown()
963    
964    def _has_gdal_support(context):
965        """Return True if the GDAL is available"""
966        return Thuban.Model.resource.has_gdal_support()
967    
968    def _has_dbconnections(context):
969        """Return whether the the session has database connections"""
970        return context.session.HasDBConnections()
971    
972  # File menu  # File menu
973  _method_command("new_session", _("&New Session"), "NewSession")  _method_command("new_session", _("&New Session"), "NewSession",
974  _method_command("open_session", _("&Open Session..."), "OpenSession")                  helptext = _("Start a new session"))
975  _method_command("save_session", _("&Save Session"), "SaveSession")  _method_command("open_session", _("&Open Session..."), "OpenSession",
976  _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs")                  helptext = _("Open a session file"))
977    _method_command("save_session", _("&Save Session"), "SaveSession",
978                    helptext =_("Save this session to the file it was opened from"))
979    _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs",
980                    helptext = _("Save this session to a new file"))
981  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
982                  checked = _has_tree_window_shown)                  checked = _has_tree_window_shown,
983                    helptext = _("Toggle on/off the session tree analysis window"))
984  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
985                  checked = _has_legend_shown)                  checked = _has_legend_shown,
986  _method_command("exit", _("E&xit"), "Exit")                  helptext = _("Toggle Legend on/off"))
987    _method_command("database_management", _("&Database Connections..."),
988                    "DatabaseManagement")
989    _method_command("exit", _("E&xit"), "Exit",
990                    helptext = _("Finish working with Thuban"))
991    
992  # Help menu  # Help menu
993  _method_command("help_about", _("&About..."), "About")  _method_command("help_about", _("&About..."), "About",
994                    helptext = _("Info about Thuban authors, version and modules"))
995    
996    
997  # Map menu  # Map menu
998  _method_command("map_projection", _("Pro&jection..."), "MapProjection")  _method_command("map_projection", _("Pro&jection..."), "MapProjection",
999                    helptext = _("Set or change the map projection"))
1000    
1001  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
1002                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
# Line 972  _tool_command("map_label_tool", _("&Labe Line 1015  _tool_command("map_label_tool", _("&Labe
1015                helptext = _("Add/Remove labels"), icon = "label",                helptext = _("Add/Remove labels"), icon = "label",
1016                sensitive = _has_visible_map)                sensitive = _has_visible_map)
1017  _method_command("map_full_extent", _("&Full extent"), "FullExtent",  _method_command("map_full_extent", _("&Full extent"), "FullExtent",
1018                 helptext = _("Full Extent"), icon = "fullextent",                 helptext = _("Zoom to the full map extent"), icon = "fullextent",
1019                sensitive = _has_visible_map)                sensitive = _has_visible_map)
1020  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",
1021                 helptext = _("Full Layer Extent"), icon = "fulllayerextent",                  helptext = _("Zoom to the full layer extent"),
1022                sensitive = _has_selected_layer)                  icon = "fulllayerextent", sensitive = _has_selected_layer)
1023  _method_command("selected_full_extent", _("&Full selection extent"), "FullSelectionExtent",  _method_command("selected_full_extent", _("&Full selection extent"),
1024                 helptext = _("Full Selection Extent"), icon = "fullselextent",                  "FullSelectionExtent",
1025                sensitive = _has_selected_shapes)                  helptext = _("Zoom to the full selection extent"),
1026                    icon = "fullselextent", sensitive = _has_selected_shapes)
1027  _method_command("map_export", _("E&xport"), "ExportMap",  _method_command("map_export", _("E&xport"), "ExportMap",
1028                      helptext = _("Export the map to file"))                  helptext = _("Export the map to file"))
1029  _method_command("map_print", _("Prin&t"), "PrintMap",  _method_command("map_print", _("Prin&t"), "PrintMap",
1030                  helptext = _("Print the map"))                  helptext = _("Print the map"))
1031  _method_command("map_rename", _("&Rename..."), "RenameMap",  _method_command("map_rename", _("&Rename..."), "RenameMap",
1032                  helptext = _("Rename the map"))                  helptext = _("Rename the map"))
1033  _method_command("layer_add", _("&Add Layer..."), "AddLayer",  _method_command("layer_add", _("&Add Layer..."), "AddLayer",
1034                  helptext = _("Add a new layer to active map"))                  helptext = _("Add a new layer to the map"))
1035  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
1036                  helptext = _("Add a new image layer to active map"))                  helptext = _("Add a new image layer to the map"),
1037                    sensitive = _has_gdal_support)
1038    _method_command("layer_add_db", _("Add &Database Layer..."), "AddDBLayer",
1039                    helptext = _("Add a new database layer to active map"),
1040                    sensitive = _has_dbconnections)
1041  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
1042                  helptext = _("Remove selected layer(s)"),                  helptext = _("Remove selected layer"),
1043                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
1044    
1045  # Layer menu  # Layer menu
1046  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
1047                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1048                    helptext = _("Specify projection for selected layer"))
1049  _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",  _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
1050                  helptext = _("Duplicate selected layer(s)"),                  helptext = _("Duplicate selected layer"),
1051            sensitive = lambda context: context.mainwindow.CanDuplicateLayer())            sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
1052  _method_command("layer_rename", _("Re&name ..."), "RenameLayer",  _method_command("layer_rename", _("Re&name ..."), "RenameLayer",
1053                  helptext = _("Rename selected layer"),                  helptext = _("Rename selected layer"),
1054                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1055  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
1056                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer"),
1057                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1058  _method_command("layer_lower", _("&Lower"), "LowerLayer",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
1059                  helptext = _("Lower selected layer(s)"),                  helptext = _("Lower selected layer"),
1060                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1061  _method_command("layer_show", _("&Show"), "ShowLayer",  _method_command("layer_show", _("&Show"), "ShowLayer",
1062                  helptext = _("Make selected layer(s) visible"),                  helptext = _("Make selected layer visible"),
1063                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1064  _method_command("layer_hide", _("&Hide"), "HideLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
1065                  helptext = _("Make selected layer(s) unvisible"),                  helptext = _("Make selected layer unvisible"),
1066                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1067  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
1068                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
1069                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1070  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
1071                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1072                    helptext = _("Edit the properties of the selected layer"))
1073  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1074                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1075                    helptext = _("Join and attach a table to the selected layer"))
1076    
1077  def _can_unjoin(context):  def _can_unjoin(context):
1078      """Return whether the Layer/Unjoin command can be executed.      """Return whether the Layer/Unjoin command can be executed.
# Line 1038  def _can_unjoin(context): Line 1089  def _can_unjoin(context):
1089      else:      else:
1090          return 0          return 0
1091  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
1092                  sensitive = _can_unjoin)                  sensitive = _can_unjoin,
1093                    helptext = _("Undo the last join operation"))
1094    
1095    
1096  def _has_tables(context):  def _has_tables(context):
1097      return bool(context.session.Tables())      return bool(context.session.Tables())
1098    
1099  # Table menu  # Table menu
1100  _method_command("table_open", _("&Open..."), "TableOpen")  _method_command("table_open", _("&Open..."), "TableOpen",
1101  _method_command("table_close", _("&Close"), "TableClose",                  helptext = _("Open a DBF-table from a file"))
1102         sensitive = lambda context: bool(context.session.UnreferencedTables()))  _method_command("table_close", _("&Close..."), "TableClose",
1103           sensitive = lambda context: bool(context.session.UnreferencedTables()),
1104                    helptext = _("Close one or more tables from a list"))
1105  _method_command("table_rename", _("&Rename..."), "TableRename",  _method_command("table_rename", _("&Rename..."), "TableRename",
1106                  sensitive = _has_tables)                  sensitive = _has_tables,
1107  _method_command("table_show", _("&Show"), "TableShow",                  helptext = _("Rename one or more tables"))
1108                  sensitive = _has_tables)  _method_command("table_show", _("&Show..."), "TableShow",
1109                    sensitive = _has_tables,
1110                    helptext = _("Show one or more tables in a dialog"))
1111  _method_command("table_join", _("&Join..."), "TableJoin",  _method_command("table_join", _("&Join..."), "TableJoin",
1112                  sensitive = _has_tables)                  sensitive = _has_tables,
1113                    helptext = _("Join two tables creating a new one"))
1114    
1115  #  Export only under Windows ...  #  Export only under Windows ...
1116  map_menu = ["layer_add", "rasterlayer_add", "layer_remove", "map_rename",  map_menu = ["layer_add", "layer_add_db", "rasterlayer_add", "layer_remove",
1117                          None,                          None,
1118                            "map_rename",
1119                          "map_projection",                          "map_projection",
1120                          None,                          None,
1121                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
1122                          "map_pan_tool",                          "map_pan_tool",
1123                          "map_full_extent",                          "map_full_extent",
1124                          "layer_full_extent",                          "layer_full_extent",
1125                          "selected_full_extent",                          "selected_full_extent",
1126                          None,                          None,
# Line 1079  main_menu = Menu("<main>", "<main>", Line 1137  main_menu = Menu("<main>", "<main>",
1137                   [Menu("file", _("&File"),                   [Menu("file", _("&File"),
1138                         ["new_session", "open_session", None,                         ["new_session", "open_session", None,
1139                          "save_session", "save_session_as", None,                          "save_session", "save_session_as", None,
1140                            "database_management", None,
1141                          "toggle_session_tree", None,                          "toggle_session_tree", None,
1142                          "exit"]),                          "exit"]),
1143                    Menu("map", _("&Map"), map_menu),                    Menu("map", _("&Map"), map_menu),
# Line 1114  main_toolbar = Menu("<toolbar>", "<toolb Line 1173  main_toolbar = Menu("<toolbar>", "<toolb
1173                       "selected_full_extent",                       "selected_full_extent",
1174                       None,                       None,
1175                       "map_identify_tool", "map_label_tool"])                       "map_identify_tool", "map_label_tool"])
1176    

Legend:
Removed from v.1126  
changed lines
  Added in v.1620

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26