accelerator key in Action ignored

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

accelerator key in Action ignored



I'm facing an issue ( traitsui 4.3, using the PyQt backend on osx 10.8 ) with
the accelerators keys, that kind a keyboard shortcut to an Action.
Thing is that the method the Action is bound to, is not called, when pressing
the accelerator key.

I've been tracing the "site-packages/traitsui/" "_do" method
such to make sure that the correct string ( "Meta-P") is passed along.

Simple pushing the button does evoke the method, so I consider this a bug, though
unfortunately I havent been able to trace its cause.

Another question I have with creating these Menu's and Action is that any  
exceptions in the handling method are ignored. Is is possible to override
this behaviour? Having exceptions not bubble up can be pretty frustrating, when
not aware of this default ( undocumented? ) behaviour.

Below is an adaptod example, which is the simplest program to demonstrate the



# -- Example of a Handler that overrides setattr(), and
#                        that has a user interface notification method


from traits.api import HasTraits, Bool, Float
from traitsui.api import (View, Handler, MenuBar, Menu, Action, ToolBar, Group,


class TC_Handler(Handler):
    def setattr(self, info, object, name, value):
        Handler.setattr(self, info, object, name, value)
        info.object._updated = True

    def do_recalc(self, info):
        info.object.v_result = info.object.v1 + info.object.v2

    def faulty_action(self, info):
            print "raising a ValueError"
        except ImportError:

    def object__updated_changed(self, info):
        if info.initialized:
            info.ui.title += "*"

class TestClass(HasTraits):
    v1 = Float(12)
    v2 = Float(12)
    v_result = Float
    b1 = Bool
    b2 = Bool
    b3 = Bool
    _updated = Bool(False)

recalc = Action(name="Recalculate",
                accelerator="Ctrl-U | Meta-U | U"

messy_in_action = Action(name="will raise an exception",
                         accelerator="Ctrl-P | Meta-P | P"

view1 = View(
                  Item("v_result", style="readonly"),
                  'b1', 'b2', 'b3'),
            title="Alter Title",
            buttons=['OK', 'Cancel'],
            toolbar = ToolBar( recalc, messy_in_action)


tc = TestClass()

Enthought-Dev mailing list
[hidden email]