/[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 1695 by bh, Mon Sep 1 12:45:07 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
20    
21  from wxPython.wx import *  from wxPython.wx import *
 from wxPython.wx import __version__ as wxPython_version  
22    
23  import Thuban  import Thuban
 import Thuban.version  
24    
25  from Thuban import _  from Thuban import _
26  from Thuban.Model.session import create_empty_session  from Thuban.Model.session import create_empty_session
27  from Thuban.Model.layer import Layer, RasterLayer  from Thuban.Model.layer import Layer, RasterLayer
28    from Thuban.Model.postgisdb import PostGISShapeStore, has_postgis_support
29  # XXX: replace this by  # XXX: replace this by
30  # from wxPython.lib.dialogs import wxMultipleChoiceDialog  # from wxPython.lib.dialogs import wxMultipleChoiceDialog
31  # 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 46  from about import About
46    
47  from Thuban.UI.dock import DockFrame  from Thuban.UI.dock import DockFrame
48  from Thuban.UI.join import JoinDialog  from Thuban.UI.join import JoinDialog
49    from Thuban.UI.dbdialog import DBFrame, DBDialog, ChooseDBTableDialog
50  import resource  import resource
51  import Thuban.Model.resource  import Thuban.Model.resource
52    
# Line 376  class MainWindow(DockFrame): Line 373  class MainWindow(DockFrame):
373                                 "Thuban Session File (*.thuban)|*.thuban",                                 "Thuban Session File (*.thuban)|*.thuban",
374                                 wxOPEN)                                 wxOPEN)
375              if dlg.ShowModal() == wxID_OK:              if dlg.ShowModal() == wxID_OK:
376                  self.application.OpenSession(dlg.GetPath())                  self.application.OpenSession(dlg.GetPath(),
377                                                 self.run_db_param_dialog)
378              dlg.Destroy()              dlg.Destroy()
379    
380        def run_db_param_dialog(self, parameters, message):
381            dlg = DBDialog(self, _("DB Connection Parameters"), parameters,
382                           message)
383            return dlg.RunDialog()
384    
385      def SaveSession(self):      def SaveSession(self):
386          if self.application.session.filename == None:          if self.application.session.filename == None:
387              self.SaveSessionAs()              self.SaveSessionAs()
# Line 445  class MainWindow(DockFrame): Line 448  class MainWindow(DockFrame):
448          dlg.ShowModal()          dlg.ShowModal()
449          dlg.Destroy()          dlg.Destroy()
450    
451        def DatabaseManagement(self):
452            name = "dbmanagement"
453            dialog = self.get_open_dialog(name)
454            if dialog is None:
455                map = self.canvas.Map()
456                dialog = DBFrame(self, name, self.application.Session())
457                self.add_dialog(name, dialog)
458                dialog.Show()
459            dialog.Raise()
460    
461      def AddLayer(self):      def AddLayer(self):
462          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",          dlg = wxFileDialog(self, _("Select one or more data files"), ".", "",
463                             wxOPEN)                             _("Shapefiles (*.shp)") + "|*.shp|" +
464                               _("All Files (*.*)") + "|*.*",
465                               wxOPEN | wxMULTIPLE)
466          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
467              filename = dlg.GetPath()              filenames = dlg.GetPaths()
468              title = os.path.splitext(os.path.basename(filename))[0]              for filename in filenames:
469              map = self.canvas.Map()                  title = os.path.splitext(os.path.basename(filename))[0]
470              has_layers = map.HasLayers()                  map = self.canvas.Map()
471              try:                  has_layers = map.HasLayers()
472                  store = self.application.Session().OpenShapefile(filename)                  try:
473              except IOError:                      store = self.application.Session().OpenShapefile(filename)
474                  # the layer couldn't be opened                  except IOError:
475                  self.RunMessageBox(_("Add Layer"),                      # the layer couldn't be opened
476                                     _("Can't open the file '%s'.") % filename)                      self.RunMessageBox(_("Add Layer"),
477              else:                                         _("Can't open the file '%s'.")%filename)
478                  layer = Layer(title, store)                  else:
479                  map.AddLayer(layer)                      layer = Layer(title, store)
480                  if not has_layers:                      map.AddLayer(layer)
481                      # if we're adding a layer to an empty map, fit the                      if not has_layers:
482                      # new map to the window                          # if we're adding a layer to an empty map, fit the
483                      self.canvas.FitMapToWindow()                          # new map to the window
484                            self.canvas.FitMapToWindow()
485          dlg.Destroy()          dlg.Destroy()
486    
487      def AddRasterLayer(self):      def AddRasterLayer(self):
# Line 490  class MainWindow(DockFrame): Line 506  class MainWindow(DockFrame):
506                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
507          dlg.Destroy()          dlg.Destroy()
508    
509        def AddDBLayer(self):
510            """Add a layer read from a database"""
511            session = self.application.Session()
512            dlg = ChooseDBTableDialog(self, self.application.Session())
513    
514            if dlg.ShowModal() == wxID_OK:
515                dbconn, dbtable = dlg.GetTable()
516                try:
517                    title = str(dbtable)
518    
519                    # Chose the correct Interface for the database type
520                    store = PostGISShapeStore(dbconn, dbtable)
521                    session.AddShapeStore(store)
522                    layer = Layer(title, store)
523                except:
524                    # Some error occured while initializing the layer
525                    self.RunMessageBox(_("Add Layer from database"),
526                                       _("Can't open the database table '%s'")
527                                       % dbtable)
528    
529                map = self.canvas.Map()
530    
531                has_layers = map.HasLayers()
532                map.AddLayer(layer)
533                if not has_layers:
534                    self.canvas.FitMapToWindow()
535    
536            dlg.Destroy()
537    
538      def RemoveLayer(self):      def RemoveLayer(self):
539          layer = self.current_layer()          layer = self.current_layer()
540          if layer is not None:          if layer is not None:
# Line 926  def _has_gdal_support(context): Line 971  def _has_gdal_support(context):
971      """Return True if the GDAL is available"""      """Return True if the GDAL is available"""
972      return Thuban.Model.resource.has_gdal_support()      return Thuban.Model.resource.has_gdal_support()
973    
974    def _has_dbconnections(context):
975        """Return whether the the session has database connections"""
976        return context.session.HasDBConnections()
977    
978    def _has_postgis_support(context):
979        return has_postgis_support()
980    
981    
982  # File menu  # File menu
983  _method_command("new_session", _("&New Session"), "NewSession",  _method_command("new_session", _("&New Session"), "NewSession",
984                  helptext = _("Start a new session"))                  helptext = _("Start a new session"))
# Line 941  _method_command("toggle_session_tree", _ Line 994  _method_command("toggle_session_tree", _
994  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
995                  checked = _has_legend_shown,                  checked = _has_legend_shown,
996                  helptext = _("Toggle Legend on/off"))                  helptext = _("Toggle Legend on/off"))
997    _method_command("database_management", _("&Database Connections..."),
998                    "DatabaseManagement",
999                    sensitive = _has_postgis_support)
1000  _method_command("exit", _("E&xit"), "Exit",  _method_command("exit", _("E&xit"), "Exit",
1001                  helptext = _("Finish working with Thuban"))                  helptext = _("Finish working with Thuban"))
1002    
# Line 990  _method_command("layer_add", _("&Add Lay Line 1046  _method_command("layer_add", _("&Add Lay
1046  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
1047                  helptext = _("Add a new image layer to the map"),                  helptext = _("Add a new image layer to the map"),
1048                  sensitive = _has_gdal_support)                  sensitive = _has_gdal_support)
1049    _method_command("layer_add_db", _("Add &Database Layer..."), "AddDBLayer",
1050                    helptext = _("Add a new database layer to active map"),
1051                    sensitive = _has_dbconnections)
1052  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
1053                  helptext = _("Remove selected layer"),                  helptext = _("Remove selected layer"),
1054                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
# Line 1065  _method_command("table_join", _("&Join.. Line 1124  _method_command("table_join", _("&Join..
1124                  helptext = _("Join two tables creating a new one"))                  helptext = _("Join two tables creating a new one"))
1125    
1126  #  Export only under Windows ...  #  Export only under Windows ...
1127  map_menu = ["layer_add", "rasterlayer_add", "layer_remove",  map_menu = ["layer_add", "layer_add_db", "rasterlayer_add", "layer_remove",
1128                          None,                          None,
1129                          "map_rename",                          "map_rename",
1130                          "map_projection",                          "map_projection",
1131                          None,                          None,
1132                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
1133                          "map_pan_tool",                          "map_pan_tool",
1134                          "map_full_extent",                          "map_full_extent",
1135                          "layer_full_extent",                          "layer_full_extent",
1136                          "selected_full_extent",                          "selected_full_extent",
1137                          None,                          None,
# Line 1089  main_menu = Menu("<main>", "<main>", Line 1148  main_menu = Menu("<main>", "<main>",
1148                   [Menu("file", _("&File"),                   [Menu("file", _("&File"),
1149                         ["new_session", "open_session", None,                         ["new_session", "open_session", None,
1150                          "save_session", "save_session_as", None,                          "save_session", "save_session_as", None,
1151                            "database_management", None,
1152                          "toggle_session_tree", None,                          "toggle_session_tree", None,
1153                          "exit"]),                          "exit"]),
1154                    Menu("map", _("&Map"), map_menu),                    Menu("map", _("&Map"), map_menu),

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26