Zitat von Fabian Braennstroem <[EMAIL PROTECTED]>:
> Hi,
>
> me again :-)
>
> I am still looking for some features, which might be nice to
> have for a file manager. I would like to set different
> colors for the file names depending on the extension. Is
> this possible using a listbox? I saw that I can use
> 'palette' for basic color settings, but it looks like that I
> am not able to change the color from entry to entry!?
The palette defines only the "attributes" that you might use. But defining
a palette doesn't mean that those attributes are applied to anything. You
have to apply the attributes to the widgets manually using AttrWrap:
wrapped_widget = AttrWrap(my_widget, "my_attribute")
Widgets without their own attribute are rendered with the attribute of
the widget containing them (if any, otherwise with the default colours of
the terminal).
Try the attached program!
>
> Do you recommend using the listbox for such file entries at
> all? I would like to add the size, date and mode of the
> files in certain regions (columns) of the listbox. It would
> be some kind of table; e.g. like in Rebecca's 'unicore'.
> Would be nice, if you got any recommendations!
The ListBox is great! :)
For my "table", I used a Columns widgets with each column containing a
ListBox widget. So in your case that would be one ListBox with the filenames
in the first column, one ListBox with the according file sizes in the second
column etc. This approach gets a little tricky if you want rows of this table
to be selectable only as a whole, but I could post a stand alone version of the
Table widget I am using in the unicore configuration stuff, if you are
interested.
Rebecca
#! /usr/bin/env python
import urwid.curses_display;
import urwid;
def run():
text1 = urwid.Text("I don't have my own attribute.")
text2 = urwid.AttrWrap(urwid.Text("I am red!"), "red_on_cyan");
text3 = urwid.Text("I don't have my own attribute, either.")
listbox = urwid.ListBox([text1, text2, text3]);
listbox = urwid.AttrWrap(listbox, "black_on_cyan");
dim = ui.get_cols_rows();
while True:
keys = ui.get_input();
if "window resize" in keys:
dim = ui.get_cols_rows();
ui.draw_screen(dim, listbox.render(dim, True));
#init screen:
ui = urwid.curses_display.Screen();
ui.register_palette(
[('black_on_cyan', 'black', 'dark cyan', 'standout'),
('red_on_cyan', 'light red', 'dark cyan'),
])
ui.run_wrapper(run);
_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid