/[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 1084 by jan, Wed May 28 10:25:09 2003 UTC revision 2365 by joey, Fri Oct 1 18:22:32 2004 UTC
# Line 1  Line 1 
1  # Copyright (C) 2001, 2002, 2003 by Intevation GmbH  # Copyright (C) 2001, 2002, 2003, 2004 by Intevation GmbH
2  # Authors:  # Authors:
3  # Jan-Oliver Wagner <[email protected]>  # Jan-Oliver Wagner <[email protected]>
4  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
# Line 12  The main window Line 12  The main window
12  """  """
13    
14  __version__ = "$Revision$"  __version__ = "$Revision$"
15    # $Source$
16  __ThubanVersion__ = "0.2" #"$THUBAN_0_2$"  # $Id$
 #__BuildDate__ = "$Date$"  
17    
18  import os  import os
19    import copy
20    
21  from wxPython.wx import *  from wxPython.wx import *
 from wxPython.wx import __version__ as wxPython_version  
   
 from wxPython.lib.dialogs import wxMultipleChoiceDialog  
22    
23  import Thuban  import Thuban
 import Thuban.version  
24    
25  from Thuban import _  from Thuban import _
26    from Thuban.Model.messages import TITLE_CHANGED
27  from Thuban.Model.session import create_empty_session  from Thuban.Model.session import create_empty_session
28  from Thuban.Model.layer import Layer, RasterLayer  from Thuban.Model.layer import Layer, RasterLayer
29    from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support
30    # XXX: replace this by
31    # from wxPython.lib.dialogs import wxMultipleChoiceDialog
32    # when Thuban does not support wxPython 2.4.0 any more.
33    from Thuban.UI.multiplechoicedialog import wxMultipleChoiceDialog
34    
35  import view  import view
36  import tree  import tree
37  import tableview, identifyview  import tableview, identifyview
 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  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, \
44         MAP_REPLACED
45    from about import About
46    
47  from Thuban.UI.dock import DockFrame  from Thuban.UI.dock import DockFrame
48  from Thuban.UI.join import JoinDialog  from Thuban.UI.join import JoinDialog
49    from Thuban.UI.dbdialog import DBFrame, DBDialog, ChooseDBTableDialog
50  import resource  import resource
51    import Thuban.Model.resource
52    
53  import projdialog  import projdialog
54    
55    from Thuban.Lib.classmapper import ClassMapper
56    
57    layer_properties_dialogs = ClassMapper()
58    
59  class MainWindow(DockFrame):  class MainWindow(DockFrame):
60    
# Line 58  class MainWindow(DockFrame): Line 64  class MainWindow(DockFrame):
64      # actually come from. This delegation is implemented in the      # actually come from. This delegation is implemented in the
65      # Subscribe and unsubscribed methods      # Subscribe and unsubscribed methods
66      delegated_messages = {LAYER_SELECTED: "canvas",      delegated_messages = {LAYER_SELECTED: "canvas",
67                            SHAPES_SELECTED: "canvas"}                            SHAPES_SELECTED: "canvas",
68                              MAP_REPLACED: "canvas"}
69    
70      # Methods delegated to some instance variables. The delegation is      # Methods delegated to some instance variables. The delegation is
71      # implemented in the __getattr__ method.      # implemented in the __getattr__ method.
# Line 97  class MainWindow(DockFrame): Line 104  class MainWindow(DockFrame):
104          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)
105          canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)          canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)
106          self.canvas = canvas          self.canvas = canvas
107            self.canvas.Subscribe(TITLE_CHANGED, self.title_changed)
108    
109          self.SetMainWindow(self.canvas)          self.SetMainWindow(self.canvas)
110    
# Line 104  class MainWindow(DockFrame): Line 112  class MainWindow(DockFrame):
112    
113          self.init_dialogs()          self.init_dialogs()
114    
115            self.ShowLegend()
116    
117          EVT_CLOSE(self, self.OnClose)          EVT_CLOSE(self, self.OnClose)
118    
119      def Subscribe(self, channel, *args):      def Subscribe(self, channel, *args):
# Line 126  class MainWindow(DockFrame): Line 136  class MainWindow(DockFrame):
136          """          """
137          if channel in self.delegated_messages:          if channel in self.delegated_messages:
138              object = getattr(self, self.delegated_messages[channel])              object = getattr(self, self.delegated_messages[channel])
139              object.Unsubscribe(channel, *args)              try:
140                    object.Unsubscribe(channel, *args)
141                except wxPyDeadObjectError:
142                    # The object was a wxObject and has already been
143                    # destroyed. Hopefully it has unsubscribed all its
144                    # subscribers already so that it's OK if we do nothing
145                    # here
146                    pass
147    
148      def __getattr__(self, attr):      def __getattr__(self, attr):
149          """If attr is one of the delegated methods return that method          """If attr is one of the delegated methods return that method
# Line 334  class MainWindow(DockFrame): Line 351  class MainWindow(DockFrame):
351          """          """
352          self.SetStatusText(text)          self.SetStatusText(text)
353    
354        def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw):
355            """
356            Open or raise a dialog.
357    
358            If a dialog with the denoted name does already exist it is
359            raised.  Otherwise a new dialog, an instance of dialog_class,
360            is created, inserted into the main list and displayed.
361            """
362            dialog = self.get_open_dialog(name)
363    
364            if dialog is None:
365                dialog = dialog_class(self, name, *args, **kw)
366                self.add_dialog(name, dialog)
367                dialog.Show(True)
368            else:
369                dialog.Raise()
370                              
371      def save_modified_session(self, can_veto = 1):      def save_modified_session(self, can_veto = 1):
372          """If the current session has been modified, ask the user          """If the current session has been modified, ask the user
373          whether to save it and do so if requested. Return the outcome of          whether to save it and do so if requested. Return the outcome of
# Line 357  class MainWindow(DockFrame): Line 391  class MainWindow(DockFrame):
391              result = wxID_NO              result = wxID_NO
392          return result          return result
393    
     def prepare_new_session(self):  
         for d in self.dialogs.values():  
             if not isinstance(d, tree.SessionTreeView):  
                 d.Close()  
   
394      def NewSession(self):      def NewSession(self):
395          if self.save_modified_session() != wxID_CANCEL:          if self.save_modified_session() != wxID_CANCEL:
             self.prepare_new_session()  
396              self.application.SetSession(create_empty_session())              self.application.SetSession(create_empty_session())
397    
398      def OpenSession(self):      def OpenSession(self):
399          if self.save_modified_session() != wxID_CANCEL:          if self.save_modified_session() != wxID_CANCEL:
400              dlg = wxFileDialog(self, _("Open Session"), ".", "",              dlg = wxFileDialog(self, _("Open Session"),
401                                   self.application.Path("data"), "",
402                                 "Thuban Session File (*.thuban)|*.thuban",                                 "Thuban Session File (*.thuban)|*.thuban",
403                                 wxOPEN)                                 wxOPEN)
404              if dlg.ShowModal() == wxID_OK:              if dlg.ShowModal() == wxID_OK:
405                  self.prepare_new_session()                  self.application.OpenSession(dlg.GetPath(),
406                  self.application.OpenSession(dlg.GetPath())                                               self.run_db_param_dialog)
407                    self.application.SetPath("data", dlg.GetPath())
408              dlg.Destroy()              dlg.Destroy()
409    
410        def run_db_param_dialog(self, parameters, message):
411            dlg = DBDialog(self, _("DB Connection Parameters"), parameters,
412                           message)
413            return dlg.RunDialog()
414    
415      def SaveSession(self):      def SaveSession(self):
416          if self.application.session.filename == None:          if self.application.session.filename == None:
417              self.SaveSessionAs()              self.SaveSessionAs()
# Line 384  class MainWindow(DockFrame): Line 419  class MainWindow(DockFrame):
419              self.application.SaveSession()              self.application.SaveSession()
420    
421      def SaveSessionAs(self):      def SaveSessionAs(self):
422          dlg = wxFileDialog(self, _("Save Session As"), ".", "",          dlg = wxFileDialog(self, _("Save Session As"),
423                               self.application.Path("data"), "",
424                             "Thuban Session File (*.thuban)|*.thuban",                             "Thuban Session File (*.thuban)|*.thuban",
425                             wxSAVE|wxOVERWRITE_PROMPT)                             wxSAVE|wxOVERWRITE_PROMPT)
426          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
427              self.application.session.SetFilename(dlg.GetPath())              self.application.session.SetFilename(dlg.GetPath())
428              self.application.SaveSession()              self.application.SaveSession()
429                self.application.SetPath("data",dlg.GetPath())
430          dlg.Destroy()          dlg.Destroy()
431    
432      def Exit(self):      def Exit(self):
# Line 412  class MainWindow(DockFrame): Line 449  class MainWindow(DockFrame):
449    
450      def SetMap(self, map):      def SetMap(self, map):
451          self.canvas.SetMap(map)          self.canvas.SetMap(map)
452          self.__SetTitle(map.Title())          self.update_title()
453    
454          dialog = self.FindRegisteredDock("legend")          dialog = self.FindRegisteredDock("legend")
455          if dialog is not None:          if dialog is not None:
# Line 439  class MainWindow(DockFrame): Line 476  class MainWindow(DockFrame):
476          return self.get_open_dialog("session_tree") is not None          return self.get_open_dialog("session_tree") is not None
477    
478      def About(self):      def About(self):
479          self.RunMessageBox(_("About"),          dlg = About(self)
480                             _("Thuban %s\n"          dlg.ShowModal()
481                              #"Build Date: %s\n"          dlg.Destroy()
482                              "using:\n"  
483                              "  %s\n"      def DatabaseManagement(self):
484                              "  %s\n\n"          name = "dbmanagement"
485                              "Thuban is a program for\n"          dialog = self.get_open_dialog(name)
486                              "exploring geographic data.\n"          if dialog is None:
487                              "Copyright (C) 2001-2003 Intevation GmbH.\n"              map = self.canvas.Map()
488                              "Thuban is licensed under the GNU GPL"              dialog = DBFrame(self, name, self.application.Session())
489                              % (Thuban.version.longversion,              self.add_dialog(name, dialog)
490                                 "wxPython %s" % wxPython_version,              dialog.Show()
491                                 "Python %d.%d.%d" % sys.version_info[:3]          dialog.Raise()
                               )),  
 #                           % __ThubanVersion__), #__BuildDate__)),  
                            wxOK | wxICON_INFORMATION)  
492    
493      def AddLayer(self):      def AddLayer(self):
494          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",          dlg = wxFileDialog(self, _("Select one or more data files"),
495                             wxOPEN)                             self.application.Path("data"), "",
496                               _("Shapefiles (*.shp)") + "|*.shp;*.SHP|" +
497                               _("All Files (*.*)") + "|*.*",
498                               wxOPEN | wxMULTIPLE)
499          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
500              filename = dlg.GetPath()              filenames = dlg.GetPaths()
501              title = os.path.splitext(os.path.basename(filename))[0]              for filename in filenames:
502              map = self.canvas.Map()                  title = os.path.splitext(os.path.basename(filename))[0]
503              has_layers = map.HasLayers()                  map = self.canvas.Map()
504              try:                  has_layers = map.HasLayers()
505                  store = self.application.Session().OpenShapefile(filename)                  try:
506              except IOError:                      store = self.application.Session().OpenShapefile(filename)
507                  # the layer couldn't be opened                  except IOError:
508                  self.RunMessageBox(_("Add Layer"),                      # the layer couldn't be opened
509                                     _("Can't open the file '%s'.") % filename)                      self.RunMessageBox(_("Add Layer"),
510              else:                                         _("Can't open the file '%s'.")%filename)
511                  layer = Layer(title, store)                  else:
512                  map.AddLayer(layer)                      layer = Layer(title, store)
513                  if not has_layers:                      map.AddLayer(layer)
514                      # if we're adding a layer to an empty map, fit the                      if not has_layers:
515                      # new map to the window                          # if we're adding a layer to an empty map, fit the
516                      self.canvas.FitMapToWindow()                          # new map to the window
517                            self.canvas.FitMapToWindow()
518                        self.application.SetPath("data",filename)
519          dlg.Destroy()          dlg.Destroy()
520    
521      def AddRasterLayer(self):      def AddRasterLayer(self):
522          dlg = wxFileDialog(self, _("Select an image file"), ".", "", "*.*",          dlg = wxFileDialog(self, _("Select an image file"),
523                               self.application.Path("data"), "", "*.*",
524                             wxOPEN)                             wxOPEN)
525          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
526              filename = dlg.GetPath()              filename = dlg.GetPath()
# Line 499  class MainWindow(DockFrame): Line 539  class MainWindow(DockFrame):
539                      # if we're adding a layer to an empty map, fit the                      # if we're adding a layer to an empty map, fit the
540                      # new map to the window                      # new map to the window
541                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
542                    self.application.SetPath("data", filename)
543            dlg.Destroy()
544    
545        def AddDBLayer(self):
546            """Add a layer read from a database"""
547            session = self.application.Session()
548            dlg = ChooseDBTableDialog(self, self.application.Session())
549    
550            if dlg.ShowModal() == wxID_OK:
551                dbconn, dbtable, id_column, geo_column = dlg.GetTable()
552                try:
553                    title = str(dbtable)
554    
555                    # Chose the correct Interface for the database type
556                    store = session.OpenDBShapeStore(dbconn, dbtable,
557                                                     id_column = id_column,
558                                                     geometry_column = geo_column)
559                    layer = Layer(title, store)
560                except:
561                    # Some error occured while initializing the layer
562                    self.RunMessageBox(_("Add Layer from database"),
563                                       _("Can't open the database table '%s'")
564                                       % dbtable)
565                    return
566    
567                map = self.canvas.Map()
568    
569                has_layers = map.HasLayers()
570                map.AddLayer(layer)
571                if not has_layers:
572                    self.canvas.FitMapToWindow()
573    
574          dlg.Destroy()          dlg.Destroy()
575    
576      def RemoveLayer(self):      def RemoveLayer(self):
# Line 519  class MainWindow(DockFrame): Line 591  class MainWindow(DockFrame):
591              return self.canvas.Map().CanRemoveLayer(layer)              return self.canvas.Map().CanRemoveLayer(layer)
592          return False          return False
593    
594        def LayerToTop(self):
595            layer = self.current_layer()
596            if layer is not None:
597                self.canvas.Map().MoveLayerToTop(layer)
598    
599      def RaiseLayer(self):      def RaiseLayer(self):
600          layer = self.current_layer()          layer = self.current_layer()
601          if layer is not None:          if layer is not None:
# Line 529  class MainWindow(DockFrame): Line 606  class MainWindow(DockFrame):
606          if layer is not None:          if layer is not None:
607              self.canvas.Map().LowerLayer(layer)              self.canvas.Map().LowerLayer(layer)
608    
609        def LayerToBottom(self):
610            layer = self.current_layer()
611            if layer is not None:
612                self.canvas.Map().MoveLayerToBottom(layer)
613    
614      def current_layer(self):      def current_layer(self):
615          """Return the currently selected layer.          """Return the currently selected layer.
616    
# Line 540  class MainWindow(DockFrame): Line 622  class MainWindow(DockFrame):
622          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
623          return self.canvas.HasSelectedLayer()          return self.canvas.HasSelectedLayer()
624    
625        def has_selected_shape_layer(self):
626            """Return true if a shape layer is currently selected"""
627            return isinstance(self.current_layer(), Layer)
628    
629      def has_selected_shapes(self):      def has_selected_shapes(self):
630          """Return true if a shape is currently selected"""          """Return true if a shape is currently selected"""
631          return self.canvas.HasSelectedShapes()          return self.canvas.HasSelectedShapes()
# Line 547  class MainWindow(DockFrame): Line 633  class MainWindow(DockFrame):
633      def HideLayer(self):      def HideLayer(self):
634          layer = self.current_layer()          layer = self.current_layer()
635          if layer is not None:          if layer is not None:
636              layer.SetVisible(0)              layer.SetVisible(False)
637            
638      def ShowLayer(self):      def ShowLayer(self):
639          layer = self.current_layer()          layer = self.current_layer()
640          if layer is not None:          if layer is not None:
641              layer.SetVisible(1)              layer.SetVisible(True)
642    
643        def ToggleLayerVisibility(self):
644            layer = self.current_layer()
645            layer.SetVisible(not layer.Visible())
646    
647        def DuplicateLayer(self):
648            """Ceate a new layer above the selected layer with the same shapestore
649            """
650            layer = self.current_layer()
651            if layer is not None and hasattr(layer, "ShapeStore"):
652                new_layer = Layer(_("Copy of `%s'") % layer.Title(),
653                                  layer.ShapeStore(),
654                                  projection = layer.GetProjection())
655                new_classification = copy.deepcopy(layer.GetClassification())
656                new_layer.SetClassification(new_classification)
657                self.Map().AddLayer(new_layer)
658    
659        def CanDuplicateLayer(self):
660            """Return whether the DuplicateLayer method can create a duplicate"""
661            layer = self.current_layer()
662            return layer is not None and hasattr(layer, "ShapeStore")
663    
664      def LayerShowTable(self):      def LayerShowTable(self):
665            """
666            Present a TableView Window for the current layer.
667            In case the window is already open, bring it to the front.
668            In case, there is no active layer, do nothing.
669            In case, the layer has no ShapeStore, do nothing.
670            """
671          layer = self.current_layer()          layer = self.current_layer()
672          if layer is not None:          if layer is not None:
673              table = layer.table              if not hasattr(layer, "ShapeStore"):
674                    return
675                table = layer.ShapeStore().Table()
676              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
677              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
678              if dialog is None:              if dialog is None:
# Line 567  class MainWindow(DockFrame): Line 682  class MainWindow(DockFrame):
682                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
683                  dialog.Show(True)                  dialog.Show(True)
684              else:              else:
685                  # FIXME: bring dialog to front here                  dialog.Raise()
                 pass  
686    
687      def MapProjection(self):      def MapProjection(self):
688    
# Line 610  class MainWindow(DockFrame): Line 724  class MainWindow(DockFrame):
724          self.OpenLayerProperties(layer)          self.OpenLayerProperties(layer)
725    
726      def OpenLayerProperties(self, layer, group = None):      def OpenLayerProperties(self, layer, group = None):
727          name = "layer_properties" + str(id(layer))          """
728          dialog = self.get_open_dialog(name)          Open or raise the properties dialog.
729    
730          if dialog is None:          This method opens or raises the properties dialog for the
731              dialog = Classifier(self, name, layer, group)          currently selected layer if one is defined for this layer
732              self.add_dialog(name, dialog)          type.
733              dialog.Show()          """
734          dialog.Raise()          dialog_class = layer_properties_dialogs.get(layer)
735    
736            if dialog_class is not None:
737                name = "layer_properties" + str(id(layer))
738                self.OpenOrRaiseDialog(name, dialog_class, layer, group = group)
739    
740      def LayerJoinTable(self):      def LayerJoinTable(self):
741          layer = self.canvas.SelectedLayer()          layer = self.canvas.SelectedLayer()
# Line 658  class MainWindow(DockFrame): Line 776  class MainWindow(DockFrame):
776          return dialog is not None and dialog.IsShown()          return dialog is not None and dialog.IsShown()
777    
778      def TableOpen(self):      def TableOpen(self):
779          dlg = wxFileDialog(self, _("Open Table"), ".", "",          dlg = wxFileDialog(self, _("Open Table"),
780                               self.application.Path("data"), "",
781                             _("DBF Files (*.dbf)") + "|*.dbf|" +                             _("DBF Files (*.dbf)") + "|*.dbf|" +
782                             #_("CSV Files (*.csv)") + "|*.csv|" +                             #_("CSV Files (*.csv)") + "|*.csv|" +
783                             _("All Files (*.*)") + "|*.*",                             _("All Files (*.*)") + "|*.*",
# Line 674  class MainWindow(DockFrame): Line 793  class MainWindow(DockFrame):
793                                     _("Can't open the file '%s'.") % filename)                                     _("Can't open the file '%s'.") % filename)
794              else:              else:
795                  self.ShowTableView(table)                  self.ShowTableView(table)
796                    self.application.SetPath("data",filename)
797    
798      def TableClose(self):      def TableClose(self):
799          tables = self.application.session.UnreferencedTables()          tables = self.application.session.UnreferencedTables()
# Line 727  class MainWindow(DockFrame): Line 847  class MainWindow(DockFrame):
847                                                 table)                                                 table)
848              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
849              dialog.Show(True)              dialog.Show(True)
850          # FIXME: else bring dialog to front          dialog.Raise()
851    
852        def TableRename(self):
853            """Let the user rename a table"""
854    
855            # First, let the user select a table
856            tables = self.application.session.Tables()
857            lst = [(t.Title(), t) for t in tables]
858            lst.sort()
859            titles = [i[0] for i in lst]
860            dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"),
861                                         _("Rename Table"), titles,
862                                         size = (400,300),
863                                         style = wxDEFAULT_DIALOG_STYLE |
864                                                 wxRESIZE_BORDER)
865            if (dlg.ShowModal() == wxID_OK):
866                to_rename = [lst[i][1] for i in dlg.GetValue()]
867                dlg.Destroy()
868            else:
869                to_rename = []
870    
871            # Second, let the user rename the layers
872            for table in to_rename:
873                dlg = wxTextEntryDialog(self, _("Table Title:"), _("Rename Table"),
874                                        table.Title())
875                try:
876                    if dlg.ShowModal() == wxID_OK:
877                        title = dlg.GetValue()
878                        if title != "":
879                            table.SetTitle(title)
880    
881                            # Make sure the session is marked as modified.
882                            # FIXME: This should be handled automatically,
883                            # but that requires more changes to the tables
884                            # than I have time for currently.
885                            self.application.session.changed()
886                finally:
887                    dlg.Destroy()
888    
889    
890      def ZoomInTool(self):      def ZoomInTool(self):
891          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
# Line 761  class MainWindow(DockFrame): Line 919  class MainWindow(DockFrame):
919          self.canvas.Print()          self.canvas.Print()
920    
921      def RenameMap(self):      def RenameMap(self):
922          dlg = wxTextEntryDialog(self, "Map Title: ", "Rename Map",          dlg = wxTextEntryDialog(self, _("Map Title:"), _("Rename Map"),
923                                  self.Map().Title())                                  self.Map().Title())
924          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
925              title = dlg.GetValue()              title = dlg.GetValue()
926              if title != "":              if title != "":
927                  self.Map().SetTitle(title)                  self.Map().SetTitle(title)
                 self.__SetTitle(title)  
928    
929          dlg.Destroy()          dlg.Destroy()
930    
931        def RenameLayer(self):
932            """Let the user rename the currently selected layer"""
933            layer = self.current_layer()
934            if layer is not None:
935                dlg = wxTextEntryDialog(self, _("Layer Title:"), _("Rename Layer"),
936                                        layer.Title())
937                try:
938                    if dlg.ShowModal() == wxID_OK:
939                        title = dlg.GetValue()
940                        if title != "":
941                            layer.SetTitle(title)
942                finally:
943                    dlg.Destroy()
944    
945      def identify_view_on_demand(self, layer, shapes):      def identify_view_on_demand(self, layer, shapes):
946          """Subscribed to the canvas' SHAPES_SELECTED message          """Subscribed to the canvas' SHAPES_SELECTED message
947    
# Line 795  class MainWindow(DockFrame): Line 966  class MainWindow(DockFrame):
966                  # FIXME: bring dialog to front?                  # FIXME: bring dialog to front?
967                  pass                  pass
968    
969      def __SetTitle(self, title):      def title_changed(self, map):
970          self.SetTitle("Thuban - " + title)          """Subscribed to the canvas' TITLE_CHANGED messages"""
971            self.update_title()
972    
973        def update_title(self):
974            """Update the window's title according to it's current state.
975    
976            In this default implementation the title is 'Thuban - ' followed
977            by the map's title or simply 'Thuban' if there is not map.
978            Derived classes should override this method to get different
979            titles.
980    
981            This method is called automatically by other methods when the
982            title may have to change. For the methods implemented in this
983            class this usually only means that a different map has been set
984            or the current map's title has changed.
985            """
986            map = self.Map()
987            if map is not None:
988                title = _("Thuban - %s") % (map.Title(),)
989            else:
990                title = _("Thuban")
991            self.SetTitle(title)
992    
993    
994  #  #
995  # Define all the commands available in the main window  # Define all the commands available in the main window
# Line 838  def _has_selected_layer(context): Line 1031  def _has_selected_layer(context):
1031      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
1032      return context.mainwindow.has_selected_layer()      return context.mainwindow.has_selected_layer()
1033    
1034    def _has_selected_layer_visible(context):
1035        """Return true if a layer is selected in the context which is
1036        visible."""
1037        if context.mainwindow.has_selected_layer():
1038            layer = context.mainwindow.current_layer()
1039            if layer.Visible(): return True
1040        return False
1041    
1042    def _has_selected_shape_layer(context):
1043        """Return true if a shape layer is selected in the context"""
1044        return context.mainwindow.has_selected_shape_layer()
1045    
1046  def _has_selected_shapes(context):  def _has_selected_shapes(context):
1047      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
1048      return context.mainwindow.has_selected_shapes()      return context.mainwindow.has_selected_shapes()
# Line 857  def _has_visible_map(context): Line 1062  def _has_visible_map(context):
1062      if map is not None:      if map is not None:
1063          for layer in map.Layers():          for layer in map.Layers():
1064              if layer.Visible():              if layer.Visible():
1065                  return 1                  return True
1066      return 0      return False
1067    
1068  def _has_legend_shown(context):  def _has_legend_shown(context):
1069      """Return true if the legend window is shown"""      """Return true if the legend window is shown"""
1070      return context.mainwindow.LegendShown()      return context.mainwindow.LegendShown()
1071    
1072    def _has_gdal_support(context):
1073        """Return True if the GDAL is available"""
1074        return Thuban.Model.resource.has_gdal_support()
1075    
1076    def _has_dbconnections(context):
1077        """Return whether the the session has database connections"""
1078        return context.session.HasDBConnections()
1079    
1080    def _has_postgis_support(context):
1081        return has_postgis_support()
1082    
1083    
1084  # File menu  # File menu
1085  _method_command("new_session", _("&New Session"), "NewSession")  _method_command("new_session", _("&New Session"), "NewSession",
1086  _method_command("open_session", _("&Open Session..."), "OpenSession")                  helptext = _("Start a new session"))
1087  _method_command("save_session", _("&Save Session"), "SaveSession")  _method_command("open_session", _("&Open Session..."), "OpenSession",
1088  _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs")                  helptext = _("Open a session file"))
1089    _method_command("save_session", _("&Save Session"), "SaveSession",
1090                    helptext =_("Save this session to the file it was opened from"))
1091    _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs",
1092                    helptext = _("Save this session to a new file"))
1093  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
1094                  checked = _has_tree_window_shown)                  checked = _has_tree_window_shown,
1095                    helptext = _("Toggle on/off the session tree analysis window"))
1096  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
1097                  checked = _has_legend_shown)                  checked = _has_legend_shown,
1098  _method_command("exit", _("E&xit"), "Exit")                  helptext = _("Toggle Legend on/off"))
1099    _method_command("database_management", _("&Database Connections..."),
1100                    "DatabaseManagement",
1101                    sensitive = _has_postgis_support)
1102    _method_command("exit", _("E&xit"), "Exit",
1103                    helptext = _("Finish working with Thuban"))
1104    
1105  # Help menu  # Help menu
1106  _method_command("help_about", _("&About..."), "About")  _method_command("help_about", _("&About..."), "About",
1107                    helptext = _("Info about Thuban authors, version and modules"))
1108    
1109    
1110  # Map menu  # Map menu
1111  _method_command("map_projection", _("Pro&jection..."), "MapProjection")  _method_command("map_projection", _("Pro&jection..."), "MapProjection",
1112                    helptext = _("Set or change the map projection"))
1113    
1114  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
1115                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
# Line 900  _tool_command("map_label_tool", _("&Labe Line 1128  _tool_command("map_label_tool", _("&Labe
1128                helptext = _("Add/Remove labels"), icon = "label",                helptext = _("Add/Remove labels"), icon = "label",
1129                sensitive = _has_visible_map)                sensitive = _has_visible_map)
1130  _method_command("map_full_extent", _("&Full extent"), "FullExtent",  _method_command("map_full_extent", _("&Full extent"), "FullExtent",
1131                 helptext = _("Full Extent"), icon = "fullextent",                 helptext = _("Zoom to the full map extent"), icon = "fullextent",
1132                sensitive = _has_visible_map)                sensitive = _has_visible_map)
1133  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",
1134                 helptext = _("Full Layer Extent"), icon = "fulllayerextent",                  helptext = _("Zoom to the full layer extent"),
1135                sensitive = _has_selected_layer)                  icon = "fulllayerextent", sensitive = _has_selected_layer)
1136  _method_command("selected_full_extent", _("&Full selection extent"), "FullSelectionExtent",  _method_command("selected_full_extent", _("&Full selection extent"),
1137                 helptext = _("Full Selection Extent"), icon = "fullselextent",                  "FullSelectionExtent",
1138                sensitive = _has_selected_shapes)                  helptext = _("Zoom to the full selection extent"),
1139                    icon = "fullselextent", sensitive = _has_selected_shapes)
1140  _method_command("map_export", _("E&xport"), "ExportMap",  _method_command("map_export", _("E&xport"), "ExportMap",
1141                      helptext = _("Export the map to file"))                  helptext = _("Export the map to file"))
1142  _method_command("map_print", _("Prin&t"), "PrintMap",  _method_command("map_print", _("Prin&t"), "PrintMap",
1143                  helptext = _("Print the map"))                  helptext = _("Print the map"))
1144  _method_command("map_rename", _("&Rename..."), "RenameMap",  _method_command("map_rename", _("&Rename..."), "RenameMap",
1145                  helptext = _("Rename the map"))                  helptext = _("Rename the map"))
1146  _method_command("layer_add", _("&Add Layer..."), "AddLayer",  _method_command("layer_add", _("&Add Layer..."), "AddLayer",
1147                  helptext = _("Add a new layer to active map"))                  helptext = _("Add a new layer to the map"))
1148  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
1149                  helptext = _("Add a new image layer to active map"))                  helptext = _("Add a new image layer to the map"),
1150                    sensitive = _has_gdal_support)
1151    _method_command("layer_add_db", _("Add &Database Layer..."), "AddDBLayer",
1152                    helptext = _("Add a new database layer to active map"),
1153                    sensitive = _has_dbconnections)
1154  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
1155                  helptext = _("Remove selected layer(s)"),                  helptext = _("Remove selected layer"),
1156                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
1157    
1158  # Layer menu  # Layer menu
1159  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
1160                    sensitive = _has_selected_layer,
1161                    helptext = _("Specify projection for selected layer"))
1162    _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
1163                    helptext = _("Duplicate selected layer"),
1164              sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
1165    _method_command("layer_rename", _("Re&name ..."), "RenameLayer",
1166                    helptext = _("Rename selected layer"),
1167                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1168  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
1169                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer"),
1170                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1171  _method_command("layer_lower", _("&Lower"), "LowerLayer",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
1172                  helptext = _("Lower selected layer(s)"),                  helptext = _("Lower selected layer"),
1173                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1174  _method_command("layer_show", _("&Show"), "ShowLayer",  _method_command("layer_show", _("&Show"), "ShowLayer",
1175                  helptext = _("Make selected layer(s) visible"),                  helptext = _("Make selected layer visible"),
1176                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1177  _method_command("layer_hide", _("&Hide"), "HideLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
1178                  helptext = _("Make selected layer(s) unvisible"),                  helptext = _("Make selected layer unvisible"),
1179                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1180  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
1181                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
1182                  sensitive = _has_selected_layer)                  sensitive = _has_selected_shape_layer)
1183  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
1184                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1185                    helptext = _("Edit the properties of the selected layer"))
1186  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1187                    sensitive = _has_selected_shape_layer,
1188                    helptext = _("Join and attach a table to the selected layer"))
1189    
1190    # further layer methods:
1191    _method_command("layer_to_top", _("&Top"), "LayerToTop",
1192                    helptext = _("Put selected layer to the top"),
1193                    sensitive = _has_selected_layer)
1194    _method_command("layer_to_bottom", _("&Bottom"), "LayerToBottom",
1195                    helptext = _("Put selected layer to the bottom"),
1196                    sensitive = _has_selected_layer)
1197    _method_command("layer_visibility", _("&Visible"), "ToggleLayerVisibility",
1198                    checked = _has_selected_layer_visible,
1199                    helptext = _("Toggle visibility of selected layer"),
1200                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1201    
1202  def _can_unjoin(context):  def _can_unjoin(context):
# Line 960  def _can_unjoin(context): Line 1214  def _can_unjoin(context):
1214      else:      else:
1215          return 0          return 0
1216  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
1217                  sensitive = _can_unjoin)                  sensitive = _can_unjoin,
1218                    helptext = _("Undo the last join operation"))
1219    
1220    
1221    def _has_tables(context):
1222        return bool(context.session.Tables())
1223    
1224  # Table menu  # Table menu
1225  _method_command("table_open", _("&Open..."), "TableOpen")  _method_command("table_open", _("&Open..."), "TableOpen",
1226  _method_command("table_close", _("&Close"), "TableClose",                  helptext = _("Open a DBF-table from a file"))
1227         sensitive = lambda context: bool(context.session.UnreferencedTables()))  _method_command("table_close", _("&Close..."), "TableClose",
1228  _method_command("table_show", _("&Show"), "TableShow")         sensitive = lambda context: bool(context.session.UnreferencedTables()),
1229  _method_command("table_join", _("&Join..."), "TableJoin")                  helptext = _("Close one or more tables from a list"))
1230    _method_command("table_rename", _("&Rename..."), "TableRename",
1231                    sensitive = _has_tables,
1232                    helptext = _("Rename one or more tables"))
1233    _method_command("table_show", _("&Show..."), "TableShow",
1234                    sensitive = _has_tables,
1235                    helptext = _("Show one or more tables in a dialog"))
1236    _method_command("table_join", _("&Join..."), "TableJoin",
1237                    sensitive = _has_tables,
1238                    helptext = _("Join two tables creating a new one"))
1239    
1240  #  Export only under Windows ...  #  Export only under Windows ...
1241  map_menu = ["layer_add", "rasterlayer_add", "layer_remove", "map_rename",  map_menu = ["layer_add", "layer_add_db", "rasterlayer_add", "layer_remove",
1242                          None,                          None,
1243                            "map_rename",
1244                          "map_projection",                          "map_projection",
1245                          None,                          None,
1246                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
1247                          "map_pan_tool",                          "map_pan_tool",
1248                          "map_full_extent",                          "map_full_extent",
1249                          "layer_full_extent",                          "layer_full_extent",
1250                          "selected_full_extent",                          "selected_full_extent",
1251                          None,                          None,
# Line 993  main_menu = Menu("<main>", "<main>", Line 1262  main_menu = Menu("<main>", "<main>",
1262                   [Menu("file", _("&File"),                   [Menu("file", _("&File"),
1263                         ["new_session", "open_session", None,                         ["new_session", "open_session", None,
1264                          "save_session", "save_session_as", None,                          "save_session", "save_session_as", None,
1265                            "database_management", None,
1266                          "toggle_session_tree", None,                          "toggle_session_tree", None,
1267                          "exit"]),                          "exit"]),
1268                    Menu("map", _("&Map"), map_menu),                    Menu("map", _("&Map"), map_menu),
1269                    Menu("layer", _("&Layer"),                    Menu("layer", _("&Layer"),
1270                          ["layer_raise", "layer_lower",                         ["layer_rename", "layer_duplicate",
1271                            None,
1272                            "layer_raise", "layer_lower",
1273                          None,                          None,
1274                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
1275                          None,                          None,
# Line 1009  main_menu = Menu("<main>", "<main>", Line 1281  main_menu = Menu("<main>", "<main>",
1281                          None,                          None,
1282                          "layer_properties"]),                          "layer_properties"]),
1283                    Menu("table", _("&Table"),                    Menu("table", _("&Table"),
1284                         ["table_open", "table_close",                         ["table_open", "table_close", "table_rename",
1285                         None,                         None,
1286                         "table_show",                         "table_show",
1287                         None,                         None,
# Line 1026  main_toolbar = Menu("<toolbar>", "<toolb Line 1298  main_toolbar = Menu("<toolbar>", "<toolb
1298                       "selected_full_extent",                       "selected_full_extent",
1299                       None,                       None,
1300                       "map_identify_tool", "map_label_tool"])                       "map_identify_tool", "map_label_tool"])
1301    

Legend:
Removed from v.1084  
changed lines
  Added in v.2365

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26