I am having two problems with this code (I haven't got the repy down so this is a new message) one is that I get an error when I try to add new arguments to def loadFile(self): The other is that when I added a file in '' and changed lines to line in the routine it stopped doing anything (I don't get an error though it seems to make the interpiter happy)
!/usr/local/python
"""
import wx
import wx.grid as gridlib
import os
import string
fileContents = """\
Column headers go here
This is a test of the
emergency broadcast system.
Had this been an actual
emergency, you would have been
told to sit down, put your
head between your legs,
and kiss your ass goodbye.
"""
···
#---------------------------------------------------------------------------
class WordGrid(gridlib.Grid):
def __init__(self, parent, log):
gridlib.Grid.__init__(self, parent, -1)
self.loadFile()
self.CreateGrid(len(self.rows), self.widestRow)
for r, row in enumerate(self.rows):
for c, col in enumerate(row):
self.SetCellValue(r, c, col)
self.SetColSize(c, 10*self.widestCol)
for c, label in enumerate(self.header):
self.SetColLabelValue(c, label)
def loadFile(self):
# you'd probably want to read a file here instead of a text string
#lines = fileContents.split('\n')
infile = open('test.sco', 'r')
testline = 'false'
for line in infile:
if ";<sco_header>" in line:
self.header = line.split()
testline = 'true'
if testline == 'true':
self.rows = [i.split() for i in line[1:]]
self.widestRow = max([len(r) for r in self.rows])
self.widestCol = max([len(c) for c in [r for r in self.rows]])
#---------------------------------------------------------------------------
class TestFrame(wx.Frame):
def __init__(self, parent, log):
wx.Frame.__init__(self, parent, -1, "sco file editor",
size=(640,480))
grid = WordGrid(self, log)
#---------------------------------------------------------------------------
******************** this is derived from ***************************
import wx
import wx.grid as gridlib
fileContents = """\
Column headers go here
This is a test of the
emergency broadcast system.
Had this been an actual
emergency, you would have been
told to sit down, put your
head between your legs,
and kiss your ass goodbye.
"""
#---------------------------------------------------------------------------
class WordGrid(gridlib.Grid):
def __init__(self, parent, log):
gridlib.Grid.__init__(self, parent, -1)
self.loadFile()
self.CreateGrid(len(self.rows), self.widestRow)
for r, row in enumerate(self.rows):
for c, col in enumerate(row):
self.SetCellValue(r, c, col)
self.SetColSize(c, 10*self.widestCol)
for c, label in enumerate(self.header):
self.SetColLabelValue(c, label)
def loadFile(self):
# you'd probably want to read a file here instead of a text string
lines = fileContents.split('\n')
self.header = lines[0].split()
self.rows = [i.split() for i in lines[1:]]
self.widestRow = max([len(r) for r in self.rows])
self.widestCol = max([len(c) for c in [r for r in self.rows]])
#---------------------------------------------------------------------------
class TestFrame(wx.Frame):
def __init__(self, parent, log):
wx.Frame.__init__(self, parent, -1, "Simple Grid Demo",
size=(640,480))
grid = WordGrid(self, log)
#---------------------------------------------------------------------------
if __name__ == '__main__':
import sys
app = wx.PySimpleApp()
frame = TestFrame(None, sys.stdout)
frame.Show(True)
app.MainLoop()
--
------------------------------------------------------------
Kent Quirk I'm making a game about global warming.
Game Architect Track the progress at:
CogniToy http://www.cognitoy.com/meltingpoint
https://sourceforge.net/projects/dex-tracker
question what is the effect of blacktop vs whitetop on global warming ???
_________________________________________________________________
Add a Yahoo! contact to Windows Live Messenger for a chance to win a free trip! http://www.imagine-windowslive.com/minisites/yahoo/default.aspx?locale=en-us&hmtagline