/[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 191 by bh, Tue May 28 16:04:49 2002 UTC revision 2364 by joey, Fri Oct 1 18:18:49 2004 UTC
# Line 1  Line 1 
1  # Copyright (C) 2001, 2002 by Intevation GmbH  # Copyright (C) 2001, 2002, 2003, 2004 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 11  The main window Line 12  The main window
12  """  """
13    
14  __version__ = "$Revision$"  __version__ = "$Revision$"
15    # $Source$
16    # $Id$
17    
18  import os  import os
19    import copy
20    
21  from wxPython.wx import *  from wxPython.wx import *
22    
23  import Thuban  import Thuban
24    
25    from Thuban import _
26    from Thuban.Model.messages import TITLE_CHANGED
27  from Thuban.Model.session import create_empty_session  from Thuban.Model.session import create_empty_session
28  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer, RasterLayer
29  from Thuban.Model.color import Color  from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support
30  from Thuban.Model.proj import Projection  # XXX: replace this by
31    # from wxPython.lib.dialogs import wxMultipleChoiceDialog
32    # when Thuban does not support wxPython 2.4.0 any more.
33    from Thuban.UI.multiplechoicedialog import wxMultipleChoiceDialog
34    
35  import view  import view
36  import tree  import tree
 import proj4dialog  
37  import tableview, identifyview  import tableview, identifyview
38    from Thuban.UI.classifier import Classifier
39    import legend
40  from menu import Menu  from menu import Menu
41    
42  import main  from context import Context
43  from command import registry, Command  from command import registry, Command, ToolCommand
44  from messages import SELECTED_SHAPE, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, \
45         MAP_REPLACED
46    from about import About
47  # the directory where the toolbar icons are stored  
48  bitmapdir = os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Bitmaps")  from Thuban.UI.dock import DockFrame
49  bitmapext = ".xpm"  from Thuban.UI.join import JoinDialog
50    from Thuban.UI.dbdialog import DBFrame, DBDialog, ChooseDBTableDialog
51    import resource
52    import Thuban.Model.resource
53    
54    import projdialog
55    
56    
57    class MainWindow(DockFrame):
58    
59        # Some messages that can be subscribed/unsubscribed directly through
60        # the MapCanvas come in fact from other objects. This is a map to
61        # map those messages to the names of the instance variables they
62        # actually come from. This delegation is implemented in the
63        # Subscribe and unsubscribed methods
64        delegated_messages = {LAYER_SELECTED: "canvas",
65                              SHAPES_SELECTED: "canvas",
66                              MAP_REPLACED: "canvas"}
67    
68        # Methods delegated to some instance variables. The delegation is
69        # implemented in the __getattr__ method.
70        delegated_methods = {"SelectLayer": "canvas",
71                             "SelectShapes": "canvas",
72                             "SelectedLayer": "canvas",
73                             "SelectedShapes": "canvas",
74                             }
75    
76        def __init__(self, parent, ID, title, application, interactor,
77                     initial_message = None, size = wxSize(-1, -1)):
78            DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)
79            #wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)
80    
81  class MainWindow(wxFrame):          self.application = application
   
     def __init__(self, parent, ID, interactor):  
         wxFrame.__init__(self, parent, ID, 'Thuban',  
                          wxDefaultPosition, wxSize(400, 300))  
   
         self.interactor = interactor  
82    
83          self.CreateStatusBar()          self.CreateStatusBar()
84          self.SetStatusText("This is the wxPython-based "          if initial_message:
85                        "Graphical User Interface for exploring geographic data")              self.SetStatusText(initial_message)
86    
87          self.identify_view = None          self.identify_view = None
88    
# Line 62  class MainWindow(wxFrame): Line 96  class MainWindow(wxFrame):
96          # call Realize to make sure that the tools appear.          # call Realize to make sure that the tools appear.
97          toolbar.Realize()          toolbar.Realize()
98    
99    
100          # Create the map canvas          # Create the map canvas
101          canvas = view.MapCanvas(self, -1, interactor)          canvas = view.MapCanvas(self, -1)
102          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)
103            canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)
104          self.canvas = canvas          self.canvas = canvas
105            self.canvas.Subscribe(TITLE_CHANGED, self.title_changed)
106    
107            self.SetMainWindow(self.canvas)
108    
109            self.SetAutoLayout(True)
110    
111          self.init_dialogs()          self.init_dialogs()
112    
113          interactor.Subscribe(SELECTED_SHAPE, self.identify_view_on_demand)          self.ShowLegend()
114    
115          EVT_CLOSE(self, self.OnClose)          EVT_CLOSE(self, self.OnClose)
116    
117        def Subscribe(self, channel, *args):
118            """Subscribe a function to a message channel.
119    
120            If channel is one of the delegated messages call the appropriate
121            object's Subscribe method. Otherwise do nothing.
122            """
123            if channel in self.delegated_messages:
124                object = getattr(self, self.delegated_messages[channel])
125                object.Subscribe(channel, *args)
126            else:
127                print "Trying to subscribe to unsupported channel %s" % channel
128    
129        def Unsubscribe(self, channel, *args):
130            """Unsubscribe a function from a message channel.
131    
132            If channel is one of the delegated messages call the appropriate
133            object's Unsubscribe method. Otherwise do nothing.
134            """
135            if channel in self.delegated_messages:
136                object = getattr(self, self.delegated_messages[channel])
137                try:
138                    object.Unsubscribe(channel, *args)
139                except wxPyDeadObjectError:
140                    # The object was a wxObject and has already been
141                    # destroyed. Hopefully it has unsubscribed all its
142                    # subscribers already so that it's OK if we do nothing
143                    # here
144                    pass
145    
146        def __getattr__(self, attr):
147            """If attr is one of the delegated methods return that method
148    
149            Otherwise raise AttributeError.
150            """
151            if attr in self.delegated_methods:
152                return getattr(getattr(self, self.delegated_methods[attr]), attr)
153            raise AttributeError(attr)
154    
155      def init_ids(self):      def init_ids(self):
156          """Initialize the ids"""          """Initialize the ids"""
157          self.current_id = 6000          self.current_id = 6000
158          self.id_to_name = {}          self.id_to_name = {}
159          self.name_to_id = {}          self.name_to_id = {}
160            self.events_bound = {}
161    
162      def get_id(self, name):      def get_id(self, name):
163          """Return the wxWindows id for the command named name.          """Return the wxWindows id for the command named name.
# Line 91  class MainWindow(wxFrame): Line 171  class MainWindow(wxFrame):
171              self.id_to_name[ID] = name              self.id_to_name[ID] = name
172          return ID          return ID
173    
174        def bind_command_events(self, command, ID):
175            """Bind the necessary events for the given command and ID"""
176            if not self.events_bound.has_key(ID):
177                # the events haven't been bound yet
178                EVT_MENU(self, ID, self.invoke_command)
179                if command.IsDynamic():
180                    EVT_UPDATE_UI(self, ID, self.update_command_ui)
181    
182      def build_menu_bar(self, menudesc):      def build_menu_bar(self, menudesc):
183          """Build and return the menu bar from the menu description"""          """Build and return the menu bar from the menu description"""
184          menu_bar = wxMenuBar()          menu_bar = wxMenuBar()
# Line 102  class MainWindow(wxFrame): Line 190  class MainWindow(wxFrame):
190          return menu_bar          return menu_bar
191    
192      def build_menu(self, menudesc):      def build_menu(self, menudesc):
193          """Build and return a wxMenu from a menudescription"""          """Return a wxMenu built from the menu description menudesc"""
194          wxmenu = wxMenu()          wxmenu = wxMenu()
195          last = None          last = None
196          for item in menudesc.items:          for item in menudesc.items:
             # here the items must all be Menu instances themselves  
197              if item is None:              if item is None:
198                  # a separator. Only add one if the last item was not a                  # a separator. Only add one if the last item was not a
199                  # separator                  # separator
# Line 157  class MainWindow(wxFrame): Line 244  class MainWindow(wxFrame):
244                  ID = self.get_id(name)                  ID = self.get_id(name)
245                  menu.Append(ID, command.Title(), command.HelpText(),                  menu.Append(ID, command.Title(), command.HelpText(),
246                              command.IsCheckCommand())                              command.IsCheckCommand())
247                  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)  
248              else:              else:
249                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
250    
251      def add_toolbar_command(self, toolbar, name):      def add_toolbar_command(self, toolbar, name):
252          """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 261  class MainWindow(wxFrame):
261              command = registry.Command(name)              command = registry.Command(name)
262              if command is not None:              if command is not None:
263                  ID = self.get_id(name)                  ID = self.get_id(name)
264                  filename = os.path.join(bitmapdir, command.Icon()) + bitmapext                  bitmap = resource.GetBitmapResource(command.Icon(),
265                  bitmap = wxBitmap(filename, wxBITMAP_TYPE_XPM)                                                      wxBITMAP_TYPE_XPM)
266                  toolbar.AddTool(ID, bitmap,                  toolbar.AddTool(ID, bitmap,
267                                  shortHelpString = command.HelpText(),                                  shortHelpString = command.HelpText(),
268                                  isToggle = command.IsCheckCommand())                                  isToggle = command.IsCheckCommand())
269                    self.bind_command_events(command, ID)
270              else:              else:
271                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
272    
273        def Context(self):
274            """Return the context object for a command invoked from this window
275            """
276            return Context(self.application, self.application.Session(), self)
277    
278      def invoke_command(self, event):      def invoke_command(self, event):
279          name = self.id_to_name.get(event.GetId())          name = self.id_to_name.get(event.GetId())
280          if name is not None:          if name is not None:
281              command = registry.Command(name)              command = registry.Command(name)
282              command.Execute(self)              command.Execute(self.Context())
283          else:          else:
284              print "Unknown command ID %d" % event.GetId()              print _("Unknown command ID %d") % event.GetId()
285    
286      def update_command_ui(self, event):      def update_command_ui(self, event):
287          #print "update_command_ui", self.id_to_name[event.GetId()]          #print "update_command_ui", self.id_to_name[event.GetId()]
288            context = self.Context()
289          command = registry.Command(self.id_to_name[event.GetId()])          command = registry.Command(self.id_to_name[event.GetId()])
290          if command is not None:          if command is not None:
291              event.Enable(command.Sensitive(self))              sensitive = command.Sensitive(context)
292              event.SetText(command.DynText(self))              event.Enable(sensitive)
293                if command.IsTool() and not sensitive and command.Checked(context):
294                    # When a checked tool command is disabled deselect all
295                    # tools. Otherwise the tool would remain active but it
296                    # might lead to errors if the tools stays active. This
297                    # problem occurred in GREAT-ER and this fixes it, but
298                    # it's not clear to me whether this is really the best
299                    # way to do it (BH, 20021206).
300                    self.canvas.SelectTool(None)
301                event.SetText(command.DynText(context))
302              if command.IsCheckCommand():              if command.IsCheckCommand():
303                  event.Check(command.Checked(self))                      event.Check(command.Checked(context))
304    
305      def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):      def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):
306          """Run a modal message box with the given text, title and flags          """Run a modal message box with the given text, title and flags
307          and return the result"""          and return the result"""
308          dlg = wxMessageDialog(self, text, title, flags)          dlg = wxMessageDialog(self, text, title, flags)
309            dlg.CenterOnParent()
310          result = dlg.ShowModal()          result = dlg.ShowModal()
311          dlg.Destroy()          dlg.Destroy()
312          return result          return result
# Line 218  class MainWindow(wxFrame): Line 320  class MainWindow(wxFrame):
320    
321      def add_dialog(self, name, dialog):      def add_dialog(self, name, dialog):
322          if self.dialogs.has_key(name):          if self.dialogs.has_key(name):
323              raise RuntimeError("The Dialog named %s is already open" % name)              raise RuntimeError(_("The Dialog named %s is already open") % name)
324          self.dialogs[name] = dialog          self.dialogs[name] = dialog
325    
326      def dialog_open(self, name):      def dialog_open(self, name):
# Line 236  class MainWindow(wxFrame): Line 338  class MainWindow(wxFrame):
338              text = "(%10.10g, %10.10g)" % pos              text = "(%10.10g, %10.10g)" % pos
339          else:          else:
340              text = ""              text = ""
341            self.set_position_text(text)
342    
343        def set_position_text(self, text):
344            """Set the statusbar text showing the current position.
345    
346            By default the text is shown in field 0 of the status bar.
347            Override this method in derived classes to put it into a
348            different field of the statusbar.
349            """
350          self.SetStatusText(text)          self.SetStatusText(text)
351    
352        def OpenOrRaiseDialog(self, name, dialog_class, *args, **kw):
353            """
354            Open or raise a dialog.
355    
356            If a dialog with the denoted name does already exist it is
357            raised.  Otherwise a new dialog, an instance of dialog_class,
358            is created, inserted into the main list and displayed.
359            """
360            dialog = self.get_open_dialog(name)
361    
362            if dialog is None:
363                dialog = dialog_class(self, name, *args, **kw)
364                self.add_dialog(name, dialog)
365                dialog.Show(True)
366            else:
367                dialog.Raise()
368                              
369      def save_modified_session(self, can_veto = 1):      def save_modified_session(self, can_veto = 1):
370          """If the current session has been modified, ask the user          """If the current session has been modified, ask the user
371          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 247  class MainWindow(wxFrame): Line 375  class MainWindow(wxFrame):
375          If the can_veto parameter is true (default) the dialog includes          If the can_veto parameter is true (default) the dialog includes
376          a cancel button, otherwise not.          a cancel button, otherwise not.
377          """          """
378          if main.app.session.WasModified():          if self.application.session.WasModified():
379              flags = wxYES_NO | wxICON_QUESTION              flags = wxYES_NO | wxICON_QUESTION
380              if can_veto:              if can_veto:
381                  flags = flags | wxCANCEL                  flags = flags | wxCANCEL
382              result = self.RunMessageBox("Exit",              result = self.RunMessageBox(_("Exit"),
383                                          ("The session has been modified."                                          _("The session has been modified."
384                                           " Do you want to save it?"),                                           " Do you want to save it?"),
385                                          flags)                                          flags)
386              if result == wxID_YES:              if result == wxID_YES:
# Line 262  class MainWindow(wxFrame): Line 390  class MainWindow(wxFrame):
390          return result          return result
391    
392      def NewSession(self):      def NewSession(self):
393          self.save_modified_session()          if self.save_modified_session() != wxID_CANCEL:
394          main.app.SetSession(create_empty_session())              self.application.SetSession(create_empty_session())
395    
396      def OpenSession(self):      def OpenSession(self):
397          self.save_modified_session()          if self.save_modified_session() != wxID_CANCEL:
398          dlg = wxFileDialog(self, "Select a session file", ".", "",              dlg = wxFileDialog(self, _("Open Session"),
399                             "*.thuban", wxOPEN)                                 self.application.Path("data"), "",
400          if dlg.ShowModal() == wxID_OK:                                 "Thuban Session File (*.thuban)|*.thuban",
401              main.app.OpenSession(dlg.GetPath())                                 wxOPEN)
402          dlg.Destroy()              if dlg.ShowModal() == wxID_OK:
403                    self.application.OpenSession(dlg.GetPath(),
404                                                 self.run_db_param_dialog)
405                    self.application.SetPath("data", dlg.GetPath())
406                dlg.Destroy()
407    
408        def run_db_param_dialog(self, parameters, message):
409            dlg = DBDialog(self, _("DB Connection Parameters"), parameters,
410                           message)
411            return dlg.RunDialog()
412    
413      def SaveSession(self):      def SaveSession(self):
414          if main.app.session.filename == None:          if self.application.session.filename == None:
415              self.SaveSessionAs()              self.SaveSessionAs()
416          main.app.SaveSession()          else:
417                self.application.SaveSession()
418    
419      def SaveSessionAs(self):      def SaveSessionAs(self):
420          dlg = wxFileDialog(self, "Enter a filename for session", ".", "",          dlg = wxFileDialog(self, _("Save Session As"),
421                             "*.thuban", wxOPEN)                             self.application.Path("data"), "",
422                               "Thuban Session File (*.thuban)|*.thuban",
423                               wxSAVE|wxOVERWRITE_PROMPT)
424          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
425              main.app.session.SetFilename(dlg.GetPath())              self.application.session.SetFilename(dlg.GetPath())
426              main.app.SaveSession()              self.application.SaveSession()
427                self.application.SetPath("data",dlg.GetPath())
428          dlg.Destroy()          dlg.Destroy()
429    
430      def Exit(self):      def Exit(self):
431          self.Close(false)          self.Close(False)
432    
433      def OnClose(self, event):      def OnClose(self, event):
434          result = self.save_modified_session(can_veto = event.CanVeto())          result = self.save_modified_session(can_veto = event.CanVeto())
435          if result == wxID_CANCEL:          if result == wxID_CANCEL:
436              event.Veto()              event.Veto()
437          else:          else:
438                # FIXME: it would be better to tie the unsubscription to
439                # wx's destroy event, but that isn't implemented for wxGTK
440                # yet.
441                self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)
442                DockFrame.OnClose(self, event)
443                for dlg in self.dialogs.values():
444                    dlg.Destroy()
445                self.canvas.Destroy()
446              self.Destroy()              self.Destroy()
447    
448      def SetMap(self, map):      def SetMap(self, map):
449          self.canvas.SetMap(map)          self.canvas.SetMap(map)
450            self.update_title()
451    
452      def ShowSessionTree(self):          dialog = self.FindRegisteredDock("legend")
453            if dialog is not None:
454                dialog.GetPanel().SetMap(self.Map())
455    
456        def Map(self):
457            """Return the map displayed by this mainwindow"""
458    
459            return self.canvas.Map()
460    
461        def ToggleSessionTree(self):
462            """If the session tree is shown close it otherwise create a new tree"""
463          name = "session_tree"          name = "session_tree"
464          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
465          if dialog is None:          if dialog is None:
466              dialog = tree.SessionTreeView(self, main.app, name)              dialog = tree.SessionTreeView(self, self.application, name)
467              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
468              dialog.Show(true)              dialog.Show(True)
469          else:          else:
470              # FIXME: bring dialog to front here              dialog.Close()
471              pass  
472        def SessionTreeShown(self):
473            """Return true iff the session tree is currently shown"""
474            return self.get_open_dialog("session_tree") is not None
475    
476      def About(self):      def About(self):
477          self.RunMessageBox("About",          dlg = About(self)
478                             ("Thuban is a program for\n"          dlg.ShowModal()
479                              "exploring geographic data.\n"          dlg.Destroy()
480                              "Copyright (C) 2001 Intevation GmbH.\n"  
481                              "Thuban is licensed under the GPL"),      def DatabaseManagement(self):
482                             wxOK | wxICON_INFORMATION)          name = "dbmanagement"
483            dialog = self.get_open_dialog(name)
484            if dialog is None:
485                map = self.canvas.Map()
486                dialog = DBFrame(self, name, self.application.Session())
487                self.add_dialog(name, dialog)
488                dialog.Show()
489            dialog.Raise()
490    
491      def AddLayer(self):      def AddLayer(self):
492          dlg = wxFileDialog(self, "Select a data file", ".", "", "*.*",          dlg = wxFileDialog(self, _("Select one or more data files"),
493                               self.application.Path("data"), "",
494                               _("Shapefiles (*.shp)") + "|*.shp;*.SHP|" +
495                               _("All Files (*.*)") + "|*.*",
496                               wxOPEN | wxMULTIPLE)
497            if dlg.ShowModal() == wxID_OK:
498                filenames = dlg.GetPaths()
499                for filename in filenames:
500                    title = os.path.splitext(os.path.basename(filename))[0]
501                    map = self.canvas.Map()
502                    has_layers = map.HasLayers()
503                    try:
504                        store = self.application.Session().OpenShapefile(filename)
505                    except IOError:
506                        # the layer couldn't be opened
507                        self.RunMessageBox(_("Add Layer"),
508                                           _("Can't open the file '%s'.")%filename)
509                    else:
510                        layer = Layer(title, store)
511                        map.AddLayer(layer)
512                        if not has_layers:
513                            # if we're adding a layer to an empty map, fit the
514                            # new map to the window
515                            self.canvas.FitMapToWindow()
516                        self.application.SetPath("data",filename)
517            dlg.Destroy()
518    
519        def AddRasterLayer(self):
520            dlg = wxFileDialog(self, _("Select an image file"),
521                               self.application.Path("data"), "", "*.*",
522                             wxOPEN)                             wxOPEN)
523          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
524              filename = dlg.GetPath()              filename = dlg.GetPath()
525              title = os.path.splitext(os.path.basename(filename))[0]              title = os.path.splitext(os.path.basename(filename))[0]
             layer = Layer(title, filename)  
526              map = self.canvas.Map()              map = self.canvas.Map()
527              has_layers = map.HasLayers()              has_layers = map.HasLayers()
528              try:              try:
529                  map.AddLayer(layer)                  layer = RasterLayer(title, filename)
530              except IOError:              except IOError:
531                  # the layer couldn't be opened                  # the layer couldn't be opened
532                  self.RunMessageBox("Add Layer",                  self.RunMessageBox(_("Add Image Layer"),
533                                     "Can't open the file '%s'." % filename)                                     _("Can't open the file '%s'.") % filename)
534              else:              else:
535                    map.AddLayer(layer)
536                  if not has_layers:                  if not has_layers:
537                      # if we're adding a layer to an empty map, for the                      # if we're adding a layer to an empty map, fit the
538                      # new map to the window                      # new map to the window
539                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
540                    self.application.SetPath("data", filename)
541            dlg.Destroy()
542    
543        def AddDBLayer(self):
544            """Add a layer read from a database"""
545            session = self.application.Session()
546            dlg = ChooseDBTableDialog(self, self.application.Session())
547    
548            if dlg.ShowModal() == wxID_OK:
549                dbconn, dbtable, id_column, geo_column = dlg.GetTable()
550                try:
551                    title = str(dbtable)
552    
553                    # Chose the correct Interface for the database type
554                    store = session.OpenDBShapeStore(dbconn, dbtable,
555                                                     id_column = id_column,
556                                                     geometry_column = geo_column)
557                    layer = Layer(title, store)
558                except:
559                    # Some error occured while initializing the layer
560                    self.RunMessageBox(_("Add Layer from database"),
561                                       _("Can't open the database table '%s'")
562                                       % dbtable)
563                    return
564    
565                map = self.canvas.Map()
566    
567                has_layers = map.HasLayers()
568                map.AddLayer(layer)
569                if not has_layers:
570                    self.canvas.FitMapToWindow()
571    
572          dlg.Destroy()          dlg.Destroy()
573    
574      def RemoveLayer(self):      def RemoveLayer(self):
# Line 345  class MainWindow(wxFrame): Line 576  class MainWindow(wxFrame):
576          if layer is not None:          if layer is not None:
577              self.canvas.Map().RemoveLayer(layer)              self.canvas.Map().RemoveLayer(layer)
578    
579        def CanRemoveLayer(self):
580            """Return true if the currently selected layer can be deleted.
581    
582            If no layer is selected return False.
583    
584            The return value of this method determines whether the remove
585            layer command is sensitive in menu.
586            """
587            layer = self.current_layer()
588            if layer is not None:
589                return self.canvas.Map().CanRemoveLayer(layer)
590            return False
591    
592        def LayerToTop(self):
593            layer = self.current_layer()
594            if layer is not None:
595                self.canvas.Map().MoveLayerToTop(layer)
596    
597      def RaiseLayer(self):      def RaiseLayer(self):
598          layer = self.current_layer()          layer = self.current_layer()
599          if layer is not None:          if layer is not None:
600              self.canvas.Map().RaiseLayer(layer)              self.canvas.Map().RaiseLayer(layer)
601            
602      def LowerLayer(self):      def LowerLayer(self):
603          layer = self.current_layer()          layer = self.current_layer()
604          if layer is not None:          if layer is not None:
605              self.canvas.Map().LowerLayer(layer)              self.canvas.Map().LowerLayer(layer)
606    
607        def LayerToBottom(self):
608            layer = self.current_layer()
609            if layer is not None:
610                self.canvas.Map().MoveLayerToBottom(layer)
611    
612      def current_layer(self):      def current_layer(self):
613          """Return the currently selected layer.          """Return the currently selected layer.
614    
615          If no layer is selected, return None          If no layer is selected, return None
616          """          """
617          return self.interactor.SelectedLayer()          return self.canvas.SelectedLayer()
618    
619      def has_selected_layer(self):      def has_selected_layer(self):
620          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
621          return self.interactor.HasSelectedLayer()          return self.canvas.HasSelectedLayer()
   
     def choose_color(self):  
         """Run the color selection dialog and return the selected color.  
622    
623          If the user cancels, return None.      def has_selected_shape_layer(self):
624          """          """Return true if a shape layer is currently selected"""
625          dlg = wxColourDialog(self)          return isinstance(self.current_layer(), Layer)
626          color = None  
627          if dlg.ShowModal() == wxID_OK:      def has_selected_shapes(self):
628              data = dlg.GetColourData()          """Return true if a shape is currently selected"""
629              wxc = data.GetColour()          return self.canvas.HasSelectedShapes()
             color = Color(wxc.Red() / 255.0,  
                           wxc.Green() / 255.0,  
                           wxc.Blue() / 255.0)  
         dlg.Destroy()  
         return color  
630    
631      def LayerFillColor(self):      def HideLayer(self):
632          layer = self.current_layer()          layer = self.current_layer()
633          if layer is not None:          if layer is not None:
634              color = self.choose_color()              layer.SetVisible(False)
             if color is not None:  
                 layer.SetFill(color)  
635    
636      def LayerTransparentFill(self):      def ShowLayer(self):
637          layer = self.current_layer()          layer = self.current_layer()
638          if layer is not None:          if layer is not None:
639              layer.SetFill(None)              layer.SetVisible(True)
640    
641      def LayerOutlineColor(self):      def ToggleLayerVisibility(self):
642          layer = self.current_layer()          layer = self.current_layer()
643          if layer is not None:          layer.SetVisible(not layer.Visible())
             color = self.choose_color()  
             if color is not None:  
                 layer.SetStroke(color)  
644    
645      def LayerNoOutline(self):      def DuplicateLayer(self):
646            """Ceate a new layer above the selected layer with the same shapestore
647            """
648          layer = self.current_layer()          layer = self.current_layer()
649          if layer is not None:          if layer is not None and hasattr(layer, "ShapeStore"):
650              layer.SetStroke(None)              new_layer = Layer(_("Copy of `%s'") % layer.Title(),
651                                  layer.ShapeStore(),
652                                  projection = layer.GetProjection())
653                new_classification = copy.deepcopy(layer.GetClassification())
654                new_layer.SetClassification(new_classification)
655                self.Map().AddLayer(new_layer)
656    
657      def HideLayer(self):      def CanDuplicateLayer(self):
658            """Return whether the DuplicateLayer method can create a duplicate"""
659          layer = self.current_layer()          layer = self.current_layer()
660          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)  
661    
662      def LayerShowTable(self):      def LayerShowTable(self):
663            """
664            Present a TableView Window for the current layer.
665            In case the window is already open, bring it to the front.
666            In case, there is no active layer, do nothing.
667            In case, the layer has no ShapeStore, do nothing.
668            """
669          layer = self.current_layer()          layer = self.current_layer()
670          if layer is not None:          if layer is not None:
671              table = layer.table              if not hasattr(layer, "ShapeStore"):
672                    return
673                table = layer.ShapeStore().Table()
674              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
675              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
676              if dialog is None:              if dialog is None:
677                  dialog = tableview.TableFrame(self, self.interactor, name,                  dialog = tableview.LayerTableFrame(self, name,
678                                                "Table: %s" % layer.Title(),                                           _("Layer Table: %s") % layer.Title(),
679                                                layer, table)                                           layer, table)
680                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
681                  dialog.Show(true)                  dialog.Show(True)
682              else:              else:
683                  # FIXME: bring dialog to front here                  dialog.Raise()
684                  pass  
685        def MapProjection(self):
686    
687      def Projection(self):          name = "map_projection"
688          map = self.canvas.Map()          dialog = self.get_open_dialog(name)
689          proj = map.projection  
690          if proj is None:          if dialog is None:
691              proj4Dlg = proj4dialog.Proj4Dialog(NULL, None, map.BoundingBox())              map = self.canvas.Map()
692          else:              dialog = projdialog.ProjFrame(self, name,
693              proj4Dlg = proj4dialog.Proj4Dialog(NULL, map.projection.params,                       _("Map Projection: %s") % map.Title(), map)
694                                                 map.BoundingBox())              self.add_dialog(name, dialog)
695          if proj4Dlg.ShowModal() == wxID_OK:              dialog.Show()
696              params = proj4Dlg.GetParams()          dialog.Raise()
697              if params is not None:  
698                  proj = Projection(params)      def LayerProjection(self):
699    
700            layer = self.current_layer()
701    
702            name = "layer_projection" + str(id(layer))
703            dialog = self.get_open_dialog(name)
704    
705            if dialog is None:
706                map = self.canvas.Map()
707                dialog = projdialog.ProjFrame(self, name,
708                         _("Layer Projection: %s") % layer.Title(), layer)
709                self.add_dialog(name, dialog)
710                dialog.Show()
711            dialog.Raise()
712    
713        def LayerEditProperties(self):
714    
715            #
716            # the menu option for this should only be available if there
717            # is a current layer, so we don't need to check if the
718            # current layer is None
719            #
720    
721            layer = self.current_layer()
722            self.OpenLayerProperties(layer)
723    
724        def OpenLayerProperties(self, layer, group = None):
725            """
726            Open or raise the properties dialog.
727    
728            This method opens or raises the properties dialog for the
729            currently selected layer if one is defined for this layer
730            type.
731            """
732            name = "layer_properties" + str(id(layer))
733            self.OpenOrRaiseDialog(name, Classifier, layer, group = group)
734            
735        def LayerJoinTable(self):
736            layer = self.canvas.SelectedLayer()
737            if layer is not None:
738                dlg = JoinDialog(self, _("Join Layer with Table"),
739                                 self.application.session,
740                                 layer = layer)
741                dlg.ShowModal()
742    
743        def LayerUnjoinTable(self):
744            layer = self.canvas.SelectedLayer()
745            if layer is not None:
746                orig_store = layer.ShapeStore().OrigShapeStore()
747                if orig_store:
748                    layer.SetShapeStore(orig_store)
749    
750        def ShowLegend(self):
751            if not self.LegendShown():
752                self.ToggleLegend()
753    
754        def ToggleLegend(self):
755            """Show the legend if it's not shown otherwise hide it again"""
756            name = "legend"
757            dialog = self.FindRegisteredDock(name)
758    
759            if dialog is None:
760                dialog = self.CreateDock(name, -1, _("Legend"), wxLAYOUT_LEFT)
761                legend.LegendPanel(dialog, None, self)
762                dialog.Dock()
763                dialog.GetPanel().SetMap(self.Map())
764                dialog.Show()
765            else:
766                dialog.Show(not dialog.IsShown())
767    
768        def LegendShown(self):
769            """Return true iff the legend is currently open"""
770            dialog = self.FindRegisteredDock("legend")
771            return dialog is not None and dialog.IsShown()
772    
773        def TableOpen(self):
774            dlg = wxFileDialog(self, _("Open Table"),
775                               self.application.Path("data"), "",
776                               _("DBF Files (*.dbf)") + "|*.dbf|" +
777                               #_("CSV Files (*.csv)") + "|*.csv|" +
778                               _("All Files (*.*)") + "|*.*",
779                               wxOPEN)
780            if dlg.ShowModal() == wxID_OK:
781                filename = dlg.GetPath()
782                dlg.Destroy()
783                try:
784                    table = self.application.session.OpenTableFile(filename)
785                except IOError:
786                    # the layer couldn't be opened
787                    self.RunMessageBox(_("Open Table"),
788                                       _("Can't open the file '%s'.") % filename)
789              else:              else:
790                  proj = None                  self.ShowTableView(table)
791              map.SetProjection(proj)                  self.application.SetPath("data",filename)
792          proj4Dlg.Destroy()  
793        def TableClose(self):
794            tables = self.application.session.UnreferencedTables()
795    
796            lst = [(t.Title(), t) for t in tables]
797            lst.sort()
798            titles = [i[0] for i in lst]
799            dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"),
800                                         _("Close Table"), titles,
801                                         size = (400, 300),
802                                         style = wxDEFAULT_DIALOG_STYLE |
803                                                 wxRESIZE_BORDER)
804            if dlg.ShowModal() == wxID_OK:
805                for i in dlg.GetValue():
806                    self.application.session.RemoveTable(lst[i][1])
807    
808    
809        def TableShow(self):
810            """Offer a multi-selection dialog for tables to be displayed
811    
812            The windows for the selected tables are opened or brought to
813            the front.
814            """
815            tables = self.application.session.Tables()
816    
817            lst = [(t.Title(), t) for t in tables]
818            lst.sort()
819            titles = [i[0] for i in lst]
820            dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"),
821                                         _("Show Table"), titles,
822                                         size = (400,300),
823                                         style = wxDEFAULT_DIALOG_STYLE |
824                                                 wxRESIZE_BORDER)
825            if (dlg.ShowModal() == wxID_OK):
826                for i in dlg.GetValue():
827                    # XXX: if the table belongs to a layer, open a
828                    # LayerTableFrame instead of QueryTableFrame
829                    self.ShowTableView(lst[i][1])
830    
831        def TableJoin(self):
832            dlg = JoinDialog(self, _("Join Tables"), self.application.session)
833            dlg.ShowModal()
834    
835        def ShowTableView(self, table):
836            """Open a table view for the table and optionally"""
837            name = "table_view%d" % id(table)
838            dialog = self.get_open_dialog(name)
839            if dialog is None:
840                dialog = tableview.QueryTableFrame(self, name,
841                                                   _("Table: %s") % table.Title(),
842                                                   table)
843                self.add_dialog(name, dialog)
844                dialog.Show(True)
845            dialog.Raise()
846    
847        def TableRename(self):
848            """Let the user rename a table"""
849    
850            # First, let the user select a table
851            tables = self.application.session.Tables()
852            lst = [(t.Title(), t) for t in tables]
853            lst.sort()
854            titles = [i[0] for i in lst]
855            dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"),
856                                         _("Rename Table"), titles,
857                                         size = (400,300),
858                                         style = wxDEFAULT_DIALOG_STYLE |
859                                                 wxRESIZE_BORDER)
860            if (dlg.ShowModal() == wxID_OK):
861                to_rename = [lst[i][1] for i in dlg.GetValue()]
862                dlg.Destroy()
863            else:
864                to_rename = []
865    
866            # Second, let the user rename the layers
867            for table in to_rename:
868                dlg = wxTextEntryDialog(self, _("Table Title:"), _("Rename Table"),
869                                        table.Title())
870                try:
871                    if dlg.ShowModal() == wxID_OK:
872                        title = dlg.GetValue()
873                        if title != "":
874                            table.SetTitle(title)
875    
876                            # Make sure the session is marked as modified.
877                            # FIXME: This should be handled automatically,
878                            # but that requires more changes to the tables
879                            # than I have time for currently.
880                            self.application.session.changed()
881                finally:
882                    dlg.Destroy()
883    
884    
885      def ZoomInTool(self):      def ZoomInTool(self):
886          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
# Line 468  class MainWindow(wxFrame): Line 901  class MainWindow(wxFrame):
901      def FullExtent(self):      def FullExtent(self):
902          self.canvas.FitMapToWindow()          self.canvas.FitMapToWindow()
903    
904        def FullLayerExtent(self):
905            self.canvas.FitLayerToWindow(self.current_layer())
906    
907        def FullSelectionExtent(self):
908            self.canvas.FitSelectedToWindow()
909    
910        def ExportMap(self):
911            self.canvas.Export()
912    
913      def PrintMap(self):      def PrintMap(self):
914          self.canvas.Print()          self.canvas.Print()
915    
916      def identify_view_on_demand(self, layer, shape):      def RenameMap(self):
917            dlg = wxTextEntryDialog(self, _("Map Title:"), _("Rename Map"),
918                                    self.Map().Title())
919            if dlg.ShowModal() == wxID_OK:
920                title = dlg.GetValue()
921                if title != "":
922                    self.Map().SetTitle(title)
923    
924            dlg.Destroy()
925    
926        def RenameLayer(self):
927            """Let the user rename the currently selected layer"""
928            layer = self.current_layer()
929            if layer is not None:
930                dlg = wxTextEntryDialog(self, _("Layer Title:"), _("Rename Layer"),
931                                        layer.Title())
932                try:
933                    if dlg.ShowModal() == wxID_OK:
934                        title = dlg.GetValue()
935                        if title != "":
936                            layer.SetTitle(title)
937                finally:
938                    dlg.Destroy()
939    
940        def identify_view_on_demand(self, layer, shapes):
941            """Subscribed to the canvas' SHAPES_SELECTED message
942    
943            If the current tool is the identify tool, at least one shape is
944            selected and the identify dialog is not shown, show the dialog.
945            """
946            # If the selection has become empty we don't need to do
947            # anything. Otherwise it could happen that the dialog was popped
948            # up when the selection became empty, e.g. when a new selection
949            # is opened while the identify tool is active and dialog had
950            # been closed
951            if not shapes:
952                return
953    
954          name = "identify_view"          name = "identify_view"
955          if self.canvas.CurrentTool() == "IdentifyTool":          if self.canvas.CurrentTool() == "IdentifyTool":
956              if not self.dialog_open(name):              if not self.dialog_open(name):
957                  dialog = identifyview.IdentifyView(self, self.interactor, name)                  dialog = identifyview.IdentifyView(self, name)
958                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
959                  dialog.Show(true)                  dialog.Show(True)
960              else:              else:
961                  # FIXME: bring dialog to front?                  # FIXME: bring dialog to front?
962                  pass                  pass
963    
964        def title_changed(self, map):
965            """Subscribed to the canvas' TITLE_CHANGED messages"""
966            self.update_title()
967    
968        def update_title(self):
969            """Update the window's title according to it's current state.
970    
971            In this default implementation the title is 'Thuban - ' followed
972            by the map's title or simply 'Thuban' if there is not map.
973            Derived classes should override this method to get different
974            titles.
975    
976            This method is called automatically by other methods when the
977            title may have to change. For the methods implemented in this
978            class this usually only means that a different map has been set
979            or the current map's title has changed.
980            """
981            map = self.Map()
982            if map is not None:
983                title = _("Thuban - %s") % (map.Title(),)
984            else:
985                title = _("Thuban")
986            self.SetTitle(title)
987    
988    
989  #  #
990  # Define all the commands available in the main window  # Define all the commands available in the main window
991  #  #
# Line 489  class MainWindow(wxFrame): Line 993  class MainWindow(wxFrame):
993    
994  # Helper functions to define common command implementations  # Helper functions to define common command implementations
995  def call_method(context, methodname, *args):  def call_method(context, methodname, *args):
996      """Call the context's method methodname with args *args"""      """Call the mainwindow's method methodname with args *args"""
997      apply(getattr(context, methodname), args)      apply(getattr(context.mainwindow, methodname), args)
998    
999  def _method_command(name, title, method, helptext = "",  def _method_command(name, title, method, helptext = "",
1000                      icon = "", sensitive = None):                      icon = "", sensitive = None, checked = None):
1001      """Add a command implemented by a method of the context object"""      """Add a command implemented by a method of the mainwindow object"""
1002      registry.Add(Command(name, title, call_method, args=(method,),      registry.Add(Command(name, title, call_method, args=(method,),
1003                           helptext = helptext, icon = icon,                           helptext = helptext, icon = icon,
1004                           sensitive = sensitive))                           sensitive = sensitive, checked = checked))
1005    
1006    def make_check_current_tool(toolname):
1007        """Return a function that tests if the currently active tool is toolname
1008    
1009        The returned function can be called with the context and returns
1010        true iff the currently active tool's name is toolname. It's directly
1011        usable as the 'checked' callback of a command.
1012        """
1013        def check_current_tool(context, name=toolname):
1014            return context.mainwindow.canvas.CurrentTool() == name
1015        return check_current_tool
1016    
1017  def _tool_command(name, title, method, toolname, helptext = "",  def _tool_command(name, title, method, toolname, helptext = "",
1018                    icon = ""):                    icon = "", sensitive = None):
1019      """Add a tool command"""      """Add a tool command"""
1020      def check_current_tool(context, name=toolname):      registry.Add(ToolCommand(name, title, call_method, args=(method,),
1021          return context.canvas.CurrentTool() == name                               helptext = helptext, icon = icon,
1022      registry.Add(Command(name, title, call_method, args=(method,),                               checked = make_check_current_tool(toolname),
1023                           helptext = helptext, icon = icon,                               sensitive = sensitive))
                          checked = check_current_tool))  
1024    
1025  def _has_selected_layer(context):  def _has_selected_layer(context):
1026      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
1027      return context.has_selected_layer()      return context.mainwindow.has_selected_layer()
1028    
1029    def _has_selected_layer_visible(context):
1030        """Return true if a layer is selected in the context which is
1031        visible."""
1032        if context.mainwindow.has_selected_layer():
1033            layer = context.mainwindow.current_layer()
1034            if layer.Visible(): return True
1035        return False
1036    
1037    def _has_selected_shape_layer(context):
1038        """Return true if a shape layer is selected in the context"""
1039        return context.mainwindow.has_selected_shape_layer()
1040    
1041    def _has_selected_shapes(context):
1042        """Return true if a layer is selected in the context"""
1043        return context.mainwindow.has_selected_shapes()
1044    
1045    def _can_remove_layer(context):
1046        return context.mainwindow.CanRemoveLayer()
1047    
1048    def _has_tree_window_shown(context):
1049        """Return true if the tree window is shown"""
1050        return context.mainwindow.SessionTreeShown()
1051    
1052    def _has_visible_map(context):
1053        """Return true iff theres a visible map in the mainwindow.
1054    
1055        A visible map is a map with at least one visible layer."""
1056        map = context.mainwindow.Map()
1057        if map is not None:
1058            for layer in map.Layers():
1059                if layer.Visible():
1060                    return True
1061        return False
1062    
1063    def _has_legend_shown(context):
1064        """Return true if the legend window is shown"""
1065        return context.mainwindow.LegendShown()
1066    
1067    def _has_gdal_support(context):
1068        """Return True if the GDAL is available"""
1069        return Thuban.Model.resource.has_gdal_support()
1070    
1071    def _has_dbconnections(context):
1072        """Return whether the the session has database connections"""
1073        return context.session.HasDBConnections()
1074    
1075    def _has_postgis_support(context):
1076        return has_postgis_support()
1077    
1078    
1079  # File menu  # File menu
1080  _method_command("new_session", "&New Session", "NewSession")  _method_command("new_session", _("&New Session"), "NewSession",
1081  _method_command("open_session", "&Open Session", "OpenSession")                  helptext = _("Start a new session"))
1082  _method_command("save_session", "&Save Session", "SaveSession")  _method_command("open_session", _("&Open Session..."), "OpenSession",
1083  _method_command("save_session_as", "Save Session &As", "SaveSessionAs")                  helptext = _("Open a session file"))
1084  _method_command("show_session_tree", "Show Session &Tree", "ShowSessionTree")  _method_command("save_session", _("&Save Session"), "SaveSession",
1085  _method_command("exit", "&Exit", "Exit")                  helptext =_("Save this session to the file it was opened from"))
1086    _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs",
1087                    helptext = _("Save this session to a new file"))
1088    _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
1089                    checked = _has_tree_window_shown,
1090                    helptext = _("Toggle on/off the session tree analysis window"))
1091    _method_command("toggle_legend", _("Legend"), "ToggleLegend",
1092                    checked = _has_legend_shown,
1093                    helptext = _("Toggle Legend on/off"))
1094    _method_command("database_management", _("&Database Connections..."),
1095                    "DatabaseManagement",
1096                    sensitive = _has_postgis_support)
1097    _method_command("exit", _("E&xit"), "Exit",
1098                    helptext = _("Finish working with Thuban"))
1099    
1100  # Help menu  # Help menu
1101  _method_command("help_about", "&About", "About")  _method_command("help_about", _("&About..."), "About",
1102                    helptext = _("Info about Thuban authors, version and modules"))
1103    
1104    
1105  # Map menu  # Map menu
1106  _method_command("map_projection", "Pro&jection", "Projection")  _method_command("map_projection", _("Pro&jection..."), "MapProjection",
1107                    helptext = _("Set or change the map projection"))
1108    
1109  _tool_command("map_zoom_in_tool", "&Zoom in", "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
1110                helptext = "Switch to map-mode 'zoom-in'", icon = "zoom_in")                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
1111  _tool_command("map_zoom_out_tool", "Zoom &out", "ZoomOutTool", "ZoomOutTool",                sensitive = _has_visible_map)
1112                helptext = "Switch to map-mode 'zoom-out'", icon = "zoom_out")  _tool_command("map_zoom_out_tool", _("Zoom &out"), "ZoomOutTool", "ZoomOutTool",
1113  _tool_command("map_pan_tool", "&Pan", "PanTool", "PanTool",                helptext = _("Switch to map-mode 'zoom-out'"), icon = "zoom_out",
1114                helptext = "Switch to map-mode 'pan'", icon = "pan")                sensitive = _has_visible_map)
1115  _tool_command("map_identify_tool", "&Identify", "IdentifyTool", "IdentifyTool",  _tool_command("map_pan_tool", _("&Pan"), "PanTool", "PanTool",
1116                helptext = "Switch to map-mode 'identify'", icon = "identify")                helptext = _("Switch to map-mode 'pan'"), icon = "pan",
1117  _tool_command("map_label_tool", "&Label", "LabelTool", "LabelTool",                sensitive = _has_visible_map)
1118                helptext = "Add/Remove labels", icon = "label")  _tool_command("map_identify_tool", _("&Identify"), "IdentifyTool",
1119  _method_command("map_full_extent", "&Full extent", "FullExtent",                "IdentifyTool",
1120                 helptext = "Full Extent", icon = "fullextent")                helptext = _("Switch to map-mode 'identify'"), icon = "identify",
1121  _method_command("map_print", "Prin&t", "PrintMap", helptext = "Print the map")                sensitive = _has_visible_map)
1122    _tool_command("map_label_tool", _("&Label"), "LabelTool", "LabelTool",
1123                  helptext = _("Add/Remove labels"), icon = "label",
1124                  sensitive = _has_visible_map)
1125    _method_command("map_full_extent", _("&Full extent"), "FullExtent",
1126                   helptext = _("Zoom to the full map extent"), icon = "fullextent",
1127                  sensitive = _has_visible_map)
1128    _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",
1129                    helptext = _("Zoom to the full layer extent"),
1130                    icon = "fulllayerextent", sensitive = _has_selected_layer)
1131    _method_command("selected_full_extent", _("&Full selection extent"),
1132                    "FullSelectionExtent",
1133                    helptext = _("Zoom to the full selection extent"),
1134                    icon = "fullselextent", sensitive = _has_selected_shapes)
1135    _method_command("map_export", _("E&xport"), "ExportMap",
1136                    helptext = _("Export the map to file"))
1137    _method_command("map_print", _("Prin&t"), "PrintMap",
1138                    helptext = _("Print the map"))
1139    _method_command("map_rename", _("&Rename..."), "RenameMap",
1140                    helptext = _("Rename the map"))
1141    _method_command("layer_add", _("&Add Layer..."), "AddLayer",
1142                    helptext = _("Add a new layer to the map"))
1143    _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
1144                    helptext = _("Add a new image layer to the map"),
1145                    sensitive = _has_gdal_support)
1146    _method_command("layer_add_db", _("Add &Database Layer..."), "AddDBLayer",
1147                    helptext = _("Add a new database layer to active map"),
1148                    sensitive = _has_dbconnections)
1149    _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
1150                    helptext = _("Remove selected layer"),
1151                    sensitive = _can_remove_layer)
1152    
1153  # Layer menu  # Layer menu
1154  _method_command("layer_add", "&Add Layer", "AddLayer",  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
1155                  helptext = "Add a new layer to active map")                  sensitive = _has_selected_layer,
1156  _method_command("layer_remove", "&Remove Layer", "RemoveLayer",                  helptext = _("Specify projection for selected layer"))
1157                  helptext = "Remove selected layer(s)",  _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
1158                  sensitive = _has_selected_layer)                  helptext = _("Duplicate selected layer"),
1159  _method_command("layer_fill_color", "&Fill Color", "LayerFillColor",            sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
1160                  helptext = "Set the fill color of selected layer(s)",  _method_command("layer_rename", _("Re&name ..."), "RenameLayer",
1161                    helptext = _("Rename selected layer"),
1162                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1163  _method_command("layer_transparent_fill", "&Transparent Fill",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
1164                  "LayerTransparentFill",                  helptext = _("Raise selected layer"),
                 helptext = "Do not fill the selected layer(s)",  
1165                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1166  _method_command("layer_outline_color", "&Outline Color", "LayerOutlineColor",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
1167                  helptext = "Set the outline color of selected layer(s)",                  helptext = _("Lower selected layer"),
1168                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1169  _method_command("layer_no_outline", "&No Outline", "LayerNoOutline",  _method_command("layer_show", _("&Show"), "ShowLayer",
1170                  helptext = "Do not draw the outline of the selected layer(s)",                  helptext = _("Make selected layer visible"),
1171                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1172  _method_command("layer_raise", "&Raise", "RaiseLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
1173                  helptext = "Raise selected layer(s)",                  helptext = _("Make selected layer unvisible"),
1174                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1175  _method_command("layer_lower", "&Lower", "LowerLayer",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
1176                  helptext = "Lower selected layer(s)",                  helptext = _("Show the selected layer's table"),
1177                    sensitive = _has_selected_shape_layer)
1178    _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
1179                    sensitive = _has_selected_layer,
1180                    helptext = _("Edit the properties of the selected layer"))
1181    _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1182                    sensitive = _has_selected_shape_layer,
1183                    helptext = _("Join and attach a table to the selected layer"))
1184    
1185    # further layer methods:
1186    _method_command("layer_to_top", _("&Top"), "LayerToTop",
1187                    helptext = _("Put selected layer to the top"),
1188                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1189  _method_command("layer_show", "&Show", "ShowLayer",  _method_command("layer_to_bottom", _("&Bottom"), "LayerToBottom",
1190                  helptext = "Make selected layer(s) visible",                  helptext = _("Put selected layer to the bottom"),
1191                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1192  _method_command("layer_hide", "&Hide", "HideLayer",  _method_command("layer_visibility", _("&Visible"), "ToggleLayerVisibility",
1193                  helptext = "Make selected layer(s) unvisible",                  checked = _has_selected_layer_visible,
1194                  sensitive = _has_selected_layer)                  helptext = _("Toggle visibility of selected layer"),
 _method_command("layer_show_table", "Show Ta&ble", "LayerShowTable",  
                 helptext = "Show the selected layer's table",  
1195                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1196    
1197    def _can_unjoin(context):
1198        """Return whether the Layer/Unjoin command can be executed.
1199    
1200  # the menu structure      This is the case if a layer is selected and that layer has a
1201  main_menu = Menu("<main>", "<main>",      shapestore that has an original shapestore.
1202                   [Menu("file", "&File",      """
1203                         ["new_session", "open_session", None,      layer = context.mainwindow.SelectedLayer()
1204                          "save_session", "save_session_as", None,      if layer is None:
1205                          "show_session_tree", None,          return 0
1206                          "exit"]),      getstore = getattr(layer, "ShapeStore", None)
1207                    Menu("map", "&Map",      if getstore is not None:
1208                         ["layer_add", "layer_remove",          return getstore().OrigShapeStore() is not None
1209        else:
1210            return 0
1211    _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
1212                    sensitive = _can_unjoin,
1213                    helptext = _("Undo the last join operation"))
1214    
1215    
1216    def _has_tables(context):
1217        return bool(context.session.Tables())
1218    
1219    # Table menu
1220    _method_command("table_open", _("&Open..."), "TableOpen",
1221                    helptext = _("Open a DBF-table from a file"))
1222    _method_command("table_close", _("&Close..."), "TableClose",
1223           sensitive = lambda context: bool(context.session.UnreferencedTables()),
1224                    helptext = _("Close one or more tables from a list"))
1225    _method_command("table_rename", _("&Rename..."), "TableRename",
1226                    sensitive = _has_tables,
1227                    helptext = _("Rename one or more tables"))
1228    _method_command("table_show", _("&Show..."), "TableShow",
1229                    sensitive = _has_tables,
1230                    helptext = _("Show one or more tables in a dialog"))
1231    _method_command("table_join", _("&Join..."), "TableJoin",
1232                    sensitive = _has_tables,
1233                    helptext = _("Join two tables creating a new one"))
1234    
1235    #  Export only under Windows ...
1236    map_menu = ["layer_add", "layer_add_db", "rasterlayer_add", "layer_remove",
1237                          None,                          None,
1238                            "map_rename",
1239                          "map_projection",                          "map_projection",
1240                          None,                          None,
1241                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
1242                          "map_pan_tool", "map_identify_tool", "map_label_tool",                          "map_pan_tool",
                         None,  
1243                          "map_full_extent",                          "map_full_extent",
1244                            "layer_full_extent",
1245                            "selected_full_extent",
1246                            None,
1247                            "map_identify_tool", "map_label_tool",
1248                          None,                          None,
1249                          "map_print"]),                          "toggle_legend",
1250                    Menu("layer", "&Layer",                          None]
1251                         ["layer_fill_color", "layer_transparent_fill",  if wxPlatform == '__WXMSW__':
1252                          "layer_outline_color", "layer_no_outline",      map_menu.append("map_export")
1253    map_menu.append("map_print")
1254    
1255    # the menu structure
1256    main_menu = Menu("<main>", "<main>",
1257                     [Menu("file", _("&File"),
1258                           ["new_session", "open_session", None,
1259                            "save_session", "save_session_as", None,
1260                            "database_management", None,
1261                            "toggle_session_tree", None,
1262                            "exit"]),
1263                      Menu("map", _("&Map"), map_menu),
1264                      Menu("layer", _("&Layer"),
1265                           ["layer_rename", "layer_duplicate",
1266                          None,                          None,
1267                          "layer_raise", "layer_lower",                          "layer_raise", "layer_lower",
1268                          None,                          None,
1269                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
1270                          None,                          None,
1271                          "layer_show_table"]),                          "layer_projection",
1272                    Menu("help", "&Help",                          None,
1273                            "layer_show_table",
1274                            "layer_jointable",
1275                            "layer_unjointable",
1276                            None,
1277                            "layer_properties"]),
1278                      Menu("table", _("&Table"),
1279                           ["table_open", "table_close", "table_rename",
1280                           None,
1281                           "table_show",
1282                           None,
1283                           "table_join"]),
1284                      Menu("help", _("&Help"),
1285                         ["help_about"])])                         ["help_about"])])
1286    
1287  # the main toolbar  # the main toolbar
1288    
1289  main_toolbar = Menu("<toolbar>", "<toolbar>",  main_toolbar = Menu("<toolbar>", "<toolbar>",
1290                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",
1291                       "map_identify_tool", "map_label_tool", "map_full_extent"])                       "map_full_extent",
1292                         "layer_full_extent",
1293                         "selected_full_extent",
1294                         None,
1295                         "map_identify_tool", "map_label_tool"])
1296    

Legend:
Removed from v.191  
changed lines
  Added in v.2364

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26