Tomás Touceda | 6 Jun 2010 21:11
Picon

How to handle decorations?

Hi,

what's the best approach to handle text decorations of the type: syntax
highlighting, selected text?

Thanks,
Tomas

_______________________________________________
Urwid mailing list
Urwid <at> lists.excess.org
http://lists.excess.org/mailman/listinfo/urwid
Ian Ward | 6 Jun 2010 23:09
Favicon
Gravatar

Re: How to handle decorations?

Tomás Touceda wrote on 2010-06-06 15:11:
> Hi,
> 
> what's the best approach to handle text decorations of the type: syntax
> highlighting, selected text?

I would make a custom widget, either a subclass of Text (if you want the
interface to be very similar to a Text widget) or a subclass of
WidgetWrap that uses a Text widget as self._w (if you want more control
over the interface).

If you're making a subclass of Text you can simply override the
get_text() method and return the attributes you want along with the text
(see http://excess.org/urwid/reference.html#Text-get_text )

With a WidgetWrap subclass you can set the Text's attributes when
setting the text, eg.:

    # use attributes based on syntax
    self._w.set_text([('keyword', "class"), " Foo", ('punct', ":")])

HTH,
Ian
Tomás Touceda | 7 Jun 2010 02:46
Picon

Re: How to handle decorations?

On 06/06/10 18:09, Ian Ward wrote:
> Tomás Touceda wrote on 2010-06-06 15:11:
>   
>> Hi,
>>
>> what's the best approach to handle text decorations of the type: syntax
>> highlighting, selected text?
>>     
> I would make a custom widget, either a subclass of Text (if you want the
> interface to be very similar to a Text widget) or a subclass of
> WidgetWrap that uses a Text widget as self._w (if you want more control
> over the interface).
>
> If you're making a subclass of Text you can simply override the
> get_text() method and return the attributes you want along with the text
> (see http://excess.org/urwid/reference.html#Text-get_text )
>
> With a WidgetWrap subclass you can set the Text's attributes when
> setting the text, eg.:
>
>     # use attributes based on syntax
>     self._w.set_text([('keyword', "class"), " Foo", ('punct', ":")])
>
>   
I'm inheriting from the Edit widget, since I need the cursor methods
from it. But I can't seem to find a way to use the palette with the
edit_text.

Why is it set_text not supported anymore with an Edit widget? is my
approach with the Edit widget wrong if I want to use formatted text?
(Continue reading)

Ian Ward | 7 Jun 2010 03:34
Favicon
Gravatar

Re: How to handle decorations?

Tomás Touceda wrote on 2010-06-06 20:46:
> On 06/06/10 18:09, Ian Ward wrote:
>> Tomás Touceda wrote on 2010-06-06 15:11:
>>   
>>> Hi,
>>>
>>> what's the best approach to handle text decorations of the type: syntax
>>> highlighting, selected text?
>>>     
>> I would make a custom widget, either a subclass of Text (if you want the
>> interface to be very similar to a Text widget) or a subclass of
>> WidgetWrap that uses a Text widget as self._w (if you want more control
>> over the interface).
>>
>> If you're making a subclass of Text you can simply override the
>> get_text() method and return the attributes you want along with the text
>> (see http://excess.org/urwid/reference.html#Text-get_text )
>>
>> With a WidgetWrap subclass you can set the Text's attributes when
>> setting the text, eg.:
>>
>>     # use attributes based on syntax
>>     self._w.set_text([('keyword', "class"), " Foo", ('punct', ":")])
>>
>>   
> I'm inheriting from the Edit widget, since I need the cursor methods
> from it. But I can't seem to find a way to use the palette with the
> edit_text.
> 
> Why is it set_text not supported anymore with an Edit widget? is my
(Continue reading)

Matti Eiden | 10 Jun 2010 02:39
Picon

Bug: ListBox fails to calculate Padding rows

Hi all,

just recently discovered urwid - and I got to admit it's pretty
amazing. I began to write my own MUA to teach myself, however I
stumbled upon a particular problem when creating an email thread
viewer (a ListBox), where each reply (Text) is indented slightly
further with the help of Padding.

However, if the Padding causes any extra rows to the Text being
rendered, ListBox fails with "listbox calculated X rows but rendered
Y"

Here's a minimal example to reproduce the bug:

import urwid
screen = urwid.raw_display.Screen()
contents=[]
text    = urwid.Text("This is a rather long text! "*100)
padding = urwid.Padding(text,left=15)
contents.append(padding)
body = urwid.ListBox(urwid.SimpleListWalker(contents))
frame = urwid.Frame(body)
loop = urwid.MainLoop(frame,[],screen=screen)
loop.run()

Any comments, thoughts or ideas how to fix?

Thanks,
Matti Eiden
(Continue reading)

Matti Eiden | 10 Jun 2010 03:23
Picon

Re: Bug: ListBox fails to calculate Padding rows

Looking at the Padding.rows() function, I notice there are three
cases, one for width='pack', one for width='clip' and the last one
which I guess goes to anything else. So I guess I should be using
width=('relative',100) amrite?

Seems to work. Still however, is this intended functionality?
Ian Ward | 11 Jun 2010 16:20
Favicon
Gravatar

Re: Bug: ListBox fails to calculate Padding rows

Matti Eiden wrote on 2010-06-09 21:23:
> Looking at the Padding.rows() function, I notice there are three
> cases, one for width='pack', one for width='clip' and the last one
> which I guess goes to anything else. So I guess I should be using
> width=('relative',100) amrite?
> 
> Seems to work. Still however, is this intended functionality?

Hi Matti,

('relative', 100) is the right way of doing that at the moment.

The Padding interface changed in 0.9.9 and 'pack' was set as the default
width parameter, but that might not have been the best choice and I
might change it to ('relative', 100) in the next release.

'pack' is only supported on a few widgets at the moment (like Text) so
making it the default has caused other problems too.

Ian
Onur Küçük | 1 Jul 2010 19:24
Picon
Favicon

gpm_mev still gives trouble


 Hello,

 On a system where gpm_mev is installed but gpm is not running, I am
still getting exception on startup of any example where TERM=linux
(raw console for example) with version 0.9.9.1.

 Attached patch fixes the problem for me.

Traceback (most recent call last):
  File "calc.py", line 819, in <module>
    main()
  File "calc.py", line 816, in main
    CalcDisplay().main()
  File "calc.py", line 578, in main
    self.loop.run()
  File "/usr/lib/python2.6/site-packages/urwid/main_loop.py", line 170,
in run self.screen.run_wrapper(self._run)
  File "/usr/lib/python2.6/site-packages/urwid/raw_display.py", line
234, in run_wrapper return fn()
  File "/usr/lib/python2.6/site-packages/urwid/main_loop.py", line 188,
in _run self.event_loop.run()
  File "/usr/lib/python2.6/site-packages/urwid/main_loop.py", line 498,
in run self._loop()
  File "/usr/lib/python2.6/site-packages/urwid/main_loop.py", line 515,
in _loop ready, w, err = select.select(fds, [], fds)
select.error: (9, 'Bad file descriptor')

 regards,
--

-- 
(Continue reading)


Gmane