title
= 'Pmw.HistoryText demonstration'
# Import Pmw from this directory tree.
sys
.path
[:0] = ['../../..']
def __init__(self
, parent
):
# Create and pack the PanedWidget to hold the query and result
# !! panedwidget should automatically size to requested size
panedWidget
= Pmw
.PanedWidget(parent
,
panedWidget
.add('query', min = 0.05, size
= 0.2)
panedWidget
.add('buttons', min = 0.1, max = 0.1)
panedWidget
.add('results', min = 0.05)
panedWidget
.pack(fill
= 'both', expand
= 1)
# Create and pack the HistoryText.
self
.historyText
= Pmw
.HistoryText(panedWidget
.pane('query'),
historycommand
= self
.statechange
,
self
.historyText
.pack(fill
= 'both', expand
= 1)
self
.historyText
.component('text').focus()
['Undo', self
.historyText
.undo
],
['Redo', self
.historyText
.redo
],
['Prev', self
.historyText
.prev
],
['Next', self
.historyText
.next
],
['Execute', Pmw
.busycallback(self
.executeQuery
)],
buttonFrame
= panedWidget
.pane('buttons')
for text
, cmd
in buttonList
:
if type(text
) == type(69):
frame
= Tkinter
.Frame(buttonFrame
, width
= text
)
frame
.pack(side
= 'left')
button
= Tkinter
.Button(buttonFrame
, text
= text
, command
= cmd
)
button
.pack(side
= 'left')
self
.buttonDict
[text
] = button
for text
in ('Prev', 'Next'):
self
.buttonDict
[text
].configure(state
= 'disabled')
self
.results
= Pmw
.ScrolledText(panedWidget
.pane('results'), text_wrap
= 'none')
self
.results
.pack(fill
= 'both', expand
= 1)
def statechange(self
, prevstate
, nextstate
):
self
.buttonDict
['Prev'].configure(state
= prevstate
)
self
.buttonDict
['Next'].configure(state
= nextstate
)
self
.historyText
.delete('1.0', 'end')
def addnewlines(self
, text
):
sql
= self
.historyText
.get()
self
.results
.insert('end', 'Query:\n' + self
.addnewlines(sql
))
self
.results
.update_idletasks()
self
.historyText
.addhistory()
results
= 'Results:\nfoo'
self
.results
.insert('end', self
.addnewlines(results
))
######################################################################
# Create demo in root window for testing.
if __name__
== '__main__':
exitButton
= Tkinter
.Button(root
, text
= 'Exit', command
= root
.destroy
)
exitButton
.pack(side
= 'bottom')