1 |
# Copyright (C) 2001, 2002 by Intevation GmbH |
# Copyright (C) 2001, 2002, 2003 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]> |
12 |
|
|
13 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
14 |
|
|
15 |
|
__ThubanVersion__ = "0.2" #"$THUBAN_0_2$" |
16 |
|
#__BuildDate__ = "$Date$" |
17 |
|
|
18 |
import os |
import os |
19 |
|
|
20 |
from wxPython.wx import * |
from wxPython.wx import * |
21 |
|
|
22 |
import Thuban |
import Thuban |
23 |
|
from Thuban import _ |
24 |
from Thuban.Model.session import create_empty_session |
from Thuban.Model.session import create_empty_session |
25 |
from Thuban.Model.layer import Layer |
from Thuban.Model.layer import Layer |
26 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Color |
30 |
import tree |
import tree |
31 |
import proj4dialog |
import proj4dialog |
32 |
import tableview, identifyview |
import tableview, identifyview |
33 |
|
import classifier |
34 |
|
import legend |
35 |
from menu import Menu |
from menu import Menu |
36 |
|
|
37 |
from context import Context |
from context import Context |
38 |
from command import registry, Command |
from command import registry, Command, ToolCommand |
39 |
from messages import SELECTED_SHAPE, VIEW_POSITION |
from messages import LAYER_SELECTED, SHAPES_SELECTED, VIEW_POSITION, DOCKABLE_DOCKED, DOCKABLE_UNDOCKED, DOCKABLE_CLOSED |
40 |
|
|
41 |
|
from Thuban.UI.dock import DockableWindow, DockFrame, DockPanel |
42 |
|
|
43 |
|
|
44 |
# the directory where the toolbar icons are stored |
# the directory where the toolbar icons are stored |
45 |
bitmapdir = os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Bitmaps") |
bitmapdir = os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Bitmaps") |
46 |
bitmapext = ".xpm" |
bitmapext = ".xpm" |
47 |
|
|
48 |
|
ID_WINDOW_LEGEND = 4001 |
49 |
|
ID_WINDOW_CANVAS = 4002 |
50 |
|
|
51 |
|
|
52 |
class MainWindow(wxFrame): |
class MainWindow(DockFrame): |
53 |
|
|
54 |
|
# Some messages that can be subscribed/unsubscribed directly through |
55 |
|
# the MapCanvas come in fact from other objects. This is a map to |
56 |
|
# map those messages to the names of the instance variables they |
57 |
|
# actually come from. This delegation is implemented in the |
58 |
|
# Subscribe and unsubscribed methods |
59 |
|
delegated_messages = {LAYER_SELECTED: "canvas", |
60 |
|
SHAPES_SELECTED: "canvas"} |
61 |
|
|
62 |
|
# Methods delegated to some instance variables. The delegation is |
63 |
|
# implemented in the __getattr__ method. |
64 |
|
delegated_methods = {"SelectLayer": "canvas", |
65 |
|
"SelectShapes": "canvas", |
66 |
|
} |
67 |
|
|
68 |
def __init__(self, parent, ID, title, application, interactor, |
def __init__(self, parent, ID, title, application, interactor, |
69 |
initial_message = None, size = wxSize(-1, -1)): |
initial_message = None, size = wxSize(-1, -1)): |
70 |
wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size) |
DockFrame.__init__(self, parent, ID, title, wxDefaultPosition, size) |
71 |
|
#wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, size) |
72 |
|
|
73 |
self.application = application |
self.application = application |
|
self.interactor = interactor |
|
74 |
|
|
75 |
self.CreateStatusBar() |
self.CreateStatusBar() |
76 |
if initial_message: |
if initial_message: |
88 |
# call Realize to make sure that the tools appear. |
# call Realize to make sure that the tools appear. |
89 |
toolbar.Realize() |
toolbar.Realize() |
90 |
|
|
91 |
|
|
92 |
# Create the map canvas |
# Create the map canvas |
93 |
canvas = view.MapCanvas(self, -1, interactor) |
canvas = view.MapCanvas(self, -1) |
94 |
canvas.Subscribe(VIEW_POSITION, self.view_position_changed) |
canvas.Subscribe(VIEW_POSITION, self.view_position_changed) |
95 |
|
canvas.Subscribe(SHAPES_SELECTED, self.identify_view_on_demand) |
96 |
self.canvas = canvas |
self.canvas = canvas |
97 |
|
|
98 |
|
self.SetMainWindow(self.canvas) |
99 |
|
|
100 |
|
self.SetAutoLayout(True) |
101 |
|
|
102 |
self.init_dialogs() |
self.init_dialogs() |
103 |
|
|
104 |
interactor.Subscribe(SELECTED_SHAPE, self.identify_view_on_demand) |
EVT_CLOSE(self, self._OnClose) |
105 |
|
|
106 |
EVT_CLOSE(self, self.OnClose) |
def Subscribe(self, channel, *args): |
107 |
|
"""Subscribe a function to a message channel. |
108 |
|
|
109 |
|
If channel is one of the delegated messages call the appropriate |
110 |
|
object's Subscribe method. Otherwise do nothing. |
111 |
|
""" |
112 |
|
if channel in self.delegated_messages: |
113 |
|
object = getattr(self, self.delegated_messages[channel]) |
114 |
|
object.Subscribe(channel, *args) |
115 |
|
else: |
116 |
|
print "Trying to subscribe to unsupported channel %s" % channel |
117 |
|
|
118 |
|
def Unsubscribe(self, channel, *args): |
119 |
|
"""Unsubscribe a function from a message channel. |
120 |
|
|
121 |
|
If channel is one of the delegated messages call the appropriate |
122 |
|
object's Unsubscribe method. Otherwise do nothing. |
123 |
|
""" |
124 |
|
if channel in self.delegated_messages: |
125 |
|
object = getattr(self, self.delegated_messages[channel]) |
126 |
|
object.Unsubscribe(channel, *args) |
127 |
|
|
128 |
|
def __getattr__(self, attr): |
129 |
|
"""If attr is one of the delegated methods return that method |
130 |
|
|
131 |
|
Otherwise raise AttributeError. |
132 |
|
""" |
133 |
|
if attr in self.delegated_methods: |
134 |
|
return getattr(getattr(self, self.delegated_methods[attr]), attr) |
135 |
|
raise AttributeError(attr) |
136 |
|
|
137 |
def init_ids(self): |
def init_ids(self): |
138 |
"""Initialize the ids""" |
"""Initialize the ids""" |
172 |
return menu_bar |
return menu_bar |
173 |
|
|
174 |
def build_menu(self, menudesc): |
def build_menu(self, menudesc): |
175 |
"""Build and return a wxMenu from a menudescription""" |
"""Return a wxMenu built from the menu description menudesc""" |
176 |
wxmenu = wxMenu() |
wxmenu = wxMenu() |
177 |
last = None |
last = None |
178 |
for item in menudesc.items: |
for item in menudesc.items: |
|
# here the items must all be Menu instances themselves |
|
179 |
if item is None: |
if item is None: |
180 |
# a separator. Only add one if the last item was not a |
# a separator. Only add one if the last item was not a |
181 |
# separator |
# separator |
228 |
command.IsCheckCommand()) |
command.IsCheckCommand()) |
229 |
self.bind_command_events(command, ID) |
self.bind_command_events(command, ID) |
230 |
else: |
else: |
231 |
print "Unknown command %s" % name |
print _("Unknown command %s") % name |
232 |
|
|
233 |
def add_toolbar_command(self, toolbar, name): |
def add_toolbar_command(self, toolbar, name): |
234 |
"""Add the command with name name to the toolbar toolbar. |
"""Add the command with name name to the toolbar toolbar. |
250 |
isToggle = command.IsCheckCommand()) |
isToggle = command.IsCheckCommand()) |
251 |
self.bind_command_events(command, ID) |
self.bind_command_events(command, ID) |
252 |
else: |
else: |
253 |
print "Unknown command %s" % name |
print _("Unknown command %s") % name |
254 |
|
|
255 |
|
def Context(self): |
256 |
|
"""Return the context object for a command invoked from this window |
257 |
|
""" |
258 |
|
return Context(self.application, self.application.Session(), self) |
259 |
|
|
260 |
def invoke_command(self, event): |
def invoke_command(self, event): |
261 |
name = self.id_to_name.get(event.GetId()) |
name = self.id_to_name.get(event.GetId()) |
262 |
if name is not None: |
if name is not None: |
263 |
command = registry.Command(name) |
command = registry.Command(name) |
264 |
context = Context(self.application, self.application.Session(), |
command.Execute(self.Context()) |
|
self) |
|
|
command.Execute(context) |
|
265 |
else: |
else: |
266 |
print "Unknown command ID %d" % event.GetId() |
print _("Unknown command ID %d") % event.GetId() |
267 |
|
|
268 |
def update_command_ui(self, event): |
def update_command_ui(self, event): |
269 |
#print "update_command_ui", self.id_to_name[event.GetId()] |
#print "update_command_ui", self.id_to_name[event.GetId()] |
270 |
context = Context(self.application, self.application.Session(), self) |
context = self.Context() |
271 |
command = registry.Command(self.id_to_name[event.GetId()]) |
command = registry.Command(self.id_to_name[event.GetId()]) |
272 |
if command is not None: |
if command is not None: |
273 |
event.Enable(command.Sensitive(context)) |
sensitive = command.Sensitive(context) |
274 |
|
event.Enable(sensitive) |
275 |
|
if command.IsTool() and not sensitive and command.Checked(context): |
276 |
|
# When a checked tool command is disabled deselect all |
277 |
|
# tools. Otherwise the tool would remain active but it |
278 |
|
# might lead to errors if the tools stays active. This |
279 |
|
# problem occurred in GREAT-ER and this fixes it, but |
280 |
|
# it's not clear to me whether this is really the best |
281 |
|
# way to do it (BH, 20021206). |
282 |
|
self.canvas.SelectTool(None) |
283 |
event.SetText(command.DynText(context)) |
event.SetText(command.DynText(context)) |
284 |
if command.IsCheckCommand(): |
if command.IsCheckCommand(): |
285 |
event.Check(command.Checked(context)) |
event.Check(command.Checked(context)) |
286 |
|
|
287 |
def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION): |
def RunMessageBox(self, title, text, flags = wxOK | wxICON_INFORMATION): |
288 |
"""Run a modal message box with the given text, title and flags |
"""Run a modal message box with the given text, title and flags |
289 |
and return the result""" |
and return the result""" |
290 |
dlg = wxMessageDialog(self, text, title, flags) |
dlg = wxMessageDialog(self, text, title, flags) |
291 |
|
dlg.CenterOnParent() |
292 |
result = dlg.ShowModal() |
result = dlg.ShowModal() |
293 |
dlg.Destroy() |
dlg.Destroy() |
294 |
return result |
return result |
302 |
|
|
303 |
def add_dialog(self, name, dialog): |
def add_dialog(self, name, dialog): |
304 |
if self.dialogs.has_key(name): |
if self.dialogs.has_key(name): |
305 |
raise RuntimeError("The Dialog named %s is already open" % name) |
raise RuntimeError(_("The Dialog named %s is already open") % name) |
306 |
self.dialogs[name] = dialog |
self.dialogs[name] = dialog |
307 |
|
|
308 |
def dialog_open(self, name): |
def dialog_open(self, name): |
320 |
text = "(%10.10g, %10.10g)" % pos |
text = "(%10.10g, %10.10g)" % pos |
321 |
else: |
else: |
322 |
text = "" |
text = "" |
323 |
|
self.set_position_text(text) |
324 |
|
|
325 |
|
def set_position_text(self, text): |
326 |
|
"""Set the statusbar text showing the current position. |
327 |
|
|
328 |
|
By default the text is shown in field 0 of the status bar. |
329 |
|
Override this method in derived classes to put it into a |
330 |
|
different field of the statusbar. |
331 |
|
""" |
332 |
self.SetStatusText(text) |
self.SetStatusText(text) |
333 |
|
|
334 |
def save_modified_session(self, can_veto = 1): |
def save_modified_session(self, can_veto = 1): |
344 |
flags = wxYES_NO | wxICON_QUESTION |
flags = wxYES_NO | wxICON_QUESTION |
345 |
if can_veto: |
if can_veto: |
346 |
flags = flags | wxCANCEL |
flags = flags | wxCANCEL |
347 |
result = self.RunMessageBox("Exit", |
result = self.RunMessageBox(_("Exit"), |
348 |
("The session has been modified." |
_("The session has been modified." |
349 |
" Do you want to save it?"), |
" Do you want to save it?"), |
350 |
flags) |
flags) |
351 |
if result == wxID_YES: |
if result == wxID_YES: |
354 |
result = wxID_NO |
result = wxID_NO |
355 |
return result |
return result |
356 |
|
|
357 |
|
def prepare_new_session(self): |
358 |
|
for d in self.dialogs.values(): |
359 |
|
if not isinstance(d, tree.SessionTreeView): |
360 |
|
d.Close() |
361 |
|
|
362 |
def NewSession(self): |
def NewSession(self): |
363 |
self.save_modified_session() |
self.save_modified_session() |
364 |
|
self.prepare_new_session() |
365 |
self.application.SetSession(create_empty_session()) |
self.application.SetSession(create_empty_session()) |
366 |
|
|
367 |
def OpenSession(self): |
def OpenSession(self): |
368 |
self.save_modified_session() |
self.save_modified_session() |
369 |
dlg = wxFileDialog(self, "Select a session file", ".", "", |
dlg = wxFileDialog(self, _("Open Session"), ".", "", "*.thuban", wxOPEN) |
|
"*.thuban", wxOPEN) |
|
370 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
371 |
|
self.prepare_new_session() |
372 |
self.application.OpenSession(dlg.GetPath()) |
self.application.OpenSession(dlg.GetPath()) |
373 |
dlg.Destroy() |
dlg.Destroy() |
374 |
|
|
375 |
def SaveSession(self): |
def SaveSession(self): |
376 |
if self.application.session.filename == None: |
if self.application.session.filename == None: |
377 |
self.SaveSessionAs() |
self.SaveSessionAs() |
378 |
self.application.SaveSession() |
else: |
379 |
|
self.application.SaveSession() |
380 |
|
|
381 |
def SaveSessionAs(self): |
def SaveSessionAs(self): |
382 |
dlg = wxFileDialog(self, "Enter a filename for session", ".", "", |
dlg = wxFileDialog(self, _("Save Session As"), ".", "", |
383 |
"*.thuban", wxOPEN) |
"*.thuban", wxOPEN) |
384 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
385 |
self.application.session.SetFilename(dlg.GetPath()) |
self.application.session.SetFilename(dlg.GetPath()) |
387 |
dlg.Destroy() |
dlg.Destroy() |
388 |
|
|
389 |
def Exit(self): |
def Exit(self): |
390 |
self.Close(false) |
self.Close(False) |
391 |
|
|
392 |
def OnClose(self, event): |
def _OnClose(self, event): |
393 |
result = self.save_modified_session(can_veto = event.CanVeto()) |
result = self.save_modified_session(can_veto = event.CanVeto()) |
394 |
if result == wxID_CANCEL: |
if result == wxID_CANCEL: |
395 |
event.Veto() |
event.Veto() |
396 |
else: |
else: |
397 |
|
# FIXME: it would be better to tie the unsubscription to |
398 |
|
# wx's destroy event, but that isn't implemented for wxGTK |
399 |
|
# yet. |
400 |
|
self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed) |
401 |
|
DockFrame._OnClose(self, event) |
402 |
self.Destroy() |
self.Destroy() |
403 |
|
|
404 |
def SetMap(self, map): |
def SetMap(self, map): |
405 |
self.canvas.SetMap(map) |
self.canvas.SetMap(map) |
406 |
|
#self.legendPanel.SetMap(map) |
407 |
|
|
408 |
|
def Map(self): |
409 |
|
"""Return the map displayed by this mainwindow""" |
410 |
|
|
411 |
|
# sanity check |
412 |
|
#assert(self.canvas.Map() is self.legendPanel.GetMap()) |
413 |
|
|
414 |
|
return self.canvas.Map() |
415 |
|
|
416 |
def ShowSessionTree(self): |
def ShowSessionTree(self): |
417 |
name = "session_tree" |
name = "session_tree" |
419 |
if dialog is None: |
if dialog is None: |
420 |
dialog = tree.SessionTreeView(self, self.application, name) |
dialog = tree.SessionTreeView(self, self.application, name) |
421 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
422 |
dialog.Show(true) |
dialog.Show(True) |
423 |
else: |
else: |
424 |
# FIXME: bring dialog to front here |
# FIXME: bring dialog to front here |
425 |
pass |
pass |
426 |
|
|
427 |
|
|
428 |
def About(self): |
def About(self): |
429 |
self.RunMessageBox("About", |
self.RunMessageBox(_("About"), |
430 |
("Thuban is a program for\n" |
_("Thuban v%s\n" |
431 |
|
#"Build Date: %s\n" |
432 |
|
"\n" |
433 |
|
"Thuban is a program for\n" |
434 |
"exploring geographic data.\n" |
"exploring geographic data.\n" |
435 |
"Copyright (C) 2001 Intevation GmbH.\n" |
"Copyright (C) 2001-2003 Intevation GmbH.\n" |
436 |
"Thuban is licensed under the GPL"), |
"Thuban is licensed under the GNU GPL" |
437 |
|
% __ThubanVersion__), #__BuildDate__)), |
438 |
wxOK | wxICON_INFORMATION) |
wxOK | wxICON_INFORMATION) |
439 |
|
|
440 |
def AddLayer(self): |
def AddLayer(self): |
441 |
dlg = wxFileDialog(self, "Select a data file", ".", "", "*.*", |
dlg = wxFileDialog(self, _("Select a data file"), ".", "", "*.*", |
442 |
wxOPEN) |
wxOPEN) |
443 |
if dlg.ShowModal() == wxID_OK: |
if dlg.ShowModal() == wxID_OK: |
444 |
filename = dlg.GetPath() |
filename = dlg.GetPath() |
450 |
map.AddLayer(layer) |
map.AddLayer(layer) |
451 |
except IOError: |
except IOError: |
452 |
# the layer couldn't be opened |
# the layer couldn't be opened |
453 |
self.RunMessageBox("Add Layer", |
self.RunMessageBox(_("Add Layer"), |
454 |
"Can't open the file '%s'." % filename) |
_("Can't open the file '%s'.") % filename) |
455 |
else: |
else: |
456 |
if not has_layers: |
if not has_layers: |
457 |
# if we're adding a layer to an empty map, for the |
# if we're adding a layer to an empty map, fit the |
458 |
# new map to the window |
# new map to the window |
459 |
self.canvas.FitMapToWindow() |
self.canvas.FitMapToWindow() |
460 |
dlg.Destroy() |
dlg.Destroy() |
464 |
if layer is not None: |
if layer is not None: |
465 |
self.canvas.Map().RemoveLayer(layer) |
self.canvas.Map().RemoveLayer(layer) |
466 |
|
|
467 |
|
def CanRemoveLayer(self): |
468 |
|
"""Return true if the currently selected layer can be deleted. |
469 |
|
|
470 |
|
If no layer is selected return False. |
471 |
|
|
472 |
|
The return value of this method determines whether the remove |
473 |
|
layer command is sensitive in menu. |
474 |
|
""" |
475 |
|
layer = self.current_layer() |
476 |
|
if layer is not None: |
477 |
|
return self.canvas.Map().CanRemoveLayer(layer) |
478 |
|
return False |
479 |
|
|
480 |
def RaiseLayer(self): |
def RaiseLayer(self): |
481 |
layer = self.current_layer() |
layer = self.current_layer() |
482 |
if layer is not None: |
if layer is not None: |
492 |
|
|
493 |
If no layer is selected, return None |
If no layer is selected, return None |
494 |
""" |
""" |
495 |
return self.interactor.SelectedLayer() |
return self.canvas.SelectedLayer() |
496 |
|
|
497 |
def has_selected_layer(self): |
def has_selected_layer(self): |
498 |
"""Return true if a layer is currently selected""" |
"""Return true if a layer is currently selected""" |
499 |
return self.interactor.HasSelectedLayer() |
return self.canvas.HasSelectedLayer() |
500 |
|
|
501 |
def choose_color(self): |
def choose_color(self): |
502 |
"""Run the color selection dialog and return the selected color. |
"""Run the color selection dialog and return the selected color. |
519 |
if layer is not None: |
if layer is not None: |
520 |
color = self.choose_color() |
color = self.choose_color() |
521 |
if color is not None: |
if color is not None: |
522 |
layer.SetFill(color) |
layer.GetClassification().SetDefaultFill(color) |
523 |
|
|
524 |
def LayerTransparentFill(self): |
def LayerTransparentFill(self): |
525 |
layer = self.current_layer() |
layer = self.current_layer() |
526 |
if layer is not None: |
if layer is not None: |
527 |
layer.SetFill(None) |
layer.GetClassification().SetDefaultFill(Color.Transparent) |
528 |
|
|
529 |
def LayerOutlineColor(self): |
def LayerOutlineColor(self): |
530 |
layer = self.current_layer() |
layer = self.current_layer() |
531 |
if layer is not None: |
if layer is not None: |
532 |
color = self.choose_color() |
color = self.choose_color() |
533 |
if color is not None: |
if color is not None: |
534 |
layer.SetStroke(color) |
layer.GetClassification().SetDefaultLineColor(color) |
535 |
|
|
536 |
def LayerNoOutline(self): |
def LayerNoOutline(self): |
537 |
layer = self.current_layer() |
layer = self.current_layer() |
538 |
if layer is not None: |
if layer is not None: |
539 |
layer.SetStroke(None) |
layer.GetClassification().SetDefaultLineColor(Color.Transparent) |
540 |
|
|
541 |
def HideLayer(self): |
def HideLayer(self): |
542 |
layer = self.current_layer() |
layer = self.current_layer() |
555 |
name = "table_view" + str(id(table)) |
name = "table_view" + str(id(table)) |
556 |
dialog = self.get_open_dialog(name) |
dialog = self.get_open_dialog(name) |
557 |
if dialog is None: |
if dialog is None: |
558 |
dialog = tableview.TableFrame(self, self.interactor, name, |
dialog = tableview.LayerTableFrame(self, name, |
559 |
"Table: %s" % layer.Title(), |
_("Table: %s") % layer.Title(), |
560 |
layer, table) |
layer, table) |
561 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
562 |
dialog.Show(true) |
dialog.Show(true) |
563 |
else: |
else: |
581 |
map.SetProjection(proj) |
map.SetProjection(proj) |
582 |
proj4Dlg.Destroy() |
proj4Dlg.Destroy() |
583 |
|
|
584 |
|
def Classify(self): |
585 |
|
|
586 |
|
# |
587 |
|
# the menu option for this should only be available if there |
588 |
|
# is a current layer, so we don't need to check if the |
589 |
|
# current layer is None |
590 |
|
# |
591 |
|
|
592 |
|
layer = self.current_layer() |
593 |
|
self.OpenClassifier(layer) |
594 |
|
|
595 |
|
def OpenClassifier(self, layer, group = None): |
596 |
|
name = "classifier" + str(id(layer)) |
597 |
|
dialog = self.get_open_dialog(name) |
598 |
|
|
599 |
|
if dialog is None: |
600 |
|
dialog = classifier.Classifier(self, name, layer, group) |
601 |
|
self.add_dialog(name, dialog) |
602 |
|
dialog.Show() |
603 |
|
dialog.Raise() |
604 |
|
|
605 |
|
|
606 |
|
def ShowLegend(self): |
607 |
|
name = "legend" |
608 |
|
dialog = self.FindRegisteredDock(name) |
609 |
|
|
610 |
|
if dialog is None: |
611 |
|
title = "Legend: %s" % self.Map().Title() |
612 |
|
dialog = self.CreateDock(name, -1, title, wxLAYOUT_LEFT) |
613 |
|
legend.LegendPanel(dialog, None, self) |
614 |
|
dialog.Dock() |
615 |
|
|
616 |
|
dialog.GetPanel().SetMap(self.Map()) |
617 |
|
dialog.Show() |
618 |
|
|
619 |
def ZoomInTool(self): |
def ZoomInTool(self): |
620 |
self.canvas.ZoomInTool() |
self.canvas.ZoomInTool() |
621 |
|
|
638 |
def PrintMap(self): |
def PrintMap(self): |
639 |
self.canvas.Print() |
self.canvas.Print() |
640 |
|
|
641 |
def identify_view_on_demand(self, layer, shape): |
def identify_view_on_demand(self, layer, shapes): |
642 |
name = "identify_view" |
name = "identify_view" |
643 |
if self.canvas.CurrentTool() == "IdentifyTool": |
if self.canvas.CurrentTool() == "IdentifyTool": |
644 |
if not self.dialog_open(name): |
if not self.dialog_open(name): |
645 |
dialog = identifyview.IdentifyView(self, self.interactor, name) |
dialog = identifyview.IdentifyView(self, name) |
646 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
647 |
dialog.Show(true) |
dialog.Show(True) |
648 |
else: |
else: |
649 |
# FIXME: bring dialog to front? |
# FIXME: bring dialog to front? |
650 |
pass |
pass |
666 |
helptext = helptext, icon = icon, |
helptext = helptext, icon = icon, |
667 |
sensitive = sensitive)) |
sensitive = sensitive)) |
668 |
|
|
669 |
def _tool_command(name, title, method, toolname, helptext = "", |
def make_check_current_tool(toolname): |
670 |
icon = ""): |
"""Return a function that tests if the currently active tool is toolname |
671 |
"""Add a tool command""" |
|
672 |
|
The returned function can be called with the context and returns |
673 |
|
true iff the currently active tool's name is toolname. It's directly |
674 |
|
usable as the 'checked' callback of a command. |
675 |
|
""" |
676 |
def check_current_tool(context, name=toolname): |
def check_current_tool(context, name=toolname): |
677 |
return context.mainwindow.canvas.CurrentTool() == name |
return context.mainwindow.canvas.CurrentTool() == name |
678 |
registry.Add(Command(name, title, call_method, args=(method,), |
return check_current_tool |
679 |
helptext = helptext, icon = icon, |
|
680 |
checked = check_current_tool)) |
def _tool_command(name, title, method, toolname, helptext = "", |
681 |
|
icon = "", sensitive = None): |
682 |
|
"""Add a tool command""" |
683 |
|
registry.Add(ToolCommand(name, title, call_method, args=(method,), |
684 |
|
helptext = helptext, icon = icon, |
685 |
|
checked = make_check_current_tool(toolname), |
686 |
|
sensitive = sensitive)) |
687 |
|
|
688 |
def _has_selected_layer(context): |
def _has_selected_layer(context): |
689 |
"""Return true if a layer is selected in the context""" |
"""Return true if a layer is selected in the context""" |
690 |
return context.mainwindow.has_selected_layer() |
return context.mainwindow.has_selected_layer() |
691 |
|
|
692 |
|
def _can_remove_layer(context): |
693 |
|
return context.mainwindow.CanRemoveLayer() |
694 |
|
|
695 |
def _has_tree_window_shown(context): |
def _has_tree_window_shown(context): |
696 |
"""Return true if the tree window is shown""" |
"""Return true if the tree window is shown""" |
697 |
return context.mainwindow.get_open_dialog("session_tree") is None |
return context.mainwindow.get_open_dialog("session_tree") is None |
698 |
|
|
699 |
|
def _has_visible_map(context): |
700 |
|
"""Return true iff theres a visible map in the mainwindow. |
701 |
|
|
702 |
|
A visible map is a map with at least one visible layer.""" |
703 |
|
map = context.mainwindow.Map() |
704 |
|
if map is not None: |
705 |
|
for layer in map.Layers(): |
706 |
|
if layer.Visible(): |
707 |
|
return 1 |
708 |
|
return 0 |
709 |
|
|
710 |
|
def _has_legend_shown(context): |
711 |
|
"""Return true if the legend window is shown""" |
712 |
|
return context.mainwindow.FindRegisteredDock("legend") is None |
713 |
|
|
714 |
|
|
715 |
# File menu |
# File menu |
716 |
_method_command("new_session", "&New Session", "NewSession") |
_method_command("new_session", _("&New Session"), "NewSession") |
717 |
_method_command("open_session", "&Open Session", "OpenSession") |
_method_command("open_session", _("&Open Session"), "OpenSession") |
718 |
_method_command("save_session", "&Save Session", "SaveSession") |
_method_command("save_session", _("&Save Session"), "SaveSession") |
719 |
_method_command("save_session_as", "Save Session &As", "SaveSessionAs") |
_method_command("save_session_as", _("Save Session &As"), "SaveSessionAs") |
720 |
_method_command("show_session_tree", "Show Session &Tree", "ShowSessionTree", |
_method_command("show_session_tree", _("Session &Tree"), "ShowSessionTree", |
721 |
sensitive = _has_tree_window_shown) |
sensitive = _has_tree_window_shown) |
722 |
_method_command("exit", "&Exit", "Exit") |
_method_command("show_legend", _("Legend"), "ShowLegend", |
723 |
|
sensitive = _has_legend_shown) |
724 |
|
_method_command("exit", _("E&xit"), "Exit") |
725 |
|
|
726 |
# Help menu |
# Help menu |
727 |
_method_command("help_about", "&About", "About") |
_method_command("help_about", _("&About"), "About") |
728 |
|
|
729 |
|
|
730 |
# Map menu |
# Map menu |
731 |
_method_command("map_projection", "Pro&jection", "Projection") |
_method_command("map_projection", _("Pro&jection"), "Projection") |
732 |
|
|
733 |
_tool_command("map_zoom_in_tool", "&Zoom in", "ZoomInTool", "ZoomInTool", |
_tool_command("map_zoom_in_tool", _("&Zoom in"), "ZoomInTool", "ZoomInTool", |
734 |
helptext = "Switch to map-mode 'zoom-in'", icon = "zoom_in") |
helptext = _("Switch to map-mode 'zoom-in'"), icon = "zoom_in", |
735 |
_tool_command("map_zoom_out_tool", "Zoom &out", "ZoomOutTool", "ZoomOutTool", |
sensitive = _has_visible_map) |
736 |
helptext = "Switch to map-mode 'zoom-out'", icon = "zoom_out") |
_tool_command("map_zoom_out_tool", _("Zoom &out"), "ZoomOutTool", "ZoomOutTool", |
737 |
_tool_command("map_pan_tool", "&Pan", "PanTool", "PanTool", |
helptext = _("Switch to map-mode 'zoom-out'"), icon = "zoom_out", |
738 |
helptext = "Switch to map-mode 'pan'", icon = "pan") |
sensitive = _has_visible_map) |
739 |
_tool_command("map_identify_tool", "&Identify", "IdentifyTool", "IdentifyTool", |
_tool_command("map_pan_tool", _("&Pan"), "PanTool", "PanTool", |
740 |
helptext = "Switch to map-mode 'identify'", icon = "identify") |
helptext = _("Switch to map-mode 'pan'"), icon = "pan", |
741 |
_tool_command("map_label_tool", "&Label", "LabelTool", "LabelTool", |
sensitive = _has_visible_map) |
742 |
helptext = "Add/Remove labels", icon = "label") |
_tool_command("map_identify_tool", _("&Identify"), "IdentifyTool", |
743 |
_method_command("map_full_extent", "&Full extent", "FullExtent", |
"IdentifyTool", |
744 |
helptext = "Full Extent", icon = "fullextent") |
helptext = _("Switch to map-mode 'identify'"), icon = "identify", |
745 |
_method_command("map_print", "Prin&t", "PrintMap", helptext = "Print the map") |
sensitive = _has_visible_map) |
746 |
|
_tool_command("map_label_tool", _("&Label"), "LabelTool", "LabelTool", |
747 |
|
helptext = _("Add/Remove labels"), icon = "label", |
748 |
|
sensitive = _has_visible_map) |
749 |
|
_method_command("map_full_extent", _("&Full extent"), "FullExtent", |
750 |
|
helptext = _("Full Extent"), icon = "fullextent", |
751 |
|
sensitive = _has_visible_map) |
752 |
|
_method_command("map_print", _("Prin&t"), "PrintMap", |
753 |
|
helptext = _("Print the map")) |
754 |
|
|
755 |
# Layer menu |
# Layer menu |
756 |
_method_command("layer_add", "&Add Layer", "AddLayer", |
_method_command("layer_add", _("&Add Layer"), "AddLayer", |
757 |
helptext = "Add a new layer to active map") |
helptext = _("Add a new layer to active map")) |
758 |
_method_command("layer_remove", "&Remove Layer", "RemoveLayer", |
_method_command("layer_remove", _("&Remove Layer"), "RemoveLayer", |
759 |
helptext = "Remove selected layer(s)", |
helptext = _("Remove selected layer(s)"), |
760 |
|
sensitive = _can_remove_layer) |
761 |
|
_method_command("layer_fill_color", _("&Fill Color"), "LayerFillColor", |
762 |
|
helptext = _("Set the fill color of selected layer(s)"), |
763 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
764 |
_method_command("layer_fill_color", "&Fill Color", "LayerFillColor", |
_method_command("layer_transparent_fill", _("&Transparent Fill"), |
|
helptext = "Set the fill color of selected layer(s)", |
|
|
sensitive = _has_selected_layer) |
|
|
_method_command("layer_transparent_fill", "&Transparent Fill", |
|
765 |
"LayerTransparentFill", |
"LayerTransparentFill", |
766 |
helptext = "Do not fill the selected layer(s)", |
helptext = _("Do not fill the selected layer(s)"), |
767 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
768 |
_method_command("layer_outline_color", "&Outline Color", "LayerOutlineColor", |
_method_command("layer_outline_color", _("&Outline Color"), "LayerOutlineColor", |
769 |
helptext = "Set the outline color of selected layer(s)", |
helptext = _("Set the outline color of selected layer(s)"), |
770 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
771 |
_method_command("layer_no_outline", "&No Outline", "LayerNoOutline", |
_method_command("layer_no_outline", _("&No Outline"), "LayerNoOutline", |
772 |
helptext = "Do not draw the outline of the selected layer(s)", |
helptext= _("Do not draw the outline of the selected layer(s)"), |
773 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
774 |
_method_command("layer_raise", "&Raise", "RaiseLayer", |
_method_command("layer_raise", _("&Raise"), "RaiseLayer", |
775 |
helptext = "Raise selected layer(s)", |
helptext = _("Raise selected layer(s)"), |
776 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
777 |
_method_command("layer_lower", "&Lower", "LowerLayer", |
_method_command("layer_lower", _("&Lower"), "LowerLayer", |
778 |
helptext = "Lower selected layer(s)", |
helptext = _("Lower selected layer(s)"), |
779 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
780 |
_method_command("layer_show", "&Show", "ShowLayer", |
_method_command("layer_show", _("&Show"), "ShowLayer", |
781 |
helptext = "Make selected layer(s) visible", |
helptext = _("Make selected layer(s) visible"), |
782 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
783 |
_method_command("layer_hide", "&Hide", "HideLayer", |
_method_command("layer_hide", _("&Hide"), "HideLayer", |
784 |
helptext = "Make selected layer(s) unvisible", |
helptext = _("Make selected layer(s) unvisible"), |
785 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
786 |
_method_command("layer_show_table", "Show Ta&ble", "LayerShowTable", |
_method_command("layer_show_table", _("Show Ta&ble"), "LayerShowTable", |
787 |
helptext = "Show the selected layer's table", |
helptext = _("Show the selected layer's table"), |
788 |
|
sensitive = _has_selected_layer) |
789 |
|
_method_command("layer_classifier", _("Classify"), "Classify", |
790 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |
|
|
|
791 |
|
|
792 |
# the menu structure |
# the menu structure |
793 |
main_menu = Menu("<main>", "<main>", |
main_menu = Menu("<main>", "<main>", |
794 |
[Menu("file", "&File", |
[Menu("file", _("&File"), |
795 |
["new_session", "open_session", None, |
["new_session", "open_session", None, |
796 |
"save_session", "save_session_as", None, |
"save_session", "save_session_as", None, |
797 |
"show_session_tree", None, |
"show_session_tree", |
798 |
|
"show_legend", None, |
799 |
"exit"]), |
"exit"]), |
800 |
Menu("map", "&Map", |
Menu("map", _("&Map"), |
801 |
["layer_add", "layer_remove", |
["layer_add", "layer_remove", |
802 |
None, |
None, |
803 |
"map_projection", |
"map_projection", |
808 |
"map_full_extent", |
"map_full_extent", |
809 |
None, |
None, |
810 |
"map_print"]), |
"map_print"]), |
811 |
Menu("layer", "&Layer", |
Menu("layer", _("&Layer"), |
812 |
["layer_fill_color", "layer_transparent_fill", |
["layer_fill_color", "layer_transparent_fill", |
813 |
"layer_outline_color", "layer_no_outline", |
"layer_outline_color", "layer_no_outline", |
814 |
None, |
None, |
816 |
None, |
None, |
817 |
"layer_show", "layer_hide", |
"layer_show", "layer_hide", |
818 |
None, |
None, |
819 |
"layer_show_table"]), |
"layer_show_table", |
820 |
Menu("help", "&Help", |
None, |
821 |
|
"layer_classifier"]), |
822 |
|
Menu("help", _("&Help"), |
823 |
["help_about"])]) |
["help_about"])]) |
824 |
|
|
825 |
# the main toolbar |
# the main toolbar |
826 |
|
|
827 |
main_toolbar = Menu("<toolbar>", "<toolbar>", |
main_toolbar = Menu("<toolbar>", "<toolbar>", |
828 |
["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
829 |
"map_identify_tool", "map_label_tool", "map_full_extent"]) |
"map_full_extent", None, |
830 |
|
"map_identify_tool", "map_label_tool"]) |