/[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 2529 by russell, Thu Jan 20 17:55:23 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 338  class MainWindow(DockFrame): Line 340  class MainWindow(DockFrame):
340              text = "(%10.10g, %10.10g)" % pos              text = "(%10.10g, %10.10g)" % pos
341          else:          else:
342              text = ""              text = ""
343                map = self.canvas.Map()
344                for layer in map.layers:
345                    bbox = layer.LatLongBoundingBox()
346                    if bbox:
347                        left, bottom, right, top = bbox
348                        if not (-180 <= left <= 180 and
349                            -180 <= right <= 180 and
350                            -90 <= top <= 90 and
351                            -90 <= bottom <= 90):
352                            text = ("Select '"+layer.title+"' and pick a " +
353                                "projection using Layer/Projection...")
354                            break
355    
356          self.set_position_text(text)          self.set_position_text(text)
357    
358      def set_position_text(self, text):      def set_position_text(self, text):
# Line 349  class MainWindow(DockFrame): Line 364  class MainWindow(DockFrame):
364          """          """
365          self.SetStatusText(text)          self.SetStatusText(text)
366    
367        def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw):
368            """
369            Open or raise a dialog.
370    
371            If a dialog with the denoted name does already exist it is
372            raised.  Otherwise a new dialog, an instance of dialog_class,
373            is created, inserted into the main list and displayed.
374            """
375            dialog = self.get_open_dialog(name)
376    
377            if dialog is None:
378                dialog = dialog_class(self, name, *args, **kw)
379                self.add_dialog(name, dialog)
380                dialog.Show(True)
381            else:
382                dialog.Raise()
383                              
384      def save_modified_session(self, can_veto = 1):      def save_modified_session(self, can_veto = 1):
385          """If the current session has been modified, ask the user          """If the current session has been modified, ask the user
386          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 561  class MainWindow(DockFrame):
561          dlg = ChooseDBTableDialog(self, self.application.Session())          dlg = ChooseDBTableDialog(self, self.application.Session())
562    
563          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
564              dbconn, dbtable = dlg.GetTable()              dbconn, dbtable, id_column, geo_column = dlg.GetTable()
565              try:              try:
566                  title = str(dbtable)                  title = str(dbtable)
567    
568                  # Chose the correct Interface for the database type                  # Chose the correct Interface for the database type
569                  store = PostGISShapeStore(dbconn, dbtable)                  store = session.OpenDBShapeStore(dbconn, dbtable,
570                  session.AddShapeStore(store)                                                   id_column = id_column,
571                                                     geometry_column = geo_column)
572                  layer = Layer(title, store)                  layer = Layer(title, store)
573              except:              except:
574                  # Some error occured while initializing the layer                  # Some error occured while initializing the layer
# Line 571  class MainWindow(DockFrame): Line 604  class MainWindow(DockFrame):
604              return self.canvas.Map().CanRemoveLayer(layer)              return self.canvas.Map().CanRemoveLayer(layer)
605          return False          return False
606    
607        def LayerToTop(self):
608            layer = self.current_layer()
609            if layer is not None:
610                self.canvas.Map().MoveLayerToTop(layer)
611    
612      def RaiseLayer(self):      def RaiseLayer(self):
613          layer = self.current_layer()          layer = self.current_layer()
614          if layer is not None:          if layer is not None:
# Line 581  class MainWindow(DockFrame): Line 619  class MainWindow(DockFrame):
619          if layer is not None:          if layer is not None:
620              self.canvas.Map().LowerLayer(layer)              self.canvas.Map().LowerLayer(layer)
621    
622        def LayerToBottom(self):
623            layer = self.current_layer()
624            if layer is not None:
625                self.canvas.Map().MoveLayerToBottom(layer)
626    
627      def current_layer(self):      def current_layer(self):
628          """Return the currently selected layer.          """Return the currently selected layer.
629    
# Line 603  class MainWindow(DockFrame): Line 646  class MainWindow(DockFrame):
646      def HideLayer(self):      def HideLayer(self):
647          layer = self.current_layer()          layer = self.current_layer()
648          if layer is not None:          if layer is not None:
649              layer.SetVisible(0)              layer.SetVisible(False)
650    
651      def ShowLayer(self):      def ShowLayer(self):
652          layer = self.current_layer()          layer = self.current_layer()
653          if layer is not None:          if layer is not None:
654              layer.SetVisible(1)              layer.SetVisible(True)
655    
656        def ToggleLayerVisibility(self):
657            layer = self.current_layer()
658            layer.SetVisible(not layer.Visible())
659    
660      def DuplicateLayer(self):      def DuplicateLayer(self):
661          """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 666  class MainWindow(DockFrame):
666                                layer.ShapeStore(),                                layer.ShapeStore(),
667                                projection = layer.GetProjection())                                projection = layer.GetProjection())
668              new_classification = copy.deepcopy(layer.GetClassification())              new_classification = copy.deepcopy(layer.GetClassification())
669                new_layer.SetClassificationColumn(
670                        layer.GetClassificationColumn())
671              new_layer.SetClassification(new_classification)              new_layer.SetClassification(new_classification)
672              self.Map().AddLayer(new_layer)              self.Map().AddLayer(new_layer)
673    
# Line 628  class MainWindow(DockFrame): Line 677  class MainWindow(DockFrame):
677          return layer is not None and hasattr(layer, "ShapeStore")          return layer is not None and hasattr(layer, "ShapeStore")
678    
679      def LayerShowTable(self):      def LayerShowTable(self):
680            """
681            Present a TableView Window for the current layer.
682            In case the window is already open, bring it to the front.
683            In case, there is no active layer, do nothing.
684            In case, the layer has no ShapeStore, do nothing.
685            """
686          layer = self.current_layer()          layer = self.current_layer()
687          if layer is not None:          if layer is not None:
688                if not hasattr(layer, "ShapeStore"):
689                    return
690              table = layer.ShapeStore().Table()              table = layer.ShapeStore().Table()
691              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
692              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
# Line 640  class MainWindow(DockFrame): Line 697  class MainWindow(DockFrame):
697                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
698                  dialog.Show(True)                  dialog.Show(True)
699              else:              else:
700                  # FIXME: bring dialog to front here                  dialog.Raise()
                 pass  
701    
702      def MapProjection(self):      def MapProjection(self):
703    
# Line 683  class MainWindow(DockFrame): Line 739  class MainWindow(DockFrame):
739          self.OpenLayerProperties(layer)          self.OpenLayerProperties(layer)
740    
741      def OpenLayerProperties(self, layer, group = None):      def OpenLayerProperties(self, layer, group = None):
742          name = "layer_properties" + str(id(layer))          """
743          dialog = self.get_open_dialog(name)          Open or raise the properties dialog.
744    
745          if dialog is None:          This method opens or raises the properties dialog for the
746              dialog = Classifier(self, name, self.Map(), layer, group)          currently selected layer if one is defined for this layer
747              self.add_dialog(name, dialog)          type.
748              dialog.Show()          """
749          dialog.Raise()          dialog_class = layer_properties_dialogs.get(layer)
750    
751            if dialog_class is not None:
752                name = "layer_properties" + str(id(layer))
753                self.OpenOrRaiseDialog(name, dialog_class, layer, group = group)
754    
755      def LayerJoinTable(self):      def LayerJoinTable(self):
756          layer = self.canvas.SelectedLayer()          layer = self.canvas.SelectedLayer()
# Line 986  def _has_selected_layer(context): Line 1046  def _has_selected_layer(context):
1046      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
1047      return context.mainwindow.has_selected_layer()      return context.mainwindow.has_selected_layer()
1048    
1049    def _has_selected_layer_visible(context):
1050        """Return true if a layer is selected in the context which is
1051        visible."""
1052        if context.mainwindow.has_selected_layer():
1053            layer = context.mainwindow.current_layer()
1054            if layer.Visible(): return True
1055        return False
1056    
1057  def _has_selected_shape_layer(context):  def _has_selected_shape_layer(context):
1058      """Return true if a shape layer is selected in the context"""      """Return true if a shape layer is selected in the context"""
1059      return context.mainwindow.has_selected_shape_layer()      return context.mainwindow.has_selected_shape_layer()
# Line 1009  def _has_visible_map(context): Line 1077  def _has_visible_map(context):
1077      if map is not None:      if map is not None:
1078          for layer in map.Layers():          for layer in map.Layers():
1079              if layer.Visible():              if layer.Visible():
1080                  return 1                  return True
1081      return 0      return False
1082    
1083  def _has_legend_shown(context):  def _has_legend_shown(context):
1084      """Return true if the legend window is shown"""      """Return true if the legend window is shown"""
# Line 1134  _method_command("layer_jointable", _("&J Line 1202  _method_command("layer_jointable", _("&J
1202                  sensitive = _has_selected_shape_layer,                  sensitive = _has_selected_shape_layer,
1203                  helptext = _("Join and attach a table to the selected layer"))                  helptext = _("Join and attach a table to the selected layer"))
1204    
1205    # further layer methods:
1206    _method_command("layer_to_top", _("&Top"), "LayerToTop",
1207                    helptext = _("Put selected layer to the top"),
1208                    sensitive = _has_selected_layer)
1209    _method_command("layer_to_bottom", _("&Bottom"), "LayerToBottom",
1210                    helptext = _("Put selected layer to the bottom"),
1211                    sensitive = _has_selected_layer)
1212    _method_command("layer_visibility", _("&Visible"), "ToggleLayerVisibility",
1213                    checked = _has_selected_layer_visible,
1214                    helptext = _("Toggle visibility of selected layer"),
1215                    sensitive = _has_selected_layer)
1216    
1217  def _can_unjoin(context):  def _can_unjoin(context):
1218      """Return whether the Layer/Unjoin command can be executed.      """Return whether the Layer/Unjoin command can be executed.
1219    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26