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

Legend:
Removed from v.624  
changed lines
  Added in v.1142

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26