/[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 713 by jonathan, Wed Apr 23 08:46:54 2003 UTC revision 1219 by bh, Mon Jun 16 17:42:54 2003 UTC
# Line 2  Line 2 
2  # Authors:  # Authors:
3  # Jan-Oliver Wagner <[email protected]>  # Jan-Oliver Wagner <[email protected]>
4  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
5    # Frank Koormann <[email protected]>
6  #  #
7  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
8  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 16  __ThubanVersion__ = "0.2" #"$THUBAN_0_2$ Line 17  __ThubanVersion__ = "0.2" #"$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 39  from command import registry, Command, T Line 46  from command import registry, Command, T
46  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION
47    
48  from Thuban.UI.dock import DockFrame  from Thuban.UI.dock import DockFrame
49    from Thuban.UI.join import JoinDialog
50    
51  import resource  import resource
52    import Thuban.Model.resource
53    
54  import projdialog  import projdialog
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 60  class MainWindow(DockFrame): Line 67  class MainWindow(DockFrame):
67      # implemented in the __getattr__ method.      # implemented in the __getattr__ method.
68      delegated_methods = {"SelectLayer": "canvas",      delegated_methods = {"SelectLayer": "canvas",
69                           "SelectShapes": "canvas",                           "SelectShapes": "canvas",
70                             "SelectedLayer": "canvas",
71                             "SelectedShapes": "canvas",
72                           }                           }
73    
74      def __init__(self, parent, ID, title, application, interactor,      def __init__(self, parent, ID, title, application, interactor,
# Line 98  class MainWindow(DockFrame): Line 107  class MainWindow(DockFrame):
107    
108          self.init_dialogs()          self.init_dialogs()
109    
110          EVT_CLOSE(self, self._OnClose)          EVT_CLOSE(self, self.OnClose)
111    
112      def Subscribe(self, channel, *args):      def Subscribe(self, channel, *args):
113          """Subscribe a function to a message channel.          """Subscribe a function to a message channel.
# Line 357  class MainWindow(DockFrame): Line 366  class MainWindow(DockFrame):
366                  d.Close()                  d.Close()
367    
368      def NewSession(self):      def NewSession(self):
369          self.save_modified_session()          if self.save_modified_session() != wxID_CANCEL:
370          self.prepare_new_session()              self.prepare_new_session()
371          self.application.SetSession(create_empty_session())              self.application.SetSession(create_empty_session())
372    
373      def OpenSession(self):      def OpenSession(self):
374          self.save_modified_session()          if self.save_modified_session() != wxID_CANCEL:
375          dlg = wxFileDialog(self, _("Open Session"), ".", "", "*.thuban", wxOPEN)              dlg = wxFileDialog(self, _("Open Session"), ".", "",
376          if dlg.ShowModal() == wxID_OK:                                 "Thuban Session File (*.thuban)|*.thuban",
377              self.prepare_new_session()                                 wxOPEN)
378              self.application.OpenSession(dlg.GetPath())              if dlg.ShowModal() == wxID_OK:
379          dlg.Destroy()                  self.prepare_new_session()
380                    self.application.OpenSession(dlg.GetPath())
381                dlg.Destroy()
382    
383      def SaveSession(self):      def SaveSession(self):
384          if self.application.session.filename == None:          if self.application.session.filename == None:
# Line 377  class MainWindow(DockFrame): Line 388  class MainWindow(DockFrame):
388    
389      def SaveSessionAs(self):      def SaveSessionAs(self):
390          dlg = wxFileDialog(self, _("Save Session As"), ".", "",          dlg = wxFileDialog(self, _("Save Session As"), ".", "",
391                             "*.thuban", wxOPEN)                             "Thuban Session File (*.thuban)|*.thuban",
392                               wxSAVE|wxOVERWRITE_PROMPT)
393          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
394              self.application.session.SetFilename(dlg.GetPath())              self.application.session.SetFilename(dlg.GetPath())
395              self.application.SaveSession()              self.application.SaveSession()
# Line 386  class MainWindow(DockFrame): Line 398  class MainWindow(DockFrame):
398      def Exit(self):      def Exit(self):
399          self.Close(False)          self.Close(False)
400    
401      def _OnClose(self, event):      def OnClose(self, event):
402          result = self.save_modified_session(can_veto = event.CanVeto())          result = self.save_modified_session(can_veto = event.CanVeto())
403          if result == wxID_CANCEL:          if result == wxID_CANCEL:
404              event.Veto()              event.Veto()
# Line 395  class MainWindow(DockFrame): Line 407  class MainWindow(DockFrame):
407              # wx's destroy event, but that isn't implemented for wxGTK              # wx's destroy event, but that isn't implemented for wxGTK
408              # yet.              # yet.
409              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)
410              DockFrame._OnClose(self, event)              DockFrame.OnClose(self, event)
411                for dlg in self.dialogs.values():
412                    dlg.Destroy()
413                self.canvas.Destroy()
414              self.Destroy()              self.Destroy()
415    
416      def SetMap(self, map):      def SetMap(self, map):
417          self.canvas.SetMap(map)          self.canvas.SetMap(map)
418          self.__SetTitle(map.Title())          self.__SetTitle(map.Title())
419          #self.legendPanel.SetMap(map)  
420            dialog = self.FindRegisteredDock("legend")
421            if dialog is not None:
422                dialog.GetPanel().SetMap(self.Map())
423    
424      def Map(self):      def Map(self):
425          """Return the map displayed by this mainwindow"""          """Return the map displayed by this mainwindow"""
426    
         # sanity check  
         #assert(self.canvas.Map() is self.legendPanel.GetMap())  
   
427          return self.canvas.Map()          return self.canvas.Map()
428    
429      def ToggleSessionTree(self):      def ToggleSessionTree(self):
# Line 428  class MainWindow(DockFrame): Line 443  class MainWindow(DockFrame):
443    
444      def About(self):      def About(self):
445          self.RunMessageBox(_("About"),          self.RunMessageBox(_("About"),
446                             _("Thuban v%s\n"                             _("Thuban %s\n"
447                              #"Build Date: %s\n"                              #"Build Date: %s\n"
448                              "\n"                              "using:\n"
449                                "  %s\n"
450                                "  %s\n\n"
451                              "Thuban is a program for\n"                              "Thuban is a program for\n"
452                              "exploring geographic data.\n"                              "exploring geographic data.\n"
453                              "Copyright (C) 2001-2003 Intevation GmbH.\n"                              "Copyright (C) 2001-2003 Intevation GmbH.\n"
454                              "Thuban is licensed under the GNU GPL"                              "Thuban is licensed under the GNU GPL"
455                             % __ThubanVersion__), #__BuildDate__)),                              % (Thuban.version.longversion,
456                                   "wxPython %s" % wxPython_version,
457                                   "Python %d.%d.%d" % sys.version_info[:3]
458                                  )),
459    #                           % __ThubanVersion__), #__BuildDate__)),
460                             wxOK | wxICON_INFORMATION)                             wxOK | wxICON_INFORMATION)
461    
462      def AddLayer(self):      def AddLayer(self):
# Line 444  class MainWindow(DockFrame): Line 465  class MainWindow(DockFrame):
465          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
466              filename = dlg.GetPath()              filename = dlg.GetPath()
467              title = os.path.splitext(os.path.basename(filename))[0]              title = os.path.splitext(os.path.basename(filename))[0]
             layer = Layer(title, filename)  
468              map = self.canvas.Map()              map = self.canvas.Map()
469              has_layers = map.HasLayers()              has_layers = map.HasLayers()
470              try:              try:
471                  map.AddLayer(layer)                  store = self.application.Session().OpenShapefile(filename)
472              except IOError:              except IOError:
473                  # the layer couldn't be opened                  # the layer couldn't be opened
474                  self.RunMessageBox(_("Add Layer"),                  self.RunMessageBox(_("Add Layer"),
475                                     _("Can't open the file '%s'.") % filename)                                     _("Can't open the file '%s'.") % filename)
476              else:              else:
477                    layer = Layer(title, store)
478                    map.AddLayer(layer)
479                    if not has_layers:
480                        # if we're adding a layer to an empty map, fit the
481                        # new map to the window
482                        self.canvas.FitMapToWindow()
483            dlg.Destroy()
484    
485        def AddRasterLayer(self):
486            dlg = wxFileDialog(self, _("Select an image file"), ".", "", "*.*",
487                               wxOPEN)
488            if dlg.ShowModal() == wxID_OK:
489                filename = dlg.GetPath()
490                title = os.path.splitext(os.path.basename(filename))[0]
491                map = self.canvas.Map()
492                has_layers = map.HasLayers()
493                try:
494                    layer = RasterLayer(title, filename)
495                except IOError:
496                    # the layer couldn't be opened
497                    self.RunMessageBox(_("Add Image Layer"),
498                                       _("Can't open the file '%s'.") % filename)
499                else:
500                    map.AddLayer(layer)
501                  if not has_layers:                  if not has_layers:
502                      # if we're adding a layer to an empty map, fit the                      # if we're adding a layer to an empty map, fit the
503                      # new map to the window                      # new map to the window
# Line 499  class MainWindow(DockFrame): Line 543  class MainWindow(DockFrame):
543          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
544          return self.canvas.HasSelectedLayer()          return self.canvas.HasSelectedLayer()
545    
546      def choose_color(self):      def has_selected_shapes(self):
547          """Run the color selection dialog and return the selected color.          """Return true if a shape is currently selected"""
548            return self.canvas.HasSelectedShapes()
         If the user cancels, return None.  
         """  
         dlg = wxColourDialog(self)  
         color = None  
         if dlg.ShowModal() == wxID_OK:  
             data = dlg.GetColourData()  
             wxc = data.GetColour()  
             color = Color(wxc.Red() / 255.0,  
                           wxc.Green() / 255.0,  
                           wxc.Blue() / 255.0)  
         dlg.Destroy()  
         return color  
549    
550      def HideLayer(self):      def HideLayer(self):
551          layer = self.current_layer()          layer = self.current_layer()
552          if layer is not None:          if layer is not None:
553              layer.SetVisible(0)              layer.SetVisible(0)
554            
555      def ShowLayer(self):      def ShowLayer(self):
556          layer = self.current_layer()          layer = self.current_layer()
557          if layer is not None:          if layer is not None:
558              layer.SetVisible(1)              layer.SetVisible(1)
559    
560        def DuplicateLayer(self):
561            """Ceate a new layer above the selected layer with the same shapestore
562            """
563            layer = self.current_layer()
564            if layer is not None and hasattr(layer, "ShapeStore"):
565                new_layer = Layer(_("Copy of `%s'") % layer.Title(),
566                                  layer.ShapeStore(),
567                                  projection = layer.GetProjection())
568                new_classification = copy.deepcopy(layer.GetClassification())
569                new_layer.SetClassification(new_classification)
570                self.Map().AddLayer(new_layer)
571    
572        def CanDuplicateLayer(self):
573            """Return whether the DuplicateLayer method can create a duplicate"""
574            layer = self.current_layer()
575            return layer is not None and hasattr(layer, "ShapeStore")
576    
577      def LayerShowTable(self):      def LayerShowTable(self):
578          layer = self.current_layer()          layer = self.current_layer()
579          if layer is not None:          if layer is not None:
580              table = layer.table              table = layer.ShapeStore().Table()
581              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
582              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
583              if dialog is None:              if dialog is None:
584                  dialog = tableview.LayerTableFrame(self, name,                  dialog = tableview.LayerTableFrame(self, name,
585                                                 _("Table: %s") % layer.Title(),                                           _("Layer Table: %s") % layer.Title(),
586                                                     layer, table)                                           layer, table)
587                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
588                  dialog.Show(true)                  dialog.Show(True)
589              else:              else:
590                  # FIXME: bring dialog to front here                  # FIXME: bring dialog to front here
591                  pass                  pass
592    
593      def Projection(self):      def MapProjection(self):
594    
595          name = "projection"          name = "map_projection"
596          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
597    
598          if dialog is None:          if dialog is None:
599              map = self.canvas.Map()              map = self.canvas.Map()
600              dialog = projdialog.ProjFrame(self, name, map)              dialog = projdialog.ProjFrame(self, name,
601                         _("Map Projection: %s") % map.Title(), map)
602                self.add_dialog(name, dialog)
603                dialog.Show()
604            dialog.Raise()
605    
606        def LayerProjection(self):
607    
608            layer = self.current_layer()
609    
610            name = "layer_projection" + str(id(layer))
611            dialog = self.get_open_dialog(name)
612    
613            if dialog is None:
614                map = self.canvas.Map()
615                dialog = projdialog.ProjFrame(self, name,
616                         _("Layer Projection: %s") % layer.Title(), layer)
617              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
618              dialog.Show()              dialog.Show()
619          dialog.Raise()          dialog.Raise()
# Line 569  class MainWindow(DockFrame): Line 634  class MainWindow(DockFrame):
634          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
635    
636          if dialog is None:          if dialog is None:
637              dialog = Classifier(self, name, layer, group)              dialog = Classifier(self, name, self.Map(), layer, group)
638              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
639              dialog.Show()              dialog.Show()
640          dialog.Raise()          dialog.Raise()
641    
642        def LayerJoinTable(self):
643            layer = self.canvas.SelectedLayer()
644            if layer is not None:
645                dlg = JoinDialog(self, _("Join Layer with Table"),
646                                 self.application.session,
647                                 layer = layer)
648                dlg.ShowModal()
649    
650        def LayerUnjoinTable(self):
651            layer = self.canvas.SelectedLayer()
652            if layer is not None:
653                orig_store = layer.ShapeStore().OrigShapeStore()
654                if orig_store:
655                    layer.SetShapeStore(orig_store)
656    
657      def ShowLegend(self):      def ShowLegend(self):
658          if not self.LegendShown():          if not self.LegendShown():
# Line 593  class MainWindow(DockFrame): Line 672  class MainWindow(DockFrame):
672          else:          else:
673              dialog.Show(not dialog.IsShown())              dialog.Show(not dialog.IsShown())
674    
675            self.canvas.FitMapToWindow()
676    
677      def LegendShown(self):      def LegendShown(self):
678          """Return true iff the legend is currently open"""          """Return true iff the legend is currently open"""
679          dialog = self.FindRegisteredDock("legend")          dialog = self.FindRegisteredDock("legend")
680          return dialog is not None and dialog.IsShown()          return dialog is not None and dialog.IsShown()
681    
682        def TableOpen(self):
683            dlg = wxFileDialog(self, _("Open Table"), ".", "",
684                               _("DBF Files (*.dbf)") + "|*.dbf|" +
685                               #_("CSV Files (*.csv)") + "|*.csv|" +
686                               _("All Files (*.*)") + "|*.*",
687                               wxOPEN)
688            if dlg.ShowModal() == wxID_OK:
689                filename = dlg.GetPath()
690                dlg.Destroy()
691                try:
692                    table = self.application.session.OpenTableFile(filename)
693                except IOError:
694                    # the layer couldn't be opened
695                    self.RunMessageBox(_("Open Table"),
696                                       _("Can't open the file '%s'.") % filename)
697                else:
698                    self.ShowTableView(table)
699    
700        def TableClose(self):
701            tables = self.application.session.UnreferencedTables()
702    
703            lst = [(t.Title(), t) for t in tables]
704            lst.sort()
705            titles = [i[0] for i in lst]
706            dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"),
707                                         _("Close Table"), titles,
708                                         size = (400, 300),
709                                         style = wxDEFAULT_DIALOG_STYLE |
710                                                 wxRESIZE_BORDER)
711            if dlg.ShowModal() == wxID_OK:
712                for i in dlg.GetValue():
713                    self.application.session.RemoveTable(lst[i][1])
714    
715    
716        def TableShow(self):
717            """Offer a multi-selection dialog for tables to be displayed
718    
719            The windows for the selected tables are opened or brought to
720            the front.
721            """
722            tables = self.application.session.Tables()
723    
724            lst = [(t.Title(), t) for t in tables]
725            lst.sort()
726            titles = [i[0] for i in lst]
727            dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"),
728                                         _("Show Table"), titles,
729                                         size = (400,300),
730                                         style = wxDEFAULT_DIALOG_STYLE |
731                                                 wxRESIZE_BORDER)
732            if (dlg.ShowModal() == wxID_OK):
733                for i in dlg.GetValue():
734                    # XXX: if the table belongs to a layer, open a
735                    # LayerTableFrame instead of QueryTableFrame
736                    self.ShowTableView(lst[i][1])
737    
738        def TableJoin(self):
739            dlg = JoinDialog(self, _("Join Tables"), self.application.session)
740            dlg.ShowModal()
741    
742        def ShowTableView(self, table):
743            """Open a table view for the table and optionally"""
744            name = "table_view%d" % id(table)
745            dialog = self.get_open_dialog(name)
746            if dialog is None:
747                dialog = tableview.QueryTableFrame(self, name,
748                                                   _("Table: %s") % table.Title(),
749                                                   table)
750                self.add_dialog(name, dialog)
751                dialog.Show(True)
752            # FIXME: else bring dialog to front
753    
754        def TableRename(self):
755            """Let the user rename a table"""
756    
757            # First, let the user select a table
758            tables = self.application.session.Tables()
759            lst = [(t.Title(), t) for t in tables]
760            lst.sort()
761            titles = [i[0] for i in lst]
762            dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"),
763                                         _("Rename Table"), titles,
764                                         size = (400,300),
765                                         style = wxDEFAULT_DIALOG_STYLE |
766                                                 wxRESIZE_BORDER)
767            if (dlg.ShowModal() == wxID_OK):
768                to_rename = [lst[i][1] for i in dlg.GetValue()]
769                dlg.Destroy()
770            else:
771                to_rename = []
772    
773            # Second, let the user rename the layers
774            for table in to_rename:
775                dlg = wxTextEntryDialog(self, "Table Title: ", "Rename Table",
776                                        table.Title())
777                try:
778                    if dlg.ShowModal() == wxID_OK:
779                        title = dlg.GetValue()
780                        if title != "":
781                            table.SetTitle(title)
782    
783                            # Make sure the session is marked as modified.
784                            # FIXME: This should be handled automatically,
785                            # but that requires more changes to the tables
786                            # than I have time for currently.
787                            self.application.session.changed()
788                finally:
789                    dlg.Destroy()
790    
791    
792      def ZoomInTool(self):      def ZoomInTool(self):
793          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
794    
# Line 617  class MainWindow(DockFrame): Line 808  class MainWindow(DockFrame):
808      def FullExtent(self):      def FullExtent(self):
809          self.canvas.FitMapToWindow()          self.canvas.FitMapToWindow()
810    
811        def FullLayerExtent(self):
812            self.canvas.FitLayerToWindow(self.current_layer())
813    
814        def FullSelectionExtent(self):
815            self.canvas.FitSelectedToWindow()
816    
817        def ExportMap(self):
818            self.canvas.Export()
819    
820      def PrintMap(self):      def PrintMap(self):
821          self.canvas.Print()          self.canvas.Print()
822    
# Line 631  class MainWindow(DockFrame): Line 831  class MainWindow(DockFrame):
831    
832          dlg.Destroy()          dlg.Destroy()
833    
834        def RenameLayer(self):
835            """Let the user rename the currently selected layer"""
836            layer = self.current_layer()
837            if layer is not None:
838                dlg = wxTextEntryDialog(self, "Layer Title: ", "Rename Layer",
839                                        layer.Title())
840                try:
841                    if dlg.ShowModal() == wxID_OK:
842                        title = dlg.GetValue()
843                        if title != "":
844                            layer.SetTitle(title)
845                finally:
846                    dlg.Destroy()
847    
848      def identify_view_on_demand(self, layer, shapes):      def identify_view_on_demand(self, layer, shapes):
849            """Subscribed to the canvas' SHAPES_SELECTED message
850    
851            If the current tool is the identify tool, at least one shape is
852            selected and the identify dialog is not shown, show the dialog.
853            """
854            # If the selection has become empty we don't need to do
855            # anything. Otherwise it could happen that the dialog was popped
856            # up when the selection became empty, e.g. when a new selection
857            # is opened while the identify tool is active and dialog had
858            # been closed
859            if not shapes:
860                return
861    
862          name = "identify_view"          name = "identify_view"
863          if self.canvas.CurrentTool() == "IdentifyTool":          if self.canvas.CurrentTool() == "IdentifyTool":
864              if not self.dialog_open(name):              if not self.dialog_open(name):
# Line 685  def _has_selected_layer(context): Line 912  def _has_selected_layer(context):
912      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
913      return context.mainwindow.has_selected_layer()      return context.mainwindow.has_selected_layer()
914    
915    def _has_selected_shapes(context):
916        """Return true if a layer is selected in the context"""
917        return context.mainwindow.has_selected_shapes()
918    
919  def _can_remove_layer(context):  def _can_remove_layer(context):
920      return context.mainwindow.CanRemoveLayer()      return context.mainwindow.CanRemoveLayer()
921    
# Line 707  def _has_legend_shown(context): Line 938  def _has_legend_shown(context):
938      """Return true if the legend window is shown"""      """Return true if the legend window is shown"""
939      return context.mainwindow.LegendShown()      return context.mainwindow.LegendShown()
940    
941    def _has_gdal_support(context):
942        """Return True if the GDAL is available"""
943        return Thuban.Model.resource.has_gdal_support()
944    
945  # File menu  # File menu
946  _method_command("new_session", _("&New Session"), "NewSession")  _method_command("new_session", _("&New Session"), "NewSession",
947  _method_command("open_session", _("&Open Session"), "OpenSession")                  helptext = _("Start a new session"))
948  _method_command("save_session", _("&Save Session"), "SaveSession")  _method_command("open_session", _("&Open Session..."), "OpenSession",
949  _method_command("save_session_as", _("Save Session &As"), "SaveSessionAs")                  helptext = _("Open a session file"))
950    _method_command("save_session", _("&Save Session"), "SaveSession",
951                    helptext =_("Save this session to the file it was opened from"))
952    _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs",
953                    helptext = _("Save this session to a new file"))
954  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
955                  checked = _has_tree_window_shown)                  checked = _has_tree_window_shown,
956                    helptext = _("Toggle on/off the session tree analysis window"))
957  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
958                  checked = _has_legend_shown)                  checked = _has_legend_shown,
959  _method_command("exit", _("E&xit"), "Exit")                  helptext = _("Toggle Legend on/off"))
960    _method_command("exit", _("E&xit"), "Exit",
961                    helptext = _("Finish working with Thuban"))
962    
963  # Help menu  # Help menu
964  _method_command("help_about", _("&About"), "About")  _method_command("help_about", _("&About..."), "About",
965                    helptext = _("Info about Thuban authors, version and modules"))
966    
967    
968  # Map menu  # Map menu
969  _method_command("map_projection", _("Pro&jection"), "Projection")  _method_command("map_projection", _("Pro&jection..."), "MapProjection",
970                    helptext = _("Set or change the map projection"))
971    
972  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
973                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
# Line 743  _tool_command("map_label_tool", _("&Labe Line 986  _tool_command("map_label_tool", _("&Labe
986                helptext = _("Add/Remove labels"), icon = "label",                helptext = _("Add/Remove labels"), icon = "label",
987                sensitive = _has_visible_map)                sensitive = _has_visible_map)
988  _method_command("map_full_extent", _("&Full extent"), "FullExtent",  _method_command("map_full_extent", _("&Full extent"), "FullExtent",
989                 helptext = _("Full Extent"), icon = "fullextent",                 helptext = _("Zoom to the full map extent"), icon = "fullextent",
990                sensitive = _has_visible_map)                sensitive = _has_visible_map)
991    _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",
992                    helptext = _("Zoom to the full layer extent"),
993                    icon = "fulllayerextent", sensitive = _has_selected_layer)
994    _method_command("selected_full_extent", _("&Full selection extent"),
995                    "FullSelectionExtent",
996                    helptext = _("Zoom to the full selection extent"),
997                    icon = "fullselextent", sensitive = _has_selected_shapes)
998    _method_command("map_export", _("E&xport"), "ExportMap",
999                    helptext = _("Export the map to file"))
1000  _method_command("map_print", _("Prin&t"), "PrintMap",  _method_command("map_print", _("Prin&t"), "PrintMap",
1001                  helptext = _("Print the map"))                  helptext = _("Print the map"))
1002  _method_command("map_rename", _("&Rename"), "RenameMap",  _method_command("map_rename", _("&Rename..."), "RenameMap",
1003                  helptext = _("Rename the map"))                  helptext = _("Rename the map"))
1004    _method_command("layer_add", _("&Add Layer..."), "AddLayer",
1005  # Layer menu                  helptext = _("Add a new layer to the map"))
1006  _method_command("layer_add", _("&Add Layer"), "AddLayer",  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
1007                  helptext = _("Add a new layer to active map"))                  helptext = _("Add a new image layer to the map"),
1008                    sensitive = _has_gdal_support)
1009  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
1010                  helptext = _("Remove selected layer(s)"),                  helptext = _("Remove selected layer"),
1011                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
1012    
1013    # Layer menu
1014    _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
1015                    sensitive = _has_selected_layer,
1016                    helptext = _("Specify projection for selected layer"))
1017    _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
1018                    helptext = _("Duplicate selected layer"),
1019              sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
1020    _method_command("layer_rename", _("Re&name ..."), "RenameLayer",
1021                    helptext = _("Rename selected layer"),
1022                    sensitive = _has_selected_layer)
1023  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
1024                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer"),
1025                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1026  _method_command("layer_lower", _("&Lower"), "LowerLayer",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
1027                  helptext = _("Lower selected layer(s)"),                  helptext = _("Lower selected layer"),
1028                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1029  _method_command("layer_show", _("&Show"), "ShowLayer",  _method_command("layer_show", _("&Show"), "ShowLayer",
1030                  helptext = _("Make selected layer(s) visible"),                  helptext = _("Make selected layer visible"),
1031                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1032  _method_command("layer_hide", _("&Hide"), "HideLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
1033                  helptext = _("Make selected layer(s) unvisible"),                  helptext = _("Make selected layer unvisible"),
1034                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1035  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
1036                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
1037                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1038  _method_command("layer_properties", _("Properties"), "LayerEditProperties",  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
1039                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1040                    helptext = _("Edit the properties of the selected layer"))
1041    _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1042                    sensitive = _has_selected_layer,
1043                    helptext = _("Join and attach a table to the selected layer"))
1044    
1045  # the menu structure  def _can_unjoin(context):
1046  main_menu = Menu("<main>", "<main>",      """Return whether the Layer/Unjoin command can be executed.
1047                   [Menu("file", _("&File"),  
1048                         ["new_session", "open_session", None,      This is the case if a layer is selected and that layer has a
1049                          "save_session", "save_session_as", None,      shapestore that has an original shapestore.
1050                          "toggle_session_tree", None,      """
1051                          "exit"]),      layer = context.mainwindow.SelectedLayer()
1052                    Menu("map", _("&Map"),      if layer is None:
1053                         ["layer_add", "layer_remove",          return 0
1054        getstore = getattr(layer, "ShapeStore", None)
1055        if getstore is not None:
1056            return getstore().OrigShapeStore() is not None
1057        else:
1058            return 0
1059    _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
1060                    sensitive = _can_unjoin,
1061                    helptext = _("Undo the last join operation"))
1062    
1063    
1064    def _has_tables(context):
1065        return bool(context.session.Tables())
1066    
1067    # Table menu
1068    _method_command("table_open", _("&Open..."), "TableOpen",
1069                    helptext = _("Open a DBF-table from a file"))
1070    _method_command("table_close", _("&Close..."), "TableClose",
1071           sensitive = lambda context: bool(context.session.UnreferencedTables()),
1072                    helptext = _("Close one or more tables from a list"))
1073    _method_command("table_rename", _("&Rename..."), "TableRename",
1074                    sensitive = _has_tables,
1075                    helptext = _("Rename one or more tables"))
1076    _method_command("table_show", _("&Show..."), "TableShow",
1077                    sensitive = _has_tables,
1078                    helptext = _("Show one or more tables in a dialog"))
1079    _method_command("table_join", _("&Join..."), "TableJoin",
1080                    sensitive = _has_tables,
1081                    helptext = _("Join two tables creating a new one"))
1082    
1083    #  Export only under Windows ...
1084    map_menu = ["layer_add", "rasterlayer_add", "layer_remove",
1085                          None,                          None,
1086                            "map_rename",
1087                          "map_projection",                          "map_projection",
1088                          None,                          None,
1089                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
1090                          "map_pan_tool", "map_identify_tool", "map_label_tool",                          "map_pan_tool",
1091                            "map_full_extent",
1092                            "layer_full_extent",
1093                            "selected_full_extent",
1094                          None,                          None,
1095                          "map_full_extent",                          "map_identify_tool", "map_label_tool",
1096                          None,                          None,
1097                          "toggle_legend",                          "toggle_legend",
1098                          None,                          None]
1099                          "map_print",  if wxPlatform == '__WXMSW__':
1100                          None,      map_menu.append("map_export")
1101                          "map_rename"]),  map_menu.append("map_print")
1102    
1103    # the menu structure
1104    main_menu = Menu("<main>", "<main>",
1105                     [Menu("file", _("&File"),
1106                           ["new_session", "open_session", None,
1107                            "save_session", "save_session_as", None,
1108                            "toggle_session_tree", None,
1109                            "exit"]),
1110                      Menu("map", _("&Map"), map_menu),
1111                    Menu("layer", _("&Layer"),                    Menu("layer", _("&Layer"),
1112                          ["layer_raise", "layer_lower",                         ["layer_rename", "layer_duplicate",
1113                            None,
1114                            "layer_raise", "layer_lower",
1115                          None,                          None,
1116                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
1117                          None,                          None,
1118                            "layer_projection",
1119                            None,
1120                          "layer_show_table",                          "layer_show_table",
1121                            "layer_jointable",
1122                            "layer_unjointable",
1123                          None,                          None,
1124                          "layer_properties"]),                          "layer_properties"]),
1125                      Menu("table", _("&Table"),
1126                           ["table_open", "table_close", "table_rename",
1127                           None,
1128                           "table_show",
1129                           None,
1130                           "table_join"]),
1131                    Menu("help", _("&Help"),                    Menu("help", _("&Help"),
1132                         ["help_about"])])                         ["help_about"])])
1133    
# Line 811  main_menu = Menu("<main>", "<main>", Line 1135  main_menu = Menu("<main>", "<main>",
1135    
1136  main_toolbar = Menu("<toolbar>", "<toolbar>",  main_toolbar = Menu("<toolbar>", "<toolbar>",
1137                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",
1138                       "map_full_extent", None,                       "map_full_extent",
1139                         "layer_full_extent",
1140                         "selected_full_extent",
1141                         None,
1142                       "map_identify_tool", "map_label_tool"])                       "map_identify_tool", "map_label_tool"])

Legend:
Removed from v.713  
changed lines
  Added in v.1219

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26