On 09-04-22 20:28, Sujan Shakya wrote:
> Hi Ian,
> Thank you for helping me. I've completed the curses task of creating
> menu based console using urwid. But right I am facing a problem. I
> need to ignore keyboard interrupts such as Ctrl-C, Ctrl-Z etc. There
> must a way to do this. So please help me.
>    
This is strictly speaking outside the scope of Urwid. As far as I know 
it doesn't provide any mechanism for controlling keyboard interrupts. In 
my project I wanted [ctrl-C] to toggle case sensitivity of searches 
rather than interrupting the program. You can control what keys are 
handled by the operating system using the termios module. What I did was 
(with lots of irrelevant code omitted):

   import termios

   def SetupTty(self):
     """Ensure the tty is setup correctly."""
     old_termios = termios.tcgetattr(0)
     old_termios[-1][termios.VINTR] = '\0'
     termios.tcsetattr(0, termios.TCSANOW, old_termios)

   def Run(self):
     """Handle user input and update the display."""
     self.SetupTty()
     # other setup followed by the main dispatch loop:
     while True:
               self.screen.draw_screen(self.screen_size, canvas)

       keys = self.screen.get_input()
       if 'ctrl d' in keys or 'f8' in keys:
         return
       for key in keys:
         # some code omitted for brevity...
         if key == 'window resize':
           self.screen_size = self.screen.get_cols_rows()
         else:
           self.Keypress(self.screen_size, key)



_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid

Reply via email to