/[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 238 by bh, Wed Jul 24 10:19:46 2002 UTC revision 704 by bh, Tue Apr 22 16:55:50 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    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  from command import registry, Command, ToolCommand
39  from messages import SELECTED_SHAPE, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION
40    
41    from Thuban.UI.dock import DockFrame
42    
43    import resource
44    
45    
 # the directory where the toolbar icons are stored  
 bitmapdir = os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Bitmaps")  
 bitmapext = ".xpm"  
46    
47    class MainWindow(DockFrame):
48    
49  class MainWindow(wxFrame):      # Some messages that can be subscribed/unsubscribed directly through
50        # the MapCanvas come in fact from other objects. This is a map to
51        # map those messages to the names of the instance variables they
52        # actually come from. This delegation is implemented in the
53        # Subscribe and unsubscribed methods
54        delegated_messages = {LAYER_SELECTED: "canvas",
55                              SHAPES_SELECTED: "canvas"}
56    
57        # Methods delegated to some instance variables. The delegation is
58        # implemented in the __getattr__ method.
59        delegated_methods = {"SelectLayer": "canvas",
60                             "SelectShapes": "canvas",
61                             }
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
         self.interactor = interactor  
69    
70          self.CreateStatusBar()          self.CreateStatusBar()
71          if initial_message:          if initial_message:
# Line 63  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, interactor)          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)
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          interactor.Subscribe(SELECTED_SHAPE, self.identify_view_on_demand)          EVT_CLOSE(self, self._OnClose)
100    
101        def Subscribe(self, channel, *args):
102            """Subscribe a function to a message channel.
103    
104            If channel is one of the delegated messages call the appropriate
105            object's Subscribe method. Otherwise do nothing.
106            """
107            if channel in self.delegated_messages:
108                object = getattr(self, self.delegated_messages[channel])
109                object.Subscribe(channel, *args)
110            else:
111                print "Trying to subscribe to unsupported channel %s" % channel
112    
113        def Unsubscribe(self, channel, *args):
114            """Unsubscribe a function from a message channel.
115    
116            If channel is one of the delegated messages call the appropriate
117            object's Unsubscribe method. Otherwise do nothing.
118            """
119            if channel in self.delegated_messages:
120                object = getattr(self, self.delegated_messages[channel])
121                object.Unsubscribe(channel, *args)
122    
123        def __getattr__(self, attr):
124            """If attr is one of the delegated methods return that method
125    
126          EVT_CLOSE(self, self.OnClose)          Otherwise raise AttributeError.
127            """
128            if attr in self.delegated_methods:
129                return getattr(getattr(self, self.delegated_methods[attr]), attr)
130            raise AttributeError(attr)
131    
132      def init_ids(self):      def init_ids(self):
133          """Initialize the ids"""          """Initialize the ids"""
# Line 112  class MainWindow(wxFrame): Line 167  class MainWindow(wxFrame):
167          return menu_bar          return menu_bar
168    
169      def build_menu(self, menudesc):      def build_menu(self, menudesc):
170          """Build and return a wxMenu from a menudescription"""          """Return a wxMenu built from the menu description menudesc"""
171          wxmenu = wxMenu()          wxmenu = wxMenu()
172          last = None          last = None
173          for item in menudesc.items:          for item in menudesc.items:
             # here the items must all be Menu instances themselves  
174              if item is None:              if item is None:
175                  # a separator. Only add one if the last item was not a                  # a separator. Only add one if the last item was not a
176                  # separator                  # separator
# Line 169  class MainWindow(wxFrame): Line 223  class MainWindow(wxFrame):
223                              command.IsCheckCommand())                              command.IsCheckCommand())
224                  self.bind_command_events(command, ID)                  self.bind_command_events(command, ID)
225              else:              else:
226                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
227    
228      def add_toolbar_command(self, toolbar, name):      def add_toolbar_command(self, toolbar, name):
229          """Add the command with name name to the toolbar toolbar.          """Add the command with name name to the toolbar toolbar.
# Line 184  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())
246                  self.bind_command_events(command, ID)                  self.bind_command_events(command, ID)
247              else:              else:
248                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
249    
250        def Context(self):
251            """Return the context object for a command invoked from this window
252            """
253            return Context(self.application, self.application.Session(), self)
254    
255      def invoke_command(self, event):      def invoke_command(self, event):
256          name = self.id_to_name.get(event.GetId())          name = self.id_to_name.get(event.GetId())
257          if name is not None:          if name is not None:
258              command = registry.Command(name)              command = registry.Command(name)
259              context = Context(self.application, self.application.Session(),              command.Execute(self.Context())
                               self)  
             command.Execute(context)  
260          else:          else:
261              print "Unknown command ID %d" % event.GetId()              print _("Unknown command ID %d") % event.GetId()
262    
263      def update_command_ui(self, event):      def update_command_ui(self, event):
264          #print "update_command_ui", self.id_to_name[event.GetId()]          #print "update_command_ui", self.id_to_name[event.GetId()]
265          context = Context(self.application, self.application.Session(), self)          context = self.Context()
266          command = registry.Command(self.id_to_name[event.GetId()])          command = registry.Command(self.id_to_name[event.GetId()])
267          if command is not None:          if command is not None:
268              event.Enable(command.Sensitive(context))              sensitive = command.Sensitive(context)
269                event.Enable(sensitive)
270                if command.IsTool() and not sensitive and command.Checked(context):
271                    # When a checked tool command is disabled deselect all
272                    # tools. Otherwise the tool would remain active but it
273                    # might lead to errors if the tools stays active. This
274                    # problem occurred in GREAT-ER and this fixes it, but
275                    # it's not clear to me whether this is really the best
276                    # way to do it (BH, 20021206).
277                    self.canvas.SelectTool(None)
278              event.SetText(command.DynText(context))              event.SetText(command.DynText(context))
279              if command.IsCheckCommand():              if command.IsCheckCommand():
280                  event.Check(command.Checked(context))                      event.Check(command.Checked(context))
281    
282      def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):      def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):
283          """Run a modal message box with the given text, title and flags          """Run a modal message box with the given text, title and flags
284          and return the result"""          and return the result"""
285          dlg = wxMessageDialog(self, text, title, flags)          dlg = wxMessageDialog(self, text, title, flags)
286            dlg.CenterOnParent()
287          result = dlg.ShowModal()          result = dlg.ShowModal()
288          dlg.Destroy()          dlg.Destroy()
289          return result          return result
# Line 230  class MainWindow(wxFrame): Line 297  class MainWindow(wxFrame):
297    
298      def add_dialog(self, name, dialog):      def add_dialog(self, name, dialog):
299          if self.dialogs.has_key(name):          if self.dialogs.has_key(name):
300              raise RuntimeError("The Dialog named %s is already open" % name)              raise RuntimeError(_("The Dialog named %s is already open") % name)
301          self.dialogs[name] = dialog          self.dialogs[name] = dialog
302    
303      def dialog_open(self, name):      def dialog_open(self, name):
# Line 248  class MainWindow(wxFrame): Line 315  class MainWindow(wxFrame):
315              text = "(%10.10g, %10.10g)" % pos              text = "(%10.10g, %10.10g)" % pos
316          else:          else:
317              text = ""              text = ""
318            self.set_position_text(text)
319    
320        def set_position_text(self, text):
321            """Set the statusbar text showing the current position.
322    
323            By default the text is shown in field 0 of the status bar.
324            Override this method in derived classes to put it into a
325            different field of the statusbar.
326            """
327          self.SetStatusText(text)          self.SetStatusText(text)
328    
329      def save_modified_session(self, can_veto = 1):      def save_modified_session(self, can_veto = 1):
# Line 263  class MainWindow(wxFrame): Line 339  class MainWindow(wxFrame):
339              flags = wxYES_NO | wxICON_QUESTION              flags = wxYES_NO | wxICON_QUESTION
340              if can_veto:              if can_veto:
341                  flags = flags | wxCANCEL                  flags = flags | wxCANCEL
342              result = self.RunMessageBox("Exit",              result = self.RunMessageBox(_("Exit"),
343                                          ("The session has been modified."                                          _("The session has been modified."
344                                           " Do you want to save it?"),                                           " Do you want to save it?"),
345                                          flags)                                          flags)
346              if result == wxID_YES:              if result == wxID_YES:
# Line 273  class MainWindow(wxFrame): Line 349  class MainWindow(wxFrame):
349              result = wxID_NO              result = wxID_NO
350          return result          return result
351    
352        def prepare_new_session(self):
353            for d in self.dialogs.values():
354                if not isinstance(d, tree.SessionTreeView):
355                    d.Close()
356    
357      def NewSession(self):      def NewSession(self):
358          self.save_modified_session()          self.save_modified_session()
359            self.prepare_new_session()
360          self.application.SetSession(create_empty_session())          self.application.SetSession(create_empty_session())
361    
362      def OpenSession(self):      def OpenSession(self):
363          self.save_modified_session()          self.save_modified_session()
364          dlg = wxFileDialog(self, "Select a session file", ".", "",          dlg = wxFileDialog(self, _("Open Session"), ".", "", "*.thuban", wxOPEN)
                            "*.thuban", wxOPEN)  
365          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
366                self.prepare_new_session()
367              self.application.OpenSession(dlg.GetPath())              self.application.OpenSession(dlg.GetPath())
368          dlg.Destroy()          dlg.Destroy()
369    
370      def SaveSession(self):      def SaveSession(self):
371          if self.application.session.filename == None:          if self.application.session.filename == None:
372              self.SaveSessionAs()              self.SaveSessionAs()
373          self.application.SaveSession()          else:
374                self.application.SaveSession()
375    
376      def SaveSessionAs(self):      def SaveSessionAs(self):
377          dlg = wxFileDialog(self, "Enter a filename for session", ".", "",          dlg = wxFileDialog(self, _("Save Session As"), ".", "",
378                             "*.thuban", wxOPEN)                             "*.thuban", wxOPEN)
379          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
380              self.application.session.SetFilename(dlg.GetPath())              self.application.session.SetFilename(dlg.GetPath())
# Line 299  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()
391          else:          else:
392                # FIXME: it would be better to tie the unsubscription to
393                # wx's destroy event, but that isn't implemented for wxGTK
394                # yet.
395                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):
405            """Return the map displayed by this mainwindow"""
406    
407            # sanity check
408            #assert(self.canvas.Map() is self.legendPanel.GetMap())
409    
410      def ShowSessionTree(self):          return self.canvas.Map()
411    
412        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:
417              dialog = tree.SessionTreeView(self, self.application, name)              dialog = tree.SessionTreeView(self, self.application, name)
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()
422              pass  
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"),
429                             ("Thuban is a program for\n"                             _("Thuban v%s\n"
430                                #"Build Date: %s\n"
431                                "\n"
432                                "Thuban is a program for\n"
433                              "exploring geographic data.\n"                              "exploring geographic data.\n"
434                              "Copyright (C) 2001 Intevation GmbH.\n"                              "Copyright (C) 2001-2003 Intevation GmbH.\n"
435                              "Thuban is licensed under the GPL"),                              "Thuban is licensed under the GNU GPL"
436                               % __ThubanVersion__), #__BuildDate__)),
437                             wxOK | wxICON_INFORMATION)                             wxOK | wxICON_INFORMATION)
438    
439      def AddLayer(self):      def AddLayer(self):
440          dlg = wxFileDialog(self, "Select a data file", ".", "", "*.*",          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",
441                             wxOPEN)                             wxOPEN)
442          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
443              filename = dlg.GetPath()              filename = dlg.GetPath()
# Line 343  class MainWindow(wxFrame): Line 449  class MainWindow(wxFrame):
449                  map.AddLayer(layer)                  map.AddLayer(layer)
450              except IOError:              except IOError:
451                  # the layer couldn't be opened                  # the layer couldn't be opened
452                  self.RunMessageBox("Add Layer",                  self.RunMessageBox(_("Add Layer"),
453                                     "Can't open the file '%s'." % filename)                                     _("Can't open the file '%s'.") % filename)
454              else:              else:
455                  if not has_layers:                  if not has_layers:
456                      # if we're adding a layer to an empty map, for the                      # if we're adding a layer to an empty map, fit the
457                      # new map to the window                      # new map to the window
458                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
459          dlg.Destroy()          dlg.Destroy()
# Line 357  class MainWindow(wxFrame): Line 463  class MainWindow(wxFrame):
463          if layer is not None:          if layer is not None:
464              self.canvas.Map().RemoveLayer(layer)              self.canvas.Map().RemoveLayer(layer)
465    
466        def CanRemoveLayer(self):
467            """Return true if the currently selected layer can be deleted.
468    
469            If no layer is selected return False.
470    
471            The return value of this method determines whether the remove
472            layer command is sensitive in menu.
473            """
474            layer = self.current_layer()
475            if layer is not None:
476                return self.canvas.Map().CanRemoveLayer(layer)
477            return False
478    
479      def RaiseLayer(self):      def RaiseLayer(self):
480          layer = self.current_layer()          layer = self.current_layer()
481          if layer is not None:          if layer is not None:
# Line 372  class MainWindow(wxFrame): Line 491  class MainWindow(wxFrame):
491    
492          If no layer is selected, return None          If no layer is selected, return None
493          """          """
494          return self.interactor.SelectedLayer()          return self.canvas.SelectedLayer()
495    
496      def has_selected_layer(self):      def has_selected_layer(self):
497          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
498          return self.interactor.HasSelectedLayer()          return self.canvas.HasSelectedLayer()
499    
500      def choose_color(self):      def choose_color(self):
501          """Run the color selection dialog and return the selected color.          """Run the color selection dialog and return the selected color.
# Line 394  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.SetFill(color)  
   
     def LayerTransparentFill(self):  
         layer = self.current_layer()  
         if layer is not None:  
             layer.SetFill(None)  
   
     def LayerOutlineColor(self):  
         layer = self.current_layer()  
         if layer is not None:  
             color = self.choose_color()  
             if color is not None:  
                 layer.SetStroke(color)  
   
     def LayerNoOutline(self):  
         layer = self.current_layer()  
         if layer is not None:  
             layer.SetStroke(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 435  class MainWindow(wxFrame): Line 530  class MainWindow(wxFrame):
530              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
531              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
532              if dialog is None:              if dialog is None:
533                  dialog = tableview.TableFrame(self, self.interactor, name,                  dialog = tableview.LayerTableFrame(self, name,
534                                                "Table: %s" % layer.Title(),                                                 _("Table: %s") % layer.Title(),
535                                                layer, table)                                                     layer, table)
536                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
537                  dialog.Show(true)                  dialog.Show(true)
538              else:              else:
# Line 461  class MainWindow(wxFrame): Line 556  class MainWindow(wxFrame):
556              map.SetProjection(proj)              map.SetProjection(proj)
557          proj4Dlg.Destroy()          proj4Dlg.Destroy()
558    
559        def LayerEditProperties(self):
560    
561            #
562            # the menu option for this should only be available if there
563            # is a current layer, so we don't need to check if the
564            # current layer is None
565            #
566    
567            layer = self.current_layer()
568            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)
573    
574            if dialog is None:
575                dialog = Classifier(self, name, layer, group)
576                self.add_dialog(name, dialog)
577                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()
606    
# Line 483  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 identify_view_on_demand(self, layer, shape):      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):
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, self.interactor, 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 505  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 _tool_command(name, title, method, toolname, helptext = "",  def make_check_current_tool(toolname):
669                    icon = ""):      """Return a function that tests if the currently active tool is toolname
670      """Add a tool command"""  
671        The returned function can be called with the context and returns
672        true iff the currently active tool's name is toolname. It's directly
673        usable as the 'checked' callback of a command.
674        """
675      def check_current_tool(context, name=toolname):      def check_current_tool(context, name=toolname):
676          return context.mainwindow.canvas.CurrentTool() == name          return context.mainwindow.canvas.CurrentTool() == name
677      registry.Add(Command(name, title, call_method, args=(method,),      return check_current_tool
678                           helptext = helptext, icon = icon,  
679                           checked = check_current_tool))  def _tool_command(name, title, method, toolname, helptext = "",
680                      icon = "", sensitive = None):
681        """Add a tool command"""
682        registry.Add(ToolCommand(name, title, call_method, args=(method,),
683                                 helptext = helptext, icon = icon,
684                                 checked = make_check_current_tool(toolname),
685                                 sensitive = sensitive))
686    
687  def _has_selected_layer(context):  def _has_selected_layer(context):
688      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
689      return context.mainwindow.has_selected_layer()      return context.mainwindow.has_selected_layer()
690    
691    def _can_remove_layer(context):
692        return context.mainwindow.CanRemoveLayer()
693    
694    def _has_tree_window_shown(context):
695        """Return true if the tree window is shown"""
696        return context.mainwindow.SessionTreeShown()
697    
698    def _has_visible_map(context):
699        """Return true iff theres a visible map in the mainwindow.
700    
701        A visible map is a map with at least one visible layer."""
702        map = context.mainwindow.Map()
703        if map is not None:
704            for layer in map.Layers():
705                if layer.Visible():
706                    return 1
707        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  _method_command("exit", "&Exit", "Exit")                  checked = _has_tree_window_shown)
721    _method_command("toggle_legend", _("Legend"), "ToggleLegend",
722                    checked = _has_legend_shown)
723    _method_command("exit", _("E&xit"), "Exit")
724    
725  # Help menu  # Help menu
726  _method_command("help_about", "&About", "About")  _method_command("help_about", _("&About"), "About")
727    
728    
729  # Map menu  # Map menu
730  _method_command("map_projection", "Pro&jection", "Projection")  _method_command("map_projection", _("Pro&jection"), "Projection")
731    
732  _tool_command("map_zoom_in_tool", "&Zoom in", "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
733                helptext = "Switch to map-mode 'zoom-in'", icon = "zoom_in")                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
734  _tool_command("map_zoom_out_tool", "Zoom &out", "ZoomOutTool", "ZoomOutTool",                sensitive = _has_visible_map)
735                helptext = "Switch to map-mode 'zoom-out'", icon = "zoom_out")  _tool_command("map_zoom_out_tool", _("Zoom &out"), "ZoomOutTool", "ZoomOutTool",
736  _tool_command("map_pan_tool", "&Pan", "PanTool", "PanTool",                helptext = _("Switch to map-mode 'zoom-out'"), icon = "zoom_out",
737                helptext = "Switch to map-mode 'pan'", icon = "pan")                sensitive = _has_visible_map)
738  _tool_command("map_identify_tool", "&Identify", "IdentifyTool", "IdentifyTool",  _tool_command("map_pan_tool", _("&Pan"), "PanTool", "PanTool",
739                helptext = "Switch to map-mode 'identify'", icon = "identify")                helptext = _("Switch to map-mode 'pan'"), icon = "pan",
740  _tool_command("map_label_tool", "&Label", "LabelTool", "LabelTool",                sensitive = _has_visible_map)
741                helptext = "Add/Remove labels", icon = "label")  _tool_command("map_identify_tool", _("&Identify"), "IdentifyTool",
742  _method_command("map_full_extent", "&Full extent", "FullExtent",                "IdentifyTool",
743                 helptext = "Full Extent", icon = "fullextent")                helptext = _("Switch to map-mode 'identify'"), icon = "identify",
744  _method_command("map_print", "Prin&t", "PrintMap", helptext = "Print the map")                sensitive = _has_visible_map)
745    _tool_command("map_label_tool", _("&Label"), "LabelTool", "LabelTool",
746                  helptext = _("Add/Remove labels"), icon = "label",
747                  sensitive = _has_visible_map)
748    _method_command("map_full_extent", _("&Full extent"), "FullExtent",
749                   helptext = _("Full Extent"), icon = "fullextent",
750                  sensitive = _has_visible_map)
751    _method_command("map_print", _("Prin&t"), "PrintMap",
752                    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",
758                  helptext = "Add a new layer to active map")                  helptext = _("Add a new layer to active map"))
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 = _has_selected_layer)                  sensitive = _can_remove_layer)
762  _method_command("layer_fill_color", "&Fill Color", "LayerFillColor",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
763                  helptext = "Set the fill color of selected layer(s)",                  helptext = _("Raise selected layer(s)"),
                 sensitive = _has_selected_layer)  
 _method_command("layer_transparent_fill", "&Transparent Fill",  
                 "LayerTransparentFill",  
                 helptext = "Do not fill the selected layer(s)",  
764                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
765  _method_command("layer_outline_color", "&Outline Color", "LayerOutlineColor",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
766                  helptext = "Set the outline color of selected layer(s)",                  helptext = _("Lower selected layer(s)"),
767                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
768  _method_command("layer_no_outline", "&No Outline", "LayerNoOutline",  _method_command("layer_show", _("&Show"), "ShowLayer",
769                  helptext = "Do not draw the outline of the selected layer(s)",                  helptext = _("Make selected layer(s) visible"),
770                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
771  _method_command("layer_raise", "&Raise", "RaiseLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
772                  helptext = "Raise selected layer(s)",                  helptext = _("Make selected layer(s) unvisible"),
773                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
774  _method_command("layer_lower", "&Lower", "LowerLayer",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
775                  helptext = "Lower selected layer(s)",                  helptext = _("Show the selected layer's table"),
776                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
777  _method_command("layer_show", "&Show", "ShowLayer",  _method_command("layer_properties", _("Properties"), "LayerEditProperties",
                 helptext = "Make selected layer(s) visible",  
778                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
 _method_command("layer_hide", "&Hide", "HideLayer",  
                 helptext = "Make selected layer(s) unvisible",  
                 sensitive = _has_selected_layer)  
 _method_command("layer_show_table", "Show Ta&ble", "LayerShowTable",  
                 helptext = "Show the selected layer's table",  
                 sensitive = _has_selected_layer)  
   
779    
780  # the menu structure  # the menu structure
781  main_menu = Menu("<main>", "<main>",  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",
789                          None,                          None,
790                          "map_projection",                          "map_projection",
# Line 606  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                    Menu("help", "&Help",                          None,
809                            "layer_properties"]),
810                      Menu("help", _("&Help"),
811                         ["help_about"])])                         ["help_about"])])
812    
813  # the main toolbar  # the main toolbar
814    
815  main_toolbar = Menu("<toolbar>", "<toolbar>",  main_toolbar = Menu("<toolbar>", "<toolbar>",
816                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",
817                       "map_identify_tool", "map_label_tool", "map_full_extent"])                       "map_full_extent", None,
818                         "map_identify_tool", "map_label_tool"])

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26