Ryan Ross | 11 Sep 2006 22:43
Picon
Favicon

ListBox Won't Scroll Using Keys

Hi All!

First of all, great library! Interfaces become much prettier much easier than 
with curses. 

The problem I am having is that my listbox (list of buttons) won't scroll 
using the arrow keys. It can definitely get focus though, as I can use the 
mouse to select the buttons (and that changes the cursor position). Below are 
some relevent portions of code. Each container here is wrapping the one 
before it. Also, I've attached a tar.gz of the code + the two sample data 
files (hopefully it will go through).

Button Definition:
newbutton = urwid.Button(string.split(line,',')[0],on_animate_button)
newbutton = urwid.AttrWrap(newbutton, 'normtext', 'header')
allow_from_buttons.append(newbutton)

ListBox Definition:
allowfrombox = urwid.ListBox(allow_from_buttons)

Frame Definition:
allowfrom = urwid.Frame(allowfrombox, urwid.AttrWrap(urwid.Text("Allow 
From"), 'listheader'))

Column Definition:
listcols = urwid.Columns([('weight',4,allowfrom),
('weight',6,allowservice)],dividechars=1,focus_column=0)

Pile Definition:
complete = urwid.Pile([('fixed', 3, top),listcols],focus_item=1)
(Continue reading)

Greg Hamilton | 12 Sep 2006 01:38
Picon
Favicon

Re: ListBox Won't Scroll Using Keys

Your run() function only handles mouse and resize events. Try something 
like this:

     for k in keys:
         if urwid.is_mouse_event(k):
             event, button, col, row = k
             complete.mouse_event(size,event,button,col,row,focus=True)
         elif k == "window resize":
             size = ui.get_cols_rows()
         else:
             size = ui.get_cols_rows()
             complete.keypress(size, k)

Greg
Ryan Ross | 12 Sep 2006 16:59
Picon
Favicon

Re: ListBox Won't Scroll Using Keys

Thanks for the help Greg! I guess I was confused. Under the tutorial Section 
2.3 it has a definition for a keypress function, which I took out for now. I 
didn't realize or notice that most of the widgets have a keypress method
as well. 

Thanks for fixing my program! :)

Ryan

On Monday 11 September 2006 4:38 pm, Greg Hamilton wrote:
> Your run() function only handles mouse and resize events. Try something 
> like this:
> 
>      for k in keys:
>          if urwid.is_mouse_event(k):
>              event, button, col, row = k
>              complete.mouse_event(size,event,button,col,row,focus=True)
>          elif k == "window resize":
>              size = ui.get_cols_rows()
>          else:
>              size = ui.get_cols_rows()
>              complete.keypress(size, k)
> 
> Greg
Fabian Braennstroem | 12 Sep 2006 22:29
Picon
Picon

Re: newbie looks for more examples

Hi Ian,

* Ian Ward <ian <at> excess.org> wrote:
> Fabian Braennstroem wrote:
>> Thanks for your help! One major drawback of lfm/curses is
>> the speed: it is pretty slow, when there are a lot of files
>> in a directory. urwid seems to be much faster, at least the
>> browser example looks like that... so it would be a nice
>> project for the urwid package, but my time and knowledge is
>> limited :-(
>
> browse.py doesn't do any stat()'ing of the files in the directory, which 
> might account for the speed difference. Urwid does let you do that 
> lazily (as files appear on screen instead of all at once), so it will 
> seem faster with lots of files.

Maybe, I can do this in lfm too ...
>
> Post any Urwid-specific issues you have to the list and I'll try to help.

Thanks!

Greetings!
 Fabian
Graham Clinch | 18 Sep 2006 00:48
Picon

Patch: Text.pack() fails with multi-line strings

Hi List,

I'm having some problems using a Text instance's pack method to get  
the screen columns a multi-line string will display as.  I've stuck a  
short example that demonstrates this problem for me at the end of the  
email.

It looks as though there's an off-by-one error in the special-case  
handling of '\n' in strings, and I believe the fix is to apply the  
following patch:

-- snip --

--- widget.py   2006-09-17 23:42:53.000000000 +0100
+++ /System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/urwid/widget.py        2006-09-17  
23:43:04.000000000 +0100
 <at>  <at>  -239,7 +239,7  <at>  <at> 
                 i = 0
                 cols = 0
                 while i < len(text):
-                       j = text.find('\n')
+                       j = text.find('\n', i)
                         if j == -1:
                                 j = len(text)
                         c = calc_width(text, i, j)

-- snip --

Graham
(Continue reading)

Ian Ward | 18 Sep 2006 15:53
Favicon
Gravatar

Re: Patch: Text.pack() fails with multi-line strings

Graham Clinch wrote:
> Hi List,
> 
> I'm having some problems using a Text instance's pack method to get the 
> screen columns a multi-line string will display as.  I've stuck a short 
> example that demonstrates this problem for me at the end of the email.
> 
> It looks as though there's an off-by-one error in the special-case 
> handling of '\n' in strings, and I believe the fix is to apply the 
> following patch:

Yes, your patch looks correct. Thanks!

I only recently added pack() with the intent of creating a menu bar and 
drop-down widget, but I haven't done much testing yet.  There may be 
more bugs lurking in that code  :-)

I'm wrestling with the more general question of how to design an 
interface for asking widgets "how big would you like to be?"  I hope I 
got it right, but if not the pack() function might change slightly in 
future versions.

Ian
Rebecca Breu | 18 Sep 2006 16:20
Picon
Favicon

Scrollbar

Hi all!

I needed a vertical scrollbar, and here it is, together with a scrollbar-enabled
listbox. I'm not sure whether my code is that optimal, but it works. :)

A disadvantage is the fact that, if you drag the handle of the scrollbar with
the
mouse, you only see the effect when releasing the mouse. That's caused by
urwid's way of handling mouse events. Well, I can live with it quite well.

Yours,
Rebecca

Attachment (scrollbar.py): text/x-python, 9 KiB
_______________________________________________
Urwid mailing list
Urwid <at> lists.excess.org
http://lists.excess.org/mailman/listinfo/urwid
Ian Ward | 18 Sep 2006 18:00
Favicon
Gravatar

Re: Scrollbar

Rebecca Breu wrote:
> Hi all!
> 
> I needed a vertical scrollbar, and here it is, together with a scrollbar-enabled
> listbox. I'm not sure whether my code is that optimal, but it works. :)

That's great!

Would you consider relicensing it LGPL so I can incorporate parts of it 
in the library?

> A disadvantage is the fact that, if you drag the handle of the scrollbar with
> the
> mouse, you only see the effect when releasing the mouse. That's caused by
> urwid's way of handling mouse events. Well, I can live with it quite well.

Urwid will pass along mouse drag events if it receives them.  I think 
that the curses library filters them out.  Try raw_display instead. (or 
run "python input_test.py raw" to see what your terminal is sending.

Ian
Rebecca Breu | 19 Sep 2006 11:20
Picon
Favicon

Re: Scrollbar

Zitat von Ian Ward <ian <at> excess.org>:

> Would you consider relicensing it LGPL so I can incorporate parts of it
> in the library?

That's no problem. Just take it.

> Urwid will pass along mouse drag events if it receives them.  I think
> that the curses library filters them out.  Try raw_display instead. (or
> run "python input_test.py raw" to see what your terminal is sending.

Mmh. Having a closer look at the reference, I see that it mentions
mouse drag events. I've never seen one of those until today. Thus I just ran
input_test.py in different terminal emulators, and I got mouse drag events
in xterm and gnome-terminal when using raw_display. Very nice, but I don't get
any mouse drag events in aterm, rxvt, mlterm or konsole. :(

I have no idea what the problem is with those terminal emulators.

Well, but making my scrollbar aware of mouse drag events has a very low
priority at the moment...

Rebecca
Rebecca Breu | 21 Sep 2006 11:26
Picon
Favicon

Make Pile behave as box widget

Hi!

What do I have to do to make a Pile which contains box and flow widgets
behave as a box widget?

I have something like:

    flow1 = urwid.Text("asdf");
    flow2 = urwid.Text(";lkj");
    box1 = urwid.Filler(urwid.Text("laskdfj"));

    widget = urwid.Pile([flow1, flow2, ("fixed", 3, box1)]);
    widget = urwid.Pile([flow1, flow2, box1]);

But when I try to use this widget as a box widget, I get the same error as if
I had used a flow widget.

    ui.draw_screen(dim, widget.render(dim, True));

  File "/home/rbreu/urwid/widget.py", line 180, in render
    def render(self,(maxcol,), focus=False):
ValueError: too many values to unpack

Rebecca

Gmane