|
From: I P. <I.P...@ma...> - 2006-02-02 12:14:33
|
Hi Rolf, Joakim,
I was wondering if you could help with the following problem.
I have a class that redirects the print statement to a Tkinter window, see
below.
The test script (testprint.py) works fine under a python shell.
However, when I try to run the same script in LabPython, I get the
following error:
"exceptions.AttributeError, 'module' object has no attribute
'argv'" (Script fails at "root=Tk()" statement)
Am I doing something silly? or can't LabPython open any GUI windows?
(NOTE: I typically use PYTHON set script.vi and PYTHON Execute script.vi.)
Your thoughts
Thanks for your help
Ian
---------------------------------------
##filename = testprint.py
from Tkinter import *
from printtogui import *
root = Tk()
text = Tktextfile(root)
logger = Logger(text)
for i in range(6):
print "%d, " %i
-----------------------------------------
## filename = printtogui.py
"""A short python script for re-directing print statement."""
import os, os.path, tkFileDialog
from Tkinter import *
class Logger:
"""A filelike object that prints its input on the screen."""
def __init__(self, logfile=None):
"""Takes one argument, a file like object for logging."""
print 'Starting logger...'
if not logfile:
self.logfile = open('relative-refs.log','w')
else:
self.logfile = logfile
sys.stderr = self # Super cheap logging
facility...
sys.stdout = self # Just redirect output to a
file.
print 'Logger running...'
def write(self, line):
sys.__stdout__.write(line)
self.logfile.write(line)
def close(self):
"""The close method restores stdout and stderr to normal."""
self.logfile.close()
sys.stderr = sys.__stderr__
sys.stdout = sys.__stdout__
class Tktextfile:
"""A file like interface to the Tk text widget."""
def __init__(self, root):
"""Create a scrollable text widget to be written to."""
self.root = root
self.text = Text(root,width=40,height=20)
self.text.pack(side=LEFT, expand=True, fill=BOTH)
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT,fill=Y)
self.text.configure(yscrollcommand=scrollbar.set)
scrollbar.config(command=self.text.yview)
self.text.focus()
def write(self, line):
"""Write method for file like widget."""
self.text.insert(INSERT, line)
self.text.see(END)
def close(self):
"""Fake close method."""
pass
-------------------------------------------------
"Rolf Kalbermatter" <rol...@ci...>
Sent by: lab...@li...
21/12/2005 00:23
Please respond to labpython-users
To: <lab...@li...>
cc:
Subject: RE: [LabPython-Users] Hello
Hi Joakim,
>
> >Chances are that there is no good solution which works both for pre
> 2.3.5 and later.
>
> Sounds like you are approaching the source already! Hope it
> affects only pyimport.c?
Nope it is more likely affecting lvpython.c and in there PyCloseHost and
there
again the use of PyEval_.. functions as well as probably
PyThreadState_Swap().
It is definitely in there where LabVIEW hangs indirectly when trying to
unload
the script DLL.
> >No! The variant datatype as used in LabVIEW is not documented, nor are
> >any of the LabVIEW manager >functions needed to deal with this
datatype.
> >It is positively not directly compatible with a Windows OLE variant and
> >my drive for reverse engineering such an obscure datatype is close to
0.
>
> I see.
> Would you like to point me to where I can find docs about the LabVIEW
> API for script nodes? I would like to have types for waveform plots and
> xy plots. I have problems generating those types when calling LabVIEW
> VIs from Python through win32com because that module doesn't distinguish
> between tuples (clusters) and lists (arrays). I guess that module uses
> OLE variants.
I'm not aware of official documentation for the script node API. Basically
I did start out to reverse engineer that API and then Jim Kring managed to
get in touch with a LabVIEW developer who was willing to give us the
header
file defining that API as used in LabVIEW 6.0. As far as that is concerned
it basically just confirmed most of the things I had already found out and
it was more or less what is now in lvpython.h except some of the comments
in there which I had added myself before, based on my own findings.
I'm sure the script node in current LabVIEW version has some more features
added but that is of little importance for labpython up to this moment.
If you interface LabVIEW through win32com then you interface through COM
(which was called OLE and now listens to the name of ActiveX) and as such
you will eveidently see OLE variants. Waveforms are basically LabVIEW
variants
but LabVIEW takes care of converting from its own variants to OLE
variants
when you interface the ActiveX interface of LabVIEW.
Rolf Kalbermatter
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log
files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
LabPython-Users mailing list
Lab...@li...
https://lists.sourceforge.net/lists/listinfo/labpython-users
|