Re: How to align the text of a Listbox to the right

2006-04-28 Thread Edward Elliott
Leonardo da Vinci wrote:
>> to limit the width to something acceptable, and show
>> only the tail of the line.
> 
> Yes, this is exactly what I wanted to do. Do you know a way to
> accomplish that? Because Eric Brunel said it is impossible on a
> Listbox.

Use a string slice.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to align the text of a Listbox to the right

2006-04-28 Thread Leonardo da Vinci
Sori Schwimmer ha scritto:

> For a listbox, I would give a width and go with string
> formatting. In your case, I guess that what I'll do is
> to limit the width to something acceptable, and show
> only the tail of the line.

Yes, this is exactly what I wanted to do. Do you know a way to
accomplish that? Because Eric Brunel said it is impossible on a
Listbox.
Thanks to everybody,

L

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to align the text of a Listbox to the right

2006-04-28 Thread Eric Brunel
On 27 Apr 2006 07:00:36 -0700, Leonardo da Vinci  
<[EMAIL PROTECTED]> wrote:

> I have to use a Listbox that shows a list of entries. Every entry is a
> char string quite long in size and I cannot set "width" to a large
> value due to limitations of screen resolution. The rightmost part is
> more important, so I thought that I could show only the end of the
> string by aligning the field to the right.

As I see it, there are two solutions to your problems:
- Display your strings differently. It may seem stupid, but there are  
sometimes situations where it is the best solution. Think about Apple's  
way of displaying full file path names in menus: they put the file base  
name first, then the full directory after a separator. If you have a way  
to do that, your problem is solved.
- Don't use a Listbox to display your list, but another widget. A simple  
Text with no wrap option may be a solution; setting a tag with the option  
justify=LEFT on your whole text would do the trick. But if your lines of  
text should be selectable, it may not be the right solution. In this case,  
another widget you can use is a Canvas. It's a little trickier but can be  
done. Here is an example:

--
 from Tkinter import *

root = Tk()

cnv = Canvas(root, width=150, height=250)
cnv.grid(row=0, column=0, sticky='nswe')
hscroll = Scrollbar(root, orient=HORIZONTAL, command=cnv.xview)
hscroll.grid(row=1, column=0, sticky='we')
vscroll = Scrollbar(root, orient=VERTICAL, command=cnv.yview)
vscroll.grid(row=0, column=1, sticky='ns')
cnv.configure(xscrollcommand=hscroll.set, yscrollcommand=vscroll.set)

xMax = 0
y = 0
for i in range(20):
   lbl = Label(cnv, text='Very, very long item number %s' % i)
   cnv.create_window(150, y, window=lbl, anchor='ne')
   y += lbl.winfo_reqheight()
   xMax = max(xMax, lbl.winfo_reqwidth())

cnv.configure(scrollregion=(150 - xMax, 0, 150, y))

root.mainloop()
--

Putting bindings on the Label widgets created in the loop can be used to  
simulate the behaviour of a Listbox.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to align the text of a Listbox to the right

2006-04-27 Thread Jarek Zgoda
Sori Schwimmer napisaƂ(a):

> For a listbox, I would give a width and go with string
> formatting. In your case, I guess that what I'll do is
> to limit the width to something acceptable, and show
> only the tail of the line.
> 
> Say, your width is w, then I'll show only the last w-4
> chars, preceded by '... ' (ellipsis+space). It might
> be nice to put a label on top of your listbox and
> dynamically change it's text attribute to the complete
> version of your selection in the listbox, broken in
> lines of appropriate length.

Yeah, but what is the question?

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


How to align the text of a Listbox to the right

2006-04-27 Thread Sori Schwimmer
For a listbox, I would give a width and go with string
formatting. In your case, I guess that what I'll do is
to limit the width to something acceptable, and show
only the tail of the line.

Say, your width is w, then I'll show only the last w-4
chars, preceded by '... ' (ellipsis+space). It might
be nice to put a label on top of your listbox and
dynamically change it's text attribute to the complete
version of your selection in the listbox, broken in
lines of appropriate length.

Hope this helps,
Sorin Schwimmer

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to align the text of a Listbox to the right

2006-04-27 Thread Leonardo da Vinci
I have to use a Listbox that shows a list of entries. Every entry is a
char string quite long in size and I cannot set "width" to a large
value due to limitations of screen resolution. The rightmost part is
more important, so I thought that I could show only the end of the
string by aligning the field to the right.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to align the text of a Listbox to the right

2006-04-27 Thread Eric Brunel
On 27 Apr 2006 02:35:50 -0700, Leonardo da Vinci  
<[EMAIL PROTECTED]> wrote:

> Greetings gentlemen and ladies,
> I have a question: in Tkinter, how to align a Listbox entry (i.e. a
> line of text) to the right?

In a real Listbox, the answer is simple: you can't.

What are you trying to do? Maybe there is another widget more suited to  
your needs.
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


How to align the text of a Listbox to the right

2006-04-27 Thread Leonardo da Vinci
Greetings gentlemen and ladies,
I have a question: in Tkinter, how to align a Listbox entry (i.e. a
line of text) to the right?
Google did not show up the answer to my request.
Thanks very much.

L

-- 
http://mail.python.org/mailman/listinfo/python-list