/[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 535 by bh, Fri Mar 14 20:42:18 2003 UTC revision 704 by bh, Tue Apr 22 16:55:50 2003 UTC
# Line 30  import view Line 30  import view
30  import tree  import tree
31  import proj4dialog  import proj4dialog
32  import tableview, identifyview  import tableview, identifyview
33  import classifier  from Thuban.UI.classifier import Classifier
34    import legend
35  from menu import Menu  from menu import Menu
36    
37  from context import Context  from context import Context
38  from command import registry, Command, ToolCommand  from command import registry, Command, ToolCommand
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
42    
43  # the directory where the toolbar icons are stored  import resource
 bitmapdir = os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Bitmaps")  
 bitmapext = ".xpm"  
44    
45    
46  class MainWindow(wxFrame):  
47    class MainWindow(DockFrame):
48    
49      # Some messages that can be subscribed/unsubscribed directly through      # Some messages that can be subscribed/unsubscribed directly through
50      # the MapCanvas come in fact from other objects. This is a map to      # the MapCanvas come in fact from other objects. This is a map to
# Line 61  class MainWindow(wxFrame): Line 62  class MainWindow(wxFrame):
62    
63      def __init__(self, parent, ID, title, application, interactor,      def __init__(self, parent, ID, title, application, interactor,
64                   initial_message = None, size = wxSize(-1, -1)):                   initial_message = None, size = wxSize(-1, -1)):
65          wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)          DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)
66            #wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)
67    
68          self.application = application          self.application = application
69    
# Line 81  class MainWindow(wxFrame): Line 83  class MainWindow(wxFrame):
83          # call Realize to make sure that the tools appear.          # call Realize to make sure that the tools appear.
84          toolbar.Realize()          toolbar.Realize()
85    
86    
87          # Create the map canvas          # Create the map canvas
88          canvas = view.MapCanvas(self, -1)          canvas = view.MapCanvas(self, -1)
89          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)
90          canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)          canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)
91          self.canvas = canvas          self.canvas = canvas
92    
93            self.SetMainWindow(self.canvas)
94    
95            self.SetAutoLayout(True)
96    
97          self.init_dialogs()          self.init_dialogs()
98    
99          EVT_CLOSE(self, self.OnClose)          EVT_CLOSE(self, self._OnClose)
100    
101      def Subscribe(self, channel, *args):      def Subscribe(self, channel, *args):
102          """Subscribe a function to a message channel.          """Subscribe a function to a message channel.
# Line 231  class MainWindow(wxFrame): Line 238  class MainWindow(wxFrame):
238              command = registry.Command(name)              command = registry.Command(name)
239              if command is not None:              if command is not None:
240                  ID = self.get_id(name)                  ID = self.get_id(name)
241                  filename = os.path.join(bitmapdir, command.Icon()) + bitmapext                  bitmap = resource.GetBitmapResource(command.Icon(),
242                  bitmap = wxBitmap(filename, wxBITMAP_TYPE_XPM)                                                      wxBITMAP_TYPE_XPM)
243                  toolbar.AddTool(ID, bitmap,                  toolbar.AddTool(ID, bitmap,
244                                  shortHelpString = command.HelpText(),                                  shortHelpString = command.HelpText(),
245                                  isToggle = command.IsCheckCommand())                                  isToggle = command.IsCheckCommand())
# Line 375  class MainWindow(wxFrame): Line 382  class MainWindow(wxFrame):
382          dlg.Destroy()          dlg.Destroy()
383    
384      def Exit(self):      def Exit(self):
385          self.Close(false)          self.Close(False)
386    
387      def OnClose(self, event):      def _OnClose(self, event):
388          result = self.save_modified_session(can_veto = event.CanVeto())          result = self.save_modified_session(can_veto = event.CanVeto())
389          if result == wxID_CANCEL:          if result == wxID_CANCEL:
390              event.Veto()              event.Veto()
# Line 386  class MainWindow(wxFrame): Line 393  class MainWindow(wxFrame):
393              # wx's destroy event, but that isn't implemented for wxGTK              # wx's destroy event, but that isn't implemented for wxGTK
394              # yet.              # yet.
395              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)
396                DockFrame._OnClose(self, event)
397              self.Destroy()              self.Destroy()
398    
399      def SetMap(self, map):      def SetMap(self, map):
400          self.canvas.SetMap(map)          self.canvas.SetMap(map)
401            self.__SetTitle(map.Title())
402            #self.legendPanel.SetMap(map)
403    
404      def Map(self):      def Map(self):
405          """Return the map displayed by this mainwindow"""          """Return the map displayed by this mainwindow"""
406    
407            # sanity check
408            #assert(self.canvas.Map() is self.legendPanel.GetMap())
409    
410          return self.canvas.Map()          return self.canvas.Map()
411    
412      def ShowSessionTree(self):      def ToggleSessionTree(self):
413            """If the session tree is shown close it otherwise create a new tree"""
414          name = "session_tree"          name = "session_tree"
415          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
416          if dialog is None:          if dialog is None:
# Line 403  class MainWindow(wxFrame): Line 418  class MainWindow(wxFrame):
418              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
419              dialog.Show(True)              dialog.Show(True)
420          else:          else:
421              # FIXME: bring dialog to front here              dialog.Close()
             pass  
422    
423        def SessionTreeShown(self):
424            """Return true iff the session tree is currently shown"""
425            return self.get_open_dialog("session_tree") is not None
426    
427      def About(self):      def About(self):
428          self.RunMessageBox(_("About"),          self.RunMessageBox(_("About"),
# Line 449  class MainWindow(wxFrame): Line 466  class MainWindow(wxFrame):
466      def CanRemoveLayer(self):      def CanRemoveLayer(self):
467          """Return true if the currently selected layer can be deleted.          """Return true if the currently selected layer can be deleted.
468    
469          If no layer is selected return false.          If no layer is selected return False.
470    
471          The return value of this method determines whether the remove          The return value of this method determines whether the remove
472          layer command is sensitive in menu.          layer command is sensitive in menu.
# Line 457  class MainWindow(wxFrame): Line 474  class MainWindow(wxFrame):
474          layer = self.current_layer()          layer = self.current_layer()
475          if layer is not None:          if layer is not None:
476              return self.canvas.Map().CanRemoveLayer(layer)              return self.canvas.Map().CanRemoveLayer(layer)
477          return 0          return False
478    
479      def RaiseLayer(self):      def RaiseLayer(self):
480          layer = self.current_layer()          layer = self.current_layer()
# Line 496  class MainWindow(wxFrame): Line 513  class MainWindow(wxFrame):
513          dlg.Destroy()          dlg.Destroy()
514          return color          return color
515    
     def LayerFillColor(self):  
         layer = self.current_layer()  
         if layer is not None:  
             color = self.choose_color()  
             if color is not None:  
                 layer.GetClassification().SetDefaultFill(color)  
   
     def LayerTransparentFill(self):  
         layer = self.current_layer()  
         if layer is not None:  
             layer.GetClassification().SetDefaultFill(Color.None)  
   
     def LayerOutlineColor(self):  
         layer = self.current_layer()  
         if layer is not None:  
             color = self.choose_color()  
             if color is not None:  
                 layer.GetClassification().SetDefaultLineColor(color)  
   
     def LayerNoOutline(self):  
         layer = self.current_layer()  
         if layer is not None:  
             layer.GetClassification().SetDefaultLineColor(Color.None)  
   
516      def HideLayer(self):      def HideLayer(self):
517          layer = self.current_layer()          layer = self.current_layer()
518          if layer is not None:          if layer is not None:
# Line 563  class MainWindow(wxFrame): Line 556  class MainWindow(wxFrame):
556              map.SetProjection(proj)              map.SetProjection(proj)
557          proj4Dlg.Destroy()          proj4Dlg.Destroy()
558    
559      def Classify(self):      def LayerEditProperties(self):
560    
561          #          #
562          # the menu option for this should only be available if there          # the menu option for this should only be available if there
# Line 572  class MainWindow(wxFrame): Line 565  class MainWindow(wxFrame):
565          #          #
566    
567          layer = self.current_layer()          layer = self.current_layer()
568          name = "classifier" + str(id(layer))          self.OpenLayerProperties(layer)
569    
570        def OpenLayerProperties(self, layer, group = None):
571            name = "layer_properties" + str(id(layer))
572          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
573    
574          if dialog is None:          if dialog is None:
575              dialog = classifier.Classifier(self, name, self.current_layer())              dialog = Classifier(self, name, layer, group)
576              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
577              dialog.Show()              dialog.Show()
578            dialog.Raise()
579    
580    
581        def ShowLegend(self):
582            if not self.LegendShown():
583                self.ToggleLegend()
584    
585        def ToggleLegend(self):
586            """Show the legend if it's not shown otherwise hide it again"""
587            name = "legend"
588            dialog = self.FindRegisteredDock(name)
589    
590            if dialog is None:
591                dialog = self.CreateDock(name, -1, _("Legend"), wxLAYOUT_LEFT)
592                legend.LegendPanel(dialog, None, self)
593                dialog.Dock()
594                dialog.GetPanel().SetMap(self.Map())
595                dialog.Show()
596            else:
597                dialog.Show(not dialog.IsShown())
598    
599        def LegendShown(self):
600            """Return true iff the legend is currently open"""
601            dialog = self.FindRegisteredDock("legend")
602            return dialog is not None and dialog.IsShown()
603    
604      def ZoomInTool(self):      def ZoomInTool(self):
605          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
# Line 602  class MainWindow(wxFrame): Line 623  class MainWindow(wxFrame):
623      def PrintMap(self):      def PrintMap(self):
624          self.canvas.Print()          self.canvas.Print()
625    
626        def RenameMap(self):
627            dlg = wxTextEntryDialog(self, "Map Title: ", "Rename Map",
628                                    self.Map().Title())
629            if dlg.ShowModal() == wxID_OK:
630                title = dlg.GetValue()
631                if title != "":
632                    self.Map().SetTitle(title)
633                    self.__SetTitle(title)
634    
635            dlg.Destroy()
636    
637      def identify_view_on_demand(self, layer, shapes):      def identify_view_on_demand(self, layer, shapes):
638          name = "identify_view"          name = "identify_view"
639          if self.canvas.CurrentTool() == "IdentifyTool":          if self.canvas.CurrentTool() == "IdentifyTool":
640              if not self.dialog_open(name):              if not self.dialog_open(name):
641                  dialog = identifyview.IdentifyView(self, name)                  dialog = identifyview.IdentifyView(self, name)
642                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
643                  dialog.Show(true)                  dialog.Show(True)
644              else:              else:
645                  # FIXME: bring dialog to front?                  # FIXME: bring dialog to front?
646                  pass                  pass
647    
648        def __SetTitle(self, title):
649            self.SetTitle("Thuban - " + title)
650    
651  #  #
652  # Define all the commands available in the main window  # Define all the commands available in the main window
653  #  #
# Line 624  def call_method(context, methodname, *ar Line 659  def call_method(context, methodname, *ar
659      apply(getattr(context.mainwindow, methodname), args)      apply(getattr(context.mainwindow, methodname), args)
660    
661  def _method_command(name, title, method, helptext = "",  def _method_command(name, title, method, helptext = "",
662                      icon = "", sensitive = None):                      icon = "", sensitive = None, checked = None):
663      """Add a command implemented by a method of the mainwindow object"""      """Add a command implemented by a method of the mainwindow object"""
664      registry.Add(Command(name, title, call_method, args=(method,),      registry.Add(Command(name, title, call_method, args=(method,),
665                           helptext = helptext, icon = icon,                           helptext = helptext, icon = icon,
666                           sensitive = sensitive))                           sensitive = sensitive, checked = checked))
667    
668  def make_check_current_tool(toolname):  def make_check_current_tool(toolname):
669      """Return a function that tests if the currently active tool is toolname      """Return a function that tests if the currently active tool is toolname
# Line 658  def _can_remove_layer(context): Line 693  def _can_remove_layer(context):
693    
694  def _has_tree_window_shown(context):  def _has_tree_window_shown(context):
695      """Return true if the tree window is shown"""      """Return true if the tree window is shown"""
696      return context.mainwindow.get_open_dialog("session_tree") is None      return context.mainwindow.SessionTreeShown()
697    
698  def _has_visible_map(context):  def _has_visible_map(context):
699      """Return true iff theres a visible map in the mainwindow.      """Return true iff theres a visible map in the mainwindow.
# Line 671  def _has_visible_map(context): Line 706  def _has_visible_map(context):
706                  return 1                  return 1
707      return 0      return 0
708    
709    def _has_legend_shown(context):
710        """Return true if the legend window is shown"""
711        return context.mainwindow.LegendShown()
712    
713    
714  # File menu  # File menu
715  _method_command("new_session", _("&New Session"), "NewSession")  _method_command("new_session", _("&New Session"), "NewSession")
716  _method_command("open_session", _("&Open Session"), "OpenSession")  _method_command("open_session", _("&Open Session"), "OpenSession")
717  _method_command("save_session", _("&Save Session"), "SaveSession")  _method_command("save_session", _("&Save Session"), "SaveSession")
718  _method_command("save_session_as", _("Save Session &As"), "SaveSessionAs")  _method_command("save_session_as", _("Save Session &As"), "SaveSessionAs")
719  _method_command("show_session_tree", _("Show Session &Tree"), "ShowSessionTree",  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
720                  sensitive = _has_tree_window_shown)                  checked = _has_tree_window_shown)
721    _method_command("toggle_legend", _("Legend"), "ToggleLegend",
722                    checked = _has_legend_shown)
723  _method_command("exit", _("E&xit"), "Exit")  _method_command("exit", _("E&xit"), "Exit")
724    
725  # Help menu  # Help menu
# Line 709  _method_command("map_full_extent", _("&F Line 750  _method_command("map_full_extent", _("&F
750                sensitive = _has_visible_map)                sensitive = _has_visible_map)
751  _method_command("map_print", _("Prin&t"), "PrintMap",  _method_command("map_print", _("Prin&t"), "PrintMap",
752                  helptext = _("Print the map"))                  helptext = _("Print the map"))
753    _method_command("map_rename", _("&Rename"), "RenameMap",
754                    helptext = _("Rename the map"))
755    
756  # Layer menu  # Layer menu
757  _method_command("layer_add", _("&Add Layer"), "AddLayer",  _method_command("layer_add", _("&Add Layer"), "AddLayer",
# Line 716  _method_command("layer_add", _("&Add Lay Line 759  _method_command("layer_add", _("&Add Lay
759  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
760                  helptext = _("Remove selected layer(s)"),                  helptext = _("Remove selected layer(s)"),
761                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
 _method_command("layer_fill_color", _("&Fill Color"), "LayerFillColor",  
                 helptext = _("Set the fill color of selected layer(s)"),  
                 sensitive = _has_selected_layer)  
 _method_command("layer_transparent_fill", _("&Transparent Fill"),  
                 "LayerTransparentFill",  
                 helptext = _("Do not fill the selected layer(s)"),  
                 sensitive = _has_selected_layer)  
 _method_command("layer_outline_color", _("&Outline Color"), "LayerOutlineColor",  
                 helptext = _("Set the outline color of selected layer(s)"),  
                 sensitive = _has_selected_layer)  
 _method_command("layer_no_outline", _("&No Outline"), "LayerNoOutline",  
                 helptext= _("Do not draw the outline of the selected layer(s)"),  
                 sensitive = _has_selected_layer)  
762  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
763                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer(s)"),
764                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
# Line 744  _method_command("layer_hide", _("&Hide") Line 774  _method_command("layer_hide", _("&Hide")
774  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
775                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
776                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
777    _method_command("layer_properties", _("Properties"), "LayerEditProperties",
 _method_command("layer_classifier", _("Classify"), "Classify",  
778                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
779    
780  # the menu structure  # the menu structure
# Line 753  main_menu = Menu("<main>", "<main>", Line 782  main_menu = Menu("<main>", "<main>",
782                   [Menu("file", _("&File"),                   [Menu("file", _("&File"),
783                         ["new_session", "open_session", None,                         ["new_session", "open_session", None,
784                          "save_session", "save_session_as", None,                          "save_session", "save_session_as", None,
785                          "show_session_tree", None,                          "toggle_session_tree", None,
786                          "exit"]),                          "exit"]),
787                    Menu("map", _("&Map"),                    Menu("map", _("&Map"),
788                         ["layer_add", "layer_remove",                         ["layer_add", "layer_remove",
# Line 765  main_menu = Menu("<main>", "<main>", Line 794  main_menu = Menu("<main>", "<main>",
794                          None,                          None,
795                          "map_full_extent",                          "map_full_extent",
796                          None,                          None,
797                          "map_print"]),                          "toggle_legend",
                   Menu("layer", _("&Layer"),  
                        ["layer_fill_color", "layer_transparent_fill",  
                         "layer_outline_color", "layer_no_outline",  
798                          None,                          None,
799                          "layer_raise", "layer_lower",                          "map_print",
800                            None,
801                            "map_rename"]),
802                      Menu("layer", _("&Layer"),
803                            ["layer_raise", "layer_lower",
804                          None,                          None,
805                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
806                          None,                          None,
807                          "layer_show_table",                          "layer_show_table",
808                          None,                          None,
809                          "layer_classifier"]),                          "layer_properties"]),
810                    Menu("help", _("&Help"),                    Menu("help", _("&Help"),
811                         ["help_about"])])                         ["help_about"])])
812    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26