/[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 193 by bh, Wed May 29 10:33:41 2002 UTC revision 535 by bh, Fri Mar 14 20:42:18 2003 UTC
# Line 1  Line 1 
1  # Copyright (C) 2001, 2002 by Intevation GmbH  # Copyright (C) 2001, 2002, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Jan-Oliver Wagner <[email protected]>  # Jan-Oliver Wagner <[email protected]>
4  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
# Line 12  The main window Line 12  The main window
12    
13  __version__ = "$Revision$"  __version__ = "$Revision$"
14    
15    __ThubanVersion__ = "0.2" #"$THUBAN_0_2$"
16    #__BuildDate__ = "$Date$"
17    
18  import os  import os
19    
20  from wxPython.wx import *  from wxPython.wx import *
21    
22  import Thuban  import Thuban
23    from Thuban import _
24  from Thuban.Model.session import create_empty_session  from Thuban.Model.session import create_empty_session
25  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer
26  from Thuban.Model.color import Color  from Thuban.Model.color import Color
# Line 26  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
34  from menu import Menu  from menu import Menu
35    
36  import main  from context import Context
37  from command import registry, Command  from command import registry, Command, ToolCommand
38  from messages import SELECTED_SHAPE, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION
39    
40    
41  # the directory where the toolbar icons are stored  # the directory where the toolbar icons are stored
# Line 40  bitmapext = ".xpm" Line 45  bitmapext = ".xpm"
45    
46  class MainWindow(wxFrame):  class MainWindow(wxFrame):
47    
48      def __init__(self, parent, ID, interactor):      # Some messages that can be subscribed/unsubscribed directly through
49          wxFrame.__init__(self, parent, ID, 'Thuban',      # the MapCanvas come in fact from other objects. This is a map to
50                           wxDefaultPosition, wxSize(400, 300))      # map those messages to the names of the instance variables they
51        # actually come from. This delegation is implemented in the
52        # Subscribe and unsubscribed methods
53        delegated_messages = {LAYER_SELECTED: "canvas",
54                              SHAPES_SELECTED: "canvas"}
55    
56        # Methods delegated to some instance variables. The delegation is
57        # implemented in the __getattr__ method.
58        delegated_methods = {"SelectLayer": "canvas",
59                             "SelectShapes": "canvas",
60                             }
61    
62        def __init__(self, parent, ID, title, application, interactor,
63                     initial_message = None, size = wxSize(-1, -1)):
64            wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)
65    
66          self.interactor = interactor          self.application = application
67    
68          self.CreateStatusBar()          self.CreateStatusBar()
69          self.SetStatusText("This is the wxPython-based "          if initial_message:
70                        "Graphical User Interface for exploring geographic data")              self.SetStatusText(initial_message)
71    
72          self.identify_view = None          self.identify_view = None
73    
# Line 63  class MainWindow(wxFrame): Line 82  class MainWindow(wxFrame):
82          toolbar.Realize()          toolbar.Realize()
83    
84          # Create the map canvas          # Create the map canvas
85          canvas = view.MapCanvas(self, -1, interactor)          canvas = view.MapCanvas(self, -1)
86          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)
87            canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)
88          self.canvas = canvas          self.canvas = canvas
89    
90          self.init_dialogs()          self.init_dialogs()
91    
         interactor.Subscribe(SELECTED_SHAPE, self.identify_view_on_demand)  
   
92          EVT_CLOSE(self, self.OnClose)          EVT_CLOSE(self, self.OnClose)
93    
94        def Subscribe(self, channel, *args):
95            """Subscribe a function to a message channel.
96    
97            If channel is one of the delegated messages call the appropriate
98            object's Subscribe method. Otherwise do nothing.
99            """
100            if channel in self.delegated_messages:
101                object = getattr(self, self.delegated_messages[channel])
102                object.Subscribe(channel, *args)
103            else:
104                print "Trying to subscribe to unsupported channel %s" % channel
105    
106        def Unsubscribe(self, channel, *args):
107            """Unsubscribe a function from a message channel.
108    
109            If channel is one of the delegated messages call the appropriate
110            object's Unsubscribe method. Otherwise do nothing.
111            """
112            if channel in self.delegated_messages:
113                object = getattr(self, self.delegated_messages[channel])
114                object.Unsubscribe(channel, *args)
115    
116        def __getattr__(self, attr):
117            """If attr is one of the delegated methods return that method
118    
119            Otherwise raise AttributeError.
120            """
121            if attr in self.delegated_methods:
122                return getattr(getattr(self, self.delegated_methods[attr]), attr)
123            raise AttributeError(attr)
124    
125      def init_ids(self):      def init_ids(self):
126          """Initialize the ids"""          """Initialize the ids"""
127          self.current_id = 6000          self.current_id = 6000
# Line 111  class MainWindow(wxFrame): Line 160  class MainWindow(wxFrame):
160          return menu_bar          return menu_bar
161    
162      def build_menu(self, menudesc):      def build_menu(self, menudesc):
163          """Build and return a wxMenu from a menudescription"""          """Return a wxMenu built from the menu description menudesc"""
164          wxmenu = wxMenu()          wxmenu = wxMenu()
165          last = None          last = None
166          for item in menudesc.items:          for item in menudesc.items:
             # here the items must all be Menu instances themselves  
167              if item is None:              if item is None:
168                  # a separator. Only add one if the last item was not a                  # a separator. Only add one if the last item was not a
169                  # separator                  # separator
# Line 168  class MainWindow(wxFrame): Line 216  class MainWindow(wxFrame):
216                              command.IsCheckCommand())                              command.IsCheckCommand())
217                  self.bind_command_events(command, ID)                  self.bind_command_events(command, ID)
218              else:              else:
219                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
220    
221      def add_toolbar_command(self, toolbar, name):      def add_toolbar_command(self, toolbar, name):
222          """Add the command with name name to the toolbar toolbar.          """Add the command with name name to the toolbar toolbar.
# Line 190  class MainWindow(wxFrame): Line 238  class MainWindow(wxFrame):
238                                  isToggle = command.IsCheckCommand())                                  isToggle = command.IsCheckCommand())
239                  self.bind_command_events(command, ID)                  self.bind_command_events(command, ID)
240              else:              else:
241                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
242    
243        def Context(self):
244            """Return the context object for a command invoked from this window
245            """
246            return Context(self.application, self.application.Session(), self)
247    
248      def invoke_command(self, event):      def invoke_command(self, event):
249          name = self.id_to_name.get(event.GetId())          name = self.id_to_name.get(event.GetId())
250          if name is not None:          if name is not None:
251              command = registry.Command(name)              command = registry.Command(name)
252              command.Execute(self)              command.Execute(self.Context())
253          else:          else:
254              print "Unknown command ID %d" % event.GetId()              print _("Unknown command ID %d") % event.GetId()
255    
256      def update_command_ui(self, event):      def update_command_ui(self, event):
257          #print "update_command_ui", self.id_to_name[event.GetId()]          #print "update_command_ui", self.id_to_name[event.GetId()]
258            context = self.Context()
259          command = registry.Command(self.id_to_name[event.GetId()])          command = registry.Command(self.id_to_name[event.GetId()])
260          if command is not None:          if command is not None:
261              event.Enable(command.Sensitive(self))              sensitive = command.Sensitive(context)
262              event.SetText(command.DynText(self))              event.Enable(sensitive)
263                if command.IsTool() and not sensitive and command.Checked(context):
264                    # When a checked tool command is disabled deselect all
265                    # tools. Otherwise the tool would remain active but it
266                    # might lead to errors if the tools stays active. This
267                    # problem occurred in GREAT-ER and this fixes it, but
268                    # it's not clear to me whether this is really the best
269                    # way to do it (BH, 20021206).
270                    self.canvas.SelectTool(None)
271                event.SetText(command.DynText(context))
272              if command.IsCheckCommand():              if command.IsCheckCommand():
273                  event.Check(command.Checked(self))                      event.Check(command.Checked(context))
274    
275      def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):      def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):
276          """Run a modal message box with the given text, title and flags          """Run a modal message box with the given text, title and flags
277          and return the result"""          and return the result"""
278          dlg = wxMessageDialog(self, text, title, flags)          dlg = wxMessageDialog(self, text, title, flags)
279            dlg.CenterOnParent()
280          result = dlg.ShowModal()          result = dlg.ShowModal()
281          dlg.Destroy()          dlg.Destroy()
282          return result          return result
# Line 226  class MainWindow(wxFrame): Line 290  class MainWindow(wxFrame):
290    
291      def add_dialog(self, name, dialog):      def add_dialog(self, name, dialog):
292          if self.dialogs.has_key(name):          if self.dialogs.has_key(name):
293              raise RuntimeError("The Dialog named %s is already open" % name)              raise RuntimeError(_("The Dialog named %s is already open") % name)
294          self.dialogs[name] = dialog          self.dialogs[name] = dialog
295    
296      def dialog_open(self, name):      def dialog_open(self, name):
# Line 244  class MainWindow(wxFrame): Line 308  class MainWindow(wxFrame):
308              text = "(%10.10g, %10.10g)" % pos              text = "(%10.10g, %10.10g)" % pos
309          else:          else:
310              text = ""              text = ""
311            self.set_position_text(text)
312    
313        def set_position_text(self, text):
314            """Set the statusbar text showing the current position.
315    
316            By default the text is shown in field 0 of the status bar.
317            Override this method in derived classes to put it into a
318            different field of the statusbar.
319            """
320          self.SetStatusText(text)          self.SetStatusText(text)
321    
322      def save_modified_session(self, can_veto = 1):      def save_modified_session(self, can_veto = 1):
# Line 255  class MainWindow(wxFrame): Line 328  class MainWindow(wxFrame):
328          If the can_veto parameter is true (default) the dialog includes          If the can_veto parameter is true (default) the dialog includes
329          a cancel button, otherwise not.          a cancel button, otherwise not.
330          """          """
331          if main.app.session.WasModified():          if self.application.session.WasModified():
332              flags = wxYES_NO | wxICON_QUESTION              flags = wxYES_NO | wxICON_QUESTION
333              if can_veto:              if can_veto:
334                  flags = flags | wxCANCEL                  flags = flags | wxCANCEL
335              result = self.RunMessageBox("Exit",              result = self.RunMessageBox(_("Exit"),
336                                          ("The session has been modified."                                          _("The session has been modified."
337                                           " Do you want to save it?"),                                           " Do you want to save it?"),
338                                          flags)                                          flags)
339              if result == wxID_YES:              if result == wxID_YES:
# Line 269  class MainWindow(wxFrame): Line 342  class MainWindow(wxFrame):
342              result = wxID_NO              result = wxID_NO
343          return result          return result
344    
345        def prepare_new_session(self):
346            for d in self.dialogs.values():
347                if not isinstance(d, tree.SessionTreeView):
348                    d.Close()
349    
350      def NewSession(self):      def NewSession(self):
351          self.save_modified_session()          self.save_modified_session()
352          main.app.SetSession(create_empty_session())          self.prepare_new_session()
353            self.application.SetSession(create_empty_session())
354    
355      def OpenSession(self):      def OpenSession(self):
356          self.save_modified_session()          self.save_modified_session()
357          dlg = wxFileDialog(self, "Select a session file", ".", "",          dlg = wxFileDialog(self, _("Open Session"), ".", "", "*.thuban", wxOPEN)
                            "*.thuban", wxOPEN)  
358          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
359              main.app.OpenSession(dlg.GetPath())              self.prepare_new_session()
360                self.application.OpenSession(dlg.GetPath())
361          dlg.Destroy()          dlg.Destroy()
362    
363      def SaveSession(self):      def SaveSession(self):
364          if main.app.session.filename == None:          if self.application.session.filename == None:
365              self.SaveSessionAs()              self.SaveSessionAs()
366          main.app.SaveSession()          else:
367                self.application.SaveSession()
368    
369      def SaveSessionAs(self):      def SaveSessionAs(self):
370          dlg = wxFileDialog(self, "Enter a filename for session", ".", "",          dlg = wxFileDialog(self, _("Save Session As"), ".", "",
371                             "*.thuban", wxOPEN)                             "*.thuban", wxOPEN)
372          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
373              main.app.session.SetFilename(dlg.GetPath())              self.application.session.SetFilename(dlg.GetPath())
374              main.app.SaveSession()              self.application.SaveSession()
375          dlg.Destroy()          dlg.Destroy()
376    
377      def Exit(self):      def Exit(self):
# Line 302  class MainWindow(wxFrame): Line 382  class MainWindow(wxFrame):
382          if result == wxID_CANCEL:          if result == wxID_CANCEL:
383              event.Veto()              event.Veto()
384          else:          else:
385                # FIXME: it would be better to tie the unsubscription to
386                # wx's destroy event, but that isn't implemented for wxGTK
387                # yet.
388                self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)
389              self.Destroy()              self.Destroy()
390    
391      def SetMap(self, map):      def SetMap(self, map):
392          self.canvas.SetMap(map)          self.canvas.SetMap(map)
393    
394        def Map(self):
395            """Return the map displayed by this mainwindow"""
396            return self.canvas.Map()
397    
398      def ShowSessionTree(self):      def ShowSessionTree(self):
399          name = "session_tree"          name = "session_tree"
400          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
401          if dialog is None:          if dialog is None:
402              dialog = tree.SessionTreeView(self, main.app, name)              dialog = tree.SessionTreeView(self, self.application, name)
403              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
404              dialog.Show(true)              dialog.Show(True)
405          else:          else:
406              # FIXME: bring dialog to front here              # FIXME: bring dialog to front here
407              pass              pass
408    
409    
410      def About(self):      def About(self):
411          self.RunMessageBox("About",          self.RunMessageBox(_("About"),
412                             ("Thuban is a program for\n"                             _("Thuban v%s\n"
413                                #"Build Date: %s\n"
414                                "\n"
415                                "Thuban is a program for\n"
416                              "exploring geographic data.\n"                              "exploring geographic data.\n"
417                              "Copyright (C) 2001 Intevation GmbH.\n"                              "Copyright (C) 2001-2003 Intevation GmbH.\n"
418                              "Thuban is licensed under the GPL"),                              "Thuban is licensed under the GNU GPL"
419                               % __ThubanVersion__), #__BuildDate__)),
420                             wxOK | wxICON_INFORMATION)                             wxOK | wxICON_INFORMATION)
421    
422      def AddLayer(self):      def AddLayer(self):
423          dlg = wxFileDialog(self, "Select a data file", ".", "", "*.*",          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",
424                             wxOPEN)                             wxOPEN)
425          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
426              filename = dlg.GetPath()              filename = dlg.GetPath()
# Line 339  class MainWindow(wxFrame): Line 432  class MainWindow(wxFrame):
432                  map.AddLayer(layer)                  map.AddLayer(layer)
433              except IOError:              except IOError:
434                  # the layer couldn't be opened                  # the layer couldn't be opened
435                  self.RunMessageBox("Add Layer",                  self.RunMessageBox(_("Add Layer"),
436                                     "Can't open the file '%s'." % filename)                                     _("Can't open the file '%s'.") % filename)
437              else:              else:
438                  if not has_layers:                  if not has_layers:
439                      # if we're adding a layer to an empty map, for the                      # if we're adding a layer to an empty map, fit the
440                      # new map to the window                      # new map to the window
441                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
442          dlg.Destroy()          dlg.Destroy()
# Line 353  class MainWindow(wxFrame): Line 446  class MainWindow(wxFrame):
446          if layer is not None:          if layer is not None:
447              self.canvas.Map().RemoveLayer(layer)              self.canvas.Map().RemoveLayer(layer)
448    
449        def CanRemoveLayer(self):
450            """Return true if the currently selected layer can be deleted.
451    
452            If no layer is selected return false.
453    
454            The return value of this method determines whether the remove
455            layer command is sensitive in menu.
456            """
457            layer = self.current_layer()
458            if layer is not None:
459                return self.canvas.Map().CanRemoveLayer(layer)
460            return 0
461    
462      def RaiseLayer(self):      def RaiseLayer(self):
463          layer = self.current_layer()          layer = self.current_layer()
464          if layer is not None:          if layer is not None:
465              self.canvas.Map().RaiseLayer(layer)              self.canvas.Map().RaiseLayer(layer)
466            
467      def LowerLayer(self):      def LowerLayer(self):
468          layer = self.current_layer()          layer = self.current_layer()
469          if layer is not None:          if layer is not None:
# Line 368  class MainWindow(wxFrame): Line 474  class MainWindow(wxFrame):
474    
475          If no layer is selected, return None          If no layer is selected, return None
476          """          """
477          return self.interactor.SelectedLayer()          return self.canvas.SelectedLayer()
478    
479      def has_selected_layer(self):      def has_selected_layer(self):
480          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
481          return self.interactor.HasSelectedLayer()          return self.canvas.HasSelectedLayer()
482    
483      def choose_color(self):      def choose_color(self):
484          """Run the color selection dialog and return the selected color.          """Run the color selection dialog and return the selected color.
# Line 395  class MainWindow(wxFrame): Line 501  class MainWindow(wxFrame):
501          if layer is not None:          if layer is not None:
502              color = self.choose_color()              color = self.choose_color()
503              if color is not None:              if color is not None:
504                  layer.SetFill(color)                  layer.GetClassification().SetDefaultFill(color)
505    
506      def LayerTransparentFill(self):      def LayerTransparentFill(self):
507          layer = self.current_layer()          layer = self.current_layer()
508          if layer is not None:          if layer is not None:
509              layer.SetFill(None)              layer.GetClassification().SetDefaultFill(Color.None)
510    
511      def LayerOutlineColor(self):      def LayerOutlineColor(self):
512          layer = self.current_layer()          layer = self.current_layer()
513          if layer is not None:          if layer is not None:
514              color = self.choose_color()              color = self.choose_color()
515              if color is not None:              if color is not None:
516                  layer.SetStroke(color)                  layer.GetClassification().SetDefaultLineColor(color)
517    
518      def LayerNoOutline(self):      def LayerNoOutline(self):
519          layer = self.current_layer()          layer = self.current_layer()
520          if layer is not None:          if layer is not None:
521              layer.SetStroke(None)              layer.GetClassification().SetDefaultLineColor(Color.None)
522    
523      def HideLayer(self):      def HideLayer(self):
524          layer = self.current_layer()          layer = self.current_layer()
# Line 431  class MainWindow(wxFrame): Line 537  class MainWindow(wxFrame):
537              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
538              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
539              if dialog is None:              if dialog is None:
540                  dialog = tableview.TableFrame(self, self.interactor, name,                  dialog = tableview.LayerTableFrame(self, name,
541                                                "Table: %s" % layer.Title(),                                                 _("Table: %s") % layer.Title(),
542                                                layer, table)                                                     layer, table)
543                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
544                  dialog.Show(true)                  dialog.Show(true)
545              else:              else:
# Line 457  class MainWindow(wxFrame): Line 563  class MainWindow(wxFrame):
563              map.SetProjection(proj)              map.SetProjection(proj)
564          proj4Dlg.Destroy()          proj4Dlg.Destroy()
565    
566        def Classify(self):
567    
568            #
569            # the menu option for this should only be available if there
570            # is a current layer, so we don't need to check if the
571            # current layer is None
572            #
573    
574            layer = self.current_layer()
575            name = "classifier" + str(id(layer))
576            dialog = self.get_open_dialog(name)
577    
578            if dialog is None:
579                dialog = classifier.Classifier(self, name, self.current_layer())
580                self.add_dialog(name, dialog)
581                dialog.Show()
582    
583      def ZoomInTool(self):      def ZoomInTool(self):
584          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
585    
# Line 479  class MainWindow(wxFrame): Line 602  class MainWindow(wxFrame):
602      def PrintMap(self):      def PrintMap(self):
603          self.canvas.Print()          self.canvas.Print()
604    
605      def identify_view_on_demand(self, layer, shape):      def identify_view_on_demand(self, layer, shapes):
606          name = "identify_view"          name = "identify_view"
607          if self.canvas.CurrentTool() == "IdentifyTool":          if self.canvas.CurrentTool() == "IdentifyTool":
608              if not self.dialog_open(name):              if not self.dialog_open(name):
609                  dialog = identifyview.IdentifyView(self, self.interactor, name)                  dialog = identifyview.IdentifyView(self, name)
610                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
611                  dialog.Show(true)                  dialog.Show(true)
612              else:              else:
# Line 497  class MainWindow(wxFrame): Line 620  class MainWindow(wxFrame):
620    
621  # Helper functions to define common command implementations  # Helper functions to define common command implementations
622  def call_method(context, methodname, *args):  def call_method(context, methodname, *args):
623      """Call the context's method methodname with args *args"""      """Call the mainwindow's method methodname with args *args"""
624      apply(getattr(context, methodname), args)      apply(getattr(context.mainwindow, methodname), args)
625    
626  def _method_command(name, title, method, helptext = "",  def _method_command(name, title, method, helptext = "",
627                      icon = "", sensitive = None):                      icon = "", sensitive = None):
628      """Add a command implemented by a method of the context object"""      """Add a command implemented by a method of the mainwindow object"""
629      registry.Add(Command(name, title, call_method, args=(method,),      registry.Add(Command(name, title, call_method, args=(method,),
630                           helptext = helptext, icon = icon,                           helptext = helptext, icon = icon,
631                           sensitive = sensitive))                           sensitive = sensitive))
632    
633    def make_check_current_tool(toolname):
634        """Return a function that tests if the currently active tool is toolname
635    
636        The returned function can be called with the context and returns
637        true iff the currently active tool's name is toolname. It's directly
638        usable as the 'checked' callback of a command.
639        """
640        def check_current_tool(context, name=toolname):
641            return context.mainwindow.canvas.CurrentTool() == name
642        return check_current_tool
643    
644  def _tool_command(name, title, method, toolname, helptext = "",  def _tool_command(name, title, method, toolname, helptext = "",
645                    icon = ""):                    icon = "", sensitive = None):
646      """Add a tool command"""      """Add a tool command"""
647      def check_current_tool(context, name=toolname):      registry.Add(ToolCommand(name, title, call_method, args=(method,),
648          return context.canvas.CurrentTool() == name                               helptext = helptext, icon = icon,
649      registry.Add(Command(name, title, call_method, args=(method,),                               checked = make_check_current_tool(toolname),
650                           helptext = helptext, icon = icon,                               sensitive = sensitive))
                          checked = check_current_tool))  
651    
652  def _has_selected_layer(context):  def _has_selected_layer(context):
653      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
654      return context.has_selected_layer()      return context.mainwindow.has_selected_layer()
655    
656    def _can_remove_layer(context):
657        return context.mainwindow.CanRemoveLayer()
658    
659    def _has_tree_window_shown(context):
660        """Return true if the tree window is shown"""
661        return context.mainwindow.get_open_dialog("session_tree") is None
662    
663    def _has_visible_map(context):
664        """Return true iff theres a visible map in the mainwindow.
665    
666        A visible map is a map with at least one visible layer."""
667        map = context.mainwindow.Map()
668        if map is not None:
669            for layer in map.Layers():
670                if layer.Visible():
671                    return 1
672        return 0
673    
674    
675  # File menu  # File menu
676  _method_command("new_session", "&New Session", "NewSession")  _method_command("new_session", _("&New Session"), "NewSession")
677  _method_command("open_session", "&Open Session", "OpenSession")  _method_command("open_session", _("&Open Session"), "OpenSession")
678  _method_command("save_session", "&Save Session", "SaveSession")  _method_command("save_session", _("&Save Session"), "SaveSession")
679  _method_command("save_session_as", "Save Session &As", "SaveSessionAs")  _method_command("save_session_as", _("Save Session &As"), "SaveSessionAs")
680  _method_command("show_session_tree", "Show Session &Tree", "ShowSessionTree")  _method_command("show_session_tree", _("Show Session &Tree"), "ShowSessionTree",
681  _method_command("exit", "&Exit", "Exit")                  sensitive = _has_tree_window_shown)
682    _method_command("exit", _("E&xit"), "Exit")
683    
684  # Help menu  # Help menu
685  _method_command("help_about", "&About", "About")  _method_command("help_about", _("&About"), "About")
686    
687    
688  # Map menu  # Map menu
689  _method_command("map_projection", "Pro&jection", "Projection")  _method_command("map_projection", _("Pro&jection"), "Projection")
690    
691  _tool_command("map_zoom_in_tool", "&Zoom in", "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
692                helptext = "Switch to map-mode 'zoom-in'", icon = "zoom_in")                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
693  _tool_command("map_zoom_out_tool", "Zoom &out", "ZoomOutTool", "ZoomOutTool",                sensitive = _has_visible_map)
694                helptext = "Switch to map-mode 'zoom-out'", icon = "zoom_out")  _tool_command("map_zoom_out_tool", _("Zoom &out"), "ZoomOutTool", "ZoomOutTool",
695  _tool_command("map_pan_tool", "&Pan", "PanTool", "PanTool",                helptext = _("Switch to map-mode 'zoom-out'"), icon = "zoom_out",
696                helptext = "Switch to map-mode 'pan'", icon = "pan")                sensitive = _has_visible_map)
697  _tool_command("map_identify_tool", "&Identify", "IdentifyTool", "IdentifyTool",  _tool_command("map_pan_tool", _("&Pan"), "PanTool", "PanTool",
698                helptext = "Switch to map-mode 'identify'", icon = "identify")                helptext = _("Switch to map-mode 'pan'"), icon = "pan",
699  _tool_command("map_label_tool", "&Label", "LabelTool", "LabelTool",                sensitive = _has_visible_map)
700                helptext = "Add/Remove labels", icon = "label")  _tool_command("map_identify_tool", _("&Identify"), "IdentifyTool",
701  _method_command("map_full_extent", "&Full extent", "FullExtent",                "IdentifyTool",
702                 helptext = "Full Extent", icon = "fullextent")                helptext = _("Switch to map-mode 'identify'"), icon = "identify",
703  _method_command("map_print", "Prin&t", "PrintMap", helptext = "Print the map")                sensitive = _has_visible_map)
704    _tool_command("map_label_tool", _("&Label"), "LabelTool", "LabelTool",
705                  helptext = _("Add/Remove labels"), icon = "label",
706                  sensitive = _has_visible_map)
707    _method_command("map_full_extent", _("&Full extent"), "FullExtent",
708                   helptext = _("Full Extent"), icon = "fullextent",
709                  sensitive = _has_visible_map)
710    _method_command("map_print", _("Prin&t"), "PrintMap",
711                    helptext = _("Print the map"))
712    
713  # Layer menu  # Layer menu
714  _method_command("layer_add", "&Add Layer", "AddLayer",  _method_command("layer_add", _("&Add Layer"), "AddLayer",
715                  helptext = "Add a new layer to active map")                  helptext = _("Add a new layer to active map"))
716  _method_command("layer_remove", "&Remove Layer", "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
717                  helptext = "Remove selected layer(s)",                  helptext = _("Remove selected layer(s)"),
718                    sensitive = _can_remove_layer)
719    _method_command("layer_fill_color", _("&Fill Color"), "LayerFillColor",
720                    helptext = _("Set the fill color of selected layer(s)"),
721                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
722  _method_command("layer_fill_color", "&Fill Color", "LayerFillColor",  _method_command("layer_transparent_fill", _("&Transparent Fill"),
                 helptext = "Set the fill color of selected layer(s)",  
                 sensitive = _has_selected_layer)  
 _method_command("layer_transparent_fill", "&Transparent Fill",  
723                  "LayerTransparentFill",                  "LayerTransparentFill",
724                  helptext = "Do not fill the selected layer(s)",                  helptext = _("Do not fill the selected layer(s)"),
725                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
726  _method_command("layer_outline_color", "&Outline Color", "LayerOutlineColor",  _method_command("layer_outline_color", _("&Outline Color"), "LayerOutlineColor",
727                  helptext = "Set the outline color of selected layer(s)",                  helptext = _("Set the outline color of selected layer(s)"),
728                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
729  _method_command("layer_no_outline", "&No Outline", "LayerNoOutline",  _method_command("layer_no_outline", _("&No Outline"), "LayerNoOutline",
730                  helptext = "Do not draw the outline of the selected layer(s)",                  helptext= _("Do not draw the outline of the selected layer(s)"),
731                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
732  _method_command("layer_raise", "&Raise", "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
733                  helptext = "Raise selected layer(s)",                  helptext = _("Raise selected layer(s)"),
734                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
735  _method_command("layer_lower", "&Lower", "LowerLayer",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
736                  helptext = "Lower selected layer(s)",                  helptext = _("Lower selected layer(s)"),
737                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
738  _method_command("layer_show", "&Show", "ShowLayer",  _method_command("layer_show", _("&Show"), "ShowLayer",
739                  helptext = "Make selected layer(s) visible",                  helptext = _("Make selected layer(s) visible"),
740                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
741  _method_command("layer_hide", "&Hide", "HideLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
742                  helptext = "Make selected layer(s) unvisible",                  helptext = _("Make selected layer(s) unvisible"),
743                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
744  _method_command("layer_show_table", "Show Ta&ble", "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
745                  helptext = "Show the selected layer's table",                  helptext = _("Show the selected layer's table"),
746                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
747    
748    _method_command("layer_classifier", _("Classify"), "Classify",
749                    sensitive = _has_selected_layer)
750    
751  # the menu structure  # the menu structure
752  main_menu = Menu("<main>", "<main>",  main_menu = Menu("<main>", "<main>",
753                   [Menu("file", "&File",                   [Menu("file", _("&File"),
754                         ["new_session", "open_session", None,                         ["new_session", "open_session", None,
755                          "save_session", "save_session_as", None,                          "save_session", "save_session_as", None,
756                          "show_session_tree", None,                          "show_session_tree", None,
757                          "exit"]),                          "exit"]),
758                    Menu("map", "&Map",                    Menu("map", _("&Map"),
759                         ["layer_add", "layer_remove",                         ["layer_add", "layer_remove",
760                          None,                          None,
761                          "map_projection",                          "map_projection",
# Line 603  main_menu = Menu("<main>", "<main>", Line 766  main_menu = Menu("<main>", "<main>",
766                          "map_full_extent",                          "map_full_extent",
767                          None,                          None,
768                          "map_print"]),                          "map_print"]),
769                    Menu("layer", "&Layer",                    Menu("layer", _("&Layer"),
770                         ["layer_fill_color", "layer_transparent_fill",                         ["layer_fill_color", "layer_transparent_fill",
771                          "layer_outline_color", "layer_no_outline",                          "layer_outline_color", "layer_no_outline",
772                          None,                          None,
# Line 611  main_menu = Menu("<main>", "<main>", Line 774  main_menu = Menu("<main>", "<main>",
774                          None,                          None,
775                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
776                          None,                          None,
777                          "layer_show_table"]),                          "layer_show_table",
778                    Menu("help", "&Help",                          None,
779                            "layer_classifier"]),
780                      Menu("help", _("&Help"),
781                         ["help_about"])])                         ["help_about"])])
782    
783  # the main toolbar  # the main toolbar
784    
785  main_toolbar = Menu("<toolbar>", "<toolbar>",  main_toolbar = Menu("<toolbar>", "<toolbar>",
786                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",
787                       "map_identify_tool", "map_label_tool", "map_full_extent"])                       "map_full_extent", None,
788                         "map_identify_tool", "map_label_tool"])

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26