/[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 911 by frank, Fri May 16 16:24:17 2003 UTC revision 1448 by jonathan, Thu Jul 17 14:59:41 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
24    
25  import Thuban  import Thuban
26    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  from Thuban.Model.layer import Layer, RasterLayer
31  from Thuban.Model.color import Color  
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 38  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 62  class MainWindow(DockFrame): Line 69  class MainWindow(DockFrame):
69      # implemented in the __getattr__ method.      # implemented in the __getattr__ method.
70      delegated_methods = {"SelectLayer": "canvas",      delegated_methods = {"SelectLayer": "canvas",
71                           "SelectShapes": "canvas",                           "SelectShapes": "canvas",
72                             "SelectedLayer": "canvas",
73                           "SelectedShapes": "canvas",                           "SelectedShapes": "canvas",
74                           }                           }
75    
# Line 101  class MainWindow(DockFrame): Line 109  class MainWindow(DockFrame):
109    
110          self.init_dialogs()          self.init_dialogs()
111    
112          EVT_CLOSE(self, self._OnClose)          self.ShowLegend()
113    
114            EVT_CLOSE(self, self.OnClose)
115    
116      def Subscribe(self, channel, *args):      def Subscribe(self, channel, *args):
117          """Subscribe a function to a message channel.          """Subscribe a function to a message channel.
# Line 360  class MainWindow(DockFrame): Line 370  class MainWindow(DockFrame):
370                  d.Close()                  d.Close()
371    
372      def NewSession(self):      def NewSession(self):
373          self.save_modified_session()          if self.save_modified_session() != wxID_CANCEL:
374          self.prepare_new_session()              self.prepare_new_session()
375          self.application.SetSession(create_empty_session())              self.application.SetSession(create_empty_session())
376    
377      def OpenSession(self):      def OpenSession(self):
378          self.save_modified_session()          if self.save_modified_session() != wxID_CANCEL:
379          dlg = wxFileDialog(self, _("Open Session"), ".", "",              dlg = wxFileDialog(self, _("Open Session"), ".", "",
380                             "Thuban Session File (*.thuban)|*.thuban", wxOPEN)                                 "Thuban Session File (*.thuban)|*.thuban",
381          if dlg.ShowModal() == wxID_OK:                                 wxOPEN)
382              self.prepare_new_session()              if dlg.ShowModal() == wxID_OK:
383              self.application.OpenSession(dlg.GetPath())                  self.prepare_new_session()
384          dlg.Destroy()                  self.application.OpenSession(dlg.GetPath())
385                dlg.Destroy()
386    
387      def SaveSession(self):      def SaveSession(self):
388          if self.application.session.filename == None:          if self.application.session.filename == None:
# Line 391  class MainWindow(DockFrame): Line 402  class MainWindow(DockFrame):
402      def Exit(self):      def Exit(self):
403          self.Close(False)          self.Close(False)
404    
405      def _OnClose(self, event):      def OnClose(self, event):
406          result = self.save_modified_session(can_veto = event.CanVeto())          result = self.save_modified_session(can_veto = event.CanVeto())
407          if result == wxID_CANCEL:          if result == wxID_CANCEL:
408              event.Veto()              event.Veto()
# Line 400  class MainWindow(DockFrame): Line 411  class MainWindow(DockFrame):
411              # wx's destroy event, but that isn't implemented for wxGTK              # wx's destroy event, but that isn't implemented for wxGTK
412              # yet.              # yet.
413              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)
414              DockFrame._OnClose(self, event)              DockFrame.OnClose(self, event)
415                for dlg in self.dialogs.values():
416                    dlg.Destroy()
417                self.canvas.Destroy()
418              self.Destroy()              self.Destroy()
419    
420      def SetMap(self, map):      def SetMap(self, map):
# Line 432  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 v%s\n"          dlg.ShowModal()
451                              #"Build Date: %s\n"          dlg.Destroy()
                             "\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"  
                            % __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 449  class MainWindow(DockFrame): Line 456  class MainWindow(DockFrame):
456          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
457              filename = dlg.GetPath()              filename = dlg.GetPath()
458              title = os.path.splitext(os.path.basename(filename))[0]              title = os.path.splitext(os.path.basename(filename))[0]
             store = self.application.Session().OpenShapefile(filename)  
             layer = Layer(title, store)  
459              map = self.canvas.Map()              map = self.canvas.Map()
460              has_layers = map.HasLayers()              has_layers = map.HasLayers()
461              try:              try:
462                  map.AddLayer(layer)                  store = self.application.Session().OpenShapefile(filename)
463              except IOError:              except IOError:
464                  # the layer couldn't be opened                  # the layer couldn't be opened
465                  self.RunMessageBox(_("Add Layer"),                  self.RunMessageBox(_("Add Layer"),
466                                     _("Can't open the file '%s'.") % filename)                                     _("Can't open the file '%s'.") % filename)
467              else:              else:
468                    layer = Layer(title, store)
469                    map.AddLayer(layer)
470                    if not has_layers:
471                        # if we're adding a layer to an empty map, fit the
472                        # new map to the window
473                        self.canvas.FitMapToWindow()
474            dlg.Destroy()
475    
476        def AddRasterLayer(self):
477            dlg = wxFileDialog(self, _("Select an image file"), ".", "", "*.*",
478                               wxOPEN)
479            if dlg.ShowModal() == wxID_OK:
480                filename = dlg.GetPath()
481                title = os.path.splitext(os.path.basename(filename))[0]
482                map = self.canvas.Map()
483                has_layers = map.HasLayers()
484                try:
485                    layer = RasterLayer(title, filename)
486                except IOError:
487                    # the layer couldn't be opened
488                    self.RunMessageBox(_("Add Image Layer"),
489                                       _("Can't open the file '%s'.") % filename)
490                else:
491                    map.AddLayer(layer)
492                  if not has_layers:                  if not has_layers:
493                      # if we're adding a layer to an empty map, fit the                      # if we're adding a layer to an empty map, fit the
494                      # new map to the window                      # new map to the window
# Line 513  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:
575                  dialog = tableview.LayerTableFrame(self, name,                  dialog = tableview.LayerTableFrame(self, name,
576                                                 _("Table: %s") % layer.Title(),                                           _("Layer Table: %s") % layer.Title(),
577                                                     layer, table)                                           layer, table)
578                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
579                  dialog.Show(true)                  dialog.Show(True)
580              else:              else:
581                  # FIXME: bring dialog to front here                  # FIXME: bring dialog to front here
582                  pass                  pass
# Line 579  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()
632    
633      def LayerJoinTable(self):      def LayerJoinTable(self):
634          print "LayerJoinTable"          layer = self.canvas.SelectedLayer()
635            if layer is not None:
636                dlg = JoinDialog(self, _("Join Layer with Table"),
637                                 self.application.session,
638                                 layer = layer)
639                dlg.ShowModal()
640    
641      def LayerUnjoinTable(self):      def LayerUnjoinTable(self):
642          print "LayerUnjoinTable"          layer = self.canvas.SelectedLayer()
643            if layer is not None:
644                orig_store = layer.ShapeStore().OrigShapeStore()
645                if orig_store:
646                    layer.SetShapeStore(orig_store)
647    
648      def ShowLegend(self):      def ShowLegend(self):
649          if not self.LegendShown():          if not self.LegendShown():
# Line 614  class MainWindow(DockFrame): Line 669  class MainWindow(DockFrame):
669          return dialog is not None and dialog.IsShown()          return dialog is not None and dialog.IsShown()
670    
671      def TableOpen(self):      def TableOpen(self):
         print "TableOpen"  
672          dlg = wxFileDialog(self, _("Open Table"), ".", "",          dlg = wxFileDialog(self, _("Open Table"), ".", "",
673                             "DBF Files (*.dbf)|*.dbf|" +                             _("DBF Files (*.dbf)") + "|*.dbf|" +
674                             "CSV Files (*.csv)|*.csv|" +                             #_("CSV Files (*.csv)") + "|*.csv|" +
675                             "All Files (*.*)|*.*",                             _("All Files (*.*)") + "|*.*",
676                             wxOPEN)                             wxOPEN)
677          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
678              #self.application.session.OpenTable(dlg.GetPath())              filename = dlg.GetPath()
679              pass              dlg.Destroy()
680                try:
681          dlg.Destroy()                  table = self.application.session.OpenTableFile(filename)
682                except IOError:
683                    # the layer couldn't be opened
684                    self.RunMessageBox(_("Open Table"),
685                                       _("Can't open the file '%s'.") % filename)
686                else:
687                    self.ShowTableView(table)
688    
689      def TableClose(self):      def TableClose(self):
690          print "TableClose"          tables = self.application.session.UnreferencedTables()
691    
692            lst = [(t.Title(), t) for t in tables]
693            lst.sort()
694            titles = [i[0] for i in lst]
695            dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"),
696                                         _("Close Table"), titles,
697                                         size = (400, 300),
698                                         style = wxDEFAULT_DIALOG_STYLE |
699                                                 wxRESIZE_BORDER)
700            if dlg.ShowModal() == wxID_OK:
701                for i in dlg.GetValue():
702                    self.application.session.RemoveTable(lst[i][1])
703    
704    
705      def TableShow(self):      def TableShow(self):
706          print "TableShow"          """Offer a multi-selection dialog for tables to be displayed
707    
708      def TableHide(self):          The windows for the selected tables are opened or brought to
709          print "TableHide"          the front.
710            """
711            tables = self.application.session.Tables()
712    
713            lst = [(t.Title(), t) for t in tables]
714            lst.sort()
715            titles = [i[0] for i in lst]
716            dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"),
717                                         _("Show Table"), titles,
718                                         size = (400,300),
719                                         style = wxDEFAULT_DIALOG_STYLE |
720                                                 wxRESIZE_BORDER)
721            if (dlg.ShowModal() == wxID_OK):
722                for i in dlg.GetValue():
723                    # XXX: if the table belongs to a layer, open a
724                    # LayerTableFrame instead of QueryTableFrame
725                    self.ShowTableView(lst[i][1])
726    
727      def TableJoin(self):      def TableJoin(self):
         print "TableJoin"  
728          dlg = JoinDialog(self, _("Join Tables"), self.application.session)          dlg = JoinDialog(self, _("Join Tables"), self.application.session)
729          if dlg.ShowModal() == wxID_OK:          dlg.ShowModal()
730              print "OK"  
731        def ShowTableView(self, table):
732            """Open a table view for the table and optionally"""
733            name = "table_view%d" % id(table)
734            dialog = self.get_open_dialog(name)
735            if dialog is None:
736                dialog = tableview.QueryTableFrame(self, name,
737                                                   _("Table: %s") % table.Title(),
738                                                   table)
739                self.add_dialog(name, dialog)
740                dialog.Show(True)
741            dialog.Raise()
742    
743        def TableRename(self):
744            """Let the user rename a table"""
745    
746            # First, let the user select a table
747            tables = self.application.session.Tables()
748            lst = [(t.Title(), t) for t in tables]
749            lst.sort()
750            titles = [i[0] for i in lst]
751            dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"),
752                                         _("Rename Table"), titles,
753                                         size = (400,300),
754                                         style = wxDEFAULT_DIALOG_STYLE |
755                                                 wxRESIZE_BORDER)
756            if (dlg.ShowModal() == wxID_OK):
757                to_rename = [lst[i][1] for i in dlg.GetValue()]
758                dlg.Destroy()
759            else:
760                to_rename = []
761    
762            # Second, let the user rename the layers
763            for table in to_rename:
764                dlg = wxTextEntryDialog(self, "Table Title: ", "Rename Table",
765                                        table.Title())
766                try:
767                    if dlg.ShowModal() == wxID_OK:
768                        title = dlg.GetValue()
769                        if title != "":
770                            table.SetTitle(title)
771    
772                            # Make sure the session is marked as modified.
773                            # FIXME: This should be handled automatically,
774                            # but that requires more changes to the tables
775                            # than I have time for currently.
776                            self.application.session.changed()
777                finally:
778                    dlg.Destroy()
779    
780    
781      def ZoomInTool(self):      def ZoomInTool(self):
782          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
# Line 683  class MainWindow(DockFrame): Line 820  class MainWindow(DockFrame):
820    
821          dlg.Destroy()          dlg.Destroy()
822    
823        def RenameLayer(self):
824            """Let the user rename the currently selected layer"""
825            layer = self.current_layer()
826            if layer is not None:
827                dlg = wxTextEntryDialog(self, "Layer Title: ", "Rename Layer",
828                                        layer.Title())
829                try:
830                    if dlg.ShowModal() == wxID_OK:
831                        title = dlg.GetValue()
832                        if title != "":
833                            layer.SetTitle(title)
834                finally:
835                    dlg.Destroy()
836    
837      def identify_view_on_demand(self, layer, shapes):      def identify_view_on_demand(self, layer, shapes):
838          """Subscribed to the canvas' SHAPES_SELECTED message          """Subscribed to the canvas' SHAPES_SELECTED message
839    
# Line 776  def _has_legend_shown(context): Line 927  def _has_legend_shown(context):
927      """Return true if the legend window is shown"""      """Return true if the legend window is shown"""
928      return context.mainwindow.LegendShown()      return context.mainwindow.LegendShown()
929    
930    def _has_gdal_support(context):
931        """Return True if the GDAL is available"""
932        return Thuban.Model.resource.has_gdal_support()
933    
934  # File menu  # File menu
935  _method_command("new_session", _("&New Session"), "NewSession")  _method_command("new_session", _("&New Session"), "NewSession",
936  _method_command("open_session", _("&Open Session..."), "OpenSession")                  helptext = _("Start a new session"))
937  _method_command("save_session", _("&Save Session"), "SaveSession")  _method_command("open_session", _("&Open Session..."), "OpenSession",
938  _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs")                  helptext = _("Open a session file"))
939    _method_command("save_session", _("&Save Session"), "SaveSession",
940                    helptext =_("Save this session to the file it was opened from"))
941    _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs",
942                    helptext = _("Save this session to a new file"))
943  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
944                  checked = _has_tree_window_shown)                  checked = _has_tree_window_shown,
945                    helptext = _("Toggle on/off the session tree analysis window"))
946  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
947                  checked = _has_legend_shown)                  checked = _has_legend_shown,
948  _method_command("exit", _("E&xit"), "Exit")                  helptext = _("Toggle Legend on/off"))
949    _method_command("exit", _("E&xit"), "Exit",
950                    helptext = _("Finish working with Thuban"))
951    
952  # Help menu  # Help menu
953  _method_command("help_about", _("&About..."), "About")  _method_command("help_about", _("&About..."), "About",
954                    helptext = _("Info about Thuban authors, version and modules"))
955    
956    
957  # Map menu  # Map menu
958  _method_command("map_projection", _("Pro&jection..."), "MapProjection")  _method_command("map_projection", _("Pro&jection..."), "MapProjection",
959                    helptext = _("Set or change the map projection"))
960    
961  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
962                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
# Line 812  _tool_command("map_label_tool", _("&Labe Line 975  _tool_command("map_label_tool", _("&Labe
975                helptext = _("Add/Remove labels"), icon = "label",                helptext = _("Add/Remove labels"), icon = "label",
976                sensitive = _has_visible_map)                sensitive = _has_visible_map)
977  _method_command("map_full_extent", _("&Full extent"), "FullExtent",  _method_command("map_full_extent", _("&Full extent"), "FullExtent",
978                 helptext = _("Full Extent"), icon = "fullextent",                 helptext = _("Zoom to the full map extent"), icon = "fullextent",
979                sensitive = _has_visible_map)                sensitive = _has_visible_map)
980  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",
981                 helptext = _("Full Layer Extent"), icon = "fulllayerextent",                  helptext = _("Zoom to the full layer extent"),
982                sensitive = _has_selected_layer)                  icon = "fulllayerextent", sensitive = _has_selected_layer)
983  _method_command("selected_full_extent", _("&Full selection extent"), "FullSelectionExtent",  _method_command("selected_full_extent", _("&Full selection extent"),
984                 helptext = _("Full Selection Extent"), icon = "fullselextent",                  "FullSelectionExtent",
985                sensitive = _has_selected_shapes)                  helptext = _("Zoom to the full selection extent"),
986                    icon = "fullselextent", sensitive = _has_selected_shapes)
987  _method_command("map_export", _("E&xport"), "ExportMap",  _method_command("map_export", _("E&xport"), "ExportMap",
988                      helptext = _("Export the map to file"))                  helptext = _("Export the map to file"))
989  _method_command("map_print", _("Prin&t"), "PrintMap",  _method_command("map_print", _("Prin&t"), "PrintMap",
990                  helptext = _("Print the map"))                  helptext = _("Print the map"))
991  _method_command("map_rename", _("&Rename..."), "RenameMap",  _method_command("map_rename", _("&Rename..."), "RenameMap",
992                  helptext = _("Rename the map"))                  helptext = _("Rename the map"))
993  _method_command("layer_add", _("&Add Layer..."), "AddLayer",  _method_command("layer_add", _("&Add Layer..."), "AddLayer",
994                  helptext = _("Add a new layer to active map"))                  helptext = _("Add a new layer to the map"))
995    _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
996                    helptext = _("Add a new image layer to the map"),
997                    sensitive = _has_gdal_support)
998  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
999                  helptext = _("Remove selected layer(s)"),                  helptext = _("Remove selected layer"),
1000                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
1001    
1002  # Layer menu  # Layer menu
1003  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
1004                    sensitive = _has_selected_layer,
1005                    helptext = _("Specify projection for selected layer"))
1006    _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
1007                    helptext = _("Duplicate selected layer"),
1008              sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
1009    _method_command("layer_rename", _("Re&name ..."), "RenameLayer",
1010                    helptext = _("Rename selected layer"),
1011                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1012  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
1013                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer"),
1014                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1015  _method_command("layer_lower", _("&Lower"), "LowerLayer",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
1016                  helptext = _("Lower selected layer(s)"),                  helptext = _("Lower selected layer"),
1017                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1018  _method_command("layer_show", _("&Show"), "ShowLayer",  _method_command("layer_show", _("&Show"), "ShowLayer",
1019                  helptext = _("Make selected layer(s) visible"),                  helptext = _("Make selected layer visible"),
1020                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1021  _method_command("layer_hide", _("&Hide"), "HideLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
1022                  helptext = _("Make selected layer(s) unvisible"),                  helptext = _("Make selected layer unvisible"),
1023                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1024  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
1025                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
1026                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1027  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
1028                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1029                    helptext = _("Edit the properties of the selected layer"))
1030  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1031                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1032                    helptext = _("Join and attach a table to the selected layer"))
1033    
1034    def _can_unjoin(context):
1035        """Return whether the Layer/Unjoin command can be executed.
1036    
1037        This is the case if a layer is selected and that layer has a
1038        shapestore that has an original shapestore.
1039        """
1040        layer = context.mainwindow.SelectedLayer()
1041        if layer is None:
1042            return 0
1043        getstore = getattr(layer, "ShapeStore", None)
1044        if getstore is not None:
1045            return getstore().OrigShapeStore() is not None
1046        else:
1047            return 0
1048  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
1049                  sensitive = _has_selected_layer)                  sensitive = _can_unjoin,
1050                    helptext = _("Undo the last join operation"))
1051    
1052    
1053    def _has_tables(context):
1054        return bool(context.session.Tables())
1055    
1056  # Table menu  # Table menu
1057  _method_command("table_open", _("&Open..."), "TableOpen")  _method_command("table_open", _("&Open..."), "TableOpen",
1058  _method_command("table_close", _("&Close"), "TableClose")                  helptext = _("Open a DBF-table from a file"))
1059  _method_command("table_show", _("&Show"), "TableShow")  _method_command("table_close", _("&Close..."), "TableClose",
1060  _method_command("table_hide", _("&Hide"), "TableHide")         sensitive = lambda context: bool(context.session.UnreferencedTables()),
1061  _method_command("table_join", _("&Join..."), "TableJoin")                  helptext = _("Close one or more tables from a list"))
1062    _method_command("table_rename", _("&Rename..."), "TableRename",
1063                    sensitive = _has_tables,
1064                    helptext = _("Rename one or more tables"))
1065    _method_command("table_show", _("&Show..."), "TableShow",
1066                    sensitive = _has_tables,
1067                    helptext = _("Show one or more tables in a dialog"))
1068    _method_command("table_join", _("&Join..."), "TableJoin",
1069                    sensitive = _has_tables,
1070                    helptext = _("Join two tables creating a new one"))
1071    
1072  #  Export only under Windows ...  #  Export only under Windows ...
1073  map_menu = ["layer_add", "layer_remove", "map_rename",  map_menu = ["layer_add", "rasterlayer_add", "layer_remove",
1074                          None,                          None,
1075                            "map_rename",
1076                          "map_projection",                          "map_projection",
1077                          None,                          None,
1078                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
# Line 892  main_menu = Menu("<main>", "<main>", Line 1098  main_menu = Menu("<main>", "<main>",
1098                          "exit"]),                          "exit"]),
1099                    Menu("map", _("&Map"), map_menu),                    Menu("map", _("&Map"), map_menu),
1100                    Menu("layer", _("&Layer"),                    Menu("layer", _("&Layer"),
1101                          ["layer_raise", "layer_lower",                         ["layer_rename", "layer_duplicate",
1102                            None,
1103                            "layer_raise", "layer_lower",
1104                          None,                          None,
1105                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
1106                          None,                          None,
# Line 904  main_menu = Menu("<main>", "<main>", Line 1112  main_menu = Menu("<main>", "<main>",
1112                          None,                          None,
1113                          "layer_properties"]),                          "layer_properties"]),
1114                    Menu("table", _("&Table"),                    Menu("table", _("&Table"),
1115                         ["table_open", "table_close",                         ["table_open", "table_close", "table_rename",
1116                         None,                         None,
1117                         "table_show", "table_hide",                         "table_show",
1118                         None,                         None,
1119                         "table_join"]),                         "table_join"]),
1120                    Menu("help", _("&Help"),                    Menu("help", _("&Help"),
# Line 921  main_toolbar = Menu("<toolbar>", "<toolb Line 1129  main_toolbar = Menu("<toolbar>", "<toolb
1129                       "selected_full_extent",                       "selected_full_extent",
1130                       None,                       None,
1131                       "map_identify_tool", "map_label_tool"])                       "map_identify_tool", "map_label_tool"])
1132    

Legend:
Removed from v.911  
changed lines
  Added in v.1448

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26