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_file, get_system_proj_file, \ |
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 |
|
DEFAULT_PROJ_FILE, EPSG_PROJ_FILE |
26 |
from Thuban.UI.dialogs import NonModalNonParentDialog |
from Thuban.UI.dialogs import NonModalNonParentDialog |
27 |
|
|
28 |
from common import ThubanBeginBusyCursor, ThubanEndBusyCursor |
from common import ThubanBeginBusyCursor, ThubanEndBusyCursor |
67 |
self.haveTried = False |
self.haveTried = False |
68 |
self.curProjPanel = None |
self.curProjPanel = None |
69 |
self.__usrProjFile = None |
self.__usrProjFile = None |
70 |
self.__sysProjFile = None |
self._sys_proj_files = {} |
71 |
|
|
72 |
self.build_dialog() |
self.build_dialog() |
73 |
self.Layout() |
self.Layout() |
95 |
|
|
96 |
hbox = wxBoxSizer(wxHORIZONTAL) |
hbox = wxBoxSizer(wxHORIZONTAL) |
97 |
vbox.Add(hbox, 1, wxALL|wxEXPAND) |
vbox.Add(hbox, 1, wxALL|wxEXPAND) |
98 |
self.projection_list = ProjectionList(self, self.load_system_proj(), |
proj_files = [self.load_user_proj(), |
99 |
self.load_user_proj(), |
self.load_system_proj(DEFAULT_PROJ_FILE)] |
100 |
|
self.projection_list = ProjectionList(self, proj_files, |
101 |
self.receiver.GetProjection()) |
self.receiver.GetProjection()) |
102 |
hbox.Add(self.projection_list, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4) |
hbox.Add(self.projection_list, 1, wxALL|wxEXPAND|wxADJUST_MINSIZE, 4) |
103 |
self.projection_list.Subscribe(PROJ_SELECTION_CHANGED, |
self.projection_list.Subscribe(PROJ_SELECTION_CHANGED, |
117 |
EVT_BUTTON(self, ID_PROJ_REMOVE, self._OnRemove) |
EVT_BUTTON(self, ID_PROJ_REMOVE, self._OnRemove) |
118 |
buttons.Add(self.button_remove, 1, wxALL|wxEXPAND, 4) |
buttons.Add(self.button_remove, 1, wxALL|wxEXPAND, 4) |
119 |
|
|
120 |
|
self.check_epsg = wxCheckBox(self, -1, _("Show EPSG")) |
121 |
|
EVT_CHECKBOX(self, self.check_epsg.GetId(), self._OnShowEPSG) |
122 |
|
buttons.Add(self.check_epsg, 1, wxALL|wxEXPAND, 4) |
123 |
|
|
124 |
# The file path |
# The file path |
125 |
self.projfilepath = wxStaticText(self, -1, "") |
self.projfilepath = wxStaticText(self, -1, "") |
126 |
vbox.Add(self.projfilepath, 0, wxALL|wxEXPAND) |
vbox.Add(self.projfilepath, 0, wxALL|wxEXPAND) |
355 |
if modified: |
if modified: |
356 |
self.write_proj_file(self.__usrProjFile) |
self.write_proj_file(self.__usrProjFile) |
357 |
|
|
358 |
|
def _OnShowEPSG(self, event): |
359 |
|
"""Handler for the EVT_CHECKBOX events from the EPSG check button |
360 |
|
|
361 |
|
If the button is checked add the EPSG_PROJ_FILE to the list of |
362 |
|
projfiles shown by the projection list. Otherwise remove it |
363 |
|
""" |
364 |
|
if self.check_epsg.IsChecked(): |
365 |
|
proj_files = [self.load_user_proj(), |
366 |
|
self.load_system_proj(DEFAULT_PROJ_FILE), |
367 |
|
self.load_system_proj(EPSG_PROJ_FILE)] |
368 |
|
else: |
369 |
|
proj_files = [self.load_user_proj(), |
370 |
|
self.load_system_proj(DEFAULT_PROJ_FILE)] |
371 |
|
self.projection_list.SetProjFiles(proj_files) |
372 |
|
|
373 |
def _OnProjName(self, event): |
def _OnProjName(self, event): |
374 |
self.__VerifyButtons() |
self.__VerifyButtons() |
375 |
|
|
564 |
return None |
return None |
565 |
|
|
566 |
def load_user_proj(self): |
def load_user_proj(self): |
567 |
ThubanBeginBusyCursor() |
"""Return the user's ProjFile |
568 |
try: |
|
569 |
if self.__usrProjFile is None: |
If the file has not yet been loaded by the dialog, load it first |
570 |
|
with get_user_proj_file and cache it in self.__usrProjFile. |
571 |
|
|
572 |
|
Show a busy cursor while loading the file. |
573 |
|
""" |
574 |
|
if self.__usrProjFile is None: |
575 |
|
ThubanBeginBusyCursor() |
576 |
|
try: |
577 |
projfile, warnings = get_user_proj_file() |
projfile, warnings = get_user_proj_file() |
578 |
self.show_warnings(_("Warnings"), projfile.GetFilename(), |
self.show_warnings(_("Warnings"), projfile.GetFilename(), |
579 |
warnings) |
warnings) |
580 |
self.__usrProjFile = projfile |
self.__usrProjFile = projfile |
581 |
return self.__usrProjFile |
finally: |
582 |
finally: |
ThubanEndBusyCursor() |
583 |
ThubanEndBusyCursor() |
return self.__usrProjFile |
584 |
|
|
585 |
def load_system_proj(self): |
def load_system_proj(self, name): |
586 |
ThubanBeginBusyCursor() |
"""Load the system ProjFile with the given name. |
587 |
try: |
|
588 |
if self.__sysProjFile is None: |
If the file has not been loaded yet, load it first with |
589 |
projfile, warnings = get_system_proj_file() |
get_system_proj_file and put it into the cache. The name is |
590 |
|
simply forwarded to get_system_proj_file. |
591 |
|
|
592 |
|
Show a busy cursor while loading the file. |
593 |
|
""" |
594 |
|
if name not in self._sys_proj_files: |
595 |
|
ThubanBeginBusyCursor() |
596 |
|
try: |
597 |
|
projfile, warnings = get_system_proj_file(name) |
598 |
self.show_warnings(_("Warnings"), projfile.GetFilename(), |
self.show_warnings(_("Warnings"), projfile.GetFilename(), |
599 |
warnings) |
warnings) |
600 |
self.__sysProjFile = projfile |
self._sys_proj_files[name] = projfile |
601 |
return self.__sysProjFile |
finally: |
602 |
finally: |
ThubanEndBusyCursor() |
603 |
ThubanEndBusyCursor() |
return self._sys_proj_files[name] |
604 |
|
|
605 |
def write_proj_file(self, proj_file): |
def write_proj_file(self, proj_file): |
606 |
"""Write the ProjFile object proj_file back to its file |
"""Write the ProjFile object proj_file back to its file |