[Tutor] name error

ugajin at talktalk.net ugajin at talktalk.net
Mon Jul 14 18:13:33 CEST 2014


I am running nodebox 1 on OSX v10.6.8, which is an open source OSX 
Python, 2D data visualiser, and although not legacy, the software it 
isn't well supported. (see http://nodebox.net/code/index.php/Home for 
further info).  I believe nodebox 1, runs with Python 2.5 
 
This may be too specialised a question for the tutor forum, but . . .  
I have posted several e-mails to the nodebox author the first of which 
was almost 3 weeks ago, and although I received an initial  positive 
response, saying he would provide a screen cast to help,  the said 
screencast has not arrived. After, I sent a polite reminder, I received 
a curt if incomplete reply telling me he was now on holiday. 
 
Sometimes it can help, to describe a problem to a 3rd person (real or 
imagined), so here goes (it may have helped a bit, but not enough). 
 
To draw a default rectangle using the nodebox 1, IDE you would simply 
write: rect(0, 0, 100, 100) to a .py file.  When run in nodebox 1, IDE 
it does what you might expect. It renders a 100 x 100 (px) rectangle 
shape, with the top left vertex at the canvas x, y coordinate 0, 0 
 
However, when I try to call the .py file as a module (using the nodebox 
IDE) which is what I am trying to acheive, I get a traceback error 
message e.g. 
# import_test_1.py 
rect(0, 0, 100, 100) 
 
#importer_test_1.py 
import_test_1 
Traceback (most recent call last): 
 File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript 
  File "/Users/apple/Documents/nodeBox/07_10_2014/importer_2.py", line 
2, in <module> 
  File "/Users/apple/Documents/nodeBox/07_10_2014/import_test_2.py", 
line 22, in <module> 
NameError: name 'rect' is not defined 
 
This begins to look like a scope issue. 
 
However, when I execute/run the following command, I get the following 
output 
# import_test_2.py 
print 'dir:', dir() 
 
dir: ['BOOLEAN', 'BUTTON', 'BezierPath', 'CENTER', 'CLOSE', 'CMYK', 
'CORNER', 'CURVETO', 'Canvas', 'ClippingPath', 'Color', 'Context', 
'DEFAULT_HEIGHT', 'DEFAULT_WIDTH', 'FORTYFIVE', 'FRAME', 'Grob', 
'HEIGHT', 'HSB', 'Image', 'JUSTIFY', 'KEY_BACKSPACE', 'KEY_DOWN', 
'KEY_LEFT', 'KEY_RIGHT', 'KEY_UP', 'LEFT', 'LINETO', 'MOUSEX', 
'MOUSEY', 'MOVETO', 'NORMAL', 'NUMBER', 'NodeBoxError', 'Oval', 
'PAGENUM', 'PathElement', 'Point', 'RGB', 'RIGHT', 'Rect', 'TEXT', 
'Text', 'Transform', 'Variable', 'WIDTH', '__builtins__', '__class__', 
'__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', 
'__init__', '__magic_var__', '__module__', '__new__', '__reduce__', 
'__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 
'_align', '_arrow', '_arrow45', '_autoclosepath', '_colormode', 
'_colorrange', '_copy_attr', '_copy_attrs', '_ctx', '_fillcolor', 
'_fontname', '_fontsize', '_get_height', '_get_width', '_imagecache', 
'_lineheight', '_makeInstance', '_noImagesHint', '_ns', '_oldvars', 
'_outputmode', '_path', '_resetContext', '_strokecolor', 
'_strokewidth', '_transform', '_transformmode', '_transformstack', 
'_vars', 'addvar', 'align', 'arrow', 'autoclosepath', 'autotext', 
'background', 'beginclip', 'beginpath', 'canvas', 'choice', 
'closepath', 'cm', 'color', 'colormode', 'colorrange', 'curveto', 
'drawpath', 'endclip', 'endpath', 'files', 'fill', 'findpath', 
'findvar', 'font', 'fontsize', 'grid', 'image', 'imagesize', 'inch', 
'key', 'keycode', 'keydown', 'line', 'lineheight', 'lineto', 'mm', 
'mousedown', 'moveto', 'nofill', 'nostroke', 'outputmode', 'oval', 
'pop', 'push', 'random', 'rect', 'reset', 'rotate', 'save', 'scale', 
'scrollwheel', 'size', 'skew', 'speed', 'star', 'stroke', 
'strokewidth', 'text', 'textheight', 'textmetrics', 'textpath', 
'textwidth', 'transform', 'translate', 'var', 'wheeldelta', 'ximport'] 
 
This seems to suggest (to me) that there is a class object named Rect 
in the default dir() 
I may not have the correct nomenclature here, is there as default IDE 
dir() module? 
 
Also, when I execute or run the following command, I get: 
print 'dir(Rect):', dir(Rect) 
dir(Rect): ['__call__', '__class__', '__cmp__', '__delattr__', 
'__doc__', '__get__', '__getattribute__', '__hash__', '__init__', 
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
'__str__', 'im_class', 'im_func', 'im_self'] 
 
Now, I am not sure if this helps, but if I put those two lines of code 
into a file and call the module with the import command, I now get the 
following output:: 
# importer_test_2 
import_test_2 
print 'dir:', dir() 
print 'dir(Rect):', dir(Rect) 
 
dir: ['__builtins__', '__doc__', '__file__', '__name__', 'draw_rect', 
'nodebox'] 
 
dir(Rect):Traceback (most recent call last): 
 File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript 
  File "/Users/apple/Documents/nodeBox/07_10_2014/importer_2.py", line 
2, in <module> 
  File "/Users/apple/Documents/nodeBox/07_10_2014/import_test_2.py", 
line 18, in <module> 
NameError: name 'Rect' is not defined 

Perhaps someone wiser than me, can suggest an approach, or something 
that I might try? 
 
Thanks in anticipation. 
 
-u 
 
After some further tests, with Rect, and some Traceback messages 
telling me that Rect(), which was located in DrawingPrimitives, was 
deprecated, I found some changes noted posted on GitHub. Those at v 
1.9.0 seem apposite (I am running v1.9.5):
for nodebox 1, v 1.9.7:
ellipse() is an alias for oval(). Path.ellipse() works as well.
Support for Line cap and line join styles. Use joinstyle() with MITER, 
ROUND or BEVEL and capstyle() with BUTT, ROUND or SQUARE. 
Path.joinstyle = MITER and Path.capstyle = BUTT works as well.
for v1.9.0:
NodeBox is now packaged: DrawingPrimitives is obsoleted in favor of 
nodebox.graphics.This also means you can work directly with the context:
 
After some further try it and see tests, I noted the following:
#nodebx_graphics.py
print 'dir(nodebox.graphics.BezierPath):', 
dir(nodebox.graphics.BezierPath)

dir(nodebox.graphics.BezierPath): ['__class__', '__delattr__', 
'__dict__', '__doc__', '__getattribute__', '__getitem__', '__hash__', 
'__init__', '__iter__', '__len__', '__module__', '__new__', 
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 
'__weakref__', '_draw', '_get_bounds', '_get_contours', '_get_fill', 
'_get_length', '_get_path', '_get_stroke', '_get_strokewidth', 
'_get_transform', '_get_transformmode', '_reset', '_set_fill', 
'_set_stroke', '_set_strokewidth', '_set_transform', 
'_set_transformmode', 'addpoint', 'append', 'bounds', 'checkKwargs', 
'closepath', 'contains', 'contours', 'copy', 'curveto', 'difference', 
'draw', 'extend', 'fill', 'fit', 'inheritFromContext', 'intersect', 
'intersects', 'kwargs', 'length', 'line', 'lineto', 'moveto', 'oval', 
'path', 'point', 'points', 'rect', 'reset', 'rotate', 'scale', 
'segmentlengths', 'setlinewidth', 'skew', 'stateAttributes', 'stroke', 
'strokewidth', 'transform', 'transformmode', 'translate', 'union', 
'xor']

Also, noted I can call the rect() function as follows:
#nodebx_graphics.py
import nodebox
nodebox.graphics.BezierPath(rect(0, 0, 100, 100))

However I still get a name error when I call it from another file, 
which is what I am trying to do:
#importer_nb_graphics
import nodebox_graphics

Traceback (most recent call last):
  File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript
  File "/Users/apple/Documents/nodeBox/07_10_2014/importer_nb_1.py", 
line 2, in <module>
  File "/Users/apple/Documents/nodeBox/07_10_2014/nodebox_graphics.py", 
line 31, in <module>
NameError: name 'rect' is not defined

I note that now the name error applies to 'rect' not 'Rect'

As asked earlier, perhaps some Pythonistas here can suggest some 
further try it and see tests for me to try?

PS. While I am here perhaps someone can also suggest a plain text 
e-mail client, as I really dislike composing on mine in plain text. I 
lose scroll bars, and text sometimes half fills the editor window when 
saved as a draft draft, and re-opened.  Especially for you guys, I 
wrote this in HTML, saved it, changed my setting, re-opened it, before 
sending it.







  


More information about the Tutor mailing list