/[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 2061 by bh, Fri Feb 13 10:46:44 2004 UTC revision 2534 by jan, Fri Jan 21 08:31:16 2005 UTC
# Line 35  from Thuban.UI.multiplechoicedialog impo Line 35  from Thuban.UI.multiplechoicedialog impo
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    
# Line 53  import Thuban.Model.resource Line 52  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 333  class MainWindow(DockFrame): Line 335  class MainWindow(DockFrame):
335          return self.dialogs.get(name)          return self.dialogs.get(name)
336    
337      def view_position_changed(self):      def view_position_changed(self):
338            """Put current position in status bar after a mouse move."""
339          pos = self.canvas.CurrentPosition()          pos = self.canvas.CurrentPosition()
340          if pos is not None:          if pos is not None:
341              text = "(%10.10g, %10.10g)" % pos              text = "(%10.10g, %10.10g)" % pos
342          else:          else:
343              text = ""              text = ""
344                # XXX This is a hack until we find a better place for this code.
345                # (BER 20050120)
346                # BH wrote (20050120):
347                # this branch is only executed when the mouse
348                # leaves the canvas window, so it's not that often [..]
349                # [Here] not the right place to put this code.  
350                # I don't have a better solution at hand,
351                # but the view_position_changed is only there to update
352                # the current position.  If other information is to
353                # be shown in the status bar it should
354                # be handled in a different way and
355                # by other methods.
356                #
357                # The status bar widget supports some kind of stack of texts.
358                # maybe that can be used to distinguis
359                # between short-lived information such as the mouse position
360                # and more permanent information such as the hint
361                # about the projections.
362                map = self.canvas.Map()
363                for layer in map.layers:
364                    bbox = layer.LatLongBoundingBox()
365                    if bbox:
366                        left, bottom, right, top = bbox
367                        if not (-180 <= left <= 180 and
368                            -180 <= right <= 180 and
369                            -90 <= top <= 90 and
370                            -90 <= bottom <= 90):
371                            text = _("Select layer '%s' and pick a projection "
372                                     "using Layer/Projection...") % layer.title
373                            break
374    
375          self.set_position_text(text)          self.set_position_text(text)
376    
377      def set_position_text(self, text):      def set_position_text(self, text):
# Line 349  class MainWindow(DockFrame): Line 383  class MainWindow(DockFrame):
383          """          """
384          self.SetStatusText(text)          self.SetStatusText(text)
385    
386        def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw):
387            """
388            Open or raise a dialog.
389    
390            If a dialog with the denoted name does already exist it is
391            raised.  Otherwise a new dialog, an instance of dialog_class,
392            is created, inserted into the main list and displayed.
393            """
394            dialog = self.get_open_dialog(name)
395    
396            if dialog is None:
397                dialog = dialog_class(self, name, *args, **kw)
398                self.add_dialog(name, dialog)
399                dialog.Show(True)
400            else:
401                dialog.Raise()
402                              
403      def save_modified_session(self, can_veto = 1):      def save_modified_session(self, can_veto = 1):
404          """If the current session has been modified, ask the user          """If the current session has been modified, ask the user
405          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 529  class MainWindow(DockFrame): Line 580  class MainWindow(DockFrame):
580          dlg = ChooseDBTableDialog(self, self.application.Session())          dlg = ChooseDBTableDialog(self, self.application.Session())
581    
582          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
583              dbconn, dbtable = dlg.GetTable()              dbconn, dbtable, id_column, geo_column = dlg.GetTable()
584              try:              try:
585                  title = str(dbtable)                  title = str(dbtable)
586    
587                  # Chose the correct Interface for the database type                  # Chose the correct Interface for the database type
588                  store = PostGISShapeStore(dbconn, dbtable)                  store = session.OpenDBShapeStore(dbconn, dbtable,
589                  session.AddShapeStore(store)                                                   id_column = id_column,
590                                                     geometry_column = geo_column)
591                  layer = Layer(title, store)                  layer = Layer(title, store)
592              except:              except:
593                  # Some error occured while initializing the layer                  # Some error occured while initializing the layer
# Line 571  class MainWindow(DockFrame): Line 623  class MainWindow(DockFrame):
623              return self.canvas.Map().CanRemoveLayer(layer)              return self.canvas.Map().CanRemoveLayer(layer)
624          return False          return False
625    
626        def LayerToTop(self):
627            layer = self.current_layer()
628            if layer is not None:
629                self.canvas.Map().MoveLayerToTop(layer)
630    
631      def RaiseLayer(self):      def RaiseLayer(self):
632          layer = self.current_layer()          layer = self.current_layer()
633          if layer is not None:          if layer is not None:
# Line 581  class MainWindow(DockFrame): Line 638  class MainWindow(DockFrame):
638          if layer is not None:          if layer is not None:
639              self.canvas.Map().LowerLayer(layer)              self.canvas.Map().LowerLayer(layer)
640    
641        def LayerToBottom(self):
642            layer = self.current_layer()
643            if layer is not None:
644                self.canvas.Map().MoveLayerToBottom(layer)
645    
646      def current_layer(self):      def current_layer(self):
647          """Return the currently selected layer.          """Return the currently selected layer.
648    
# Line 603  class MainWindow(DockFrame): Line 665  class MainWindow(DockFrame):
665      def HideLayer(self):      def HideLayer(self):
666          layer = self.current_layer()          layer = self.current_layer()
667          if layer is not None:          if layer is not None:
668              layer.SetVisible(0)              layer.SetVisible(False)
669    
670      def ShowLayer(self):      def ShowLayer(self):
671          layer = self.current_layer()          layer = self.current_layer()
672          if layer is not None:          if layer is not None:
673              layer.SetVisible(1)              layer.SetVisible(True)
674    
675        def ToggleLayerVisibility(self):
676            layer = self.current_layer()
677            layer.SetVisible(not layer.Visible())
678    
679      def DuplicateLayer(self):      def DuplicateLayer(self):
680          """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 619  class MainWindow(DockFrame): Line 685  class MainWindow(DockFrame):
685                                layer.ShapeStore(),                                layer.ShapeStore(),
686                                projection = layer.GetProjection())                                projection = layer.GetProjection())
687              new_classification = copy.deepcopy(layer.GetClassification())              new_classification = copy.deepcopy(layer.GetClassification())
688                new_layer.SetClassificationColumn(
689                        layer.GetClassificationColumn())
690              new_layer.SetClassification(new_classification)              new_layer.SetClassification(new_classification)
691              self.Map().AddLayer(new_layer)              self.Map().AddLayer(new_layer)
692    
# Line 628  class MainWindow(DockFrame): Line 696  class MainWindow(DockFrame):
696          return layer is not None and hasattr(layer, "ShapeStore")          return layer is not None and hasattr(layer, "ShapeStore")
697    
698      def LayerShowTable(self):      def LayerShowTable(self):
699            """
700            Present a TableView Window for the current layer.
701            In case the window is already open, bring it to the front.
702            In case, there is no active layer, do nothing.
703            In case, the layer has no ShapeStore, do nothing.
704            """
705          layer = self.current_layer()          layer = self.current_layer()
706          if layer is not None:          if layer is not None:
707                if not hasattr(layer, "ShapeStore"):
708                    return
709              table = layer.ShapeStore().Table()              table = layer.ShapeStore().Table()
710              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
711              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
# Line 640  class MainWindow(DockFrame): Line 716  class MainWindow(DockFrame):
716                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
717                  dialog.Show(True)                  dialog.Show(True)
718              else:              else:
719                  # FIXME: bring dialog to front here                  dialog.Raise()
                 pass  
720    
721      def MapProjection(self):      def MapProjection(self):
722    
# Line 683  class MainWindow(DockFrame): Line 758  class MainWindow(DockFrame):
758          self.OpenLayerProperties(layer)          self.OpenLayerProperties(layer)
759    
760      def OpenLayerProperties(self, layer, group = None):      def OpenLayerProperties(self, layer, group = None):
761          name = "layer_properties" + str(id(layer))          """
762          dialog = self.get_open_dialog(name)          Open or raise the properties dialog.
763    
764          if dialog is None:          This method opens or raises the properties dialog for the
765              dialog = Classifier(self, name, self.Map(), layer, group)          currently selected layer if one is defined for this layer
766              self.add_dialog(name, dialog)          type.
767              dialog.Show()          """
768          dialog.Raise()          dialog_class = layer_properties_dialogs.get(layer)
769    
770            if dialog_class is not None:
771                name = "layer_properties" + str(id(layer))
772                self.OpenOrRaiseDialog(name, dialog_class, layer, group = group)
773    
774      def LayerJoinTable(self):      def LayerJoinTable(self):
775          layer = self.canvas.SelectedLayer()          layer = self.canvas.SelectedLayer()
# Line 986  def _has_selected_layer(context): Line 1065  def _has_selected_layer(context):
1065      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
1066      return context.mainwindow.has_selected_layer()      return context.mainwindow.has_selected_layer()
1067    
1068    def _has_selected_layer_visible(context):
1069        """Return true if a layer is selected in the context which is
1070        visible."""
1071        if context.mainwindow.has_selected_layer():
1072            layer = context.mainwindow.current_layer()
1073            if layer.Visible(): return True
1074        return False
1075    
1076  def _has_selected_shape_layer(context):  def _has_selected_shape_layer(context):
1077      """Return true if a shape layer is selected in the context"""      """Return true if a shape layer is selected in the context"""
1078      return context.mainwindow.has_selected_shape_layer()      return context.mainwindow.has_selected_shape_layer()
# Line 1009  def _has_visible_map(context): Line 1096  def _has_visible_map(context):
1096      if map is not None:      if map is not None:
1097          for layer in map.Layers():          for layer in map.Layers():
1098              if layer.Visible():              if layer.Visible():
1099                  return 1                  return True
1100      return 0      return False
1101    
1102  def _has_legend_shown(context):  def _has_legend_shown(context):
1103      """Return true if the legend window is shown"""      """Return true if the legend window is shown"""
# Line 1134  _method_command("layer_jointable", _("&J Line 1221  _method_command("layer_jointable", _("&J
1221                  sensitive = _has_selected_shape_layer,                  sensitive = _has_selected_shape_layer,
1222                  helptext = _("Join and attach a table to the selected layer"))                  helptext = _("Join and attach a table to the selected layer"))
1223    
1224    # further layer methods:
1225    _method_command("layer_to_top", _("&Top"), "LayerToTop",
1226                    helptext = _("Put selected layer to the top"),
1227                    sensitive = _has_selected_layer)
1228    _method_command("layer_to_bottom", _("&Bottom"), "LayerToBottom",
1229                    helptext = _("Put selected layer to the bottom"),
1230                    sensitive = _has_selected_layer)
1231    _method_command("layer_visibility", _("&Visible"), "ToggleLayerVisibility",
1232                    checked = _has_selected_layer_visible,
1233                    helptext = _("Toggle visibility of selected layer"),
1234                    sensitive = _has_selected_layer)
1235    
1236  def _can_unjoin(context):  def _can_unjoin(context):
1237      """Return whether the Layer/Unjoin command can be executed.      """Return whether the Layer/Unjoin command can be executed.
1238    

Legend:
Removed from v.2061  
changed lines
  Added in v.2534

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26