[Python-talk] Pickling Question

bruce.labitt at autoliv.com bruce.labitt at autoliv.com
Fri Jul 17 18:09:57 EDT 2009


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...

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

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.

Also, I cannot seem to get self.log defined.  So I cannot get 
self.log.WriteText to work. 
Where is log defined?  And how does one read self.log?  self.log.ReadText?

Different question:
How does one read the states of radioboxes that have not been pressed?
Just rely on the default value?


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?  (I know I am.  I don't 
even
know how to ask the question!)

The code I have written, does work.  It writes to file and I read it back 
OnOK, it doesn't
seem elegant though. 

Thanks for your help so far!
Bruce


kent3737 at gmail.com wrote on 07/17/2009 05:02:16 PM:

> And just in case it is not already clear, you are definitely on the
> wrong track, turn around now!
> 
> On Fri, Jul 17, 2009 at 4:58 PM, Kent Johnson<kent37 at tds.net> wrote:
> > On Fri, Jul 17, 2009 at 3:31 PM, <bruce.labitt at autoliv.com> wrote:
> >> It would be that attempt, yes :)  I've yet to get anything else to 
work.
> >> Actually I need to read the entire state/setting before running.  I
> >> haven't gotten that far.
> >
> > Take a look at the RadioButton demo in wx demos for an example of how
> > to save references to controls and refer to them in an event handler.
> >
> > This example is much more complex than you need, don't try to copy it
> > too literally. You could just use self.radio1 etc but maybe it will
> > get you on the right track.
> >
> > Kent
> >


******************************
Neither the footer nor anything else in this E-mail is intended to or constitutes an <br>electronic signature and/or legally binding agreement in the absence of an <br>express statement or Autoliv policy and/or procedure to the contrary.<br>This E-mail and any attachments hereto are Autoliv property and may contain legally <br>privileged, confidential and/or proprietary information.<br>The recipient of this E-mail is prohibited from distributing, copying, forwarding or in any way <br>disseminating any material contained within this E-mail without prior written <br>permission from the author. If you receive this E-mail in error, please <br>immediately notify the author and delete this E-mail.  Autoliv disclaims all <br>responsibility and liability for the consequences of any person who fails to <br>abide by the terms herein. <br>
******************************


More information about the Python-talk mailing list