/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/application.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/application.py

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

revision 2445 by bh, Thu Feb 19 15:19:39 2004 UTC revision 2446 by frank, Mon Dec 13 11:52:34 2004 UTC
# Line 34  import view Line 34  import view
34  import tree  import tree
35  import mainwindow  import mainwindow
36  import dbdialog  import dbdialog
37    import altpathdialog
38  import exceptiondialog  import exceptiondialog
39    
40  from messages import SESSION_REPLACED  from messages import SESSION_REPLACED
# Line 59  class ThubanApplication(wxApp, Publisher Line 60  class ThubanApplication(wxApp, Publisher
60          # from the application.          # from the application.
61    
62          # Defaults for the directories used in file dialogs          # Defaults for the directories used in file dialogs
63          self.path={"data":".", "projection":"."}          self.path={"data":".", "projection":".", "alt_path":""}
64    
65          self.session = None          self.session = None
66          self.top = None          self.top = None
# Line 217  class ThubanApplication(wxApp, Publisher Line 218  class ThubanApplication(wxApp, Publisher
218          """          """
219          self.SetSession(create_empty_session())          self.SetSession(create_empty_session())
220    
221      def OpenSession(self, filename, db_connection_callback = None):      def OpenSession(self, filename, db_connection_callback = None,
222                                        shapefile_callback = None):
223          """Open the session in the file named filename"""          """Open the session in the file named filename"""
224          # Make sure we deal with an absolute pathname. Otherwise we can          # Make sure we deal with an absolute pathname. Otherwise we can
225          # get problems when saving because the saving code expects an          # get problems when saving because the saving code expects an
# Line 225  class ThubanApplication(wxApp, Publisher Line 227  class ThubanApplication(wxApp, Publisher
227          filename = os.path.abspath(filename)          filename = os.path.abspath(filename)
228          if db_connection_callback is None:          if db_connection_callback is None:
229              db_connection_callback = self.run_db_param_dialog              db_connection_callback = self.run_db_param_dialog
230            if shapefile_callback is None:
231                shapefile_callback = self.run_alt_path_dialog
232          try:          try:
233              session = load_session(filename,              session = load_session(filename,
234                                 db_connection_callback=db_connection_callback)                                 db_connection_callback=db_connection_callback,
235                                   shapefile_callback=shapefile_callback)
236          except LoadCancelled:          except LoadCancelled:
237              return              return
238          session.SetFilename(filename)          session.SetFilename(filename)
# Line 256  class ThubanApplication(wxApp, Publisher Line 261  class ThubanApplication(wxApp, Publisher
261                                  parameters, message)                                  parameters, message)
262          return dlg.RunDialog()          return dlg.RunDialog()
263    
264        # run_alt_path_dialog: Raise a dialog to ask for an alternative path
265        # if the shapefile couldn't be found.
266        # TODO:
267        #   - Store a list of already used alternative paths and return these
268        #     iteratively (using a generator)
269        #   - How do we interact with the user to tell him we used a different
270        #     shapefile (location), mode "check"? The current approach with the
271        #     file dialog is not that comfortable.
272        #
273        def run_alt_path_dialog(self, filename, mode = None, second_try = 0):
274            """Implemetation of the shapefile_callback while loading sessions.
275            
276               This implements two modes:
277               - search: Search for an alternative path. If available from a
278                 list of alrady known paths, else interactivly by file dialog.
279                 Currently the "second_try" is important since else the user might
280                 be caught in a loop.
281               - check: Ask the user for confirmation, if a path from list has
282                 been found successful.
283    
284               Returns:
285               - fname: The full path to the (shape) file.
286               - from_list: Flags if the path was taken from list or entered
287                 manually.
288            """
289    
290            if mode == "search":
291                if self.Path('alt_path') == "" or second_try:
292                    dlg = altpathdialog.AltPathFileDialog(filename)
293                    fname = dlg.RunDialog()
294                    if fname is not None:
295                        self.SetPath('alt_path', fname)    
296                    from_list = 0
297                else:
298                    fname = os.path.join(self.Path('alt_path'),
299                                         os.path.basename(filename))
300                    from_list = 1
301            elif mode == "check":
302                    dlg = altpathdialog.AltPathConfirmDialog(filename)
303                    fname = dlg.RunDialog()
304                    if fname is not None:
305                        self.SetPath('alt_path', fname)
306                    from_list = 0
307            else:
308                fname = None
309                from_list = 0
310            return fname, from_list
311    
312    
313      def SaveSession(self):      def SaveSession(self):
314          save_session(self.session, self.session.filename)          save_session(self.session, self.session.filename)

Legend:
Removed from v.2445  
changed lines
  Added in v.2446

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26