Ian Ward | 2 Dec 2009 01:38
Favicon
Gravatar

Re: Bug found with selectable widget snapping while scrolling listbox.

Dominic LoBue wrote:
> Attached is a new hg export. I changed the behavior to what you
> suggested. In addition I added the boolean attribute _snap to the
> listbox. When _snap is set to True, the listbox scrolling behavior
> snaps to to selectable widgets. When _snap is set to False, it
> doesn't.
> 
> Obviously not a perfect solution - the ideal would be to have the
> scroller look for a "snap" attribute in the widget it is scrolling to,
> and if that attribute is True, then snap. But I figured this was a
> happy middle ground to get by until you separate scrolling from the
> listbox like you wanted.
> 
> Dominic

This patch seems broken for me (expected indented block) and if I fix
that then the unit tests fail.  Maybe the tests just need to be updated
but that should be done carefully, along with adding a new test for the
new behaviour.

I'll look at it when I have some time.

Ian
Dominic LoBue | 2 Dec 2009 06:06
Picon

Re: Bug found with selectable widget snapping while scrolling listbox.

On Tue, Dec 1, 2009 at 4:38 PM, Ian Ward <ian <at> excess.org> wrote:
> Dominic LoBue wrote:
>> Attached is a new hg export. I changed the behavior to what you
>> suggested. In addition I added the boolean attribute _snap to the
>> listbox. When _snap is set to True, the listbox scrolling behavior
>> snaps to to selectable widgets. When _snap is set to False, it
>> doesn't.
>>
>> Obviously not a perfect solution - the ideal would be to have the
>> scroller look for a "snap" attribute in the widget it is scrolling to,
>> and if that attribute is True, then snap. But I figured this was a
>> happy middle ground to get by until you separate scrolling from the
>> listbox like you wanted.
>>
>> Dominic
>
> This patch seems broken for me (expected indented block) and if I fix
> that then the unit tests fail.  Maybe the tests just need to be updated
> but that should be done carefully, along with adding a new test for the
> new behaviour.
>
> I'll look at it when I have some time.
>
> Ian
>
> _______________________________________________
> Urwid mailing list
> Urwid <at> lists.excess.org
> http://lists.excess.org/mailman/listinfo/urwid
>
(Continue reading)

Yasir Assam | 7 Dec 2009 08:53

Enable/disable buttons?

I'm new to urwid. I'm trying to create a simple dialog as follows:

import urwid

f1 = urwid.Edit("Field 1: ")
f2 = urwid.Edit("Field 2: ")
f3 = urwid.Edit("Field 3: ")

ok = urwid.Button("OK")
cancel = urwid.Button("Cancel")

gf = urwid.GridFlow([ok, cancel], 10, 10, 0, "center")

pile = urwid.Pile([
        f1,
        f2,
        f3,
        urwid.Divider(),
        gf
        ])

fill = urwid.Filler(pile, valign="top")

loop = urwid.MainLoop(fill)
loop.run()

I want to be able to disable the OK button depending on what's being 
input. By "disable" I stopping the cursor from moving it to it when I 
use the arrow keys to move focus around.

(Continue reading)

Ian Ward | 7 Dec 2009 14:47
Favicon
Gravatar

Re: Enable/disable buttons?

Yasir Assam wrote:
> ok = urwid.Button("OK")
[...]
> I want to be able to disable the OK button depending on what's being
> input. By "disable" I stopping the cursor from moving it to it when I
> use the arrow keys to move focus around.
> 
> Is there an easy way to do this?

Yes, the selectable() method on widgets determines whether the cursor
will move to a widget, so you could make a Button subclass that returns
False from selectable() when the button should not be selectable.

You will also have to intercept mouse clicks for it to be a complete
solution.  Look at the code for the Button class, it's not very complicated.

http://excess.org/urwid/browser/urwid/wimp.py#L412

Ian
Yasir Assam | 7 Dec 2009 21:20

Re: Enable/disable buttons?

Thanks for replying Ian.

I tried something like this yesterday, but I couldn't move the cursor 
past the OK button (I'm using the up/down keys to move the cursor and 
ignoring the mouse for now). Disabling the OK button puts the enabled 
Cancel out of each unless I use the mouse.

Here's the code:

import urwid

class DisabledButton(urwid.Button):

    def __init__(self, text):
        self.__super.__init__(text)

    def selectable(self):
        return False

f1 = urwid.Edit("Field 1:                      ")
f2 = urwid.Edit("Field 2:                      ")
f3 = urwid.Edit("Field 3:                      ")

#ok = urwid.Button("OK")
ok = DisabledButton("OK")
cancel = urwid.Button("Cancel")

gf = urwid.GridFlow([ok, cancel], 10, 10, 0, "center")

pile = urwid.Pile([
(Continue reading)

Yasir Assam | 7 Dec 2009 22:11

Re: Enable/disable buttons?


> puts the enabled Cancel out of each unless I use the mouse.
I meant "out of reach"

Yasir

No virus found in this outgoing message.
Checked by AVG - www.avg.com 
Version: 8.5.426 / Virus Database: 270.14.97/2550 - Release Date: 12/07/09 07:33:00
_______________________________________________
Urwid mailing list
Urwid <at> lists.excess.org
http://lists.excess.org/mailman/listinfo/urwid
Ian Ward | 7 Dec 2009 22:47
Favicon
Gravatar

Re: Enable/disable buttons?

Yasir Assam wrote:
> 
>> puts the enabled Cancel out of each unless I use the mouse.
> I meant "out of reach"
> 

You might try calling set_focus on the GridFlow widget to select the
cancel button.  I believe if the widget in focus is not selectable then
the GridFlow assumes none of the widgets it contains are.

Ian
Yasir Assam | 7 Dec 2009 22:51

Re: Enable/disable buttons?


>>> puts the enabled Cancel out of each unless I use the mouse.
>>>       
>> I meant "out of reach"
>>
>>     
>
> You might try calling set_focus on the GridFlow widget to select the
> cancel button.  I believe if the widget in focus is not selectable then
> the GridFlow assumes none of the widgets it contains are.
>   
Where do I call set_focus()?

Yasir

No virus found in this outgoing message.
Checked by AVG - www.avg.com 
Version: 8.5.426 / Virus Database: 270.14.97/2550 - Release Date: 12/07/09 07:33:00
_______________________________________________
Urwid mailing list
Urwid <at> lists.excess.org
http://lists.excess.org/mailman/listinfo/urwid
Ian Ward | 9 Dec 2009 13:57
Favicon
Gravatar

Re: Enable/disable buttons?

Yasir Assam wrote:
>
>> You might try calling set_focus on the GridFlow widget to select the
>> cancel button.  I believe if the widget in focus is not selectable then
>> the GridFlow assumes none of the widgets it contains are.
>>   
> Where do I call set_focus()?
> 

The GridFlow object is called gf in your example.  try:
  gf.set_focus(1)
Yasir Assam | 10 Dec 2009 05:51

Re: Enable/disable buttons?


> Yasir Assam wrote:
>   
>>> You might try calling set_focus on the GridFlow widget to select the
>>> cancel button.  I believe if the widget in focus is not selectable then
>>> the GridFlow assumes none of the widgets it contains are.
>>>   
>>>       
>> Where do I call set_focus()?
>>
>>     
>
> The GridFlow object is called gf in your example.  try:
>   gf.set_focus(1)
>   
Thanks. I misunderstood you - I thought set_focus would put the cursor 
there as soon as it's called, but it doesn't.

Yasir

No virus found in this outgoing message.
Checked by AVG - www.avg.com 
Version: 8.5.426 / Virus Database: 270.14.100/2554 - Release Date: 12/09/09 07:32:00
_______________________________________________
Urwid mailing list
Urwid <at> lists.excess.org
(Continue reading)


Gmane