/[thuban]/branches/WIP-pyshapelib-bramz/Extensions/ogr/ogrstart.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Extensions/ogr/ogrstart.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2549 by nhueffme, Wed Jan 26 09:17:01 2005 UTC revision 2559 by nhueffme, Tue Feb 8 09:52:56 2005 UTC
# Line 10  __version__ = "$Revision$" Line 10  __version__ = "$Revision$"
10  # $Id$  # $Id$
11    
12  # Needed wx-toolkit classes  # Needed wx-toolkit classes
13    #from wxPython.wx import *
14  from wxPython.wx import wxFileDialog, wxOPEN, wxMULTIPLE, wxID_OK, \  from wxPython.wx import wxFileDialog, wxOPEN, wxMULTIPLE, wxID_OK, \
15          wxOK, wxICON_HAND          wxOK, wxICON_HAND
16    
# Line 26  from Thuban.UI.dbdialog import DBDialog Line 27  from Thuban.UI.dbdialog import DBDialog
27  from Extensions.ogr import ogrshapes, ogrdialog  from Extensions.ogr import ogrshapes, ogrdialog
28  from Extensions.ogr.ogrdialog import ChooseOGRDBTableDialog  from Extensions.ogr.ogrdialog import ChooseOGRDBTableDialog
29    
30    from Thuban.UI.menu import Menu
31    
32  def open_with_ogr(context):  def open_with_ogr(context):
33      '''Open a file supported by ogr.      '''Open a file supported by ogr.
34      '''      '''
# Line 49  def open_with_ogr(context): Line 52  def open_with_ogr(context):
52                  layername = layerDlg.GetLayer()                  layername = layerDlg.GetLayer()
53              try:              try:
54                  session = context.application.Session()                  session = context.application.Session()
55                  store = ogrshapes.OGRShapeStore(session, filename, layername)                  store = ogrshapes.OGRShapeStore(filename, layername)
56                  session.AddShapeStore(store)                  session.AddShapeStore(store)
57              except:              except:
58                  # the layer couldn't be opened                  # the layer couldn't be opened
# Line 87  def open_db(context): Line 90  def open_db(context):
90    
91      canvas = context.mainwindow.canvas      canvas = context.mainwindow.canvas
92      map = canvas.Map()      map = canvas.Map()
93        
94      session = context.application.Session()      session = context.application.Session()
95      dlg = ChooseOGRDBTableDialog(canvas, session)      dlg = ChooseOGRDBTableDialog(canvas, session)
96    
# Line 98  def open_db(context): Line 101  def open_db(context):
101              filename = ('PG: host=%s user=%s dbname=%s port=%s'              filename = ('PG: host=%s user=%s dbname=%s port=%s'
102                          %(dbconn.host, dbconn.user, dbconn.dbname, dbconn.port))                          %(dbconn.host, dbconn.user, dbconn.dbname, dbconn.port))
103    
104              store = ogrshapes.OGRShapeStore(session, filename, dbtable)              store = ogrshapes.OGRShapeStore(filename, dbtable)
105              session.AddShapeStore(store)              session.AddShapeStore(store)
106    
107              layer = Layer(dbtable, store)              layer = Layer(dbtable, store)
# Line 124  from Thuban.UI.command import registry, Line 127  from Thuban.UI.command import registry,
127  # See Thuban/UI/menu.py for the API of the Menu class  # See Thuban/UI/menu.py for the API of the Menu class
128  from Thuban.UI.mainwindow import main_menu  from Thuban.UI.mainwindow import main_menu
129    
130    
131    # find the map menu (create it a new if not found)
132    map_menu = main_menu.FindOrInsertMenu('map', _('Map'))
133    ogr_menu = Menu("ogr", _("Open layer via OGR"),[])
134    
135    
136  # create new commands and register them  # create new commands and register them
137  registry.Add(Command('open_ogr_files', 'Open an ogr-file', open_with_ogr,  registry.Add(Command('open_ogr_files', 'Open an ogr-file', open_with_ogr,
138                       helptext = 'Open a file supported from ogr'))                       helptext = 'Open a file supported from ogr'))
139    
140  # find the ogr menu (create it a new if not found)  registry.Add(Command('select_file_format', 'Select a file format',
 ogr_menu = main_menu.FindOrInsertMenu('ogr', _('OGR'))  
 registry.Add(Command('select_file_format', 'Select a file format',  
141                       select_file_format,                       select_file_format,
142                       helptext = "Select a file format supported from ogr"))                       helptext = "Select a file format supported from ogr"))
143    
# Line 139  registry.Add(Command('open_db', 'Open a Line 146  registry.Add(Command('open_db', 'Open a
146                       helptext = "Open a layer from a database, e.g. PostGIS"))                       helptext = "Open a layer from a database, e.g. PostGIS"))
147    
148  # finally bind the new command with an entry in the extensions menu  # finally bind the new command with an entry in the extensions menu
149  ogr_menu.InsertItem('open_ogr_files')  ogr_menu.InsertItem("open_ogr_files")
150  ogr_menu.InsertItem('select_file_format')  ogr_menu.InsertItem('select_file_format')
151  ogr_menu.InsertItem('open_db')  ogr_menu.InsertItem('open_db')
152    
153    # Add ogr menu to map menu
154    map_menu.InsertItem(ogr_menu, after = "rasterlayer_add")
155    

Legend:
Removed from v.2549  
changed lines
  Added in v.2559

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26