/[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 1619 by bh, Fri Jul 18 18:20:40 2003 UTC revision 1620 by bh, Wed Aug 20 13:14:22 2003 UTC
# Line 28  import Thuban.version Line 28  import Thuban.version
28  from Thuban import _  from Thuban import _
29  from Thuban.Model.session import create_empty_session  from Thuban.Model.session import create_empty_session
30  from Thuban.Model.layer import Layer, RasterLayer  from Thuban.Model.layer import Layer, RasterLayer
31    from Thuban.Model.postgisdb import PostGISShapeStore
32  # XXX: replace this by  # XXX: replace this by
33  # from wxPython.lib.dialogs import wxMultipleChoiceDialog  # from wxPython.lib.dialogs import wxMultipleChoiceDialog
34  # 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 49  from about import About
49    
50  from Thuban.UI.dock import DockFrame  from Thuban.UI.dock import DockFrame
51  from Thuban.UI.join import JoinDialog  from Thuban.UI.join import JoinDialog
52    from Thuban.UI.dbdialog import DBFrame, ChooseDBTableDialog
53  import resource  import resource
54  import Thuban.Model.resource  import Thuban.Model.resource
55    
# Line 445  class MainWindow(DockFrame): Line 445  class MainWindow(DockFrame):
445          dlg.ShowModal()          dlg.ShowModal()
446          dlg.Destroy()          dlg.Destroy()
447    
448        def DatabaseManagement(self):
449            name = "dbmanagement"
450            dialog = self.get_open_dialog(name)
451            if dialog is None:
452                map = self.canvas.Map()
453                dialog = DBFrame(self, name, self.application.Session())
454                self.add_dialog(name, dialog)
455                dialog.Show()
456            dialog.Raise()
457    
458      def AddLayer(self):      def AddLayer(self):
459          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",
460                             wxOPEN)                             wxOPEN)
# Line 490  class MainWindow(DockFrame): Line 500  class MainWindow(DockFrame):
500                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
501          dlg.Destroy()          dlg.Destroy()
502    
503        def AddDBLayer(self):
504            """Add a layer read from a database"""
505            session = self.application.Session()
506            dlg = ChooseDBTableDialog(self.application.Session(), self,-1, "")
507    
508            if dlg.ShowModal() == wxID_OK:
509                dbconn, dbtable = dlg.GetTable()
510                try:
511                    title = str(dbtable)
512    
513                    # Chose the correct Interface for the database type
514                    store = PostGISShapeStore(dbconn, dbtable)
515                    session.AddShapeStore(store)
516                    layer = Layer(title, store)
517                except:
518                    # Some error occured while initializing the layer
519                    self.RunMessageBox(_("Add Layer from database"),
520                                       _("Can't open the database table '%s'")
521                                       % dbtable)
522    
523                map = self.canvas.Map()
524    
525                has_layers = map.HasLayers()
526                map.AddLayer(layer)
527                if not has_layers:
528                    self.canvas.FitMapToWindow()
529    
530            dlg.Destroy()
531    
532      def RemoveLayer(self):      def RemoveLayer(self):
533          layer = self.current_layer()          layer = self.current_layer()
534          if layer is not None:          if layer is not None:
# Line 926  def _has_gdal_support(context): Line 965  def _has_gdal_support(context):
965      """Return True if the GDAL is available"""      """Return True if the GDAL is available"""
966      return Thuban.Model.resource.has_gdal_support()      return Thuban.Model.resource.has_gdal_support()
967    
968    def _has_dbconnections(context):
969        """Return whether the the session has database connections"""
970        return context.session.HasDBConnections()
971    
972  # File menu  # File menu
973  _method_command("new_session", _("&New Session"), "NewSession",  _method_command("new_session", _("&New Session"), "NewSession",
974                  helptext = _("Start a new session"))                  helptext = _("Start a new session"))
# Line 941  _method_command("toggle_session_tree", _ Line 984  _method_command("toggle_session_tree", _
984  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
985                  checked = _has_legend_shown,                  checked = _has_legend_shown,
986                  helptext = _("Toggle Legend on/off"))                  helptext = _("Toggle Legend on/off"))
987    _method_command("database_management", _("&Database Connections..."),
988                    "DatabaseManagement")
989  _method_command("exit", _("E&xit"), "Exit",  _method_command("exit", _("E&xit"), "Exit",
990                  helptext = _("Finish working with Thuban"))                  helptext = _("Finish working with Thuban"))
991    
# Line 990  _method_command("layer_add", _("&Add Lay Line 1035  _method_command("layer_add", _("&Add Lay
1035  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
1036                  helptext = _("Add a new image layer to the map"),                  helptext = _("Add a new image layer to the map"),
1037                  sensitive = _has_gdal_support)                  sensitive = _has_gdal_support)
1038    _method_command("layer_add_db", _("Add &Database Layer..."), "AddDBLayer",
1039                    helptext = _("Add a new database layer to active map"),
1040                    sensitive = _has_dbconnections)
1041  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
1042                  helptext = _("Remove selected layer"),                  helptext = _("Remove selected layer"),
1043                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
# Line 1065  _method_command("table_join", _("&Join.. Line 1113  _method_command("table_join", _("&Join..
1113                  helptext = _("Join two tables creating a new one"))                  helptext = _("Join two tables creating a new one"))
1114    
1115  #  Export only under Windows ...  #  Export only under Windows ...
1116  map_menu = ["layer_add", "rasterlayer_add", "layer_remove",  map_menu = ["layer_add", "layer_add_db", "rasterlayer_add", "layer_remove",
1117                          None,                          None,
1118                          "map_rename",                          "map_rename",
1119                          "map_projection",                          "map_projection",
1120                          None,                          None,
1121                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
1122                          "map_pan_tool",                          "map_pan_tool",
1123                          "map_full_extent",                          "map_full_extent",
1124                          "layer_full_extent",                          "layer_full_extent",
1125                          "selected_full_extent",                          "selected_full_extent",
1126                          None,                          None,
# Line 1089  main_menu = Menu("<main>", "<main>", Line 1137  main_menu = Menu("<main>", "<main>",
1137                   [Menu("file", _("&File"),                   [Menu("file", _("&File"),
1138                         ["new_session", "open_session", None,                         ["new_session", "open_session", None,
1139                          "save_session", "save_session_as", None,                          "save_session", "save_session_as", None,
1140                            "database_management", None,
1141                          "toggle_session_tree", None,                          "toggle_session_tree", None,
1142                          "exit"]),                          "exit"]),
1143                    Menu("map", _("&Map"), map_menu),                    Menu("map", _("&Map"), map_menu),

Legend:
Removed from v.1619  
changed lines
  Added in v.1620

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26