1 ##---------------------------------------------------------------------------##
3 ## idle - simple text view dialog
6 ##---------------------------------------------------------------------------##
8 simple text browser for idle
13 class TextViewer(Toplevel
):
15 simple text viewer dialog for idle
17 def __init__(self
,parent
,title
,fileName
):
19 fileName - string,should be an absoulute filename
21 Toplevel
.__init
__(self
, parent
)
22 self
.configure(borderwidth
=5)
23 self
.geometry("+%d+%d" % (parent
.winfo_rootx()+10,
24 parent
.winfo_rooty()+10))
25 #elguavas - config placeholders til config stuff completed
31 self
.transient(parent
)
33 self
.protocol("WM_DELETE_WINDOW", self
.Ok
)
35 self
.textView
.focus_set()
36 #key bindings for this dialog
37 self
.bind('<Return>',self
.Ok
) #dismiss dialog
38 self
.bind('<Escape>',self
.Ok
) #dismiss dialog
39 self
.LoadTextFile(fileName
)
40 self
.textView
.config(state
=DISABLED
)
43 def LoadTextFile(self
, fileName
):
46 textFile
= open(fileName
, 'r')
48 tkMessageBox
.showerror(title
='File Load Error',
49 message
='Unable to load file '+`fileName`
+' .')
51 self
.textView
.insert(0.0,textFile
.read())
53 def CreateWidgets(self
):
54 frameText
= Frame(self
)
55 frameButtons
= Frame(self
)
56 self
.buttonOk
= Button(frameButtons
,text
='Ok',
57 command
=self
.Ok
,takefocus
=FALSE
,default
=ACTIVE
)
58 self
.scrollbarView
= Scrollbar(frameText
,orient
=VERTICAL
,
59 takefocus
=FALSE
,highlightthickness
=0)
60 self
.textView
= Text(frameText
,wrap
=WORD
,highlightthickness
=0)
61 self
.scrollbarView
.config(command
=self
.textView
.yview
)
62 self
.textView
.config(yscrollcommand
=self
.scrollbarView
.set)
63 self
.buttonOk
.pack(padx
=5,pady
=5)
64 self
.scrollbarView
.pack(side
=RIGHT
,fill
=Y
)
65 self
.textView
.pack(side
=LEFT
,expand
=TRUE
,fill
=BOTH
)
66 frameButtons
.pack(side
=BOTTOM
,fill
=X
)
67 frameText
.pack(side
=TOP
,expand
=TRUE
,fill
=BOTH
)
69 def Ok(self
, event
=None):
72 if __name__
== '__main__':
75 Button(root
,text
='View',
76 command
=lambda:TextViewer(root
,'Text','./textView.py')).pack()