[Python-talk] Pickling Question
Kent Johnson
kent37 at tds.net
Sat Jul 18 09:45:06 EDT 2009
On Fri, Jul 17, 2009 at 6:09 PM, <bruce.labitt at autoliv.com> wrote:
> Kent,
>
> I don't know about being off the track yet... I cannot get the demo
> example to work
> on linux. Apologize in advance for all of this...
Trust me, you are off track.
> In the demo code there is a definition of log
> class TestRadioBox(wx.Panel):
> def __init__(self, parent, log):
> self.log = log
> # all the rest snipped
>
> def runTest(frame, nb,log):
> win = TestRadioBox(nb, log)
> return win
>
> if __name__=='__main__':
> import sys, os
> import run
> run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
>
> I do not not know where run is - can't find it on my system. Running this
> program in ipython results in:
>
> ImportError: No module named run
This code is written to run in the context of the demo app. I'm not
sure where run is defined either. log is some kind of logging object
passed in from the demo. nb is the parent window.
> Also, I have no idea what the heck nb is... Seriously, I have little idea
> what the
> above stuff is doing. Makes it hard to follow the examples, I think.
Then you probably need to back up a bit and do some more reading and
experimenting with simple stuff. Do you understand object-oriented
programming in Python? That is kind of a prerequisite.
> Different question:
> How does one read the states of radioboxes that have not been pressed?
> Just rely on the default value?
Keep a reference to the radiobutton and ask it for its state.
>
>
> As for my code, I have the following workaround:
> Inside the class MyForm the first few lines of __init__ are
>
> def __init__(self):
> LOGFILE = 'log.txt'
> self.FILE = open(LOGFILE,'w+') # define self.FILE
>
> For the radio event I have:
>
> def OnRadio(self, event):
> radioSelected = event.GetEventObject() # what event got me here
> whichbox = radioSelected.GetLabel() # label
> buttonSelected = event.GetInt() # button number
> timeOnRadio = time.asctime(time.localtime()) # system local
> time
> self.FILE.write('%s\t %s\t %s\n' % (whichbox, buttonSelected,
> timeOnRadio)
>
> For the GO event I have:
>
> def OnOK(self,event):
> self.FILE.seek(0) # go to
> beginning of file
> fileList = self.FILE.readlines() # read it
> self.FILE.close()
> for myline in fileList: # extract data,
> set values
> # extract the data from string
>
> domyprogram() # the actual
> program, all the rest was setup!
> if(rb1 & button1): # some pseudo logic like this
> doplot()
> else:
> self.closeProgram()
>
>
> Is this bad, or am I totally missing something?
Both. I don't mean to be mean, but really, you are going down the wrong road.
Kent
More information about the Python-talk
mailing list