/[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 314 by bh, Wed Sep 11 15:18:09 2002 UTC revision 911 by frank, Fri May 16 16:24:17 2003 UTC
# Line 1  Line 1 
1  # Copyright (C) 2001, 2002 by Intevation GmbH  # Copyright (C) 2001, 2002, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Jan-Oliver Wagner <[email protected]>  # Jan-Oliver Wagner <[email protected]>
4  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
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    __ThubanVersion__ = "0.2" #"$THUBAN_0_2$"
17    #__BuildDate__ = "$Date$"
18    
19  import os  import os
20    
21  from wxPython.wx import *  from wxPython.wx import *
22    
23  import Thuban  import Thuban
24    from Thuban import _
25  from Thuban.Model.session import create_empty_session  from Thuban.Model.session import create_empty_session
26  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer
27  from Thuban.Model.color import Color  from Thuban.Model.color import Color
# Line 26  import view Line 31  import view
31  import tree  import tree
32  import proj4dialog  import proj4dialog
33  import tableview, identifyview  import tableview, identifyview
34    from Thuban.UI.classifier import Classifier
35    import legend
36  from menu import Menu  from menu import Menu
37    
38  from context import Context  from context import Context
39  from command import registry, Command  from command import registry, Command, ToolCommand
40  from messages import SELECTED_SHAPE, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION
41    
42    from Thuban.UI.dock import DockFrame
43    from Thuban.UI.join import JoinDialog
44    
45    import resource
46    
47    import projdialog
48    
49    
 # the directory where the toolbar icons are stored  
 bitmapdir = os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Bitmaps")  
 bitmapext = ".xpm"  
50    
51    class MainWindow(DockFrame):
52    
53  class MainWindow(wxFrame):      # Some messages that can be subscribed/unsubscribed directly through
54        # the MapCanvas come in fact from other objects. This is a map to
55        # map those messages to the names of the instance variables they
56        # actually come from. This delegation is implemented in the
57        # Subscribe and unsubscribed methods
58        delegated_messages = {LAYER_SELECTED: "canvas",
59                              SHAPES_SELECTED: "canvas"}
60    
61        # Methods delegated to some instance variables. The delegation is
62        # implemented in the __getattr__ method.
63        delegated_methods = {"SelectLayer": "canvas",
64                             "SelectShapes": "canvas",
65                             "SelectedShapes": "canvas",
66                             }
67    
68      def __init__(self, parent, ID, title, application, interactor,      def __init__(self, parent, ID, title, application, interactor,
69                   initial_message = None, size = wxSize(-1, -1)):                   initial_message = None, size = wxSize(-1, -1)):
70          wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)          DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)
71            #wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size)
72    
73          self.application = application          self.application = application
         self.interactor = interactor  
74    
75          self.CreateStatusBar()          self.CreateStatusBar()
76          if initial_message:          if initial_message:
# Line 63  class MainWindow(wxFrame): Line 88  class MainWindow(wxFrame):
88          # call Realize to make sure that the tools appear.          # call Realize to make sure that the tools appear.
89          toolbar.Realize()          toolbar.Realize()
90    
91    
92          # Create the map canvas          # Create the map canvas
93          canvas = view.MapCanvas(self, -1, interactor)          canvas = view.MapCanvas(self, -1)
94          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)          canvas.Subscribe(VIEW_POSITION, self.view_position_changed)
95            canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand)
96          self.canvas = canvas          self.canvas = canvas
97    
98            self.SetMainWindow(self.canvas)
99    
100            self.SetAutoLayout(True)
101    
102          self.init_dialogs()          self.init_dialogs()
103    
104          interactor.Subscribe(SELECTED_SHAPE, self.identify_view_on_demand)          EVT_CLOSE(self, self._OnClose)
105    
106        def Subscribe(self, channel, *args):
107            """Subscribe a function to a message channel.
108    
109            If channel is one of the delegated messages call the appropriate
110            object's Subscribe method. Otherwise do nothing.
111            """
112            if channel in self.delegated_messages:
113                object = getattr(self, self.delegated_messages[channel])
114                object.Subscribe(channel, *args)
115            else:
116                print "Trying to subscribe to unsupported channel %s" % channel
117    
118        def Unsubscribe(self, channel, *args):
119            """Unsubscribe a function from a message channel.
120    
121            If channel is one of the delegated messages call the appropriate
122            object's Unsubscribe method. Otherwise do nothing.
123            """
124            if channel in self.delegated_messages:
125                object = getattr(self, self.delegated_messages[channel])
126                object.Unsubscribe(channel, *args)
127    
128        def __getattr__(self, attr):
129            """If attr is one of the delegated methods return that method
130    
131          EVT_CLOSE(self, self.OnClose)          Otherwise raise AttributeError.
132            """
133            if attr in self.delegated_methods:
134                return getattr(getattr(self, self.delegated_methods[attr]), attr)
135            raise AttributeError(attr)
136    
137      def init_ids(self):      def init_ids(self):
138          """Initialize the ids"""          """Initialize the ids"""
# Line 168  class MainWindow(wxFrame): Line 228  class MainWindow(wxFrame):
228                              command.IsCheckCommand())                              command.IsCheckCommand())
229                  self.bind_command_events(command, ID)                  self.bind_command_events(command, ID)
230              else:              else:
231                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
232    
233      def add_toolbar_command(self, toolbar, name):      def add_toolbar_command(self, toolbar, name):
234          """Add the command with name name to the toolbar toolbar.          """Add the command with name name to the toolbar toolbar.
# Line 183  class MainWindow(wxFrame): Line 243  class MainWindow(wxFrame):
243              command = registry.Command(name)              command = registry.Command(name)
244              if command is not None:              if command is not None:
245                  ID = self.get_id(name)                  ID = self.get_id(name)
246                  filename = os.path.join(bitmapdir, command.Icon()) + bitmapext                  bitmap = resource.GetBitmapResource(command.Icon(),
247                  bitmap = wxBitmap(filename, wxBITMAP_TYPE_XPM)                                                      wxBITMAP_TYPE_XPM)
248                  toolbar.AddTool(ID, bitmap,                  toolbar.AddTool(ID, bitmap,
249                                  shortHelpString = command.HelpText(),                                  shortHelpString = command.HelpText(),
250                                  isToggle = command.IsCheckCommand())                                  isToggle = command.IsCheckCommand())
251                  self.bind_command_events(command, ID)                  self.bind_command_events(command, ID)
252              else:              else:
253                  print "Unknown command %s" % name                  print _("Unknown command %s") % name
254    
255      def Context(self):      def Context(self):
256          """Return the context object for a command invoked from this window          """Return the context object for a command invoked from this window
# Line 203  class MainWindow(wxFrame): Line 263  class MainWindow(wxFrame):
263              command = registry.Command(name)              command = registry.Command(name)
264              command.Execute(self.Context())              command.Execute(self.Context())
265          else:          else:
266              print "Unknown command ID %d" % event.GetId()              print _("Unknown command ID %d") % event.GetId()
267    
268      def update_command_ui(self, event):      def update_command_ui(self, event):
269          #print "update_command_ui", self.id_to_name[event.GetId()]          #print "update_command_ui", self.id_to_name[event.GetId()]
270          context = self.Context()          context = self.Context()
271          command = registry.Command(self.id_to_name[event.GetId()])          command = registry.Command(self.id_to_name[event.GetId()])
272          if command is not None:          if command is not None:
273              event.Enable(command.Sensitive(context))              sensitive = command.Sensitive(context)
274                event.Enable(sensitive)
275                if command.IsTool() and not sensitive and command.Checked(context):
276                    # When a checked tool command is disabled deselect all
277                    # tools. Otherwise the tool would remain active but it
278                    # might lead to errors if the tools stays active. This
279                    # problem occurred in GREAT-ER and this fixes it, but
280                    # it's not clear to me whether this is really the best
281                    # way to do it (BH, 20021206).
282                    self.canvas.SelectTool(None)
283              event.SetText(command.DynText(context))              event.SetText(command.DynText(context))
284              if command.IsCheckCommand():              if command.IsCheckCommand():
285                  event.Check(command.Checked(context))                      event.Check(command.Checked(context))
286    
287      def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):      def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION):
288          """Run a modal message box with the given text, title and flags          """Run a modal message box with the given text, title and flags
289          and return the result"""          and return the result"""
290          dlg = wxMessageDialog(self, text, title, flags)          dlg = wxMessageDialog(self, text, title, flags)
291            dlg.CenterOnParent()
292          result = dlg.ShowModal()          result = dlg.ShowModal()
293          dlg.Destroy()          dlg.Destroy()
294          return result          return result
# Line 232  class MainWindow(wxFrame): Line 302  class MainWindow(wxFrame):
302    
303      def add_dialog(self, name, dialog):      def add_dialog(self, name, dialog):
304          if self.dialogs.has_key(name):          if self.dialogs.has_key(name):
305              raise RuntimeError("The Dialog named %s is already open" % name)              raise RuntimeError(_("The Dialog named %s is already open") % name)
306          self.dialogs[name] = dialog          self.dialogs[name] = dialog
307    
308      def dialog_open(self, name):      def dialog_open(self, name):
# Line 250  class MainWindow(wxFrame): Line 320  class MainWindow(wxFrame):
320              text = "(%10.10g, %10.10g)" % pos              text = "(%10.10g, %10.10g)" % pos
321          else:          else:
322              text = ""              text = ""
323            self.set_position_text(text)
324    
325        def set_position_text(self, text):
326            """Set the statusbar text showing the current position.
327    
328            By default the text is shown in field 0 of the status bar.
329            Override this method in derived classes to put it into a
330            different field of the statusbar.
331            """
332          self.SetStatusText(text)          self.SetStatusText(text)
333    
334      def save_modified_session(self, can_veto = 1):      def save_modified_session(self, can_veto = 1):
# Line 265  class MainWindow(wxFrame): Line 344  class MainWindow(wxFrame):
344              flags = wxYES_NO | wxICON_QUESTION              flags = wxYES_NO | wxICON_QUESTION
345              if can_veto:              if can_veto:
346                  flags = flags | wxCANCEL                  flags = flags | wxCANCEL
347              result = self.RunMessageBox("Exit",              result = self.RunMessageBox(_("Exit"),
348                                          ("The session has been modified."                                          _("The session has been modified."
349                                           " Do you want to save it?"),                                           " Do you want to save it?"),
350                                          flags)                                          flags)
351              if result == wxID_YES:              if result == wxID_YES:
# Line 275  class MainWindow(wxFrame): Line 354  class MainWindow(wxFrame):
354              result = wxID_NO              result = wxID_NO
355          return result          return result
356    
357        def prepare_new_session(self):
358            for d in self.dialogs.values():
359                if not isinstance(d, tree.SessionTreeView):
360                    d.Close()
361    
362      def NewSession(self):      def NewSession(self):
363          self.save_modified_session()          self.save_modified_session()
364            self.prepare_new_session()
365          self.application.SetSession(create_empty_session())          self.application.SetSession(create_empty_session())
366    
367      def OpenSession(self):      def OpenSession(self):
368          self.save_modified_session()          self.save_modified_session()
369          dlg = wxFileDialog(self, "Select a session file", ".", "",          dlg = wxFileDialog(self, _("Open Session"), ".", "",
370                             "*.thuban", wxOPEN)                             "Thuban Session File (*.thuban)|*.thuban", wxOPEN)
371          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
372                self.prepare_new_session()
373              self.application.OpenSession(dlg.GetPath())              self.application.OpenSession(dlg.GetPath())
374          dlg.Destroy()          dlg.Destroy()
375    
376      def SaveSession(self):      def SaveSession(self):
377          if self.application.session.filename == None:          if self.application.session.filename == None:
378              self.SaveSessionAs()              self.SaveSessionAs()
379          self.application.SaveSession()          else:
380                self.application.SaveSession()
381    
382      def SaveSessionAs(self):      def SaveSessionAs(self):
383          dlg = wxFileDialog(self, "Enter a filename for session", ".", "",          dlg = wxFileDialog(self, _("Save Session As"), ".", "",
384                             "*.thuban", wxOPEN)                             "Thuban Session File (*.thuban)|*.thuban",
385                               wxSAVE|wxOVERWRITE_PROMPT)
386          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
387              self.application.session.SetFilename(dlg.GetPath())              self.application.session.SetFilename(dlg.GetPath())
388              self.application.SaveSession()              self.application.SaveSession()
389          dlg.Destroy()          dlg.Destroy()
390    
391      def Exit(self):      def Exit(self):
392          self.Close(false)          self.Close(False)
393    
394      def OnClose(self, event):      def _OnClose(self, event):
395          result = self.save_modified_session(can_veto = event.CanVeto())          result = self.save_modified_session(can_veto = event.CanVeto())
396          if result == wxID_CANCEL:          if result == wxID_CANCEL:
397              event.Veto()              event.Veto()
# Line 312  class MainWindow(wxFrame): Line 400  class MainWindow(wxFrame):
400              # wx's destroy event, but that isn't implemented for wxGTK              # wx's destroy event, but that isn't implemented for wxGTK
401              # yet.              # yet.
402              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)
403                DockFrame._OnClose(self, event)
404              self.Destroy()              self.Destroy()
405    
406      def SetMap(self, map):      def SetMap(self, map):
407          self.canvas.SetMap(map)          self.canvas.SetMap(map)
408            self.__SetTitle(map.Title())
409    
410            dialog = self.FindRegisteredDock("legend")
411            if dialog is not None:
412                dialog.GetPanel().SetMap(self.Map())
413    
414      def Map(self):      def Map(self):
415          """Return the map displayed by this mainwindow"""          """Return the map displayed by this mainwindow"""
416    
417          return self.canvas.Map()          return self.canvas.Map()
418    
419      def ShowSessionTree(self):      def ToggleSessionTree(self):
420            """If the session tree is shown close it otherwise create a new tree"""
421          name = "session_tree"          name = "session_tree"
422          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
423          if dialog is None:          if dialog is None:
424              dialog = tree.SessionTreeView(self, self.application, name)              dialog = tree.SessionTreeView(self, self.application, name)
425              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
426              dialog.Show(true)              dialog.Show(True)
427          else:          else:
428              # FIXME: bring dialog to front here              dialog.Close()
429              pass  
430        def SessionTreeShown(self):
431            """Return true iff the session tree is currently shown"""
432            return self.get_open_dialog("session_tree") is not None
433    
434      def About(self):      def About(self):
435          self.RunMessageBox("About",          self.RunMessageBox(_("About"),
436                             ("Thuban is a program for\n"                             _("Thuban v%s\n"
437                                #"Build Date: %s\n"
438                                "\n"
439                                "Thuban is a program for\n"
440                              "exploring geographic data.\n"                              "exploring geographic data.\n"
441                              "Copyright (C) 2001 Intevation GmbH.\n"                              "Copyright (C) 2001-2003 Intevation GmbH.\n"
442                              "Thuban is licensed under the GPL"),                              "Thuban is licensed under the GNU GPL"
443                               % __ThubanVersion__), #__BuildDate__)),
444                             wxOK | wxICON_INFORMATION)                             wxOK | wxICON_INFORMATION)
445    
446      def AddLayer(self):      def AddLayer(self):
447          dlg = wxFileDialog(self, "Select a data file", ".", "", "*.*",          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",
448                             wxOPEN)                             wxOPEN)
449          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
450              filename = dlg.GetPath()              filename = dlg.GetPath()
451              title = os.path.splitext(os.path.basename(filename))[0]              title = os.path.splitext(os.path.basename(filename))[0]
452              layer = Layer(title, filename)              store = self.application.Session().OpenShapefile(filename)
453                layer = Layer(title, store)
454              map = self.canvas.Map()              map = self.canvas.Map()
455              has_layers = map.HasLayers()              has_layers = map.HasLayers()
456              try:              try:
457                  map.AddLayer(layer)                  map.AddLayer(layer)
458              except IOError:              except IOError:
459                  # the layer couldn't be opened                  # the layer couldn't be opened
460                  self.RunMessageBox("Add Layer",                  self.RunMessageBox(_("Add Layer"),
461                                     "Can't open the file '%s'." % filename)                                     _("Can't open the file '%s'.") % filename)
462              else:              else:
463                  if not has_layers:                  if not has_layers:
464                      # if we're adding a layer to an empty map, for the                      # if we're adding a layer to an empty map, fit the
465                      # new map to the window                      # new map to the window
466                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
467          dlg.Destroy()          dlg.Destroy()
# Line 370  class MainWindow(wxFrame): Line 474  class MainWindow(wxFrame):
474      def CanRemoveLayer(self):      def CanRemoveLayer(self):
475          """Return true if the currently selected layer can be deleted.          """Return true if the currently selected layer can be deleted.
476    
477          If no layer is selected return false.          If no layer is selected return False.
478    
479          The return value of this method determines whether the remove          The return value of this method determines whether the remove
480          layer command is sensitive in menu.          layer command is sensitive in menu.
# Line 378  class MainWindow(wxFrame): Line 482  class MainWindow(wxFrame):
482          layer = self.current_layer()          layer = self.current_layer()
483          if layer is not None:          if layer is not None:
484              return self.canvas.Map().CanRemoveLayer(layer)              return self.canvas.Map().CanRemoveLayer(layer)
485          return 0          return False
486    
487      def RaiseLayer(self):      def RaiseLayer(self):
488          layer = self.current_layer()          layer = self.current_layer()
# Line 395  class MainWindow(wxFrame): Line 499  class MainWindow(wxFrame):
499    
500          If no layer is selected, return None          If no layer is selected, return None
501          """          """
502          return self.interactor.SelectedLayer()          return self.canvas.SelectedLayer()
503    
504      def has_selected_layer(self):      def has_selected_layer(self):
505          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
506          return self.interactor.HasSelectedLayer()          return self.canvas.HasSelectedLayer()
507    
508      def choose_color(self):      def has_selected_shapes(self):
509          """Run the color selection dialog and return the selected color.          """Return true if a shape is currently selected"""
510            return self.canvas.HasSelectedShapes()
         If the user cancels, return None.  
         """  
         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):  
         layer = self.current_layer()  
         if layer is not None:  
             layer.SetFill(None)  
   
     def LayerOutlineColor(self):  
         layer = self.current_layer()  
         if layer is not None:  
             color = self.choose_color()  
             if color is not None:  
                 layer.SetStroke(color)  
   
     def LayerNoOutline(self):  
         layer = self.current_layer()  
         if layer is not None:  
             layer.SetStroke(None)  
511    
512      def HideLayer(self):      def HideLayer(self):
513          layer = self.current_layer()          layer = self.current_layer()
# Line 458  class MainWindow(wxFrame): Line 526  class MainWindow(wxFrame):
526              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
527              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
528              if dialog is None:              if dialog is None:
529                  dialog = tableview.LayerTableFrame(self, self.interactor, name,                  dialog = tableview.LayerTableFrame(self, name,
530                                                     "Table: %s" % layer.Title(),                                                 _("Table: %s") % layer.Title(),
531                                                     layer, table)                                                     layer, table)
532                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
533                  dialog.Show(true)                  dialog.Show(true)
# Line 467  class MainWindow(wxFrame): Line 535  class MainWindow(wxFrame):
535                  # FIXME: bring dialog to front here                  # FIXME: bring dialog to front here
536                  pass                  pass
537    
538      def Projection(self):      def MapProjection(self):
539          map = self.canvas.Map()  
540          proj = map.projection          name = "map_projection"
541          if proj is None:          dialog = self.get_open_dialog(name)
542              proj4Dlg = proj4dialog.Proj4Dialog(NULL, None, map.BoundingBox())  
543            if dialog is None:
544                map = self.canvas.Map()
545                dialog = projdialog.ProjFrame(self, name,
546                         _("Map Projection: %s") % map.Title(), map)
547                self.add_dialog(name, dialog)
548                dialog.Show()
549            dialog.Raise()
550    
551        def LayerProjection(self):
552    
553            layer = self.current_layer()
554    
555            name = "layer_projection" + str(id(layer))
556            dialog = self.get_open_dialog(name)
557    
558            if dialog is None:
559                map = self.canvas.Map()
560                dialog = projdialog.ProjFrame(self, name,
561                         _("Layer Projection: %s") % layer.Title(), layer)
562                self.add_dialog(name, dialog)
563                dialog.Show()
564            dialog.Raise()
565    
566        def LayerEditProperties(self):
567    
568            #
569            # the menu option for this should only be available if there
570            # is a current layer, so we don't need to check if the
571            # current layer is None
572            #
573    
574            layer = self.current_layer()
575            self.OpenLayerProperties(layer)
576    
577        def OpenLayerProperties(self, layer, group = None):
578            name = "layer_properties" + str(id(layer))
579            dialog = self.get_open_dialog(name)
580    
581            if dialog is None:
582                dialog = Classifier(self, name, layer, group)
583                self.add_dialog(name, dialog)
584                dialog.Show()
585            dialog.Raise()
586    
587        def LayerJoinTable(self):
588            print "LayerJoinTable"
589    
590        def LayerUnjoinTable(self):
591            print "LayerUnjoinTable"
592    
593        def ShowLegend(self):
594            if not self.LegendShown():
595                self.ToggleLegend()
596    
597        def ToggleLegend(self):
598            """Show the legend if it's not shown otherwise hide it again"""
599            name = "legend"
600            dialog = self.FindRegisteredDock(name)
601    
602            if dialog is None:
603                dialog = self.CreateDock(name, -1, _("Legend"), wxLAYOUT_LEFT)
604                legend.LegendPanel(dialog, None, self)
605                dialog.Dock()
606                dialog.GetPanel().SetMap(self.Map())
607                dialog.Show()
608          else:          else:
609              proj4Dlg = proj4dialog.Proj4Dialog(NULL, map.projection.params,              dialog.Show(not dialog.IsShown())
610                                                 map.BoundingBox())  
611          if proj4Dlg.ShowModal() == wxID_OK:      def LegendShown(self):
612              params = proj4Dlg.GetParams()          """Return true iff the legend is currently open"""
613              if params is not None:          dialog = self.FindRegisteredDock("legend")
614                  proj = Projection(params)          return dialog is not None and dialog.IsShown()
615              else:  
616                  proj = None      def TableOpen(self):
617              map.SetProjection(proj)          print "TableOpen"
618          proj4Dlg.Destroy()          dlg = wxFileDialog(self, _("Open Table"), ".", "",
619                               "DBF Files (*.dbf)|*.dbf|" +
620                               "CSV Files (*.csv)|*.csv|" +
621                               "All Files (*.*)|*.*",
622                               wxOPEN)
623            if dlg.ShowModal() == wxID_OK:
624                #self.application.session.OpenTable(dlg.GetPath())
625                pass
626    
627            dlg.Destroy()
628    
629        def TableClose(self):
630            print "TableClose"
631    
632        def TableShow(self):
633            print "TableShow"
634    
635        def TableHide(self):
636            print "TableHide"
637    
638        def TableJoin(self):
639            print "TableJoin"
640            dlg = JoinDialog(self, _("Join Tables"), self.application.session)
641            if dlg.ShowModal() == wxID_OK:
642                print "OK"
643    
644      def ZoomInTool(self):      def ZoomInTool(self):
645          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
# Line 503  class MainWindow(wxFrame): Line 660  class MainWindow(wxFrame):
660      def FullExtent(self):      def FullExtent(self):
661          self.canvas.FitMapToWindow()          self.canvas.FitMapToWindow()
662    
663        def FullLayerExtent(self):
664            self.canvas.FitLayerToWindow(self.current_layer())
665    
666        def FullSelectionExtent(self):
667            self.canvas.FitSelectedToWindow()
668    
669        def ExportMap(self):
670            self.canvas.Export()
671    
672      def PrintMap(self):      def PrintMap(self):
673          self.canvas.Print()          self.canvas.Print()
674    
675      def identify_view_on_demand(self, layer, shape):      def RenameMap(self):
676            dlg = wxTextEntryDialog(self, "Map Title: ", "Rename Map",
677                                    self.Map().Title())
678            if dlg.ShowModal() == wxID_OK:
679                title = dlg.GetValue()
680                if title != "":
681                    self.Map().SetTitle(title)
682                    self.__SetTitle(title)
683    
684            dlg.Destroy()
685    
686        def identify_view_on_demand(self, layer, shapes):
687            """Subscribed to the canvas' SHAPES_SELECTED message
688    
689            If the current tool is the identify tool, at least one shape is
690            selected and the identify dialog is not shown, show the dialog.
691            """
692            # If the selection has become empty we don't need to do
693            # anything. Otherwise it could happen that the dialog was popped
694            # up when the selection became empty, e.g. when a new selection
695            # is opened while the identify tool is active and dialog had
696            # been closed
697            if not shapes:
698                return
699    
700          name = "identify_view"          name = "identify_view"
701          if self.canvas.CurrentTool() == "IdentifyTool":          if self.canvas.CurrentTool() == "IdentifyTool":
702              if not self.dialog_open(name):              if not self.dialog_open(name):
703                  dialog = identifyview.IdentifyView(self, self.interactor, name)                  dialog = identifyview.IdentifyView(self, name)
704                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
705                  dialog.Show(true)                  dialog.Show(True)
706              else:              else:
707                  # FIXME: bring dialog to front?                  # FIXME: bring dialog to front?
708                  pass                  pass
709    
710        def __SetTitle(self, title):
711            self.SetTitle("Thuban - " + title)
712    
713  #  #
714  # Define all the commands available in the main window  # Define all the commands available in the main window
715  #  #
# Line 528  def call_method(context, methodname, *ar Line 721  def call_method(context, methodname, *ar
721      apply(getattr(context.mainwindow, methodname), args)      apply(getattr(context.mainwindow, methodname), args)
722    
723  def _method_command(name, title, method, helptext = "",  def _method_command(name, title, method, helptext = "",
724                      icon = "", sensitive = None):                      icon = "", sensitive = None, checked = None):
725      """Add a command implemented by a method of the mainwindow object"""      """Add a command implemented by a method of the mainwindow object"""
726      registry.Add(Command(name, title, call_method, args=(method,),      registry.Add(Command(name, title, call_method, args=(method,),
727                           helptext = helptext, icon = icon,                           helptext = helptext, icon = icon,
728                           sensitive = sensitive))                           sensitive = sensitive, checked = checked))
729    
730  def make_check_current_tool(toolname):  def make_check_current_tool(toolname):
731      """Return a function that tests if the currently active tool is toolname      """Return a function that tests if the currently active tool is toolname
# Line 548  def make_check_current_tool(toolname): Line 741  def make_check_current_tool(toolname):
741  def _tool_command(name, title, method, toolname, helptext = "",  def _tool_command(name, title, method, toolname, helptext = "",
742                    icon = "", sensitive = None):                    icon = "", sensitive = None):
743      """Add a tool command"""      """Add a tool command"""
744      registry.Add(Command(name, title, call_method, args=(method,),      registry.Add(ToolCommand(name, title, call_method, args=(method,),
745                           helptext = helptext, icon = icon,                               helptext = helptext, icon = icon,
746                           checked = make_check_current_tool(toolname),                               checked = make_check_current_tool(toolname),
747                           sensitive = sensitive))                               sensitive = sensitive))
748    
749  def _has_selected_layer(context):  def _has_selected_layer(context):
750      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
751      return context.mainwindow.has_selected_layer()      return context.mainwindow.has_selected_layer()
752    
753    def _has_selected_shapes(context):
754        """Return true if a layer is selected in the context"""
755        return context.mainwindow.has_selected_shapes()
756    
757  def _can_remove_layer(context):  def _can_remove_layer(context):
758      return context.mainwindow.CanRemoveLayer()      return context.mainwindow.CanRemoveLayer()
759    
760  def _has_tree_window_shown(context):  def _has_tree_window_shown(context):
761      """Return true if the tree window is shown"""      """Return true if the tree window is shown"""
762      return context.mainwindow.get_open_dialog("session_tree") is None      return context.mainwindow.SessionTreeShown()
763    
764  def _has_visible_map(context):  def _has_visible_map(context):
765      """Return true iff theres a visible map in the mainwindow.      """Return true iff theres a visible map in the mainwindow.
# Line 575  def _has_visible_map(context): Line 772  def _has_visible_map(context):
772                  return 1                  return 1
773      return 0      return 0
774    
775    def _has_legend_shown(context):
776        """Return true if the legend window is shown"""
777        return context.mainwindow.LegendShown()
778    
779    
780  # File menu  # File menu
781  _method_command("new_session", "&New Session", "NewSession")  _method_command("new_session", _("&New Session"), "NewSession")
782  _method_command("open_session", "&Open Session", "OpenSession")  _method_command("open_session", _("&Open Session..."), "OpenSession")
783  _method_command("save_session", "&Save Session", "SaveSession")  _method_command("save_session", _("&Save Session"), "SaveSession")
784  _method_command("save_session_as", "Save Session &As", "SaveSessionAs")  _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs")
785  _method_command("show_session_tree", "Show Session &Tree", "ShowSessionTree",  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
786                  sensitive = _has_tree_window_shown)                  checked = _has_tree_window_shown)
787  _method_command("exit", "E&xit", "Exit")  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
788                    checked = _has_legend_shown)
789    _method_command("exit", _("E&xit"), "Exit")
790    
791  # Help menu  # Help menu
792  _method_command("help_about", "&About", "About")  _method_command("help_about", _("&About..."), "About")
793    
794    
795  # Map menu  # Map menu
796  _method_command("map_projection", "Pro&jection", "Projection")  _method_command("map_projection", _("Pro&jection..."), "MapProjection")
797    
798  _tool_command("map_zoom_in_tool", "&Zoom in", "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
799                helptext = "Switch to map-mode 'zoom-in'", icon = "zoom_in",                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
800                sensitive = _has_visible_map)                sensitive = _has_visible_map)
801  _tool_command("map_zoom_out_tool", "Zoom &out", "ZoomOutTool", "ZoomOutTool",  _tool_command("map_zoom_out_tool", _("Zoom &out"), "ZoomOutTool", "ZoomOutTool",
802                helptext = "Switch to map-mode 'zoom-out'", icon = "zoom_out",                helptext = _("Switch to map-mode 'zoom-out'"), icon = "zoom_out",
803                sensitive = _has_visible_map)                sensitive = _has_visible_map)
804  _tool_command("map_pan_tool", "&Pan", "PanTool", "PanTool",  _tool_command("map_pan_tool", _("&Pan"), "PanTool", "PanTool",
805                helptext = "Switch to map-mode 'pan'", icon = "pan",                helptext = _("Switch to map-mode 'pan'"), icon = "pan",
806                sensitive = _has_visible_map)                sensitive = _has_visible_map)
807  _tool_command("map_identify_tool", "&Identify", "IdentifyTool", "IdentifyTool",  _tool_command("map_identify_tool", _("&Identify"), "IdentifyTool",
808                helptext = "Switch to map-mode 'identify'", icon = "identify",                "IdentifyTool",
809                  helptext = _("Switch to map-mode 'identify'"), icon = "identify",
810                sensitive = _has_visible_map)                sensitive = _has_visible_map)
811  _tool_command("map_label_tool", "&Label", "LabelTool", "LabelTool",  _tool_command("map_label_tool", _("&Label"), "LabelTool", "LabelTool",
812                helptext = "Add/Remove labels", icon = "label",                helptext = _("Add/Remove labels"), icon = "label",
813                sensitive = _has_visible_map)                sensitive = _has_visible_map)
814  _method_command("map_full_extent", "&Full extent", "FullExtent",  _method_command("map_full_extent", _("&Full extent"), "FullExtent",
815                 helptext = "Full Extent", icon = "fullextent",                 helptext = _("Full Extent"), icon = "fullextent",
816                sensitive = _has_visible_map)                sensitive = _has_visible_map)
817  _method_command("map_print", "Prin&t", "PrintMap", helptext = "Print the map")  _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",
818                   helptext = _("Full Layer Extent"), icon = "fulllayerextent",
819                  sensitive = _has_selected_layer)
820    _method_command("selected_full_extent", _("&Full selection extent"), "FullSelectionExtent",
821                   helptext = _("Full Selection Extent"), icon = "fullselextent",
822                  sensitive = _has_selected_shapes)
823    _method_command("map_export", _("E&xport"), "ExportMap",
824                        helptext = _("Export the map to file"))
825    _method_command("map_print", _("Prin&t"), "PrintMap",
826                    helptext = _("Print the map"))
827    _method_command("map_rename", _("&Rename..."), "RenameMap",
828                    helptext = _("Rename the map"))
829    _method_command("layer_add", _("&Add Layer..."), "AddLayer",
830                    helptext = _("Add a new layer to active map"))
831    _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
832                    helptext = _("Remove selected layer(s)"),
833                    sensitive = _can_remove_layer)
834    
835  # Layer menu  # Layer menu
836  _method_command("layer_add", "&Add Layer", "AddLayer",  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
                 helptext = "Add a new layer to active map")  
 _method_command("layer_remove", "&Remove Layer", "RemoveLayer",  
                 helptext = "Remove selected layer(s)",  
                 sensitive = _can_remove_layer)  
 _method_command("layer_fill_color", "&Fill Color", "LayerFillColor",  
                 helptext = "Set the fill color of selected layer(s)",  
837                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
838  _method_command("layer_transparent_fill", "&Transparent Fill",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
839                  "LayerTransparentFill",                  helptext = _("Raise selected layer(s)"),
                 helptext = "Do not fill the selected layer(s)",  
840                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
841  _method_command("layer_outline_color", "&Outline Color", "LayerOutlineColor",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
842                  helptext = "Set the outline color of selected layer(s)",                  helptext = _("Lower selected layer(s)"),
843                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
844  _method_command("layer_no_outline", "&No Outline", "LayerNoOutline",  _method_command("layer_show", _("&Show"), "ShowLayer",
845                  helptext = "Do not draw the outline of the selected layer(s)",                  helptext = _("Make selected layer(s) visible"),
846                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
847  _method_command("layer_raise", "&Raise", "RaiseLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
848                  helptext = "Raise selected layer(s)",                  helptext = _("Make selected layer(s) unvisible"),
849                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
850  _method_command("layer_lower", "&Lower", "LowerLayer",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
851                  helptext = "Lower selected layer(s)",                  helptext = _("Show the selected layer's table"),
852                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
853  _method_command("layer_show", "&Show", "ShowLayer",  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
                 helptext = "Make selected layer(s) visible",  
854                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
855  _method_command("layer_hide", "&Hide", "HideLayer",  _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
                 helptext = "Make selected layer(s) unvisible",  
856                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
857  _method_command("layer_show_table", "Show Ta&ble", "LayerShowTable",  _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
                 helptext = "Show the selected layer's table",  
858                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
859    
860    # Table menu
861    _method_command("table_open", _("&Open..."), "TableOpen")
862    _method_command("table_close", _("&Close"), "TableClose")
863    _method_command("table_show", _("&Show"), "TableShow")
864    _method_command("table_hide", _("&Hide"), "TableHide")
865    _method_command("table_join", _("&Join..."), "TableJoin")
866    
867  # the menu structure  #  Export only under Windows ...
868  main_menu = Menu("<main>", "<main>",  map_menu = ["layer_add", "layer_remove", "map_rename",
                  [Menu("file", "&File",  
                        ["new_session", "open_session", None,  
                         "save_session", "save_session_as", None,  
                         "show_session_tree", None,  
                         "exit"]),  
                   Menu("map", "&Map",  
                        ["layer_add", "layer_remove",  
869                          None,                          None,
870                          "map_projection",                          "map_projection",
871                          None,                          None,
872                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
873                          "map_pan_tool", "map_identify_tool", "map_label_tool",                          "map_pan_tool",
874                          None,                          "map_full_extent",
875                          "map_full_extent",                          "layer_full_extent",
876                            "selected_full_extent",
877                          None,                          None,
878                          "map_print"]),                          "map_identify_tool", "map_label_tool",
                   Menu("layer", "&Layer",  
                        ["layer_fill_color", "layer_transparent_fill",  
                         "layer_outline_color", "layer_no_outline",  
879                          None,                          None,
880                          "layer_raise", "layer_lower",                          "toggle_legend",
881                            None]
882    if wxPlatform == '__WXMSW__':
883        map_menu.append("map_export")
884    map_menu.append("map_print")
885    
886    # the menu structure
887    main_menu = Menu("<main>", "<main>",
888                     [Menu("file", _("&File"),
889                           ["new_session", "open_session", None,
890                            "save_session", "save_session_as", None,
891                            "toggle_session_tree", None,
892                            "exit"]),
893                      Menu("map", _("&Map"), map_menu),
894                      Menu("layer", _("&Layer"),
895                            ["layer_raise", "layer_lower",
896                          None,                          None,
897                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
898                          None,                          None,
899                          "layer_show_table"]),                          "layer_projection",
900                    Menu("help", "&Help",                          None,
901                            "layer_show_table",
902                            "layer_jointable",
903                            "layer_unjointable",
904                            None,
905                            "layer_properties"]),
906                      Menu("table", _("&Table"),
907                           ["table_open", "table_close",
908                           None,
909                           "table_show", "table_hide",
910                           None,
911                           "table_join"]),
912                      Menu("help", _("&Help"),
913                         ["help_about"])])                         ["help_about"])])
914    
915  # the main toolbar  # the main toolbar
916    
917  main_toolbar = Menu("<toolbar>", "<toolbar>",  main_toolbar = Menu("<toolbar>", "<toolbar>",
918                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",
919                       "map_identify_tool", "map_label_tool", "map_full_extent"])                       "map_full_extent",
920                         "layer_full_extent",
921                         "selected_full_extent",
922                         None,
923                         "map_identify_tool", "map_label_tool"])

Legend:
Removed from v.314  
changed lines
  Added in v.911

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26