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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26