18 |
import traceback |
import traceback |
19 |
|
|
20 |
from wxPython.wx import * |
from wxPython.wx import * |
|
from wxPython.lib.dialogs import wxScrolledMessageDialog |
|
21 |
|
|
22 |
from Thuban.Lib.connector import Publisher |
from Thuban.Lib.connector import Publisher |
23 |
from Thuban.Lib.fileutil import get_application_dir |
from Thuban.Lib.fileutil import get_application_dir |
33 |
import view |
import view |
34 |
import tree |
import tree |
35 |
import mainwindow |
import mainwindow |
36 |
|
import dbdialog |
37 |
|
import exceptiondialog |
38 |
|
|
39 |
from messages import SESSION_REPLACED |
from messages import SESSION_REPLACED |
40 |
|
|
61 |
self.ShowMainWindow() |
self.ShowMainWindow() |
62 |
self.session = None |
self.session = None |
63 |
self.create_session() |
self.create_session() |
64 |
|
self.path={"data":".", "projection":"."} |
65 |
return True |
return True |
66 |
|
|
67 |
def OnExit(self): |
def OnExit(self): |
165 |
self.unsubscribe_session(oldsession) |
self.unsubscribe_session(oldsession) |
166 |
oldsession.Destroy() |
oldsession.Destroy() |
167 |
|
|
168 |
|
def SetPath(self, group, filename): |
169 |
|
"""Store the application's default path for file dialogs extracted |
170 |
|
from a given filename. |
171 |
|
""" |
172 |
|
self.path[group] = os.path.dirname( filename ) |
173 |
|
|
174 |
|
def Path(self, group): |
175 |
|
"""Return the application's default path for file dialogs.""" |
176 |
|
return self.path[group] |
177 |
|
|
178 |
def subscribe_session(self, session): |
def subscribe_session(self, session): |
179 |
"""Subscribe to some of the sessions channels. |
"""Subscribe to some of the sessions channels. |
180 |
|
|
207 |
# get problems when saving because the saving code expects an |
# get problems when saving because the saving code expects an |
208 |
# absolute directory name |
# absolute directory name |
209 |
filename = os.path.abspath(filename) |
filename = os.path.abspath(filename) |
210 |
|
if db_connection_callback is None: |
211 |
|
db_connection_callback = self.run_db_param_dialog |
212 |
try: |
try: |
213 |
session = load_session(filename, |
session = load_session(filename, |
214 |
db_connection_callback=db_connection_callback) |
db_connection_callback=db_connection_callback) |
234 |
dlg.Destroy() |
dlg.Destroy() |
235 |
break |
break |
236 |
|
|
237 |
|
def run_db_param_dialog(self, parameters, message): |
238 |
|
"""Implementation of the db_connection_callback for loading sessions""" |
239 |
|
dlg = dbdialog.DBDialog(None, _("DB Connection Parameters"), |
240 |
|
parameters, message) |
241 |
|
return dlg.RunDialog() |
242 |
|
|
243 |
|
|
244 |
def SaveSession(self): |
def SaveSession(self): |
245 |
save_session(self.session, self.session.filename) |
save_session(self.session, self.session.filename) |
246 |
|
|
247 |
def maps_changed(self, *args): |
def maps_changed(self, *args): |
248 |
|
"""Subscribed to the session's MAPS_CHANGED messages. |
249 |
|
|
250 |
|
Set the toplevel window's map to the map in the session. This is |
251 |
|
done by calling the window's SetMap method with the map as |
252 |
|
argument. If the session doesn't have any maps None is used |
253 |
|
instead. |
254 |
|
|
255 |
|
Currently Thuban can only really handle at most one map in a |
256 |
|
sessions so the first map in the session's list of maps as |
257 |
|
returned by the Maps method is used. |
258 |
|
""" |
259 |
if self.session.HasMaps(): |
if self.session.HasMaps(): |
260 |
self.top.SetMap(self.session.Maps()[0]) |
self.top.SetMap(self.session.Maps()[0]) |
261 |
else: |
else: |
281 |
try: |
try: |
282 |
lines = traceback.format_exception(exc_type, exc_value, |
lines = traceback.format_exception(exc_type, exc_value, |
283 |
exc_traceback) |
exc_traceback) |
284 |
message = "An unhandled exception occurred:\n%s\n" % exc_value+\ |
message = _("An unhandled exception occurred:\n%s\n" |
285 |
"(please report to " \ |
"(please report to" |
286 |
"http://thuban.intevation.org/bugtracker.html)"\ |
" http://thuban.intevation.org/bugtracker.html)" |
287 |
"\n\n\n"+\ |
"\n\n%s") % (exc_value, "".join(lines)) |
|
"".join(lines) |
|
288 |
print message |
print message |
289 |
|
|
290 |
# We don't use an explicit parent here because this method might |
# We don't use an explicit parent here because this method might |
291 |
# be called in circumstances where the main window doesn't exist |
# be called in circumstances where the main window doesn't exist |
292 |
# anymore. |
# anymore. |
293 |
dlg = wxScrolledMessageDialog(None, message, |
exceptiondialog.run_exception_dialog(None, message) |
|
"Thuban: Internal Error") |
|
|
dlg.ShowModal() |
|
|
dlg.Destroy() |
|
294 |
|
|
295 |
finally: |
finally: |
296 |
self.in_exception_dialog = 0 |
self.in_exception_dialog = 0 |