/[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 1070 by bh, Tue May 27 15:09:31 2003 UTC revision 1108 by jonathan, Fri May 30 06:31:21 2003 UTC
# Line 17  __ThubanVersion__ = "0.2" #"$THUBAN_0_2$ Line 17  __ThubanVersion__ = "0.2" #"$THUBAN_0_2$
17  #__BuildDate__ = "$Date$"  #__BuildDate__ = "$Date$"
18    
19  import os  import os
20    import copy
21    
22  from wxPython.wx import *  from wxPython.wx import *
23  from wxPython.wx import __version__ as wxPython_version  from wxPython.wx import __version__ as wxPython_version
# Line 64  class MainWindow(DockFrame): Line 65  class MainWindow(DockFrame):
65      # implemented in the __getattr__ method.      # implemented in the __getattr__ method.
66      delegated_methods = {"SelectLayer": "canvas",      delegated_methods = {"SelectLayer": "canvas",
67                           "SelectShapes": "canvas",                           "SelectShapes": "canvas",
68                             "SelectedLayer": "canvas",
69                           "SelectedShapes": "canvas",                           "SelectedShapes": "canvas",
70                           }                           }
71    
# Line 547  class MainWindow(DockFrame): Line 549  class MainWindow(DockFrame):
549          layer = self.current_layer()          layer = self.current_layer()
550          if layer is not None:          if layer is not None:
551              layer.SetVisible(0)              layer.SetVisible(0)
552            
553      def ShowLayer(self):      def ShowLayer(self):
554          layer = self.current_layer()          layer = self.current_layer()
555          if layer is not None:          if layer is not None:
556              layer.SetVisible(1)              layer.SetVisible(1)
557    
558        def DuplicateLayer(self):
559            """Ceate a new layer above the selected layer with the same shapestore
560            """
561            layer = self.current_layer()
562            if layer is not None and hasattr(layer, "ShapeStore"):
563                new_layer = Layer(_("Copy of `%s'") % layer.Title(),
564                                  layer.ShapeStore(),
565                                  projection = layer.GetProjection())
566                new_classification = copy.deepcopy(layer.GetClassification())
567                new_layer.SetClassification(new_classification)
568                self.Map().AddLayer(new_layer)
569    
570        def CanDuplicateLayer(self):
571            """Return whether the DuplicateLayer method can create a duplicate"""
572            layer = self.current_layer()
573            return layer is not None and hasattr(layer, "ShapeStore")
574    
575      def LayerShowTable(self):      def LayerShowTable(self):
576          layer = self.current_layer()          layer = self.current_layer()
577          if layer is not None:          if layer is not None:
# Line 619  class MainWindow(DockFrame): Line 638  class MainWindow(DockFrame):
638          dialog.Raise()          dialog.Raise()
639    
640      def LayerJoinTable(self):      def LayerJoinTable(self):
641          print "LayerJoinTable: Not implemented."          layer = self.canvas.SelectedLayer()
642            if layer is not None:
643                dlg = JoinDialog(self, _("Join Layer with Table"),
644                                 self.application.session,
645                                 layer = layer)
646                dlg.ShowModal()
647    
648      def LayerUnjoinTable(self):      def LayerUnjoinTable(self):
649          print "LayerUnjoinTable: Not implemented."          layer = self.canvas.SelectedLayer()
650            if layer is not None:
651                orig_store = layer.ShapeStore().OrigShapeStore()
652                if orig_store:
653                    layer.SetShapeStore(orig_store)
654    
655      def ShowLegend(self):      def ShowLegend(self):
656          if not self.LegendShown():          if not self.LegendShown():
# Line 642  class MainWindow(DockFrame): Line 670  class MainWindow(DockFrame):
670          else:          else:
671              dialog.Show(not dialog.IsShown())              dialog.Show(not dialog.IsShown())
672    
673            self.canvas.FitMapToWindow()
674    
675      def LegendShown(self):      def LegendShown(self):
676          """Return true iff the legend is currently open"""          """Return true iff the legend is currently open"""
677          dialog = self.FindRegisteredDock("legend")          dialog = self.FindRegisteredDock("legend")
# Line 668  class MainWindow(DockFrame): Line 698  class MainWindow(DockFrame):
698      def TableClose(self):      def TableClose(self):
699          tables = self.application.session.UnreferencedTables()          tables = self.application.session.UnreferencedTables()
700    
701            lst = [(t.Title(), t) for t in tables]
702            lst.sort()
703            titles = [i[0] for i in lst]
704          dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"),          dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"),
705                                       _("Close Table"),                                       _("Close Table"), titles,
706                                       [t.Title() for t in tables],                                       size = (400, 300),
707                                       size = (400, 300), style=wxRESIZE_BORDER)                                       style = wxDEFAULT_DIALOG_STYLE |
708                                                 wxRESIZE_BORDER)
709          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
710              for i in dlg.GetValue():              for i in dlg.GetValue():
711                  self.application.session.RemoveTable(tables[i])                  self.application.session.RemoveTable(lst[i][1])
712    
713    
714      def TableShow(self):      def TableShow(self):
# Line 685  class MainWindow(DockFrame): Line 719  class MainWindow(DockFrame):
719          """          """
720          tables = self.application.session.Tables()          tables = self.application.session.Tables()
721    
722            lst = [(t.Title(), t) for t in tables]
723            lst.sort()
724            titles = [i[0] for i in lst]
725          dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"),          dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"),
726                                       _("Show Table"),                                       _("Show Table"), titles,
727                                       [t.Title() for t in tables],                                       size = (400,300),
728                                       size = (400,300), style = wxRESIZE_BORDER)                                       style = wxDEFAULT_DIALOG_STYLE |
729                                                 wxRESIZE_BORDER)
730          if (dlg.ShowModal() == wxID_OK):          if (dlg.ShowModal() == wxID_OK):
731              for i in dlg.GetValue():              for i in dlg.GetValue():
732                  # XXX: if the table belongs to a layer, open a                  # XXX: if the table belongs to a layer, open a
733                  # LayerTableFrame instead of QueryTableFrame                  # LayerTableFrame instead of QueryTableFrame
734                  self.ShowTableView(tables[i])                  self.ShowTableView(lst[i][1])
735    
736      def TableJoin(self):      def TableJoin(self):
737          dlg = JoinDialog(self, _("Join Tables"), self.application.session)          dlg = JoinDialog(self, _("Join Tables"), self.application.session)
# Line 907  _method_command("layer_remove", _("&Remo Line 945  _method_command("layer_remove", _("&Remo
945  # Layer menu  # Layer menu
946  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
947                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
948    _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
949                    helptext = _("Duplicate selected layer(s)"),
950              sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
951  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
952                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer(s)"),
953                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
# Line 926  _method_command("layer_properties", _("& Line 967  _method_command("layer_properties", _("&
967                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
968  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
969                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
970    
971    def _can_unjoin(context):
972        """Return whether the Layer/Unjoin command can be executed.
973    
974        This is the case if a layer is selected and that layer has a
975        shapestore that has an original shapestore.
976        """
977        layer = context.mainwindow.SelectedLayer()
978        if layer is None:
979            return 0
980        getstore = getattr(layer, "ShapeStore", None)
981        if getstore is not None:
982            return getstore().OrigShapeStore() is not None
983        else:
984            return 0
985  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
986                  sensitive = _has_selected_layer)                  sensitive = _can_unjoin)
987    
988  # Table menu  # Table menu
989  _method_command("table_open", _("&Open..."), "TableOpen")  _method_command("table_open", _("&Open..."), "TableOpen")
# Line 968  main_menu = Menu("<main>", "<main>", Line 1024  main_menu = Menu("<main>", "<main>",
1024                          None,                          None,
1025                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
1026                          None,                          None,
1027                            "layer_duplicate",
1028                            None,
1029                          "layer_projection",                          "layer_projection",
1030                          None,                          None,
1031                          "layer_show_table",                          "layer_show_table",

Legend:
Removed from v.1070  
changed lines
  Added in v.1108

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26