summaryrefslogtreecommitdiffstats
path: root/Tools/idle/HelpWindow.py
blob: a1b13c34ce5d2e1ebf43f8e211027cde0c6b8905 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import sys
from Tkinter import *


class HelpWindow:

    helpfile = "help.txt"
    helptitle = "Help Window"

    def __init__(self, root=None):
        if not root:
            import Tkinter
            root = Tkinter._default_root
        if root:
            self.top = top = Toplevel(root)
        else:
            self.top = top = root = Tk()

        helpfile = self.helpfile
        if not os.path.exists(helpfile):
            base = os.path.basename(self.helpfile)
            for dir in sys.path:
                fullname = os.path.join(dir, base)
                if os.path.exists(fullname):
                    helpfile = fullname
                    break
        try:
            f = open(helpfile)
            data = f.read()
            f.close()
        except IOError, msg:
            data = "Can't open the help file (%s)" % `helpfile`

        top.protocol("WM_DELETE_WINDOW", self.close_command)
        top.wm_title(self.helptitle)

        self.close_button = Button(top, text="close",
                                   command=self.close_command)
        self.close_button.pack(side="bottom")

        self.vbar = vbar = Scrollbar(top, name="vbar")
        self.text = text = Text(top)

        vbar["command"] = text.yview
        text["yscrollcommand"] = vbar.set

        vbar.pack(side="right", fill="y")
        text.pack(side="left", fill="both", expand=1)

        text.insert("1.0", data)

        text.config(state="disabled")
        text.see("1.0")

    def close_command(self):
        self.top.destroy()


def main():
    h = HelpWindow()
    h.top.mainloop()

if __name__ == "__main__":
    main()