trait does not get updated when programmatically updating qt editor text value

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

trait does not get updated when programmatically updating qt editor text value

Burnpanck
Hello

When trying to debug a problem with the Tuple editor under python 3 I
wrote a test-case
that set's the editor values using a "setFocus" and "setText" sequence
on the underlying
Qt control. However, under python 3, the trait values do not get
updated. Interestingly,
when manually typing text, the values do get updated. Therefore, I
suspect the the
Qt control firing different events in the two cases. Unfortunately, my
knowledge about
both Qt and TraitsUI/Pyface is rather low. I would appreciate any
pointer to where
the connection between Qt and TraitsUI/Pyface is actually made. I was
unable to
find that myself.

Thank you,
Yves Delley
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: trait does not get updated when programmatically updating qt editor text value

Pietro Berkes
The connection is made in the "init" method here:

P.



On Fri, Dec 20, 2013 at 10:52 AM, Burnpanck <[hidden email]> wrote:
Hello

When trying to debug a problem with the Tuple editor under python 3 I
wrote a test-case
that set's the editor values using a "setFocus" and "setText" sequence
on the underlying
Qt control. However, under python 3, the trait values do not get
updated. Interestingly,
when manually typing text, the values do get updated. Therefore, I
suspect the the
Qt control firing different events in the two cases. Unfortunately, my
knowledge about
both Qt and TraitsUI/Pyface is rather low. I would appreciate any
pointer to where
the connection between Qt and TraitsUI/Pyface is actually made. I was
unable to
find that myself.

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



--
Pietro Berkes
Scientific software developer
Enthought UK


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: trait does not get updated when programmatically updating qt editor text value

Pietro Berkes
BTW, I think I know what is going on in your tests: you need to run the Qt event loop so that the events are dispatched.

You can use this context manager:


@contextmanager
def event_loop():
    """ Post and process the Qt events at the exit of the code block. """

    from pyface.util.guisupport import get_app_qt4

    app = get_app_qt4()

    yield

    app.sendPostedEvents()
    app.processEvents()


then in your test you go

with event_loop():
control.setText('foo')

etc.

Hope this helps,
P.


On Fri, Dec 20, 2013 at 11:03 AM, Pietro Berkes <[hidden email]> wrote:
The connection is made in the "init" method here:

P.



On Fri, Dec 20, 2013 at 10:52 AM, Burnpanck <[hidden email]> wrote:
Hello

When trying to debug a problem with the Tuple editor under python 3 I
wrote a test-case
that set's the editor values using a "setFocus" and "setText" sequence
on the underlying
Qt control. However, under python 3, the trait values do not get
updated. Interestingly,
when manually typing text, the values do get updated. Therefore, I
suspect the the
Qt control firing different events in the two cases. Unfortunately, my
knowledge about
both Qt and TraitsUI/Pyface is rather low. I would appreciate any
pointer to where
the connection between Qt and TraitsUI/Pyface is actually made. I was
unable to
find that myself.

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



--
Pietro Berkes
Scientific software developer
Enthought UK




--
Pietro Berkes
Scientific software developer
Enthought UK


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: trait does not get updated when programmatically updating qt editor text value

Burnpanck
Thanks for the quick response! It was not the event-loop though. Instead,
the problem was the fact that the TextEditor registers "textEdited" but not "textChanged".
As explicitely stated in the QT4 documentation at
http://qt-project.org/doc/qt-4.8/qlineedit.html#textEdited
that signal does not get emitted upon "setText". The workaround is to use
a "setFocus", "clear", "insert" sequence instead, which does emit "textEdited".

Thanks, Yves

On 20.12.2013 12:37, Pietro Berkes wrote:
BTW, I think I know what is going on in your tests: you need to run the Qt event loop so that the events are dispatched.

You can use this context manager:
@contextmanager
def event_loop():
    """ Post and process the Qt events at the exit of the code block. """
    from pyface.util.guisupport import get_app_qt4
    app = get_app_qt4()
    yield
    app.sendPostedEvents()
    app.processEvents()
then in your test you go
with event_loop():
control.setText('foo')
etc.
Hope this helps,
P.


On Fri, Dec 20, 2013 at 11:03 AM, Pietro Berkes <[hidden email]> wrote:
The connection is made in the "init" method here:

P.



On Fri, Dec 20, 2013 at 10:52 AM, Burnpanck <[hidden email]> wrote:
Hello

When trying to debug a problem with the Tuple editor under python 3 I
wrote a test-case
that set's the editor values using a "setFocus" and "setText" sequence
on the underlying
Qt control. However, under python 3, the trait values do not get
updated. Interestingly,
when manually typing text, the values do get updated. Therefore, I
suspect the the
Qt control firing different events in the two cases. Unfortunately, my
knowledge about
both Qt and TraitsUI/Pyface is rather low. I would appreciate any
pointer to where
the connection between Qt and TraitsUI/Pyface is actually made. I was
unable to
find that myself.

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



--
Pietro Berkes
Scientific software developer
Enthought UK




--
Pietro Berkes
Scientific software developer
Enthought UK



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


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