/[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 1233 by jonathan, Wed Jun 18 14:47:19 2003 UTC revision 1625 by bh, Thu Aug 21 16:02:23 2003 UTC
# Line 13  The main window Line 13  The main window
13    
14  __version__ = "$Revision$"  __version__ = "$Revision$"
15    
16  __ThubanVersion__ = "0.2" #"$THUBAN_0_2$"  __ThubanVersion__ = "0.8" #"$THUBAN_0_2$"
17  #__BuildDate__ = "$Date$"  #__BuildDate__ = "$Date$"
18    
19  import os  import os
# 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, has_postgis_support
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 43  from menu import Menu Line 43  from menu import Menu
43    
44  from context import Context  from context import Context
45  from command import registry, Command, ToolCommand  from command import registry, Command, ToolCommand
46  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION  from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, \
47         MAP_REPLACED
48    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    
56  import projdialog  import projdialog
57    
58    
59  class MainWindow(DockFrame):  class MainWindow(DockFrame):
60    
61      # Some messages that can be subscribed/unsubscribed directly through      # Some messages that can be subscribed/unsubscribed directly through
# Line 61  class MainWindow(DockFrame): Line 64  class MainWindow(DockFrame):
64      # actually come from. This delegation is implemented in the      # actually come from. This delegation is implemented in the
65      # Subscribe and unsubscribed methods      # Subscribe and unsubscribed methods
66      delegated_messages = {LAYER_SELECTED: "canvas",      delegated_messages = {LAYER_SELECTED: "canvas",
67                            SHAPES_SELECTED: "canvas"}                            SHAPES_SELECTED: "canvas",
68                              MAP_REPLACED: "canvas"}
69    
70      # Methods delegated to some instance variables. The delegation is      # Methods delegated to some instance variables. The delegation is
71      # implemented in the __getattr__ method.      # implemented in the __getattr__ method.
# Line 362  class MainWindow(DockFrame): Line 366  class MainWindow(DockFrame):
366              result = wxID_NO              result = wxID_NO
367          return result          return result
368    
     def prepare_new_session(self):  
         for d in self.dialogs.values():  
             if not isinstance(d, tree.SessionTreeView):  
                 d.Close()  
   
369      def NewSession(self):      def NewSession(self):
370          if self.save_modified_session() != wxID_CANCEL:          if self.save_modified_session() != wxID_CANCEL:
             self.prepare_new_session()  
371              self.application.SetSession(create_empty_session())              self.application.SetSession(create_empty_session())
372    
373      def OpenSession(self):      def OpenSession(self):
# Line 378  class MainWindow(DockFrame): Line 376  class MainWindow(DockFrame):
376                                 "Thuban Session File (*.thuban)|*.thuban",                                 "Thuban Session File (*.thuban)|*.thuban",
377                                 wxOPEN)                                 wxOPEN)
378              if dlg.ShowModal() == wxID_OK:              if dlg.ShowModal() == wxID_OK:
                 self.prepare_new_session()  
379                  self.application.OpenSession(dlg.GetPath())                  self.application.OpenSession(dlg.GetPath())
380              dlg.Destroy()              dlg.Destroy()
381    
# Line 444  class MainWindow(DockFrame): Line 441  class MainWindow(DockFrame):
441          return self.get_open_dialog("session_tree") is not None          return self.get_open_dialog("session_tree") is not None
442    
443      def About(self):      def About(self):
444          self.RunMessageBox(_("About"),          dlg = About(self)
445                             _("Thuban %s\n"          dlg.ShowModal()
446                              #"Build Date: %s\n"          dlg.Destroy()
447                              "using:\n"  
448                              "  %s\n"      def DatabaseManagement(self):
449                              "  %s\n\n"          name = "dbmanagement"
450                              "Thuban is a program for\n"          dialog = self.get_open_dialog(name)
451                              "exploring geographic data.\n"          if dialog is None:
452                              "Copyright (C) 2001-2003 Intevation GmbH.\n"              map = self.canvas.Map()
453                              "Thuban is licensed under the GNU GPL"              dialog = DBFrame(self, name, self.application.Session())
454                              % (Thuban.version.longversion,              self.add_dialog(name, dialog)
455                                 "wxPython %s" % wxPython_version,              dialog.Show()
456                                 "Python %d.%d.%d" % sys.version_info[:3]          dialog.Raise()
                               )),  
 #                           % __ThubanVersion__), #__BuildDate__)),  
                            wxOK | wxICON_INFORMATION)  
457    
458      def AddLayer(self):      def AddLayer(self):
459          dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*",          dlg = wxFileDialog(self, _("Select one or more data files"), ".", "",
460                             wxOPEN)                             _("Shapefiles (*.shp)") + "|*.shp|" +
461                               _("All Files (*.*)") + "|*.*",
462                               wxOPEN | wxMULTIPLE)
463          if dlg.ShowModal() == wxID_OK:          if dlg.ShowModal() == wxID_OK:
464              filename = dlg.GetPath()              filenames = dlg.GetPaths()
465              title = os.path.splitext(os.path.basename(filename))[0]              for filename in filenames:
466              map = self.canvas.Map()                  title = os.path.splitext(os.path.basename(filename))[0]
467              has_layers = map.HasLayers()                  map = self.canvas.Map()
468              try:                  has_layers = map.HasLayers()
469                  store = self.application.Session().OpenShapefile(filename)                  try:
470              except IOError:                      store = self.application.Session().OpenShapefile(filename)
471                  # the layer couldn't be opened                  except IOError:
472                  self.RunMessageBox(_("Add Layer"),                      # the layer couldn't be opened
473                                     _("Can't open the file '%s'.") % filename)                      self.RunMessageBox(_("Add Layer"),
474              else:                                         _("Can't open the file '%s'.")%filename)
475                  layer = Layer(title, store)                  else:
476                  map.AddLayer(layer)                      layer = Layer(title, store)
477                  if not has_layers:                      map.AddLayer(layer)
478                      # if we're adding a layer to an empty map, fit the                      if not has_layers:
479                      # new map to the window                          # if we're adding a layer to an empty map, fit the
480                      self.canvas.FitMapToWindow()                          # new map to the window
481                            self.canvas.FitMapToWindow()
482          dlg.Destroy()          dlg.Destroy()
483    
484      def AddRasterLayer(self):      def AddRasterLayer(self):
# Line 506  class MainWindow(DockFrame): Line 503  class MainWindow(DockFrame):
503                      self.canvas.FitMapToWindow()                      self.canvas.FitMapToWindow()
504          dlg.Destroy()          dlg.Destroy()
505    
506        def AddDBLayer(self):
507            """Add a layer read from a database"""
508            session = self.application.Session()
509            dlg = ChooseDBTableDialog(self.application.Session(), self,-1, "")
510    
511            if dlg.ShowModal() == wxID_OK:
512                dbconn, dbtable = dlg.GetTable()
513                try:
514                    title = str(dbtable)
515    
516                    # Chose the correct Interface for the database type
517                    store = PostGISShapeStore(dbconn, dbtable)
518                    session.AddShapeStore(store)
519                    layer = Layer(title, store)
520                except:
521                    # Some error occured while initializing the layer
522                    self.RunMessageBox(_("Add Layer from database"),
523                                       _("Can't open the database table '%s'")
524                                       % dbtable)
525    
526                map = self.canvas.Map()
527    
528                has_layers = map.HasLayers()
529                map.AddLayer(layer)
530                if not has_layers:
531                    self.canvas.FitMapToWindow()
532    
533            dlg.Destroy()
534    
535      def RemoveLayer(self):      def RemoveLayer(self):
536          layer = self.current_layer()          layer = self.current_layer()
537          if layer is not None:          if layer is not None:
# Line 674  class MainWindow(DockFrame): Line 700  class MainWindow(DockFrame):
700          else:          else:
701              dialog.Show(not dialog.IsShown())              dialog.Show(not dialog.IsShown())
702    
         self.canvas.FitMapToWindow()  
   
703      def LegendShown(self):      def LegendShown(self):
704          """Return true iff the legend is currently open"""          """Return true iff the legend is currently open"""
705          dialog = self.FindRegisteredDock("legend")          dialog = self.FindRegisteredDock("legend")
# Line 751  class MainWindow(DockFrame): Line 775  class MainWindow(DockFrame):
775                                                 table)                                                 table)
776              self.add_dialog(name, dialog)              self.add_dialog(name, dialog)
777              dialog.Show(True)              dialog.Show(True)
778          # FIXME: else bring dialog to front          dialog.Raise()
779    
780      def TableRename(self):      def TableRename(self):
781          """Let the user rename a table"""          """Let the user rename a table"""
# Line 944  def _has_gdal_support(context): Line 968  def _has_gdal_support(context):
968      """Return True if the GDAL is available"""      """Return True if the GDAL is available"""
969      return Thuban.Model.resource.has_gdal_support()      return Thuban.Model.resource.has_gdal_support()
970    
971    def _has_dbconnections(context):
972        """Return whether the the session has database connections"""
973        return context.session.HasDBConnections()
974    
975    def _has_postgis_support(context):
976        return has_postgis_support()
977    
978    
979  # File menu  # File menu
980  _method_command("new_session", _("&New Session"), "NewSession",  _method_command("new_session", _("&New Session"), "NewSession",
981                  helptext = _("Start a new session"))                  helptext = _("Start a new session"))
# Line 959  _method_command("toggle_session_tree", _ Line 991  _method_command("toggle_session_tree", _
991  _method_command("toggle_legend", _("Legend"), "ToggleLegend",  _method_command("toggle_legend", _("Legend"), "ToggleLegend",
992                  checked = _has_legend_shown,                  checked = _has_legend_shown,
993                  helptext = _("Toggle Legend on/off"))                  helptext = _("Toggle Legend on/off"))
994    _method_command("database_management", _("&Database Connections..."),
995                    "DatabaseManagement",
996                    sensitive = _has_postgis_support)
997  _method_command("exit", _("E&xit"), "Exit",  _method_command("exit", _("E&xit"), "Exit",
998                  helptext = _("Finish working with Thuban"))                  helptext = _("Finish working with Thuban"))
999    
# Line 1008  _method_command("layer_add", _("&Add Lay Line 1043  _method_command("layer_add", _("&Add Lay
1043  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",  _method_command("rasterlayer_add", _("&Add Image Layer..."), "AddRasterLayer",
1044                  helptext = _("Add a new image layer to the map"),                  helptext = _("Add a new image layer to the map"),
1045                  sensitive = _has_gdal_support)                  sensitive = _has_gdal_support)
1046    _method_command("layer_add_db", _("Add &Database Layer..."), "AddDBLayer",
1047                    helptext = _("Add a new database layer to active map"),
1048                    sensitive = _has_dbconnections)
1049  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",  _method_command("layer_remove", _("&Remove Layer"), "RemoveLayer",
1050                  helptext = _("Remove selected layer"),                  helptext = _("Remove selected layer"),
1051                  sensitive = _can_remove_layer)                  sensitive = _can_remove_layer)
# Line 1083  _method_command("table_join", _("&Join.. Line 1121  _method_command("table_join", _("&Join..
1121                  helptext = _("Join two tables creating a new one"))                  helptext = _("Join two tables creating a new one"))
1122    
1123  #  Export only under Windows ...  #  Export only under Windows ...
1124  map_menu = ["layer_add", "rasterlayer_add", "layer_remove",  map_menu = ["layer_add", "layer_add_db", "rasterlayer_add", "layer_remove",
1125                          None,                          None,
1126                          "map_rename",                          "map_rename",
1127                          "map_projection",                          "map_projection",
1128                          None,                          None,
1129                          "map_zoom_in_tool", "map_zoom_out_tool",                          "map_zoom_in_tool", "map_zoom_out_tool",
1130                          "map_pan_tool",                          "map_pan_tool",
1131                          "map_full_extent",                          "map_full_extent",
1132                          "layer_full_extent",                          "layer_full_extent",
1133                          "selected_full_extent",                          "selected_full_extent",
1134                          None,                          None,
# Line 1107  main_menu = Menu("<main>", "<main>", Line 1145  main_menu = Menu("<main>", "<main>",
1145                   [Menu("file", _("&File"),                   [Menu("file", _("&File"),
1146                         ["new_session", "open_session", None,                         ["new_session", "open_session", None,
1147                          "save_session", "save_session_as", None,                          "save_session", "save_session_as", None,
1148                            "database_management", None,
1149                          "toggle_session_tree", None,                          "toggle_session_tree", None,
1150                          "exit"]),                          "exit"]),
1151                    Menu("map", _("&Map"), map_menu),                    Menu("map", _("&Map"), map_menu),
# Line 1142  main_toolbar = Menu("<toolbar>", "<toolb Line 1181  main_toolbar = Menu("<toolbar>", "<toolb
1181                       "selected_full_extent",                       "selected_full_extent",
1182                       None,                       None,
1183                       "map_identify_tool", "map_label_tool"])                       "map_identify_tool", "map_label_tool"])
1184    

Legend:
Removed from v.1233  
changed lines
  Added in v.1625

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26