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

_jelle_

Hi,

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/key_bindings.py" "_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
bug.

Thanks,

-jelle

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

#--[Imports]--------------------------------------------------------------------

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

#--[Code]-----------------------------------------------------------------------

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):
        try:
            print "raising a ValueError"
        except ImportError:
            pass


    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",
                action="do_recalc",
                accelerator="Ctrl-U | Meta-U | U"
                )

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

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

        )


tc = TestClass()
tc.configure_traits(view=view1)


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev