/[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 102 by jan, Fri Apr 19 14:22:25 2002 UTC revision 1464 by bh, Fri Jul 18 18:20:40 2003 UTC
# Line 1  Line 1 
1  # Copyright (C) 2001 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]>
5    # Frank Koormann <[email protected]>
6  #  #
7  # This program is free software under the GPL (>=v2)  # This program is free software under the GPL (>=v2)
8  # Read the file COPYING coming with Thuban for details.  # Read the file COPYING coming with Thuban for details.
# Line 12  The main window Line 13  The main window
13    
14  __version__ = "$Revision$"  __version__ = "$Revision$"
15    
16  import sys, os  __ThubanVersion__ = "0.8" #"$THUBAN_0_2$"
17    #__BuildDate__ = "$Date$"
18    
19    import os
20    import copy
21    
22  from wxPython.wx import *  from wxPython.wx import *
23    from wxPython.wx import __version__ as wxPython_version
24    
25  import Thuban  import Thuban
26  from Thuban.Model.session import Session, create_empty_session  import Thuban.version
27  from Thuban.Model.map import Map  
28  from Thuban.Model.layer import Layer  from Thuban import _
29  from Thuban.Model.color import Color  from Thuban.Model.session import create_empty_session
30  from Thuban.Model.proj import Projection  from Thuban.Model.layer import Layer, RasterLayer
31    
32    # XXX: replace this by
33    # from wxPython.lib.dialogs import wxMultipleChoiceDialog
34    # when Thuban does not support wxPython 2.4.0 any more.
35    from Thuban.UI.multiplechoicedialog import wxMultipleChoiceDialog
36    
37  import view  import view
38  import tree  import tree
 import proj4dialog  
39  import tableview, identifyview  import tableview, identifyview
40    from Thuban.UI.classifier import Classifier
41    import legend
42    from menu import Menu
43    
44    from context import Context
45    from command import registry, Command, ToolCommand
46    from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, \
47         MAP_REPLACED
48    from about import About
49    
50    from Thuban.UI.dock import DockFrame
51    from Thuban.UI.join import JoinDialog
52    
53    import resource
54    import Thuban.Model.resource
55    
56    import projdialog
57    
58    
59    class MainWindow(DockFrame):
60    
61        # Some messages that can be subscribed/unsubscribed directly through
62        # the MapCanvas come in fact from other objects. This is a map to
63        # map those messages to the names of the instance variables they
64        # actually come from. This delegation is implemented in the
65        # Subscribe and unsubscribed methods
66        delegated_messages = {LAYER_SELECTED: "canvas",
67                              SHAPES_SELECTED: "canvas",
68                              MAP_REPLACED: "canvas"}
69    
70        # Methods delegated to some instance variables. The delegation is
71        # implemented in the __getattr__ method.
72        delegated_methods = {"SelectLayer": "canvas",
73                             "SelectShapes": "canvas",
74                             "SelectedLayer": "canvas",
75                             "SelectedShapes": "canvas",
76                             }
77    
78        def __init__(self, parent, ID, title, application, interactor,
79                     initial_message = None, size = wxSize(-1, -1)):
80            DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)
81            #wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)
82    
83  import main          self.application = application
 from command import registry, Command  
 from messages import SELECTED_SHAPE  
   
   
 # the directory where the toolbar icons are stored  
 bitmapdir = os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Bitmaps")  
 bitmapext = ".xpm"  
   
   
 class MainWindow(wxFrame):  
   
     def __init__(self, parent, ID, interactor):  
         wxFrame.__init__(self, parent, ID, 'Thuban',  
                          wxDefaultPosition, wxSize(400, 300))  
   
         self.interactor = interactor  
84    
85          self.CreateStatusBar()          self.CreateStatusBar()
86          self.SetStatusText("This is the wxPython-based "          if initial_message:
87                        "Graphical User Interface for exploring geographic data")              self.SetStatusText(initial_message)
88    
89          self.identify_view = None          self.identify_view = None
90    
91          self.init_ids()          self.init_ids()
92    
93          menuBar = wxMenuBar()          # creat the menubar from the main_menu description
94            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,  
                      "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))  
95    
96          for name in ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",          # Similarly, create the toolbar from main_toolbar
97                       "map_identify_tool", "map_label_tool"]:          toolbar = self.build_toolbar(main_toolbar)
             self.add_toolbar_command(toolbar, name)  
98          # call Realize to make sure that the tools appear.          # call Realize to make sure that the tools appear.
99          toolbar.Realize()          toolbar.Realize()
100    
101    
102          # Create the map canvas          # Create the map canvas
103          canvas = view.MapCanvas(self, -1, interactor)          canvas = view.MapCanvas(self, -1)
104            canvas.Subscribe(VIEW_POSITION, self.view_position_changed)
105            canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)
106          self.canvas = canvas          self.canvas = canvas
107    
108            self.SetMainWindow(self.canvas)
109    
110            self.SetAutoLayout(True)
111    
112          self.init_dialogs()          self.init_dialogs()
113    
114          interactor.Subscribe(SELECTED_SHAPE, self.identify_view_on_demand)          self.ShowLegend()
115    
116          EVT_CLOSE(self, self.OnClose)          EVT_CLOSE(self, self.OnClose)
117    
118        def Subscribe(self, channel, *args):
119            """Subscribe a function to a message channel.
120    
121            If channel is one of the delegated messages call the appropriate
122            object's Subscribe method. Otherwise do nothing.
123            """
124            if channel in self.delegated_messages:
125                object = getattr(self, self.delegated_messages[channel])
126                object.Subscribe(channel, *args)
127            else:
128                print "Trying to subscribe to unsupported channel %s" % channel
129    
130        def Unsubscribe(self, channel, *args):
131            """Unsubscribe a function from a message channel.
132    
133            If channel is one of the delegated messages call the appropriate
134            object's Unsubscribe method. Otherwise do nothing.
135            """
136            if channel in self.delegated_messages:
137                object = getattr(self, self.delegated_messages[channel])
138                object.Unsubscribe(channel, *args)
139    
140        def __getattr__(self, attr):
141            """If attr is one of the delegated methods return that method
142    
143            Otherwise raise AttributeError.
144            """
145            if attr in self.delegated_methods:
146                return getattr(getattr(self, self.delegated_methods[attr]), attr)
147            raise AttributeError(attr)
148    
149      def init_ids(self):      def init_ids(self):
150          """Initialize the ids"""          """Initialize the ids"""
151          self.current_id = 6000          self.current_id = 6000
152          self.id_to_name = {}          self.id_to_name = {}
153          self.name_to_id = {}          self.name_to_id = {}
154            self.events_bound = {}
155    
156      def get_id(self, name):      def get_id(self, name):
157          """Return the wxWindows id for the command named name.          """Return the wxWindows id for the command named name.
# Line 136  class MainWindow(wxFrame): Line 164  class MainWindow(wxFrame):
164              self.name_to_id[name] = ID              self.name_to_id[name] = ID
165              self.id_to_name[ID] = name              self.id_to_name[ID] = name
166          return ID          return ID
167            
168        def bind_command_events(self, command, ID):
169            """Bind the necessary events for the given command and ID"""
170            if not self.events_bound.has_key(ID):
171                # the events haven't been bound yet
172                EVT_MENU(self, ID, self.invoke_command)
173                if command.IsDynamic():
174                    EVT_UPDATE_UI(self, ID, self.update_command_ui)
175    
176        def build_menu_bar(self, menudesc):
177            """Build and return the menu bar from the menu description"""
178            menu_bar = wxMenuBar()
179    
180            for item in menudesc.items:
181                # here the items must all be Menu instances themselves
182                menu_bar.Append(self.build_menu(item), item.title)
183    
184            return menu_bar
185    
186        def build_menu(self, menudesc):
187            """Return a wxMenu built from the menu description menudesc"""
188            wxmenu = wxMenu()
189            last = None
190            for item in menudesc.items:
191                if item is None:
192                    # a separator. Only add one if the last item was not a
193                    # separator
194                    if last is not None:
195                        wxmenu.AppendSeparator()
196                elif isinstance(item, Menu):
197                    # a submenu
198                    wxmenu.AppendMenu(wxNewId(), item.title, self.build_menu(item))
199                else:
200                    # must the name the name of a command
201                    self.add_menu_command(wxmenu, item)
202                last = item
203            return wxmenu
204    
205        def build_toolbar(self, toolbardesc):
206            """Build and return the main toolbar window from a toolbar description
207    
208            The parameter should be an instance of the Menu class but it
209            should not contain submenus.
210            """
211            toolbar = self.CreateToolBar(wxTB_3DBUTTONS)
212    
213            # set the size of the tools' bitmaps. Not needed on wxGTK, but
214            # on Windows, although it doesn't work very well there. It seems
215            # that only 16x16 icons are really supported on windows.
216            # We probably shouldn't hardwire the bitmap size here.
217            toolbar.SetToolBitmapSize(wxSize(24, 24))
218    
219            for item in toolbardesc.items:
220                if item is None:
221                    toolbar.AddSeparator()
222                else:
223                    # assume it's a string.
224                    self.add_toolbar_command(toolbar, item)
225    
226            return toolbar
227    
228      def add_menu_command(self, menu, name):      def add_menu_command(self, menu, name):
229          """Add the command with name name to the menu menu.          """Add the command with name name to the menu menu.
230    
# Line 150  class MainWindow(wxFrame): Line 238  class MainWindow(wxFrame):
238                  ID = self.get_id(name)                  ID = self.get_id(name)
239                  menu.Append(ID, command.Title(), command.HelpText(),                  menu.Append(ID, command.Title(), command.HelpText(),
240                              command.IsCheckCommand())                              command.IsCheckCommand())
241                  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)  
242              else:              else:
243                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
244    
245      def add_toolbar_command(self, toolbar, name):      def add_toolbar_command(self, toolbar, name):
246          """Add the command with name name to the toolbar toolbar.          """Add the command with name name to the toolbar toolbar.
# Line 169  class MainWindow(wxFrame): Line 255  class MainWindow(wxFrame):
255              command = registry.Command(name)              command = registry.Command(name)
256              if command is not None:              if command is not None:
257                  ID = self.get_id(name)                  ID = self.get_id(name)
258                  filename = os.path.join(bitmapdir, command.Icon()) + bitmapext                  bitmap = resource.GetBitmapResource(command.Icon(),
259                  bitmap = wxBitmap(filename, wxBITMAP_TYPE_XPM)                                                      wxBITMAP_TYPE_XPM)
260                  toolbar.AddTool(ID, bitmap,                  toolbar.AddTool(ID, bitmap,
261                                  shortHelpString = command.HelpText(),                                  shortHelpString = command.HelpText(),
262                                  isToggle = command.IsCheckCommand())                                  isToggle = command.IsCheckCommand())
263                    self.bind_command_events(command, ID)
264              else:              else:
265                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
266    
267        def Context(self):
268            """Return the context object for a command invoked from this window
269            """
270            return Context(self.application, self.application.Session(), self)
271    
272      def invoke_command(self, event):      def invoke_command(self, event):
273          name = self.id_to_name.get(event.GetId())          name = self.id_to_name.get(event.GetId())
274          if name is not None:          if name is not None:
275              command = registry.Command(name)              command = registry.Command(name)
276              command.Execute(self)              command.Execute(self.Context())
277          else:          else:
278              print "Unknown command ID %d" % event.GetId()              print _("Unknown command ID %d") % event.GetId()
279    
280      def update_command_ui(self, event):      def update_command_ui(self, event):
281          #print "update_command_ui", self.id_to_name[event.GetId()]          #print "update_command_ui", self.id_to_name[event.GetId()]
282            context = self.Context()
283          command = registry.Command(self.id_to_name[event.GetId()])          command = registry.Command(self.id_to_name[event.GetId()])
284          if command is not None:          if command is not None:
285              event.Enable(command.Sensitive(self))              sensitive = command.Sensitive(context)
286              event.SetText(command.DynText(self))              event.Enable(sensitive)
287                if command.IsTool() and not sensitive and command.Checked(context):
288                    # When a checked tool command is disabled deselect all
289                    # tools. Otherwise the tool would remain active but it
290                    # might lead to errors if the tools stays active. This
291                    # problem occurred in GREAT-ER and this fixes it, but
292                    # it's not clear to me whether this is really the best
293                    # way to do it (BH, 20021206).
294                    self.canvas.SelectTool(None)
295                event.SetText(command.DynText(context))
296              if command.IsCheckCommand():              if command.IsCheckCommand():
297                  event.Check(command.Checked(self))                      event.Check(command.Checked(context))
298    
299      def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):      def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):
300          """Run a modla message box with the given text, title and flags          """Run a modal message box with the given text, title and flags
301          and return the result"""          and return the result"""
302          dlg = wxMessageDialog(self, text, title, flags)          dlg = wxMessageDialog(self, text, title, flags)
303            dlg.CenterOnParent()
304          result = dlg.ShowModal()          result = dlg.ShowModal()
305          dlg.Destroy()          dlg.Destroy()
306          return result          return result
# Line 211  class MainWindow(wxFrame): Line 314  class MainWindow(wxFrame):
314    
315      def add_dialog(self, name, dialog):      def add_dialog(self, name, dialog):
316          if self.dialogs.has_key(name):          if self.dialogs.has_key(name):
317              raise RuntimeError("The Dialog named %s is already open" % name)              raise RuntimeError(_("The Dialog named %s is already open") % name)
318          self.dialogs[name] = dialog          self.dialogs[name] = dialog
319    
320      def dialog_open(self, name):      def dialog_open(self, name):
# Line 223  class MainWindow(wxFrame): Line 326  class MainWindow(wxFrame):
326      def get_open_dialog(self, name):      def get_open_dialog(self, name):
327          return self.dialogs.get(name)          return self.dialogs.get(name)
328    
329        def view_position_changed(self):
330            pos = self.canvas.CurrentPosition()
331            if pos is not None:
332                text = "(%10.10g, %10.10g)" % pos
333            else:
334                text = ""
335            self.set_position_text(text)
336    
337        def set_position_text(self, text):
338            """Set the statusbar text showing the current position.
339    
340            By default the text is shown in field 0 of the status bar.
341            Override this method in derived classes to put it into a
342            different field of the statusbar.
343            """
344            self.SetStatusText(text)
345    
346      def save_modified_session(self, can_veto = 1):      def save_modified_session(self, can_veto = 1):
347          """If the current session has been modified, ask the user          """If the current session has been modified, ask the user
348          whether to save it and do so if requested. Return the outcome of          whether to save it and do so if requested. Return the outcome of
# Line 232  class MainWindow(wxFrame): Line 352  class MainWindow(wxFrame):
352          If the can_veto parameter is true (default) the dialog includes          If the can_veto parameter is true (default) the dialog includes
353          a cancel button, otherwise not.          a cancel button, otherwise not.
354          """          """
355          if main.app.session.WasModified():          if self.application.session.WasModified():
356              flags = wxYES_NO | wxICON_QUESTION              flags = wxYES_NO | wxICON_QUESTION
357              if can_veto:              if can_veto:
358                  flags = flags | wxCANCEL                  flags = flags | wxCANCEL
359              result = self.RunMessageBox("Exit",              result = self.RunMessageBox(_("Exit"),
360                                          ("The session has been modified."                                          _("The session has been modified."
361                                           " Do you want to save it?"),                                           " Do you want to save it?"),
362                                          flags)                                          flags)
363              if result == wxID_YES:              if result == wxID_YES:
# Line 247  class MainWindow(wxFrame): Line 367  class MainWindow(wxFrame):
367          return result          return result
368    
369      def NewSession(self):      def NewSession(self):
370          self.save_modified_session()          if self.save_modified_session() != wxID_CANCEL:
371          main.app.SetSession(create_empty_session())              self.application.SetSession(create_empty_session())
372    
373      def OpenSession(self):      def OpenSession(self):
374          self.save_modified_session()          if self.save_modified_session() != wxID_CANCEL:
375          dlg = wxFileDialog(self, "Select a session file", ".", "",              dlg = wxFileDialog(self, _("Open Session"), ".", "",
376                             "*.session", wxOPEN)                                 "Thuban Session File (*.thuban)|*.thuban",
377          if dlg.ShowModal() == wxID_OK:                                 wxOPEN)
378              main.app.OpenSession(dlg.GetPath())              if dlg.ShowModal() == wxID_OK:
379          dlg.Destroy()                  self.application.OpenSession(dlg.GetPath())
380                dlg.Destroy()
381    
382      def SaveSession(self):      def SaveSession(self):
383          if main.app.session.filename == None:          if self.application.session.filename == None:
384              self.SaveSessionAs()              self.SaveSessionAs()
385          main.app.SaveSession()          else:
386                self.application.SaveSession()
387    
388      def SaveSessionAs(self):      def SaveSessionAs(self):
389          dlg = wxFileDialog(self, "Enter a filename for session", ".", "",          dlg = wxFileDialog(self, _("Save Session As"), ".", "",
390                             "*.session", wxOPEN)                             "Thuban Session File (*.thuban)|*.thuban",
391                               wxSAVE|wxOVERWRITE_PROMPT)
392          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
393              main.app.session.SetFilename(dlg.GetPath())              self.application.session.SetFilename(dlg.GetPath())
394              main.app.SaveSession()              self.application.SaveSession()
395          dlg.Destroy()          dlg.Destroy()
396    
397      def Exit(self):      def Exit(self):
398          self.Close(false)          self.Close(False)
399    
400      def OnClose(self, event):      def OnClose(self, event):
401          result = self.save_modified_session(can_veto = event.CanVeto())          result = self.save_modified_session(can_veto = event.CanVeto())
402          if result == wxID_CANCEL:          if result == wxID_CANCEL:
403              event.Veto()              event.Veto()
404          else:          else:
405                # FIXME: it would be better to tie the unsubscription to
406                # wx's destroy event, but that isn't implemented for wxGTK
407                # yet.
408                self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)
409                DockFrame.OnClose(self, event)
410                for dlg in self.dialogs.values():
411                    dlg.Destroy()
412                self.canvas.Destroy()
413              self.Destroy()              self.Destroy()
414    
415      def SetMap(self, map):      def SetMap(self, map):
416          self.canvas.SetMap(map)          self.canvas.SetMap(map)
417            self.__SetTitle(map.Title())
418    
419            dialog = self.FindRegisteredDock("legend")
420            if dialog is not None:
421                dialog.GetPanel().SetMap(self.Map())
422    
423        def Map(self):
424            """Return the map displayed by this mainwindow"""
425    
426      def ShowSessionTree(self):          return self.canvas.Map()
427    
428        def ToggleSessionTree(self):
429            """If the session tree is shown close it otherwise create a new tree"""
430          name = "session_tree"          name = "session_tree"
431          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
432          if dialog is None:          if dialog is None:
433              dialog = tree.SessionTreeView(self, main.app, name)              dialog = tree.SessionTreeView(self, self.application, name)
434              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
435              dialog.Show(true)              dialog.Show(True)
436          else:          else:
437              # FIXME: bring dialog to front here              dialog.Close()
438              pass  
439        def SessionTreeShown(self):
440            """Return true iff the session tree is currently shown"""
441            return self.get_open_dialog("session_tree") is not None
442    
443      def About(self):      def About(self):
444          self.RunMessageBox("About",          dlg = About(self)
445                             ("Thuban is a program for\n"          dlg.ShowModal()
446                              "exploring geographic data.\n"          dlg.Destroy()
                             "Copyright (C) 2001 Intevation GmbH.\n"  
                             "Thuban is licensed under the GPL"),  
                            wxOK | wxICON_INFORMATION)  
447    
448      def AddLayer(self):      def AddLayer(self):
449          dlg = wxFileDialog(self, "Select a session file", ".", "", "*.*",          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",
450                             wxOPEN)                             wxOPEN)
451          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
452              filename = dlg.GetPath()              filename = dlg.GetPath()
453              title = os.path.splitext(os.path.basename(filename))[0]              title = os.path.splitext(os.path.basename(filename))[0]
             layer = Layer(title, filename)  
454              map = self.canvas.Map()              map = self.canvas.Map()
455              has_layers = map.HasLayers()              has_layers = map.HasLayers()
456              try:              try:
457                    store = self.application.Session().OpenShapefile(filename)
458                except IOError:
459                    # the layer couldn't be opened
460                    self.RunMessageBox(_("Add Layer"),
461                                       _("Can't open the file '%s'.") % filename)
462                else:
463                    layer = Layer(title, store)
464                  map.AddLayer(layer)                  map.AddLayer(layer)
465                    if not has_layers:
466                        # if we're adding a layer to an empty map, fit the
467                        # new map to the window
468                        self.canvas.FitMapToWindow()
469            dlg.Destroy()
470    
471        def AddRasterLayer(self):
472            dlg = wxFileDialog(self, _("Select an image file"), ".", "", "*.*",
473                               wxOPEN)
474            if dlg.ShowModal() == wxID_OK:
475                filename = dlg.GetPath()
476                title = os.path.splitext(os.path.basename(filename))[0]
477                map = self.canvas.Map()
478                has_layers = map.HasLayers()
479                try:
480                    layer = RasterLayer(title, filename)
481              except IOError:              except IOError:
482                  # the layer couldn't be opened                  # the layer couldn't be opened
483                  self.RunMessageBox("Add Layer",                  self.RunMessageBox(_("Add Image Layer"),
484                                     "Can't open the file '%s'." % filename)                                     _("Can't open the file '%s'.") % filename)
485              else:              else:
486                    map.AddLayer(layer)
487                  if not has_layers:                  if not has_layers:
488                      # if we're adding a layer to an empty map, for the                      # if we're adding a layer to an empty map, fit the
489                      # new map to the window                      # new map to the window
490                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
491          dlg.Destroy()          dlg.Destroy()
# Line 330  class MainWindow(wxFrame): Line 495  class MainWindow(wxFrame):
495          if layer is not None:          if layer is not None:
496              self.canvas.Map().RemoveLayer(layer)              self.canvas.Map().RemoveLayer(layer)
497    
498        def CanRemoveLayer(self):
499            """Return true if the currently selected layer can be deleted.
500    
501            If no layer is selected return False.
502    
503            The return value of this method determines whether the remove
504            layer command is sensitive in menu.
505            """
506            layer = self.current_layer()
507            if layer is not None:
508                return self.canvas.Map().CanRemoveLayer(layer)
509            return False
510    
511      def RaiseLayer(self):      def RaiseLayer(self):
512          layer = self.current_layer()          layer = self.current_layer()
513          if layer is not None:          if layer is not None:
514              self.canvas.Map().RaiseLayer(layer)              self.canvas.Map().RaiseLayer(layer)
515            
516      def LowerLayer(self):      def LowerLayer(self):
517          layer = self.current_layer()          layer = self.current_layer()
518          if layer is not None:          if layer is not None:
# Line 345  class MainWindow(wxFrame): Line 523  class MainWindow(wxFrame):
523    
524          If no layer is selected, return None          If no layer is selected, return None
525          """          """
526          return self.interactor.SelectedLayer()          return self.canvas.SelectedLayer()
527    
528      def has_selected_layer(self):      def has_selected_layer(self):
529          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
530          return self.interactor.HasSelectedLayer()          return self.canvas.HasSelectedLayer()
531    
532      def choose_color(self):      def has_selected_shapes(self):
533          """Run the color selection dialog and return the selected color.          """Return true if a shape is currently selected"""
534            return self.canvas.HasSelectedShapes()
535    
536          If the user cancels, return None.      def HideLayer(self):
         """  
         dlg = wxColourDialog(self)  
         color = None  
         if dlg.ShowModal() == wxID_OK:  
             data = dlg.GetColourData()  
             wxc = data.GetColour()  
             color = Color(wxc.Red() / 255.0,  
                           wxc.Green() / 255.0,  
                           wxc.Blue() / 255.0)  
         dlg.Destroy()  
         return color  
   
     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):  
537          layer = self.current_layer()          layer = self.current_layer()
538          if layer is not None:          if layer is not None:
539              layer.SetFill(None)              layer.SetVisible(0)
540    
541      def LayerOutlineColor(self):      def ShowLayer(self):
542          layer = self.current_layer()          layer = self.current_layer()
543          if layer is not None:          if layer is not None:
544              color = self.choose_color()              layer.SetVisible(1)
             if color is not None:  
                 layer.SetStroke(color)  
545    
546      def LayerNoOutline(self):      def DuplicateLayer(self):
547            """Ceate a new layer above the selected layer with the same shapestore
548            """
549          layer = self.current_layer()          layer = self.current_layer()
550          if layer is not None:          if layer is not None and hasattr(layer, "ShapeStore"):
551              layer.SetStroke(None)              new_layer = Layer(_("Copy of `%s'") % layer.Title(),
552                                  layer.ShapeStore(),
553                                  projection = layer.GetProjection())
554                new_classification = copy.deepcopy(layer.GetClassification())
555                new_layer.SetClassification(new_classification)
556                self.Map().AddLayer(new_layer)
557    
558      def HideLayer(self):      def CanDuplicateLayer(self):
559            """Return whether the DuplicateLayer method can create a duplicate"""
560          layer = self.current_layer()          layer = self.current_layer()
561          if layer is not None:          return layer is not None and hasattr(layer, "ShapeStore")
             layer.SetVisible(0)  
           
     def ShowLayer(self):  
         layer = self.current_layer()  
         if layer is not None:  
             layer.SetVisible(1)  
562    
563      def LayerShowTable(self):      def LayerShowTable(self):
564          layer = self.current_layer()          layer = self.current_layer()
565          if layer is not None:          if layer is not None:
566              table = layer.table              table = layer.ShapeStore().Table()
567              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
568              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
569              if dialog is None:              if dialog is None:
570                  dialog = tableview.TableFrame(self, self.interactor, name,                  dialog = tableview.LayerTableFrame(self, name,
571                                                "Table: %s" % layer.Title(),                                           _("Layer Table: %s") % layer.Title(),
572                                                layer, table)                                           layer, table)
573                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
574                  dialog.Show(true)                  dialog.Show(True)
575              else:              else:
576                  # FIXME: bring dialog to front here                  # FIXME: bring dialog to front here
577                  pass                  pass
578    
579      def Projection(self):      def MapProjection(self):
580          map = self.canvas.Map()  
581          proj = map.projection          name = "map_projection"
582          if proj is None:          dialog = self.get_open_dialog(name)
583              proj4Dlg = proj4dialog.Proj4Dialog(NULL, None)  
584          else:          if dialog is None:
585              proj4Dlg = proj4dialog.Proj4Dialog(NULL, map.projection.params)              map = self.canvas.Map()
586          if proj4Dlg.ShowModal() == wxID_OK:              dialog = projdialog.ProjFrame(self, name,
587              params = proj4Dlg.GetParams()                       _("Map Projection: %s") % map.Title(), map)
588              if params is not None:              self.add_dialog(name, dialog)
589                  proj = Projection(params)              dialog.Show()
590            dialog.Raise()
591    
592        def LayerProjection(self):
593    
594            layer = self.current_layer()
595    
596            name = "layer_projection" + str(id(layer))
597            dialog = self.get_open_dialog(name)
598    
599            if dialog is None:
600                map = self.canvas.Map()
601                dialog = projdialog.ProjFrame(self, name,
602                         _("Layer Projection: %s") % layer.Title(), layer)
603                self.add_dialog(name, dialog)
604                dialog.Show()
605            dialog.Raise()
606    
607        def LayerEditProperties(self):
608    
609            #
610            # the menu option for this should only be available if there
611            # is a current layer, so we don't need to check if the
612            # current layer is None
613            #
614    
615            layer = self.current_layer()
616            self.OpenLayerProperties(layer)
617    
618        def OpenLayerProperties(self, layer, group = None):
619            name = "layer_properties" + str(id(layer))
620            dialog = self.get_open_dialog(name)
621    
622            if dialog is None:
623                dialog = Classifier(self, name, self.Map(), layer, group)
624                self.add_dialog(name, dialog)
625                dialog.Show()
626            dialog.Raise()
627    
628        def LayerJoinTable(self):
629            layer = self.canvas.SelectedLayer()
630            if layer is not None:
631                dlg = JoinDialog(self, _("Join Layer with Table"),
632                                 self.application.session,
633                                 layer = layer)
634                dlg.ShowModal()
635    
636        def LayerUnjoinTable(self):
637            layer = self.canvas.SelectedLayer()
638            if layer is not None:
639                orig_store = layer.ShapeStore().OrigShapeStore()
640                if orig_store:
641                    layer.SetShapeStore(orig_store)
642    
643        def ShowLegend(self):
644            if not self.LegendShown():
645                self.ToggleLegend()
646    
647        def ToggleLegend(self):
648            """Show the legend if it's not shown otherwise hide it again"""
649            name = "legend"
650            dialog = self.FindRegisteredDock(name)
651    
652            if dialog is None:
653                dialog = self.CreateDock(name, -1, _("Legend"), wxLAYOUT_LEFT)
654                legend.LegendPanel(dialog, None, self)
655                dialog.Dock()
656                dialog.GetPanel().SetMap(self.Map())
657                dialog.Show()
658            else:
659                dialog.Show(not dialog.IsShown())
660    
661        def LegendShown(self):
662            """Return true iff the legend is currently open"""
663            dialog = self.FindRegisteredDock("legend")
664            return dialog is not None and dialog.IsShown()
665    
666        def TableOpen(self):
667            dlg = wxFileDialog(self, _("Open Table"), ".", "",
668                               _("DBF Files (*.dbf)") + "|*.dbf|" +
669                               #_("CSV Files (*.csv)") + "|*.csv|" +
670                               _("All Files (*.*)") + "|*.*",
671                               wxOPEN)
672            if dlg.ShowModal() == wxID_OK:
673                filename = dlg.GetPath()
674                dlg.Destroy()
675                try:
676                    table = self.application.session.OpenTableFile(filename)
677                except IOError:
678                    # the layer couldn't be opened
679                    self.RunMessageBox(_("Open Table"),
680                                       _("Can't open the file '%s'.") % filename)
681              else:              else:
682                  proj = None                  self.ShowTableView(table)
683              map.SetProjection(proj)  
684          proj4Dlg.Destroy()      def TableClose(self):
685            tables = self.application.session.UnreferencedTables()
686    
687            lst = [(t.Title(), t) for t in tables]
688            lst.sort()
689            titles = [i[0] for i in lst]
690            dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"),
691                                         _("Close Table"), titles,
692                                         size = (400, 300),
693                                         style = wxDEFAULT_DIALOG_STYLE |
694                                                 wxRESIZE_BORDER)
695            if dlg.ShowModal() == wxID_OK:
696                for i in dlg.GetValue():
697                    self.application.session.RemoveTable(lst[i][1])
698    
699    
700        def TableShow(self):
701            """Offer a multi-selection dialog for tables to be displayed
702    
703            The windows for the selected tables are opened or brought to
704            the front.
705            """
706            tables = self.application.session.Tables()
707    
708            lst = [(t.Title(), t) for t in tables]
709            lst.sort()
710            titles = [i[0] for i in lst]
711            dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"),
712                                         _("Show Table"), titles,
713                                         size = (400,300),
714                                         style = wxDEFAULT_DIALOG_STYLE |
715                                                 wxRESIZE_BORDER)
716            if (dlg.ShowModal() == wxID_OK):
717                for i in dlg.GetValue():
718                    # XXX: if the table belongs to a layer, open a
719                    # LayerTableFrame instead of QueryTableFrame
720                    self.ShowTableView(lst[i][1])
721    
722        def TableJoin(self):
723            dlg = JoinDialog(self, _("Join Tables"), self.application.session)
724            dlg.ShowModal()
725    
726        def ShowTableView(self, table):
727            """Open a table view for the table and optionally"""
728            name = "table_view%d" % id(table)
729            dialog = self.get_open_dialog(name)
730            if dialog is None:
731                dialog = tableview.QueryTableFrame(self, name,
732                                                   _("Table: %s") % table.Title(),
733                                                   table)
734                self.add_dialog(name, dialog)
735                dialog.Show(True)
736            dialog.Raise()
737    
738        def TableRename(self):
739            """Let the user rename a table"""
740    
741            # First, let the user select a table
742            tables = self.application.session.Tables()
743            lst = [(t.Title(), t) for t in tables]
744            lst.sort()
745            titles = [i[0] for i in lst]
746            dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"),
747                                         _("Rename Table"), titles,
748                                         size = (400,300),
749                                         style = wxDEFAULT_DIALOG_STYLE |
750                                                 wxRESIZE_BORDER)
751            if (dlg.ShowModal() == wxID_OK):
752                to_rename = [lst[i][1] for i in dlg.GetValue()]
753                dlg.Destroy()
754            else:
755                to_rename = []
756    
757            # Second, let the user rename the layers
758            for table in to_rename:
759                dlg = wxTextEntryDialog(self, "Table Title: ", "Rename Table",
760                                        table.Title())
761                try:
762                    if dlg.ShowModal() == wxID_OK:
763                        title = dlg.GetValue()
764                        if title != "":
765                            table.SetTitle(title)
766    
767                            # Make sure the session is marked as modified.
768                            # FIXME: This should be handled automatically,
769                            # but that requires more changes to the tables
770                            # than I have time for currently.
771                            self.application.session.changed()
772                finally:
773                    dlg.Destroy()
774    
775    
776      def ZoomInTool(self):      def ZoomInTool(self):
777          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
# Line 452  class MainWindow(wxFrame): Line 792  class MainWindow(wxFrame):
792      def FullExtent(self):      def FullExtent(self):
793          self.canvas.FitMapToWindow()          self.canvas.FitMapToWindow()
794    
795        def FullLayerExtent(self):
796            self.canvas.FitLayerToWindow(self.current_layer())
797    
798        def FullSelectionExtent(self):
799            self.canvas.FitSelectedToWindow()
800    
801        def ExportMap(self):
802            self.canvas.Export()
803    
804      def PrintMap(self):      def PrintMap(self):
805          self.canvas.Print()          self.canvas.Print()
806    
807      def identify_view_on_demand(self, layer, shape):      def RenameMap(self):
808            dlg = wxTextEntryDialog(self, "Map Title: ", "Rename Map",
809                                    self.Map().Title())
810            if dlg.ShowModal() == wxID_OK:
811                title = dlg.GetValue()
812                if title != "":
813                    self.Map().SetTitle(title)
814                    self.__SetTitle(title)
815    
816            dlg.Destroy()
817    
818        def RenameLayer(self):
819            """Let the user rename the currently selected layer"""
820            layer = self.current_layer()
821            if layer is not None:
822                dlg = wxTextEntryDialog(self, "Layer Title: ", "Rename Layer",
823                                        layer.Title())
824                try:
825                    if dlg.ShowModal() == wxID_OK:
826                        title = dlg.GetValue()
827                        if title != "":
828                            layer.SetTitle(title)
829                finally:
830                    dlg.Destroy()
831    
832        def identify_view_on_demand(self, layer, shapes):
833            """Subscribed to the canvas' SHAPES_SELECTED message
834    
835            If the current tool is the identify tool, at least one shape is
836            selected and the identify dialog is not shown, show the dialog.
837            """
838            # If the selection has become empty we don't need to do
839            # anything. Otherwise it could happen that the dialog was popped
840            # up when the selection became empty, e.g. when a new selection
841            # is opened while the identify tool is active and dialog had
842            # been closed
843            if not shapes:
844                return
845    
846          name = "identify_view"          name = "identify_view"
847          if self.canvas.CurrentTool() == "IdentifyTool":          if self.canvas.CurrentTool() == "IdentifyTool":
848              if not self.dialog_open(name):              if not self.dialog_open(name):
849                  dialog = identifyview.IdentifyView(self, self.interactor, name)                  dialog = identifyview.IdentifyView(self, name)
850                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
851                  dialog.Show(true)                  dialog.Show(True)
852              else:              else:
853                  # FIXME: bring dialog to front?                  # FIXME: bring dialog to front?
854                  pass                  pass
855    
856        def __SetTitle(self, title):
857            self.SetTitle("Thuban - " + title)
858    
859  #  #
860  # Define all the commands available in the main window  # Define all the commands available in the main window
861  #  #
# Line 473  class MainWindow(wxFrame): Line 863  class MainWindow(wxFrame):
863    
864  # Helper functions to define common command implementations  # Helper functions to define common command implementations
865  def call_method(context, methodname, *args):  def call_method(context, methodname, *args):
866      """Call the context's method methodname with args *args"""      """Call the mainwindow's method methodname with args *args"""
867      apply(getattr(context, methodname), args)      apply(getattr(context.mainwindow, methodname), args)
868    
869  def _method_command(name, title, method, helptext = "", sensitive = None):  def _method_command(name, title, method, helptext = "",
870      """Add a command implemented by a method of the context object"""                      icon = "", sensitive = None, checked = None):
871        """Add a command implemented by a method of the mainwindow object"""
872      registry.Add(Command(name, title, call_method, args=(method,),      registry.Add(Command(name, title, call_method, args=(method,),
873                           helptext = helptext, sensitive = sensitive))                           helptext = helptext, icon = icon,
874                             sensitive = sensitive, checked = checked))
875    
876    def make_check_current_tool(toolname):
877        """Return a function that tests if the currently active tool is toolname
878    
879        The returned function can be called with the context and returns
880        true iff the currently active tool's name is toolname. It's directly
881        usable as the 'checked' callback of a command.
882        """
883        def check_current_tool(context, name=toolname):
884            return context.mainwindow.canvas.CurrentTool() == name
885        return check_current_tool
886    
887  def _tool_command(name, title, method, toolname, helptext = "",  def _tool_command(name, title, method, toolname, helptext = "",
888                    icon = ""):                    icon = "", sensitive = None):
889      """Add a tool command"""      """Add a tool command"""
890      def check_current_tool(context, name=toolname):      registry.Add(ToolCommand(name, title, call_method, args=(method,),
891          return context.canvas.CurrentTool() == name                               helptext = helptext, icon = icon,
892      registry.Add(Command(name, title, call_method, args=(method,),                               checked = make_check_current_tool(toolname),
893                           helptext = helptext, icon = icon,                               sensitive = sensitive))
                          checked = check_current_tool))  
894    
895  def _has_selected_layer(context):  def _has_selected_layer(context):
896      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
897      return context.has_selected_layer()      return context.mainwindow.has_selected_layer()
898    
899    def _has_selected_shapes(context):
900        """Return true if a layer is selected in the context"""
901        return context.mainwindow.has_selected_shapes()
902    
903    def _can_remove_layer(context):
904        return context.mainwindow.CanRemoveLayer()
905    
906    def _has_tree_window_shown(context):
907        """Return true if the tree window is shown"""
908        return context.mainwindow.SessionTreeShown()
909    
910    def _has_visible_map(context):
911        """Return true iff theres a visible map in the mainwindow.
912    
913        A visible map is a map with at least one visible layer."""
914        map = context.mainwindow.Map()
915        if map is not None:
916            for layer in map.Layers():
917                if layer.Visible():
918                    return 1
919        return 0
920    
921    def _has_legend_shown(context):
922        """Return true if the legend window is shown"""
923        return context.mainwindow.LegendShown()
924    
925    def _has_gdal_support(context):
926        """Return True if the GDAL is available"""
927        return Thuban.Model.resource.has_gdal_support()
928    
929  # File menu  # File menu
930  _method_command("new_session", "&New Session", "NewSession")  _method_command("new_session", _("&New Session"), "NewSession",
931  _method_command("open_session", "&Open Session", "OpenSession")                  helptext = _("Start a new session"))
932  _method_command("save_session", "&Save Session", "SaveSession")  _method_command("open_session", _("&Open Session..."), "OpenSession",
933  _method_command("save_session_as", "Save Session &As", "SaveSessionAs")                  helptext = _("Open a session file"))
934  _method_command("exit", "&Exit", "Exit")  _method_command("save_session", _("&Save Session"), "SaveSession",
935                    helptext =_("Save this session to the file it was opened from"))
936    _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs",
937                    helptext = _("Save this session to a new file"))
938    _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
939                    checked = _has_tree_window_shown,
940                    helptext = _("Toggle on/off the session tree analysis window"))
941    _method_command("toggle_legend", _("Legend"), "ToggleLegend",
942                    checked = _has_legend_shown,
943                    helptext = _("Toggle Legend on/off"))
944    _method_command("exit", _("E&xit"), "Exit",
945                    helptext = _("Finish working with Thuban"))
946    
947  # Help menu  # Help menu
948  _method_command("help_about", "&About", "About")  _method_command("help_about", _("&About..."), "About",
949                    helptext = _("Info about Thuban authors, version and modules"))
950    
951    
952  # Map menu  # Map menu
953  _method_command("map_projection", "Pro&jection", "Projection")  _method_command("map_projection", _("Pro&jection..."), "MapProjection",
954                    helptext = _("Set or change the map projection"))
955    
956  _tool_command("map_zoom_in_tool", "&Zoom in", "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
957                helptext = "Switch to map-mode 'zoom-in'", icon = "zoom_in")                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
958  _tool_command("map_zoom_out_tool", "Zoom &out", "ZoomOutTool", "ZoomOutTool",                sensitive = _has_visible_map)
959                helptext = "Switch to map-mode 'zoom-out'", icon = "zoom_out")  _tool_command("map_zoom_out_tool", _("Zoom &out"), "ZoomOutTool", "ZoomOutTool",
960  _tool_command("map_pan_tool", "&Pan", "PanTool", "PanTool",                helptext = _("Switch to map-mode 'zoom-out'"), icon = "zoom_out",
961                helptext = "Switch to map-mode 'pan'", icon = "pan")                sensitive = _has_visible_map)
962  _tool_command("map_identify_tool", "&Identify", "IdentifyTool", "IdentifyTool",  _tool_command("map_pan_tool", _("&Pan"), "PanTool", "PanTool",
963                helptext = "Switch to map-mode 'identify'", icon = "identify")                helptext = _("Switch to map-mode 'pan'"), icon = "pan",
964  _tool_command("map_label_tool", "&Label", "LabelTool", "LabelTool",                sensitive = _has_visible_map)
965                helptext = "Add/Remove labels", icon = "label")  _tool_command("map_identify_tool", _("&Identify"), "IdentifyTool",
966  _method_command("map_full_extent", "&Full extent", "FullExtent")                "IdentifyTool",
967  _method_command("map_print", "Prin&t", "PrintMap", helptext = "Print the map")                helptext = _("Switch to map-mode 'identify'"), icon = "identify",
968                  sensitive = _has_visible_map)
969    _tool_command("map_label_tool", _("&Label"), "LabelTool", "LabelTool",
970                  helptext = _("Add/Remove labels"), icon = "label",
971                  sensitive = _has_visible_map)
972    _method_command("map_full_extent", _("&Full extent"), "FullExtent",
973                   helptext = _("Zoom to the full map extent"), icon = "fullextent",
974                  sensitive = _has_visible_map)
975    _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",
976                    helptext = _("Zoom to the full layer extent"),
977                    icon = "fulllayerextent", sensitive = _has_selected_layer)
978    _method_command("selected_full_extent", _("&Full selection extent"),
979                    "FullSelectionExtent",
980                    helptext = _("Zoom to the full selection extent"),
981                    icon = "fullselextent", sensitive = _has_selected_shapes)
982    _method_command("map_export", _("E&xport"), "ExportMap",
983                    helptext = _("Export the map to file"))
984    _method_command("map_print", _("Prin&t"), "PrintMap",
985                    helptext = _("Print the map"))
986    _method_command("map_rename", _("&Rename..."), "RenameMap",
987                    helptext = _("Rename the map"))
988    _method_command("layer_add", _("&Add Layer..."), "AddLayer",
989                    helptext = _("Add a new layer to the map"))
990    _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
991                    helptext = _("Add a new image layer to the map"),
992                    sensitive = _has_gdal_support)
993    _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
994                    helptext = _("Remove selected layer"),
995                    sensitive = _can_remove_layer)
996    
997  # Layer menu  # Layer menu
998  _method_command("layer_add", "&Add Layer", "AddLayer",  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
999                  helptext = "Add a new layer to active map")                  sensitive = _has_selected_layer,
1000  _method_command("layer_remove", "&Remove Layer", "RemoveLayer",                  helptext = _("Specify projection for selected layer"))
1001                  helptext = "Remove selected layer(s)",  _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
1002                    helptext = _("Duplicate selected layer"),
1003              sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
1004    _method_command("layer_rename", _("Re&name ..."), "RenameLayer",
1005                    helptext = _("Rename selected layer"),
1006                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1007  _method_command("layer_fill_color", "&Fill Color", "LayerFillColor",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
1008                  helptext = "Set the fill color of selected layer(s)",                  helptext = _("Raise selected layer"),
1009                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1010  _method_command("layer_transparent_fill", "&Transparent Fill",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
1011                  "LayerTransparentFill",                  helptext = _("Lower selected layer"),
                 helptext = "Do not fill the selected layer(s)",  
1012                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1013  _method_command("layer_ourline_color", "&Outline Color", "LayerOutlineColor",  _method_command("layer_show", _("&Show"), "ShowLayer",
1014                  helptext = "Set the outline color of selected layer(s)",                  helptext = _("Make selected layer visible"),
1015                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1016  _method_command("layer_no_outline", "&No Outline", "LayerNoOutline",  _method_command("layer_hide", _("&Hide"), "HideLayer",
1017                  helptext = "Do not draw the outline of the selected layer(s)",                  helptext = _("Make selected layer unvisible"),
1018                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1019  _method_command("layer_raise", "&Raise", "RaiseLayer",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
1020                  helptext = "Raise selected layer(s)",                  helptext = _("Show the selected layer's table"),
                 sensitive = _has_selected_layer)  
 _method_command("layer_lower", "&Lower", "LowerLayer",  
                 helptext = "Lower selected layer(s)",  
                 sensitive = _has_selected_layer)  
 _method_command("layer_show", "&Show", "ShowLayer",  
                 helptext = "Make selected layer(s) visible",  
                 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",  
1021                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1022    _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
1023                    sensitive = _has_selected_layer,
1024                    helptext = _("Edit the properties of the selected layer"))
1025    _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1026                    sensitive = _has_selected_layer,
1027                    helptext = _("Join and attach a table to the selected layer"))
1028    
1029    def _can_unjoin(context):
1030        """Return whether the Layer/Unjoin command can be executed.
1031    
1032        This is the case if a layer is selected and that layer has a
1033        shapestore that has an original shapestore.
1034        """
1035        layer = context.mainwindow.SelectedLayer()
1036        if layer is None:
1037            return 0
1038        getstore = getattr(layer, "ShapeStore", None)
1039        if getstore is not None:
1040            return getstore().OrigShapeStore() is not None
1041        else:
1042            return 0
1043    _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
1044                    sensitive = _can_unjoin,
1045                    helptext = _("Undo the last join operation"))
1046    
1047    
1048    def _has_tables(context):
1049        return bool(context.session.Tables())
1050    
1051    # Table menu
1052    _method_command("table_open", _("&Open..."), "TableOpen",
1053                    helptext = _("Open a DBF-table from a file"))
1054    _method_command("table_close", _("&Close..."), "TableClose",
1055           sensitive = lambda context: bool(context.session.UnreferencedTables()),
1056                    helptext = _("Close one or more tables from a list"))
1057    _method_command("table_rename", _("&Rename..."), "TableRename",
1058                    sensitive = _has_tables,
1059                    helptext = _("Rename one or more tables"))
1060    _method_command("table_show", _("&Show..."), "TableShow",
1061                    sensitive = _has_tables,
1062                    helptext = _("Show one or more tables in a dialog"))
1063    _method_command("table_join", _("&Join..."), "TableJoin",
1064                    sensitive = _has_tables,
1065                    helptext = _("Join two tables creating a new one"))
1066    
1067    #  Export only under Windows ...
1068    map_menu = ["layer_add", "rasterlayer_add", "layer_remove",
1069                            None,
1070                            "map_rename",
1071                            "map_projection",
1072                            None,
1073                            "map_zoom_in_tool", "map_zoom_out_tool",
1074                            "map_pan_tool",
1075                            "map_full_extent",
1076                            "layer_full_extent",
1077                            "selected_full_extent",
1078                            None,
1079                            "map_identify_tool", "map_label_tool",
1080                            None,
1081                            "toggle_legend",
1082                            None]
1083    if wxPlatform == '__WXMSW__':
1084        map_menu.append("map_export")
1085    map_menu.append("map_print")
1086    
1087    # the menu structure
1088    main_menu = Menu("<main>", "<main>",
1089                     [Menu("file", _("&File"),
1090                           ["new_session", "open_session", None,
1091                            "save_session", "save_session_as", None,
1092                            "toggle_session_tree", None,
1093                            "exit"]),
1094                      Menu("map", _("&Map"), map_menu),
1095                      Menu("layer", _("&Layer"),
1096                           ["layer_rename", "layer_duplicate",
1097                            None,
1098                            "layer_raise", "layer_lower",
1099                            None,
1100                            "layer_show", "layer_hide",
1101                            None,
1102                            "layer_projection",
1103                            None,
1104                            "layer_show_table",
1105                            "layer_jointable",
1106                            "layer_unjointable",
1107                            None,
1108                            "layer_properties"]),
1109                      Menu("table", _("&Table"),
1110                           ["table_open", "table_close", "table_rename",
1111                           None,
1112                           "table_show",
1113                           None,
1114                           "table_join"]),
1115                      Menu("help", _("&Help"),
1116                           ["help_about"])])
1117    
1118    # the main toolbar
1119    
1120    main_toolbar = Menu("<toolbar>", "<toolbar>",
1121                        ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",
1122                         "map_full_extent",
1123                         "layer_full_extent",
1124                         "selected_full_extent",
1125                         None,
1126                         "map_identify_tool", "map_label_tool"])
1127    

Legend:
Removed from v.102  
changed lines
  Added in v.1464

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26