/[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 1309 by jonathan, Thu Jun 26 17:00:44 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 12  The main window Line 13  The main window
13    
14  __version__ = "$Revision$"  __version__ = "$Revision$"
15    
16  __ThubanVersion__ = "0.2" #"$THUBAN_0_2$"  __ThubanVersion__ = "0.8" #"$THUBAN_0_2$"
17  #__BuildDate__ = "$Date$"  #__BuildDate__ = "$Date$"
18    
19  import os  import os
20    import copy
21    
22  from wxPython.wx import *  from wxPython.wx import *
23    from wxPython.wx import __version__ as wxPython_version
24    
25  import Thuban  import Thuban
26    import Thuban.version
27    
28  from Thuban import _  from Thuban import _
29  from Thuban.Model.session import create_empty_session  from Thuban.Model.session import create_empty_session
30  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer, RasterLayer
31  from Thuban.Model.color import Color  
32  from Thuban.Model.proj import Projection  # XXX: replace this by
33    # from wxPython.lib.dialogs import wxMultipleChoiceDialog
34    # when Thuban does not support wxPython 2.4.0 any more.
35    from Thuban.UI.multiplechoicedialog import wxMultipleChoiceDialog
36    
37  import view  import view
38  import tree  import tree
 import proj4dialog  
39  import tableview, identifyview  import tableview, identifyview
40  from Thuban.UI.classifier import Classifier  from Thuban.UI.classifier import Classifier
41  import legend  import legend
# Line 37  from menu import Menu Line 44  from menu import Menu
44  from context import Context  from context import Context
45  from command import registry, Command, ToolCommand  from command import registry, Command, ToolCommand
46  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION
47    from about import About
48    
49  from Thuban.UI.dock import DockFrame  from Thuban.UI.dock import DockFrame
50    from Thuban.UI.join import JoinDialog
51    
52  import resource  import resource
53    import Thuban.Model.resource
54    
55  import projdialog  import projdialog
56    
57    
   
58  class MainWindow(DockFrame):  class MainWindow(DockFrame):
59    
60      # Some messages that can be subscribed/unsubscribed directly through      # Some messages that can be subscribed/unsubscribed directly through
# Line 60  class MainWindow(DockFrame): Line 69  class MainWindow(DockFrame):
69      # implemented in the __getattr__ method.      # implemented in the __getattr__ method.
70      delegated_methods = {"SelectLayer": "canvas",      delegated_methods = {"SelectLayer": "canvas",
71                           "SelectShapes": "canvas",                           "SelectShapes": "canvas",
72                             "SelectedLayer": "canvas",
73                             "SelectedShapes": "canvas",
74                           }                           }
75    
76      def __init__(self, parent, ID, title, application, interactor,      def __init__(self, parent, ID, title, application, interactor,
# Line 98  class MainWindow(DockFrame): Line 109  class MainWindow(DockFrame):
109    
110          self.init_dialogs()          self.init_dialogs()
111    
112          EVT_CLOSE(self, self._OnClose)          self.ShowLegend()
113    
114            EVT_CLOSE(self, self.OnClose)
115    
116      def Subscribe(self, channel, *args):      def Subscribe(self, channel, *args):
117          """Subscribe a function to a message channel.          """Subscribe a function to a message channel.
# Line 357  class MainWindow(DockFrame): Line 370  class MainWindow(DockFrame):
370                  d.Close()                  d.Close()
371    
372      def NewSession(self):      def NewSession(self):
373          self.save_modified_session()          if self.save_modified_session() != wxID_CANCEL:
374          self.prepare_new_session()              self.prepare_new_session()
375          self.application.SetSession(create_empty_session())              self.application.SetSession(create_empty_session())
376    
377      def OpenSession(self):      def OpenSession(self):
378          self.save_modified_session()          if self.save_modified_session() != wxID_CANCEL:
379          dlg = wxFileDialog(self, _("Open Session"), ".", "", "*.thuban", wxOPEN)              dlg = wxFileDialog(self, _("Open Session"), ".", "",
380          if dlg.ShowModal() == wxID_OK:                                 "Thuban Session File (*.thuban)|*.thuban",
381              self.prepare_new_session()                                 wxOPEN)
382              self.application.OpenSession(dlg.GetPath())              if dlg.ShowModal() == wxID_OK:
383          dlg.Destroy()                  self.prepare_new_session()
384                    self.application.OpenSession(dlg.GetPath())
385                dlg.Destroy()
386    
387      def SaveSession(self):      def SaveSession(self):
388          if self.application.session.filename == None:          if self.application.session.filename == None:
# Line 377  class MainWindow(DockFrame): Line 392  class MainWindow(DockFrame):
392    
393      def SaveSessionAs(self):      def SaveSessionAs(self):
394          dlg = wxFileDialog(self, _("Save Session As"), ".", "",          dlg = wxFileDialog(self, _("Save Session As"), ".", "",
395                             "*.thuban", wxOPEN)                             "Thuban Session File (*.thuban)|*.thuban",
396                               wxSAVE|wxOVERWRITE_PROMPT)
397          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
398              self.application.session.SetFilename(dlg.GetPath())              self.application.session.SetFilename(dlg.GetPath())
399              self.application.SaveSession()              self.application.SaveSession()
# Line 386  class MainWindow(DockFrame): Line 402  class MainWindow(DockFrame):
402      def Exit(self):      def Exit(self):
403          self.Close(False)          self.Close(False)
404    
405      def _OnClose(self, event):      def OnClose(self, event):
406          result = self.save_modified_session(can_veto = event.CanVeto())          result = self.save_modified_session(can_veto = event.CanVeto())
407          if result == wxID_CANCEL:          if result == wxID_CANCEL:
408              event.Veto()              event.Veto()
# Line 395  class MainWindow(DockFrame): Line 411  class MainWindow(DockFrame):
411              # wx's destroy event, but that isn't implemented for wxGTK              # wx's destroy event, but that isn't implemented for wxGTK
412              # yet.              # yet.
413              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)
414              DockFrame._OnClose(self, event)              DockFrame.OnClose(self, event)
415                for dlg in self.dialogs.values():
416                    dlg.Destroy()
417                self.canvas.Destroy()
418              self.Destroy()              self.Destroy()
419    
420      def SetMap(self, map):      def SetMap(self, map):
421          self.canvas.SetMap(map)          self.canvas.SetMap(map)
422          self.__SetTitle(map.Title())          self.__SetTitle(map.Title())
423          #self.legendPanel.SetMap(map)  
424            dialog = self.FindRegisteredDock("legend")
425            if dialog is not None:
426                dialog.GetPanel().SetMap(self.Map())
427    
428      def Map(self):      def Map(self):
429          """Return the map displayed by this mainwindow"""          """Return the map displayed by this mainwindow"""
430    
         # sanity check  
         #assert(self.canvas.Map() is self.legendPanel.GetMap())  
   
431          return self.canvas.Map()          return self.canvas.Map()
432    
433      def ToggleSessionTree(self):      def ToggleSessionTree(self):
# Line 427  class MainWindow(DockFrame): Line 446  class MainWindow(DockFrame):
446          return self.get_open_dialog("session_tree") is not None          return self.get_open_dialog("session_tree") is not None
447    
448      def About(self):      def About(self):
449          self.RunMessageBox(_("About"),          dlg = About(self)
450                             _("Thuban v%s\n"          dlg.ShowModal()
451                              #"Build Date: %s\n"          dlg.Destroy()
                             "\n"  
                             "Thuban is a program for\n"  
                             "exploring geographic data.\n"  
                             "Copyright (C) 2001-2003 Intevation GmbH.\n"  
                             "Thuban is licensed under the GNU GPL"  
                            % __ThubanVersion__), #__BuildDate__)),  
                            wxOK | wxICON_INFORMATION)  
452    
453      def AddLayer(self):      def AddLayer(self):
454          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",
# Line 444  class MainWindow(DockFrame): Line 456  class MainWindow(DockFrame):
456          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
457              filename = dlg.GetPath()              filename = dlg.GetPath()
458              title = os.path.splitext(os.path.basename(filename))[0]              title = os.path.splitext(os.path.basename(filename))[0]
             layer = Layer(title, filename)  
459              map = self.canvas.Map()              map = self.canvas.Map()
460              has_layers = map.HasLayers()              has_layers = map.HasLayers()
461              try:              try:
462                  map.AddLayer(layer)                  store = self.application.Session().OpenShapefile(filename)
463              except IOError:              except IOError:
464                  # the layer couldn't be opened                  # the layer couldn't be opened
465                  self.RunMessageBox(_("Add Layer"),                  self.RunMessageBox(_("Add Layer"),
466                                     _("Can't open the file '%s'.") % filename)                                     _("Can't open the file '%s'.") % filename)
467              else:              else:
468                    layer = Layer(title, store)
469                    map.AddLayer(layer)
470                    if not has_layers:
471                        # if we're adding a layer to an empty map, fit the
472                        # new map to the window
473                        self.canvas.FitMapToWindow()
474            dlg.Destroy()
475    
476        def AddRasterLayer(self):
477            dlg = wxFileDialog(self, _("Select an image file"), ".", "", "*.*",
478                               wxOPEN)
479            if dlg.ShowModal() == wxID_OK:
480                filename = dlg.GetPath()
481                title = os.path.splitext(os.path.basename(filename))[0]
482                map = self.canvas.Map()
483                has_layers = map.HasLayers()
484                try:
485                    layer = RasterLayer(title, filename)
486                except IOError:
487                    # the layer couldn't be opened
488                    self.RunMessageBox(_("Add Image Layer"),
489                                       _("Can't open the file '%s'.") % filename)
490                else:
491                    map.AddLayer(layer)
492                  if not has_layers:                  if not has_layers:
493                      # if we're adding a layer to an empty map, fit the                      # if we're adding a layer to an empty map, fit the
494                      # new map to the window                      # new map to the window
# Line 499  class MainWindow(DockFrame): Line 534  class MainWindow(DockFrame):
534          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
535          return self.canvas.HasSelectedLayer()          return self.canvas.HasSelectedLayer()
536    
537      def choose_color(self):      def has_selected_shapes(self):
538          """Run the color selection dialog and return the selected color.          """Return true if a shape is currently selected"""
539            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  
540    
541      def HideLayer(self):      def HideLayer(self):
542          layer = self.current_layer()          layer = self.current_layer()
543          if layer is not None:          if layer is not None:
544              layer.SetVisible(0)              layer.SetVisible(0)
545            
546      def ShowLayer(self):      def ShowLayer(self):
547          layer = self.current_layer()          layer = self.current_layer()
548          if layer is not None:          if layer is not None:
549              layer.SetVisible(1)              layer.SetVisible(1)
550    
551        def DuplicateLayer(self):
552            """Ceate a new layer above the selected layer with the same shapestore
553            """
554            layer = self.current_layer()
555            if layer is not None and hasattr(layer, "ShapeStore"):
556                new_layer = Layer(_("Copy of `%s'") % layer.Title(),
557                                  layer.ShapeStore(),
558                                  projection = layer.GetProjection())
559                new_classification = copy.deepcopy(layer.GetClassification())
560                new_layer.SetClassification(new_classification)
561                self.Map().AddLayer(new_layer)
562    
563        def CanDuplicateLayer(self):
564            """Return whether the DuplicateLayer method can create a duplicate"""
565            layer = self.current_layer()
566            return layer is not None and hasattr(layer, "ShapeStore")
567    
568      def LayerShowTable(self):      def LayerShowTable(self):
569          layer = self.current_layer()          layer = self.current_layer()
570          if layer is not None:          if layer is not None:
571              table = layer.table              table = layer.ShapeStore().Table()
572              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
573              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
574              if dialog is None:              if dialog is None:
575                  dialog = tableview.LayerTableFrame(self, name,                  dialog = tableview.LayerTableFrame(self, name,
576                                                 _("Table: %s") % layer.Title(),                                           _("Layer Table: %s") % layer.Title(),
577                                                     layer, table)                                           layer, table)
578                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
579                  dialog.Show(true)                  dialog.Show(True)
580              else:              else:
581                  # FIXME: bring dialog to front here                  # FIXME: bring dialog to front here
582                  pass                  pass
583    
584      def Projection(self):      def MapProjection(self):
585    
586            name = "map_projection"
587            dialog = self.get_open_dialog(name)
588    
589            if dialog is None:
590                map = self.canvas.Map()
591                dialog = projdialog.ProjFrame(self, name,
592                         _("Map Projection: %s") % map.Title(), map)
593                self.add_dialog(name, dialog)
594                dialog.Show()
595            dialog.Raise()
596    
597        def LayerProjection(self):
598    
599          name = "projection"          layer = self.current_layer()
600    
601            name = "layer_projection" + str(id(layer))
602          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
603    
604          if dialog is None:          if dialog is None:
605              map = self.canvas.Map()              map = self.canvas.Map()
606              dialog = projdialog.ProjFrame(self, name, map)              dialog = projdialog.ProjFrame(self, name,
607                         _("Layer Projection: %s") % layer.Title(), layer)
608              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
609              dialog.Show()              dialog.Show()
610          dialog.Raise()          dialog.Raise()
# Line 569  class MainWindow(DockFrame): Line 625  class MainWindow(DockFrame):
625          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
626    
627          if dialog is None:          if dialog is None:
628              dialog = Classifier(self, name, layer, group)              dialog = Classifier(self, name, self.Map(), layer, group)
629              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
630              dialog.Show()              dialog.Show()
631          dialog.Raise()          dialog.Raise()
632    
633        def LayerJoinTable(self):
634            layer = self.canvas.SelectedLayer()
635            if layer is not None:
636                dlg = JoinDialog(self, _("Join Layer with Table"),
637                                 self.application.session,
638                                 layer = layer)
639                dlg.ShowModal()
640    
641        def LayerUnjoinTable(self):
642            layer = self.canvas.SelectedLayer()
643            if layer is not None:
644                orig_store = layer.ShapeStore().OrigShapeStore()
645                if orig_store:
646                    layer.SetShapeStore(orig_store)
647    
648      def ShowLegend(self):      def ShowLegend(self):
649          if not self.LegendShown():          if not self.LegendShown():
# Line 593  class MainWindow(DockFrame): Line 663  class MainWindow(DockFrame):
663          else:          else:
664              dialog.Show(not dialog.IsShown())              dialog.Show(not dialog.IsShown())
665    
666            self.canvas.FitMapToWindow()
667    
668      def LegendShown(self):      def LegendShown(self):
669          """Return true iff the legend is currently open"""          """Return true iff the legend is currently open"""
670          dialog = self.FindRegisteredDock("legend")          dialog = self.FindRegisteredDock("legend")
671          return dialog is not None and dialog.IsShown()          return dialog is not None and dialog.IsShown()
672    
673        def TableOpen(self):
674            dlg = wxFileDialog(self, _("Open Table"), ".", "",
675                               _("DBF Files (*.dbf)") + "|*.dbf|" +
676                               #_("CSV Files (*.csv)") + "|*.csv|" +
677                               _("All Files (*.*)") + "|*.*",
678                               wxOPEN)
679            if dlg.ShowModal() == wxID_OK:
680                filename = dlg.GetPath()
681                dlg.Destroy()
682                try:
683                    table = self.application.session.OpenTableFile(filename)
684                except IOError:
685                    # the layer couldn't be opened
686                    self.RunMessageBox(_("Open Table"),
687                                       _("Can't open the file '%s'.") % filename)
688                else:
689                    self.ShowTableView(table)
690    
691        def TableClose(self):
692            tables = self.application.session.UnreferencedTables()
693    
694            lst = [(t.Title(), t) for t in tables]
695            lst.sort()
696            titles = [i[0] for i in lst]
697            dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"),
698                                         _("Close Table"), titles,
699                                         size = (400, 300),
700                                         style = wxDEFAULT_DIALOG_STYLE |
701                                                 wxRESIZE_BORDER)
702            if dlg.ShowModal() == wxID_OK:
703                for i in dlg.GetValue():
704                    self.application.session.RemoveTable(lst[i][1])
705    
706    
707        def TableShow(self):
708            """Offer a multi-selection dialog for tables to be displayed
709    
710            The windows for the selected tables are opened or brought to
711            the front.
712            """
713            tables = self.application.session.Tables()
714    
715            lst = [(t.Title(), t) for t in tables]
716            lst.sort()
717            titles = [i[0] for i in lst]
718            dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"),
719                                         _("Show Table"), titles,
720                                         size = (400,300),
721                                         style = wxDEFAULT_DIALOG_STYLE |
722                                                 wxRESIZE_BORDER)
723            if (dlg.ShowModal() == wxID_OK):
724                for i in dlg.GetValue():
725                    # XXX: if the table belongs to a layer, open a
726                    # LayerTableFrame instead of QueryTableFrame
727                    self.ShowTableView(lst[i][1])
728    
729        def TableJoin(self):
730            dlg = JoinDialog(self, _("Join Tables"), self.application.session)
731            dlg.ShowModal()
732    
733        def ShowTableView(self, table):
734            """Open a table view for the table and optionally"""
735            name = "table_view%d" % id(table)
736            dialog = self.get_open_dialog(name)
737            if dialog is None:
738                dialog = tableview.QueryTableFrame(self, name,
739                                                   _("Table: %s") % table.Title(),
740                                                   table)
741                self.add_dialog(name, dialog)
742                dialog.Show(True)
743            # FIXME: else bring dialog to front
744    
745        def TableRename(self):
746            """Let the user rename a table"""
747    
748            # First, let the user select a table
749            tables = self.application.session.Tables()
750            lst = [(t.Title(), t) for t in tables]
751            lst.sort()
752            titles = [i[0] for i in lst]
753            dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"),
754                                         _("Rename Table"), titles,
755                                         size = (400,300),
756                                         style = wxDEFAULT_DIALOG_STYLE |
757                                                 wxRESIZE_BORDER)
758            if (dlg.ShowModal() == wxID_OK):
759                to_rename = [lst[i][1] for i in dlg.GetValue()]
760                dlg.Destroy()
761            else:
762                to_rename = []
763    
764            # Second, let the user rename the layers
765            for table in to_rename:
766                dlg = wxTextEntryDialog(self, "Table Title: ", "Rename Table",
767                                        table.Title())
768                try:
769                    if dlg.ShowModal() == wxID_OK:
770                        title = dlg.GetValue()
771                        if title != "":
772                            table.SetTitle(title)
773    
774                            # Make sure the session is marked as modified.
775                            # FIXME: This should be handled automatically,
776                            # but that requires more changes to the tables
777                            # than I have time for currently.
778                            self.application.session.changed()
779                finally:
780                    dlg.Destroy()
781    
782    
783      def ZoomInTool(self):      def ZoomInTool(self):
784          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
785    
# Line 617  class MainWindow(DockFrame): Line 799  class MainWindow(DockFrame):
799      def FullExtent(self):      def FullExtent(self):
800          self.canvas.FitMapToWindow()          self.canvas.FitMapToWindow()
801    
802        def FullLayerExtent(self):
803            self.canvas.FitLayerToWindow(self.current_layer())
804    
805        def FullSelectionExtent(self):
806            self.canvas.FitSelectedToWindow()
807    
808        def ExportMap(self):
809            self.canvas.Export()
810    
811      def PrintMap(self):      def PrintMap(self):
812          self.canvas.Print()          self.canvas.Print()
813    
# Line 631  class MainWindow(DockFrame): Line 822  class MainWindow(DockFrame):
822    
823          dlg.Destroy()          dlg.Destroy()
824    
825        def RenameLayer(self):
826            """Let the user rename the currently selected layer"""
827            layer = self.current_layer()
828            if layer is not None:
829                dlg = wxTextEntryDialog(self, "Layer Title: ", "Rename Layer",
830                                        layer.Title())
831                try:
832                    if dlg.ShowModal() == wxID_OK:
833                        title = dlg.GetValue()
834                        if title != "":
835                            layer.SetTitle(title)
836                finally:
837                    dlg.Destroy()
838    
839      def identify_view_on_demand(self, layer, shapes):      def identify_view_on_demand(self, layer, shapes):
840            """Subscribed to the canvas' SHAPES_SELECTED message
841    
842            If the current tool is the identify tool, at least one shape is
843            selected and the identify dialog is not shown, show the dialog.
844            """
845            # If the selection has become empty we don't need to do
846            # anything. Otherwise it could happen that the dialog was popped
847            # up when the selection became empty, e.g. when a new selection
848            # is opened while the identify tool is active and dialog had
849            # been closed
850            if not shapes:
851                return
852    
853          name = "identify_view"          name = "identify_view"
854          if self.canvas.CurrentTool() == "IdentifyTool":          if self.canvas.CurrentTool() == "IdentifyTool":
855              if not self.dialog_open(name):              if not self.dialog_open(name):
# Line 685  def _has_selected_layer(context): Line 903  def _has_selected_layer(context):
903      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
904      return context.mainwindow.has_selected_layer()      return context.mainwindow.has_selected_layer()
905    
906    def _has_selected_shapes(context):
907        """Return true if a layer is selected in the context"""
908        return context.mainwindow.has_selected_shapes()
909    
910  def _can_remove_layer(context):  def _can_remove_layer(context):
911      return context.mainwindow.CanRemoveLayer()      return context.mainwindow.CanRemoveLayer()
912    
# Line 707  def _has_legend_shown(context): Line 929  def _has_legend_shown(context):
929      """Return true if the legend window is shown"""      """Return true if the legend window is shown"""
930      return context.mainwindow.LegendShown()      return context.mainwindow.LegendShown()
931    
932    def _has_gdal_support(context):
933        """Return True if the GDAL is available"""
934        return Thuban.Model.resource.has_gdal_support()
935    
936  # File menu  # File menu
937  _method_command("new_session", _("&New Session"), "NewSession")  _method_command("new_session", _("&New Session"), "NewSession",
938  _method_command("open_session", _("&Open Session"), "OpenSession")                  helptext = _("Start a new session"))
939  _method_command("save_session", _("&Save Session"), "SaveSession")  _method_command("open_session", _("&Open Session..."), "OpenSession",
940  _method_command("save_session_as", _("Save Session &As"), "SaveSessionAs")                  helptext = _("Open a session file"))
941    _method_command("save_session", _("&Save Session"), "SaveSession",
942                    helptext =_("Save this session to the file it was opened from"))
943    _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs",
944                    helptext = _("Save this session to a new file"))
945  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
946                  checked = _has_tree_window_shown)                  checked = _has_tree_window_shown,
947                    helptext = _("Toggle on/off the session tree analysis window"))
948  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
949                  checked = _has_legend_shown)                  checked = _has_legend_shown,
950  _method_command("exit", _("E&xit"), "Exit")                  helptext = _("Toggle Legend on/off"))
951    _method_command("exit", _("E&xit"), "Exit",
952                    helptext = _("Finish working with Thuban"))
953    
954  # Help menu  # Help menu
955  _method_command("help_about", _("&About"), "About")  _method_command("help_about", _("&About..."), "About",
956                    helptext = _("Info about Thuban authors, version and modules"))
957    
958    
959  # Map menu  # Map menu
960  _method_command("map_projection", _("Pro&jection"), "Projection")  _method_command("map_projection", _("Pro&jection..."), "MapProjection",
961                    helptext = _("Set or change the map projection"))
962    
963  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
964                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 977  _tool_command("map_label_tool", _("&Labe
977                helptext = _("Add/Remove labels"), icon = "label",                helptext = _("Add/Remove labels"), icon = "label",
978                sensitive = _has_visible_map)                sensitive = _has_visible_map)
979  _method_command("map_full_extent", _("&Full extent"), "FullExtent",  _method_command("map_full_extent", _("&Full extent"), "FullExtent",
980                 helptext = _("Full Extent"), icon = "fullextent",                 helptext = _("Zoom to the full map extent"), icon = "fullextent",
981                sensitive = _has_visible_map)                sensitive = _has_visible_map)
982    _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",
983                    helptext = _("Zoom to the full layer extent"),
984                    icon = "fulllayerextent", sensitive = _has_selected_layer)
985    _method_command("selected_full_extent", _("&Full selection extent"),
986                    "FullSelectionExtent",
987                    helptext = _("Zoom to the full selection extent"),
988                    icon = "fullselextent", sensitive = _has_selected_shapes)
989    _method_command("map_export", _("E&xport"), "ExportMap",
990                    helptext = _("Export the map to file"))
991  _method_command("map_print", _("Prin&t"), "PrintMap",  _method_command("map_print", _("Prin&t"), "PrintMap",
992                  helptext = _("Print the map"))                  helptext = _("Print the map"))
993  _method_command("map_rename", _("&Rename"), "RenameMap",  _method_command("map_rename", _("&Rename..."), "RenameMap",
994                  helptext = _("Rename the map"))                  helptext = _("Rename the map"))
995    _method_command("layer_add", _("&Add Layer..."), "AddLayer",
996  # Layer menu                  helptext = _("Add a new layer to the map"))
997  _method_command("layer_add", _("&Add Layer"), "AddLayer",  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
998                  helptext = _("Add a new layer to active map"))                  helptext = _("Add a new image layer to the map"),
999                    sensitive = _has_gdal_support)
1000  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
1001                  helptext = _("Remove selected layer(s)"),                  helptext = _("Remove selected layer"),
1002                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
1003    
1004    # Layer menu
1005    _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
1006                    sensitive = _has_selected_layer,
1007                    helptext = _("Specify projection for selected layer"))
1008    _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
1009                    helptext = _("Duplicate selected layer"),
1010              sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
1011    _method_command("layer_rename", _("Re&name ..."), "RenameLayer",
1012                    helptext = _("Rename selected layer"),
1013                    sensitive = _has_selected_layer)
1014  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
1015                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer"),
1016                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1017  _method_command("layer_lower", _("&Lower"), "LowerLayer",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
1018                  helptext = _("Lower selected layer(s)"),                  helptext = _("Lower selected layer"),
1019                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1020  _method_command("layer_show", _("&Show"), "ShowLayer",  _method_command("layer_show", _("&Show"), "ShowLayer",
1021                  helptext = _("Make selected layer(s) visible"),                  helptext = _("Make selected layer visible"),
1022                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1023  _method_command("layer_hide", _("&Hide"), "HideLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
1024                  helptext = _("Make selected layer(s) unvisible"),                  helptext = _("Make selected layer unvisible"),
1025                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1026  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
1027                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
1028                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1029  _method_command("layer_properties", _("Properties"), "LayerEditProperties",  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
1030                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1031                    helptext = _("Edit the properties of the selected layer"))
1032    _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1033                    sensitive = _has_selected_layer,
1034                    helptext = _("Join and attach a table to the selected layer"))
1035    
1036  # the menu structure  def _can_unjoin(context):
1037  main_menu = Menu("<main>", "<main>",      """Return whether the Layer/Unjoin command can be executed.
1038                   [Menu("file", _("&File"),  
1039                         ["new_session", "open_session", None,      This is the case if a layer is selected and that layer has a
1040                          "save_session", "save_session_as", None,      shapestore that has an original shapestore.
1041                          "toggle_session_tree", None,      """
1042                          "exit"]),      layer = context.mainwindow.SelectedLayer()
1043                    Menu("map", _("&Map"),      if layer is None:
1044                         ["layer_add", "layer_remove",          return 0
1045        getstore = getattr(layer, "ShapeStore", None)
1046        if getstore is not None:
1047            return getstore().OrigShapeStore() is not None
1048        else:
1049            return 0
1050    _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
1051                    sensitive = _can_unjoin,
1052                    helptext = _("Undo the last join operation"))
1053    
1054    
1055    def _has_tables(context):
1056        return bool(context.session.Tables())
1057    
1058    # Table menu
1059    _method_command("table_open", _("&Open..."), "TableOpen",
1060                    helptext = _("Open a DBF-table from a file"))
1061    _method_command("table_close", _("&Close..."), "TableClose",
1062           sensitive = lambda context: bool(context.session.UnreferencedTables()),
1063                    helptext = _("Close one or more tables from a list"))
1064    _method_command("table_rename", _("&Rename..."), "TableRename",
1065                    sensitive = _has_tables,
1066                    helptext = _("Rename one or more tables"))
1067    _method_command("table_show", _("&Show..."), "TableShow",
1068                    sensitive = _has_tables,
1069                    helptext = _("Show one or more tables in a dialog"))
1070    _method_command("table_join", _("&Join..."), "TableJoin",
1071                    sensitive = _has_tables,
1072                    helptext = _("Join two tables creating a new one"))
1073    
1074    #  Export only under Windows ...
1075    map_menu = ["layer_add", "rasterlayer_add", "layer_remove",
1076                          None,                          None,
1077                            "map_rename",
1078                          "map_projection",                          "map_projection",
1079                          None,                          None,
1080                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
1081                          "map_pan_tool", "map_identify_tool", "map_label_tool",                          "map_pan_tool",
1082                            "map_full_extent",
1083                            "layer_full_extent",
1084                            "selected_full_extent",
1085                          None,                          None,
1086                          "map_full_extent",                          "map_identify_tool", "map_label_tool",
1087                          None,                          None,
1088                          "toggle_legend",                          "toggle_legend",
1089                          None,                          None]
1090                          "map_print",  if wxPlatform == '__WXMSW__':
1091                          None,      map_menu.append("map_export")
1092                          "map_rename"]),  map_menu.append("map_print")
1093    
1094    # the menu structure
1095    main_menu = Menu("<main>", "<main>",
1096                     [Menu("file", _("&File"),
1097                           ["new_session", "open_session", None,
1098                            "save_session", "save_session_as", None,
1099                            "toggle_session_tree", None,
1100                            "exit"]),
1101                      Menu("map", _("&Map"), map_menu),
1102                    Menu("layer", _("&Layer"),                    Menu("layer", _("&Layer"),
1103                          ["layer_raise", "layer_lower",                         ["layer_rename", "layer_duplicate",
1104                            None,
1105                            "layer_raise", "layer_lower",
1106                          None,                          None,
1107                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
1108                          None,                          None,
1109                            "layer_projection",
1110                            None,
1111                          "layer_show_table",                          "layer_show_table",
1112                            "layer_jointable",
1113                            "layer_unjointable",
1114                          None,                          None,
1115                          "layer_properties"]),                          "layer_properties"]),
1116                      Menu("table", _("&Table"),
1117                           ["table_open", "table_close", "table_rename",
1118                           None,
1119                           "table_show",
1120                           None,
1121                           "table_join"]),
1122                    Menu("help", _("&Help"),                    Menu("help", _("&Help"),
1123                         ["help_about"])])                         ["help_about"])])
1124    
# Line 811  main_menu = Menu("<main>", "<main>", Line 1126  main_menu = Menu("<main>", "<main>",
1126    
1127  main_toolbar = Menu("<toolbar>", "<toolbar>",  main_toolbar = Menu("<toolbar>", "<toolbar>",
1128                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",
1129                       "map_full_extent", None,                       "map_full_extent",
1130                         "layer_full_extent",
1131                         "selected_full_extent",
1132                         None,
1133                       "map_identify_tool", "map_label_tool"])                       "map_identify_tool", "map_label_tool"])
1134    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26