Tkinter: Clipping a canvas text item

Discussion in 'Python' started by Peter Otten, Feb 21, 2004.

  1. Peter Otten

    Peter Otten Guest

    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
     
    Peter Otten, Feb 21, 2004
    #1
    1. Advertising

  2. Peter Otten

    robin bryce Guest

    Re: running fastcgi on windows?

    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.1:pORTNUM

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


    Hope this helps & best of luck.

    Robin

    [1] http://www.fastcgi.com/mod_fastcgi/docs/mod_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/
     
    robin bryce, Feb 21, 2004
    #2
    1. Advertising

  3. Peter Otten

    robin bryce Guest

    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
     
    robin bryce, Feb 21, 2004
    #3
  4. Peter Otten

    John Roth Guest

    "Peter Otten" <> wrote in message
    news:c17ls5$hmr$04$-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
     
    John Roth, Feb 21, 2004
    #4
  5. Peter Otten

    wolf Guest

    Re: running fastcgi on windows?

    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
     
    wolf, Feb 23, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. john
    Replies:
    1
    Views:
    615
    alan.washington
    Oct 20, 2004
  2. humbads
    Replies:
    4
    Views:
    1,253
    Shailesh Humbad
    Feb 16, 2006
  3. Douglas Alan

    Tkinter, resizing, and widget clipping

    Douglas Alan, Nov 7, 2003, in forum: Python
    Replies:
    1
    Views:
    422
    Douglas Alan
    Nov 8, 2003
  4. Askari
    Replies:
    2
    Views:
    726
    Askari
    Aug 30, 2004
  5. PhilC
    Replies:
    2
    Views:
    909
    PhilC
    Oct 25, 2004
Loading...

Share This Page