/[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 622 by bh, Mon Apr 7 10:54:32 2003 UTC revision 1644 by bh, Mon Aug 25 12:44:55 2003 UTC
# Line 2  Line 2 
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  __ThubanVersion__ = "0.2" #"$THUBAN_0_2$"  # $Id$
 #__BuildDate__ = "$Date$"  
17    
18  import os  import os
19    import copy
20    
21  from wxPython.wx import *  from wxPython.wx import *
22    from wxPython.wx import __version__ as wxPython_version
23    
24  import Thuban  import Thuban
25    import Thuban.version
26    
27  from Thuban import _  from Thuban import _
28  from Thuban.Model.session import create_empty_session  from Thuban.Model.session import create_empty_session
29  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer, RasterLayer
30  from Thuban.Model.color import Color  from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support
31  from Thuban.Model.proj import Projection  # XXX: replace this by
32    # from wxPython.lib.dialogs import wxMultipleChoiceDialog
33    # when Thuban does not support wxPython 2.4.0 any more.
34    from Thuban.UI.multiplechoicedialog import wxMultipleChoiceDialog
35    
36  import view  import view
37  import tree  import tree
 import proj4dialog  
38  import tableview, identifyview  import tableview, identifyview
39  import classifier  from Thuban.UI.classifier import Classifier
40  import legend  import legend
41  from menu import Menu  from menu import Menu
42    
43  from context import Context  from context import Context
44  from command import registry, Command, ToolCommand  from command import registry, Command, ToolCommand
45  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, DOCKABLE_DOCKED, DOCKABLE_UNDOCKED, DOCKABLE_CLOSED  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, \
46         MAP_REPLACED
47  from Thuban.UI.dock import DockableWindow, DockFrame, DockPanel  from about import About
48    
49    from Thuban.UI.dock import DockFrame
50  # the directory where the toolbar icons are stored  from Thuban.UI.join import JoinDialog
51  bitmapdir = os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Bitmaps")  from Thuban.UI.dbdialog import DBFrame, ChooseDBTableDialog
52  bitmapext = ".xpm"  import resource
53    import Thuban.Model.resource
54    
55  ID_WINDOW_LEGEND = 4001  import projdialog
 ID_WINDOW_CANVAS = 4002  
56    
57    
58  class MainWindow(DockFrame):  class MainWindow(DockFrame):
# Line 57  class MainWindow(DockFrame): Line 63  class MainWindow(DockFrame):
63      # actually come from. This delegation is implemented in the      # actually come from. This delegation is implemented in the
64      # Subscribe and unsubscribed methods      # Subscribe and unsubscribed methods
65      delegated_messages = {LAYER_SELECTED: "canvas",      delegated_messages = {LAYER_SELECTED: "canvas",
66                            SHAPES_SELECTED: "canvas"}                            SHAPES_SELECTED: "canvas",
67                              MAP_REPLACED: "canvas"}
68    
69      # Methods delegated to some instance variables. The delegation is      # Methods delegated to some instance variables. The delegation is
70      # implemented in the __getattr__ method.      # implemented in the __getattr__ method.
71      delegated_methods = {"SelectLayer": "canvas",      delegated_methods = {"SelectLayer": "canvas",
72                           "SelectShapes": "canvas",                           "SelectShapes": "canvas",
73                             "SelectedLayer": "canvas",
74                             "SelectedShapes": "canvas",
75                           }                           }
76    
77      def __init__(self, parent, ID, title, application, interactor,      def __init__(self, parent, ID, title, application, interactor,
# Line 101  class MainWindow(DockFrame): Line 110  class MainWindow(DockFrame):
110    
111          self.init_dialogs()          self.init_dialogs()
112    
113          EVT_CLOSE(self, self._OnClose)          self.ShowLegend()
114    
115            EVT_CLOSE(self, self.OnClose)
116    
117      def Subscribe(self, channel, *args):      def Subscribe(self, channel, *args):
118          """Subscribe a function to a message channel.          """Subscribe a function to a message channel.
# Line 243  class MainWindow(DockFrame): Line 254  class MainWindow(DockFrame):
254              command = registry.Command(name)              command = registry.Command(name)
255              if command is not None:              if command is not None:
256                  ID = self.get_id(name)                  ID = self.get_id(name)
257                  filename = os.path.join(bitmapdir, command.Icon()) + bitmapext                  bitmap = resource.GetBitmapResource(command.Icon(),
258                  bitmap = wxBitmap(filename, wxBITMAP_TYPE_XPM)                                                      wxBITMAP_TYPE_XPM)
259                  toolbar.AddTool(ID, bitmap,                  toolbar.AddTool(ID, bitmap,
260                                  shortHelpString = command.HelpText(),                                  shortHelpString = command.HelpText(),
261                                  isToggle = command.IsCheckCommand())                                  isToggle = command.IsCheckCommand())
# Line 354  class MainWindow(DockFrame): Line 365  class MainWindow(DockFrame):
365              result = wxID_NO              result = wxID_NO
366          return result          return result
367    
     def prepare_new_session(self):  
         for d in self.dialogs.values():  
             if not isinstance(d, tree.SessionTreeView):  
                 d.Close()  
   
368      def NewSession(self):      def NewSession(self):
369          self.save_modified_session()          if self.save_modified_session() != wxID_CANCEL:
370          self.prepare_new_session()              self.application.SetSession(create_empty_session())
         self.application.SetSession(create_empty_session())  
371    
372      def OpenSession(self):      def OpenSession(self):
373          self.save_modified_session()          if self.save_modified_session() != wxID_CANCEL:
374          dlg = wxFileDialog(self, _("Open Session"), ".", "", "*.thuban", wxOPEN)              dlg = wxFileDialog(self, _("Open Session"), ".", "",
375          if dlg.ShowModal() == wxID_OK:                                 "Thuban Session File (*.thuban)|*.thuban",
376              self.prepare_new_session()                                 wxOPEN)
377              self.application.OpenSession(dlg.GetPath())              if dlg.ShowModal() == wxID_OK:
378          dlg.Destroy()                  self.application.OpenSession(dlg.GetPath())
379                dlg.Destroy()
380    
381      def SaveSession(self):      def SaveSession(self):
382          if self.application.session.filename == None:          if self.application.session.filename == None:
# Line 380  class MainWindow(DockFrame): Line 386  class MainWindow(DockFrame):
386    
387      def SaveSessionAs(self):      def SaveSessionAs(self):
388          dlg = wxFileDialog(self, _("Save Session As"), ".", "",          dlg = wxFileDialog(self, _("Save Session As"), ".", "",
389                             "*.thuban", wxOPEN)                             "Thuban Session File (*.thuban)|*.thuban",
390                               wxSAVE|wxOVERWRITE_PROMPT)
391          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
392              self.application.session.SetFilename(dlg.GetPath())              self.application.session.SetFilename(dlg.GetPath())
393              self.application.SaveSession()              self.application.SaveSession()
# Line 389  class MainWindow(DockFrame): Line 396  class MainWindow(DockFrame):
396      def Exit(self):      def Exit(self):
397          self.Close(False)          self.Close(False)
398    
399      def _OnClose(self, event):      def OnClose(self, event):
400          result = self.save_modified_session(can_veto = event.CanVeto())          result = self.save_modified_session(can_veto = event.CanVeto())
401          if result == wxID_CANCEL:          if result == wxID_CANCEL:
402              event.Veto()              event.Veto()
# Line 398  class MainWindow(DockFrame): Line 405  class MainWindow(DockFrame):
405              # wx's destroy event, but that isn't implemented for wxGTK              # wx's destroy event, but that isn't implemented for wxGTK
406              # yet.              # yet.
407              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)              self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed)
408              DockFrame._OnClose(self, event)              DockFrame.OnClose(self, event)
409                for dlg in self.dialogs.values():
410                    dlg.Destroy()
411                self.canvas.Destroy()
412              self.Destroy()              self.Destroy()
413    
414      def SetMap(self, map):      def SetMap(self, map):
415          self.canvas.SetMap(map)          self.canvas.SetMap(map)
416          #self.legendPanel.SetMap(map)          self.__SetTitle(map.Title())
417    
418            dialog = self.FindRegisteredDock("legend")
419            if dialog is not None:
420                dialog.GetPanel().SetMap(self.Map())
421    
422      def Map(self):      def Map(self):
423          """Return the map displayed by this mainwindow"""          """Return the map displayed by this mainwindow"""
424    
         # sanity check  
         #assert(self.canvas.Map() is self.legendPanel.GetMap())  
   
425          return self.canvas.Map()          return self.canvas.Map()
426    
427      def ToggleSessionTree(self):      def ToggleSessionTree(self):
# Line 429  class MainWindow(DockFrame): Line 440  class MainWindow(DockFrame):
440          return self.get_open_dialog("session_tree") is not None          return self.get_open_dialog("session_tree") is not None
441    
442      def About(self):      def About(self):
443          self.RunMessageBox(_("About"),          dlg = About(self)
444                             _("Thuban v%s\n"          dlg.ShowModal()
445                              #"Build Date: %s\n"          dlg.Destroy()
446                              "\n"  
447                              "Thuban is a program for\n"      def DatabaseManagement(self):
448                              "exploring geographic data.\n"          name = "dbmanagement"
449                              "Copyright (C) 2001-2003 Intevation GmbH.\n"          dialog = self.get_open_dialog(name)
450                              "Thuban is licensed under the GNU GPL"          if dialog is None:
451                             % __ThubanVersion__), #__BuildDate__)),              map = self.canvas.Map()
452                             wxOK | wxICON_INFORMATION)              dialog = DBFrame(self, name, self.application.Session())
453                self.add_dialog(name, dialog)
454                dialog.Show()
455            dialog.Raise()
456    
457      def AddLayer(self):      def AddLayer(self):
458          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",          dlg = wxFileDialog(self, _("Select one or more data files"), ".", "",
459                               _("Shapefiles (*.shp)") + "|*.shp|" +
460                               _("All Files (*.*)") + "|*.*",
461                               wxOPEN | wxMULTIPLE)
462            if dlg.ShowModal() == wxID_OK:
463                filenames = dlg.GetPaths()
464                for filename in filenames:
465                    title = os.path.splitext(os.path.basename(filename))[0]
466                    map = self.canvas.Map()
467                    has_layers = map.HasLayers()
468                    try:
469                        store = self.application.Session().OpenShapefile(filename)
470                    except IOError:
471                        # the layer couldn't be opened
472                        self.RunMessageBox(_("Add Layer"),
473                                           _("Can't open the file '%s'.")%filename)
474                    else:
475                        layer = Layer(title, store)
476                        map.AddLayer(layer)
477                        if not has_layers:
478                            # if we're adding a layer to an empty map, fit the
479                            # new map to the window
480                            self.canvas.FitMapToWindow()
481            dlg.Destroy()
482    
483        def AddRasterLayer(self):
484            dlg = wxFileDialog(self, _("Select an image file"), ".", "", "*.*",
485                             wxOPEN)                             wxOPEN)
486          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
487              filename = dlg.GetPath()              filename = dlg.GetPath()
488              title = os.path.splitext(os.path.basename(filename))[0]              title = os.path.splitext(os.path.basename(filename))[0]
             layer = Layer(title, filename)  
489              map = self.canvas.Map()              map = self.canvas.Map()
490              has_layers = map.HasLayers()              has_layers = map.HasLayers()
491              try:              try:
492                  map.AddLayer(layer)                  layer = RasterLayer(title, filename)
493              except IOError:              except IOError:
494                  # the layer couldn't be opened                  # the layer couldn't be opened
495                  self.RunMessageBox(_("Add Layer"),                  self.RunMessageBox(_("Add Image Layer"),
496                                     _("Can't open the file '%s'.") % filename)                                     _("Can't open the file '%s'.") % filename)
497              else:              else:
498                    map.AddLayer(layer)
499                  if not has_layers:                  if not has_layers:
500                      # if we're adding a layer to an empty map, fit the                      # if we're adding a layer to an empty map, fit the
501                      # new map to the window                      # new map to the window
502                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
503          dlg.Destroy()          dlg.Destroy()
504    
505        def AddDBLayer(self):
506            """Add a layer read from a database"""
507            session = self.application.Session()
508            dlg = ChooseDBTableDialog(self.application.Session(), self,-1, "")
509    
510            if dlg.ShowModal() == wxID_OK:
511                dbconn, dbtable = dlg.GetTable()
512                try:
513                    title = str(dbtable)
514    
515                    # Chose the correct Interface for the database type
516                    store = PostGISShapeStore(dbconn, dbtable)
517                    session.AddShapeStore(store)
518                    layer = Layer(title, store)
519                except:
520                    # Some error occured while initializing the layer
521                    self.RunMessageBox(_("Add Layer from database"),
522                                       _("Can't open the database table '%s'")
523                                       % dbtable)
524    
525                map = self.canvas.Map()
526    
527                has_layers = map.HasLayers()
528                map.AddLayer(layer)
529                if not has_layers:
530                    self.canvas.FitMapToWindow()
531    
532            dlg.Destroy()
533    
534      def RemoveLayer(self):      def RemoveLayer(self):
535          layer = self.current_layer()          layer = self.current_layer()
536          if layer is not None:          if layer is not None:
# Line 501  class MainWindow(DockFrame): Line 570  class MainWindow(DockFrame):
570          """Return true if a layer is currently selected"""          """Return true if a layer is currently selected"""
571          return self.canvas.HasSelectedLayer()          return self.canvas.HasSelectedLayer()
572    
573      def choose_color(self):      def has_selected_shapes(self):
574          """Run the color selection dialog and return the selected color.          """Return true if a shape is currently selected"""
575            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.GetClassification().SetDefaultFill(color)  
576    
577      def LayerTransparentFill(self):      def HideLayer(self):
578          layer = self.current_layer()          layer = self.current_layer()
579          if layer is not None:          if layer is not None:
580              layer.GetClassification().SetDefaultFill(Color.Transparent)              layer.SetVisible(0)
581    
582      def LayerOutlineColor(self):      def ShowLayer(self):
583          layer = self.current_layer()          layer = self.current_layer()
584          if layer is not None:          if layer is not None:
585              color = self.choose_color()              layer.SetVisible(1)
             if color is not None:  
                 layer.GetClassification().SetDefaultLineColor(color)  
586    
587      def LayerNoOutline(self):      def DuplicateLayer(self):
588            """Ceate a new layer above the selected layer with the same shapestore
589            """
590          layer = self.current_layer()          layer = self.current_layer()
591          if layer is not None:          if layer is not None and hasattr(layer, "ShapeStore"):
592              layer.GetClassification().SetDefaultLineColor(Color.Transparent)              new_layer = Layer(_("Copy of `%s'") % layer.Title(),
593                                  layer.ShapeStore(),
594                                  projection = layer.GetProjection())
595                new_classification = copy.deepcopy(layer.GetClassification())
596                new_layer.SetClassification(new_classification)
597                self.Map().AddLayer(new_layer)
598    
599      def HideLayer(self):      def CanDuplicateLayer(self):
600          layer = self.current_layer()          """Return whether the DuplicateLayer method can create a duplicate"""
         if layer is not None:  
             layer.SetVisible(0)  
           
     def ShowLayer(self):  
601          layer = self.current_layer()          layer = self.current_layer()
602          if layer is not None:          return layer is not None and hasattr(layer, "ShapeStore")
             layer.SetVisible(1)  
603    
604      def LayerShowTable(self):      def LayerShowTable(self):
605          layer = self.current_layer()          layer = self.current_layer()
606          if layer is not None:          if layer is not None:
607              table = layer.table              table = layer.ShapeStore().Table()
608              name = "table_view" + str(id(table))              name = "table_view" + str(id(table))
609              dialog = self.get_open_dialog(name)              dialog = self.get_open_dialog(name)
610              if dialog is None:              if dialog is None:
611                  dialog = tableview.LayerTableFrame(self, name,                  dialog = tableview.LayerTableFrame(self, name,
612                                                 _("Table: %s") % layer.Title(),                                           _("Layer Table: %s") % layer.Title(),
613                                                     layer, table)                                           layer, table)
614                  self.add_dialog(name, dialog)                  self.add_dialog(name, dialog)
615                  dialog.Show(true)                  dialog.Show(True)
616              else:              else:
617                  # FIXME: bring dialog to front here                  # FIXME: bring dialog to front here
618                  pass                  pass
619    
620      def Projection(self):      def MapProjection(self):
         map = self.canvas.Map()  
         proj = map.projection  
         if proj is None:  
             proj4Dlg = proj4dialog.Proj4Dialog(NULL, None, map.BoundingBox())  
         else:  
             proj4Dlg = proj4dialog.Proj4Dialog(NULL, map.projection.params,  
                                                map.BoundingBox())  
         if proj4Dlg.ShowModal() == wxID_OK:  
             params = proj4Dlg.GetParams()  
             if params is not None:  
                 proj = Projection(params)  
             else:  
                 proj = None  
             map.SetProjection(proj)  
         proj4Dlg.Destroy()  
621    
622      def Classify(self):          name = "map_projection"
623            dialog = self.get_open_dialog(name)
624    
625            if dialog is None:
626                map = self.canvas.Map()
627                dialog = projdialog.ProjFrame(self, name,
628                         _("Map Projection: %s") % map.Title(), map)
629                self.add_dialog(name, dialog)
630                dialog.Show()
631            dialog.Raise()
632    
633        def LayerProjection(self):
634    
635            layer = self.current_layer()
636    
637            name = "layer_projection" + str(id(layer))
638            dialog = self.get_open_dialog(name)
639    
640            if dialog is None:
641                map = self.canvas.Map()
642                dialog = projdialog.ProjFrame(self, name,
643                         _("Layer Projection: %s") % layer.Title(), layer)
644                self.add_dialog(name, dialog)
645                dialog.Show()
646            dialog.Raise()
647    
648        def LayerEditProperties(self):
649    
650          #          #
651          # the menu option for this should only be available if there          # the menu option for this should only be available if there
# Line 593  class MainWindow(DockFrame): Line 654  class MainWindow(DockFrame):
654          #          #
655    
656          layer = self.current_layer()          layer = self.current_layer()
657          self.OpenClassifier(layer)          self.OpenLayerProperties(layer)
658    
659      def OpenClassifier(self, layer, group = None):      def OpenLayerProperties(self, layer, group = None):
660          name = "classifier" + str(id(layer))          name = "layer_properties" + str(id(layer))
661          dialog = self.get_open_dialog(name)          dialog = self.get_open_dialog(name)
662    
663          if dialog is None:          if dialog is None:
664              dialog = classifier.Classifier(self, name, layer, group)              dialog = Classifier(self, name, self.Map(), layer, group)
665              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
666              dialog.Show()              dialog.Show()
667          dialog.Raise()          dialog.Raise()
668    
669        def LayerJoinTable(self):
670            layer = self.canvas.SelectedLayer()
671            if layer is not None:
672                dlg = JoinDialog(self, _("Join Layer with Table"),
673                                 self.application.session,
674                                 layer = layer)
675                dlg.ShowModal()
676    
677        def LayerUnjoinTable(self):
678            layer = self.canvas.SelectedLayer()
679            if layer is not None:
680                orig_store = layer.ShapeStore().OrigShapeStore()
681                if orig_store:
682                    layer.SetShapeStore(orig_store)
683    
684      def ShowLegend(self):      def ShowLegend(self):
685          if not self.LegendShown():          if not self.LegendShown():
# Line 616  class MainWindow(DockFrame): Line 691  class MainWindow(DockFrame):
691          dialog = self.FindRegisteredDock(name)          dialog = self.FindRegisteredDock(name)
692    
693          if dialog is None:          if dialog is None:
694              title = "Legend: %s" % self.Map().Title()              dialog = self.CreateDock(name, -1, _("Legend"), wxLAYOUT_LEFT)
             dialog = self.CreateDock(name, -1, title, wxLAYOUT_LEFT)  
695              legend.LegendPanel(dialog, None, self)              legend.LegendPanel(dialog, None, self)
696              dialog.Dock()              dialog.Dock()
697              dialog.GetPanel().SetMap(self.Map())              dialog.GetPanel().SetMap(self.Map())
# Line 630  class MainWindow(DockFrame): Line 704  class MainWindow(DockFrame):
704          dialog = self.FindRegisteredDock("legend")          dialog = self.FindRegisteredDock("legend")
705          return dialog is not None and dialog.IsShown()          return dialog is not None and dialog.IsShown()
706    
707        def TableOpen(self):
708            dlg = wxFileDialog(self, _("Open Table"), ".", "",
709                               _("DBF Files (*.dbf)") + "|*.dbf|" +
710                               #_("CSV Files (*.csv)") + "|*.csv|" +
711                               _("All Files (*.*)") + "|*.*",
712                               wxOPEN)
713            if dlg.ShowModal() == wxID_OK:
714                filename = dlg.GetPath()
715                dlg.Destroy()
716                try:
717                    table = self.application.session.OpenTableFile(filename)
718                except IOError:
719                    # the layer couldn't be opened
720                    self.RunMessageBox(_("Open Table"),
721                                       _("Can't open the file '%s'.") % filename)
722                else:
723                    self.ShowTableView(table)
724    
725        def TableClose(self):
726            tables = self.application.session.UnreferencedTables()
727    
728            lst = [(t.Title(), t) for t in tables]
729            lst.sort()
730            titles = [i[0] for i in lst]
731            dlg = wxMultipleChoiceDialog(self, _("Pick the tables to close:"),
732                                         _("Close Table"), titles,
733                                         size = (400, 300),
734                                         style = wxDEFAULT_DIALOG_STYLE |
735                                                 wxRESIZE_BORDER)
736            if dlg.ShowModal() == wxID_OK:
737                for i in dlg.GetValue():
738                    self.application.session.RemoveTable(lst[i][1])
739    
740    
741        def TableShow(self):
742            """Offer a multi-selection dialog for tables to be displayed
743    
744            The windows for the selected tables are opened or brought to
745            the front.
746            """
747            tables = self.application.session.Tables()
748    
749            lst = [(t.Title(), t) for t in tables]
750            lst.sort()
751            titles = [i[0] for i in lst]
752            dlg = wxMultipleChoiceDialog(self, _("Pick the table to show:"),
753                                         _("Show Table"), titles,
754                                         size = (400,300),
755                                         style = wxDEFAULT_DIALOG_STYLE |
756                                                 wxRESIZE_BORDER)
757            if (dlg.ShowModal() == wxID_OK):
758                for i in dlg.GetValue():
759                    # XXX: if the table belongs to a layer, open a
760                    # LayerTableFrame instead of QueryTableFrame
761                    self.ShowTableView(lst[i][1])
762    
763        def TableJoin(self):
764            dlg = JoinDialog(self, _("Join Tables"), self.application.session)
765            dlg.ShowModal()
766    
767        def ShowTableView(self, table):
768            """Open a table view for the table and optionally"""
769            name = "table_view%d" % id(table)
770            dialog = self.get_open_dialog(name)
771            if dialog is None:
772                dialog = tableview.QueryTableFrame(self, name,
773                                                   _("Table: %s") % table.Title(),
774                                                   table)
775                self.add_dialog(name, dialog)
776                dialog.Show(True)
777            dialog.Raise()
778    
779        def TableRename(self):
780            """Let the user rename a table"""
781    
782            # First, let the user select a table
783            tables = self.application.session.Tables()
784            lst = [(t.Title(), t) for t in tables]
785            lst.sort()
786            titles = [i[0] for i in lst]
787            dlg = wxMultipleChoiceDialog(self, _("Pick the table to rename:"),
788                                         _("Rename Table"), titles,
789                                         size = (400,300),
790                                         style = wxDEFAULT_DIALOG_STYLE |
791                                                 wxRESIZE_BORDER)
792            if (dlg.ShowModal() == wxID_OK):
793                to_rename = [lst[i][1] for i in dlg.GetValue()]
794                dlg.Destroy()
795            else:
796                to_rename = []
797    
798            # Second, let the user rename the layers
799            for table in to_rename:
800                dlg = wxTextEntryDialog(self, "Table Title: ", "Rename Table",
801                                        table.Title())
802                try:
803                    if dlg.ShowModal() == wxID_OK:
804                        title = dlg.GetValue()
805                        if title != "":
806                            table.SetTitle(title)
807    
808                            # Make sure the session is marked as modified.
809                            # FIXME: This should be handled automatically,
810                            # but that requires more changes to the tables
811                            # than I have time for currently.
812                            self.application.session.changed()
813                finally:
814                    dlg.Destroy()
815    
816    
817      def ZoomInTool(self):      def ZoomInTool(self):
818          self.canvas.ZoomInTool()          self.canvas.ZoomInTool()
819    
# Line 649  class MainWindow(DockFrame): Line 833  class MainWindow(DockFrame):
833      def FullExtent(self):      def FullExtent(self):
834          self.canvas.FitMapToWindow()          self.canvas.FitMapToWindow()
835    
836        def FullLayerExtent(self):
837            self.canvas.FitLayerToWindow(self.current_layer())
838    
839        def FullSelectionExtent(self):
840            self.canvas.FitSelectedToWindow()
841    
842        def ExportMap(self):
843            self.canvas.Export()
844    
845      def PrintMap(self):      def PrintMap(self):
846          self.canvas.Print()          self.canvas.Print()
847    
848        def RenameMap(self):
849            dlg = wxTextEntryDialog(self, "Map Title: ", "Rename Map",
850                                    self.Map().Title())
851            if dlg.ShowModal() == wxID_OK:
852                title = dlg.GetValue()
853                if title != "":
854                    self.Map().SetTitle(title)
855                    self.__SetTitle(title)
856    
857            dlg.Destroy()
858    
859        def RenameLayer(self):
860            """Let the user rename the currently selected layer"""
861            layer = self.current_layer()
862            if layer is not None:
863                dlg = wxTextEntryDialog(self, "Layer Title: ", "Rename Layer",
864                                        layer.Title())
865                try:
866                    if dlg.ShowModal() == wxID_OK:
867                        title = dlg.GetValue()
868                        if title != "":
869                            layer.SetTitle(title)
870                finally:
871                    dlg.Destroy()
872    
873      def identify_view_on_demand(self, layer, shapes):      def identify_view_on_demand(self, layer, shapes):
874            """Subscribed to the canvas' SHAPES_SELECTED message
875    
876            If the current tool is the identify tool, at least one shape is
877            selected and the identify dialog is not shown, show the dialog.
878            """
879            # If the selection has become empty we don't need to do
880            # anything. Otherwise it could happen that the dialog was popped
881            # up when the selection became empty, e.g. when a new selection
882            # is opened while the identify tool is active and dialog had
883            # been closed
884            if not shapes:
885                return
886    
887          name = "identify_view"          name = "identify_view"
888          if self.canvas.CurrentTool() == "IdentifyTool":          if self.canvas.CurrentTool() == "IdentifyTool":
889              if not self.dialog_open(name):              if not self.dialog_open(name):
# Line 663  class MainWindow(DockFrame): Line 894  class MainWindow(DockFrame):
894                  # FIXME: bring dialog to front?                  # FIXME: bring dialog to front?
895                  pass                  pass
896    
897        def __SetTitle(self, title):
898            self.SetTitle("Thuban - " + title)
899    
900  #  #
901  # Define all the commands available in the main window  # Define all the commands available in the main window
902  #  #
# Line 703  def _has_selected_layer(context): Line 937  def _has_selected_layer(context):
937      """Return true if a layer is selected in the context"""      """Return true if a layer is selected in the context"""
938      return context.mainwindow.has_selected_layer()      return context.mainwindow.has_selected_layer()
939    
940    def _has_selected_shapes(context):
941        """Return true if a layer is selected in the context"""
942        return context.mainwindow.has_selected_shapes()
943    
944  def _can_remove_layer(context):  def _can_remove_layer(context):
945      return context.mainwindow.CanRemoveLayer()      return context.mainwindow.CanRemoveLayer()
946    
# Line 725  def _has_legend_shown(context): Line 963  def _has_legend_shown(context):
963      """Return true if the legend window is shown"""      """Return true if the legend window is shown"""
964      return context.mainwindow.LegendShown()      return context.mainwindow.LegendShown()
965    
966    def _has_gdal_support(context):
967        """Return True if the GDAL is available"""
968        return Thuban.Model.resource.has_gdal_support()
969    
970    def _has_dbconnections(context):
971        """Return whether the the session has database connections"""
972        return context.session.HasDBConnections()
973    
974    def _has_postgis_support(context):
975        return has_postgis_support()
976    
977    
978  # File menu  # File menu
979  _method_command("new_session", _("&New Session"), "NewSession")  _method_command("new_session", _("&New Session"), "NewSession",
980  _method_command("open_session", _("&Open Session"), "OpenSession")                  helptext = _("Start a new session"))
981  _method_command("save_session", _("&Save Session"), "SaveSession")  _method_command("open_session", _("&Open Session..."), "OpenSession",
982  _method_command("save_session_as", _("Save Session &As"), "SaveSessionAs")                  helptext = _("Open a session file"))
983    _method_command("save_session", _("&Save Session"), "SaveSession",
984                    helptext =_("Save this session to the file it was opened from"))
985    _method_command("save_session_as", _("Save Session &As..."), "SaveSessionAs",
986                    helptext = _("Save this session to a new file"))
987  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",  _method_command("toggle_session_tree", _("Session &Tree"), "ToggleSessionTree",
988                  checked = _has_tree_window_shown)                  checked = _has_tree_window_shown,
989                    helptext = _("Toggle on/off the session tree analysis window"))
990  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
991                  checked = _has_legend_shown)                  checked = _has_legend_shown,
992  _method_command("exit", _("E&xit"), "Exit")                  helptext = _("Toggle Legend on/off"))
993    _method_command("database_management", _("&Database Connections..."),
994                    "DatabaseManagement",
995                    sensitive = _has_postgis_support)
996    _method_command("exit", _("E&xit"), "Exit",
997                    helptext = _("Finish working with Thuban"))
998    
999  # Help menu  # Help menu
1000  _method_command("help_about", _("&About"), "About")  _method_command("help_about", _("&About..."), "About",
1001                    helptext = _("Info about Thuban authors, version and modules"))
1002    
1003    
1004  # Map menu  # Map menu
1005  _method_command("map_projection", _("Pro&jection"), "Projection")  _method_command("map_projection", _("Pro&jection..."), "MapProjection",
1006                    helptext = _("Set or change the map projection"))
1007    
1008  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",  _tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool",
1009                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",                helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in",
# Line 761  _tool_command("map_label_tool", _("&Labe Line 1022  _tool_command("map_label_tool", _("&Labe
1022                helptext = _("Add/Remove labels"), icon = "label",                helptext = _("Add/Remove labels"), icon = "label",
1023                sensitive = _has_visible_map)                sensitive = _has_visible_map)
1024  _method_command("map_full_extent", _("&Full extent"), "FullExtent",  _method_command("map_full_extent", _("&Full extent"), "FullExtent",
1025                 helptext = _("Full Extent"), icon = "fullextent",                 helptext = _("Zoom to the full map extent"), icon = "fullextent",
1026                sensitive = _has_visible_map)                sensitive = _has_visible_map)
1027    _method_command("layer_full_extent", _("&Full layer extent"), "FullLayerExtent",
1028                    helptext = _("Zoom to the full layer extent"),
1029                    icon = "fulllayerextent", sensitive = _has_selected_layer)
1030    _method_command("selected_full_extent", _("&Full selection extent"),
1031                    "FullSelectionExtent",
1032                    helptext = _("Zoom to the full selection extent"),
1033                    icon = "fullselextent", sensitive = _has_selected_shapes)
1034    _method_command("map_export", _("E&xport"), "ExportMap",
1035                    helptext = _("Export the map to file"))
1036  _method_command("map_print", _("Prin&t"), "PrintMap",  _method_command("map_print", _("Prin&t"), "PrintMap",
1037                  helptext = _("Print the map"))                  helptext = _("Print the map"))
1038    _method_command("map_rename", _("&Rename..."), "RenameMap",
1039  # Layer menu                  helptext = _("Rename the map"))
1040  _method_command("layer_add", _("&Add Layer"), "AddLayer",  _method_command("layer_add", _("&Add Layer..."), "AddLayer",
1041                  helptext = _("Add a new layer to active map"))                  helptext = _("Add a new layer to the map"))
1042    _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
1043                    helptext = _("Add a new image layer to the map"),
1044                    sensitive = _has_gdal_support)
1045    _method_command("layer_add_db", _("Add &Database Layer..."), "AddDBLayer",
1046                    helptext = _("Add a new database layer to active map"),
1047                    sensitive = _has_dbconnections)
1048  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
1049                  helptext = _("Remove selected layer(s)"),                  helptext = _("Remove selected layer"),
1050                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
1051  _method_command("layer_fill_color", _("&Fill Color"), "LayerFillColor",  
1052                  helptext = _("Set the fill color of selected layer(s)"),  # Layer menu
1053                  sensitive = _has_selected_layer)  _method_command("layer_projection", _("Pro&jection..."), "LayerProjection",
1054  _method_command("layer_transparent_fill", _("&Transparent Fill"),                  sensitive = _has_selected_layer,
1055                  "LayerTransparentFill",                  helptext = _("Specify projection for selected layer"))
1056                  helptext = _("Do not fill the selected layer(s)"),  _method_command("layer_duplicate", _("&Duplicate"), "DuplicateLayer",
1057                  sensitive = _has_selected_layer)                  helptext = _("Duplicate selected layer"),
1058  _method_command("layer_outline_color", _("&Outline Color"), "LayerOutlineColor",            sensitive = lambda context: context.mainwindow.CanDuplicateLayer())
1059                  helptext = _("Set the outline color of selected layer(s)"),  _method_command("layer_rename", _("Re&name ..."), "RenameLayer",
1060                  sensitive = _has_selected_layer)                  helptext = _("Rename selected layer"),
 _method_command("layer_no_outline", _("&No Outline"), "LayerNoOutline",  
                 helptext= _("Do not draw the outline of the selected layer(s)"),  
1061                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1062  _method_command("layer_raise", _("&Raise"), "RaiseLayer",  _method_command("layer_raise", _("&Raise"), "RaiseLayer",
1063                  helptext = _("Raise selected layer(s)"),                  helptext = _("Raise selected layer"),
1064                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1065  _method_command("layer_lower", _("&Lower"), "LowerLayer",  _method_command("layer_lower", _("&Lower"), "LowerLayer",
1066                  helptext = _("Lower selected layer(s)"),                  helptext = _("Lower selected layer"),
1067                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1068  _method_command("layer_show", _("&Show"), "ShowLayer",  _method_command("layer_show", _("&Show"), "ShowLayer",
1069                  helptext = _("Make selected layer(s) visible"),                  helptext = _("Make selected layer visible"),
1070                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1071  _method_command("layer_hide", _("&Hide"), "HideLayer",  _method_command("layer_hide", _("&Hide"), "HideLayer",
1072                  helptext = _("Make selected layer(s) unvisible"),                  helptext = _("Make selected layer unvisible"),
1073                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1074  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",  _method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable",
1075                  helptext = _("Show the selected layer's table"),                  helptext = _("Show the selected layer's table"),
1076                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer)
1077  _method_command("layer_classifier", _("Classify"), "Classify",  _method_command("layer_properties", _("&Properties..."), "LayerEditProperties",
1078                  sensitive = _has_selected_layer)                  sensitive = _has_selected_layer,
1079                    helptext = _("Edit the properties of the selected layer"))
1080    _method_command("layer_jointable", _("&Join Table..."), "LayerJoinTable",
1081                    sensitive = _has_selected_layer,
1082                    helptext = _("Join and attach a table to the selected layer"))
1083    
1084  # the menu structure  def _can_unjoin(context):
1085  main_menu = Menu("<main>", "<main>",      """Return whether the Layer/Unjoin command can be executed.
1086                   [Menu("file", _("&File"),  
1087                         ["new_session", "open_session", None,      This is the case if a layer is selected and that layer has a
1088                          "save_session", "save_session_as", None,      shapestore that has an original shapestore.
1089                          "toggle_session_tree",      """
1090                          "toggle_legend", None,      layer = context.mainwindow.SelectedLayer()
1091                          "exit"]),      if layer is None:
1092                    Menu("map", _("&Map"),          return 0
1093                         ["layer_add", "layer_remove",      getstore = getattr(layer, "ShapeStore", None)
1094        if getstore is not None:
1095            return getstore().OrigShapeStore() is not None
1096        else:
1097            return 0
1098    _method_command("layer_unjointable", _("&Unjoin Table..."), "LayerUnjoinTable",
1099                    sensitive = _can_unjoin,
1100                    helptext = _("Undo the last join operation"))
1101    
1102    
1103    def _has_tables(context):
1104        return bool(context.session.Tables())
1105    
1106    # Table menu
1107    _method_command("table_open", _("&Open..."), "TableOpen",
1108                    helptext = _("Open a DBF-table from a file"))
1109    _method_command("table_close", _("&Close..."), "TableClose",
1110           sensitive = lambda context: bool(context.session.UnreferencedTables()),
1111                    helptext = _("Close one or more tables from a list"))
1112    _method_command("table_rename", _("&Rename..."), "TableRename",
1113                    sensitive = _has_tables,
1114                    helptext = _("Rename one or more tables"))
1115    _method_command("table_show", _("&Show..."), "TableShow",
1116                    sensitive = _has_tables,
1117                    helptext = _("Show one or more tables in a dialog"))
1118    _method_command("table_join", _("&Join..."), "TableJoin",
1119                    sensitive = _has_tables,
1120                    helptext = _("Join two tables creating a new one"))
1121    
1122    #  Export only under Windows ...
1123    map_menu = ["layer_add", "layer_add_db", "rasterlayer_add", "layer_remove",
1124                          None,                          None,
1125                            "map_rename",
1126                          "map_projection",                          "map_projection",
1127                          None,                          None,
1128                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
1129                          "map_pan_tool", "map_identify_tool", "map_label_tool",                          "map_pan_tool",
                         None,  
1130                          "map_full_extent",                          "map_full_extent",
1131                            "layer_full_extent",
1132                            "selected_full_extent",
1133                            None,
1134                            "map_identify_tool", "map_label_tool",
1135                          None,                          None,
1136                          "map_print"]),                          "toggle_legend",
1137                            None]
1138    if wxPlatform == '__WXMSW__':
1139        map_menu.append("map_export")
1140    map_menu.append("map_print")
1141    
1142    # the menu structure
1143    main_menu = Menu("<main>", "<main>",
1144                     [Menu("file", _("&File"),
1145                           ["new_session", "open_session", None,
1146                            "save_session", "save_session_as", None,
1147                            "database_management", None,
1148                            "toggle_session_tree", None,
1149                            "exit"]),
1150                      Menu("map", _("&Map"), map_menu),
1151                    Menu("layer", _("&Layer"),                    Menu("layer", _("&Layer"),
1152                         ["layer_fill_color", "layer_transparent_fill",                         ["layer_rename", "layer_duplicate",
                         "layer_outline_color", "layer_no_outline",  
1153                          None,                          None,
1154                          "layer_raise", "layer_lower",                          "layer_raise", "layer_lower",
1155                          None,                          None,
1156                          "layer_show", "layer_hide",                          "layer_show", "layer_hide",
1157                          None,                          None,
1158                            "layer_projection",
1159                            None,
1160                          "layer_show_table",                          "layer_show_table",
1161                            "layer_jointable",
1162                            "layer_unjointable",
1163                          None,                          None,
1164                          "layer_classifier"]),                          "layer_properties"]),
1165                      Menu("table", _("&Table"),
1166                           ["table_open", "table_close", "table_rename",
1167                           None,
1168                           "table_show",
1169                           None,
1170                           "table_join"]),
1171                    Menu("help", _("&Help"),                    Menu("help", _("&Help"),
1172                         ["help_about"])])                         ["help_about"])])
1173    
# Line 840  main_menu = Menu("<main>", "<main>", Line 1175  main_menu = Menu("<main>", "<main>",
1175    
1176  main_toolbar = Menu("<toolbar>", "<toolbar>",  main_toolbar = Menu("<toolbar>", "<toolbar>",
1177                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",                      ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool",
1178                       "map_full_extent", None,                       "map_full_extent",
1179                         "layer_full_extent",
1180                         "selected_full_extent",
1181                         None,
1182                       "map_identify_tool", "map_label_tool"])                       "map_identify_tool", "map_label_tool"])
1183    

Legend:
Removed from v.622  
changed lines
  Added in v.1644

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26