193 |
else: |
else: |
194 |
print "Unknown command %s" % name |
print "Unknown command %s" % name |
195 |
|
|
196 |
|
def Context(self): |
197 |
|
"""Return the context object for a command invoked from this window |
198 |
|
""" |
199 |
|
return Context(self.application, self.application.Session(), self) |
200 |
|
|
201 |
def invoke_command(self, event): |
def invoke_command(self, event): |
202 |
name = self.id_to_name.get(event.GetId()) |
name = self.id_to_name.get(event.GetId()) |
203 |
if name is not None: |
if name is not None: |
204 |
command = registry.Command(name) |
command = registry.Command(name) |
205 |
context = Context(self.application, self.application.Session(), |
command.Execute(self.Context()) |
|
self) |
|
|
command.Execute(context) |
|
206 |
else: |
else: |
207 |
print "Unknown command ID %d" % event.GetId() |
print "Unknown command ID %d" % event.GetId() |
208 |
|
|
209 |
def update_command_ui(self, event): |
def update_command_ui(self, event): |
210 |
#print "update_command_ui", self.id_to_name[event.GetId()] |
#print "update_command_ui", self.id_to_name[event.GetId()] |
211 |
context = Context(self.application, self.application.Session(), self) |
context = self.Context() |
212 |
command = registry.Command(self.id_to_name[event.GetId()]) |
command = registry.Command(self.id_to_name[event.GetId()]) |
213 |
if command is not None: |
if command is not None: |
214 |
event.Enable(command.Sensitive(context)) |
event.Enable(command.Sensitive(context)) |
309 |
if result == wxID_CANCEL: |
if result == wxID_CANCEL: |
310 |
event.Veto() |
event.Veto() |
311 |
else: |
else: |
312 |
|
# FIXME: it would be better to tie the unsubscription to |
313 |
|
# wx's destroy event, but that isn't implemented for wxGTK |
314 |
|
# yet. |
315 |
|
self.canvas.Unsubscribe(VIEW_POSITION, self.view_position_changed) |
316 |
self.Destroy() |
self.Destroy() |
317 |
|
|
318 |
def SetMap(self, map): |
def SetMap(self, map): |
364 |
if layer is not None: |
if layer is not None: |
365 |
self.canvas.Map().RemoveLayer(layer) |
self.canvas.Map().RemoveLayer(layer) |
366 |
|
|
367 |
|
def CanRemoveLayer(self): |
368 |
|
"""Return true if the currently selected layer can be deleted. |
369 |
|
|
370 |
|
If no layer is selected return false. |
371 |
|
|
372 |
|
The return value of this method determines whether the remove |
373 |
|
layer command is sensitive in menu. |
374 |
|
""" |
375 |
|
layer = self.current_layer() |
376 |
|
if layer is not None: |
377 |
|
return self.canvas.Map().CanRemoveLayer(layer) |
378 |
|
return 0 |
379 |
|
|
380 |
def RaiseLayer(self): |
def RaiseLayer(self): |
381 |
layer = self.current_layer() |
layer = self.current_layer() |
382 |
if layer is not None: |
if layer is not None: |
455 |
name = "table_view" + str(id(table)) |
name = "table_view" + str(id(table)) |
456 |
dialog = self.get_open_dialog(name) |
dialog = self.get_open_dialog(name) |
457 |
if dialog is None: |
if dialog is None: |
458 |
dialog = tableview.TableFrame(self, self.interactor, name, |
dialog = tableview.LayerTableFrame(self, self.interactor, name, |
459 |
"Table: %s" % layer.Title(), |
"Table: %s" % layer.Title(), |
460 |
layer, table) |
layer, table) |
461 |
self.add_dialog(name, dialog) |
self.add_dialog(name, dialog) |
462 |
dialog.Show(true) |
dialog.Show(true) |
463 |
else: |
else: |
531 |
helptext = helptext, icon = icon, |
helptext = helptext, icon = icon, |
532 |
sensitive = sensitive)) |
sensitive = sensitive)) |
533 |
|
|
534 |
|
def make_check_current_tool(toolname): |
535 |
|
"""Return a function that tests if the currently active tool is toolname |
536 |
|
|
537 |
|
The returned function can be called with the context and returns |
538 |
|
true iff the currently active tool's name is toolname. It's directly |
539 |
|
usable as the 'checked' callback of a command. |
540 |
|
""" |
541 |
|
def check_current_tool(context, name=toolname): |
542 |
|
return context.mainwindow.canvas.CurrentTool() == name |
543 |
|
return check_current_tool |
544 |
|
|
545 |
def _tool_command(name, title, method, toolname, helptext = "", |
def _tool_command(name, title, method, toolname, helptext = "", |
546 |
icon = ""): |
icon = ""): |
547 |
"""Add a tool command""" |
"""Add a tool command""" |
|
def check_current_tool(context, name=toolname): |
|
|
return context.mainwindow.canvas.CurrentTool() == name |
|
548 |
registry.Add(Command(name, title, call_method, args=(method,), |
registry.Add(Command(name, title, call_method, args=(method,), |
549 |
helptext = helptext, icon = icon, |
helptext = helptext, icon = icon, |
550 |
checked = check_current_tool)) |
checked = make_check_current_tool(toolname))) |
551 |
|
|
552 |
def _has_selected_layer(context): |
def _has_selected_layer(context): |
553 |
"""Return true if a layer is selected in the context""" |
"""Return true if a layer is selected in the context""" |
554 |
return context.mainwindow.has_selected_layer() |
return context.mainwindow.has_selected_layer() |
555 |
|
|
556 |
|
def _can_remove_layer(context): |
557 |
|
return context.mainwindow.CanRemoveLayer() |
558 |
|
|
559 |
|
def _has_tree_window_shown(context): |
560 |
|
"""Return true if the tree window is shown""" |
561 |
|
return context.mainwindow.get_open_dialog("session_tree") is None |
562 |
|
|
563 |
# File menu |
# File menu |
564 |
_method_command("new_session", "&New Session", "NewSession") |
_method_command("new_session", "&New Session", "NewSession") |
565 |
_method_command("open_session", "&Open Session", "OpenSession") |
_method_command("open_session", "&Open Session", "OpenSession") |
566 |
_method_command("save_session", "&Save Session", "SaveSession") |
_method_command("save_session", "&Save Session", "SaveSession") |
567 |
_method_command("save_session_as", "Save Session &As", "SaveSessionAs") |
_method_command("save_session_as", "Save Session &As", "SaveSessionAs") |
568 |
_method_command("show_session_tree", "Show Session &Tree", "ShowSessionTree") |
_method_command("show_session_tree", "Show Session &Tree", "ShowSessionTree", |
569 |
|
sensitive = _has_tree_window_shown) |
570 |
_method_command("exit", "&Exit", "Exit") |
_method_command("exit", "&Exit", "Exit") |
571 |
|
|
572 |
# Help menu |
# Help menu |
595 |
helptext = "Add a new layer to active map") |
helptext = "Add a new layer to active map") |
596 |
_method_command("layer_remove", "&Remove Layer", "RemoveLayer", |
_method_command("layer_remove", "&Remove Layer", "RemoveLayer", |
597 |
helptext = "Remove selected layer(s)", |
helptext = "Remove selected layer(s)", |
598 |
sensitive = _has_selected_layer) |
sensitive = _can_remove_layer) |
599 |
_method_command("layer_fill_color", "&Fill Color", "LayerFillColor", |
_method_command("layer_fill_color", "&Fill Color", "LayerFillColor", |
600 |
helptext = "Set the fill color of selected layer(s)", |
helptext = "Set the fill color of selected layer(s)", |
601 |
sensitive = _has_selected_layer) |
sensitive = _has_selected_layer) |