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

Legend:
Removed from v.616  
changed lines
  Added in v.1155

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26