/[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 150 by bh, Tue May 7 16:55:38 2002 UTC revision 517 by jonathan, Tue Mar 11 17:28:39 2003 UTC
# Line 12  The main window Line 12  The main window
12    
13  __version__ = "$Revision$"  __version__ = "$Revision$"
14    
15  import sys, os  __ThubanVersion__ = "0.2" #"$THUBAN_0_2$"
16    #__BuildDate__ = "$Date$"
17    
18    import os
19    
20  from wxPython.wx import *  from wxPython.wx import *
21    
22  import Thuban  import Thuban
23  from Thuban.Model.session import Session, create_empty_session  from Thuban import _
24  from Thuban.Model.map import Map  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
27  from Thuban.Model.proj import Projection  from Thuban.Model.proj import Projection
# Line 27  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
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 SELECTED_SHAPE, VIEW_POSITION
39    
40    
# Line 40  bitmapext = ".xpm" Line 45  bitmapext = ".xpm"
45    
46  class MainWindow(wxFrame):  class MainWindow(wxFrame):
47    
48      def __init__(self, parent, ID, interactor):      def __init__(self, parent, ID, title, application, interactor,
49          wxFrame.__init__(self, parent, ID, 'Thuban',                   initial_message = None, size = wxSize(-1, -1)):
50                           wxDefaultPosition, wxSize(400, 300))          wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)
51    
52            self.application = application
53          self.interactor = interactor          self.interactor = interactor
54    
55          self.CreateStatusBar()          self.CreateStatusBar()
56          self.SetStatusText("This is the wxPython-based "          if initial_message:
57                        "Graphical User Interface for exploring geographic data")              self.SetStatusText(initial_message)
58    
59          self.identify_view = None          self.identify_view = None
60    
61          self.init_ids()          self.init_ids()
62    
63          menuBar = wxMenuBar()          # creat the menubar from the main_menu description
64            self.SetMenuBar(self.build_menu_bar(main_menu))
         menu = wxMenu()  
         menuBar.Append(menu, "&File");  
         for name in ["new_session", "open_session", None,  
                      "save_session", "save_session_as", None,  
                      "show_session_tree", None,  
                      "exit"]:  
             self.add_menu_command(menu, name)  
   
         menu = wxMenu()  
         menuBar.Append(menu, "&Map");  
         for name in ["layer_add", "layer_remove",  
                      None,  
                      "map_projection",  
                      None,  
                      "map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",  
                      "map_identify_tool", "map_label_tool",  
                      None,  
                      "map_full_extent",  
                      None,  
                      "map_print"]:  
             self.add_menu_command(menu, name)  
   
         menu = wxMenu()  
         menuBar.Append(menu, "&Layer");  
         for name in ["layer_fill_color", "layer_transparent_fill",  
                      "layer_ourline_color", "layer_no_outline",  
                      None,  
                      "layer_raise", "layer_lower",  
                      None,  
                      "layer_show", "layer_hide",  
                      None,  
                      "layer_show_table"]:  
             self.add_menu_command(menu, name)  
   
         menu = wxMenu()  
         menuBar.Append(menu, "&Help");  
         self.add_menu_command(menu, "help_about")  
   
         self.SetMenuBar(menuBar)  
   
         # toolbar  
         toolbar = self.CreateToolBar(wxTB_3DBUTTONS)  
   
         # set the size of the tools' bitmaps. Not needed on wxGTK, but  
         # on Windows. We probably shouldn't hardwire the bitmap size  
         # here  
         toolbar.SetToolBitmapSize(wxSize(24, 24))  
65    
66          for name in ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",          # Similarly, create the toolbar from main_toolbar
67                       "map_identify_tool", "map_label_tool", "map_full_extent"]:          toolbar = self.build_toolbar(main_toolbar)
             self.add_toolbar_command(toolbar, name)  
68          # call Realize to make sure that the tools appear.          # call Realize to make sure that the tools appear.
69          toolbar.Realize()          toolbar.Realize()
70    
# Line 126  class MainWindow(wxFrame): Line 84  class MainWindow(wxFrame):
84          self.current_id = 6000          self.current_id = 6000
85          self.id_to_name = {}          self.id_to_name = {}
86          self.name_to_id = {}          self.name_to_id = {}
87            self.events_bound = {}
88    
89      def get_id(self, name):      def get_id(self, name):
90          """Return the wxWindows id for the command named name.          """Return the wxWindows id for the command named name.
# Line 138  class MainWindow(wxFrame): Line 97  class MainWindow(wxFrame):
97              self.name_to_id[name] = ID              self.name_to_id[name] = ID
98              self.id_to_name[ID] = name              self.id_to_name[ID] = name
99          return ID          return ID
100            
101        def bind_command_events(self, command, ID):
102            """Bind the necessary events for the given command and ID"""
103            if not self.events_bound.has_key(ID):
104                # the events haven't been bound yet
105                EVT_MENU(self, ID, self.invoke_command)
106                if command.IsDynamic():
107                    EVT_UPDATE_UI(self, ID, self.update_command_ui)
108    
109        def build_menu_bar(self, menudesc):
110            """Build and return the menu bar from the menu description"""
111            menu_bar = wxMenuBar()
112    
113            for item in menudesc.items:
114                # here the items must all be Menu instances themselves
115                menu_bar.Append(self.build_menu(item), item.title)
116    
117            return menu_bar
118    
119        def build_menu(self, menudesc):
120            """Return a wxMenu built from the menu description menudesc"""
121            wxmenu = wxMenu()
122            last = None
123            for item in menudesc.items:
124                if item is None:
125                    # a separator. Only add one if the last item was not a
126                    # separator
127                    if last is not None:
128                        wxmenu.AppendSeparator()
129                elif isinstance(item, Menu):
130                    # a submenu
131                    wxmenu.AppendMenu(wxNewId(), item.title, self.build_menu(item))
132                else:
133                    # must the name the name of a command
134                    self.add_menu_command(wxmenu, item)
135                last = item
136            return wxmenu
137    
138        def build_toolbar(self, toolbardesc):
139            """Build and return the main toolbar window from a toolbar description
140    
141            The parameter should be an instance of the Menu class but it
142            should not contain submenus.
143            """
144            toolbar = self.CreateToolBar(wxTB_3DBUTTONS)
145    
146            # set the size of the tools' bitmaps. Not needed on wxGTK, but
147            # on Windows, although it doesn't work very well there. It seems
148            # that only 16x16 icons are really supported on windows.
149            # We probably shouldn't hardwire the bitmap size here.
150            toolbar.SetToolBitmapSize(wxSize(24, 24))
151    
152            for item in toolbardesc.items:
153                if item is None:
154                    toolbar.AddSeparator()
155                else:
156                    # assume it's a string.
157                    self.add_toolbar_command(toolbar, item)
158    
159            return toolbar
160    
161      def add_menu_command(self, menu, name):      def add_menu_command(self, menu, name):
162          """Add the command with name name to the menu menu.          """Add the command with name name to the menu menu.
163    
# Line 152  class MainWindow(wxFrame): Line 171  class MainWindow(wxFrame):
171                  ID = self.get_id(name)                  ID = self.get_id(name)
172                  menu.Append(ID, command.Title(), command.HelpText(),                  menu.Append(ID, command.Title(), command.HelpText(),
173                              command.IsCheckCommand())                              command.IsCheckCommand())
174                  EVT_MENU(self, ID, self.invoke_command)                  self.bind_command_events(command, ID)
                 if command.IsDynamic():  
                     EVT_UPDATE_UI(self, ID, self.update_command_ui)  
175              else:              else:
176                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
177    
178      def add_toolbar_command(self, toolbar, name):      def add_toolbar_command(self, toolbar, name):
179          """Add the command with name name to the toolbar toolbar.          """Add the command with name name to the toolbar toolbar.
# Line 176  class MainWindow(wxFrame): Line 193  class MainWindow(wxFrame):
193                  toolbar.AddTool(ID, bitmap,                  toolbar.AddTool(ID, bitmap,
194                                  shortHelpString = command.HelpText(),                                  shortHelpString = command.HelpText(),
195                                  isToggle = command.IsCheckCommand())                                  isToggle = command.IsCheckCommand())
196                    self.bind_command_events(command, ID)
197              else:              else:
198                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
199    
200        def Context(self):
201            """Return the context object for a command invoked from this window
202            """
203            return Context(self.application, self.application.Session(), self)
204    
205      def invoke_command(self, event):      def invoke_command(self, event):
206          name = self.id_to_name.get(event.GetId())          name = self.id_to_name.get(event.GetId())
207          if name is not None:          if name is not None:
208              command = registry.Command(name)              command = registry.Command(name)
209              command.Execute(self)              command.Execute(self.Context())
210          else:          else:
211              print "Unknown command ID %d" % event.GetId()              print _("Unknown command ID %d") % event.GetId()
212    
213      def update_command_ui(self, event):      def update_command_ui(self, event):
214          #print "update_command_ui", self.id_to_name[event.GetId()]          #print "update_command_ui", self.id_to_name[event.GetId()]
215            context = self.Context()
216          command = registry.Command(self.id_to_name[event.GetId()])          command = registry.Command(self.id_to_name[event.GetId()])
217          if command is not None:          if command is not None:
218              event.Enable(command.Sensitive(self))              sensitive = command.Sensitive(context)
219              event.SetText(command.DynText(self))              event.Enable(sensitive)
220                if command.IsTool() and not sensitive and command.Checked(context):
221                    # When a checked tool command is disabled deselect all
222                    # tools. Otherwise the tool would remain active but it
223                    # might lead to errors if the tools stays active. This
224                    # problem occurred in GREAT-ER and this fixes it, but
225                    # it's not clear to me whether this is really the best
226                    # way to do it (BH, 20021206).
227                    self.canvas.SelectTool(None)
228                event.SetText(command.DynText(context))
229              if command.IsCheckCommand():              if command.IsCheckCommand():
230                  event.Check(command.Checked(self))                      event.Check(command.Checked(context))
231    
232      def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):      def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):
233          """Run a modla message box with the given text, title and flags          """Run a modal message box with the given text, title and flags
234          and return the result"""          and return the result"""
235          dlg = wxMessageDialog(self, text, title, flags)          dlg = wxMessageDialog(self, text, title, flags)
236            dlg.CenterOnParent()
237          result = dlg.ShowModal()          result = dlg.ShowModal()
238          dlg.Destroy()          dlg.Destroy()
239          return result          return result
# Line 213  class MainWindow(wxFrame): Line 247  class MainWindow(wxFrame):
247    
248      def add_dialog(self, name, dialog):      def add_dialog(self, name, dialog):
249          if self.dialogs.has_key(name):          if self.dialogs.has_key(name):
250              raise RuntimeError("The Dialog named %s is already open" % name)              raise RuntimeError(_("The Dialog named %s is already open") % name)
251          self.dialogs[name] = dialog          self.dialogs[name] = dialog
252    
253      def dialog_open(self, name):      def dialog_open(self, name):
# Line 231  class MainWindow(wxFrame): Line 265  class MainWindow(wxFrame):
265              text = "(%10.10g, %10.10g)" % pos              text = "(%10.10g, %10.10g)" % pos
266          else:          else:
267              text = ""              text = ""
268            self.set_position_text(text)
269    
270        def set_position_text(self, text):
271            """Set the statusbar text showing the current position.
272    
273            By default the text is shown in field 0 of the status bar.
274            Override this method in derived classes to put it into a
275            different field of the statusbar.
276            """
277          self.SetStatusText(text)          self.SetStatusText(text)
278    
279      def save_modified_session(self, can_veto = 1):      def save_modified_session(self, can_veto = 1):
# Line 242  class MainWindow(wxFrame): Line 285  class MainWindow(wxFrame):
285          If the can_veto parameter is true (default) the dialog includes          If the can_veto parameter is true (default) the dialog includes
286          a cancel button, otherwise not.          a cancel button, otherwise not.
287          """          """
288          if main.app.session.WasModified():          if self.application.session.WasModified():
289              flags = wxYES_NO | wxICON_QUESTION              flags = wxYES_NO | wxICON_QUESTION
290              if can_veto:              if can_veto:
291                  flags = flags | wxCANCEL                  flags = flags | wxCANCEL
292              result = self.RunMessageBox("Exit",              result = self.RunMessageBox(_("Exit"),
293                                          ("The session has been modified."                                          _("The session has been modified."
294                                           " Do you want to save it?"),                                           " Do you want to save it?"),
295                                          flags)                                          flags)
296              if result == wxID_YES:              if result == wxID_YES:
# Line 256  class MainWindow(wxFrame): Line 299  class MainWindow(wxFrame):
299              result = wxID_NO              result = wxID_NO
300          return result          return result
301    
302        def prepare_new_session(self):
303            for d in self.dialogs.values():
304                if not isinstance(d, tree.SessionTreeView):
305                    d.Close()
306    
307      def NewSession(self):      def NewSession(self):
308          self.save_modified_session()          self.save_modified_session()
309          main.app.SetSession(create_empty_session())          self.prepare_new_session()
310            self.application.SetSession(create_empty_session())
311    
312      def OpenSession(self):      def OpenSession(self):
313          self.save_modified_session()          self.save_modified_session()
314          dlg = wxFileDialog(self, "Select a session file", ".", "",          dlg = wxFileDialog(self, _("Open Session"), ".", "", "*.thuban", wxOPEN)
                            "*.thuban", wxOPEN)  
315          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
316              main.app.OpenSession(dlg.GetPath())              self.prepare_new_session()
317                self.application.OpenSession(dlg.GetPath())
318          dlg.Destroy()          dlg.Destroy()
319    
320      def SaveSession(self):      def SaveSession(self):
321          if main.app.session.filename == None:          if self.application.session.filename == None:
322              self.SaveSessionAs()              self.SaveSessionAs()
323          main.app.SaveSession()          else:
324                self.application.SaveSession()
325    
326      def SaveSessionAs(self):      def SaveSessionAs(self):
327          dlg = wxFileDialog(self, "Enter a filename for session", ".", "",          dlg = wxFileDialog(self, _("Save Session As"), ".", "",
328                             "*.thuban", wxOPEN)                             "*.thuban", wxOPEN)
329          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
330              main.app.session.SetFilename(dlg.GetPath())              self.application.session.SetFilename(dlg.GetPath())
331              main.app.SaveSession()              self.application.SaveSession()
332          dlg.Destroy()          dlg.Destroy()
333    
334      def Exit(self):      def Exit(self):
# Line 289  class MainWindow(wxFrame): Line 339  class MainWindow(wxFrame):
339          if result == wxID_CANCEL:          if result == wxID_CANCEL:
340              event.Veto()              event.Veto()
341          else:          else:
342                # FIXME: it would be better to tie the unsubscription to
343                # wx's destroy event, but that isn't implemented for wxGTK
344                # yet.
345                self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)
346              self.Destroy()              self.Destroy()
347    
348      def SetMap(self, map):      def SetMap(self, map):
349          self.canvas.SetMap(map)          self.canvas.SetMap(map)
350    
351        def Map(self):
352            """Return the map displayed by this mainwindow"""
353            return self.canvas.Map()
354    
355      def ShowSessionTree(self):      def ShowSessionTree(self):
356          name = "session_tree"          name = "session_tree"
357          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
358          if dialog is None:          if dialog is None:
359              dialog = tree.SessionTreeView(self, main.app, name)              dialog = tree.SessionTreeView(self, self.application, name)
360              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
361              dialog.Show(true)              dialog.Show(True)
362          else:          else:
363              # FIXME: bring dialog to front here              # FIXME: bring dialog to front here
364              pass              pass
365    
366    
367      def About(self):      def About(self):
368          self.RunMessageBox("About",          self.RunMessageBox(_("About"),
369                             ("Thuban is a program for\n"                             _("Thuban v%s\n"
370                                #"Build Date: %s\n"
371                                "\n"
372                                "Thuban is a program for\n"
373                              "exploring geographic data.\n"                              "exploring geographic data.\n"
374                              "Copyright (C) 2001 Intevation GmbH.\n"                              "Copyright (C) 2001-2003 Intevation GmbH.\n"
375                              "Thuban is licensed under the GPL"),                              "Thuban is licensed under the GNU GPL"
376                               % __ThubanVersion__), #__BuildDate__)),
377                             wxOK | wxICON_INFORMATION)                             wxOK | wxICON_INFORMATION)
378    
379      def AddLayer(self):      def AddLayer(self):
380          dlg = wxFileDialog(self, "Select a data file", ".", "", "*.*",          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",
381                             wxOPEN)                             wxOPEN)
382          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
383              filename = dlg.GetPath()              filename = dlg.GetPath()
# Line 326  class MainWindow(wxFrame): Line 389  class MainWindow(wxFrame):
389                  map.AddLayer(layer)                  map.AddLayer(layer)
390              except IOError:              except IOError:
391                  # the layer couldn't be opened                  # the layer couldn't be opened
392                  self.RunMessageBox("Add Layer",                  self.RunMessageBox(_("Add Layer"),
393                                     "Can't open the file '%s'." % filename)                                     _("Can't open the file '%s'.") % filename)
394              else:              else:
395                  if not has_layers:                  if not has_layers:
396                      # if we're adding a layer to an empty map, for the                      # if we're adding a layer to an empty map, for the
# Line 340  class MainWindow(wxFrame): Line 403  class MainWindow(wxFrame):
403          if layer is not None:          if layer is not None:
404              self.canvas.Map().RemoveLayer(layer)              self.canvas.Map().RemoveLayer(layer)
405    
406        def CanRemoveLayer(self):
407            """Return true if the currently selected layer can be deleted.
408    
409            If no layer is selected return false.
410    
411            The return value of this method determines whether the remove
412            layer command is sensitive in menu.
413            """
414            layer = self.current_layer()
415            if layer is not None:
416                return self.canvas.Map().CanRemoveLayer(layer)
417            return 0
418    
419      def RaiseLayer(self):      def RaiseLayer(self):
420          layer = self.current_layer()          layer = self.current_layer()
421          if layer is not None:          if layer is not None:
422              self.canvas.Map().RaiseLayer(layer)              self.canvas.Map().RaiseLayer(layer)
423            
424      def LowerLayer(self):      def LowerLayer(self):
425          layer = self.current_layer()          layer = self.current_layer()
426          if layer is not None:          if layer is not None:
# Line 382  class MainWindow(wxFrame): Line 458  class MainWindow(wxFrame):
458          if layer is not None:          if layer is not None:
459              color = self.choose_color()              color = self.choose_color()
460              if color is not None:              if color is not None:
461                  layer.SetFill(color)                  layer.GetClassification().SetDefaultFill(color)
462    
463      def LayerTransparentFill(self):      def LayerTransparentFill(self):
464          layer = self.current_layer()          layer = self.current_layer()
465          if layer is not None:          if layer is not None:
466              layer.SetFill(None)              layer.GetClassification().SetDefaultFill(Color.None)
467    
468      def LayerOutlineColor(self):      def LayerOutlineColor(self):
469          layer = self.current_layer()          layer = self.current_layer()
470          if layer is not None:          if layer is not None:
471              color = self.choose_color()              color = self.choose_color()
472              if color is not None:              if color is not None:
473                  layer.SetStroke(color)                  layer.GetClassification().SetDefaultLineColor(color)
474    
475      def LayerNoOutline(self):      def LayerNoOutline(self):
476          layer = self.current_layer()          layer = self.current_layer()
477          if layer is not None:          if layer is not None:
478              layer.SetStroke(None)              layer.GetClassification().SetDefaultLineColor(Color.None)
479    
480      def HideLayer(self):      def HideLayer(self):
481          layer = self.current_layer()          layer = self.current_layer()
# Line 418  class MainWindow(wxFrame): Line 494  class MainWindow(wxFrame):
494              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
495              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
496              if dialog is None:              if dialog is None:
497                  dialog = tableview.TableFrame(self, self.interactor, name,                  dialog = tableview.LayerTableFrame(self, self.interactor, name,
498                                                "Table: %s" % layer.Title(),                                                     _("Table: %s") % layer.Title(),
499                                                layer, table)                                                     layer, table)
500                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
501                  dialog.Show(true)                  dialog.Show(true)
502              else:              else:
# Line 444  class MainWindow(wxFrame): Line 520  class MainWindow(wxFrame):
520              map.SetProjection(proj)              map.SetProjection(proj)
521          proj4Dlg.Destroy()          proj4Dlg.Destroy()
522    
523        def Classify(self):
524    
525            #
526            # the menu option for this should only be available if there
527            # is a current layer, so we don't need to check if the
528            # current layer is None
529            #
530    
531            layer = self.current_layer()
532            name = "classifier" + str(id(layer))
533            dialog = self.get_open_dialog(name)
534    
535            if dialog is None:
536                dialog = classifier.Classifier(self, self.interactor,
537                                               name, self.current_layer())
538                self.add_dialog(name, dialog)
539                dialog.Show()
540    
541      def ZoomInTool(self):      def ZoomInTool(self):
542          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
543    
# Line 484  class MainWindow(wxFrame): Line 578  class MainWindow(wxFrame):
578    
579  # Helper functions to define common command implementations  # Helper functions to define common command implementations
580  def call_method(context, methodname, *args):  def call_method(context, methodname, *args):
581      """Call the context's method methodname with args *args"""      """Call the mainwindow's method methodname with args *args"""
582      apply(getattr(context, methodname), args)      apply(getattr(context.mainwindow, methodname), args)
583    
584  def _method_command(name, title, method, helptext = "",  def _method_command(name, title, method, helptext = "",
585                      icon = "", sensitive = None):                      icon = "", sensitive = None):
586      """Add a command implemented by a method of the context object"""      """Add a command implemented by a method of the mainwindow object"""
587      registry.Add(Command(name, title, call_method, args=(method,),      registry.Add(Command(name, title, call_method, args=(method,),
588                           helptext = helptext, icon = icon,                           helptext = helptext, icon = icon,
589                           sensitive = sensitive))                           sensitive = sensitive))
590    
591    def make_check_current_tool(toolname):
592        """Return a function that tests if the currently active tool is toolname
593    
594        The returned function can be called with the context and returns
595        true iff the currently active tool's name is toolname. It's directly
596        usable as the 'checked' callback of a command.
597        """
598        def check_current_tool(context, name=toolname):
599            return context.mainwindow.canvas.CurrentTool() == name
600        return check_current_tool
601    
602  def _tool_command(name, title, method, toolname, helptext = "",  def _tool_command(name, title, method, toolname, helptext = "",
603                    icon = ""):                    icon = "", sensitive = None):
604      """Add a tool command"""      """Add a tool command"""
605      def check_current_tool(context, name=toolname):      registry.Add(ToolCommand(name, title, call_method, args=(method,),
606          return context.canvas.CurrentTool() == name                               helptext = helptext, icon = icon,
607      registry.Add(Command(name, title, call_method, args=(method,),                               checked = make_check_current_tool(toolname),
608                           helptext = helptext, icon = icon,                               sensitive = sensitive))
                          checked = check_current_tool))  
609    
610  def _has_selected_layer(context):  def _has_selected_layer(context):
611      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
612      return context.has_selected_layer()      return context.mainwindow.has_selected_layer()
613    
614    def _can_remove_layer(context):
615        return context.mainwindow.CanRemoveLayer()
616    
617    def _has_tree_window_shown(context):
618        """Return true if the tree window is shown"""
619        return context.mainwindow.get_open_dialog("session_tree") is None
620    
621    def _has_visible_map(context):
622        """Return true iff theres a visible map in the mainwindow.
623    
624        A visible map is a map with at least one visible layer."""
625        map = context.mainwindow.Map()
626        if map is not None:
627            for layer in map.Layers():
628                if layer.Visible():
629                    return 1
630        return 0
631    
632    
633  # File menu  # File menu
634  _method_command("new_session", "&New Session", "NewSession")  _method_command("new_session", _("&New Session"), "NewSession")
635  _method_command("open_session", "&Open Session", "OpenSession")  _method_command("open_session", _("&Open Session"), "OpenSession")
636  _method_command("save_session", "&Save Session", "SaveSession")  _method_command("save_session", _("&Save Session"), "SaveSession")
637  _method_command("save_session_as", "Save Session &As", "SaveSessionAs")  _method_command("save_session_as", _("Save Session &As"), "SaveSessionAs")
638  _method_command("show_session_tree", "Show Session &Tree", "ShowSessionTree")  _method_command("show_session_tree", _("Show Session &Tree"), "ShowSessionTree",
639  _method_command("exit", "&Exit", "Exit")                  sensitive = _has_tree_window_shown)
640    _method_command("exit", _("E&xit"), "Exit")
641    
642  # Help menu  # Help menu
643  _method_command("help_about", "&About", "About")  _method_command("help_about", _("&About"), "About")
644    
645    
646  # Map menu  # Map menu
647  _method_command("map_projection", "Pro&jection", "Projection")  _method_command("map_projection", _("Pro&jection"), "Projection")
648    
649  _tool_command("map_zoom_in_tool", "&Zoom in", "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
650                helptext = "Switch to map-mode 'zoom-in'", icon = "zoom_in")                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
651  _tool_command("map_zoom_out_tool", "Zoom &out", "ZoomOutTool", "ZoomOutTool",                sensitive = _has_visible_map)
652                helptext = "Switch to map-mode 'zoom-out'", icon = "zoom_out")  _tool_command("map_zoom_out_tool", _("Zoom &out"), "ZoomOutTool", "ZoomOutTool",
653  _tool_command("map_pan_tool", "&Pan", "PanTool", "PanTool",                helptext = _("Switch to map-mode 'zoom-out'"), icon = "zoom_out",
654                helptext = "Switch to map-mode 'pan'", icon = "pan")                sensitive = _has_visible_map)
655  _tool_command("map_identify_tool", "&Identify", "IdentifyTool", "IdentifyTool",  _tool_command("map_pan_tool", _("&Pan"), "PanTool", "PanTool",
656                helptext = "Switch to map-mode 'identify'", icon = "identify")                helptext = _("Switch to map-mode 'pan'"), icon = "pan",
657  _tool_command("map_label_tool", "&Label", "LabelTool", "LabelTool",                sensitive = _has_visible_map)
658                helptext = "Add/Remove labels", icon = "label")  _tool_command("map_identify_tool", _("&Identify"), "IdentifyTool",
659  _method_command("map_full_extent", "&Full extent", "FullExtent",                "IdentifyTool",
660                 helptext = "Full Extent", icon = "fullextent")                helptext = _("Switch to map-mode 'identify'"), icon = "identify",
661  _method_command("map_print", "Prin&t", "PrintMap", helptext = "Print the map")                sensitive = _has_visible_map)
662    _tool_command("map_label_tool", _("&Label"), "LabelTool", "LabelTool",
663                  helptext = _("Add/Remove labels"), icon = "label",
664                  sensitive = _has_visible_map)
665    _method_command("map_full_extent", _("&Full extent"), "FullExtent",
666                   helptext = _("Full Extent"), icon = "fullextent",
667                  sensitive = _has_visible_map)
668    _method_command("map_print", _("Prin&t"), "PrintMap",
669                    helptext = _("Print the map"))
670    
671  # Layer menu  # Layer menu
672  _method_command("layer_add", "&Add Layer", "AddLayer",  _method_command("layer_add", _("&Add Layer"), "AddLayer",
673                  helptext = "Add a new layer to active map")                  helptext = _("Add a new layer to active map"))
674  _method_command("layer_remove", "&Remove Layer", "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
675                  helptext = "Remove selected layer(s)",                  helptext = _("Remove selected layer(s)"),
676                  sensitive = _has_selected_layer)                  sensitive = _can_remove_layer)
677  _method_command("layer_fill_color", "&Fill Color", "LayerFillColor",  _method_command("layer_fill_color", _("&Fill Color"), "LayerFillColor",
678                  helptext = "Set the fill color of selected layer(s)",                  helptext = _("Set the fill color of selected layer(s)"),
679                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
680  _method_command("layer_transparent_fill", "&Transparent Fill",  _method_command("layer_transparent_fill", _("&Transparent Fill"),
681                  "LayerTransparentFill",                  "LayerTransparentFill",
682                  helptext = "Do not fill the selected layer(s)",                  helptext = _("Do not fill the selected layer(s)"),
683                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
684  _method_command("layer_ourline_color", "&Outline Color", "LayerOutlineColor",  _method_command("layer_outline_color", _("&Outline Color"), "LayerOutlineColor",
685                  helptext = "Set the outline color of selected layer(s)",                  helptext = _("Set the outline color of selected layer(s)"),
686                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
687  _method_command("layer_no_outline", "&No Outline", "LayerNoOutline",  _method_command("layer_no_outline", _("&No Outline"), "LayerNoOutline",
688                  helptext = "Do not draw the outline of the selected layer(s)",                  helptext= _("Do not draw the outline of the selected layer(s)"),
689                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
690  _method_command("layer_raise", "&Raise", "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
691                  helptext = "Raise selected layer(s)",                  helptext = _("Raise selected layer(s)"),
692                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
693  _method_command("layer_lower", "&Lower", "LowerLayer",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
694                  helptext = "Lower selected layer(s)",                  helptext = _("Lower selected layer(s)"),
695                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
696  _method_command("layer_show", "&Show", "ShowLayer",  _method_command("layer_show", _("&Show"), "ShowLayer",
697                  helptext = "Make selected layer(s) visible",                  helptext = _("Make selected layer(s) visible"),
698                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
699  _method_command("layer_hide", "&Hide", "HideLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
700                  helptext = "Make selected layer(s) unvisible",                  helptext = _("Make selected layer(s) unvisible"),
701                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
702  _method_command("layer_show_table", "Show Ta&ble", "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
703                  helptext = "Show the selected layer's table",                  helptext = _("Show the selected layer's table"),
704                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
705    
706    _method_command("layer_classifier", _("Classify"), "Classify",
707                    sensitive = _has_selected_layer)
708    
709    # the menu structure
710    main_menu = Menu("<main>", "<main>",
711                     [Menu("file", _("&File"),
712                           ["new_session", "open_session", None,
713                            "save_session", "save_session_as", None,
714                            "show_session_tree", None,
715                            "exit"]),
716                      Menu("map", _("&Map"),
717                           ["layer_add", "layer_remove",
718                            None,
719                            "map_projection",
720                            None,
721                            "map_zoom_in_tool", "map_zoom_out_tool",
722                            "map_pan_tool", "map_identify_tool", "map_label_tool",
723                            None,
724                            "map_full_extent",
725                            None,
726                            "map_print"]),
727                      Menu("layer", _("&Layer"),
728                           ["layer_fill_color", "layer_transparent_fill",
729                            "layer_outline_color", "layer_no_outline",
730                            None,
731                            "layer_raise", "layer_lower",
732                            None,
733                            "layer_show", "layer_hide",
734                            None,
735                            "layer_show_table",
736                            None,
737                            "layer_classifier"]),
738                      Menu("help", _("&Help"),
739                           ["help_about"])])
740    
741    # the main toolbar
742    
743    main_toolbar = Menu("<toolbar>", "<toolbar>",
744                        ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",
745                         "map_full_extent", None,
746                         "map_identify_tool", "map_label_tool"])

Legend:
Removed from v.150  
changed lines
  Added in v.517

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26