A draft, saved for future reference, of an analog of
Python-DSV, but for fixed-length files...
from wxPython.grid import wxGrid
from wxPython.wx import wxPySimpleApp
from wxPython.wx import wxFrame
import wx
import string
import types
class FixLenDiscovery(wxFrame):
colNum = 2
rowNum = 6
defLen = "5"
def addField(self,event):
self.fieldGrid.InsertCols(pos = self.colNum)
self.grid.InsertCols(pos = self.colNum)
self.fieldGrid.SetCellValue(0, self.colNum, self.defLen)
self.colNum = self.colNum + 1
self.Layout()
def removeField(self,event):
if self.colNum > 1:
self.fieldGrid.DeleteCols(self.colNum - 1)
self.grid.DeleteCols(self.colNum - 1)
self.colNum = self.colNum - 1
self.Layout()
def loadFile(self,event):
path = self.filePicker.GetPath()
file = open(path, 'r')
self.grid.ClearGrid()
for row in range(0, self.rowNum -1):
for col in range(0, self.colNum):
width = self.fieldGrid.GetCellValue(0, col)
width = string.atoi(width)
value = file.read(width)
self.grid.SetCellValue(row, col, value)
self.grid.AutoSize()
def __init__(self):
wxFrame.__init__(self, None, -1, '', size=(1000, 500))
self.filePicker = wx.FilePickerCtrl(self, 1)
self.loadButton = wx.Button(self, wx.FIXED, "Preview")
self.loadButton.Bind(wx.EVT_BUTTON, self.loadFile)
self.grid=wxGrid(self, -1)
self.grid.CreateGrid(self.rowNum, self.colNum)
self.grid.DisableCellEditControl()
topBox = wx.BoxSizer(wx.HORIZONTAL)
topBox.Add(self.filePicker, 3)
topBox.Add(wx.StaticText(self, wx.FIXED, ""), 1)
topBox.Add(self.loadButton, 1)
fieldsBox = wx.BoxSizer(wx.VERTICAL)
fieldsButtonBox = wx.BoxSizer(wx.HORIZONTAL)
self.fieldGrid = wxGrid(self, -1)
self.fieldGrid.CreateGrid(1, self.colNum)
for i in range(0, self.colNum):
self.fieldGrid.SetCellValue(0, i, self.defLen)
addFieldButton = wx.Button(self, wx.FIXED, "Add field")
addFieldButton.Bind(wx.EVT_BUTTON, self.addField)
removeFieldButton = wx.Button(self, wx.FIXED, "Remove field")
removeFieldButton.Bind(wx.EVT_BUTTON, self.removeField)
fieldsButtonBox.Add(addFieldButton, 1)
fieldsButtonBox.Add(removeFieldButton, 1)
fieldsBox.Add(self.fieldGrid, 1)
fieldsBox.Add(fieldsButtonBox, 1)
mySizer = wx.BoxSizer(wx.VERTICAL)
mySizer.Add(topBox, 1)
mySizer.Add(fieldsBox, 3)
mySizer.Add(self.grid, 4)
self.SetAutoLayout(True)
self.SetSizer(mySizer)
self.Layout()
if __name__ == "__main__":
app = wxPySimpleApp()
frame = FixLenDiscovery()
frame.Show(True)
app.MainLoop()