/[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 1644 by bh, Mon Aug 25 12:44:55 2003 UTC revision 2551 by jonathan, Thu Jan 27 14:19:41 2005 UTC
# Line 1  Line 1 
1  # Copyright (C) 2001, 2002, 2003 by Intevation GmbH  # Copyright (C) 2001, 2002, 2003, 2004, 2005 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 19  import os Line 19  import os
19  import copy  import copy
20    
21  from wxPython.wx import *  from wxPython.wx import *
 from wxPython.wx import __version__ as wxPython_version  
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, LAYER_PROJECTION_CHANGED, \
27         MAP_PROJECTION_CHANGED, MAP_LAYERS_ADDED, MAP_LAYERS_REMOVED
28    
29  from Thuban.Model.session import create_empty_session  from Thuban.Model.session import create_empty_session
30  from Thuban.Model.layer import Layer, RasterLayer  from Thuban.Model.layer import Layer, RasterLayer
31  from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support  from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support
# Line 36  from Thuban.UI.multiplechoicedialog impo Line 37  from Thuban.UI.multiplechoicedialog impo
37  import view  import view
38  import tree  import tree
39  import tableview, identifyview  import tableview, identifyview
 from Thuban.UI.classifier import Classifier  
40  import legend  import legend
41  from menu import Menu  from menu import Menu
42    
# Line 48  from about import About Line 48  from about import About
48    
49  from Thuban.UI.dock import DockFrame  from Thuban.UI.dock import DockFrame
50  from Thuban.UI.join import JoinDialog  from Thuban.UI.join import JoinDialog
51  from Thuban.UI.dbdialog import DBFrame, ChooseDBTableDialog  from Thuban.UI.dbdialog import DBFrame, DBDialog, ChooseDBTableDialog
52  import resource  import resource
53  import Thuban.Model.resource  import Thuban.Model.resource
54    
55  import projdialog  import projdialog
56    
57    from Thuban.UI.classifier import Classifier
58    from Thuban.UI.rasterlayerproperties import RasterLayerProperties
59    from Thuban.Model.layer import RasterLayer
60    
61    from Thuban.Lib.classmapper import ClassMapper
62    
63    layer_properties_dialogs = ClassMapper()
64    layer_properties_dialogs.add(RasterLayer, RasterLayerProperties)
65    layer_properties_dialogs.add(Layer, Classifier)
66    
67  class MainWindow(DockFrame):  class MainWindow(DockFrame):
68    
# Line 74  class MainWindow(DockFrame): Line 83  class MainWindow(DockFrame):
83                           "SelectedShapes": "canvas",                           "SelectedShapes": "canvas",
84                           }                           }
85    
86        # Messages from the canvas that may require a status bar update.
87        # The update_status_bar method will be subscribed to these messages.
88        update_status_bar_messages = (VIEW_POSITION, LAYER_PROJECTION_CHANGED,
89                                      MAP_PROJECTION_CHANGED, MAP_LAYERS_ADDED,
90                                      MAP_LAYERS_REMOVED)
91    
92      def __init__(self, parent, ID, title, application, interactor,      def __init__(self, parent, ID, title, application, interactor,
93                   initial_message = None, size = wxSize(-1, -1)):                   initial_message = None, size = wxSize(-1, -1)):
94          DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)          DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)
# Line 100  class MainWindow(DockFrame): Line 115  class MainWindow(DockFrame):
115    
116          # Create the map canvas          # Create the map canvas
117          canvas = view.MapCanvas(self, -1)          canvas = view.MapCanvas(self, -1)
         canvas.Subscribe(VIEW_POSITION, self.view_position_changed)  
118          canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)          canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)
119          self.canvas = canvas          self.canvas = canvas
120            self.canvas.Subscribe(TITLE_CHANGED, self.title_changed)
121    
122            for channel in self.update_status_bar_messages:
123                self.canvas.Subscribe(channel, self.update_status_bar)
124    
125          self.SetMainWindow(self.canvas)          self.SetMainWindow(self.canvas)
126    
# Line 134  class MainWindow(DockFrame): Line 152  class MainWindow(DockFrame):
152          """          """
153          if channel in self.delegated_messages:          if channel in self.delegated_messages:
154              object = getattr(self, self.delegated_messages[channel])              object = getattr(self, self.delegated_messages[channel])
155              object.Unsubscribe(channel, *args)              try:
156                    object.Unsubscribe(channel, *args)
157                except wxPyDeadObjectError:
158                    # The object was a wxObject and has already been
159                    # destroyed. Hopefully it has unsubscribed all its
160                    # subscribers already so that it's OK if we do nothing
161                    # here
162                    pass
163    
164      def __getattr__(self, attr):      def __getattr__(self, attr):
165          """If attr is one of the delegated methods return that method          """If attr is one of the delegated methods return that method
# Line 325  class MainWindow(DockFrame): Line 350  class MainWindow(DockFrame):
350      def get_open_dialog(self, name):      def get_open_dialog(self, name):
351          return self.dialogs.get(name)          return self.dialogs.get(name)
352    
353      def view_position_changed(self):      def update_status_bar(self, *args):
354            """Handler for a bunch of messages that may require a status bar update
355    
356            Currently this handles the canvas' VIEW_POSITION_CHANGED
357            messages as well as several messages about changes in the map
358            which may affect whether and how projections are used.
359    
360            These messages affect the text in the status bar in the following way:
361    
362            When VIEW_POSITION_CHANGED messages are sent and the mouse is
363            actually in the canvas window, display the current mouse
364            coordinates as defined by the canvas' CurrentPosition method.
365    
366            If there is no current position to show, check whether there is
367            a potential problem with the map and layer projections and
368            display a message about it.  Otherwise the status bar will
369            become empty.
370    
371            The text is displayed in the status bar using the
372            set_position_text method.
373            """
374            # Implementation note: We do not really have to know which
375            # message was sent.  We can simply call the canvas'
376            # CurrentPosition method and if that returns a tuple, it was a
377            # VIEW_POSITION_CHANGED message and we have to display it.
378            # Otherwise it was a VIEW_POSITION_CHANGED message where the
379            # mouse has left the canvas or it was a message about a change
380            # to the map, in which case we check the projections.
381            #
382            # When changing this method, keep in mind that the
383            # VIEW_POSITION_CHANGED message are sent for every mouse move in
384            # the canvas window, that is they happen very often, so the path
385            # taken in that case has to be fast.
386            text = ""
387          pos = self.canvas.CurrentPosition()          pos = self.canvas.CurrentPosition()
388          if pos is not None:          if pos is not None:
389              text = "(%10.10g, %10.10g)" % pos              text = "(%10.10g, %10.10g)" % pos
390          else:          else:
391              text = ""              for layer in self.canvas.Map().Layers():
392                    bbox = layer.LatLongBoundingBox()
393                    if bbox:
394                        left, bottom, right, top = bbox
395                        if not (-180 <= left <= 180 and
396                                -180 <= right <= 180 and
397                                -90 <= top <= 90 and
398                                -90 <= bottom <= 90):
399                            text = _("Select layer '%s' and pick a projection "
400                                     "using Layer/Projection...") % layer.title
401                            break
402    
403          self.set_position_text(text)          self.set_position_text(text)
404    
405      def set_position_text(self, text):      def set_position_text(self, text):
406          """Set the statusbar text showing the current position.          """Set the statusbar text to that created by update_status_bar
407    
408          By default the text is shown in field 0 of the status bar.          By default the text is shown in field 0 of the status bar.
409          Override this method in derived classes to put it into a          Override this method in derived classes to put it into a
410          different field of the statusbar.          different field of the statusbar.
411    
412            For historical reasons this method is called set_position_text
413            because at first the text was always either the current position
414            or the empty string.  Now it can contain other messages as well.
415            The method will be renamed at one point.
416          """          """
417            # Note: If this method is renamed we should perhaps think about
418            # some backwards compatibility measures for projects like
419            # GREAT-ER which override this method.
420          self.SetStatusText(text)          self.SetStatusText(text)
421    
422        def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw):
423            """
424            Open or raise a dialog.
425    
426            If a dialog with the denoted name does already exist it is
427            raised.  Otherwise a new dialog, an instance of dialog_class,
428            is created, inserted into the main list and displayed.
429            """
430            dialog = self.get_open_dialog(name)
431    
432            if dialog is None:
433                dialog = dialog_class(self, name, *args, **kw)
434                self.add_dialog(name, dialog)
435                dialog.Show(True)
436            else:
437                dialog.Raise()
438                              
439      def save_modified_session(self, can_veto = 1):      def save_modified_session(self, can_veto = 1):
440          """If the current session has been modified, ask the user          """If the current session has been modified, ask the user
441          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 371  class MainWindow(DockFrame): Line 465  class MainWindow(DockFrame):
465    
466      def OpenSession(self):      def OpenSession(self):
467          if self.save_modified_session() != wxID_CANCEL:          if self.save_modified_session() != wxID_CANCEL:
468              dlg = wxFileDialog(self, _("Open Session"), ".", "",              dlg = wxFileDialog(self, _("Open Session"),
469                                   self.application.Path("data"), "",
470                                 "Thuban Session File (*.thuban)|*.thuban",                                 "Thuban Session File (*.thuban)|*.thuban",
471                                 wxOPEN)                                 wxOPEN)
472              if dlg.ShowModal() == wxID_OK:              if dlg.ShowModal() == wxID_OK:
473                  self.application.OpenSession(dlg.GetPath())                  self.application.OpenSession(dlg.GetPath(),
474                                                 self.run_db_param_dialog)
475                    self.application.SetPath("data", dlg.GetPath())
476              dlg.Destroy()              dlg.Destroy()
477    
478        def run_db_param_dialog(self, parameters, message):
479            dlg = DBDialog(self, _("DB Connection Parameters"), parameters,
480                           message)
481            return dlg.RunDialog()
482    
483      def SaveSession(self):      def SaveSession(self):
484          if self.application.session.filename == None:          if self.application.session.filename == None:
485              self.SaveSessionAs()              self.SaveSessionAs()
# Line 385  class MainWindow(DockFrame): Line 487  class MainWindow(DockFrame):
487              self.application.SaveSession()              self.application.SaveSession()
488    
489      def SaveSessionAs(self):      def SaveSessionAs(self):
490          dlg = wxFileDialog(self, _("Save Session As"), ".", "",          dlg = wxFileDialog(self, _("Save Session As"),
491                               self.application.Path("data"), "",
492                             "Thuban Session File (*.thuban)|*.thuban",                             "Thuban Session File (*.thuban)|*.thuban",
493                             wxSAVE|wxOVERWRITE_PROMPT)                             wxSAVE|wxOVERWRITE_PROMPT)
494          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
495              self.application.session.SetFilename(dlg.GetPath())              self.application.session.SetFilename(dlg.GetPath())
496              self.application.SaveSession()              self.application.SaveSession()
497                self.application.SetPath("data",dlg.GetPath())
498          dlg.Destroy()          dlg.Destroy()
499    
500      def Exit(self):      def Exit(self):
# Line 404  class MainWindow(DockFrame): Line 508  class MainWindow(DockFrame):
508              # FIXME: it would be better to tie the unsubscription to              # FIXME: it would be better to tie the unsubscription to
509              # wx's destroy event, but that isn't implemented for wxGTK              # wx's destroy event, but that isn't implemented for wxGTK
510              # yet.              # yet.
511              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)              for channel in self.update_status_bar_messages:
512                    self.canvas.Unsubscribe(channel, self.update_status_bar)
513    
514              DockFrame.OnClose(self, event)              DockFrame.OnClose(self, event)
515              for dlg in self.dialogs.values():              for dlg in self.dialogs.values():
516                  dlg.Destroy()                  dlg.Destroy()
# Line 413  class MainWindow(DockFrame): Line 519  class MainWindow(DockFrame):
519    
520      def SetMap(self, map):      def SetMap(self, map):
521          self.canvas.SetMap(map)          self.canvas.SetMap(map)
522          self.__SetTitle(map.Title())          self.update_title()
523    
524          dialog = self.FindRegisteredDock("legend")          dialog = self.FindRegisteredDock("legend")
525          if dialog is not None:          if dialog is not None:
# Line 455  class MainWindow(DockFrame): Line 561  class MainWindow(DockFrame):
561          dialog.Raise()          dialog.Raise()
562    
563      def AddLayer(self):      def AddLayer(self):
564          dlg = wxFileDialog(self, _("Select one or more data files"), ".", "",          dlg = wxFileDialog(self, _("Select one or more data files"),
565                             _("Shapefiles (*.shp)") + "|*.shp|" +                             self.application.Path("data"), "",
566                             _("All Files (*.*)") + "|*.*",                             _("Shapefiles (*.shp)") + "|*.shp;*.SHP|" +
567                               _("All Files (*.*)") + "|*.*",
568                             wxOPEN | wxMULTIPLE)                             wxOPEN | wxMULTIPLE)
569          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
570              filenames = dlg.GetPaths()              filenames = dlg.GetPaths()
# Line 478  class MainWindow(DockFrame): Line 585  class MainWindow(DockFrame):
585                          # if we're adding a layer to an empty map, fit the                          # if we're adding a layer to an empty map, fit the
586                          # new map to the window                          # new map to the window
587                          self.canvas.FitMapToWindow()                          self.canvas.FitMapToWindow()
588                        self.application.SetPath("data",filename)
589          dlg.Destroy()          dlg.Destroy()
590    
591      def AddRasterLayer(self):      def AddRasterLayer(self):
592          dlg = wxFileDialog(self, _("Select an image file"), ".", "", "*.*",          dlg = wxFileDialog(self, _("Select an image file"),
593                               self.application.Path("data"), "", "*.*",
594                             wxOPEN)                             wxOPEN)
595          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
596              filename = dlg.GetPath()              filename = dlg.GetPath()
# Line 500  class MainWindow(DockFrame): Line 609  class MainWindow(DockFrame):
609                      # if we're adding a layer to an empty map, fit the                      # if we're adding a layer to an empty map, fit the
610                      # new map to the window                      # new map to the window
611                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
612                    self.application.SetPath("data", filename)
613          dlg.Destroy()          dlg.Destroy()
614    
615      def AddDBLayer(self):      def AddDBLayer(self):
616          """Add a layer read from a database"""          """Add a layer read from a database"""
617          session = self.application.Session()          session = self.application.Session()
618          dlg = ChooseDBTableDialog(self.application.Session(), self,-1, "")          dlg = ChooseDBTableDialog(self, self.application.Session())
619    
620          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
621              dbconn, dbtable = dlg.GetTable()              dbconn, dbtable, id_column, geo_column = dlg.GetTable()
622              try:              try:
623                  title = str(dbtable)                  title = str(dbtable)
624    
625                  # Chose the correct Interface for the database type                  # Chose the correct Interface for the database type
626                  store = PostGISShapeStore(dbconn, dbtable)                  store = session.OpenDBShapeStore(dbconn, dbtable,
627                  session.AddShapeStore(store)                                                   id_column = id_column,
628                                                     geometry_column = geo_column)
629                  layer = Layer(title, store)                  layer = Layer(title, store)
630              except:              except:
631                  # Some error occured while initializing the layer                  # Some error occured while initializing the layer
632                  self.RunMessageBox(_("Add Layer from database"),                  self.RunMessageBox(_("Add Layer from database"),
633                                     _("Can't open the database table '%s'")                                     _("Can't open the database table '%s'")
634                                     % dbtable)                                     % dbtable)
635                    return
636    
637              map = self.canvas.Map()              map = self.canvas.Map()
638    
# Line 549  class MainWindow(DockFrame): Line 661  class MainWindow(DockFrame):
661              return self.canvas.Map().CanRemoveLayer(layer)              return self.canvas.Map().CanRemoveLayer(layer)
662          return False          return False
663    
664        def LayerToTop(self):
665            layer = self.current_layer()
666            if layer is not None:
667                self.canvas.Map().MoveLayerToTop(layer)
668    
669      def RaiseLayer(self):      def RaiseLayer(self):
670          layer = self.current_layer()          layer = self.current_layer()
671          if layer is not None:          if layer is not None:
# Line 559  class MainWindow(DockFrame): Line 676  class MainWindow(DockFrame):
676          if layer is not None:          if layer is not None:
677              self.canvas.Map().LowerLayer(layer)              self.canvas.Map().LowerLayer(layer)
678    
679        def LayerToBottom(self):
680            layer = self.current_layer()
681            if layer is not None:
682                self.canvas.Map().MoveLayerToBottom(layer)
683    
684      def current_layer(self):      def current_layer(self):
685          """Return the currently selected layer.          """Return the currently selected layer.
686    
# Line 570  class MainWindow(DockFrame): Line 692  class MainWindow(DockFrame):
692          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
693          return self.canvas.HasSelectedLayer()          return self.canvas.HasSelectedLayer()
694    
695        def has_selected_shape_layer(self):
696            """Return true if a shape layer is currently selected"""
697            return isinstance(self.current_layer(), Layer)
698    
699      def has_selected_shapes(self):      def has_selected_shapes(self):
700          """Return true if a shape is currently selected"""          """Return true if a shape is currently selected"""
701          return self.canvas.HasSelectedShapes()          return self.canvas.HasSelectedShapes()
# Line 577  class MainWindow(DockFrame): Line 703  class MainWindow(DockFrame):
703      def HideLayer(self):      def HideLayer(self):
704          layer = self.current_layer()          layer = self.current_layer()
705          if layer is not None:          if layer is not None:
706              layer.SetVisible(0)              layer.SetVisible(False)
707    
708      def ShowLayer(self):      def ShowLayer(self):
709          layer = self.current_layer()          layer = self.current_layer()
710          if layer is not None:          if layer is not None:
711              layer.SetVisible(1)              layer.SetVisible(True)
712    
713        def ToggleLayerVisibility(self):
714            layer = self.current_layer()
715            layer.SetVisible(not layer.Visible())
716    
717      def DuplicateLayer(self):      def DuplicateLayer(self):
718          """Ceate a new layer above the selected layer with the same shapestore          """Ceate a new layer above the selected layer with the same shapestore
# Line 593  class MainWindow(DockFrame): Line 723  class MainWindow(DockFrame):
723                                layer.ShapeStore(),                                layer.ShapeStore(),
724                                projection = layer.GetProjection())                                projection = layer.GetProjection())
725              new_classification = copy.deepcopy(layer.GetClassification())              new_classification = copy.deepcopy(layer.GetClassification())
726                new_layer.SetClassificationColumn(
727                        layer.GetClassificationColumn())
728              new_layer.SetClassification(new_classification)              new_layer.SetClassification(new_classification)
729              self.Map().AddLayer(new_layer)              self.Map().AddLayer(new_layer)
730    
# Line 602  class MainWindow(DockFrame): Line 734  class MainWindow(DockFrame):
734          return layer is not None and hasattr(layer, "ShapeStore")          return layer is not None and hasattr(layer, "ShapeStore")
735    
736      def LayerShowTable(self):      def LayerShowTable(self):
737            """
738            Present a TableView Window for the current layer.
739            In case the window is already open, bring it to the front.
740            In case, there is no active layer, do nothing.
741            In case, the layer has no ShapeStore, do nothing.
742            """
743          layer = self.current_layer()          layer = self.current_layer()
744          if layer is not None:          if layer is not None:
745                if not hasattr(layer, "ShapeStore"):
746                    return
747              table = layer.ShapeStore().Table()              table = layer.ShapeStore().Table()
748              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
749              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
# Line 614  class MainWindow(DockFrame): Line 754  class MainWindow(DockFrame):
754                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
755                  dialog.Show(True)                  dialog.Show(True)
756              else:              else:
757                  # FIXME: bring dialog to front here                  dialog.Raise()
                 pass  
758    
759      def MapProjection(self):      def MapProjection(self):
760    
# Line 657  class MainWindow(DockFrame): Line 796  class MainWindow(DockFrame):
796          self.OpenLayerProperties(layer)          self.OpenLayerProperties(layer)
797    
798      def OpenLayerProperties(self, layer, group = None):      def OpenLayerProperties(self, layer, group = None):
799          name = "layer_properties" + str(id(layer))          """
800          dialog = self.get_open_dialog(name)          Open or raise the properties dialog.
801    
802          if dialog is None:          This method opens or raises the properties dialog for the
803              dialog = Classifier(self, name, self.Map(), layer, group)          currently selected layer if one is defined for this layer
804              self.add_dialog(name, dialog)          type.
805              dialog.Show()          """
806          dialog.Raise()          dialog_class = layer_properties_dialogs.get(layer)
807    
808            if dialog_class is not None:
809                name = "layer_properties" + str(id(layer))
810                self.OpenOrRaiseDialog(name, dialog_class, layer, group = group)
811    
812      def LayerJoinTable(self):      def LayerJoinTable(self):
813          layer = self.canvas.SelectedLayer()          layer = self.canvas.SelectedLayer()
# Line 705  class MainWindow(DockFrame): Line 848  class MainWindow(DockFrame):
848          return dialog is not None and dialog.IsShown()          return dialog is not None and dialog.IsShown()
849    
850      def TableOpen(self):      def TableOpen(self):
851          dlg = wxFileDialog(self, _("Open Table"), ".", "",          dlg = wxFileDialog(self, _("Open Table"),
852                               self.application.Path("data"), "",
853                             _("DBF Files (*.dbf)") + "|*.dbf|" +                             _("DBF Files (*.dbf)") + "|*.dbf|" +
854                             #_("CSV Files (*.csv)") + "|*.csv|" +                             #_("CSV Files (*.csv)") + "|*.csv|" +
855                             _("All Files (*.*)") + "|*.*",                             _("All Files (*.*)") + "|*.*",
# Line 721  class MainWindow(DockFrame): Line 865  class MainWindow(DockFrame):
865                                     _("Can't open the file '%s'.") % filename)                                     _("Can't open the file '%s'.") % filename)
866              else:              else:
867                  self.ShowTableView(table)                  self.ShowTableView(table)
868                    self.application.SetPath("data",filename)
869    
870      def TableClose(self):      def TableClose(self):
871          tables = self.application.session.UnreferencedTables()          tables = self.application.session.UnreferencedTables()
# Line 797  class MainWindow(DockFrame): Line 942  class MainWindow(DockFrame):
942    
943          # Second, let the user rename the layers          # Second, let the user rename the layers
944          for table in to_rename:          for table in to_rename:
945              dlg = wxTextEntryDialog(self, "Table Title: ", "Rename Table",              dlg = wxTextEntryDialog(self, _("Table Title:"), _("Rename Table"),
946                                      table.Title())                                      table.Title())
947              try:              try:
948                  if dlg.ShowModal() == wxID_OK:                  if dlg.ShowModal() == wxID_OK:
# Line 846  class MainWindow(DockFrame): Line 991  class MainWindow(DockFrame):
991          self.canvas.Print()          self.canvas.Print()
992    
993      def RenameMap(self):      def RenameMap(self):
994          dlg = wxTextEntryDialog(self, "Map Title: ", "Rename Map",          dlg = wxTextEntryDialog(self, _("Map Title:"), _("Rename Map"),
995                                  self.Map().Title())                                  self.Map().Title())
996          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
997              title = dlg.GetValue()              title = dlg.GetValue()
998              if title != "":              if title != "":
999                  self.Map().SetTitle(title)                  self.Map().SetTitle(title)
                 self.__SetTitle(title)  
1000    
1001          dlg.Destroy()          dlg.Destroy()
1002    
# Line 860  class MainWindow(DockFrame): Line 1004  class MainWindow(DockFrame):
1004          """Let the user rename the currently selected layer"""          """Let the user rename the currently selected layer"""
1005          layer = self.current_layer()          layer = self.current_layer()
1006          if layer is not None:          if layer is not None:
1007              dlg = wxTextEntryDialog(self, "Layer Title: ", "Rename Layer",              dlg = wxTextEntryDialog(self, _("Layer Title:"), _("Rename Layer"),
1008                                      layer.Title())                                      layer.Title())
1009              try:              try:
1010                  if dlg.ShowModal() == wxID_OK:                  if dlg.ShowModal() == wxID_OK:
# Line 894  class MainWindow(DockFrame): Line 1038  class MainWindow(DockFrame):
1038                  # FIXME: bring dialog to front?                  # FIXME: bring dialog to front?
1039                  pass                  pass
1040    
1041      def __SetTitle(self, title):      def title_changed(self, map):
1042          self.SetTitle("Thuban - " + title)          """Subscribed to the canvas' TITLE_CHANGED messages"""
1043            self.update_title()
1044    
1045        def update_title(self):
1046            """Update the window's title according to it's current state.
1047    
1048            In this default implementation the title is 'Thuban - ' followed
1049            by the map's title or simply 'Thuban' if there is not map.
1050            Derived classes should override this method to get different
1051            titles.
1052    
1053            This method is called automatically by other methods when the
1054            title may have to change. For the methods implemented in this
1055            class this usually only means that a different map has been set
1056            or the current map's title has changed.
1057            """
1058            map = self.Map()
1059            if map is not None:
1060                title = _("Thuban - %s") % (map.Title(),)
1061            else:
1062                title = _("Thuban")
1063            self.SetTitle(title)
1064    
1065    
1066  #  #
1067  # Define all the commands available in the main window  # Define all the commands available in the main window
# Line 937  def _has_selected_layer(context): Line 1103  def _has_selected_layer(context):
1103      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
1104      return context.mainwindow.has_selected_layer()      return context.mainwindow.has_selected_layer()
1105    
1106    def _has_selected_layer_visible(context):
1107        """Return true if a layer is selected in the context which is
1108        visible."""
1109        if context.mainwindow.has_selected_layer():
1110            layer = context.mainwindow.current_layer()
1111            if layer.Visible(): return True
1112        return False
1113    
1114    def _has_selected_shape_layer(context):
1115        """Return true if a shape layer is selected in the context"""
1116        return context.mainwindow.has_selected_shape_layer()
1117    
1118  def _has_selected_shapes(context):  def _has_selected_shapes(context):
1119      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
1120      return context.mainwindow.has_selected_shapes()      return context.mainwindow.has_selected_shapes()
# Line 956  def _has_visible_map(context): Line 1134  def _has_visible_map(context):
1134      if map is not None:      if map is not None:
1135          for layer in map.Layers():          for layer in map.Layers():
1136              if layer.Visible():              if layer.Visible():
1137                  return 1                  return True
1138      return 0      return False
1139    
1140  def _has_legend_shown(context):  def _has_legend_shown(context):
1141      """Return true if the legend window is shown"""      """Return true if the legend window is shown"""
# Line 1073  _method_command("layer_hide", _("&Hide") Line 1251  _method_command("layer_hide", _("&Hide")
1251                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1252  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
1253                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
1254                  sensitive = _has_selected_layer)                  sensitive = _has_selected_shape_layer)
1255  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
1256                  sensitive = _has_selected_layer,                  sensitive = _has_selected_layer,
1257                  helptext = _("Edit the properties of the selected layer"))                  helptext = _("Edit the properties of the selected layer"))
1258  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1259                  sensitive = _has_selected_layer,                  sensitive = _has_selected_shape_layer,
1260                  helptext = _("Join and attach a table to the selected layer"))                  helptext = _("Join and attach a table to the selected layer"))
1261    
1262    # further layer methods:
1263    _method_command("layer_to_top", _("&Top"), "LayerToTop",
1264                    helptext = _("Put selected layer to the top"),
1265                    sensitive = _has_selected_layer)
1266    _method_command("layer_to_bottom", _("&Bottom"), "LayerToBottom",
1267                    helptext = _("Put selected layer to the bottom"),
1268                    sensitive = _has_selected_layer)
1269    _method_command("layer_visibility", _("&Visible"), "ToggleLayerVisibility",
1270                    checked = _has_selected_layer_visible,
1271                    helptext = _("Toggle visibility of selected layer"),
1272                    sensitive = _has_selected_layer)
1273    
1274  def _can_unjoin(context):  def _can_unjoin(context):
1275      """Return whether the Layer/Unjoin command can be executed.      """Return whether the Layer/Unjoin command can be executed.
1276    

Legend:
Removed from v.1644  
changed lines
  Added in v.2551

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26