/[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 937 by jonathan, Tue May 20 15:24:51 2003 UTC revision 1094 by bh, Wed May 28 18:59:46 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
24    
25    from wxPython.lib.dialogs import wxMultipleChoiceDialog
26    
27  import Thuban  import Thuban
28  import Thuban.version  import Thuban.version
29    
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 65  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 104  class MainWindow(DockFrame): Line 105  class MainWindow(DockFrame):
105    
106          self.init_dialogs()          self.init_dialogs()
107    
108          EVT_CLOSE(self, self._OnClose)          EVT_CLOSE(self, self.OnClose)
109    
110      def Subscribe(self, channel, *args):      def Subscribe(self, channel, *args):
111          """Subscribe a function to a message channel.          """Subscribe a function to a message channel.
# Line 395  class MainWindow(DockFrame): Line 396  class MainWindow(DockFrame):
396      def Exit(self):      def Exit(self):
397          self.Close(False)          self.Close(False)
398    
399      def _OnClose(self, event):      def OnClose(self, event):
400          result = self.save_modified_session(can_veto = event.CanVeto())          result = self.save_modified_session(can_veto = event.CanVeto())
401          if result == wxID_CANCEL:          if result == wxID_CANCEL:
402              event.Veto()              event.Veto()
# Line 404  class MainWindow(DockFrame): Line 405  class MainWindow(DockFrame):
405              # wx's destroy event, but that isn't implemented for wxGTK              # wx's destroy event, but that isn't implemented for wxGTK
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 459  class MainWindow(DockFrame): Line 463  class MainWindow(DockFrame):
463          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
464              filename = dlg.GetPath()              filename = dlg.GetPath()
465              title = os.path.splitext(os.path.basename(filename))[0]              title = os.path.splitext(os.path.basename(filename))[0]
             store = self.application.Session().OpenShapefile(filename)  
             layer = Layer(title, store)  
466              map = self.canvas.Map()              map = self.canvas.Map()
467              has_layers = map.HasLayers()              has_layers = map.HasLayers()
468              try:              try:
469                  map.AddLayer(layer)                  store = self.application.Session().OpenShapefile(filename)
470              except IOError:              except IOError:
471                  # the layer couldn't be opened                  # the layer couldn't be opened
472                  self.RunMessageBox(_("Add Layer"),                  self.RunMessageBox(_("Add Layer"),
473                                     _("Can't open the file '%s'.") % filename)                                     _("Can't open the file '%s'.") % filename)
474              else:              else:
475                    layer = Layer(title, store)
476                    map.AddLayer(layer)
477                  if not has_layers:                  if not has_layers:
478                      # if we're adding a layer to an empty map, fit the                      # if we're adding a layer to an empty map, fit the
479                      # new map to the window                      # new map to the window
# Line 482  class MainWindow(DockFrame): Line 486  class MainWindow(DockFrame):
486          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
487              filename = dlg.GetPath()              filename = dlg.GetPath()
488              title = os.path.splitext(os.path.basename(filename))[0]              title = os.path.splitext(os.path.basename(filename))[0]
             layer = RasterLayer(title, filename)  
489              map = self.canvas.Map()              map = self.canvas.Map()
490              has_layers = map.HasLayers()              has_layers = map.HasLayers()
491              try:              try:
492                  map.AddLayer(layer)                  layer = RasterLayer(title, filename)
493              except IOError:              except IOError:
494                  # the layer couldn't be opened                  # the layer couldn't be opened
495                  self.RunMessageBox(_("Add Image Layer"),                  self.RunMessageBox(_("Add Image Layer"),
496                                     _("Can't open the file '%s'.") % filename)                                     _("Can't open the file '%s'.") % filename)
497              else:              else:
498                    map.AddLayer(layer)
499                  if not has_layers:                  if not has_layers:
500                      # if we're adding a layer to an empty map, fit the                      # if we're adding a layer to an empty map, fit the
501                      # new map to the window                      # new map to the window
# Line 545  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 559  class MainWindow(DockFrame): Line 580  class MainWindow(DockFrame):
580              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
581              if dialog is None:              if dialog is None:
582                  dialog = tableview.LayerTableFrame(self, name,                  dialog = tableview.LayerTableFrame(self, name,
583                                                 _("Table: %s") % layer.Title(),                                           _("Layer Table: %s") % layer.Title(),
584                                                     layer, table)                                           layer, table)
585                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
586                  dialog.Show(true)                  dialog.Show(True)
587              else:              else:
588                  # FIXME: bring dialog to front here                  # FIXME: bring dialog to front here
589                  pass                  pass
# Line 617  class MainWindow(DockFrame): Line 638  class MainWindow(DockFrame):
638          dialog.Raise()          dialog.Raise()
639    
640      def LayerJoinTable(self):      def LayerJoinTable(self):
641          print "LayerJoinTable"          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"          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 646  class MainWindow(DockFrame): Line 676  class MainWindow(DockFrame):
676          return dialog is not None and dialog.IsShown()          return dialog is not None and dialog.IsShown()
677    
678      def TableOpen(self):      def TableOpen(self):
         print "TableOpen"  
679          dlg = wxFileDialog(self, _("Open Table"), ".", "",          dlg = wxFileDialog(self, _("Open Table"), ".", "",
680                             "DBF Files (*.dbf)|*.dbf|" +                             _("DBF Files (*.dbf)") + "|*.dbf|" +
681                             "CSV Files (*.csv)|*.csv|" +                             #_("CSV Files (*.csv)") + "|*.csv|" +
682                             "All Files (*.*)|*.*",                             _("All Files (*.*)") + "|*.*",
683                             wxOPEN)                             wxOPEN)
684          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
685              #self.application.session.OpenTable(dlg.GetPath())              filename = dlg.GetPath()
686              pass              dlg.Destroy()
687                try:
688          dlg.Destroy()                  table = self.application.session.OpenTableFile(filename)
689                except IOError:
690                    # the layer couldn't be opened
691                    self.RunMessageBox(_("Open Table"),
692                                       _("Can't open the file '%s'.") % filename)
693                else:
694                    self.ShowTableView(table)
695    
696      def TableClose(self):      def TableClose(self):
697          print "TableClose"          tables = self.application.session.UnreferencedTables()
698    
699            lst = [(t.Title(), t) for t in tables]
700            lst.sort()
701            titles = [i[0] for i in lst]
702            dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"),
703                                         _("Close Table"), titles,
704                                         size = (400, 300),
705                                         style = wxDEFAULT_DIALOG_STYLE |
706                                                 wxRESIZE_BORDER)
707            if dlg.ShowModal() == wxID_OK:
708                for i in dlg.GetValue():
709                    self.application.session.RemoveTable(lst[i][1])
710    
711    
712      def TableShow(self):      def TableShow(self):
713          print "TableShow"          """Offer a multi-selection dialog for tables to be displayed
714    
715            The windows for the selected tables are opened or brought to
716            the front.
717            """
718            tables = self.application.session.Tables()
719    
720      def TableHide(self):          lst = [(t.Title(), t) for t in tables]
721          print "TableHide"          lst.sort()
722            titles = [i[0] for i in lst]
723            dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"),
724                                         _("Show Table"), titles,
725                                         size = (400,300),
726                                         style = wxDEFAULT_DIALOG_STYLE |
727                                                 wxRESIZE_BORDER)
728            if (dlg.ShowModal() == wxID_OK):
729                for i in dlg.GetValue():
730                    # XXX: if the table belongs to a layer, open a
731                    # LayerTableFrame instead of QueryTableFrame
732                    self.ShowTableView(lst[i][1])
733    
734      def TableJoin(self):      def TableJoin(self):
         print "TableJoin"  
735          dlg = JoinDialog(self, _("Join Tables"), self.application.session)          dlg = JoinDialog(self, _("Join Tables"), self.application.session)
736          if dlg.ShowModal() == wxID_OK:          dlg.ShowModal()
737              print "OK"  
738        def ShowTableView(self, table):
739            """Open a table view for the table and optionally"""
740            name = "table_view%d" % id(table)
741            dialog = self.get_open_dialog(name)
742            if dialog is None:
743                dialog = tableview.QueryTableFrame(self, name,
744                                                   _("Table: %s") % table.Title(),
745                                                   table)
746                self.add_dialog(name, dialog)
747                dialog.Show(True)
748            # FIXME: else bring dialog to front
749    
750      def ZoomInTool(self):      def ZoomInTool(self):
751          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
# Line 869  _method_command("layer_remove", _("&Remo Line 943  _method_command("layer_remove", _("&Remo
943  # Layer menu  # Layer menu
944  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
945                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
946    _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
947                    helptext = _("Duplicate selected layer(s)"),
948              sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
949  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
950                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer(s)"),
951                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
# Line 888  _method_command("layer_properties", _("& Line 965  _method_command("layer_properties", _("&
965                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
966  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
967                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
968    
969    def _can_unjoin(context):
970        """Return whether the Layer/Unjoin command can be executed.
971    
972        This is the case if a layer is selected and that layer has a
973        shapestore that has an original shapestore.
974        """
975        layer = context.mainwindow.SelectedLayer()
976        if layer is None:
977            return 0
978        getstore = getattr(layer, "ShapeStore", None)
979        if getstore is not None:
980            return getstore().OrigShapeStore() is not None
981        else:
982            return 0
983  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
984                  sensitive = _has_selected_layer)                  sensitive = _can_unjoin)
985    
986  # Table menu  # Table menu
987  _method_command("table_open", _("&Open..."), "TableOpen")  _method_command("table_open", _("&Open..."), "TableOpen")
988  _method_command("table_close", _("&Close"), "TableClose")  _method_command("table_close", _("&Close"), "TableClose",
989           sensitive = lambda context: bool(context.session.UnreferencedTables()))
990  _method_command("table_show", _("&Show"), "TableShow")  _method_command("table_show", _("&Show"), "TableShow")
 _method_command("table_hide", _("&Hide"), "TableHide")  
991  _method_command("table_join", _("&Join..."), "TableJoin")  _method_command("table_join", _("&Join..."), "TableJoin")
992    
993  #  Export only under Windows ...  #  Export only under Windows ...
# Line 930  main_menu = Menu("<main>", "<main>", Line 1022  main_menu = Menu("<main>", "<main>",
1022                          None,                          None,
1023                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
1024                          None,                          None,
1025                            "layer_duplicate",
1026                            None,
1027                          "layer_projection",                          "layer_projection",
1028                          None,                          None,
1029                          "layer_show_table",                          "layer_show_table",
# Line 940  main_menu = Menu("<main>", "<main>", Line 1034  main_menu = Menu("<main>", "<main>",
1034                    Menu("table", _("&Table"),                    Menu("table", _("&Table"),
1035                         ["table_open", "table_close",                         ["table_open", "table_close",
1036                         None,                         None,
1037                         "table_show", "table_hide",                         "table_show",
1038                         None,                         None,
1039                         "table_join"]),                         "table_join"]),
1040                    Menu("help", _("&Help"),                    Menu("help", _("&Help"),

Legend:
Removed from v.937  
changed lines
  Added in v.1094

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26