/[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 951 by frank, Wed May 21 14:20:32 2003 UTC revision 1644 by bh, Mon Aug 25 12:44:55 2003 UTC
# Line 12  The main window Line 12  The main window
12  """  """
13    
14  __version__ = "$Revision$"  __version__ = "$Revision$"
15    # $Source$
16  __ThubanVersion__ = "0.2" #"$THUBAN_0_2$"  # $Id$
 #__BuildDate__ = "$Date$"  
17    
18  import os  import os
19    import copy
20    
21  from wxPython.wx import *  from wxPython.wx import *
22  from wxPython.wx import __version__ as wxPython_version  from wxPython.wx import __version__ as wxPython_version
# Line 27  import Thuban.version Line 27  import Thuban.version
27  from Thuban import _  from Thuban import _
28  from Thuban.Model.session import create_empty_session  from Thuban.Model.session import create_empty_session
29  from Thuban.Model.layer import Layer, RasterLayer  from Thuban.Model.layer import Layer, RasterLayer
30  from Thuban.Model.color import Color  from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support
31  from Thuban.Model.proj import Projection  # XXX: replace this by
32    # from wxPython.lib.dialogs import wxMultipleChoiceDialog
33    # when Thuban does not support wxPython 2.4.0 any more.
34    from Thuban.UI.multiplechoicedialog import wxMultipleChoiceDialog
35    
36  import view  import view
37  import tree  import tree
 import proj4dialog  
38  import tableview, identifyview  import tableview, identifyview
39  from Thuban.UI.classifier import Classifier  from Thuban.UI.classifier import Classifier
40  import legend  import legend
# Line 40  from menu import Menu Line 42  from menu import Menu
42    
43  from context import Context  from context import Context
44  from command import registry, Command, ToolCommand  from command import registry, Command, ToolCommand
45  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, \
46         MAP_REPLACED
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    from Thuban.UI.dbdialog import DBFrame, ChooseDBTableDialog
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 59  class MainWindow(DockFrame): Line 63  class MainWindow(DockFrame):
63      # actually come from. This delegation is implemented in the      # actually come from. This delegation is implemented in the
64      # Subscribe and unsubscribed methods      # Subscribe and unsubscribed methods
65      delegated_messages = {LAYER_SELECTED: "canvas",      delegated_messages = {LAYER_SELECTED: "canvas",
66                            SHAPES_SELECTED: "canvas"}                            SHAPES_SELECTED: "canvas",
67                              MAP_REPLACED: "canvas"}
68    
69      # Methods delegated to some instance variables. The delegation is      # Methods delegated to some instance variables. The delegation is
70      # implemented in the __getattr__ method.      # implemented in the __getattr__ method.
71      delegated_methods = {"SelectLayer": "canvas",      delegated_methods = {"SelectLayer": "canvas",
72                           "SelectShapes": "canvas",                           "SelectShapes": "canvas",
73                             "SelectedLayer": "canvas",
74                           "SelectedShapes": "canvas",                           "SelectedShapes": "canvas",
75                           }                           }
76    
# Line 104  class MainWindow(DockFrame): Line 110  class MainWindow(DockFrame):
110    
111          self.init_dialogs()          self.init_dialogs()
112    
113            self.ShowLegend()
114    
115          EVT_CLOSE(self, self.OnClose)          EVT_CLOSE(self, self.OnClose)
116    
117      def Subscribe(self, channel, *args):      def Subscribe(self, channel, *args):
# Line 357  class MainWindow(DockFrame): Line 365  class MainWindow(DockFrame):
365              result = wxID_NO              result = wxID_NO
366          return result          return result
367    
     def prepare_new_session(self):  
         for d in self.dialogs.values():  
             if not isinstance(d, tree.SessionTreeView):  
                 d.Close()  
   
368      def NewSession(self):      def NewSession(self):
369          if self.save_modified_session() != wxID_CANCEL:          if self.save_modified_session() != wxID_CANCEL:
             self.prepare_new_session()  
370              self.application.SetSession(create_empty_session())              self.application.SetSession(create_empty_session())
371    
372      def OpenSession(self):      def OpenSession(self):
# Line 373  class MainWindow(DockFrame): Line 375  class MainWindow(DockFrame):
375                                 "Thuban Session File (*.thuban)|*.thuban",                                 "Thuban Session File (*.thuban)|*.thuban",
376                                 wxOPEN)                                 wxOPEN)
377              if dlg.ShowModal() == wxID_OK:              if dlg.ShowModal() == wxID_OK:
                 self.prepare_new_session()  
378                  self.application.OpenSession(dlg.GetPath())                  self.application.OpenSession(dlg.GetPath())
379              dlg.Destroy()              dlg.Destroy()
380    
# Line 404  class MainWindow(DockFrame): Line 405  class MainWindow(DockFrame):
405              # wx's destroy event, but that isn't implemented for wxGTK              # wx's destroy event, but that isn't implemented for wxGTK
406              # yet.              # yet.
407              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)
408              DockFrame._OnClose(self, event)              DockFrame.OnClose(self, event)
409                for dlg in self.dialogs.values():
410                    dlg.Destroy()
411                self.canvas.Destroy()
412              self.Destroy()              self.Destroy()
413    
414      def SetMap(self, map):      def SetMap(self, map):
# Line 436  class MainWindow(DockFrame): Line 440  class MainWindow(DockFrame):
440          return self.get_open_dialog("session_tree") is not None          return self.get_open_dialog("session_tree") is not None
441    
442      def About(self):      def About(self):
443          self.RunMessageBox(_("About"),          dlg = About(self)
444                             _("Thuban %s\n"          dlg.ShowModal()
445                              #"Build Date: %s\n"          dlg.Destroy()
446                              "using:\n"  
447                              "  %s\n"      def DatabaseManagement(self):
448                              "  %s\n\n"          name = "dbmanagement"
449                              "Thuban is a program for\n"          dialog = self.get_open_dialog(name)
450                              "exploring geographic data.\n"          if dialog is None:
451                              "Copyright (C) 2001-2003 Intevation GmbH.\n"              map = self.canvas.Map()
452                              "Thuban is licensed under the GNU GPL"              dialog = DBFrame(self, name, self.application.Session())
453                              % (Thuban.version.longversion,              self.add_dialog(name, dialog)
454                                 "wxPython %s" % wxPython_version,              dialog.Show()
455                                 "Python %d.%d.%d" % sys.version_info[:3]          dialog.Raise()
                               )),  
 #                           % __ThubanVersion__), #__BuildDate__)),  
                            wxOK | wxICON_INFORMATION)  
456    
457      def AddLayer(self):      def AddLayer(self):
458          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",          dlg = wxFileDialog(self, _("Select one or more data files"), ".", "",
459                             wxOPEN)                             _("Shapefiles (*.shp)") + "|*.shp|" +
460                               _("All Files (*.*)") + "|*.*",
461                               wxOPEN | wxMULTIPLE)
462          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
463              filename = dlg.GetPath()              filenames = dlg.GetPaths()
464              title = os.path.splitext(os.path.basename(filename))[0]              for filename in filenames:
465              store = self.application.Session().OpenShapefile(filename)                  title = os.path.splitext(os.path.basename(filename))[0]
466              layer = Layer(title, store)                  map = self.canvas.Map()
467              map = self.canvas.Map()                  has_layers = map.HasLayers()
468              has_layers = map.HasLayers()                  try:
469              try:                      store = self.application.Session().OpenShapefile(filename)
470                  map.AddLayer(layer)                  except IOError:
471              except IOError:                      # the layer couldn't be opened
472                  # the layer couldn't be opened                      self.RunMessageBox(_("Add Layer"),
473                  self.RunMessageBox(_("Add Layer"),                                         _("Can't open the file '%s'.")%filename)
474                                     _("Can't open the file '%s'.") % filename)                  else:
475              else:                      layer = Layer(title, store)
476                  if not has_layers:                      map.AddLayer(layer)
477                      # if we're adding a layer to an empty map, fit the                      if not has_layers:
478                      # new map to the window                          # if we're adding a layer to an empty map, fit the
479                      self.canvas.FitMapToWindow()                          # new map to the window
480                            self.canvas.FitMapToWindow()
481          dlg.Destroy()          dlg.Destroy()
482    
483      def AddRasterLayer(self):      def AddRasterLayer(self):
# Line 482  class MainWindow(DockFrame): Line 486  class MainWindow(DockFrame):
486          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
487              filename = dlg.GetPath()              filename = dlg.GetPath()
488              title = os.path.splitext(os.path.basename(filename))[0]              title = os.path.splitext(os.path.basename(filename))[0]
             layer = RasterLayer(title, filename)  
489              map = self.canvas.Map()              map = self.canvas.Map()
490              has_layers = map.HasLayers()              has_layers = map.HasLayers()
491              try:              try:
492                  map.AddLayer(layer)                  layer = RasterLayer(title, filename)
493              except IOError:              except IOError:
494                  # the layer couldn't be opened                  # the layer couldn't be opened
495                  self.RunMessageBox(_("Add Image Layer"),                  self.RunMessageBox(_("Add Image Layer"),
496                                     _("Can't open the file '%s'.") % filename)                                     _("Can't open the file '%s'.") % filename)
497              else:              else:
498                    map.AddLayer(layer)
499                  if not has_layers:                  if not has_layers:
500                      # if we're adding a layer to an empty map, fit the                      # if we're adding a layer to an empty map, fit the
501                      # new map to the window                      # new map to the window
502                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
503          dlg.Destroy()          dlg.Destroy()
504    
505        def AddDBLayer(self):
506            """Add a layer read from a database"""
507            session = self.application.Session()
508            dlg = ChooseDBTableDialog(self.application.Session(), self,-1, "")
509    
510            if dlg.ShowModal() == wxID_OK:
511                dbconn, dbtable = dlg.GetTable()
512                try:
513                    title = str(dbtable)
514    
515                    # Chose the correct Interface for the database type
516                    store = PostGISShapeStore(dbconn, dbtable)
517                    session.AddShapeStore(store)
518                    layer = Layer(title, store)
519                except:
520                    # Some error occured while initializing the layer
521                    self.RunMessageBox(_("Add Layer from database"),
522                                       _("Can't open the database table '%s'")
523                                       % dbtable)
524    
525                map = self.canvas.Map()
526    
527                has_layers = map.HasLayers()
528                map.AddLayer(layer)
529                if not has_layers:
530                    self.canvas.FitMapToWindow()
531    
532            dlg.Destroy()
533    
534      def RemoveLayer(self):      def RemoveLayer(self):
535          layer = self.current_layer()          layer = self.current_layer()
536          if layer is not None:          if layer is not None:
# Line 545  class MainWindow(DockFrame): Line 578  class MainWindow(DockFrame):
578          layer = self.current_layer()          layer = self.current_layer()
579          if layer is not None:          if layer is not None:
580              layer.SetVisible(0)              layer.SetVisible(0)
581            
582      def ShowLayer(self):      def ShowLayer(self):
583          layer = self.current_layer()          layer = self.current_layer()
584          if layer is not None:          if layer is not None:
585              layer.SetVisible(1)              layer.SetVisible(1)
586    
587        def DuplicateLayer(self):
588            """Ceate a new layer above the selected layer with the same shapestore
589            """
590            layer = self.current_layer()
591            if layer is not None and hasattr(layer, "ShapeStore"):
592                new_layer = Layer(_("Copy of `%s'") % layer.Title(),
593                                  layer.ShapeStore(),
594                                  projection = layer.GetProjection())
595                new_classification = copy.deepcopy(layer.GetClassification())
596                new_layer.SetClassification(new_classification)
597                self.Map().AddLayer(new_layer)
598    
599        def CanDuplicateLayer(self):
600            """Return whether the DuplicateLayer method can create a duplicate"""
601            layer = self.current_layer()
602            return layer is not None and hasattr(layer, "ShapeStore")
603    
604      def LayerShowTable(self):      def LayerShowTable(self):
605          layer = self.current_layer()          layer = self.current_layer()
606          if layer is not None:          if layer is not None:
607              table = layer.table              table = layer.ShapeStore().Table()
608              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
609              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
610              if dialog is None:              if dialog is None:
611                  dialog = tableview.LayerTableFrame(self, name,                  dialog = tableview.LayerTableFrame(self, name,
612                                                 _("Table: %s") % layer.Title(),                                           _("Layer Table: %s") % layer.Title(),
613                                                     layer, table)                                           layer, table)
614                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
615                  dialog.Show(true)                  dialog.Show(True)
616              else:              else:
617                  # FIXME: bring dialog to front here                  # FIXME: bring dialog to front here
618                  pass                  pass
# Line 611  class MainWindow(DockFrame): Line 661  class MainWindow(DockFrame):
661          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
662    
663          if dialog is None:          if dialog is None:
664              dialog = Classifier(self, name, layer, group)              dialog = Classifier(self, name, self.Map(), layer, group)
665              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
666              dialog.Show()              dialog.Show()
667          dialog.Raise()          dialog.Raise()
668    
669      def LayerJoinTable(self):      def LayerJoinTable(self):
670          print "LayerJoinTable"          layer = self.canvas.SelectedLayer()
671            if layer is not None:
672                dlg = JoinDialog(self, _("Join Layer with Table"),
673                                 self.application.session,
674                                 layer = layer)
675                dlg.ShowModal()
676    
677      def LayerUnjoinTable(self):      def LayerUnjoinTable(self):
678          print "LayerUnjoinTable"          layer = self.canvas.SelectedLayer()
679            if layer is not None:
680                orig_store = layer.ShapeStore().OrigShapeStore()
681                if orig_store:
682                    layer.SetShapeStore(orig_store)
683    
684      def ShowLegend(self):      def ShowLegend(self):
685          if not self.LegendShown():          if not self.LegendShown():
# Line 646  class MainWindow(DockFrame): Line 705  class MainWindow(DockFrame):
705          return dialog is not None and dialog.IsShown()          return dialog is not None and dialog.IsShown()
706    
707      def TableOpen(self):      def TableOpen(self):
         print "TableOpen"  
708          dlg = wxFileDialog(self, _("Open Table"), ".", "",          dlg = wxFileDialog(self, _("Open Table"), ".", "",
709                             "DBF Files (*.dbf)|*.dbf|" +                             _("DBF Files (*.dbf)") + "|*.dbf|" +
710                             "CSV Files (*.csv)|*.csv|" +                             #_("CSV Files (*.csv)") + "|*.csv|" +
711                             "All Files (*.*)|*.*",                             _("All Files (*.*)") + "|*.*",
712                             wxOPEN)                             wxOPEN)
713          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
714              #self.application.session.OpenTable(dlg.GetPath())              filename = dlg.GetPath()
715              pass              dlg.Destroy()
716                try:
717          dlg.Destroy()                  table = self.application.session.OpenTableFile(filename)
718                except IOError:
719                    # the layer couldn't be opened
720                    self.RunMessageBox(_("Open Table"),
721                                       _("Can't open the file '%s'.") % filename)
722                else:
723                    self.ShowTableView(table)
724    
725      def TableClose(self):      def TableClose(self):
726          print "TableClose"          tables = self.application.session.UnreferencedTables()
727    
728            lst = [(t.Title(), t) for t in tables]
729            lst.sort()
730            titles = [i[0] for i in lst]
731            dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"),
732                                         _("Close Table"), titles,
733                                         size = (400, 300),
734                                         style = wxDEFAULT_DIALOG_STYLE |
735                                                 wxRESIZE_BORDER)
736            if dlg.ShowModal() == wxID_OK:
737                for i in dlg.GetValue():
738                    self.application.session.RemoveTable(lst[i][1])
739    
740    
741      def TableShow(self):      def TableShow(self):
742          print "TableShow"          """Offer a multi-selection dialog for tables to be displayed
743    
744      def TableHide(self):          The windows for the selected tables are opened or brought to
745          print "TableHide"          the front.
746            """
747            tables = self.application.session.Tables()
748    
749            lst = [(t.Title(), t) for t in tables]
750            lst.sort()
751            titles = [i[0] for i in lst]
752            dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"),
753                                         _("Show Table"), titles,
754                                         size = (400,300),
755                                         style = wxDEFAULT_DIALOG_STYLE |
756                                                 wxRESIZE_BORDER)
757            if (dlg.ShowModal() == wxID_OK):
758                for i in dlg.GetValue():
759                    # XXX: if the table belongs to a layer, open a
760                    # LayerTableFrame instead of QueryTableFrame
761                    self.ShowTableView(lst[i][1])
762    
763      def TableJoin(self):      def TableJoin(self):
         print "TableJoin"  
764          dlg = JoinDialog(self, _("Join Tables"), self.application.session)          dlg = JoinDialog(self, _("Join Tables"), self.application.session)
765          if dlg.ShowModal() == wxID_OK:          dlg.ShowModal()
766              print "OK"  
767        def ShowTableView(self, table):
768            """Open a table view for the table and optionally"""
769            name = "table_view%d" % id(table)
770            dialog = self.get_open_dialog(name)
771            if dialog is None:
772                dialog = tableview.QueryTableFrame(self, name,
773                                                   _("Table: %s") % table.Title(),
774                                                   table)
775                self.add_dialog(name, dialog)
776                dialog.Show(True)
777            dialog.Raise()
778    
779        def TableRename(self):
780            """Let the user rename a table"""
781    
782            # First, let the user select a table
783            tables = self.application.session.Tables()
784            lst = [(t.Title(), t) for t in tables]
785            lst.sort()
786            titles = [i[0] for i in lst]
787            dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"),
788                                         _("Rename Table"), titles,
789                                         size = (400,300),
790                                         style = wxDEFAULT_DIALOG_STYLE |
791                                                 wxRESIZE_BORDER)
792            if (dlg.ShowModal() == wxID_OK):
793                to_rename = [lst[i][1] for i in dlg.GetValue()]
794                dlg.Destroy()
795            else:
796                to_rename = []
797    
798            # Second, let the user rename the layers
799            for table in to_rename:
800                dlg = wxTextEntryDialog(self, "Table Title: ", "Rename Table",
801                                        table.Title())
802                try:
803                    if dlg.ShowModal() == wxID_OK:
804                        title = dlg.GetValue()
805                        if title != "":
806                            table.SetTitle(title)
807    
808                            # Make sure the session is marked as modified.
809                            # FIXME: This should be handled automatically,
810                            # but that requires more changes to the tables
811                            # than I have time for currently.
812                            self.application.session.changed()
813                finally:
814                    dlg.Destroy()
815    
816    
817      def ZoomInTool(self):      def ZoomInTool(self):
818          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
# Line 715  class MainWindow(DockFrame): Line 856  class MainWindow(DockFrame):
856    
857          dlg.Destroy()          dlg.Destroy()
858    
859        def RenameLayer(self):
860            """Let the user rename the currently selected layer"""
861            layer = self.current_layer()
862            if layer is not None:
863                dlg = wxTextEntryDialog(self, "Layer Title: ", "Rename Layer",
864                                        layer.Title())
865                try:
866                    if dlg.ShowModal() == wxID_OK:
867                        title = dlg.GetValue()
868                        if title != "":
869                            layer.SetTitle(title)
870                finally:
871                    dlg.Destroy()
872    
873      def identify_view_on_demand(self, layer, shapes):      def identify_view_on_demand(self, layer, shapes):
874          """Subscribed to the canvas' SHAPES_SELECTED message          """Subscribed to the canvas' SHAPES_SELECTED message
875    
# Line 808  def _has_legend_shown(context): Line 963  def _has_legend_shown(context):
963      """Return true if the legend window is shown"""      """Return true if the legend window is shown"""
964      return context.mainwindow.LegendShown()      return context.mainwindow.LegendShown()
965    
966    def _has_gdal_support(context):
967        """Return True if the GDAL is available"""
968        return Thuban.Model.resource.has_gdal_support()
969    
970    def _has_dbconnections(context):
971        """Return whether the the session has database connections"""
972        return context.session.HasDBConnections()
973    
974    def _has_postgis_support(context):
975        return has_postgis_support()
976    
977    
978  # File menu  # File menu
979  _method_command("new_session", _("&New Session"), "NewSession")  _method_command("new_session", _("&New Session"), "NewSession",
980  _method_command("open_session", _("&Open Session..."), "OpenSession")                  helptext = _("Start a new session"))
981  _method_command("save_session", _("&Save Session"), "SaveSession")  _method_command("open_session", _("&Open Session..."), "OpenSession",
982  _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs")                  helptext = _("Open a session file"))
983    _method_command("save_session", _("&Save Session"), "SaveSession",
984                    helptext =_("Save this session to the file it was opened from"))
985    _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs",
986                    helptext = _("Save this session to a new file"))
987  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
988                  checked = _has_tree_window_shown)                  checked = _has_tree_window_shown,
989                    helptext = _("Toggle on/off the session tree analysis window"))
990  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
991                  checked = _has_legend_shown)                  checked = _has_legend_shown,
992  _method_command("exit", _("E&xit"), "Exit")                  helptext = _("Toggle Legend on/off"))
993    _method_command("database_management", _("&Database Connections..."),
994                    "DatabaseManagement",
995                    sensitive = _has_postgis_support)
996    _method_command("exit", _("E&xit"), "Exit",
997                    helptext = _("Finish working with Thuban"))
998    
999  # Help menu  # Help menu
1000  _method_command("help_about", _("&About..."), "About")  _method_command("help_about", _("&About..."), "About",
1001                    helptext = _("Info about Thuban authors, version and modules"))
1002    
1003    
1004  # Map menu  # Map menu
1005  _method_command("map_projection", _("Pro&jection..."), "MapProjection")  _method_command("map_projection", _("Pro&jection..."), "MapProjection",
1006                    helptext = _("Set or change the map projection"))
1007    
1008  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
1009                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
# Line 844  _tool_command("map_label_tool", _("&Labe Line 1022  _tool_command("map_label_tool", _("&Labe
1022                helptext = _("Add/Remove labels"), icon = "label",                helptext = _("Add/Remove labels"), icon = "label",
1023                sensitive = _has_visible_map)                sensitive = _has_visible_map)
1024  _method_command("map_full_extent", _("&Full extent"), "FullExtent",  _method_command("map_full_extent", _("&Full extent"), "FullExtent",
1025                 helptext = _("Full Extent"), icon = "fullextent",                 helptext = _("Zoom to the full map extent"), icon = "fullextent",
1026                sensitive = _has_visible_map)                sensitive = _has_visible_map)
1027  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",
1028                 helptext = _("Full Layer Extent"), icon = "fulllayerextent",                  helptext = _("Zoom to the full layer extent"),
1029                sensitive = _has_selected_layer)                  icon = "fulllayerextent", sensitive = _has_selected_layer)
1030  _method_command("selected_full_extent", _("&Full selection extent"), "FullSelectionExtent",  _method_command("selected_full_extent", _("&Full selection extent"),
1031                 helptext = _("Full Selection Extent"), icon = "fullselextent",                  "FullSelectionExtent",
1032                sensitive = _has_selected_shapes)                  helptext = _("Zoom to the full selection extent"),
1033                    icon = "fullselextent", sensitive = _has_selected_shapes)
1034  _method_command("map_export", _("E&xport"), "ExportMap",  _method_command("map_export", _("E&xport"), "ExportMap",
1035                      helptext = _("Export the map to file"))                  helptext = _("Export the map to file"))
1036  _method_command("map_print", _("Prin&t"), "PrintMap",  _method_command("map_print", _("Prin&t"), "PrintMap",
1037                  helptext = _("Print the map"))                  helptext = _("Print the map"))
1038  _method_command("map_rename", _("&Rename..."), "RenameMap",  _method_command("map_rename", _("&Rename..."), "RenameMap",
1039                  helptext = _("Rename the map"))                  helptext = _("Rename the map"))
1040  _method_command("layer_add", _("&Add Layer..."), "AddLayer",  _method_command("layer_add", _("&Add Layer..."), "AddLayer",
1041                  helptext = _("Add a new layer to active map"))                  helptext = _("Add a new layer to the map"))
1042  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
1043                  helptext = _("Add a new image layer to active map"))                  helptext = _("Add a new image layer to the map"),
1044                    sensitive = _has_gdal_support)
1045    _method_command("layer_add_db", _("Add &Database Layer..."), "AddDBLayer",
1046                    helptext = _("Add a new database layer to active map"),
1047                    sensitive = _has_dbconnections)
1048  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
1049                  helptext = _("Remove selected layer(s)"),                  helptext = _("Remove selected layer"),
1050                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
1051    
1052  # Layer menu  # Layer menu
1053  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
1054                    sensitive = _has_selected_layer,
1055                    helptext = _("Specify projection for selected layer"))
1056    _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
1057                    helptext = _("Duplicate selected layer"),
1058              sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
1059    _method_command("layer_rename", _("Re&name ..."), "RenameLayer",
1060                    helptext = _("Rename selected layer"),
1061                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1062  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
1063                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer"),
1064                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1065  _method_command("layer_lower", _("&Lower"), "LowerLayer",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
1066                  helptext = _("Lower selected layer(s)"),                  helptext = _("Lower selected layer"),
1067                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1068  _method_command("layer_show", _("&Show"), "ShowLayer",  _method_command("layer_show", _("&Show"), "ShowLayer",
1069                  helptext = _("Make selected layer(s) visible"),                  helptext = _("Make selected layer visible"),
1070                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1071  _method_command("layer_hide", _("&Hide"), "HideLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
1072                  helptext = _("Make selected layer(s) unvisible"),                  helptext = _("Make selected layer unvisible"),
1073                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1074  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
1075                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
1076                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1077  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
1078                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1079                    helptext = _("Edit the properties of the selected layer"))
1080  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1081                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1082                    helptext = _("Join and attach a table to the selected layer"))
1083    
1084    def _can_unjoin(context):
1085        """Return whether the Layer/Unjoin command can be executed.
1086    
1087        This is the case if a layer is selected and that layer has a
1088        shapestore that has an original shapestore.
1089        """
1090        layer = context.mainwindow.SelectedLayer()
1091        if layer is None:
1092            return 0
1093        getstore = getattr(layer, "ShapeStore", None)
1094        if getstore is not None:
1095            return getstore().OrigShapeStore() is not None
1096        else:
1097            return 0
1098  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
1099                  sensitive = _has_selected_layer)                  sensitive = _can_unjoin,
1100                    helptext = _("Undo the last join operation"))
1101    
1102    
1103    def _has_tables(context):
1104        return bool(context.session.Tables())
1105    
1106  # Table menu  # Table menu
1107  _method_command("table_open", _("&Open..."), "TableOpen")  _method_command("table_open", _("&Open..."), "TableOpen",
1108  _method_command("table_close", _("&Close"), "TableClose")                  helptext = _("Open a DBF-table from a file"))
1109  _method_command("table_show", _("&Show"), "TableShow")  _method_command("table_close", _("&Close..."), "TableClose",
1110  _method_command("table_hide", _("&Hide"), "TableHide")         sensitive = lambda context: bool(context.session.UnreferencedTables()),
1111  _method_command("table_join", _("&Join..."), "TableJoin")                  helptext = _("Close one or more tables from a list"))
1112    _method_command("table_rename", _("&Rename..."), "TableRename",
1113                    sensitive = _has_tables,
1114                    helptext = _("Rename one or more tables"))
1115    _method_command("table_show", _("&Show..."), "TableShow",
1116                    sensitive = _has_tables,
1117                    helptext = _("Show one or more tables in a dialog"))
1118    _method_command("table_join", _("&Join..."), "TableJoin",
1119                    sensitive = _has_tables,
1120                    helptext = _("Join two tables creating a new one"))
1121    
1122  #  Export only under Windows ...  #  Export only under Windows ...
1123  map_menu = ["layer_add", "rasterlayer_add", "layer_remove", "map_rename",  map_menu = ["layer_add", "layer_add_db", "rasterlayer_add", "layer_remove",
1124                          None,                          None,
1125                            "map_rename",
1126                          "map_projection",                          "map_projection",
1127                          None,                          None,
1128                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
1129                          "map_pan_tool",                          "map_pan_tool",
1130                          "map_full_extent",                          "map_full_extent",
1131                          "layer_full_extent",                          "layer_full_extent",
1132                          "selected_full_extent",                          "selected_full_extent",
1133                          None,                          None,
# Line 922  main_menu = Menu("<main>", "<main>", Line 1144  main_menu = Menu("<main>", "<main>",
1144                   [Menu("file", _("&File"),                   [Menu("file", _("&File"),
1145                         ["new_session", "open_session", None,                         ["new_session", "open_session", None,
1146                          "save_session", "save_session_as", None,                          "save_session", "save_session_as", None,
1147                            "database_management", None,
1148                          "toggle_session_tree", None,                          "toggle_session_tree", None,
1149                          "exit"]),                          "exit"]),
1150                    Menu("map", _("&Map"), map_menu),                    Menu("map", _("&Map"), map_menu),
1151                    Menu("layer", _("&Layer"),                    Menu("layer", _("&Layer"),
1152                          ["layer_raise", "layer_lower",                         ["layer_rename", "layer_duplicate",
1153                            None,
1154                            "layer_raise", "layer_lower",
1155                          None,                          None,
1156                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
1157                          None,                          None,
# Line 938  main_menu = Menu("<main>", "<main>", Line 1163  main_menu = Menu("<main>", "<main>",
1163                          None,                          None,
1164                          "layer_properties"]),                          "layer_properties"]),
1165                    Menu("table", _("&Table"),                    Menu("table", _("&Table"),
1166                         ["table_open", "table_close",                         ["table_open", "table_close", "table_rename",
1167                         None,                         None,
1168                         "table_show", "table_hide",                         "table_show",
1169                         None,                         None,
1170                         "table_join"]),                         "table_join"]),
1171                    Menu("help", _("&Help"),                    Menu("help", _("&Help"),
# Line 955  main_toolbar = Menu("<toolbar>", "<toolb Line 1180  main_toolbar = Menu("<toolbar>", "<toolb
1180                       "selected_full_extent",                       "selected_full_extent",
1181                       None,                       None,
1182                       "map_identify_tool", "map_label_tool"])                       "map_identify_tool", "map_label_tool"])
1183    

Legend:
Removed from v.951  
changed lines
  Added in v.1644

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26