1 |
# Copyright (C) 2001 by Intevation GmbH |
# Copyright (C) 2001, 2002 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Jan-Oliver Wagner <[email protected]> |
# Jan-Oliver Wagner <[email protected]> |
4 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
30 |
|
|
31 |
import main |
import main |
32 |
from command import registry, Command |
from command import registry, Command |
33 |
from messages import SELECTED_SHAPE |
from messages import SELECTED_SHAPE, VIEW_POSITION |
34 |
|
|
35 |
|
|
36 |
# the directory where the toolbar icons are stored |
# the directory where the toolbar icons are stored |
104 |
toolbar.SetToolBitmapSize(wxSize(24, 24)) |
toolbar.SetToolBitmapSize(wxSize(24, 24)) |
105 |
|
|
106 |
for name in ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
for name in ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
107 |
"map_identify_tool", "map_label_tool"]: |
"map_identify_tool", "map_label_tool", "map_full_extent"]: |
108 |
self.add_toolbar_command(toolbar, name) |
self.add_toolbar_command(toolbar, name) |
109 |
# call Realize to make sure that the tools appear. |
# call Realize to make sure that the tools appear. |
110 |
toolbar.Realize() |
toolbar.Realize() |
111 |
|
|
112 |
# Create the map canvas |
# Create the map canvas |
113 |
canvas = view.MapCanvas(self, -1, interactor) |
canvas = view.MapCanvas(self, -1, interactor) |
114 |
|
canvas.Subscribe(VIEW_POSITION, self.view_position_changed) |
115 |
self.canvas = canvas |
self.canvas = canvas |
116 |
|
|
117 |
self.init_dialogs() |
self.init_dialogs() |
224 |
def get_open_dialog(self, name): |
def get_open_dialog(self, name): |
225 |
return self.dialogs.get(name) |
return self.dialogs.get(name) |
226 |
|
|
227 |
|
def view_position_changed(self): |
228 |
|
pos = self.canvas.CurrentPosition() |
229 |
|
if pos is not None: |
230 |
|
text = "(%10.10g, %10.10g)" % pos |
231 |
|
else: |
232 |
|
text = "" |
233 |
|
self.SetStatusText(text) |
234 |
|
|
235 |
def save_modified_session(self, can_veto = 1): |
def save_modified_session(self, can_veto = 1): |
236 |
"""If the current session has been modified, ask the user |
"""If the current session has been modified, ask the user |
237 |
whether to save it and do so if requested. Return the outcome of |
whether to save it and do so if requested. Return the outcome of |
262 |
def OpenSession(self): |
def OpenSession(self): |
263 |
self.save_modified_session() |
self.save_modified_session() |
264 |
dlg = wxFileDialog(self, "Select a session file", ".", "", |
dlg = wxFileDialog(self, "Select a session file", ".", "", |
265 |
"*.session", wxOPEN) |
"*.thuban", wxOPEN) |
266 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
267 |
main.app.OpenSession(dlg.GetPath()) |
main.app.OpenSession(dlg.GetPath()) |
268 |
dlg.Destroy() |
dlg.Destroy() |
269 |
|
|
270 |
def SaveSession(self): |
def SaveSession(self): |
271 |
|
if main.app.session.filename == None: |
272 |
|
self.SaveSessionAs() |
273 |
main.app.SaveSession() |
main.app.SaveSession() |
274 |
|
|
275 |
def SaveSessionAs(self): |
def SaveSessionAs(self): |
276 |
dlg = wxFileDialog(self, "Enter a filename for session", ".", "", |
dlg = wxFileDialog(self, "Enter a filename for session", ".", "", |
277 |
"*.session", wxOPEN) |
"*.thuban", wxOPEN) |
278 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
279 |
main.app.session.SetFilename(dlg.GetPath()) |
main.app.session.SetFilename(dlg.GetPath()) |
280 |
main.app.SaveSession() |
main.app.SaveSession() |
313 |
wxOK | wxICON_INFORMATION) |
wxOK | wxICON_INFORMATION) |
314 |
|
|
315 |
def AddLayer(self): |
def AddLayer(self): |
316 |
dlg = wxFileDialog(self, "Select a session file", ".", "", "*.*", |
dlg = wxFileDialog(self, "Select a data file", ".", "", "*.*", |
317 |
wxOPEN) |
wxOPEN) |
318 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
319 |
filename = dlg.GetPath() |
filename = dlg.GetPath() |
430 |
map = self.canvas.Map() |
map = self.canvas.Map() |
431 |
proj = map.projection |
proj = map.projection |
432 |
if proj is None: |
if proj is None: |
433 |
proj4Dlg = proj4dialog.Proj4Dialog(NULL, None) |
proj4Dlg = proj4dialog.Proj4Dialog(NULL, None, map.BoundingBox()) |
434 |
else: |
else: |
435 |
proj4Dlg = proj4dialog.Proj4Dialog(NULL, map.projection.params) |
proj4Dlg = proj4dialog.Proj4Dialog(NULL, map.projection.params, |
436 |
|
map.BoundingBox()) |
437 |
if proj4Dlg.ShowModal() == wxID_OK: |
if proj4Dlg.ShowModal() == wxID_OK: |
438 |
params = proj4Dlg.GetParams() |
params = proj4Dlg.GetParams() |
439 |
if params is not None: |
if params is not None: |
486 |
"""Call the context's method methodname with args *args""" |
"""Call the context's method methodname with args *args""" |
487 |
apply(getattr(context, methodname), args) |
apply(getattr(context, methodname), args) |
488 |
|
|
489 |
def _method_command(name, title, method, helptext = "", sensitive = None): |
def _method_command(name, title, method, helptext = "", |
490 |
|
icon = "", sensitive = None): |
491 |
"""Add a command implemented by a method of the context object""" |
"""Add a command implemented by a method of the context object""" |
492 |
registry.Add(Command(name, title, call_method, args=(method,), |
registry.Add(Command(name, title, call_method, args=(method,), |
493 |
helptext = helptext, sensitive = sensitive)) |
helptext = helptext, icon = icon, |
494 |
|
sensitive = sensitive)) |
495 |
|
|
496 |
def _tool_command(name, title, method, toolname, helptext = "", |
def _tool_command(name, title, method, toolname, helptext = "", |
497 |
icon = ""): |
icon = ""): |
498 |
"""Add a tool command""" |
"""Add a tool command""" |
530 |
helptext = "Switch to map-mode 'identify'", icon = "identify") |
helptext = "Switch to map-mode 'identify'", icon = "identify") |
531 |
_tool_command("map_label_tool", "&Label", "LabelTool", "LabelTool", |
_tool_command("map_label_tool", "&Label", "LabelTool", "LabelTool", |
532 |
helptext = "Add/Remove labels", icon = "label") |
helptext = "Add/Remove labels", icon = "label") |
533 |
_method_command("map_full_extent", "&Full extent", "FullExtent") |
_method_command("map_full_extent", "&Full extent", "FullExtent", |
534 |
|
helptext = "Full Extent", icon = "fullextent") |
535 |
_method_command("map_print", "Prin&t", "PrintMap", helptext = "Print the map") |
_method_command("map_print", "Prin&t", "PrintMap", helptext = "Print the map") |
536 |
|
|
537 |
# Layer menu |
# Layer menu |