supertextbox.py :  » Network » Grail-Internet-Browser » grail-0.6 » utils » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Grail Internet Browser 
Grail Internet Browser » grail 0.6 » utils » supertextbox.py
if __name__ == '__main__':
    # Testing
    import sys
    sys.path.insert(0, "../pythonlib")


from tktools import *


def make_super_text_box(parent, width=0, height=0, hbar=0, vbar=1,
                  fill=BOTH, expand=1, wrap=WORD, pack=1):

    """Create a text box with smooth scrolling."""

    hbar, vbar, frame = make_scrollbars(parent, hbar, vbar, pack)
    subframe = Frame(frame, borderwidth=2, relief=SUNKEN)
    subframe.pack(expand=expand, fill=fill)
    canvas = Canvas(subframe)
    frame.canvas = canvas
    canvas.pack(expand=expand, fill=fill, side=LEFT)
    text = Text(canvas, wrap=wrap, borderwidth=0)
    canvas.create_window(0, 0,
                         anchor=NW,
                         tags='theText',
                         window=text)
    if width:
        text.config(width=width)
        width = text.winfo_reqwidth()
        canvas.config(width=width)
        canvas.itemconfig('theText', width=width)
    if height:
        text.config(height=height)
        height = text.winfo_reqheight()
        canvas.config(height=height)
        canvas.itemconfig('theText', height=height)
    set_scroll_commands(text, hbar, None)
    text.vbar = vbar
    set_scroll_commands(canvas, None, vbar)
    canvas.text = text
    canvas.bind('<Configure>', resize_super_text_box)
    return text, frame


def resize_super_text_box(event=None, frame=None):
    canvas = frame and frame.canvas or event.widget
    canvas.update_idletasks()
    width = canvas.winfo_width()
    height = canvas.winfo_height()
##    print "canvas:", width, "x", height
    fakeheight = 1000000
    canvas.itemconfig('theText', width=width, height=fakeheight)
    text = canvas.text
    text.yview("1.0")
    canvas.update_idletasks()
    info = text.dlineinfo("end-1char")
##    print "info:", info
    if info:
        x, y, w, h, bl = info
        totheight = y + h
        canvas.config(scrollregion=(0, 0, width, totheight))
    else:
        canvas.config(scrollregion=(0, 0, 0, 0))


def test():
    data = "The quick brown fox jumps over the lazy dog.\n" * 25 + "END"
    root = Tk()
    super, frame = make_super_text_box(root, hbar=1, vbar=1,
                                       width=40, height=20, wrap=NONE)
    super.insert(END, data)
    resize_super_text_box(frame=frame)
    root.mainloop()


if __name__ == '__main__':
    test()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.