/[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 1464 by bh, Fri Jul 18 18:20:40 2003 UTC revision 1644 by bh, Mon Aug 25 12:44:55 2003 UTC
# Line 12  The main window Line 12  The main window
12  """  """
13    
14  __version__ = "$Revision$"  __version__ = "$Revision$"
15    # $Source$
16  __ThubanVersion__ = "0.8" #"$THUBAN_0_2$"  # $Id$
 #__BuildDate__ = "$Date$"  
17    
18  import os  import os
19  import copy  import copy
# Line 28  import Thuban.version Line 27  import Thuban.version
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, RasterLayer  from Thuban.Model.layer import Layer, RasterLayer
30    from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support
31  # XXX: replace this by  # XXX: replace this by
32  # from wxPython.lib.dialogs import wxMultipleChoiceDialog  # from wxPython.lib.dialogs import wxMultipleChoiceDialog
33  # when Thuban does not support wxPython 2.4.0 any more.  # when Thuban does not support wxPython 2.4.0 any more.
# Line 49  from about import About Line 48  from about import About
48    
49  from Thuban.UI.dock import DockFrame  from Thuban.UI.dock import DockFrame
50  from Thuban.UI.join import JoinDialog  from Thuban.UI.join import JoinDialog
51    from Thuban.UI.dbdialog import DBFrame, ChooseDBTableDialog
52  import resource  import resource
53  import Thuban.Model.resource  import Thuban.Model.resource
54    
# Line 445  class MainWindow(DockFrame): Line 444  class MainWindow(DockFrame):
444          dlg.ShowModal()          dlg.ShowModal()
445          dlg.Destroy()          dlg.Destroy()
446    
447        def DatabaseManagement(self):
448            name = "dbmanagement"
449            dialog = self.get_open_dialog(name)
450            if dialog is None:
451                map = self.canvas.Map()
452                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                             wxOPEN)                             _("Shapefiles (*.shp)") + "|*.shp|" +
460                               _("All Files (*.*)") + "|*.*",
461                               wxOPEN | wxMULTIPLE)
462          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
463              filename = dlg.GetPath()              filenames = dlg.GetPaths()
464              title = os.path.splitext(os.path.basename(filename))[0]              for filename in filenames:
465              map = self.canvas.Map()                  title = os.path.splitext(os.path.basename(filename))[0]
466              has_layers = map.HasLayers()                  map = self.canvas.Map()
467              try:                  has_layers = map.HasLayers()
468                  store = self.application.Session().OpenShapefile(filename)                  try:
469              except IOError:                      store = self.application.Session().OpenShapefile(filename)
470                  # the layer couldn't be opened                  except IOError:
471                  self.RunMessageBox(_("Add Layer"),                      # the layer couldn't be opened
472                                     _("Can't open the file '%s'.") % filename)                      self.RunMessageBox(_("Add Layer"),
473              else:                                         _("Can't open the file '%s'.")%filename)
474                  layer = Layer(title, store)                  else:
475                  map.AddLayer(layer)                      layer = Layer(title, store)
476                  if not has_layers:                      map.AddLayer(layer)
477                      # if we're adding a layer to an empty map, fit the                      if not has_layers:
478                      # new map to the window                          # if we're adding a layer to an empty map, fit the
479                      self.canvas.FitMapToWindow()                          # new map to the window
480                            self.canvas.FitMapToWindow()
481          dlg.Destroy()          dlg.Destroy()
482    
483      def AddRasterLayer(self):      def AddRasterLayer(self):
# Line 490  class MainWindow(DockFrame): Line 502  class MainWindow(DockFrame):
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 926  def _has_gdal_support(context): Line 967  def _has_gdal_support(context):
967      """Return True if the GDAL is available"""      """Return True if the GDAL is available"""
968      return Thuban.Model.resource.has_gdal_support()      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                  helptext = _("Start a new session"))                  helptext = _("Start a new session"))
# Line 941  _method_command("toggle_session_tree", _ Line 990  _method_command("toggle_session_tree", _
990  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
991                  checked = _has_legend_shown,                  checked = _has_legend_shown,
992                  helptext = _("Toggle Legend on/off"))                  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",  _method_command("exit", _("E&xit"), "Exit",
997                  helptext = _("Finish working with Thuban"))                  helptext = _("Finish working with Thuban"))
998    
# Line 990  _method_command("layer_add", _("&Add Lay Line 1042  _method_command("layer_add", _("&Add Lay
1042  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
1043                  helptext = _("Add a new image layer to the map"),                  helptext = _("Add a new image layer to the map"),
1044                  sensitive = _has_gdal_support)                  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"),                  helptext = _("Remove selected layer"),
1050                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
# Line 1065  _method_command("table_join", _("&Join.. Line 1120  _method_command("table_join", _("&Join..
1120                  helptext = _("Join two tables creating a new one"))                  helptext = _("Join two tables creating a new one"))
1121    
1122  #  Export only under Windows ...  #  Export only under Windows ...
1123  map_menu = ["layer_add", "rasterlayer_add", "layer_remove",  map_menu = ["layer_add", "layer_add_db", "rasterlayer_add", "layer_remove",
1124                          None,                          None,
1125                          "map_rename",                          "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_pan_tool",
1130                          "map_full_extent",                          "map_full_extent",
1131                          "layer_full_extent",                          "layer_full_extent",
1132                          "selected_full_extent",                          "selected_full_extent",
1133                          None,                          None,
# Line 1089  main_menu = Menu("<main>", "<main>", Line 1144  main_menu = Menu("<main>", "<main>",
1144                   [Menu("file", _("&File"),                   [Menu("file", _("&File"),
1145                         ["new_session", "open_session", None,                         ["new_session", "open_session", None,
1146                          "save_session", "save_session_as", None,                          "save_session", "save_session_as", None,
1147                            "database_management", None,
1148                          "toggle_session_tree", None,                          "toggle_session_tree", None,
1149                          "exit"]),                          "exit"]),
1150                    Menu("map", _("&Map"), map_menu),                    Menu("map", _("&Map"), map_menu),

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26