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 56 57 58 59 60 61
|
import os
from wxPython.wx import *
ID_OPEN=111
ID_NEW=112
ID_SAVE=113
class MainWindow(wxFrame):
def __init__(self,parent,id,title):
wxFrame.__init__(self,parent,wxID_ANY, title, size = (600, 400), style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
self.control = wxNotebook(self, 1)
filemenu= wxMenu()
filemenu.Append(ID_NEW, "&Nouveau"," Nouveau fichier")
filemenu.Append(ID_OPEN, "&Open"," Ouvrir un fichier")
filemenu.Append(ID_SAVE, "&Save"," Sauve un fichier")
menuBar = wxMenuBar()
menuBar.Append(filemenu,"&File")
self.SetMenuBar(menuBar)
EVT_MENU(self, ID_OPEN, self.OnOpen)
EVT_MENU(self, ID_NEW, self.OnNew)
EVT_MENU(self, ID_SAVE, self.OnSave)
self.Show(true)
def OnOpen(self,e):
self.dirname = ''
dlg = wxFileDialog(self, "Choose a file", self.dirname, "", "*.*", wxOPEN)
if dlg.ShowModal() == wxID_OK:
self.filename=dlg.GetFilename()
self.dirname=dlg.GetDirectory()
f=open(os.path.join(self.dirname,self.filename),'r')
win = wxTextCtrl(self.control, -1, style=wxTE_MULTILINE)
win.SetValue(f.read())
nom=self.filename
self.control.AddPage(win, nom, true)
f.close()
dlg.Destroy()
def OnNew(self,e):
win = wxTextCtrl(self.control, -1, style=wxTE_MULTILINE)
nom="document " + str(self.control.GetPageCount())
self.control.AddPage(win, nom, true)
def OnSave(self,e):
self.dirname = ''
id=self.control.GetSelection()
nom=self.control.GetPageText(id)
dlg = wxFileDialog(self, "Save", self.dirname, nom, "*.*", wxSAVE)
if dlg.ShowModal() == wxID_OK:
self.filename=dlg.GetFilename()
self.dirname=dlg.GetDirectory()
f=open(os.path.join(self.dirname,self.filename),'w')
f.write(self.control.wxTextCtrl.GetValue())
f.close()
dlg.Destroy()
app = wxPySimpleApp()
frame = MainWindow(None, -1, "Sample editor")
app.MainLoop() |
Partager