13 |
# $Source$ |
# $Source$ |
14 |
# $Id$ |
# $Id$ |
15 |
|
|
16 |
import os, sys, math |
import os |
17 |
from wxPython.wx import * |
from wxPython.wx import * |
18 |
|
|
19 |
from Thuban import _ |
from Thuban import _ |
20 |
|
|
21 |
from Thuban.Model.proj import Projection, ProjFile |
from Thuban.Model.proj import Projection, ProjFile |
22 |
|
|
23 |
from Thuban.Model.resource import get_user_proj_files, get_system_proj_files, \ |
from Thuban.Model.resource import get_user_proj_file, get_system_proj_file, \ |
24 |
read_proj_file, write_proj_file |
read_proj_file, write_proj_file |
25 |
from Thuban.UI.dialogs import NonModalNonParentDialog |
from Thuban.UI.dialogs import NonModalNonParentDialog |
26 |
|
|
207 |
def _OnProjAvail(self, event): |
def _OnProjAvail(self, event): |
208 |
self.__DoOnProjAvail() |
self.__DoOnProjAvail() |
209 |
|
|
210 |
|
def show_warnings(self, title, filename, warnings): |
211 |
|
"""Show the warnings (a list of strings) in a dialog |
212 |
|
|
213 |
|
If the list is empty no dialog will be shown. |
214 |
|
""" |
215 |
|
if warnings: |
216 |
|
text = (_('Warnings when reading "%s":\n\n%s') |
217 |
|
% (filename, "\n\n".join(warnings))) |
218 |
|
self.parent.RunMessageBox(title, text) |
219 |
|
|
220 |
def _OnImport(self, event): |
def _OnImport(self, event): |
221 |
|
|
222 |
dlg = wxFileDialog(self, _("Import"), style = wxOPEN) |
dlg = wxFileDialog(self, _("Import"), style = wxOPEN) |
225 |
path = dlg.GetPath() |
path = dlg.GetPath() |
226 |
|
|
227 |
try: |
try: |
228 |
projFile = read_proj_file(path) |
projFile, warnings = read_proj_file(path) |
229 |
|
self.show_warnings(_("Warnings"), path, warnings) |
230 |
for proj in projFile.GetProjections(): |
for proj in projFile.GetProjections(): |
231 |
self.__usrProjFile.Add(proj) |
self.__usrProjFile.Add(proj) |
232 |
write_proj_file(self.__usrProjFile) |
write_proj_file(self.__usrProjFile) |
511 |
# |
# |
512 |
self.availprojs.Append("<None>", (None, None)) |
self.availprojs.Append("<None>", (None, None)) |
513 |
|
|
514 |
projfile = get_system_proj_files() |
projfile, warnings = get_system_proj_file() |
515 |
projfile = projfile[0] |
self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings) |
516 |
for proj in projfile.GetProjections(): |
for proj in projfile.GetProjections(): |
517 |
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
518 |
self.__sysProjFile = projfile |
self.__sysProjFile = projfile |
519 |
|
|
520 |
projfile = get_user_proj_files() |
projfile, warnings = get_user_proj_file() |
521 |
projfile = projfile[0] |
self.show_warnings(_("Warnings"), projfile.GetFilename(), warnings) |
522 |
for proj in projfile.GetProjections(): |
for proj in projfile.GetProjections(): |
523 |
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
self.availprojs.Append(proj.GetName(), [proj, projfile]) |
524 |
self.__usrProjFile = projfile |
self.__usrProjFile = projfile |
709 |
def _DoLayout(self): |
def _DoLayout(self): |
710 |
sizer = wxBoxSizer(wxVERTICAL) |
sizer = wxBoxSizer(wxVERTICAL) |
711 |
|
|
712 |
sizer.Add(wxStaticText(self, -1, |
sizer.Add(wxStaticText(self, -1, |
713 |
_("Thuban does not know the parameters for the " + |
_("Thuban does not know the parameters for the" |
714 |
"current projection and cannot display a " + |
" current projection and cannot display a" |
715 |
"configuration panel."))) |
" configuration panel."))) |
716 |
|
|
717 |
ProjPanel._DoLayout(self, sizer) |
ProjPanel._DoLayout(self, sizer) |
718 |
|
|
984 |
ID_UTM_PROPOSE_ZONE_DIALOG_TAKE = 4001 |
ID_UTM_PROPOSE_ZONE_DIALOG_TAKE = 4001 |
985 |
ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002 |
ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL = 4002 |
986 |
class UTMProposeZoneDialog(wxDialog): |
class UTMProposeZoneDialog(wxDialog): |
987 |
|
|
988 |
"""Propose a sensible Zone considering the current map extent.""" |
"""Propose a sensible Zone considering the current map extent.""" |
989 |
|
|
990 |
def __init__(self, parent, (x, y, x2, y2)): |
def __init__(self, parent, (x, y, x2, y2)): |
991 |
wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"), |
wxDialog.__init__(self, parent, -1, _("Projection: Propose UTM Zone"), |
992 |
wxDefaultPosition, wxSize(200, 100)) |
wxDefaultPosition, wxSize(200, 100)) |
996 |
center = (x2 - x) / 2 + x |
center = (x2 - x) / 2 + x |
997 |
self.proposedZone = int(center / 6 + 1) |
self.proposedZone = int(center / 6 + 1) |
998 |
self.dialogLayout() |
self.dialogLayout() |
999 |
|
|
1000 |
def dialogLayout(self): |
def dialogLayout(self): |
1001 |
topBox = wxBoxSizer(wxVERTICAL) |
topBox = wxBoxSizer(wxVERTICAL) |
1002 |
|
|
1003 |
textBox = wxBoxSizer(wxVERTICAL) |
textBox = wxBoxSizer(wxVERTICAL) |
1004 |
textBox.Add(wxStaticText(self, -1, _("The current map extent center " + |
textBox.Add(wxStaticText(self, -1, _("The current map extent center " |
1005 |
"lies in UTM Zone")), |
"lies in UTM Zone")), |
1006 |
0, wxALIGN_CENTER|wxALL, 4) |
0, wxALIGN_CENTER|wxALL, 4) |
1007 |
textBox.Add(wxStaticText(self, -1, str(self.proposedZone)), |
textBox.Add(wxStaticText(self, -1, str(self.proposedZone)), |
1008 |
0, wxALIGN_CENTER|wxALL, 4) |
0, wxALIGN_CENTER|wxALL, 4) |
1009 |
|
|
1010 |
topBox.Add(textBox, 1, wxEXPAND|wxALL, 4) |
topBox.Add(textBox, 1, wxEXPAND|wxALL, 4) |
1011 |
|
|
1012 |
buttonBox = wxBoxSizer(wxHORIZONTAL) |
buttonBox = wxBoxSizer(wxHORIZONTAL) |
1013 |
buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, |
buttonBox.Add(wxButton(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, |
1014 |
_("Take")), 0, wxALL, 4) |
_("Take")), 0, wxALL, 4) |
1017 |
topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10) |
topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10) |
1018 |
EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake) |
EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_TAKE, self.OnTake) |
1019 |
EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel) |
EVT_BUTTON(self, ID_UTM_PROPOSE_ZONE_DIALOG_CANCEL, self.OnCancel) |
1020 |
|
|
1021 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
1022 |
self.SetSizer(topBox) |
self.SetSizer(topBox) |
1023 |
topBox.Fit(self) |
topBox.Fit(self) |
1024 |
topBox.SetSizeHints(self) |
topBox.SetSizeHints(self) |
1025 |
|
|
1026 |
def OnTake(self, event): |
def OnTake(self, event): |
1027 |
self.EndModal(wxID_OK) |
self.EndModal(wxID_OK) |
1028 |
|
|
1029 |
def OnCancel(self, event): |
def OnCancel(self, event): |
1030 |
self.EndModal(wxID_CANCEL) |
self.EndModal(wxID_CANCEL) |
1031 |
|
|