/[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 1056 by frank, Tue May 27 11:29:46 2003 UTC revision 1625 by bh, Thu Aug 21 16:02:23 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    
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.color import Color  from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support
32  from Thuban.Model.proj import Projection  # 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
 import proj4dialog  
39  import tableview, identifyview  import tableview, identifyview
40  from Thuban.UI.classifier import Classifier  from Thuban.UI.classifier import Classifier
41  import legend  import legend
# Line 42  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 61  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.
72      delegated_methods = {"SelectLayer": "canvas",      delegated_methods = {"SelectLayer": "canvas",
73                           "SelectShapes": "canvas",                           "SelectShapes": "canvas",
74                             "SelectedLayer": "canvas",
75                           "SelectedShapes": "canvas",                           "SelectedShapes": "canvas",
76                           }                           }
77    
# Line 106  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 359  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 375  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 441  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 one or more data files"), ".", "",
460                             wxOPEN)                             _("Shapefiles (*.shp)") + "|*.shp|" +
461                               _("All Files (*.*)") + "|*.*",
462                               wxOPEN | wxMULTIPLE)
463          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
464              filename = dlg.GetPath()              filenames = dlg.GetPaths()
465              title = os.path.splitext(os.path.basename(filename))[0]              for filename in filenames:
466              map = self.canvas.Map()                  title = os.path.splitext(os.path.basename(filename))[0]
467              has_layers = map.HasLayers()                  map = self.canvas.Map()
468              try:                  has_layers = map.HasLayers()
469                  store = self.application.Session().OpenShapefile(filename)                  try:
470              except IOError:                      store = self.application.Session().OpenShapefile(filename)
471                  # the layer couldn't be opened                  except IOError:
472                  self.RunMessageBox(_("Add Layer"),                      # the layer couldn't be opened
473                                     _("Can't open the file '%s'.") % filename)                      self.RunMessageBox(_("Add Layer"),
474              else:                                         _("Can't open the file '%s'.")%filename)
475                  layer = Layer(title, store)                  else:
476                  map.AddLayer(layer)                      layer = Layer(title, store)
477                  if not has_layers:                      map.AddLayer(layer)
478                      # if we're adding a layer to an empty map, fit the                      if not has_layers:
479                      # new map to the window                          # if we're adding a layer to an empty map, fit the
480                      self.canvas.FitMapToWindow()                          # new map to the window
481                            self.canvas.FitMapToWindow()
482          dlg.Destroy()          dlg.Destroy()
483    
484      def AddRasterLayer(self):      def AddRasterLayer(self):
# Line 503  class MainWindow(DockFrame): Line 503  class MainWindow(DockFrame):
503                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
504          dlg.Destroy()          dlg.Destroy()
505    
506        def AddDBLayer(self):
507            """Add a layer read from a database"""
508            session = self.application.Session()
509            dlg = ChooseDBTableDialog(self.application.Session(), self,-1, "")
510    
511            if dlg.ShowModal() == wxID_OK:
512                dbconn, dbtable = dlg.GetTable()
513                try:
514                    title = str(dbtable)
515    
516                    # Chose the correct Interface for the database type
517                    store = PostGISShapeStore(dbconn, dbtable)
518                    session.AddShapeStore(store)
519                    layer = Layer(title, store)
520                except:
521                    # Some error occured while initializing the layer
522                    self.RunMessageBox(_("Add Layer from database"),
523                                       _("Can't open the database table '%s'")
524                                       % dbtable)
525    
526                map = self.canvas.Map()
527    
528                has_layers = map.HasLayers()
529                map.AddLayer(layer)
530                if not has_layers:
531                    self.canvas.FitMapToWindow()
532    
533            dlg.Destroy()
534    
535      def RemoveLayer(self):      def RemoveLayer(self):
536          layer = self.current_layer()          layer = self.current_layer()
537          if layer is not None:          if layer is not None:
# Line 550  class MainWindow(DockFrame): Line 579  class MainWindow(DockFrame):
579          layer = self.current_layer()          layer = self.current_layer()
580          if layer is not None:          if layer is not None:
581              layer.SetVisible(0)              layer.SetVisible(0)
582            
583      def ShowLayer(self):      def ShowLayer(self):
584          layer = self.current_layer()          layer = self.current_layer()
585          if layer is not None:          if layer is not None:
586              layer.SetVisible(1)              layer.SetVisible(1)
587    
588        def DuplicateLayer(self):
589            """Ceate a new layer above the selected layer with the same shapestore
590            """
591            layer = self.current_layer()
592            if layer is not None and hasattr(layer, "ShapeStore"):
593                new_layer = Layer(_("Copy of `%s'") % layer.Title(),
594                                  layer.ShapeStore(),
595                                  projection = layer.GetProjection())
596                new_classification = copy.deepcopy(layer.GetClassification())
597                new_layer.SetClassification(new_classification)
598                self.Map().AddLayer(new_layer)
599    
600        def CanDuplicateLayer(self):
601            """Return whether the DuplicateLayer method can create a duplicate"""
602            layer = self.current_layer()
603            return layer is not None and hasattr(layer, "ShapeStore")
604    
605      def LayerShowTable(self):      def LayerShowTable(self):
606          layer = self.current_layer()          layer = self.current_layer()
607          if layer is not None:          if layer is not None:
608              table = layer.table              table = layer.ShapeStore().Table()
609              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
610              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
611              if dialog is None:              if dialog is None:
# Line 616  class MainWindow(DockFrame): Line 662  class MainWindow(DockFrame):
662          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
663    
664          if dialog is None:          if dialog is None:
665              dialog = Classifier(self, name, layer, group)              dialog = Classifier(self, name, self.Map(), layer, group)
666              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
667              dialog.Show()              dialog.Show()
668          dialog.Raise()          dialog.Raise()
669    
670      def LayerJoinTable(self):      def LayerJoinTable(self):
671          print "LayerJoinTable: Not implemented."          layer = self.canvas.SelectedLayer()
672            if layer is not None:
673                dlg = JoinDialog(self, _("Join Layer with Table"),
674                                 self.application.session,
675                                 layer = layer)
676                dlg.ShowModal()
677    
678      def LayerUnjoinTable(self):      def LayerUnjoinTable(self):
679          print "LayerUnjoinTable: Not implemented."          layer = self.canvas.SelectedLayer()
680            if layer is not None:
681                orig_store = layer.ShapeStore().OrigShapeStore()
682                if orig_store:
683                    layer.SetShapeStore(orig_store)
684    
685      def ShowLegend(self):      def ShowLegend(self):
686          if not self.LegendShown():          if not self.LegendShown():
# Line 669  class MainWindow(DockFrame): Line 724  class MainWindow(DockFrame):
724                  self.ShowTableView(table)                  self.ShowTableView(table)
725    
726      def TableClose(self):      def TableClose(self):
727          print "TableClose: not implemented"          tables = self.application.session.UnreferencedTables()
728    
729            lst = [(t.Title(), t) for t in tables]
730            lst.sort()
731            titles = [i[0] for i in lst]
732            dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"),
733                                         _("Close Table"), titles,
734                                         size = (400, 300),
735                                         style = wxDEFAULT_DIALOG_STYLE |
736                                                 wxRESIZE_BORDER)
737            if dlg.ShowModal() == wxID_OK:
738                for i in dlg.GetValue():
739                    self.application.session.RemoveTable(lst[i][1])
740    
741    
742      def TableShow(self):      def TableShow(self):
743          """Offer a multi-selection dialog for tables to be displayed          """Offer a multi-selection dialog for tables to be displayed
# Line 679  class MainWindow(DockFrame): Line 747  class MainWindow(DockFrame):
747          """          """
748          tables = self.application.session.Tables()          tables = self.application.session.Tables()
749    
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 show:"),          dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"),
754                                       _("Show Table"),                                       _("Show Table"), titles,
755                                       [t.Title() for t in tables],                                       size = (400,300),
756                                       size = (400,300), style = wxRESIZE_BORDER)                                       style = wxDEFAULT_DIALOG_STYLE |
757                                                 wxRESIZE_BORDER)
758          if (dlg.ShowModal() == wxID_OK):          if (dlg.ShowModal() == wxID_OK):
759              for i in dlg.GetValue():              for i in dlg.GetValue():
760                  # XXX: if the table belongs to a layer, open a                  # XXX: if the table belongs to a layer, open a
761                  # LayerTableFrame instead of QueryTableFrame                  # LayerTableFrame instead of QueryTableFrame
762                  self.ShowTableView(tables[i])                  self.ShowTableView(lst[i][1])
763    
764      def TableJoin(self):      def TableJoin(self):
765          dlg = JoinDialog(self, _("Join Tables"), self.application.session)          dlg = JoinDialog(self, _("Join Tables"), self.application.session)
# Line 703  class MainWindow(DockFrame): Line 775  class MainWindow(DockFrame):
775                                                 table)                                                 table)
776              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
777              dialog.Show(True)              dialog.Show(True)
778          # FIXME: else bring dialog to front          dialog.Raise()
779    
780        def TableRename(self):
781            """Let the user rename a table"""
782    
783            # First, let the user select a table
784            tables = self.application.session.Tables()
785            lst = [(t.Title(), t) for t in tables]
786            lst.sort()
787            titles = [i[0] for i in lst]
788            dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"),
789                                         _("Rename Table"), titles,
790                                         size = (400,300),
791                                         style = wxDEFAULT_DIALOG_STYLE |
792                                                 wxRESIZE_BORDER)
793            if (dlg.ShowModal() == wxID_OK):
794                to_rename = [lst[i][1] for i in dlg.GetValue()]
795                dlg.Destroy()
796            else:
797                to_rename = []
798    
799            # Second, let the user rename the layers
800            for table in to_rename:
801                dlg = wxTextEntryDialog(self, "Table Title: ", "Rename Table",
802                                        table.Title())
803                try:
804                    if dlg.ShowModal() == wxID_OK:
805                        title = dlg.GetValue()
806                        if title != "":
807                            table.SetTitle(title)
808    
809                            # Make sure the session is marked as modified.
810                            # FIXME: This should be handled automatically,
811                            # but that requires more changes to the tables
812                            # than I have time for currently.
813                            self.application.session.changed()
814                finally:
815                    dlg.Destroy()
816    
817    
818      def ZoomInTool(self):      def ZoomInTool(self):
819          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
# Line 747  class MainWindow(DockFrame): Line 857  class MainWindow(DockFrame):
857    
858          dlg.Destroy()          dlg.Destroy()
859    
860        def RenameLayer(self):
861            """Let the user rename the currently selected layer"""
862            layer = self.current_layer()
863            if layer is not None:
864                dlg = wxTextEntryDialog(self, "Layer Title: ", "Rename Layer",
865                                        layer.Title())
866                try:
867                    if dlg.ShowModal() == wxID_OK:
868                        title = dlg.GetValue()
869                        if title != "":
870                            layer.SetTitle(title)
871                finally:
872                    dlg.Destroy()
873    
874      def identify_view_on_demand(self, layer, shapes):      def identify_view_on_demand(self, layer, shapes):
875          """Subscribed to the canvas' SHAPES_SELECTED message          """Subscribed to the canvas' SHAPES_SELECTED message
876    
# Line 840  def _has_legend_shown(context): Line 964  def _has_legend_shown(context):
964      """Return true if the legend window is shown"""      """Return true if the legend window is shown"""
965      return context.mainwindow.LegendShown()      return context.mainwindow.LegendShown()
966    
967    def _has_gdal_support(context):
968        """Return True if the GDAL is available"""
969        return Thuban.Model.resource.has_gdal_support()
970    
971    def _has_dbconnections(context):
972        """Return whether the the session has database connections"""
973        return context.session.HasDBConnections()
974    
975    def _has_postgis_support(context):
976        return has_postgis_support()
977    
978    
979  # File menu  # File menu
980  _method_command("new_session", _("&New Session"), "NewSession")  _method_command("new_session", _("&New Session"), "NewSession",
981  _method_command("open_session", _("&Open Session..."), "OpenSession")                  helptext = _("Start a new session"))
982  _method_command("save_session", _("&Save Session"), "SaveSession")  _method_command("open_session", _("&Open Session..."), "OpenSession",
983  _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs")                  helptext = _("Open a session file"))
984    _method_command("save_session", _("&Save Session"), "SaveSession",
985                    helptext =_("Save this session to the file it was opened from"))
986    _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs",
987                    helptext = _("Save this session to a new file"))
988  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
989                  checked = _has_tree_window_shown)                  checked = _has_tree_window_shown,
990                    helptext = _("Toggle on/off the session tree analysis window"))
991  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
992                  checked = _has_legend_shown)                  checked = _has_legend_shown,
993  _method_command("exit", _("E&xit"), "Exit")                  helptext = _("Toggle Legend on/off"))
994    _method_command("database_management", _("&Database Connections..."),
995                    "DatabaseManagement",
996                    sensitive = _has_postgis_support)
997    _method_command("exit", _("E&xit"), "Exit",
998                    helptext = _("Finish working with Thuban"))
999    
1000  # Help menu  # Help menu
1001  _method_command("help_about", _("&About..."), "About")  _method_command("help_about", _("&About..."), "About",
1002                    helptext = _("Info about Thuban authors, version and modules"))
1003    
1004    
1005  # Map menu  # Map menu
1006  _method_command("map_projection", _("Pro&jection..."), "MapProjection")  _method_command("map_projection", _("Pro&jection..."), "MapProjection",
1007                    helptext = _("Set or change the map projection"))
1008    
1009  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
1010                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
# Line 876  _tool_command("map_label_tool", _("&Labe Line 1023  _tool_command("map_label_tool", _("&Labe
1023                helptext = _("Add/Remove labels"), icon = "label",                helptext = _("Add/Remove labels"), icon = "label",
1024                sensitive = _has_visible_map)                sensitive = _has_visible_map)
1025  _method_command("map_full_extent", _("&Full extent"), "FullExtent",  _method_command("map_full_extent", _("&Full extent"), "FullExtent",
1026                 helptext = _("Full Extent"), icon = "fullextent",                 helptext = _("Zoom to the full map extent"), icon = "fullextent",
1027                sensitive = _has_visible_map)                sensitive = _has_visible_map)
1028  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",
1029                 helptext = _("Full Layer Extent"), icon = "fulllayerextent",                  helptext = _("Zoom to the full layer extent"),
1030                sensitive = _has_selected_layer)                  icon = "fulllayerextent", sensitive = _has_selected_layer)
1031  _method_command("selected_full_extent", _("&Full selection extent"), "FullSelectionExtent",  _method_command("selected_full_extent", _("&Full selection extent"),
1032                 helptext = _("Full Selection Extent"), icon = "fullselextent",                  "FullSelectionExtent",
1033                sensitive = _has_selected_shapes)                  helptext = _("Zoom to the full selection extent"),
1034                    icon = "fullselextent", sensitive = _has_selected_shapes)
1035  _method_command("map_export", _("E&xport"), "ExportMap",  _method_command("map_export", _("E&xport"), "ExportMap",
1036                      helptext = _("Export the map to file"))                  helptext = _("Export the map to file"))
1037  _method_command("map_print", _("Prin&t"), "PrintMap",  _method_command("map_print", _("Prin&t"), "PrintMap",
1038                  helptext = _("Print the map"))                  helptext = _("Print the map"))
1039  _method_command("map_rename", _("&Rename..."), "RenameMap",  _method_command("map_rename", _("&Rename..."), "RenameMap",
1040                  helptext = _("Rename the map"))                  helptext = _("Rename the map"))
1041  _method_command("layer_add", _("&Add Layer..."), "AddLayer",  _method_command("layer_add", _("&Add Layer..."), "AddLayer",
1042                  helptext = _("Add a new layer to active map"))                  helptext = _("Add a new layer to the map"))
1043  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
1044                  helptext = _("Add a new image layer to active map"))                  helptext = _("Add a new image layer to the map"),
1045                    sensitive = _has_gdal_support)
1046    _method_command("layer_add_db", _("Add &Database Layer..."), "AddDBLayer",
1047                    helptext = _("Add a new database layer to active map"),
1048                    sensitive = _has_dbconnections)
1049  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
1050                  helptext = _("Remove selected layer(s)"),                  helptext = _("Remove selected layer"),
1051                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
1052    
1053  # Layer menu  # Layer menu
1054  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
1055                    sensitive = _has_selected_layer,
1056                    helptext = _("Specify projection for selected layer"))
1057    _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
1058                    helptext = _("Duplicate selected layer"),
1059              sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
1060    _method_command("layer_rename", _("Re&name ..."), "RenameLayer",
1061                    helptext = _("Rename selected layer"),
1062                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1063  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
1064                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer"),
1065                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1066  _method_command("layer_lower", _("&Lower"), "LowerLayer",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
1067                  helptext = _("Lower selected layer(s)"),                  helptext = _("Lower selected layer"),
1068                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1069  _method_command("layer_show", _("&Show"), "ShowLayer",  _method_command("layer_show", _("&Show"), "ShowLayer",
1070                  helptext = _("Make selected layer(s) visible"),                  helptext = _("Make selected layer visible"),
1071                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1072  _method_command("layer_hide", _("&Hide"), "HideLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
1073                  helptext = _("Make selected layer(s) unvisible"),                  helptext = _("Make selected layer unvisible"),
1074                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1075  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
1076                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
1077                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1078  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
1079                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1080                    helptext = _("Edit the properties of the selected layer"))
1081  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1082                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1083                    helptext = _("Join and attach a table to the selected layer"))
1084    
1085    def _can_unjoin(context):
1086        """Return whether the Layer/Unjoin command can be executed.
1087    
1088        This is the case if a layer is selected and that layer has a
1089        shapestore that has an original shapestore.
1090        """
1091        layer = context.mainwindow.SelectedLayer()
1092        if layer is None:
1093            return 0
1094        getstore = getattr(layer, "ShapeStore", None)
1095        if getstore is not None:
1096            return getstore().OrigShapeStore() is not None
1097        else:
1098            return 0
1099  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
1100                  sensitive = _has_selected_layer)                  sensitive = _can_unjoin,
1101                    helptext = _("Undo the last join operation"))
1102    
1103    
1104    def _has_tables(context):
1105        return bool(context.session.Tables())
1106    
1107  # Table menu  # Table menu
1108  _method_command("table_open", _("&Open..."), "TableOpen")  _method_command("table_open", _("&Open..."), "TableOpen",
1109  _method_command("table_close", _("&Close"), "TableClose")                  helptext = _("Open a DBF-table from a file"))
1110  _method_command("table_show", _("&Show"), "TableShow")  _method_command("table_close", _("&Close..."), "TableClose",
1111  _method_command("table_join", _("&Join..."), "TableJoin")         sensitive = lambda context: bool(context.session.UnreferencedTables()),
1112                    helptext = _("Close one or more tables from a list"))
1113    _method_command("table_rename", _("&Rename..."), "TableRename",
1114                    sensitive = _has_tables,
1115                    helptext = _("Rename one or more tables"))
1116    _method_command("table_show", _("&Show..."), "TableShow",
1117                    sensitive = _has_tables,
1118                    helptext = _("Show one or more tables in a dialog"))
1119    _method_command("table_join", _("&Join..."), "TableJoin",
1120                    sensitive = _has_tables,
1121                    helptext = _("Join two tables creating a new one"))
1122    
1123  #  Export only under Windows ...  #  Export only under Windows ...
1124  map_menu = ["layer_add", "rasterlayer_add", "layer_remove", "map_rename",  map_menu = ["layer_add", "layer_add_db", "rasterlayer_add", "layer_remove",
1125                          None,                          None,
1126                            "map_rename",
1127                          "map_projection",                          "map_projection",
1128                          None,                          None,
1129                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
1130                          "map_pan_tool",                          "map_pan_tool",
1131                          "map_full_extent",                          "map_full_extent",
1132                          "layer_full_extent",                          "layer_full_extent",
1133                          "selected_full_extent",                          "selected_full_extent",
1134                          None,                          None,
# Line 953  main_menu = Menu("<main>", "<main>", Line 1145  main_menu = Menu("<main>", "<main>",
1145                   [Menu("file", _("&File"),                   [Menu("file", _("&File"),
1146                         ["new_session", "open_session", None,                         ["new_session", "open_session", None,
1147                          "save_session", "save_session_as", None,                          "save_session", "save_session_as", None,
1148                            "database_management", None,
1149                          "toggle_session_tree", None,                          "toggle_session_tree", None,
1150                          "exit"]),                          "exit"]),
1151                    Menu("map", _("&Map"), map_menu),                    Menu("map", _("&Map"), map_menu),
1152                    Menu("layer", _("&Layer"),                    Menu("layer", _("&Layer"),
1153                          ["layer_raise", "layer_lower",                         ["layer_rename", "layer_duplicate",
1154                            None,
1155                            "layer_raise", "layer_lower",
1156                          None,                          None,
1157                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
1158                          None,                          None,
# Line 969  main_menu = Menu("<main>", "<main>", Line 1164  main_menu = Menu("<main>", "<main>",
1164                          None,                          None,
1165                          "layer_properties"]),                          "layer_properties"]),
1166                    Menu("table", _("&Table"),                    Menu("table", _("&Table"),
1167                         ["table_open", "table_close",                         ["table_open", "table_close", "table_rename",
1168                         None,                         None,
1169                         "table_show",                         "table_show",
1170                         None,                         None,
# Line 986  main_toolbar = Menu("<toolbar>", "<toolb Line 1181  main_toolbar = Menu("<toolbar>", "<toolb
1181                       "selected_full_extent",                       "selected_full_extent",
1182                       None,                       None,
1183                       "map_identify_tool", "map_label_tool"])                       "map_identify_tool", "map_label_tool"])
1184    

Legend:
Removed from v.1056  
changed lines
  Added in v.1625

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26