1 |
frank |
2446 |
# Copyright (c) 2004 by Intevation GmbH |
2 |
|
|
# Authors: |
3 |
|
|
# Frank Koormann <[email protected]> |
4 |
|
|
# |
5 |
|
|
# This program is free software under the GPL (>=v2) |
6 |
|
|
# Read the file COPYING coming with Thuban for details. |
7 |
|
|
|
8 |
|
|
|
9 |
|
|
"""Dialogs for alternative paths (path recovery). |
10 |
|
|
|
11 |
|
|
AltPathFileDialog: File dialog to specify alterative path. |
12 |
|
|
AltPathConfirmDialog: Confirm or cancel alternative path suggestion. |
13 |
|
|
""" |
14 |
|
|
|
15 |
|
|
from Thuban import _ |
16 |
|
|
|
17 |
|
|
from wxPython.wx import wxFileDialog, wxMessageDialog, wxOPEN, \ |
18 |
|
|
wxYES_NO, wxYES_DEFAULT, wxICON_INFORMATION, \ |
19 |
|
|
wxID_OK, wxID_YES |
20 |
|
|
|
21 |
|
|
import os |
22 |
|
|
|
23 |
|
|
class AltPathFileDialog(wxFileDialog): |
24 |
|
|
|
25 |
|
|
def __init__(self, filename): |
26 |
|
|
msg = _("Select an alternative data file for %s" % \ |
27 |
|
|
os.path.basename(filename)) |
28 |
|
|
|
29 |
|
|
wxFileDialog.__init__(self, None, |
30 |
|
|
msg, |
31 |
|
|
os.path.dirname(filename), |
32 |
|
|
os.path.basename(filename), |
33 |
|
|
_("Shapefiles (*.shp)") + "|*.shp;*.SHP|" + |
34 |
|
|
_("All Files (*.*)") + "|*.*", |
35 |
|
|
wxOPEN) |
36 |
|
|
|
37 |
|
|
def RunDialog(self): |
38 |
|
|
val = self.ShowModal() |
39 |
|
|
self.Destroy() |
40 |
|
|
if val == wxID_OK: |
41 |
|
|
return self.GetPaths()[0] |
42 |
|
|
else: |
43 |
|
|
return None |
44 |
|
|
|
45 |
|
|
class AltPathConfirmDialog(wxMessageDialog): |
46 |
|
|
|
47 |
|
|
def __init__(self, filename): |
48 |
|
|
self.filename = filename |
49 |
|
|
msg = _("Found the following as an alternative for %s.\n%s\n\n Please confirm with Yes or select alternative with No." % (os.path.basename(filename), filename)) |
50 |
|
|
|
51 |
|
|
wxMessageDialog.__init__(self, None, msg, _("Alternative Path"), |
52 |
|
|
wxYES_NO|wxYES_DEFAULT|wxICON_INFORMATION) |
53 |
|
|
|
54 |
|
|
def RunDialog(self): |
55 |
|
|
val = self.ShowModal() |
56 |
|
|
self.Destroy() |
57 |
|
|
if val == wxID_YES: |
58 |
|
|
return self.filename |
59 |
|
|
else: |
60 |
|
|
dlg = AltPathFileDialog(self.filename) |
61 |
|
|
fname = dlg.RunDialog() |
62 |
|
|
return fname |