/[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 1287 by jonathan, Mon Jun 23 10:47:11 2003 UTC revision 2364 by joey, Fri Oct 1 18:18:49 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.8" #"$THUBAN_0_2$"  # $Id$
 #__BuildDate__ = "$Date$"  
17    
18  import os  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
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  # XXX: replace this by
31  # from wxPython.lib.dialogs import wxMultipleChoiceDialog  # from wxPython.lib.dialogs import wxMultipleChoiceDialog
32  # when Thuban does not support wxPython 2.4.0 any more.  # when Thuban does not support wxPython 2.4.0 any more.
# Line 43  from menu import Menu Line 41  from menu import Menu
41    
42  from context import Context  from context import Context
43  from command import registry, Command, ToolCommand  from command import registry, Command, ToolCommand
44  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, \
45         MAP_REPLACED
46    from about import About
47    
48  from Thuban.UI.dock import DockFrame  from Thuban.UI.dock import DockFrame
49  from Thuban.UI.join import JoinDialog  from Thuban.UI.join import JoinDialog
50    from Thuban.UI.dbdialog import DBFrame, DBDialog, ChooseDBTableDialog
51  import resource  import resource
52  import Thuban.Model.resource  import Thuban.Model.resource
53    
54  import projdialog  import projdialog
55    
56    
57  class MainWindow(DockFrame):  class MainWindow(DockFrame):
58    
59      # Some messages that can be subscribed/unsubscribed directly through      # Some messages that can be subscribed/unsubscribed directly through
# Line 61  class MainWindow(DockFrame): Line 62  class MainWindow(DockFrame):
62      # actually come from. This delegation is implemented in the      # actually come from. This delegation is implemented in the
63      # Subscribe and unsubscribed methods      # Subscribe and unsubscribed methods
64      delegated_messages = {LAYER_SELECTED: "canvas",      delegated_messages = {LAYER_SELECTED: "canvas",
65                            SHAPES_SELECTED: "canvas"}                            SHAPES_SELECTED: "canvas",
66                              MAP_REPLACED: "canvas"}
67    
68      # Methods delegated to some instance variables. The delegation is      # Methods delegated to some instance variables. The delegation is
69      # implemented in the __getattr__ method.      # implemented in the __getattr__ method.
# Line 100  class MainWindow(DockFrame): Line 102  class MainWindow(DockFrame):
102          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)
103          canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)          canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)
104          self.canvas = canvas          self.canvas = canvas
105            self.canvas.Subscribe(TITLE_CHANGED, self.title_changed)
106    
107          self.SetMainWindow(self.canvas)          self.SetMainWindow(self.canvas)
108    
# Line 131  class MainWindow(DockFrame): Line 134  class MainWindow(DockFrame):
134          """          """
135          if channel in self.delegated_messages:          if channel in self.delegated_messages:
136              object = getattr(self, self.delegated_messages[channel])              object = getattr(self, self.delegated_messages[channel])
137              object.Unsubscribe(channel, *args)              try:
138                    object.Unsubscribe(channel, *args)
139                except wxPyDeadObjectError:
140                    # The object was a wxObject and has already been
141                    # destroyed. Hopefully it has unsubscribed all its
142                    # subscribers already so that it's OK if we do nothing
143                    # here
144                    pass
145    
146      def __getattr__(self, attr):      def __getattr__(self, attr):
147          """If attr is one of the delegated methods return that method          """If attr is one of the delegated methods return that method
# Line 339  class MainWindow(DockFrame): Line 349  class MainWindow(DockFrame):
349          """          """
350          self.SetStatusText(text)          self.SetStatusText(text)
351    
352        def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw):
353            """
354            Open or raise a dialog.
355    
356            If a dialog with the denoted name does already exist it is
357            raised.  Otherwise a new dialog, an instance of dialog_class,
358            is created, inserted into the main list and displayed.
359            """
360            dialog = self.get_open_dialog(name)
361    
362            if dialog is None:
363                dialog = dialog_class(self, name, *args, **kw)
364                self.add_dialog(name, dialog)
365                dialog.Show(True)
366            else:
367                dialog.Raise()
368                              
369      def save_modified_session(self, can_veto = 1):      def save_modified_session(self, can_veto = 1):
370          """If the current session has been modified, ask the user          """If the current session has been modified, ask the user
371          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 362  class MainWindow(DockFrame): Line 389  class MainWindow(DockFrame):
389              result = wxID_NO              result = wxID_NO
390          return result          return result
391    
     def prepare_new_session(self):  
         for d in self.dialogs.values():  
             if not isinstance(d, tree.SessionTreeView):  
                 d.Close()  
   
392      def NewSession(self):      def NewSession(self):
393          if self.save_modified_session() != wxID_CANCEL:          if self.save_modified_session() != wxID_CANCEL:
             self.prepare_new_session()  
394              self.application.SetSession(create_empty_session())              self.application.SetSession(create_empty_session())
395    
396      def OpenSession(self):      def OpenSession(self):
397          if self.save_modified_session() != wxID_CANCEL:          if self.save_modified_session() != wxID_CANCEL:
398              dlg = wxFileDialog(self, _("Open Session"), ".", "",              dlg = wxFileDialog(self, _("Open Session"),
399                                   self.application.Path("data"), "",
400                                 "Thuban Session File (*.thuban)|*.thuban",                                 "Thuban Session File (*.thuban)|*.thuban",
401                                 wxOPEN)                                 wxOPEN)
402              if dlg.ShowModal() == wxID_OK:              if dlg.ShowModal() == wxID_OK:
403                  self.prepare_new_session()                  self.application.OpenSession(dlg.GetPath(),
404                  self.application.OpenSession(dlg.GetPath())                                               self.run_db_param_dialog)
405                    self.application.SetPath("data", dlg.GetPath())
406              dlg.Destroy()              dlg.Destroy()
407    
408        def run_db_param_dialog(self, parameters, message):
409            dlg = DBDialog(self, _("DB Connection Parameters"), parameters,
410                           message)
411            return dlg.RunDialog()
412    
413      def SaveSession(self):      def SaveSession(self):
414          if self.application.session.filename == None:          if self.application.session.filename == None:
415              self.SaveSessionAs()              self.SaveSessionAs()
# Line 389  class MainWindow(DockFrame): Line 417  class MainWindow(DockFrame):
417              self.application.SaveSession()              self.application.SaveSession()
418    
419      def SaveSessionAs(self):      def SaveSessionAs(self):
420          dlg = wxFileDialog(self, _("Save Session As"), ".", "",          dlg = wxFileDialog(self, _("Save Session As"),
421                               self.application.Path("data"), "",
422                             "Thuban Session File (*.thuban)|*.thuban",                             "Thuban Session File (*.thuban)|*.thuban",
423                             wxSAVE|wxOVERWRITE_PROMPT)                             wxSAVE|wxOVERWRITE_PROMPT)
424          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
425              self.application.session.SetFilename(dlg.GetPath())              self.application.session.SetFilename(dlg.GetPath())
426              self.application.SaveSession()              self.application.SaveSession()
427                self.application.SetPath("data",dlg.GetPath())
428          dlg.Destroy()          dlg.Destroy()
429    
430      def Exit(self):      def Exit(self):
# Line 417  class MainWindow(DockFrame): Line 447  class MainWindow(DockFrame):
447    
448      def SetMap(self, map):      def SetMap(self, map):
449          self.canvas.SetMap(map)          self.canvas.SetMap(map)
450          self.__SetTitle(map.Title())          self.update_title()
451    
452          dialog = self.FindRegisteredDock("legend")          dialog = self.FindRegisteredDock("legend")
453          if dialog is not None:          if dialog is not None:
# Line 444  class MainWindow(DockFrame): Line 474  class MainWindow(DockFrame):
474          return self.get_open_dialog("session_tree") is not None          return self.get_open_dialog("session_tree") is not None
475    
476      def About(self):      def About(self):
477          self.RunMessageBox(_("About"),          dlg = About(self)
478                             _("Thuban %s\n\n"          dlg.ShowModal()
479                              #"Build Date: %s\n"          dlg.Destroy()
480                              "Currently using:\n"  
481                              "  %s\n"      def DatabaseManagement(self):
482                              "  %s\n\n"          name = "dbmanagement"
483                              "Thuban is a program for\n"          dialog = self.get_open_dialog(name)
484                              "exploring geographic data.\n"          if dialog is None:
485                              "Copyright (C) 2001-2003 Intevation GmbH.\n"              map = self.canvas.Map()
486                              "Thuban is licensed under the GNU GPL"              dialog = DBFrame(self, name, self.application.Session())
487                              % (Thuban.version.longversion,              self.add_dialog(name, dialog)
488                                 "wxPython %s" % wxPython_version,              dialog.Show()
489                                 "Python %d.%d.%d" % sys.version_info[:3]          dialog.Raise()
                               )),  
 #                           % __ThubanVersion__), #__BuildDate__)),  
                            wxOK | wxICON_INFORMATION)  
490    
491      def AddLayer(self):      def AddLayer(self):
492          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",          dlg = wxFileDialog(self, _("Select one or more data files"),
493                             wxOPEN)                             self.application.Path("data"), "",
494                               _("Shapefiles (*.shp)") + "|*.shp;*.SHP|" +
495                               _("All Files (*.*)") + "|*.*",
496                               wxOPEN | wxMULTIPLE)
497          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
498              filename = dlg.GetPath()              filenames = dlg.GetPaths()
499              title = os.path.splitext(os.path.basename(filename))[0]              for filename in filenames:
500              map = self.canvas.Map()                  title = os.path.splitext(os.path.basename(filename))[0]
501              has_layers = map.HasLayers()                  map = self.canvas.Map()
502              try:                  has_layers = map.HasLayers()
503                  store = self.application.Session().OpenShapefile(filename)                  try:
504              except IOError:                      store = self.application.Session().OpenShapefile(filename)
505                  # the layer couldn't be opened                  except IOError:
506                  self.RunMessageBox(_("Add Layer"),                      # the layer couldn't be opened
507                                     _("Can't open the file '%s'.") % filename)                      self.RunMessageBox(_("Add Layer"),
508              else:                                         _("Can't open the file '%s'.")%filename)
509                  layer = Layer(title, store)                  else:
510                  map.AddLayer(layer)                      layer = Layer(title, store)
511                  if not has_layers:                      map.AddLayer(layer)
512                      # if we're adding a layer to an empty map, fit the                      if not has_layers:
513                      # new map to the window                          # if we're adding a layer to an empty map, fit the
514                      self.canvas.FitMapToWindow()                          # new map to the window
515                            self.canvas.FitMapToWindow()
516                        self.application.SetPath("data",filename)
517          dlg.Destroy()          dlg.Destroy()
518    
519      def AddRasterLayer(self):      def AddRasterLayer(self):
520          dlg = wxFileDialog(self, _("Select an image file"), ".", "", "*.*",          dlg = wxFileDialog(self, _("Select an image file"),
521                               self.application.Path("data"), "", "*.*",
522                             wxOPEN)                             wxOPEN)
523          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
524              filename = dlg.GetPath()              filename = dlg.GetPath()
# Line 504  class MainWindow(DockFrame): Line 537  class MainWindow(DockFrame):
537                      # if we're adding a layer to an empty map, fit the                      # if we're adding a layer to an empty map, fit the
538                      # new map to the window                      # new map to the window
539                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
540                    self.application.SetPath("data", filename)
541            dlg.Destroy()
542    
543        def AddDBLayer(self):
544            """Add a layer read from a database"""
545            session = self.application.Session()
546            dlg = ChooseDBTableDialog(self, self.application.Session())
547    
548            if dlg.ShowModal() == wxID_OK:
549                dbconn, dbtable, id_column, geo_column = dlg.GetTable()
550                try:
551                    title = str(dbtable)
552    
553                    # Chose the correct Interface for the database type
554                    store = session.OpenDBShapeStore(dbconn, dbtable,
555                                                     id_column = id_column,
556                                                     geometry_column = geo_column)
557                    layer = Layer(title, store)
558                except:
559                    # Some error occured while initializing the layer
560                    self.RunMessageBox(_("Add Layer from database"),
561                                       _("Can't open the database table '%s'")
562                                       % dbtable)
563                    return
564    
565                map = self.canvas.Map()
566    
567                has_layers = map.HasLayers()
568                map.AddLayer(layer)
569                if not has_layers:
570                    self.canvas.FitMapToWindow()
571    
572          dlg.Destroy()          dlg.Destroy()
573    
574      def RemoveLayer(self):      def RemoveLayer(self):
# Line 524  class MainWindow(DockFrame): Line 589  class MainWindow(DockFrame):
589              return self.canvas.Map().CanRemoveLayer(layer)              return self.canvas.Map().CanRemoveLayer(layer)
590          return False          return False
591    
592        def LayerToTop(self):
593            layer = self.current_layer()
594            if layer is not None:
595                self.canvas.Map().MoveLayerToTop(layer)
596    
597      def RaiseLayer(self):      def RaiseLayer(self):
598          layer = self.current_layer()          layer = self.current_layer()
599          if layer is not None:          if layer is not None:
# Line 534  class MainWindow(DockFrame): Line 604  class MainWindow(DockFrame):
604          if layer is not None:          if layer is not None:
605              self.canvas.Map().LowerLayer(layer)              self.canvas.Map().LowerLayer(layer)
606    
607        def LayerToBottom(self):
608            layer = self.current_layer()
609            if layer is not None:
610                self.canvas.Map().MoveLayerToBottom(layer)
611    
612      def current_layer(self):      def current_layer(self):
613          """Return the currently selected layer.          """Return the currently selected layer.
614    
# Line 545  class MainWindow(DockFrame): Line 620  class MainWindow(DockFrame):
620          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
621          return self.canvas.HasSelectedLayer()          return self.canvas.HasSelectedLayer()
622    
623        def has_selected_shape_layer(self):
624            """Return true if a shape layer is currently selected"""
625            return isinstance(self.current_layer(), Layer)
626    
627      def has_selected_shapes(self):      def has_selected_shapes(self):
628          """Return true if a shape is currently selected"""          """Return true if a shape is currently selected"""
629          return self.canvas.HasSelectedShapes()          return self.canvas.HasSelectedShapes()
# Line 552  class MainWindow(DockFrame): Line 631  class MainWindow(DockFrame):
631      def HideLayer(self):      def HideLayer(self):
632          layer = self.current_layer()          layer = self.current_layer()
633          if layer is not None:          if layer is not None:
634              layer.SetVisible(0)              layer.SetVisible(False)
635    
636      def ShowLayer(self):      def ShowLayer(self):
637          layer = self.current_layer()          layer = self.current_layer()
638          if layer is not None:          if layer is not None:
639              layer.SetVisible(1)              layer.SetVisible(True)
640    
641        def ToggleLayerVisibility(self):
642            layer = self.current_layer()
643            layer.SetVisible(not layer.Visible())
644    
645      def DuplicateLayer(self):      def DuplicateLayer(self):
646          """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 577  class MainWindow(DockFrame): Line 660  class MainWindow(DockFrame):
660          return layer is not None and hasattr(layer, "ShapeStore")          return layer is not None and hasattr(layer, "ShapeStore")
661    
662      def LayerShowTable(self):      def LayerShowTable(self):
663            """
664            Present a TableView Window for the current layer.
665            In case the window is already open, bring it to the front.
666            In case, there is no active layer, do nothing.
667            In case, the layer has no ShapeStore, do nothing.
668            """
669          layer = self.current_layer()          layer = self.current_layer()
670          if layer is not None:          if layer is not None:
671                if not hasattr(layer, "ShapeStore"):
672                    return
673              table = layer.ShapeStore().Table()              table = layer.ShapeStore().Table()
674              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
675              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
# Line 589  class MainWindow(DockFrame): Line 680  class MainWindow(DockFrame):
680                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
681                  dialog.Show(True)                  dialog.Show(True)
682              else:              else:
683                  # FIXME: bring dialog to front here                  dialog.Raise()
                 pass  
684    
685      def MapProjection(self):      def MapProjection(self):
686    
# Line 632  class MainWindow(DockFrame): Line 722  class MainWindow(DockFrame):
722          self.OpenLayerProperties(layer)          self.OpenLayerProperties(layer)
723    
724      def OpenLayerProperties(self, layer, group = None):      def OpenLayerProperties(self, layer, group = None):
725          name = "layer_properties" + str(id(layer))          """
726          dialog = self.get_open_dialog(name)          Open or raise the properties dialog.
   
         if dialog is None:  
             dialog = Classifier(self, name, self.Map(), layer, group)  
             self.add_dialog(name, dialog)  
             dialog.Show()  
         dialog.Raise()  
727    
728            This method opens or raises the properties dialog for the
729            currently selected layer if one is defined for this layer
730            type.
731            """
732            name = "layer_properties" + str(id(layer))
733            self.OpenOrRaiseDialog(name, Classifier, layer, group = group)
734            
735      def LayerJoinTable(self):      def LayerJoinTable(self):
736          layer = self.canvas.SelectedLayer()          layer = self.canvas.SelectedLayer()
737          if layer is not None:          if layer is not None:
# Line 674  class MainWindow(DockFrame): Line 765  class MainWindow(DockFrame):
765          else:          else:
766              dialog.Show(not dialog.IsShown())              dialog.Show(not dialog.IsShown())
767    
         self.canvas.FitMapToWindow()  
   
768      def LegendShown(self):      def LegendShown(self):
769          """Return true iff the legend is currently open"""          """Return true iff the legend is currently open"""
770          dialog = self.FindRegisteredDock("legend")          dialog = self.FindRegisteredDock("legend")
771          return dialog is not None and dialog.IsShown()          return dialog is not None and dialog.IsShown()
772    
773      def TableOpen(self):      def TableOpen(self):
774          dlg = wxFileDialog(self, _("Open Table"), ".", "",          dlg = wxFileDialog(self, _("Open Table"),
775                               self.application.Path("data"), "",
776                             _("DBF Files (*.dbf)") + "|*.dbf|" +                             _("DBF Files (*.dbf)") + "|*.dbf|" +
777                             #_("CSV Files (*.csv)") + "|*.csv|" +                             #_("CSV Files (*.csv)") + "|*.csv|" +
778                             _("All Files (*.*)") + "|*.*",                             _("All Files (*.*)") + "|*.*",
# Line 698  class MainWindow(DockFrame): Line 788  class MainWindow(DockFrame):
788                                     _("Can't open the file '%s'.") % filename)                                     _("Can't open the file '%s'.") % filename)
789              else:              else:
790                  self.ShowTableView(table)                  self.ShowTableView(table)
791                    self.application.SetPath("data",filename)
792    
793      def TableClose(self):      def TableClose(self):
794          tables = self.application.session.UnreferencedTables()          tables = self.application.session.UnreferencedTables()
# Line 751  class MainWindow(DockFrame): Line 842  class MainWindow(DockFrame):
842                                                 table)                                                 table)
843              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
844              dialog.Show(True)              dialog.Show(True)
845          # FIXME: else bring dialog to front          dialog.Raise()
846    
847      def TableRename(self):      def TableRename(self):
848          """Let the user rename a table"""          """Let the user rename a table"""
# Line 774  class MainWindow(DockFrame): Line 865  class MainWindow(DockFrame):
865    
866          # Second, let the user rename the layers          # Second, let the user rename the layers
867          for table in to_rename:          for table in to_rename:
868              dlg = wxTextEntryDialog(self, "Table Title: ", "Rename Table",              dlg = wxTextEntryDialog(self, _("Table Title:"), _("Rename Table"),
869                                      table.Title())                                      table.Title())
870              try:              try:
871                  if dlg.ShowModal() == wxID_OK:                  if dlg.ShowModal() == wxID_OK:
# Line 823  class MainWindow(DockFrame): Line 914  class MainWindow(DockFrame):
914          self.canvas.Print()          self.canvas.Print()
915    
916      def RenameMap(self):      def RenameMap(self):
917          dlg = wxTextEntryDialog(self, "Map Title: ", "Rename Map",          dlg = wxTextEntryDialog(self, _("Map Title:"), _("Rename Map"),
918                                  self.Map().Title())                                  self.Map().Title())
919          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
920              title = dlg.GetValue()              title = dlg.GetValue()
921              if title != "":              if title != "":
922                  self.Map().SetTitle(title)                  self.Map().SetTitle(title)
                 self.__SetTitle(title)  
923    
924          dlg.Destroy()          dlg.Destroy()
925    
# Line 837  class MainWindow(DockFrame): Line 927  class MainWindow(DockFrame):
927          """Let the user rename the currently selected layer"""          """Let the user rename the currently selected layer"""
928          layer = self.current_layer()          layer = self.current_layer()
929          if layer is not None:          if layer is not None:
930              dlg = wxTextEntryDialog(self, "Layer Title: ", "Rename Layer",              dlg = wxTextEntryDialog(self, _("Layer Title:"), _("Rename Layer"),
931                                      layer.Title())                                      layer.Title())
932              try:              try:
933                  if dlg.ShowModal() == wxID_OK:                  if dlg.ShowModal() == wxID_OK:
# Line 871  class MainWindow(DockFrame): Line 961  class MainWindow(DockFrame):
961                  # FIXME: bring dialog to front?                  # FIXME: bring dialog to front?
962                  pass                  pass
963    
964      def __SetTitle(self, title):      def title_changed(self, map):
965          self.SetTitle("Thuban - " + title)          """Subscribed to the canvas' TITLE_CHANGED messages"""
966            self.update_title()
967    
968        def update_title(self):
969            """Update the window's title according to it's current state.
970    
971            In this default implementation the title is 'Thuban - ' followed
972            by the map's title or simply 'Thuban' if there is not map.
973            Derived classes should override this method to get different
974            titles.
975    
976            This method is called automatically by other methods when the
977            title may have to change. For the methods implemented in this
978            class this usually only means that a different map has been set
979            or the current map's title has changed.
980            """
981            map = self.Map()
982            if map is not None:
983                title = _("Thuban - %s") % (map.Title(),)
984            else:
985                title = _("Thuban")
986            self.SetTitle(title)
987    
988    
989  #  #
990  # Define all the commands available in the main window  # Define all the commands available in the main window
# Line 914  def _has_selected_layer(context): Line 1026  def _has_selected_layer(context):
1026      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
1027      return context.mainwindow.has_selected_layer()      return context.mainwindow.has_selected_layer()
1028    
1029    def _has_selected_layer_visible(context):
1030        """Return true if a layer is selected in the context which is
1031        visible."""
1032        if context.mainwindow.has_selected_layer():
1033            layer = context.mainwindow.current_layer()
1034            if layer.Visible(): return True
1035        return False
1036    
1037    def _has_selected_shape_layer(context):
1038        """Return true if a shape layer is selected in the context"""
1039        return context.mainwindow.has_selected_shape_layer()
1040    
1041  def _has_selected_shapes(context):  def _has_selected_shapes(context):
1042      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
1043      return context.mainwindow.has_selected_shapes()      return context.mainwindow.has_selected_shapes()
# Line 933  def _has_visible_map(context): Line 1057  def _has_visible_map(context):
1057      if map is not None:      if map is not None:
1058          for layer in map.Layers():          for layer in map.Layers():
1059              if layer.Visible():              if layer.Visible():
1060                  return 1                  return True
1061      return 0      return False
1062    
1063  def _has_legend_shown(context):  def _has_legend_shown(context):
1064      """Return true if the legend window is shown"""      """Return true if the legend window is shown"""
# Line 944  def _has_gdal_support(context): Line 1068  def _has_gdal_support(context):
1068      """Return True if the GDAL is available"""      """Return True if the GDAL is available"""
1069      return Thuban.Model.resource.has_gdal_support()      return Thuban.Model.resource.has_gdal_support()
1070    
1071    def _has_dbconnections(context):
1072        """Return whether the the session has database connections"""
1073        return context.session.HasDBConnections()
1074    
1075    def _has_postgis_support(context):
1076        return has_postgis_support()
1077    
1078    
1079  # File menu  # File menu
1080  _method_command("new_session", _("&New Session"), "NewSession",  _method_command("new_session", _("&New Session"), "NewSession",
1081                  helptext = _("Start a new session"))                  helptext = _("Start a new session"))
# Line 959  _method_command("toggle_session_tree", _ Line 1091  _method_command("toggle_session_tree", _
1091  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
1092                  checked = _has_legend_shown,                  checked = _has_legend_shown,
1093                  helptext = _("Toggle Legend on/off"))                  helptext = _("Toggle Legend on/off"))
1094    _method_command("database_management", _("&Database Connections..."),
1095                    "DatabaseManagement",
1096                    sensitive = _has_postgis_support)
1097  _method_command("exit", _("E&xit"), "Exit",  _method_command("exit", _("E&xit"), "Exit",
1098                  helptext = _("Finish working with Thuban"))                  helptext = _("Finish working with Thuban"))
1099    
# Line 1008  _method_command("layer_add", _("&Add Lay Line 1143  _method_command("layer_add", _("&Add Lay
1143  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
1144                  helptext = _("Add a new image layer to the map"),                  helptext = _("Add a new image layer to the map"),
1145                  sensitive = _has_gdal_support)                  sensitive = _has_gdal_support)
1146    _method_command("layer_add_db", _("Add &Database Layer..."), "AddDBLayer",
1147                    helptext = _("Add a new database layer to active map"),
1148                    sensitive = _has_dbconnections)
1149  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
1150                  helptext = _("Remove selected layer"),                  helptext = _("Remove selected layer"),
1151                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
# Line 1036  _method_command("layer_hide", _("&Hide") Line 1174  _method_command("layer_hide", _("&Hide")
1174                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1175  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
1176                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
1177                  sensitive = _has_selected_layer)                  sensitive = _has_selected_shape_layer)
1178  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
1179                  sensitive = _has_selected_layer,                  sensitive = _has_selected_layer,
1180                  helptext = _("Edit the properties of the selected layer"))                  helptext = _("Edit the properties of the selected layer"))
1181  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1182                  sensitive = _has_selected_layer,                  sensitive = _has_selected_shape_layer,
1183                  helptext = _("Join and attach a table to the selected layer"))                  helptext = _("Join and attach a table to the selected layer"))
1184    
1185    # further layer methods:
1186    _method_command("layer_to_top", _("&Top"), "LayerToTop",
1187                    helptext = _("Put selected layer to the top"),
1188                    sensitive = _has_selected_layer)
1189    _method_command("layer_to_bottom", _("&Bottom"), "LayerToBottom",
1190                    helptext = _("Put selected layer to the bottom"),
1191                    sensitive = _has_selected_layer)
1192    _method_command("layer_visibility", _("&Visible"), "ToggleLayerVisibility",
1193                    checked = _has_selected_layer_visible,
1194                    helptext = _("Toggle visibility of selected layer"),
1195                    sensitive = _has_selected_layer)
1196    
1197  def _can_unjoin(context):  def _can_unjoin(context):
1198      """Return whether the Layer/Unjoin command can be executed.      """Return whether the Layer/Unjoin command can be executed.
1199    
# Line 1083  _method_command("table_join", _("&Join.. Line 1233  _method_command("table_join", _("&Join..
1233                  helptext = _("Join two tables creating a new one"))                  helptext = _("Join two tables creating a new one"))
1234    
1235  #  Export only under Windows ...  #  Export only under Windows ...
1236  map_menu = ["layer_add", "rasterlayer_add", "layer_remove",  map_menu = ["layer_add", "layer_add_db", "rasterlayer_add", "layer_remove",
1237                          None,                          None,
1238                          "map_rename",                          "map_rename",
1239                          "map_projection",                          "map_projection",
1240                          None,                          None,
1241                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
1242                          "map_pan_tool",                          "map_pan_tool",
1243                          "map_full_extent",                          "map_full_extent",
1244                          "layer_full_extent",                          "layer_full_extent",
1245                          "selected_full_extent",                          "selected_full_extent",
1246                          None,                          None,
# Line 1107  main_menu = Menu("<main>", "<main>", Line 1257  main_menu = Menu("<main>", "<main>",
1257                   [Menu("file", _("&File"),                   [Menu("file", _("&File"),
1258                         ["new_session", "open_session", None,                         ["new_session", "open_session", None,
1259                          "save_session", "save_session_as", None,                          "save_session", "save_session_as", None,
1260                            "database_management", None,
1261                          "toggle_session_tree", None,                          "toggle_session_tree", None,
1262                          "exit"]),                          "exit"]),
1263                    Menu("map", _("&Map"), map_menu),                    Menu("map", _("&Map"), map_menu),
# Line 1142  main_toolbar = Menu("<toolbar>", "<toolb Line 1293  main_toolbar = Menu("<toolbar>", "<toolb
1293                       "selected_full_extent",                       "selected_full_extent",
1294                       None,                       None,
1295                       "map_identify_tool", "map_label_tool"])                       "map_identify_tool", "map_label_tool"])
1296    

Legend:
Removed from v.1287  
changed lines
  Added in v.2364

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26