handling Ctrl-click on shelf button

   3523   3   0
User Avatar
Member
194 posts
Joined:
Offline
i see that the generic tool utils use if kwargs.has_key(“ctrlclick”):
and then it's easy to check whether the value for that key is True or False.

my question is - is there a case when the key “ctrlclick” might be missing from kwargs? do i need to worry about handling that case?

thx.
User Avatar
スタッフ
1450 posts
Joined: 7月 2005
Offline
When invoked from the shelf, the “ctrlclick” will always be there. But it is a good programming style to check anyway. Maybe in the future, there will be a way of invoking a tool with custom kwargs in Python itself, and then users may not add “ctrlclick” explicitly, in which case you may get exceptions in your tool.
User Avatar
Member
194 posts
Joined:
Offline
Thanks.
I'll keep the check whether the key exists.
I wasn't sure what to do if it does not.
Right now my code does not do anything if the ‘ctrlclick’ does not exist in kwargs. Should it throw a certain kind of exception? Or just print out some error message?

Or maybe it should default to the normal ‘click’ behavior and bring up a dialog where the user specifies the tool's parameters.

edit: i guess the last alternative makes most sense.
User Avatar
スタッフ
1450 posts
Joined: 7月 2005
Offline
yeah, since ‘ctrlclick’ is optional and is really a modifier, you can treat the lack of ‘ctrlclick’ as if its value were ‘false’.
  • Quick Links