/[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 1052 by bh, Tue May 27 09:34:28 2003 UTC revision 1126 by bh, Mon Jun 2 14:15:43 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 29  import Thuban.version Line 30  import Thuban.version
30  from Thuban import _  from Thuban import _
31  from Thuban.Model.session import create_empty_session  from Thuban.Model.session import create_empty_session
32  from Thuban.Model.layer import Layer, RasterLayer  from Thuban.Model.layer import Layer, RasterLayer
 from Thuban.Model.color import Color  
 from Thuban.Model.proj import Projection  
33    
34  import view  import view
35  import tree  import tree
 import proj4dialog  
36  import tableview, identifyview  import tableview, identifyview
37  from Thuban.UI.classifier import Classifier  from Thuban.UI.classifier import Classifier
38  import legend  import legend
# Line 67  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 407  class MainWindow(DockFrame): Line 406  class MainWindow(DockFrame):
406              # yet.              # yet.
407              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)
408              DockFrame.OnClose(self, event)              DockFrame.OnClose(self, event)
409                for dlg in self.dialogs.values():
410                    dlg.Destroy()
411                self.canvas.Destroy()
412              self.Destroy()              self.Destroy()
413    
414      def SetMap(self, map):      def SetMap(self, map):
# 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 654  class MainWindow(DockFrame): Line 684  class MainWindow(DockFrame):
684                             _("All Files (*.*)") + "|*.*",                             _("All Files (*.*)") + "|*.*",
685                             wxOPEN)                             wxOPEN)
686          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
687              self.application.session.OpenTableFile(dlg.GetPath())              filename = dlg.GetPath()
688                dlg.Destroy()
689          dlg.Destroy()              try:
690                    table = self.application.session.OpenTableFile(filename)
691                except IOError:
692                    # the layer couldn't be opened
693                    self.RunMessageBox(_("Open Table"),
694                                       _("Can't open the file '%s'.") % filename)
695                else:
696                    self.ShowTableView(table)
697    
698      def TableClose(self):      def TableClose(self):
699          print "TableClose: not implemented"          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:"),
705                                         _("Close Table"), titles,
706                                         size = (400, 300),
707                                         style = wxDEFAULT_DIALOG_STYLE |
708                                                 wxRESIZE_BORDER)
709            if dlg.ShowModal() == wxID_OK:
710                for i in dlg.GetValue():
711                    self.application.session.RemoveTable(lst[i][1])
712    
713    
714      def TableShow(self):      def TableShow(self):
715          """Offer a multi-selection dialog for tables to be displayed          """Offer a multi-selection dialog for tables to be displayed
716            
717          The windows for the selected tables are opened or brought to          The windows for the selected tables are opened or brought to
718          the front.          the front.
719          """          """
720          tables = self.application.session.Tables()          tables = self.application.session.Tables()
         table_list = []  
         for table in tables:  
             table_list.append(table.Title())  
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"), table_list,                                       _("Show Table"), titles,
727                                       size = (400,300), style = wxRESIZE_BORDER)                                       size = (400,300),
728                                         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():
                 # XXX: First check whether the dialog is already open  
                 # and if so, bring it to the front.  
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                  print "tables[i]:", tables[i]                  self.ShowTableView(lst[i][1])
                 dialog = tableview.QueryTableFrame(self, table_list[i],  
                                               _("Table: %s") % table_list[i],  
                                               tables[i])  
                 self.add_dialog(table_list[i], dialog)  
                 dialog.Show(True)  
   
         # XXX: just some analyis code, remove it when the above XXX is  
         # resolved.  
         for d in self.dialogs.values():  
             if isinstance(d, tableview.LayerTableFrame):  
                 print "LayerTable:", d.GetTitle()  
             elif isinstance(d, tableview.QueryTableFrame):  
                 print "QueryTable:", d.GetTitle()  
             else:  
                 print "Other:", d.GetTitle()  
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)
738          dlg.ShowModal()          dlg.ShowModal()
739    
740        def ShowTableView(self, table):
741            """Open a table view for the table and optionally"""
742            name = "table_view%d" % id(table)
743            dialog = self.get_open_dialog(name)
744            if dialog is None:
745                dialog = tableview.QueryTableFrame(self, name,
746                                                   _("Table: %s") % table.Title(),
747                                                   table)
748                self.add_dialog(name, dialog)
749                dialog.Show(True)
750            # FIXME: else bring dialog to front
751    
752        def TableRename(self):
753            """Let the user rename a table"""
754    
755            # First, let the user select a table
756            tables = self.application.session.Tables()
757            lst = [(t.Title(), t) for t in tables]
758            lst.sort()
759            titles = [i[0] for i in lst]
760            dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"),
761                                         _("Rename Table"), titles,
762                                         size = (400,300),
763                                         style = wxDEFAULT_DIALOG_STYLE |
764                                                 wxRESIZE_BORDER)
765            if (dlg.ShowModal() == wxID_OK):
766                to_rename = [lst[i][1] for i in dlg.GetValue()]
767                dlg.Destroy()
768            else:
769                to_rename = []
770    
771            # Second, let the user rename the layers
772            for table in to_rename:
773                dlg = wxTextEntryDialog(self, "Table Title: ", "Rename Table",
774                                        table.Title())
775                try:
776                    if dlg.ShowModal() == wxID_OK:
777                        title = dlg.GetValue()
778                        if title != "":
779                            table.SetTitle(title)
780    
781                            # Make sure the session is marked as modified.
782                            # FIXME: This should be handled automatically,
783                            # but that requires more changes to the tables
784                            # than I have time for currently.
785                            self.application.session.changed()
786                finally:
787                    dlg.Destroy()
788    
789    
790      def ZoomInTool(self):      def ZoomInTool(self):
791          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
792    
# Line 744  class MainWindow(DockFrame): Line 829  class MainWindow(DockFrame):
829    
830          dlg.Destroy()          dlg.Destroy()
831    
832        def RenameLayer(self):
833            """Let the user rename the currently selected layer"""
834            layer = self.current_layer()
835            if layer is not None:
836                dlg = wxTextEntryDialog(self, "Layer Title: ", "Rename Layer",
837                                        layer.Title())
838                try:
839                    if dlg.ShowModal() == wxID_OK:
840                        title = dlg.GetValue()
841                        if title != "":
842                            layer.SetTitle(title)
843                finally:
844                    dlg.Destroy()
845    
846      def identify_view_on_demand(self, layer, shapes):      def identify_view_on_demand(self, layer, shapes):
847          """Subscribed to the canvas' SHAPES_SELECTED message          """Subscribed to the canvas' SHAPES_SELECTED message
848    
# Line 898  _method_command("layer_remove", _("&Remo Line 997  _method_command("layer_remove", _("&Remo
997  # Layer menu  # Layer menu
998  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
999                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1000    _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
1001                    helptext = _("Duplicate selected layer(s)"),
1002              sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
1003    _method_command("layer_rename", _("Re&name ..."), "RenameLayer",
1004                    helptext = _("Rename selected layer"),
1005                    sensitive = _has_selected_layer)
1006  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
1007                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer(s)"),
1008                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
# Line 917  _method_command("layer_properties", _("& Line 1022  _method_command("layer_properties", _("&
1022                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1023  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1024                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1025    
1026    def _can_unjoin(context):
1027        """Return whether the Layer/Unjoin command can be executed.
1028    
1029        This is the case if a layer is selected and that layer has a
1030        shapestore that has an original shapestore.
1031        """
1032        layer = context.mainwindow.SelectedLayer()
1033        if layer is None:
1034            return 0
1035        getstore = getattr(layer, "ShapeStore", None)
1036        if getstore is not None:
1037            return getstore().OrigShapeStore() is not None
1038        else:
1039            return 0
1040  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
1041                  sensitive = _has_selected_layer)                  sensitive = _can_unjoin)
1042    
1043    
1044    def _has_tables(context):
1045        return bool(context.session.Tables())
1046    
1047  # Table menu  # Table menu
1048  _method_command("table_open", _("&Open..."), "TableOpen")  _method_command("table_open", _("&Open..."), "TableOpen")
1049  _method_command("table_close", _("&Close"), "TableClose")  _method_command("table_close", _("&Close"), "TableClose",
1050  _method_command("table_show", _("&Show"), "TableShow")         sensitive = lambda context: bool(context.session.UnreferencedTables()))
1051  _method_command("table_join", _("&Join..."), "TableJoin")  _method_command("table_rename", _("&Rename..."), "TableRename",
1052                    sensitive = _has_tables)
1053    _method_command("table_show", _("&Show"), "TableShow",
1054                    sensitive = _has_tables)
1055    _method_command("table_join", _("&Join..."), "TableJoin",
1056                    sensitive = _has_tables)
1057    
1058  #  Export only under Windows ...  #  Export only under Windows ...
1059  map_menu = ["layer_add", "rasterlayer_add", "layer_remove", "map_rename",  map_menu = ["layer_add", "rasterlayer_add", "layer_remove", "map_rename",
# Line 954  main_menu = Menu("<main>", "<main>", Line 1083  main_menu = Menu("<main>", "<main>",
1083                          "exit"]),                          "exit"]),
1084                    Menu("map", _("&Map"), map_menu),                    Menu("map", _("&Map"), map_menu),
1085                    Menu("layer", _("&Layer"),                    Menu("layer", _("&Layer"),
1086                          ["layer_raise", "layer_lower",                         ["layer_rename", "layer_duplicate",
1087                            None,
1088                            "layer_raise", "layer_lower",
1089                          None,                          None,
1090                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
1091                          None,                          None,
# Line 966  main_menu = Menu("<main>", "<main>", Line 1097  main_menu = Menu("<main>", "<main>",
1097                          None,                          None,
1098                          "layer_properties"]),                          "layer_properties"]),
1099                    Menu("table", _("&Table"),                    Menu("table", _("&Table"),
1100                         ["table_open", "table_close",                         ["table_open", "table_close", "table_rename",
1101                         None,                         None,
1102                         "table_show",                         "table_show",
1103                         None,                         None,

Legend:
Removed from v.1052  
changed lines
  Added in v.1126

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26