Hello Ian
Thank's for your reply.
Would you send the part of your code that is not working?  If you use
Filler(my_widget, 'middle', 10) then my_widget should be only 10 rows
high and the rest of the space will be blank.  If you want to use that
extra space for something then the ListBox needs to behave like a flow
widget, so you could use BoxAdapter(my_widget, 10) instead.
I solved this! It was a stupid error, I was trying to make a list of a list!!!!
The problem here is that ListBox objects are always selectable, since
you might want to scroll through unselectable content.  If you don't
mind not being able to scroll that one ListBox you can make it
unselectable by subclassing ListBox:

class UnselectableListBox(urwid.ListBox):
        _selectable = False
It work perfectly [if you did not know ;)]

The third point I also understood. But now I really need some help. As you can see from my attached code (sorry if it not clean, but I am really new on this python stuff), I create a class CUPSconsole where I created two empty (actually with one empty element) listboxes. I was expecting (again sorry if i going to say something really stupid) that when I call "update_readings()" function the listbox contents should be updated. But nothing happens. What am I doing wrong? What have I missed?

Thanks for all the trouble Ian, and for such nice package.
Pedro
import urwid
import urwid.raw_display
from urwid.raw_display import Screen

import string,os

dumy=0

finishedlist = ["Column not-selected"]
queuedlist = ["Column Selectable" ]*10    

class UnselectableListBox(urwid.ListBox):
	_selectable = False

class SelText(urwid.Text):
    """
    A selectable text widget. See urwid.Text.
    """

    def selectable(self):
        """
        Make widget selectable.
        """
        return True

    def keypress(self, size, key):
        """
        Don't handle any keys.
        """
        return key
    


class NotSelText(urwid.Text):
    """
    A selectable text widget. See urwid.Text.
    """

    def selectable(self):
        """
        Make widget selectable.
        """
        return False



class CUPSconsole:
    """ CUPS console """
    palette = [
	    ('body',         'black',      'light gray', 'standout'),
	    ('header',       'white',      'dark red',   'bold'),
	    ('button normal','light gray', 'dark blue', 'standout'),
	    ('button select','white',      'dark green'),
	    ('button disabled','dark gray','dark blue'),
	    ('edit',         'light gray', 'dark blue'),
	    ('bigtext',      'white',      'black'),
	    ('chars',        'light gray', 'black'),
	    ('title',         'white',      'dark cyan'),
	    ]

    def __init__(self):
        
	    HEADER =  urwid.Pile([
		    urwid.AttrWrap(urwid.Text(""), 'header'),
		    urwid.AttrWrap(urwid.Text("HPLaser Printer Queue", 'center'), 'header'),
		    urwid.AttrWrap(urwid.Text(""), 'header')
		    ])
	    #dummy Listbox
	    
	    self.queue_widget = urwid.AttrWrap(urwid.ListBox(#
		    [urwid.AttrWrap(SelText(""), None, 'edit')]), 'chars')
	    self.queue_widget.set_focus(0)

	    self.finish_widget = urwid.AttrWrap(UnselectableListBox(#
		    [urwid.AttrWrap(NotSelText(" "), None, 'edit')]), 'chars')
	    
	    ControlColumns = urwid.Columns([self.queue_widget, self.finish_widget], dividechars=2, focus_column=0) 
	    ControlColumns = urwid.Padding(ControlColumns, ('fixed left', 2), ('fixed right', 2))
	    
	    self.top = urwid.AttrWrap( urwid.Filler(ControlColumns, 'middle', 10) , 'title')
	    self.top = urwid.Frame( self.top, header=HEADER )

	    self.update_readings()
	    

    def update_readings(self):
	    reverselist = list(reversed(queuedlist))
	    self.queue_widget.body = urwid.AttrWrap(urwid.ListBox(#
		    [urwid.AttrWrap(SelText(dummy), None, 'edit')
		     for dummy in reverselist]),'chars')

    def main(self):
	    self.ui = Screen()
	    self.ui.register_palette( self.palette )
	    self.ui.run_wrapper (self.run )


    def run(self):
	    global dumy
	    size = self.ui.get_cols_rows()
	    while True:
		    self.top.footer = urwid.AttrWrap(urwid.Text("%s"%(dumy)), 'header')
		    canvas = self.top.render(size, focus=1)
		    self.ui.draw_screen(size,canvas)

		    keys = None

		    while not keys:
			    keys = self.ui.get_input()
			    
		    for k in keys:
			    if "window resize" in keys:
				    size = self.ui.get_cols_rows() 
			    if k == "s":
				    return
			    if urwid.is_mouse_event(k):
				    event, button, col, row = k
				    self.ui.mouse_event(dim, event, button, col, row, focus=True)
			    else:
				    self.top.keypress(size, k)
				    dumy = self.queue_widget.get_focus()[1]

			    if k == "enter":
				    pass
			    if k == "k":
				    pass
				    
				    
    

def console():
    do_display()

def do_display():
    printerdisplay = CUPSconsole()
    printerdisplay.main()


if __name__ == "__main__":
	console()
_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid

Reply via email to