# coding=cp936
import os
import wx
import wx.grid
class MainWindow(wx.Frame):
colLabels = ["RM Delay","Send","Recv","Direction","Len","Data(Hex)","Comment"]
def __init__(self):
wx.Frame.__init__(self,None,title = "消息发生器脚本编辑器",size = (855,472))
menuFile = wx.Menu()
menuFile.Append(1, "&打开")
menuFile.AppendSeparator()
menuFile.Append(2, "&保存")
menuFile.Append(3, "&另存为")
menuFile.AppendSeparator()
menuFile.Append(4, "&关于")
menuFile.Append(5, "退出")
menuBar = wx.MenuBar()
menuBar.Append(menuFile, "文件")
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU, self.About, id=4)
self.Bind(wx.EVT_MENU, self.Quit, id=5)
self.Bind(wx.EVT_MENU, self.OpenFile, id=1)
self.filedir = "当前脚本路径"
self.CreateStatusBar()
self.SetStatusText(self.filedir)
self.grid = wx.grid.Grid(self)
self.row_num = 18
self.grid.CreateGrid(self.row_num-1,7)
self.grid.SetColSize(0,70)
self.grid.SetColSize(1,55)
self.grid.SetColSize(2,55)
self.grid.SetColSize(4,55)
self.grid.SetColSize(5,360)
for col in range(7):
self.grid.SetColLabelValue(col,self.colLabels[col])
self.attr = wx.grid.GridCellAttr()
self.attr.SetBackgroundColour(wx.Colour(210,232,251))
def About(self,event):
wx.MessageBox("无线脚本编辑器V1.0.0 | 协议版本V1.0.0","关于",wx.OK|wx.ICON_INFORMATION,self)
def Quit(self,event):
self.Close()
def OpenFile(self,event):
app = wx.App()
wildcard = "选择脚本文件 (*.csv)|*.csv|所有文件(*.*)|*.*"
dialog = wx.FileDialog(self, "选择脚本", os.getcwd(),
"", wildcard, wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
self.filedir = dialog.GetPath()
self.SetStatusText(self.filedir)
oldrows = self.row_num
data = file(self.filedir,'rb')
lines = data.readlines()
self.row_num = len(lines)
self.grid.ClearGrid()
if self.row_num > oldrows:
addrows = self.row_num - oldrows
self.grid.AppendRows(addrows)
if self.row_num < oldrows:
delrows = oldrows - self.row_num
self.grid.DeleteRows(pos = self.row_num-1,numRows = delrows)
for i in range(1,self.row_num):
Lines = lines[i].split(',')
for y in range(1,7):
self.grid.SetCellValue(i-1,y-1,"%s"%Lines[y])
data.close()
dialog.Destroy()
app = wx.App()
frame = MainWindow()
frame.Show()
app.MainLoop()