Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving an app into the background and back fails with raw_display #25

Closed
derdon opened this issue Mar 15, 2013 · 3 comments
Closed

Moving an app into the background and back fails with raw_display #25

derdon opened this issue Mar 15, 2013 · 3 comments

Comments

@derdon
Copy link

derdon commented Mar 15, 2013

This is the code for a minimal application from the tutorial:

import urwid

txt = urwid.Text(u"Hello World")
fill = urwid.Filler(txt, 'top')
loop = urwid.MainLoop(fill)
loop.run()

When I put this application into the background (via CTRL-Z), the cursor of my console disappears. If I then try to move this application back into the forground with the fg command, the text [1] + continued python minimal.py is printed but the application is not running again (at least one can't see it). With the following code, everything works as expected: the application can be moved into the background without modifying the cursor and can be moved back into the foreground so the user can continue using the application.

import urwid
from urwid import curses_display

txt = urwid.Text(u"Hello World")
fill = urwid.Filler(txt, 'top')
loop = urwid.MainLoop(fill, screen=curses_display.Screen())
loop.run()

wardi from the IRC channel told me to note that there are the signals SIGSTOP, SIGCONT, SIGTSTP, SIGTTIN, and SIGTTOU. Some or maybe all of them may be useful for resolving this issue.

@ghost
Copy link

ghost commented Nov 5, 2013

When you hit Ctrl-z to stop a program it receives a SIGSTOP signal, which can't be caught, blocked or ignored (see man 7 signal for details). When using fg, it will receive SIGCONT.

Here's a way you can handle SIGCONT in Python and use it to force urwid to restart the screen:

import signal

def handle_sigcont(signal_number, stack_frame):
    # Assuming you can reference urwid's main loop with `loop`
    loop.screen.stop()
    loop.screen.start()
    loop.draw_screen()

signal.signal(signal.SIGCONT, handle_sigcont)

I don't know wether the handle_sigcont function uses the idiomatic urwid way for having your program continued but it has worked for me. I'd love to know about better options.

@wardi
Copy link
Collaborator

wardi commented Dec 24, 2013

raw_display registers a handler for SIGWINCH, that seems like a reasonable place to also register a SIGCONT handler.

anyone care to implement this one?

@wardi
Copy link
Collaborator

wardi commented Dec 26, 2013

8013027 should solve this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants