/[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 704 by bh, Tue Apr 22 16:55:50 2003 UTC revision 879 by jonathan, Fri May 9 16:33:10 2003 UTC
# Line 39  from command import registry, Command, T Line 39  from command import registry, Command, T
39  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION
40    
41  from Thuban.UI.dock import DockFrame  from Thuban.UI.dock import DockFrame
42    from Thuban.UI.join import JoinDialog
43    
44  import resource  import resource
45    
46    import projdialog
47    
48    
49    
50  class MainWindow(DockFrame):  class MainWindow(DockFrame):
# Line 58  class MainWindow(DockFrame): Line 61  class MainWindow(DockFrame):
61      # implemented in the __getattr__ method.      # implemented in the __getattr__ method.
62      delegated_methods = {"SelectLayer": "canvas",      delegated_methods = {"SelectLayer": "canvas",
63                           "SelectShapes": "canvas",                           "SelectShapes": "canvas",
64                             "SelectedShapes": "canvas",
65                           }                           }
66    
67      def __init__(self, parent, ID, title, application, interactor,      def __init__(self, parent, ID, title, application, interactor,
# Line 361  class MainWindow(DockFrame): Line 365  class MainWindow(DockFrame):
365    
366      def OpenSession(self):      def OpenSession(self):
367          self.save_modified_session()          self.save_modified_session()
368          dlg = wxFileDialog(self, _("Open Session"), ".", "", "*.thuban", wxOPEN)          dlg = wxFileDialog(self, _("Open Session"), ".", "",
369                               "Thuban Session File (*.thuban)|*.thuban", wxOPEN)
370          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
371              self.prepare_new_session()              self.prepare_new_session()
372              self.application.OpenSession(dlg.GetPath())              self.application.OpenSession(dlg.GetPath())
# Line 375  class MainWindow(DockFrame): Line 380  class MainWindow(DockFrame):
380    
381      def SaveSessionAs(self):      def SaveSessionAs(self):
382          dlg = wxFileDialog(self, _("Save Session As"), ".", "",          dlg = wxFileDialog(self, _("Save Session As"), ".", "",
383                             "*.thuban", wxOPEN)                             "Thuban Session File (*.thuban)|*.thuban",
384                               wxSAVE|wxOVERWRITE_PROMPT)
385          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
386              self.application.session.SetFilename(dlg.GetPath())              self.application.session.SetFilename(dlg.GetPath())
387              self.application.SaveSession()              self.application.SaveSession()
# Line 399  class MainWindow(DockFrame): Line 405  class MainWindow(DockFrame):
405      def SetMap(self, map):      def SetMap(self, map):
406          self.canvas.SetMap(map)          self.canvas.SetMap(map)
407          self.__SetTitle(map.Title())          self.__SetTitle(map.Title())
408          #self.legendPanel.SetMap(map)  
409            dialog = self.FindRegisteredDock("legend")
410            if dialog is not None:
411                dialog.GetPanel().SetMap(self.Map())
412    
413      def Map(self):      def Map(self):
414          """Return the map displayed by this mainwindow"""          """Return the map displayed by this mainwindow"""
415    
         # sanity check  
         #assert(self.canvas.Map() is self.legendPanel.GetMap())  
   
416          return self.canvas.Map()          return self.canvas.Map()
417    
418      def ToggleSessionTree(self):      def ToggleSessionTree(self):
# Line 442  class MainWindow(DockFrame): Line 448  class MainWindow(DockFrame):
448          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
449              filename = dlg.GetPath()              filename = dlg.GetPath()
450              title = os.path.splitext(os.path.basename(filename))[0]              title = os.path.splitext(os.path.basename(filename))[0]
451              layer = Layer(title, filename)              store = self.application.Session().OpenShapefile(filename)
452                layer = Layer(title, store)
453              map = self.canvas.Map()              map = self.canvas.Map()
454              has_layers = map.HasLayers()              has_layers = map.HasLayers()
455              try:              try:
# Line 497  class MainWindow(DockFrame): Line 504  class MainWindow(DockFrame):
504          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
505          return self.canvas.HasSelectedLayer()          return self.canvas.HasSelectedLayer()
506    
507      def choose_color(self):      def has_selected_shapes(self):
508          """Run the color selection dialog and return the selected color.          """Return true if a shape is currently selected"""
509            return self.canvas.HasSelectedShapes()
         If the user cancels, return None.  
         """  
         dlg = wxColourDialog(self)  
         color = None  
         if dlg.ShowModal() == wxID_OK:  
             data = dlg.GetColourData()  
             wxc = data.GetColour()  
             color = Color(wxc.Red() / 255.0,  
                           wxc.Green() / 255.0,  
                           wxc.Blue() / 255.0)  
         dlg.Destroy()  
         return color  
510    
511      def HideLayer(self):      def HideLayer(self):
512          layer = self.current_layer()          layer = self.current_layer()
# Line 539  class MainWindow(DockFrame): Line 534  class MainWindow(DockFrame):
534                  # FIXME: bring dialog to front here                  # FIXME: bring dialog to front here
535                  pass                  pass
536    
537      def Projection(self):      def MapProjection(self):
538          map = self.canvas.Map()  
539          proj = map.projection          name = "map_projection"
540          if proj is None:          dialog = self.get_open_dialog(name)
541              proj4Dlg = proj4dialog.Proj4Dialog(NULL, None, map.BoundingBox())  
542          else:          if dialog is None:
543              proj4Dlg = proj4dialog.Proj4Dialog(NULL, map.projection.params,              map = self.canvas.Map()
544                                                 map.BoundingBox())              dialog = projdialog.ProjFrame(self, name,
545          if proj4Dlg.ShowModal() == wxID_OK:                       _("Map Projection: %s") % map.Title(), map)
546              params = proj4Dlg.GetParams()              self.add_dialog(name, dialog)
547              if params is not None:              dialog.Show()
548                  proj = Projection(params)          dialog.Raise()
549              else:  
550                  proj = None      def LayerProjection(self):
551              map.SetProjection(proj)  
552          proj4Dlg.Destroy()          layer = self.current_layer()
553    
554            name = "layer_projection" + str(id(layer))
555            dialog = self.get_open_dialog(name)
556    
557            if dialog is None:
558                map = self.canvas.Map()
559                dialog = projdialog.ProjFrame(self, name,
560                         _("Layer Projection: %s") % layer.Title(), layer)
561                self.add_dialog(name, dialog)
562                dialog.Show()
563            dialog.Raise()
564    
565      def LayerEditProperties(self):      def LayerEditProperties(self):
566    
# Line 577  class MainWindow(DockFrame): Line 583  class MainWindow(DockFrame):
583              dialog.Show()              dialog.Show()
584          dialog.Raise()          dialog.Raise()
585    
586        def LayerJoinTable(self):
587            print "LayerJoinTable"
588    
589        def LayerUnjoinTable(self):
590            print "LayerUnjoinTable"
591    
592      def ShowLegend(self):      def ShowLegend(self):
593          if not self.LegendShown():          if not self.LegendShown():
# Line 601  class MainWindow(DockFrame): Line 612  class MainWindow(DockFrame):
612          dialog = self.FindRegisteredDock("legend")          dialog = self.FindRegisteredDock("legend")
613          return dialog is not None and dialog.IsShown()          return dialog is not None and dialog.IsShown()
614    
615        def TableOpen(self):
616            print "TableOpen"
617            dlg = wxFileDialog(self, _("Open Table"), ".", "",
618                               "DBF Files (*.dbf)|*.dbf|" +
619                               "CSV Files (*.csv)|*.csv|" +
620                               "All Files (*.*)|*.*",
621                               wxOPEN)
622            if dlg.ShowModal() == wxID_OK:
623                #self.application.session.OpenTable(dlg.GetPath())
624                pass
625    
626            dlg.Destroy()
627    
628        def TableClose(self):
629            print "TableClose"
630    
631        def TableShow(self):
632            print "TableShow"
633    
634        def TableHide(self):
635            print "TableHide"
636    
637        def TableJoin(self):
638            print "TableJoin"
639            dlg = JoinDialog(self, _("Join Tables"), self.application.session)
640            if dlg.ShowModal() == wxID_OK:
641                print "OK"
642    
643      def ZoomInTool(self):      def ZoomInTool(self):
644          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
645    
# Line 620  class MainWindow(DockFrame): Line 659  class MainWindow(DockFrame):
659      def FullExtent(self):      def FullExtent(self):
660          self.canvas.FitMapToWindow()          self.canvas.FitMapToWindow()
661    
662        def FullLayerExtent(self):
663            self.canvas.FitLayerToWindow(self.current_layer())
664    
665        def FullSelectionExtent(self):
666            self.canvas.FitSelectedToWindow()
667    
668      def PrintMap(self):      def PrintMap(self):
669          self.canvas.Print()          self.canvas.Print()
670    
# Line 635  class MainWindow(DockFrame): Line 680  class MainWindow(DockFrame):
680          dlg.Destroy()          dlg.Destroy()
681    
682      def identify_view_on_demand(self, layer, shapes):      def identify_view_on_demand(self, layer, shapes):
683            """Subscribed to the canvas' SHAPES_SELECTED message
684    
685            If the current tool is the identify tool, at least one shape is
686            selected and the identify dialog is not shown, show the dialog.
687            """
688            # If the selection has become empty we don't need to do
689            # anything. Otherwise it could happen that the dialog was popped
690            # up when the selection became empty, e.g. when a new selection
691            # is opened while the identify tool is active and dialog had
692            # been closed
693            if not shapes:
694                return
695    
696          name = "identify_view"          name = "identify_view"
697          if self.canvas.CurrentTool() == "IdentifyTool":          if self.canvas.CurrentTool() == "IdentifyTool":
698              if not self.dialog_open(name):              if not self.dialog_open(name):
# Line 688  def _has_selected_layer(context): Line 746  def _has_selected_layer(context):
746      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
747      return context.mainwindow.has_selected_layer()      return context.mainwindow.has_selected_layer()
748    
749    def _has_selected_shapes(context):
750        """Return true if a layer is selected in the context"""
751        return context.mainwindow.has_selected_shapes()
752    
753  def _can_remove_layer(context):  def _can_remove_layer(context):
754      return context.mainwindow.CanRemoveLayer()      return context.mainwindow.CanRemoveLayer()
755    
# Line 713  def _has_legend_shown(context): Line 775  def _has_legend_shown(context):
775    
776  # File menu  # File menu
777  _method_command("new_session", _("&New Session"), "NewSession")  _method_command("new_session", _("&New Session"), "NewSession")
778  _method_command("open_session", _("&Open Session"), "OpenSession")  _method_command("open_session", _("&Open Session..."), "OpenSession")
779  _method_command("save_session", _("&Save Session"), "SaveSession")  _method_command("save_session", _("&Save Session"), "SaveSession")
780  _method_command("save_session_as", _("Save Session &As"), "SaveSessionAs")  _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs")
781  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
782                  checked = _has_tree_window_shown)                  checked = _has_tree_window_shown)
783  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
# Line 723  _method_command("toggle_legend", _("Lege Line 785  _method_command("toggle_legend", _("Lege
785  _method_command("exit", _("E&xit"), "Exit")  _method_command("exit", _("E&xit"), "Exit")
786    
787  # Help menu  # Help menu
788  _method_command("help_about", _("&About"), "About")  _method_command("help_about", _("&About..."), "About")
789    
790    
791  # Map menu  # Map menu
792  _method_command("map_projection", _("Pro&jection"), "Projection")  _method_command("map_projection", _("Pro&jection..."), "MapProjection")
793    
794  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
795                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
# Line 748  _tool_command("map_label_tool", _("&Labe Line 810  _tool_command("map_label_tool", _("&Labe
810  _method_command("map_full_extent", _("&Full extent"), "FullExtent",  _method_command("map_full_extent", _("&Full extent"), "FullExtent",
811                 helptext = _("Full Extent"), icon = "fullextent",                 helptext = _("Full Extent"), icon = "fullextent",
812                sensitive = _has_visible_map)                sensitive = _has_visible_map)
813    _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",
814                   helptext = _("Full Layer Extent"), icon = "fulllayerextent",
815                  sensitive = _has_selected_layer)
816    _method_command("selected_full_extent", _("&Full selection extent"), "FullSelectionExtent",
817                   helptext = _("Full Selection Extent"), icon = "fullselextent",
818                  sensitive = _has_selected_shapes)
819  _method_command("map_print", _("Prin&t"), "PrintMap",  _method_command("map_print", _("Prin&t"), "PrintMap",
820                  helptext = _("Print the map"))                  helptext = _("Print the map"))
821  _method_command("map_rename", _("&Rename"), "RenameMap",  _method_command("map_rename", _("&Rename..."), "RenameMap",
822                  helptext = _("Rename the map"))                  helptext = _("Rename the map"))
823    _method_command("layer_add", _("&Add Layer..."), "AddLayer",
 # Layer menu  
 _method_command("layer_add", _("&Add Layer"), "AddLayer",  
824                  helptext = _("Add a new layer to active map"))                  helptext = _("Add a new layer to active map"))
825  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
826                  helptext = _("Remove selected layer(s)"),                  helptext = _("Remove selected layer(s)"),
827                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
828    
829    # Layer menu
830    _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
831                    sensitive = _has_selected_layer)
832  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
833                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer(s)"),
834                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
# Line 774  _method_command("layer_hide", _("&Hide") Line 844  _method_command("layer_hide", _("&Hide")
844  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
845                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
846                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
847  _method_command("layer_properties", _("Properties"), "LayerEditProperties",  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
848                    sensitive = _has_selected_layer)
849    _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
850                    sensitive = _has_selected_layer)
851    _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
852                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
853    
854    # Table menu
855    _method_command("table_open", _("&Open..."), "TableOpen")
856    _method_command("table_close", _("&Close"), "TableClose")
857    _method_command("table_show", _("&Show"), "TableShow")
858    _method_command("table_hide", _("&Hide"), "TableHide")
859    _method_command("table_join", _("&Join..."), "TableJoin")
860    
861  # the menu structure  # the menu structure
862  main_menu = Menu("<main>", "<main>",  main_menu = Menu("<main>", "<main>",
863                   [Menu("file", _("&File"),                   [Menu("file", _("&File"),
# Line 785  main_menu = Menu("<main>", "<main>", Line 866  main_menu = Menu("<main>", "<main>",
866                          "toggle_session_tree", None,                          "toggle_session_tree", None,
867                          "exit"]),                          "exit"]),
868                    Menu("map", _("&Map"),                    Menu("map", _("&Map"),
869                         ["layer_add", "layer_remove",                         ["layer_add", "layer_remove", "map_rename",
870                          None,                          None,
871                          "map_projection",                          "map_projection",
872                          None,                          None,
873                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
874                          "map_pan_tool", "map_identify_tool", "map_label_tool",                          "map_pan_tool",
875                            "map_full_extent",
876                            "layer_full_extent",
877                            "selected_full_extent",
878                          None,                          None,
879                          "map_full_extent",                          "map_identify_tool", "map_label_tool",
880                          None,                          None,
881                          "toggle_legend",                          "toggle_legend",
882                          None,                          None,
883                          "map_print",                          "map_print"]),
                         None,  
                         "map_rename"]),  
884                    Menu("layer", _("&Layer"),                    Menu("layer", _("&Layer"),
885                          ["layer_raise", "layer_lower",                          ["layer_raise", "layer_lower",
886                          None,                          None,
887                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
888                          None,                          None,
889                            "layer_projection",
890                            None,
891                          "layer_show_table",                          "layer_show_table",
892                            "layer_jointable",
893                            "layer_unjointable",
894                          None,                          None,
895                          "layer_properties"]),                          "layer_properties"]),
896                      Menu("table", _("&Table"),
897                           ["table_open", "table_close",
898                           None,
899                           "table_show", "table_hide",
900                           None,
901                           "table_join"]),
902                    Menu("help", _("&Help"),                    Menu("help", _("&Help"),
903                         ["help_about"])])                         ["help_about"])])
904    
# Line 814  main_menu = Menu("<main>", "<main>", Line 906  main_menu = Menu("<main>", "<main>",
906    
907  main_toolbar = Menu("<toolbar>", "<toolbar>",  main_toolbar = Menu("<toolbar>", "<toolbar>",
908                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",
909                       "map_full_extent", None,                       "map_full_extent",
910                         "layer_full_extent",
911                         "selected_full_extent",
912                         None,
913                       "map_identify_tool", "map_label_tool"])                       "map_identify_tool", "map_label_tool"])

Legend:
Removed from v.704  
changed lines
  Added in v.879

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26