17 |
from wxPython.wx import * |
from wxPython.wx import * |
18 |
|
|
19 |
import Thuban |
import Thuban |
20 |
from Thuban.Model.session import Session |
from Thuban.Model.session import Session, create_empty_session |
21 |
from Thuban.Model.map import Map |
from Thuban.Model.map import Map |
22 |
from Thuban.Model.layer import Layer |
from Thuban.Model.layer import Layer |
23 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Color |
65 |
|
|
66 |
menu = wxMenu() |
menu = wxMenu() |
67 |
menuBar.Append(menu, "&Map"); |
menuBar.Append(menu, "&Map"); |
68 |
for name in ["map_projection", |
for name in ["layer_add", "layer_remove", |
69 |
|
None, |
70 |
|
"map_projection", |
71 |
None, |
None, |
72 |
"map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
"map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
73 |
"map_identify_tool", "map_label_tool", |
"map_identify_tool", "map_label_tool", |
79 |
|
|
80 |
menu = wxMenu() |
menu = wxMenu() |
81 |
menuBar.Append(menu, "&Layer"); |
menuBar.Append(menu, "&Layer"); |
82 |
for name in ["layer_add", "layer_remove", |
for name in ["layer_fill_color", "layer_transparent_fill", |
|
None, |
|
|
"layer_fill_color", "layer_transparent_fill", |
|
83 |
"layer_ourline_color", "layer_no_outline", |
"layer_ourline_color", "layer_no_outline", |
84 |
None, |
None, |
85 |
"layer_raise", "layer_lower", |
"layer_raise", "layer_lower", |
97 |
|
|
98 |
# toolbar |
# toolbar |
99 |
toolbar = self.CreateToolBar(wxTB_3DBUTTONS) |
toolbar = self.CreateToolBar(wxTB_3DBUTTONS) |
100 |
|
|
101 |
|
# set the size of the tools' bitmaps. Not needed on wxGTK, but |
102 |
|
# on Windows. We probably shouldn't hardwire the bitmap size |
103 |
|
# here |
104 |
|
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"]: |
108 |
self.add_toolbar_command(toolbar, name) |
self.add_toolbar_command(toolbar, name) |
223 |
def get_open_dialog(self, name): |
def get_open_dialog(self, name): |
224 |
return self.dialogs.get(name) |
return self.dialogs.get(name) |
225 |
|
|
226 |
|
def save_modified_session(self, can_veto = 1): |
227 |
|
"""If the current session has been modified, ask the user |
228 |
|
whether to save it and do so if requested. Return the outcome of |
229 |
|
the dialog (either wxID_OK, wxID_CANCEL or wxID_NO). If the |
230 |
|
dialog wasn't run return wxID_NO. |
231 |
|
|
232 |
|
If the can_veto parameter is true (default) the dialog includes |
233 |
|
a cancel button, otherwise not. |
234 |
|
""" |
235 |
|
if main.app.session.WasModified(): |
236 |
|
flags = wxYES_NO | wxICON_QUESTION |
237 |
|
if can_veto: |
238 |
|
flags = flags | wxCANCEL |
239 |
|
result = self.RunMessageBox("Exit", |
240 |
|
("The session has been modified." |
241 |
|
" Do you want to save it?"), |
242 |
|
flags) |
243 |
|
if result == wxID_YES: |
244 |
|
self.SaveSession() |
245 |
|
else: |
246 |
|
result = wxID_NO |
247 |
|
return result |
248 |
|
|
249 |
def NewSession(self): |
def NewSession(self): |
250 |
session = Session("") |
self.save_modified_session() |
251 |
session.AddMap(Map("")) |
main.app.SetSession(create_empty_session()) |
|
main.app.SetSession(session) |
|
252 |
|
|
253 |
def OpenSession(self): |
def OpenSession(self): |
254 |
|
self.save_modified_session() |
255 |
dlg = wxFileDialog(self, "Select a session file", ".", "", |
dlg = wxFileDialog(self, "Select a session file", ".", "", |
256 |
"*.session", wxOPEN) |
"*.session", wxOPEN) |
257 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
259 |
dlg.Destroy() |
dlg.Destroy() |
260 |
|
|
261 |
def SaveSession(self): |
def SaveSession(self): |
262 |
|
if main.app.session.filename == None: |
263 |
|
self.SaveSessionAs() |
264 |
main.app.SaveSession() |
main.app.SaveSession() |
265 |
|
|
266 |
def SaveSessionAs(self): |
def SaveSessionAs(self): |
275 |
self.Close(false) |
self.Close(false) |
276 |
|
|
277 |
def OnClose(self, event): |
def OnClose(self, event): |
278 |
veto = 0 |
result = self.save_modified_session(can_veto = event.CanVeto()) |
279 |
if main.app.session.WasModified(): |
if result == wxID_CANCEL: |
|
flags = wxYES_NO | wxICON_QUESTION |
|
|
if event.CanVeto(): |
|
|
flags = flags | wxCANCEL |
|
|
result = self.RunMessageBox("Exit", |
|
|
("The session has been modified." |
|
|
" Do you want to save it?"), |
|
|
flags) |
|
|
if result == wxID_YES: |
|
|
self.SaveSession() |
|
|
elif result == wxID_CANCEL: |
|
|
veto = 1 |
|
|
|
|
|
if veto: |
|
280 |
event.Veto() |
event.Veto() |
281 |
else: |
else: |
282 |
self.Destroy() |
self.Destroy() |
444 |
|
|
445 |
def IdentifyTool(self): |
def IdentifyTool(self): |
446 |
self.canvas.IdentifyTool() |
self.canvas.IdentifyTool() |
447 |
|
self.identify_view_on_demand(None, None) |
448 |
|
|
449 |
def LabelTool(self): |
def LabelTool(self): |
450 |
self.canvas.LabelTool() |
self.canvas.LabelTool() |
521 |
_method_command("map_print", "Prin&t", "PrintMap", helptext = "Print the map") |
_method_command("map_print", "Prin&t", "PrintMap", helptext = "Print the map") |
522 |
|
|
523 |
# Layer menu |
# Layer menu |
524 |
_method_command("layer_add", "&Add", "AddLayer", |
_method_command("layer_add", "&Add Layer", "AddLayer", |
525 |
helptext = "Add a new layer to active map") |
helptext = "Add a new layer to active map") |
526 |
_method_command("layer_remove", "&Remove", "RemoveLayer", |
_method_command("layer_remove", "&Remove Layer", "RemoveLayer", |
527 |
helptext = "Remove selected layer(s)", |
helptext = "Remove selected layer(s)", |
528 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
529 |
_method_command("layer_fill_color", "&Fill Color", "LayerFillColor", |
_method_command("layer_fill_color", "&Fill Color", "LayerFillColor", |