39 |
|
|
40 |
class MainWindow(wxFrame): |
class MainWindow(wxFrame): |
41 |
|
|
42 |
def __init__(self, parent, ID): |
def __init__(self, parent, ID, interactor): |
43 |
wxFrame.__init__(self, parent, ID, 'Thuban', |
wxFrame.__init__(self, parent, ID, 'Thuban', |
44 |
wxDefaultPosition, wxSize(400, 300)) |
wxDefaultPosition, wxSize(400, 300)) |
45 |
|
|
97 |
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", |
98 |
"map_identify_tool", "map_label_tool"]: |
"map_identify_tool", "map_label_tool"]: |
99 |
self.add_toolbar_command(toolbar, name) |
self.add_toolbar_command(toolbar, name) |
100 |
|
# call Realize to make sure that the tools appear. |
101 |
|
toolbar.Realize() |
102 |
|
|
103 |
# Create the map canvas |
# Create the map canvas |
104 |
canvas = view.MapCanvas(self, -1) |
canvas = view.MapCanvas(self, -1, interactor) |
105 |
self.canvas = canvas |
self.canvas = canvas |
106 |
|
|
107 |
EVT_CLOSE(self, self.OnClose) |
EVT_CLOSE(self, self.OnClose) |
177 |
command = registry.Command(self.id_to_name[event.GetId()]) |
command = registry.Command(self.id_to_name[event.GetId()]) |
178 |
if command is not None: |
if command is not None: |
179 |
event.Enable(command.Sensitive(self)) |
event.Enable(command.Sensitive(self)) |
|
event.Check(command.Checked(self)) |
|
180 |
event.SetText(command.DynText(self)) |
event.SetText(command.DynText(self)) |
181 |
|
if command.IsCheckCommand(): |
182 |
|
event.Check(command.Checked(self)) |
183 |
|
|
184 |
|
def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION): |
185 |
|
"""Run a modla message box with the given text, title and flags |
186 |
|
and return the result""" |
187 |
|
dlg = wxMessageDialog(self, text, title, flags) |
188 |
|
result = dlg.ShowModal() |
189 |
|
dlg.Destroy() |
190 |
|
return result |
191 |
|
|
192 |
def NewSession(self): |
def NewSession(self): |
193 |
session = Session("") |
session = Session("") |
221 |
flags = wxYES_NO | wxICON_QUESTION |
flags = wxYES_NO | wxICON_QUESTION |
222 |
if event.CanVeto(): |
if event.CanVeto(): |
223 |
flags = flags | wxCANCEL |
flags = flags | wxCANCEL |
224 |
dlg = wxMessageDialog(self, |
result = self.RunMessageBox("Exit", |
225 |
("The session has been modified." |
("The session has been modified." |
226 |
" Do you want to save it?"), |
" Do you want to save it?"), |
227 |
"Exit", flags) |
flags) |
|
result = dlg.ShowModal() |
|
|
dlg.Destroy() |
|
228 |
if result == wxID_YES: |
if result == wxID_YES: |
229 |
self.SaveSession() |
self.SaveSession() |
230 |
elif result == wxID_CANCEL: |
elif result == wxID_CANCEL: |
239 |
self.canvas.SetMap(map) |
self.canvas.SetMap(map) |
240 |
|
|
241 |
def About(self): |
def About(self): |
242 |
dlg = wxMessageDialog(self, |
self.RunMessageBox("About", |
243 |
("Thuban is a program for\n" |
("Thuban is a program for\n" |
244 |
"exploring geographic data.\n" |
"exploring geographic data.\n" |
245 |
"Copyright (C) 2001 Intevation GmbH.\n" |
"Copyright (C) 2001 Intevation GmbH.\n" |
246 |
"Thuban is licensed under the GPL"), |
"Thuban is licensed under the GPL"), |
247 |
"About", wxOK | wxICON_INFORMATION) |
wxOK | wxICON_INFORMATION) |
|
dlg.ShowModal() |
|
|
dlg.Destroy() |
|
248 |
|
|
249 |
def AddLayer(self): |
def AddLayer(self): |
250 |
dlg = wxFileDialog(self, "Select a session file", ".", "", "*.*", |
dlg = wxFileDialog(self, "Select a session file", ".", "", "*.*", |
253 |
filename = dlg.GetPath() |
filename = dlg.GetPath() |
254 |
title = os.path.splitext(os.path.basename(filename))[0] |
title = os.path.splitext(os.path.basename(filename))[0] |
255 |
layer = Layer(title, filename) |
layer = Layer(title, filename) |
256 |
self.canvas.Map().AddLayer(layer) |
map = self.canvas.Map() |
257 |
|
has_layers = map.HasLayers() |
258 |
|
try: |
259 |
|
map.AddLayer(layer) |
260 |
|
except IOError: |
261 |
|
# the layer couldn't be opened |
262 |
|
self.RunMessageBox("Add Layer", |
263 |
|
"Can't open the file '%s'." % filename) |
264 |
|
else: |
265 |
|
if not has_layers: |
266 |
|
# if we're adding a layer to an empty map, for the |
267 |
|
# new map to the window |
268 |
|
self.canvas.FitMapToWindow() |
269 |
dlg.Destroy() |
dlg.Destroy() |
270 |
|
|
271 |
def RemoveLayer(self): |
def RemoveLayer(self): |
272 |
layer = self.current_layer() |
layer = self.current_layer() |
273 |
if layer is not None: |
if layer is not None: |
274 |
self.canvas.Map().RemoveLayer(layer) |
self.canvas.Map().RemoveLayer(layer) |
|
else: |
|
|
dlg = wxMessageDialog(self, "No layer is selected.\n", |
|
|
"Remove layer", wxOK | wxICON_INFORMATION) |
|
|
dlg.ShowModal() |
|
|
dlg.Destroy() |
|
275 |
|
|
276 |
def RaiseLayer(self): |
def RaiseLayer(self): |
277 |
layer = self.current_layer() |
layer = self.current_layer() |