1 title = 'Pmw.HistoryText demonstration'
3 # Import Pmw from this directory tree.
5 sys.path[:0] = ['../../..']
11 def __init__(self, parent):
12 # Create and pack the PanedWidget to hold the query and result
14 # !! panedwidget should automatically size to requested size
15 panedWidget = Pmw.PanedWidget(parent,
19 panedWidget.add('query', min = 0.05, size = 0.2)
20 panedWidget.add('buttons', min = 0.1, max = 0.1)
21 panedWidget.add('results', min = 0.05)
22 panedWidget.pack(fill = 'both', expand = 1)
24 # Create and pack the HistoryText.
25 self.historyText = Pmw.HistoryText(panedWidget.pane('query'),
29 historycommand = self.statechange,
31 self.historyText.pack(fill = 'both', expand = 1)
32 self.historyText.component('text').focus()
36 ['Clear', self.clear],
37 ['Undo', self.historyText.undo],
38 ['Redo', self.historyText.redo],
40 ['Prev', self.historyText.prev],
41 ['Next', self.historyText.next],
43 ['Execute', Pmw.busycallback(self.executeQuery)],
47 buttonFrame = panedWidget.pane('buttons')
48 for text, cmd in buttonList:
49 if type(text) == type(69):
50 frame = Tkinter.Frame(buttonFrame, width = text)
51 frame.pack(side = 'left')
53 button = Tkinter.Button(buttonFrame, text = text, command = cmd)
54 button.pack(side = 'left')
55 self.buttonDict[text] = button
57 for text in ('Prev', 'Next'):
58 self.buttonDict[text].configure(state = 'disabled')
60 self.results = Pmw.ScrolledText(panedWidget.pane('results'), text_wrap = 'none')
61 self.results.pack(fill = 'both', expand = 1)
63 def statechange(self, prevstate, nextstate):
64 self.buttonDict['Prev'].configure(state = prevstate)
65 self.buttonDict['Next'].configure(state = nextstate)
68 self.historyText.delete('1.0', 'end')
70 def addnewlines(self, text):
79 def executeQuery(self):
80 sql = self.historyText.get()
81 self.results.insert('end', 'Query:\n' + self.addnewlines(sql))
82 self.results.see('end')
83 self.results.update_idletasks()
84 self.historyText.addhistory()
85 results = 'Results:\nfoo'
87 self.results.insert('end', self.addnewlines(results))
88 self.results.see('end')
91 ######################################################################
93 # Create demo in root window for testing.
94 if __name__ == '__main__':
99 exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
100 exitButton.pack(side = 'bottom')