[KWWidgets] Modify vtkKWKeyBindingsWidget in vtkKWWindowBase

Georg Ziegler gziegler at mail.tuwien.ac.at
Thu Oct 1 03:52:07 EDT 2009

Hi Sebastien
thank you for your quick reply that pointed me in the right direction.

1) I did as you suggested by overriding DisplayKeyBindingsCallback

2)I looked at the code you mentioned below and found an easier solution 
for the moment. Adding the command is done inside an if-block:

if (!this->GetApplication()->GetReleaseMode())

For the moment I just set ReleaseMode to On and the command isn't added 
in the first place. If this solution turns out to cause problems 
elsewhere I'll have to get back to your solution mentioned below.

Anyway, thanks for the quick and helpful reply.


Sebastien BARRE schrieb:
> Hi Georg,
> At 9/30/2009 07:56 AM, Georg Ziegler wrote:
>> 1) Set the path where the file for the keybindings should be saved to 
>> GetApplication()->GetUserDataDirectory() instead of the directory from 
>> where the application is started.
> Actually the path is not hardcoded to where the application is started. 
> The user can pick any path.
> In vtkKWKeyBindingsWidget::CreateWidget, a vtkKWLoadSaveButton is 
> created, and its path default to the last path that was "open" (from the 
> "OpenPath" key in the registry).
> Or you can modify the OpenPath directly in the registry, though that's a 
> big of a hack (using vtkKWApplication::SetRegistryValue).
> So what you can do is for example retrieve/set a different path in a 
> subclass of the keybindings widget
> Actually I just committed a change, and the SaveButton is now exposed, 
> you don't have to subclass the keybindings widget (though you'll have to 
> reimplement DisplayKeyBindingsCallback in your window subclass I'm afraid).
>> 2) Remove the Keybinding for invoking the TCL-Interactor.
> If I'm not mistaken, the manager list all keybindings automatically, 
> meaning that keybinding is there because it was explicitly set. It's 
> done in vtkKWWindow:
>     idx = menu->AddCommand(
>       this->GetTclInteractorMenuLabel(), this, "DisplayTclInteractor");
>     menu->SetBindingForItemAccelerator(idx, menu->GetParentTopLevel());
> What I suspect is that you removed the menu item itself using 
> vtkKWMenu::DeleteItem, but the binding is still showing up. The reason 
> for that is that technically the binding is set on a widget, not on the 
> menu: that's the second argument, here menu->GetParentTopLevel(), which 
> means the main window. What that call actually mean is: "please 
> conveniently create a binding on the window that uses the same command 
> stored in a specific menu item". When you remove the menu item, it 
> doesn't remove that binding. First, the menu doesn't know/remember/store 
> which widget the binding was applied to, and second, there is actually 
> no reason why that binding should automatically go away because the 
> corresponding menu item disappeared, the menu item was just one way to 
> access that functionality, but there might be others...
> Anyway, to solve your problem, you can call 
> RemoveBindingForItemAccelerator on vtkKWMenu before deleting the item, 
> passing the same parameter as SetBindingForItemAccelerator, or I think 
> you can just remove the keybinding directly on the window, with 
> RemoveKeyBinding and pass the same accelerator as the one that was used 
> in the menu.
>     menu->RemoveBindingForItemAccelerator(idx, menu->GetParentTopLevel());
>     menu->DeleteItem(idx);
> Hope that helps

More information about the KWWidgets mailing list