Python Urwid issues with set_alarm

I am having problems with set_alarm using urwid library. Basically, when you run it and hit Enter on Chapman, you get the error below. I don't know much about urwid and it doesn't seem to have any documentation and I tried to find examples to compare, but I couldn't find them.

import urwid
import pyfiglet

class data():

drpepper = pyfiglet.Figlet(font='doom')
choices = u'Chapman Cleese Gilliam Idle Jones Palin'.split()

def menu(self, title, choices):
    body = [urwid.Text(title), urwid.Divider()]
    for c in choices:
        button = urwid.Button(c)
        if c == "Chapman":
            urwid.connect_signal(button, 'click', self.info, c)
        body.append(urwid.AttrMap(button, None, focus_map='reversed'))
    return urwid.ListBox(urwid.SimpleFocusListWalker(body))

def item_chosen(self, button, choice):
    response = urwid.Text([u'You chose ', choice, u'\n'])
    done = urwid.Button(u'Ok')
    urwid.connect_signal(done, 'click', info)
    main.original_widget = urwid.Filler(urwid.Pile([response, urwid.AttrMap(done, None, focus_map='reversed')]))

def info(self, button, choice):
    response = urwid.Text(self.drpepper.renderText("text"), align="center")
    response2 = urwid.Text("Test")
    with open("/home/jt/works?.txt", "a+") as data:
        data.write("THIS IS A TEST 2")
    done = urwid.Button(u'Ok')
    self.main.original_widget = urwid.Filler(urwid.Pile([self.loop.set_alarm_in(5, response), response2]))

def exit_program(self, button):
    raise urwid.ExitMainLoop()

def mainish(self):
    main = urwid.Padding(self.menu(u'Pythons', self.choices), left=2, right=2)
    top = urwid.Overlay(main, urwid.SolidFill(u'\N{MEDIUM SHADE}'),
        align='center', width=('relative', 60),
        valign='middle', height=('relative', 60),
        min_width=20, min_height=9)
    self.loop = urwid.MainLoop(top, palette=[('reversed', 'standout', '')])
    self.loop.run()

      

start = data () start.mainish ()

This is mistake

    β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’  < Traceback (most recent call last):                                                              
  File "urwidtest.py", line 46, in <module>β–’β–’β–’β–’  < Cleese                                                                                          
    crap.mainish()β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’  < Gilliam                                                                                         
  File "urwidtest.py", line 42, in mainishβ–’β–’β–’β–’β–’  < Idle                                                                                            
    self.loop.run()β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’  < Jones                                                                                           
  File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 278, in run                                                               
    self._run()β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’                                                                                                    
  File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 375, in _run                                                              
    self.event_loop.run()β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’                                                                                                    
  File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 678, in run                                                               
    self._loop()β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’                                                                                                    
  File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 715, in _loop                                                             
    self._watch_files[fd]()β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’                                                                                                    
  File "/usr/local/lib/python3.4/dist-packages/urwid/raw_display.py", line 392, in <lambda>                                                        
    event_loop, callback, self.get_available_raw_input())                                                                                          
  File "/usr/local/lib/python3.4/dist-packages/urwid/raw_display.py", line 492, in parse_input                                                     
    callback(processed, processed_codes)β–’β–’β–’β–’β–’β–’β–’                                                                                                    
  File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 399, in _update                                                           
    self.process_input(keys)β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’                                                                                                    
  File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 499, in process_input                                                     
    k = self._topmost_widget.keypress(self.screen_size, k)                                                                                         
  File "/usr/local/lib/python3.4/dist-packages/urwid/container.py", line 592, in keypress                                                          
    *self.calculate_padding_filler(size, True)), key)                                                                                              
  File "/usr/local/lib/python3.4/dist-packages/urwid/decoration.py", line 621, in keypress                                                         
    return self._original_widget.keypress(maxvals, key)                                                                                            
  File "/usr/local/lib/python3.4/dist-packages/urwid/listbox.py", line 985, in keypress                                                            
    key = focus_widget.keypress((maxcol,),key)β–’                                                                                                    
  File "/usr/local/lib/python3.4/dist-packages/urwid/wimp.py", line 535, in keypress                                                               
    self._emit('click')β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’                                                                                                    
  File "/usr/local/lib/python3.4/dist-packages/urwid/widget.py", line 463, in _emit                                                                
    signals.emit_signal(self, name, self, *args)                                                                                                   
  File "/usr/local/lib/python3.4/dist-packages/urwid/signals.py", line 264, in emit                                                                
    result |= self._call_callback(callback, user_arg, user_args, args)                                                                             
  File "/usr/local/lib/python3.4/dist-packages/urwid/signals.py", line 294, in _call_callbackβ–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’
    return bool(callback(*args_to_pass))β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’
  File "urwidtest.py", line 30, in infoβ–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’
    self.main.original_widget = urwid.Filler(urwid.Pile([self.loop.set_alarm_in(5, response), response2]))β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’
  File "/usr/local/lib/python3.4/dist-packages/urwid/container.py", line 1253, in __init__β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’
    if focus_item is None and w.selectable():β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’
AttributeError: 'function' object has no attribute 'selectable'β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’

      

+3


source to share


1 answer


After a thousand combinations, I finally got this. Know how? I kept hacking codes randomly until it finally worked like a rough estimate.

Finally, after endless hours that would force you guys a few minutes to post something. I love the support community for python (sarcasm) ... I love how people claim to have an awesome support community when I can't get an answer.

Okay, it's over. This is for those who are struggling as no one else will help you.

self.main.original_widget = urwid.Filler(urwid.Pile([self.loop.set_alarm_in(5, response), response2]))

      



You can see here that main.original_widget clears the screen and saves it in place. I cannot explain why it is understandable, because no one will help. But I realized that you need to create a reserve.

He is waiting for text editing or something else. You cannot call a function inside a widget. What for? There is no clue. Ask the Urwid community if you can even get one answer. Moving

By creating a fallback, you create var say "self.x = urwid.Text (" ")" nothing inside of it, which I assume is keeping it. Subsequently, you create an alarm by creating say self.test.set_alarm_in (4)

Then it will call the test () function for 4 seconds or so. so you can easily put self.x.set_text ("hello world") and it should work.

0


source







All Articles