473,609 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simple oop question (hopefully)

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(gridli b.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.SetCellVal ue(r, c, col)
self.SetColSize (c, 10*self.widestC ol)

for c, label in enumerate(self. header):
self.SetColLabe lValue(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.appen d(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(r ow)

print('this is a test to see if I can Crash it')

class TestFrame(wx.Fr ame):
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.EV T_BUTTON, self.OnButton, b)
b.Bind(wx.EVT_S ET_FOCUS, self.OnButtonFo cus)
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(s elf, 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])

Oct 30 '06 #1
1 1245
I am tagging this so I can find it again (google groups) www.dexrow.com
Er*********@msn .com wrote:
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(gridli b.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.SetCellVal ue(r, c, col)
self.SetColSize (c, 10*self.widestC ol)

for c, label in enumerate(self. header):
self.SetColLabe lValue(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.appen d(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(r ow)

print('this is a test to see if I can Crash it')

class TestFrame(wx.Fr ame):
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.EV T_BUTTON, self.OnButton, b)
b.Bind(wx.EVT_S ET_FOCUS, self.OnButtonFo cus)
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(s elf, 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])
Oct 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3244
by: Preston Crawford | last post by:
I'm looking to quickly get a photo album online. Very simple, thumbnails, a few pages, maybe a description, but hopefully a small script that's easy to edit and work into my existing site. I know about hot scripts, etc. but I was wondering if any one could recommend one? Secondly, I also want to setup a journal. It's not really a "blog" although I guess blog software may work. But it isn't going to be a message board or anything like...
0
356
by: Anthony Robinson | last post by:
Hopefully I can explain what I'm trying to do well enough for someone to be able to shed some light on my problem. I have three tables: AIMRETRIEVAL -->ARCHIVERETRIEVAL-->AIMRETRIEVEDITEM. There is a one-to-many relationship between AIMRETRIEVAL and ARCHIVERETRIEVAL. The foreign key on ARCHIVERETRIEVAL is AIMRETRIEVALID. There is also a one-to-many relationship between ARCHIVERETRIEVAL and AIMRETRIEVEDITEM. The foreign key on...
13
1509
by: tindog | last post by:
I am brand new to this programming especially C#. I am confused (at the moment). I have bought two books to get started to learn C# language and Visual C#.net 2003 in 24 hours. Which is the best to learn the straight language or the VS techniques??? I am using VS2005 team suite, but have come to a halt as confused think I am jumping ahead too quickly. I have done a lovely form for my PDA but is useless as does not do anything, would like...
3
1393
by: Brad | last post by:
I have another hopefully simple question. I am so used to writing VB .Net windows apps that there are some things in ASP .Net that just does not easily cross over. I know how to pass variables to another form, but how would I do this from one page to another? I am not finding a simple solution. Thanks for the help
4
1363
by: Timmah1980 | last post by:
I'm sure this is a simple enough fix for someone out there, but I'm afraid it's beyond me! I'm putting together this simple menu for a client: http://www.timkeay.co.uk/mpc2/index.htm It works fine, but I'd like to make a couple of tweeks. As you can see, the sub-menus don't sit exactly in line with the header, so I'd like to shift them right by one pixel to correct this. I'd also like to shift
0
954
by: boazin | last post by:
Hi all, I was trying to build a rather simple server (with a twist) using asyncore and got myself complicated. Well, here's the deal: My server will handle multiple connections, some require reply, and some not (they will disconnect by themselves) all the clients want to to deliver binary data to a socket we'll call P socket. this socket is a device that hopefully always wating for new
10
2121
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel <System.Web.Services.WebService(Namespace:="http:// wwwpreview.#deleted#.co.uk/~ptaylor/Customer.wsdl")_
1
1475
by: Andrew | last post by:
I'm learning PHP so this might be a simple question to more expeienced developers hopefully. I have a findrecords.php page which has the following code which creates a new record in a database table if this is the first time the user performs a search: // Web Session tracking if (isset ($_SESSION)) { // nothing - we don't want to add a new record if this is set
0
1064
by: showellshowell | last post by:
Hi everybody, I'm looking for a very simple HTTP debugging sniffer in Python-- hopefully 200 lines of less--that allows me to write simple methods to inspect requests and responses. It would ideally work like this: sniffer = SimpleHttpDebuggingSniffer(actual_host_address, actual_host_port) sniffer.listening_port = SOME_PORT_ON_MY_DESKTOP sniffer.inbound_inspector = some_method_i_write
0
8139
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8579
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8555
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8232
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7024
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5524
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4032
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4098
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.