Wendell Smith | 4 Aug 2010 22:00
Picon

Urwid and Python 3

  Hi,

I contacted this list earlier to ask about python 3, and it sounded like 
you all had enough work to do without worrying about it. Since I would 
like to use urwid for an ipython interpreter, and ipython wants to 
switch to python 3 as soon as possible, I thought I might see how well 
it works to switch urwid over to python 3... and after trying it out, I 
have a fairly well working python 3 version of urwid!

Its available at http://github.com/wackywendell/urwid
Or if you're using git:
$ git clone git://github.com/wackywendell/urwid.git

Its setup to use the recommended way of converting to python 3: the code 
posted is working py2.6 code, and if you run the 2to3 converter on it, 
it should give you working python3 code. There is a script called 
'23dir' in there as well, which runs through the urwid directory, and 
copies everything to an urwid3 directory. When its done, there should be 
a working python3 implementation.

I say its working... and it is: run python tour.py, and it works, even 
with unicode characters. At least, on my machine, with European unicode 
characters. I'm pretty sure I've killed any support for wide characters 
(because I don't understand how that worked, sorry.) It also doesn't 
pass many of the unit tests in python3... but, well, I'm not done, I 
just tried out the conversion to see how feasible it was.

Anyways, please tell me what you think!

-Wendell
(Continue reading)

Ian Ward | 5 Aug 2010 04:47
Favicon
Gravatar

Re: Urwid and Python 3

Wendell Smith wrote on 2010-08-04 16:00:
>   Hi,
> 
> I contacted this list earlier to ask about python 3, and it sounded like 
> you all had enough work to do without worrying about it. Since I would 
> like to use urwid for an ipython interpreter, and ipython wants to 
> switch to python 3 as soon as possible, I thought I might see how well 
> it works to switch urwid over to python 3... and after trying it out, I 
> have a fairly well working python 3 version of urwid!

Thanks, I did notice you working on that in github.

> Its available at http://github.com/wackywendell/urwid
> Or if you're using git:
> $ git clone git://github.com/wackywendell/urwid.git
> 
> Its setup to use the recommended way of converting to python 3: the code 
> posted is working py2.6 code, and if you run the 2to3 converter on it, 
> it should give you working python3 code. There is a script called 
> '23dir' in there as well, which runs through the urwid directory, and 
> copies everything to an urwid3 directory. When its done, there should be 
> a working python3 implementation.

That sounds like what we need.  There is a python3 branch in the hg
repository that Kirk Mcdonald was working on a few months ago, but I
don't think his was split into 2.6 version + script.

http://bitbucket.org/kirkmcdonald/urwid-py3k

I wasn't able to push that branch to git when I tried. (my hg-git-fu
(Continue reading)

Wendell Smith | 8 Aug 2010 16:40
Picon

Re: Urwid and Python 3

  Excellent, and thank you for alerting me to the bitbucket repository - 
I'm working on including that now; its helpful to have a working py3k 
version so that I can see what it should look like after it goes through 
the 2to3 converter. I managed to convert it to git, and I'm merging with 
it right now - although it will take some time.

Thanks,
Wendell

On 08/04/2010 10:47 PM, Ian Ward wrote:
> Wendell Smith wrote on 2010-08-04 16:00:
>>    Hi,
>>
>> I contacted this list earlier to ask about python 3, and it sounded like
>> you all had enough work to do without worrying about it. Since I would
>> like to use urwid for an ipython interpreter, and ipython wants to
>> switch to python 3 as soon as possible, I thought I might see how well
>> it works to switch urwid over to python 3... and after trying it out, I
>> have a fairly well working python 3 version of urwid!
> Thanks, I did notice you working on that in github.
>
>> Its available at http://github.com/wackywendell/urwid
>> Or if you're using git:
>> $ git clone git://github.com/wackywendell/urwid.git
>>
>> Its setup to use the recommended way of converting to python 3: the code
>> posted is working py2.6 code, and if you run the 2to3 converter on it,
>> it should give you working python3 code. There is a script called
>> '23dir' in there as well, which runs through the urwid directory, and
>> copies everything to an urwid3 directory. When its done, there should be
(Continue reading)

Muhammad Ammar | 11 Aug 2010 18:03
Picon

fixed sized footer

Hi All,

Following is a sample code, the problem is that when "txtstatus2msg" text string is large the footer resize itself, how can i avoid footer resize.
i want to shift the text to next line without resizing the footer.

Anyone have any hint/idea?


import urwid


palette = [('header', 'black', 'light gray'),
           ('body', 'black', 'light blue'),
           ('footer', 'black', 'light magenta')]

txt_title = urwid.Text("My Application", 'center')

txt_title = urwid.Pile([urwid.Divider(top=2),
                        txt_title,
                        urwid.Divider(top=1)])

head = urwid.AttrMap(txt_title, 'header')

txt_one = urwid.Text("one  ", 'center')
txt_two = urwid.Text("two ", 'center')
txt_close = urwid.Text("exit ", 'center')

menuList = urwid.SimpleListWalker([
                                       urwid.Divider(" "),    
                                       txt_one,
                                       urwid.Divider(" "),
                                       txt_two,
                                       urwid.Divider(" "),
                                       txt_close,
                                       urwid.Divider(" "),
                                      ])

lb = urwid.ListBox(menuList)

body = urwid.LineBox(lb)
body = urwid.Padding(body, align='center', width=40)
body = urwid.Filler(body, valign='middle', height=9)
body = urwid.AttrMap(body, 'body')

txt_status1       = urwid.Text("Status: ", 'left')       
txtstatus1msg     = urwid.Text("")
txt_status2       = urwid.Text("Message: ")
txtstatus2msg     = urwid.Text("")
       
cols = urwid.Columns([('fixed', 10, txt_status1),
                      ('fixed', 20, txtstatus1msg),
                      ('fixed', 9, txt_status2),
                                   txtstatus2msg], )
       
status = urwid.Pile([urwid.Divider(top=1), cols, urwid.Divider(top=2)])
status = urwid.Padding(status, 'center', 70)                   #can't change this, else controls will not be in center

footer = urwid.AttrMap(status, 'footer')

top = urwid.Frame(body, head, footer)
top = urwid.AttrMap(top, 'bg')

def OnKey(key):
             
    if key == 'f6':
        txtstatus2msg.set_text("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
        
    if key == 'f7':
        txtstatus2msg.set_text("aaaaaaaaaaaaaaaaaaaaaaaaaaa")

loop = urwid.MainLoop(top, palette, unhandled_input=OnKey)
loop.run()

Regards,
_______________________________________________
Urwid mailing list
Urwid <at> lists.excess.org
http://lists.excess.org/mailman/listinfo/urwid
Ian Ward | 12 Aug 2010 00:10
Favicon
Gravatar

Re: fixed sized footer

Muhammad Ammar wrote on 2010-08-11 12:03:
> Hi All,
> 
> Following is a sample code, the problem is that when "txtstatus2msg"
> text string is large the footer resize itself, how can i avoid footer
> resize.
> i want to shift the text to next line without resizing the footer.
> 
> Anyone have any hint/idea?

    txtstatus2msg = urwid.Text("", wrap='clip')

is one way.

Ian
goffi | 20 Aug 2010 11:52

SàT: XMPP client with urwid frontend + smalls remarks about urwid

Hi there,

I've just release SàT 0.0.3 which is a XMMP client based on a 
daemon/frontend architecture, communicating by DBus.
The idea is to have everything done in the daemon, and the frontend only 
manage the view.
Currently the following frontends exist:
- Wix (WxWidget): GUI
- Primitivus (Urwid): Console interface
- Jp: CLI
A Web and Qt (Kde ?) frontend are also planed.

The daemon is based on Twisted/Wokkel. The sources and some screenshots 
are available on my website 
(http://www.goffi.org/index.php?post/2010/08/19/Salut-%C3%A0-Toi-v0.0.3 
- in french sorry - or http://www.goffi.org/index.php?download/35 for 
the direct download). Note that the project is *not yet intended for 
end-user*, and the installation is currently a bit complex (but there is 
step-by-step how-to in INSTALL file). The project will hopefully be 
usable for end-user around the end of the year, and should be 
multi-platform.

I talk about this here because my previously-ncurses based console 
interface now uses Urwid, and thanks to you I could do stuffs quickly 
and efficiently. I have made some widgets which can eventually be useful 
to others (advanced edit, tabs container, or file selection dialog box), 
you can check in frontends/primitivus directory, you will probably be 
interested by custom_widgets.py and files_management.py. Everything is 
under GPL v3

I have two small remarks:
- except if I have missed something, there is nothing to dynamically 
change Colums and Pile widget, I had to manually change widget_list and 
column_types, which can be broken if the Urwid code change. I think a 
few methods to add/remove dynamically widget should be useful
- I heavily use DBus, and dbus return dbus.String objects, which are 
subclasses of unicode. But Urwid do a strict type comparison, and I have 
a TagMarkupException when trying, for e.g. to create an urwid.Text. 
Using isinstance can fix it. As suggested on IRC chan, you can find a 
small patch attached.

Here what I have without path:

In [1]:  import urwid
In [2]: import dbus
In [3]: toto = dbus.String('toto')
In [4]: txt_wid = urwid.Text(toto)
 > ...blah...
 > TagMarkupException: Invalid markup element: dbus.String(u'toto')

With the patch it works.
Note: there is an other strict type check in widget.py (l.910), but the 
following unicode conversion make it working.

Thanks again for the good work, and enjoy :)
Goffi

_______________________________________________
Urwid mailing list
Urwid <at> lists.excess.org
http://lists.excess.org/mailman/listinfo/urwid
Ian Ward | 21 Aug 2010 14:51
Favicon
Gravatar

Re: SàT: XMPP client with urwid frontend + smalls remarks about urwid

goffi wrote on 2010-08-20 05:52:
> I've just release SàT 0.0.3 which is a XMMP client based on a
> daemon/frontend architecture, communicating by DBus.
> The idea is to have everything done in the daemon, and the frontend only
> manage the view.
> Currently the following frontends exist:
> - Wix (WxWidget): GUI
> - Primitivus (Urwid): Console interface
> - Jp: CLI
> A Web and Qt (Kde ?) frontend are also planed.
> 
> The daemon is based on Twisted/Wokkel. The sources and some screenshots
> are available on my website
> (http://www.goffi.org/index.php?post/2010/08/19/Salut-%C3%A0-Toi-v0.0.3
> - in french sorry - or http://www.goffi.org/index.php?download/35 for
> the direct download). Note that the project is *not yet intended for

Wow.  It looks really nice.  I've added a link to it from
http://excess.org/urwid/wiki/ApplicationList and marked it "ALPHA".
Please update the link as you see fit.

> end-user*, and the installation is currently a bit complex (but there is
> step-by-step how-to in INSTALL file). The project will hopefully be
> usable for end-user around the end of the year, and should be
> multi-platform.
> 
> I talk about this here because my previously-ncurses based console
> interface now uses Urwid, and thanks to you I could do stuffs quickly
> and efficiently. I have made some widgets which can eventually be useful
> to others (advanced edit, tabs container, or file selection dialog box),
> you can check in frontends/primitivus directory, you will probably be
> interested by custom_widgets.py and files_management.py. Everything is
> under GPL v3

That's great to see.  Is there any chance you would license that file
more permissively so that parts of it might become part of Urwid? (Urwid
is LGPLv2)

> I have two small remarks:
> - except if I have missed something, there is nothing to dynamically
> change Colums and Pile widget, I had to manually change widget_list and
> column_types, which can be broken if the Urwid code change. I think a
> few methods to add/remove dynamically widget should be useful

That's correct.  Every time I start to work on that I seem to get
sidetracked by my desire to refactor all the container widgets to pull
out the common parts.  There's even a plan on the wiki from 3 years (!) ago.

Your point is well taken.  It's more important to have an interface to
modify Columns/Pile than that the interface and implementation are perfect.

> - I heavily use DBus, and dbus return dbus.String objects, which are
> subclasses of unicode. But Urwid do a strict type comparison, and I have
> a TagMarkupException when trying, for e.g. to create an urwid.Text.
> Using isinstance can fix it. As suggested on IRC chan, you can find a
> small patch attached.

Applied.  Thanks.

Ian
goffi | 23 Aug 2010 09:32

Re: SàT: XMPP client with urwid frontend + smalls remarks about urwid

On 21/08/10 20:51, Ian Ward wrote:
> I've added a link to it from
> http://excess.org/urwid/wiki/ApplicationList  and marked it "ALPHA".
> Please update the link as you see fit.
>
>

cool, thx :)

> That's great to see.  Is there any chance you would license that file
> more permissively so that parts of it might become part of Urwid? (Urwid
> is LGPLv2)
>

Well, I will keep my main project under GPL v3, but I can understand the 
need of LGPL for a library, so what can I do is separate the widgets in 
a library, and release it under LGPL. BTW, why are you using LGPL v2 
instead of v3 ?

I would really be happy to see theses widgets part of Urwid, but I think 
the code need some work to reach your coding standard and to follow your 
coding style (it use a mix of CamelCase and underline_names as I use 
CamelCase for function names, and Urwid use underlines), it probably 
need a review from Urwid devs.

In addition, I use some stuff specific to my project, which need to be a 
little more generic (for example the code to render focus is really 
ugly). I put below a list of the available widgets. Please also note 
that I'm currently travelling, until next December, so I'm not easily 
available on IRC (I don't always have an Internet connexion), so the 
best is probably to contact me by mail.

Widgets made for SàT:
- Password: an Edit widget with an additional 'hidden_char' argument, 
this character (default '*') is showed instead of real text

- SurroundedText: Text centred on a repeated character (like a Divider, 
but with a text in the centre). I was mainly needing this for the 
LabelLine decorator (see below)

- AdvancedEdit: an Edit widget which the following added keys:
               - C-a: like 'home'
               - C-e: like 'end'
               - C-k: remove everything on the right of the cursor
               - C-w: remove the word on the left
               - Shif-[tab]: completion (I didn't used [tab] alone as 
it's already used to change focus)
    The completion use a callback defined by user, and an arg is used to 
keep track of the last completion (so if you press shift-[tab] several 
times you will roll between possible completions).

- SelectableText: a text which, as name suggest, can be selected (useful 
for e.g. making list of choices). You can define an other text/attribute 
when the text is selected (for example change the background color).

- ClickableText: a text which emit a "click" signal when [enter] is 
pressed (or mouse left button) on it

- CustomButton: quite similar to Button, but doesn't expand to all 
available room, and you can change left and right border (it was needed 
for tabs container). It can also give it's rendering size.

- GenericList/List: a wannabe List selection widget, but need work.

- NotificationBar: probably too involved with Primitivus (the urwid 
frontend for SàT) to be useful for somebody else

- MenuBox/Menu/MenuRoller: widgets to make menus (which works with 
mouse) which a box who appears to select items. You have one menu that 
you can roll with the MenuRoller (I did this to save place on screen). 
The best to understand is probably to try Primitivus or see the screenshots.

- GenericDialog/InputDialog/ConfirmDialog/Alert: common simple dialogs.

- ColumnsRoller: Put all widgets on 1 row (never more), and instead of 
hiding them when there is not enough room, it show an arrow to move 
between them (not sure to be clear !).

- FocusFrame: just a frame where you can change Focus between 
header/body/footer by pressing [tab] (except if [tab] is already used by 
one widget)

- TabsContainer: As name suggest, it's a container (often called 
"Notebook" in GUI toolkits) where you can associate tabs with "pages" 
and select them by clicking/pressing on it. When you click on a tab, the 
"page" (widget) associated with it will be showed

- LabelLine: Like LineBox except that you can change the top with a 
label (by using SurroundedText). I'm using it to save space (the title 
is on the decorator and doesn't take another line).

- VerticalSeparator: Draw a line (or any character) on the left and/or 
right of a widget

and the FilesViewer widget use lot of the above widgets and has the 
following features:
     - a path line on the top with all the features of AdvancedEdit, 
where C-w delete smartly one path part (e.g.: '/home/toto' + C-w ==> 
'/home').
	When you change a path, if it's a dir, the files list is automatically 
updated.
	If you press '~' as first character, '/home/[username]' will appear 
automatically.
	Completion works: for exemple if you are in '/home', press shit-[tab] 
to roll between user names.
     - a bookmark part on the left: it try to read gtk and kde's 
bookmarks and show them. It can be nice to have a way to add our own 
bookmarks.
     - the right part show files: the directory on the top, and the 
files below. Pressing 'meta-d' go in directories, 'meta-f' go in files. 
meta-h (un)hide hidden files. If you write the first characters of a 
file, you will go directly on it. For e.g. if you are in '/usr', 
pressing 'g' and 'a' will go on 'games'.

cheers
Goffi
Ian Ward | 26 Aug 2010 15:48
Favicon
Gravatar

Re: SàT: XMPP client with urwid frontend + smalls remarks about urwid

goffi wrote on 2010-08-23 03:32:
> On 21/08/10 20:51, Ian Ward wrote:
>> That's great to see.  Is there any chance you would license that file
>> more permissively so that parts of it might become part of Urwid? (Urwid
>> is LGPLv2)
>>
> 
> Well, I will keep my main project under GPL v3, but I can understand the 
> need of LGPL for a library, so what can I do is separate the widgets in 
> a library, and release it under LGPL. BTW, why are you using LGPL v2 
> instead of v3 ?

Urwid is old (predates GPLv3) and I'm not interested enough in licensing
to have done a comparison.

I did initially release Urwid under the GPL but changed to the LGPL
after someone asked for a more permissive license.

> I would really be happy to see theses widgets part of Urwid, but I think 
> the code need some work to reach your coding standard and to follow your 
> coding style (it use a mix of CamelCase and underline_names as I use 
> CamelCase for function names, and Urwid use underlines), it probably 
> need a review from Urwid devs.
> 
> In addition, I use some stuff specific to my project, which need to be a 
> little more generic (for example the code to render focus is really 
> ugly). I put below a list of the available widgets. Please also note 
> that I'm currently travelling, until next December, so I'm not easily 
> available on IRC (I don't always have an Internet connexion), so the 
> best is probably to contact me by mail.

Once the widgets are separated out I could start by putting them in with
the contributed examples.  I know people would find them useful even in
their current state.

Ian
goffi | 27 Aug 2010 05:24

Re: SàT: XMPP client with urwid frontend smalls remarks about urwid

Quoting Ian Ward <ian <at> excess.org>:

> Urwid is old (predates GPLv3) and I'm not interested enough in licensing
> to have done a comparison.

Licensing is boring to me too =). The main additions in GPL v3 are protections
against Tivoization and other ways to walk around GPL, which where not known at
the time of v2. I have seen several companies trying to do that, and if we can
avoid it, it's better.

> Once the widgets are separated out I could start by putting them in with
> the contributed examples.  I know people would find them useful even in
> their current state.

Oki I'll do it ASAP.

cheers
Goffi

Gmane