Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Tkinter: Clipping a canvas text item

Reply
Thread Tools

Tkinter: Clipping a canvas text item

 
 
Peter Otten
Guest
Posts: n/a
 
      02-21-2004
Is there a way to limit both width and height of a canvas text item?
My current workaround seems clumsy:

import Tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root, width=400, height=200, bg="white")
canvas.pack()

# simulate a clipped text item - never transparent
s = "The long and winding road.."
lbl = tk.Label(root, text=s, anchor=tk.W, bg=canvas["bg"])
canvas.create_window(50, 80, width=100, height=20,
window=lbl,
anchor=tk.NW)

root.mainloop()

Thanks,
Peter
 
Reply With Quote
 
 
 
 
robin bryce
Guest
Posts: n/a
 
      02-21-2004
wolf,

I've been working in this area recently. I'm new to it too so don't take
what I say as gospel.

apache's mod_fastcgi talks to the scripts it loads via stdin, stdout and
stderr.

It deals with three basic cases: Dynamic scripts started when the url is
first accessed, Static scripts that are started with the apache server
and external scripts which are started independently of apache.

In all cases you need to think of the scripts in question as vanilla
executables that you would run at a command prompt. The difference is
that mod_fastcgi writes the request data to the exe process standard
input and expects response data, in FastCGI format, on the standard
output.

mod_fastcgi does not care what the 'exe' is as long as it replies using
the FastCGI protocol on the standard output.

The differences in the above cases are to do with how and when the
scripts are started and by what.

In all of the above cases fcgi.py acts as a utility script for helping
you to to write python scripts that can read fastcgi request data from
the standard input and reply to that request, in fastcgi format, on the
standard output. if you had a program other than apache that talked
FastCGI then these scripts would probably be just as happy talking to it
as they would apache.

the problem with fcgi.py on windows is probably, I have not tried it on
windows, to do with os dependencies introduced by the need to open and
manipulate sockets and redirect standard output. making it windows
friendly is essentially a job of bullying it into doing things the
Windows way (but see attached file and later comments for a possible
alternative).

the _test() function in fcgi.py is the basic template for the body of
your fastcgi friendly python script. a typical fast cgi friendly python
script would look like:

#!/path/to/python
import fcgi

# something modelled on the body of fcgi._test()

# end

I spent longer than I should have with this all broken simply because I
forgot that statements like print "why am I broken" write to the
standard output.

The best place for information about configuring Apache to use fastcgi
is proly the fastcgi site [1] and you should verify my assertions there.
Also a book that helped me loads was "Professional Apache 2.0" by Peter
Wainwright [2].

options for the dynamic case:

# turn on cgi
Options +ExecCGI

# turn on fastcgi for url's ending in .py - can be any extension you
like.

AddHandler fastcgi-script .py

# restart now and again to counter memory leaks and limmit the number of
processes

FastCgiConfig -restart -restart-delay 10 -maxprocesses 5

are about the only options you need - assuming you've loaded mod_fastcgi

options for the static case:

FastCgiServer /path/to/your/script.extension -init-start-delay 5
replaces FastCgiConfig


I recently modified the fcgi.py script you referenced to get it to work
with the Twisted framework [3]. This let me bridge from an apache server
to a remote Twisted web server using the the third, external server
model. After I did this I posted my changes [4] to fcgi.py to the
Twisted mailing list only to have someone, very kindly, point out I
could have got the same job done much easier with mod_proxy. I'm still
not clear if FastCGI offers any advantages over mod_proxy in this case.

The modifications remove the portions of fcgi.py that are dependent os
services and instead rely on the Twisted framework for this. I have not
run my app on a windows box since I introduced this feature but it was
running on windows before this. I can see no reason why it won't still
work.

This is the FastCGI case where apache is configured using the
FastCGIExternalServer directive.

FastCGIExternalServer /dummy/resource/path/foo.py -host
127.0.0.1ORTNUM

you can replace the ip address with a remote one or do
-RPORTNUM:127.0.0.1ORTNUM style tricks with ssh (PuTTY to windows
users[5]).


Hope this helps & best of luck.

Robin

[1] http://www.fastcgi.com/mod_fastcgi/d...d_fastcgi.html
[2] "Professional Apache 2.0"by Peter Wainwright. http://www.wrox.com/
[3] http://www.twistedmatrix.com/
[4] The version of fcgi.py with my mods is atatched. I've been in touch
with Robin Dunn and he's fine about me contributing my mods provided the
original copyright and boiler plate is left intact. Please note that
Robin Dunn has _not_ in anyway suggested that my mods are beneficial in
anyway.
[5] http://www.chiark.greenend.org.uk/~sgtatham/putty/


 
Reply With Quote
 
 
 
 
robin bryce
Guest
Posts: n/a
 
      02-21-2004
oops. wrong thread. apologies.

On Sat, 2004-02-21 at 13:19, Peter Otten wrote:
> Is there a way to limit both width and height of a canvas text item?
> My current workaround seems clumsy:
>
> import Tkinter as tk
> root = tk.Tk()
> canvas = tk.Canvas(root, width=400, height=200, bg="white")
> canvas.pack()
>
> # simulate a clipped text item - never transparent
> s = "The long and winding road.."
> lbl = tk.Label(root, text=s, anchor=tk.W, bg=canvas["bg"])
> canvas.create_window(50, 80, width=100, height=20,
> window=lbl,
> anchor=tk.NW)
>
> root.mainloop()
>
> Thanks,
> Peter



 
Reply With Quote
 
John Roth
Guest
Posts: n/a
 
      02-21-2004
"Peter Otten" <(E-Mail Removed)> wrote in message
news:c17ls5$hmr$04$(E-Mail Removed)-online.com...
> Is there a way to limit both width and height of a canvas text item?
> My current workaround seems clumsy:
>
> import Tkinter as tk
> root = tk.Tk()
> canvas = tk.Canvas(root, width=400, height=200, bg="white")
> canvas.pack()
>
> # simulate a clipped text item - never transparent
> s = "The long and winding road.."
> lbl = tk.Label(root, text=s, anchor=tk.W, bg=canvas["bg"])
> canvas.create_window(50, 80, width=100, height=20,
> window=lbl,
> anchor=tk.NW)
>
> root.mainloop()
>
> Thanks,
> Peter


I suppose if I absolutely had to do it, I'd clip by hiding the edges
under something else. Or else I'd find another toolkit that can
do the job. Thankfully, I don't have to do it.

John Roth


 
Reply With Quote
 
wolf
Guest
Posts: n/a
 
      02-23-2004
robin,

thanks a lot for your answer. it helps me in
so far as i now believe it should be feasible
to get fastcgi and python running on windows.
would you mind to re-post your modified file
directly? i'm afraid the attachment didn't make
it to the list and i couldn't find it on
the twisted mailing list either.

_wolf
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to couper contenier of a canvas in an outer canvas??? olsr.kamal@gmail.com Python 10 03-15-2013 08:46 PM
challenge: auto-clipping text on resize humbads HTML 4 02-16-2006 01:32 AM
Canvas with scrollbars - how to get correct canvas coordinate when the scroll bars have moved? PhilC Python 2 10-25-2004 11:57 AM
How can I force clipping of text in a table cell? john ASP .Net 1 10-20-2004 07:23 PM
Canvas scrolling - scrollBar become "disabled" on change in canvas Askari Python 2 08-30-2004 02:56 PM



Advertisments