以下がソースです。
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Editor
import wx
import wx.lib.agw.flatnotebook as fnb
import wx.stc as stc
import sys,os
import textCmd
import textSrc
class EditPane(wx.Panel):
def __init__( self, parent, id, pos, size):
""" 画面右、タブごとに編集ページを表示する """
wx.Panel.__init__( self, parent, id, pos, size )
self.curTabNo = 0
self.fileName = ""
self.fileList =[]
self.instList =[]
self.Bind(fnb.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
self.Bind(fnb.EVT_FLATNOTEBOOK_PAGE_CLOSING, self.OnPageClosing)
self.book = fnb.FlatNotebook(self, 100,
agwStyle=fnb.FNB_X_ON_TAB |
fnb.FNB_NO_NAV_BUTTONS |
fnb.FNB_NO_X_BUTTON )
layout = wx.BoxSizer(wx.VERTICAL)
layout.Add( self.book, proportion=1, flag=wx.GROW| wx.ALL, border=10 )
self.SetSizer(layout)
def OnPageChanged(self, event):
''' get for current tabno '''
self.curTabNo = event.GetSelection()
self.fileName = self.fileList[ self.curTabNo ]
print "Page Changed start ----"
print "*:curTabNo",self.curTabNo
print "fileName",self.fileName
print "fileList",self.fileList
#print "instList",self.instList
print("Page Changed To %d" % event.GetSelection())
event.Skip()
def OnPageClosing(self, event):
'''
delete tab
proc1. remove array of fileList, instList
'''
tabNo = event.GetSelection()
del self.instList[ tabNo ]
del self.fileList[ tabNo ]
self.cutTabNo = event.GetSelection()
if self.cutTabNo == 0: self.fileName = ""
#else: self.fileName = self.fileList[ self.cutTabNo ]
print "close start ------"
print "*:curTabNo",self.curTabNo
print "fileName",self.fileName
print "fileList",self.fileList
#print "instList",self.instList
print("Page Closing, Selection: %d" % event.GetSelection())
print "close end"
event.Skip()
def addPage( self, dirName, fileName ):
""" ページを追加する、ファイル内容をリードして表示タブを作成しています"""
notePane = wx.Panel( self, wx.ID_ANY)
notePane.SetBackgroundColour( "black" )
#text = stc.StyledTextCtrl(notePane, wx.ID_ANY)
text = textSrc.TextSrc(notePane, wx.ID_ANY)
text.LoadFile( self.fileName )
self.fileList.append( self.fileName )
self.instList.append( text )
layout = wx.BoxSizer(wx.VERTICAL)
layout.Add( text, proportion=1, flag=wx.GROW | wx.ALL, border=10 )
notePane.SetSizer( layout )
self.book.AddPage( notePane, fileName )
self.curTabNo = len( self.fileList )-1
self.book.SetSelection( self.curTabNo )
print "addPage start ------"
print "*:curTabNo",self.curTabNo
print "addPage:fileName",self.fileName
print "addPage:fileList",self.fileList
#print "addPage:instList",self.instList
return
def OnOpenFile( self ):
dirName = ''
dialog = wx.FileDialog( self, "Choose a file", dirName, "", "*.*", wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
fileName = dialog.GetFilename()
dirName = dialog.GetDirectory()
self.fileName = os.path.join( dirName, fileName)
self.addPage( dirName, fileName )
return
def OnSaveFile( self ):
self.SetTitle( '(' + self.fileName + ') wpdb')
print "*:curTabNo",self.curTabNo
print "*:fileName",self.fileName
print "*:fileList",self.fileList
print "*:instList",self.instList
return
class Main(wx.Frame):
def __init__(self, parent, id, title):
""" レイアウトの作成 """
wx.Frame.__init__(self, parent, id, title, size=(800, 600))
# メインのレイアウトの作成
panel = wx.Panel( self, wx.ID_ANY )
#right= Right(panel, wx.ID_ANY)
self.right = right = EditPane( panel, wx.ID_ANY,pos=(0,0), size=(500,800) )
left = wx.Panel( panel, wx.ID_ANY,pos=(350,350), size=(500,100) )
right.SetBackgroundColour(wx.GREEN)
left.SetBackgroundColour(wx.RED)
# メニューの作成
self.CreateStatusBar()
menu_file = wx.Menu()
save_item = menu_file.Append(0, u"開く")
save_item = menu_file.Append(1, u"保存")
exit_item = menu_file.Append(2, u"終了")
menu_edit = wx.Menu()
copy_item = menu_edit.Append(3, u"コピー")
paste_item = menu_edit.Append(4, u"貼り付け")
menu_bar = wx.MenuBar()
menu_bar.Append(menu_file, u"ファイル")
menu_bar.Append(menu_edit, u"編集")
self.Bind(wx.EVT_MENU, self.selectMenu)
self.SetMenuBar(menu_bar)
def selectMenu( self,event):
self.SetStatusText("MenuSelected! " + str(event.GetId()))
id = event.GetId()
if id==0: self.right.OnOpenFile()
if id==1: self.right.OnSaveFile()
if __name__ == "__main__":
app = wx.App()
f = Main(None, wx.ID_ANY )
f.Centre()
f.Show(True)
app.MainLoop()