Python Urwid issues with set_alarm

532 views Asked by At

I'm having issues with set_alarm using the library urwid. Basically, when you run it and hit enter on Chapman you will get the error below. I don't know much about urwid, and it seem sto lack documentation and I tried to look for examples to compare but I couldn't find any.

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 the error

    ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒  < 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'▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
1

There are 1 answers

1
AudioBubble On

After a thousand combinations I finally got it. Know how? I randomly kept hacking codes together until it finally worked like a bruteforce guess.

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

Okay, end rant. This is for those who are struggling since nobody else will help you out.

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

Here you see main.original_widget clears the screen and preserves in a spot. I cannot explain why clearly because nobody will help. But, I realized that you have to create a reserve.

It expects a text edit or something. You cannot call a function inside of the widget. Why? No clue. Ask Urwid community if you can even get a single response. Moving on

By creating a reserve you create a var say "self.x = urwid.Text("")" with nothing inside of it which I assume preserves it. Afterwards, you create an alarm by creating say self.test.set_alarm_in(4)

It will then call the function test() in matter of 4 seconds or so. so you can easily put self.x.set_text("hello world") and it should work.