/[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 621 by jonathan, Mon Apr 7 10:14:50 2003 UTC revision 653 by jonathan, Fri Apr 11 14:28:29 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  import legend
35  from menu import Menu  from menu import Menu
36    
# Line 40  from messages import LAYER_SELECTED, SHA Line 40  from messages import LAYER_SELECTED, SHA
40    
41  from Thuban.UI.dock import DockableWindow, DockFrame, DockPanel  from Thuban.UI.dock import DockableWindow, DockFrame, DockPanel
42    
43    import resource
44    
45    
46  # the directory where the toolbar icons are stored  # the directory where the toolbar icons are stored
47  bitmapdir = os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Bitmaps")  bitmapdir = os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Bitmaps")
# Line 243  class MainWindow(DockFrame): Line 245  class MainWindow(DockFrame):
245              command = registry.Command(name)              command = registry.Command(name)
246              if command is not None:              if command is not None:
247                  ID = self.get_id(name)                  ID = self.get_id(name)
248                  filename = os.path.join(bitmapdir, command.Icon()) + bitmapext                  bitmap = resource.GetBitmapResource(command.Icon(),
249                  bitmap = wxBitmap(filename, wxBITMAP_TYPE_XPM)                                                      wxBITMAP_TYPE_XPM)
250                  toolbar.AddTool(ID, bitmap,                  toolbar.AddTool(ID, bitmap,
251                                  shortHelpString = command.HelpText(),                                  shortHelpString = command.HelpText(),
252                                  isToggle = command.IsCheckCommand())                                  isToggle = command.IsCheckCommand())
# Line 403  class MainWindow(DockFrame): Line 405  class MainWindow(DockFrame):
405    
406      def SetMap(self, map):      def SetMap(self, map):
407          self.canvas.SetMap(map)          self.canvas.SetMap(map)
408            self.__SetTitle(map.Title())
409          #self.legendPanel.SetMap(map)          #self.legendPanel.SetMap(map)
410    
411      def Map(self):      def Map(self):
# Line 413  class MainWindow(DockFrame): Line 416  class MainWindow(DockFrame):
416    
417          return self.canvas.Map()          return self.canvas.Map()
418    
419      def ShowSessionTree(self):      def ToggleSessionTree(self):
420            """If the session tree is shown close it otherwise create a new tree"""
421          name = "session_tree"          name = "session_tree"
422          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
423          if dialog is None:          if dialog is None:
# Line 421  class MainWindow(DockFrame): Line 425  class MainWindow(DockFrame):
425              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
426              dialog.Show(True)              dialog.Show(True)
427          else:          else:
428              # FIXME: bring dialog to front here              dialog.Close()
             pass  
429    
430        def SessionTreeShown(self):
431            """Return true iff the session tree is currently shown"""
432            return self.get_open_dialog("session_tree") is not None
433    
434      def About(self):      def About(self):
435          self.RunMessageBox(_("About"),          self.RunMessageBox(_("About"),
# Line 514  class MainWindow(DockFrame): Line 520  class MainWindow(DockFrame):
520          dlg.Destroy()          dlg.Destroy()
521          return color          return color
522    
     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.Transparent)  
   
     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.Transparent)  
   
523      def HideLayer(self):      def HideLayer(self):
524          layer = self.current_layer()          layer = self.current_layer()
525          if layer is not None:          if layer is not None:
# Line 581  class MainWindow(DockFrame): Line 563  class MainWindow(DockFrame):
563              map.SetProjection(proj)              map.SetProjection(proj)
564          proj4Dlg.Destroy()          proj4Dlg.Destroy()
565    
566      def Classify(self):      def LayerEditProperties(self):
567    
568          #          #
569          # the menu option for this should only be available if there          # the menu option for this should only be available if there
# Line 590  class MainWindow(DockFrame): Line 572  class MainWindow(DockFrame):
572          #          #
573    
574          layer = self.current_layer()          layer = self.current_layer()
575          self.OpenClassifier(layer)          self.OpenLayerProperties(layer)
576    
577      def OpenClassifier(self, layer, group = None):      def OpenLayerProperties(self, layer, group = None):
578          name = "classifier" + str(id(layer))          name = "layer_properties" + str(id(layer))
579          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
580    
581          if dialog is None:          if dialog is None:
582              dialog = classifier.Classifier(self, name, layer, group)              dialog = Classifier(self, name, layer, group)
583              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
584              dialog.Show()              dialog.Show()
585          dialog.Raise()          dialog.Raise()
586    
587    
588      def ShowLegend(self):      def ShowLegend(self):
589            if not self.LegendShown():
590                self.ToggleLegend()
591    
592        def ToggleLegend(self):
593            """Show the legend if it's not shown otherwise hide it again"""
594          name = "legend"          name = "legend"
595          dialog = self.FindRegisteredDock(name)          dialog = self.FindRegisteredDock(name)
596    
597          if dialog is None:          if dialog is None:
598              title = "Legend: %s" % self.Map().Title()              dialog = self.CreateDock(name, -1, _("Legend"), wxLAYOUT_LEFT)
             dialog = self.CreateDock(name, -1, title, wxLAYOUT_LEFT)  
599              legend.LegendPanel(dialog, None, self)              legend.LegendPanel(dialog, None, self)
600              dialog.Dock()              dialog.Dock()
601                dialog.GetPanel().SetMap(self.Map())
602                dialog.Show()
603            else:
604                dialog.Show(not dialog.IsShown())
605    
606          dialog.GetPanel().SetMap(self.Map())      def LegendShown(self):
607          dialog.Show()          """Return true iff the legend is currently open"""
608            dialog = self.FindRegisteredDock("legend")
609            return dialog is not None and dialog.IsShown()
610    
611      def ZoomInTool(self):      def ZoomInTool(self):
612          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
# Line 638  class MainWindow(DockFrame): Line 630  class MainWindow(DockFrame):
630      def PrintMap(self):      def PrintMap(self):
631          self.canvas.Print()          self.canvas.Print()
632    
633        def RenameMap(self):
634            dlg = wxTextEntryDialog(self, "Map Title: ", "Rename Map",
635                                    self.Map().Title())
636            if dlg.ShowModal() == wxID_OK:
637                title = dlg.GetValue()
638                if title != "":
639                    self.Map().SetTitle(title)
640                    self.__SetTitle(title)
641    
642            dlg.Destroy()
643    
644      def identify_view_on_demand(self, layer, shapes):      def identify_view_on_demand(self, layer, shapes):
645          name = "identify_view"          name = "identify_view"
646          if self.canvas.CurrentTool() == "IdentifyTool":          if self.canvas.CurrentTool() == "IdentifyTool":
# Line 649  class MainWindow(DockFrame): Line 652  class MainWindow(DockFrame):
652                  # FIXME: bring dialog to front?                  # FIXME: bring dialog to front?
653                  pass                  pass
654    
655        def __SetTitle(self, title):
656            self.SetTitle("Thuban - " + title)
657    
658  #  #
659  # Define all the commands available in the main window  # Define all the commands available in the main window
660  #  #
# Line 660  def call_method(context, methodname, *ar Line 666  def call_method(context, methodname, *ar
666      apply(getattr(context.mainwindow, methodname), args)      apply(getattr(context.mainwindow, methodname), args)
667    
668  def _method_command(name, title, method, helptext = "",  def _method_command(name, title, method, helptext = "",
669                      icon = "", sensitive = None):                      icon = "", sensitive = None, checked = None):
670      """Add a command implemented by a method of the mainwindow object"""      """Add a command implemented by a method of the mainwindow object"""
671      registry.Add(Command(name, title, call_method, args=(method,),      registry.Add(Command(name, title, call_method, args=(method,),
672                           helptext = helptext, icon = icon,                           helptext = helptext, icon = icon,
673                           sensitive = sensitive))                           sensitive = sensitive, checked = checked))
674    
675  def make_check_current_tool(toolname):  def make_check_current_tool(toolname):
676      """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 694  def _can_remove_layer(context): Line 700  def _can_remove_layer(context):
700    
701  def _has_tree_window_shown(context):  def _has_tree_window_shown(context):
702      """Return true if the tree window is shown"""      """Return true if the tree window is shown"""
703      return context.mainwindow.get_open_dialog("session_tree") is None      return context.mainwindow.SessionTreeShown()
704    
705  def _has_visible_map(context):  def _has_visible_map(context):
706      """Return true iff theres a visible map in the mainwindow.      """Return true iff theres a visible map in the mainwindow.
# Line 709  def _has_visible_map(context): Line 715  def _has_visible_map(context):
715    
716  def _has_legend_shown(context):  def _has_legend_shown(context):
717      """Return true if the legend window is shown"""      """Return true if the legend window is shown"""
718      return context.mainwindow.FindRegisteredDock("legend") is None      return context.mainwindow.LegendShown()
719    
720    
721  # File menu  # File menu
# Line 717  _method_command("new_session", _("&New S Line 723  _method_command("new_session", _("&New S
723  _method_command("open_session", _("&Open Session"), "OpenSession")  _method_command("open_session", _("&Open Session"), "OpenSession")
724  _method_command("save_session", _("&Save Session"), "SaveSession")  _method_command("save_session", _("&Save Session"), "SaveSession")
725  _method_command("save_session_as", _("Save Session &As"), "SaveSessionAs")  _method_command("save_session_as", _("Save Session &As"), "SaveSessionAs")
726  _method_command("show_session_tree", _("Session &Tree"), "ShowSessionTree",  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
727                  sensitive = _has_tree_window_shown)                  checked = _has_tree_window_shown)
728  _method_command("show_legend", _("Legend"), "ShowLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
729                  sensitive = _has_legend_shown)                  checked = _has_legend_shown)
730  _method_command("exit", _("E&xit"), "Exit")  _method_command("exit", _("E&xit"), "Exit")
731    
732  # Help menu  # Help menu
# Line 751  _method_command("map_full_extent", _("&F Line 757  _method_command("map_full_extent", _("&F
757                sensitive = _has_visible_map)                sensitive = _has_visible_map)
758  _method_command("map_print", _("Prin&t"), "PrintMap",  _method_command("map_print", _("Prin&t"), "PrintMap",
759                  helptext = _("Print the map"))                  helptext = _("Print the map"))
760    _method_command("map_rename", _("&Rename"), "RenameMap",
761                    helptext = _("Rename the map"))
762    
763  # Layer menu  # Layer menu
764  _method_command("layer_add", _("&Add Layer"), "AddLayer",  _method_command("layer_add", _("&Add Layer"), "AddLayer",
# Line 758  _method_command("layer_add", _("&Add Lay Line 766  _method_command("layer_add", _("&Add Lay
766  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
767                  helptext = _("Remove selected layer(s)"),                  helptext = _("Remove selected layer(s)"),
768                  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)  
769  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
770                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer(s)"),
771                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
# Line 786  _method_command("layer_hide", _("&Hide") Line 781  _method_command("layer_hide", _("&Hide")
781  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
782                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
783                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
784  _method_command("layer_classifier", _("Classify"), "Classify",  _method_command("layer_properties", _("Properties"), "LayerEditProperties",
785                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
786    
787  # the menu structure  # the menu structure
# Line 794  main_menu = Menu("<main>", "<main>", Line 789  main_menu = Menu("<main>", "<main>",
789                   [Menu("file", _("&File"),                   [Menu("file", _("&File"),
790                         ["new_session", "open_session", None,                         ["new_session", "open_session", None,
791                          "save_session", "save_session_as", None,                          "save_session", "save_session_as", None,
792                          "show_session_tree",                          "toggle_session_tree", None,
                         "show_legend", None,  
793                          "exit"]),                          "exit"]),
794                    Menu("map", _("&Map"),                    Menu("map", _("&Map"),
795                         ["layer_add", "layer_remove",                         ["layer_add", "layer_remove",
# Line 807  main_menu = Menu("<main>", "<main>", Line 801  main_menu = Menu("<main>", "<main>",
801                          None,                          None,
802                          "map_full_extent",                          "map_full_extent",
803                          None,                          None,
804                          "map_print"]),                          "toggle_legend",
805                    Menu("layer", _("&Layer"),                          None,
806                         ["layer_fill_color", "layer_transparent_fill",                          "map_print",
                         "layer_outline_color", "layer_no_outline",  
807                          None,                          None,
808                          "layer_raise", "layer_lower",                          "map_rename"]),
809                      Menu("layer", _("&Layer"),
810                            ["layer_raise", "layer_lower",
811                          None,                          None,
812                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
813                          None,                          None,
814                          "layer_show_table",                          "layer_show_table",
815                          None,                          None,
816                          "layer_classifier"]),                          "layer_properties"]),
817                    Menu("help", _("&Help"),                    Menu("help", _("&Help"),
818                         ["help_about"])])                         ["help_about"])])
819    

Legend:
Removed from v.621  
changed lines
  Added in v.653

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26