# Use the tool bar to open the wxFileDialog
# cancel out of it and try to use the arrow keys.
# they don't work
# Sorry if this is old hat. I couldn't find any mention of it in this list.
···
#
# Darrell Gallion
from wxPython.wx import *
from wxPython.stc import *
class PythonSTC(wxStyledTextCtrl):
def __init__(self, parent, ID, topWindow):
wxStyledTextCtrl.__init__(self, parent, ID)
def OnOpenFile(self, evt):
dlg = wxFileDialog(self, "Choose a file", ".", "", "*.*", wxOPEN)
if dlg.ShowModal() == wxID_OK:
self.SetText(open(dlg.GetPath()).read())
dlg.Destroy()
def BuildToolBar(self, toolBar, frame):
toolBar.AddSimpleTool(20, wxBitmap('open.bmp', wxBITMAP_TYPE_BMP),
"Open")
EVT_TOOL(frame, 20, self.OnOpenFile)
toolBar.Realize()
def create(frame, topWindow, log):
ed = PythonSTC(frame, -1, topWindow)
toolBar =frame.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER)
ed.BuildToolBar(toolBar, frame)
ed.SetText("now is the time \n")
return ed
if __name__ == '__main__':
import sys
app = wxPySimpleApp()
frame = wxFrame(None, -1, "Tester...")
win = create(frame, frame, sys.stdout)
frame.Show(true)
app.MainLoop()