Opened 3 years ago

Closed 2 years ago

#5492 enhancement closed fixed (fixed)

G(tk)Application support in gtk3reactor

Reported by: lucian Owned by: itamar
Priority: normal Milestone:
Component: core Keywords:
Cc: dobey Branch: branches/gtk-app-5492
(diff, github, buildbot, log)
Author: lucian Launchpad Bug:

Description

GLib has a GApplication class that handles things like application uniqueness and a few other things, and provides its own .run() method. GtkApplication inherits from it and also does Gtk-specific things.

After installing the gtk3reactor, if I call reactor.run() the UI does show up, but the GApplication's 'activate' event never fires. At glyph's suggestion I explicitly set the reactor's mainloop to that of the GApplication's and 'activate' fired as expected.

The reactor also doesn't stop when I close the window, even with the hack.

Attachments (5)

play.py (552 bytes) - added by lucian 3 years ago.
Example of hanging reactor.
play.2.py (710 bytes) - added by lucian 3 years ago.
Example with Window and a twisted callback
tx_gapp.patch (1.6 KB) - added by lucian 3 years ago.
Patch to replicate the _run=app.run and installSignalHandlersFalse=False workarounds
tx_gapp2.patch (2.5 KB) - added by lucian 3 years ago.
Default back to installing signal handlers by default, at exarkun's suggestion. Add docs.
tx_gapp3.patch (4.6 KB) - added by lucian 3 years ago.
Remove a useless method, add tests.

Download all attachments as: .zip

Change History (21)

comment:1 Changed 3 years ago by itamar

  • Cc dobey added

Could you provide a minimal example?

comment:2 Changed 3 years ago by itamar

  • Milestone set to Twisted-12.1

Changed 3 years ago by lucian

Example of hanging reactor.

comment:3 Changed 3 years ago by lucian

Perhaps something like the reactor.registerWxApp would work?

http://twistedmatrix.com/documents/current/core/howto/choosing-reactor.html#auto12

Changed 3 years ago by lucian

Example with Window and a twisted callback

comment:4 Changed 3 years ago by lucian

The sedonc minimal example doesn't hang when I close the window. I believe it happened because of my usage of IRCClient in my app.

I was wrong, I should've written the minimal example before filing the ticket.

comment:5 Changed 3 years ago by lucian

If I start the reactor with .run(installSignalHandlers=False), the app responds to SIGTERM and dies correctly, and also responds to SIGINT (incorrectly, because of a GTK/py-gi bug https://bugzilla.gnome.org/show_bug.cgi?id=622084)

Changed 3 years ago by lucian

Patch to replicate the _run=app.run and installSignalHandlersFalse=False workarounds

Changed 3 years ago by lucian

Default back to installing signal handlers by default, at exarkun's suggestion. Add docs.

Changed 3 years ago by lucian

Remove a useless method, add tests.

comment:6 Changed 3 years ago by lucian

  • Keywords review added

comment:7 Changed 3 years ago by itamar

If possible the tests should use #5547. If #5547 isn't ready and we want to release 12.1, we should at a minimum make sure we do the SIGCHLD cleanup stuff that ReactorBuilder does since these tests create a new reactor instance and run it.

comment:8 Changed 3 years ago by itamarst

  • Author set to itamarst
  • Branch set to branches/gtk-app-5492

(In [34040]) Branching to 'gtk-app-5492'

comment:9 Changed 3 years ago by itamar

  • Keywords review removed
  • Owner set to itamar

I made some fixes in the branch, in particular matching coding standard a bit better, and moving the code to gireactor instead of _glibbase.

comment:10 Changed 3 years ago by itamar

  • Author changed from itamarst to lucian
  • Keywords review added
  • Owner itamar deleted

OK, ready for final review assuming all tests are happy:

http://buildbot.twistedmatrix.com/boxes-supported?branch=/branches/gtk-app-5492

comment:11 Changed 2 years ago by therve

  • Keywords review removed
  • Owner set to itamar
  • I'm seeing test failures when using the gi and gtk3 reactor on the whole test suite. They got attached to random tests:
[ERROR]
Traceback (most recent call last):
  File "Twisted/trunk/twisted/internet/base.py", line 800, in runUntilCurrent
    call.func(*call.args, **call.kw)
  File "Twisted/trunk/twisted/internet/_glibbase.py", line 296, in stop
    posixbase.PosixReactorBase.stop(self)
  File "Twisted/trunk/twisted/internet/base.py", line 577, in stop
    "Can't stop reactor that isn't running.")
twisted.internet.error.ReactorNotRunning: Can't stop reactor that isn't running.

I think maybe overriding _run may not be enough?

  • choosing-reactor.xhtml has some tabs in it. It'd be nice to wrap lines to 80 chars too.

Do we have a gtk3 slave somewhere too?

comment:12 Changed 2 years ago by itamar

  • Milestone Twisted-12.1 deleted

So in theory I fixed it. But I can't test it since it's not possible to do this correctly on older versions of gobject introspection, AFAICT. Removing from 12.1 milestone, though, this isn't really necessary for basic gtk3 support; if we make it in then fine, but doesn't seem like it should be a blocker.

comment:13 Changed 2 years ago by itamar

Next step: run tests on e.g. Ubuntu 12.04. I will upgrade my system from 11.10 real soon now, but feel free to run on your system and if it looks good it's mergeable in theory.

comment:14 Changed 2 years ago by therve

Looks good, tests are passing for me now. I think we can merge it as it is. Maybe the last question I have is whether we should raise an error when registerGApplication is called after reactor.run or called a second time.

comment:15 Changed 2 years ago by itamar

OK, I added those two things, will merge once buildbot is happy.

comment:16 Changed 2 years ago by itamarst

  • Resolution set to fixed
  • Status changed from new to closed

(In [34391]) Merge gtk-app-5492: Add support for Gio.Application instance registration.

Fixes: #5492
Author: lucian, itamar
Review: itamar, therve

Note: See TracTickets for help on using tickets.