I am just trying to acess a function in wordgrid (savefile) to a button
that is defined in TestFrame. I can't seem to make it work I either
get an error that my variable isn't global or it makes other
complaints. thanks in advance.. sorry for the simple question.. -
import wx
-
import wx.grid as gridlib
-
import sys
-
-
-
#--------------------------------------------------------------------------*-
-
-
-
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):
-
#from_file
-
infile = open(sys.argv[1], 'r') #The first argument passed in is
-
the file name
-
foundHeader = False
-
self.rows = []
-
for line in infile:
-
if sys.argv[2] in line: #look for the second argument and
-
make that the header
-
#removefirst = line.split(' ')
-
self.header = line.split()
-
#foundHeader = 'true'
-
continue # we don't want to process this line any
-
further
-
else:
-
self.rows.append(line.split())
-
-
-
self.widestRow = max([len(r) for r in self.rows])
-
self.widestCol = max([len(c) for c in [r for r in self.rows]])
-
def savefile(self):
-
outfile = open(sys.argv[1], 'w') #open the file defined in the
-
output line for writing
-
for row in self.rows:
-
outfile.write(row)
-
-
-
print('this is a test to see if I can Crash it')
-
-
-
class TestFrame(wx.Frame):
-
def __init__(self, parent, log):
-
-
-
wx.Frame.__init__(self, parent, -1, "Dex Tracker Sco Editor",
-
size=(640,480))
-
p = wx.Panel(self, -1, style=0)
-
grid = WordGrid(p, log)
-
#grid = CustTableGrid(p, log)
-
b = wx.Button(p, -1, "Save Grid")
-
b.SetDefault()
-
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
-
b.Bind(wx.EVT_SET_FOCUS, self.OnButtonFocus)
-
bs = wx.BoxSizer(wx.VERTICAL)
-
bs.Add(grid, 1, wx.GROW|wx.ALL, 5)
-
bs.Add(b)
-
p.SetSizer(bs)
-
-
-
def OnButton(self, evt):
-
print "button selected"
-
grid = WordGrid(self, log).savefile()
-
#self.WordGrid.savefile(self)
-
-
-
def OnButtonFocus(self, evt):
-
print "button focus"
-
-
-
#--------------------------------------------------------------------------*-
-
#def main():
-
-
-
def main(From_File, find_string):
-
"""This is the entire editor for .sco files.. It doesn't realy
-
care if it is music or not. Any file that you lay out with even rows
-
and collums
-
can be displayed The first argument passed to main is the file to
-
be used and the second if the string to be used as the command to set
-
up the header of the grid.
-
The sting you wish to use to identify the header should be placed
-
last so it doesn't show up in the grid.
-
"""
-
-
-
import sys
-
-
-
app = wx.PySimpleApp()
-
frame = TestFrame(None, sys.stdout)
-
frame.Show(True)
-
app.MainLoop()
-
pass
-
-
-
if __name__ == '__main__':
-
import sys
-
#try:
-
main(sys.argv[1], sys.argv[2])
-
https://sourceforge.net/projects/dex-tracker
5 1446
Hey Eric,
It's great to see that you are using wx! Looks like you're getting the hang of it! Keep at it and keep posting. I hope this is clear and works for you,
Barton
should be: -
class TestFrame(wx.Frame):
-
def __init__(self, parent, log):
-
-
-
wx.Frame.__init__(self, parent, -1, "Dex Tracker Sco Editor", size=(640,480))
-
p = wx.Panel(self, -1, style=0)
-
self.grid = WordGrid(p, log)
-
-
## ...
-
-
-
bs.Add(self.grid, 1, wx.GROW|wx.ALL, 5)
-
Here, self refers to the frame and since -
def OnButton(self, evt):
-
print "button selected"
-
self.grid.savefile()
-
is a method of the frame, self is the frame here too.
that seems to work as far as running the program. I seem to be able to change the cell values but the changes are not saved in the file. What is happening is that I get an exact (except it does get rid of the whitespace) copy of what I read but none of my changes (I lost 20k of whitespace and god knows what else invisible charecters). I have tried to read them off the screen but I am getting nowhere with that. -
-
import wx
-
import wx.grid as gridlib
-
import sys
-
-
-
-
#---------------------------------------------------------------------------
-
-
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)
-
-
self.Bind(gridlib.EVT_GRID_CELL_CHANGE, self.OnCellChange)
-
-
-
def OnCellChange(self, evt):
-
row = self.GetGridCursorRow()
-
col = self.GetGridCursorCol()
-
-
#self.SetCellValue(evt.GetRow(), evt.GetPosition(), self.GetValue(row, col))
-
#This is the example no good will keep it in the same position
-
-
if value == 'no good':
-
self.moveTo = evt.GetRow(), evt.GetCol()
-
-
def loadFile(self):
-
#from_file
-
infile = open(sys.argv[1], 'r') #The first argument passed in is the file name
-
foundHeader = False
-
self.rows = []
-
for line in infile:
-
if sys.argv[2] in line: #look for the second argument and make that the header
-
#removefirst = line.split(' ')
-
self.header = line.split()
-
#foundHeader = 'true'
-
continue # we don't want to process this line any further
-
else:
-
self.rows.append(line.split())
-
-
self.widestRow = max([len(r) for r in self.rows])
-
self.widestCol = max([len(c) for c in [r for r in self.rows]])
-
-
def savefile(self):
-
linestring = ''
-
outfile = open(sys.argv[1], 'w') #open the file defined in the output line for writing
-
for word in self.header:
-
linestring = linestring + word + ' '
-
outfile.write(linestring + '\n')
-
linestring = ''
-
for row in self.rows:
-
for word in row:
-
linestring = linestring + ' ' + word
-
outfile.write(linestring)
-
outfile.write('\n')
-
linestring = ''
-
print('this is a test to see if I can Crash it')
-
-
class TestFrame(wx.Frame):
-
def __init__(self, parent, log):
-
-
wx.Frame.__init__(self, parent, -1, "Dex Tracker Sco Editor", size=(640,480))
-
p = wx.Panel(self, -1, style=0)
-
self.grid = WordGrid(p, log)
-
#grid = CustTableGrid(p, log)
-
b = wx.Button(p, -1, "Save Grid")
-
b.SetDefault()
-
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
-
b.Bind(wx.EVT_SET_FOCUS, self.OnButtonFocus)
-
bs = wx.BoxSizer(wx.VERTICAL)
-
bs.Add(self.grid, 1, wx.GROW|wx.ALL, 5)
-
bs.Add(b)
-
p.SetSizer(bs)
-
-
def OnButton(self, evt):
-
print "button selected"
-
self.grid.savefile()
-
#WordGrid(p, log).savefile(self)
-
#grid = WordGrid(self, log).savefile()
-
#self.WordGrid.savefile(self)
-
-
def OnButtonFocus(self, evt):
-
print "button focus"
-
-
#---------------------------------------------------------------------------
-
#def main():
-
-
def main(From_File, find_string):
-
"""This is the entire editor for .sco files.. It doesn't realy care if it is music or not. Any file that you lay out with even rows and collums
-
can be displayed The first argument passed to main is the file to be used and the second if the string to be used as the command to set up the header of the grid.
-
The sting you wish to use to identify the header should be placed last so it doesn't show up in the grid.
-
"""
-
-
import sys
-
-
app = wx.PySimpleApp()
-
frame = TestFrame(None, sys.stdout)
-
frame.Show(True)
-
app.MainLoop()
-
pass
-
-
if __name__ == '__main__':
-
import sys
-
#try:
-
main(sys.argv[1], sys.argv[2])
-
-
It looks like you are trying to do something like this: -
#self.SetCellValue(evt.GetRow(), evt.GetPosition(), self.GetValue(row, col))
-
-
self.rows[row][col] = self.GetValue(row, col)
-
Use lots of print statements when debugging, like -
value = self.GetValue(row, col)
-
print value, type(value)
-
to make sure that the wx function returns the type that you need. Sometimes it's a good idea to use -
self.rows[row][col] = str(self.GetValue(row, col))
-
just in case it's unicode or wxStr object.
That worked fantastic thanks alot.
That worked fantastic thanks alot.
You are quite welcome!
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Blue® |
last post by:
I found this piece of JS which serves exactly what I need. It validates if
the input is exactly five numberic characters.
When it is validated, the form action is not carried out. What should I...
|
by: Steve |
last post by:
Visual Studio 2003 .Net / C#
I have a 2 page Tab Control for users to add a Job in my application. The
first page is for them to choose which type of Job they would like. The type
of Job...
|
by: Geoff Cox |
last post by:
Hello,
I am trying to print out the array values for a second time but get
error on page message?
Thanks
Geoff
<html>
|
by: Richard Lionheart |
last post by:
Hi All,
I generated a WebForm and created a Virtual Directory for it IIS. But I got
an error message (shown below) saying something like my app lacked
appropriate privileges.
David Wang...
|
by: Mountain |
last post by:
I would like opinions on whether this solution could be important and
whether anyone knows if it is already solved. (I would also like to
know if anyone thinks it cannot be solved.)
First, we...
|
by: beachboy |
last post by:
My project has many class (function), it need to create a new instance each
time by the id value, how can i write a code as much simple?
Actually, all cases is doing the same thing.... , but is...
|
by: Jeff |
last post by:
Hey
(and thank you for reading my post)
In visual web developer 2005 express edition I've created a simple website
project..
At this website I want users who register to be able to upload a...
|
by: Miro |
last post by:
Im really stuck on something.
My goal is to get away from Image Lists and to use a Resource file instead.
I followed an example and went to Properties of my project and clicked on
the resource...
|
by: =?Utf-8?B?YzY3NjIyOA==?= |
last post by:
Hi All,
Our company is merging two production domains(from two different servers)
onto one server. So during the migration we use an intranet testing server to
hold all files from these two...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |