-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextEditor.py
More file actions
55 lines (44 loc) · 1.74 KB
/
TextEditor.py
File metadata and controls
55 lines (44 loc) · 1.74 KB
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
#!/usr/bin/env python
import wx
import os
class MyFrame(wx.Frame):
""" We simply derive a new class of Frame. """
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(200,100))
self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
self.CreateStatusBar()
# Setting up the menu
filemenu = wx.Menu()
menuAbout = filemenu.Append(wx.ID_ABOUT, "About", " Information about this program")
menuExit = filemenu.Append(wx.ID_EXIT, "Exit", " Terminate the program")
menuOpen = filemenu.Append(wx.ID_OPEN, "Open", " Open a file")
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append(filemenu, "File")
self.SetMenuBar(menuBar)
# Set events
self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
self.Bind(wx.EVT_MENU, self.OnOpen, menuOpen)
#filemenu.AppendSeparator()
self.Show(True)
def OnAbout(self, event):
dlg = wx.MessageDialog(self, "A small text editor", "About sample editor", wx.OK)
dlg.ShowModal()
dlg.Destroy()
def OnExit(self, event):
self.Close(True)
def OnOpen(self, event):
""" Open a file """
self.dirname = ''
dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.filename = dlg.GetFilename()
self.dirname = dlg.GetDirectory()
f = open(os.path.join(self.dirname, self.filename), 'r')
self.control.SetValue(f.read())
f.close()
dlg.Destroy()
app = wx.App(False)
frame = MyFrame(None, 'Sample editor')
app.MainLoop()