On Tue, Jun 12, 2007 at 08:25:37PM -0400, Ed Richley wrote:
> > Grrrrrr .... dumb paste-o.
> 
> Great. I just did a svn update and it works much better now. Thanks.
> Oddly, my old drawing must contain something inconsistent with the
> new code, because it still wants the dimension units to be millimeters.
> But, a new drawing works fine.

Weird.

> Can you explain how all the preferences are stored? My simple mind (ruined by
> self-taught C-programming) would have a bunch of variables that get set at
> start-up and when editing, and written when edit->preferences is told "OK".
> But, here there are a bunch of lists, dictionaries, tuples, etc., and it was
> really hard for me to follow what was going on. I'm sure there is a good 
> reason, but I'd like to know more so I can help.

The 'prefs.py' file is python code (obviously), and the code for loading
and saving the values is found in 'PythonCAD/Generic/preferences.py'.
The file itself has a couple of comments in it to explain what type of
values the next bunch of variables should be, so in my 'prefs.py' file
the follow appear:

# [ ... snip ... ]
# 
# Boolean variables
#
autosplit = True
highlight_points = True
#
# Size variables (float values)
#
chamfer_length = 1.5
fillet_radius = 2.0
leader_arrow_size = 10.0
# [ ... snip ... ]

When the defined variable is a dictionary, the variable itself is a
style, textstyle, or dimstyle. Each key represents one option with
the style. If you've adjusted any of the values in the style to some
value other than that defined by the style, the key and value are
listed after the dictionary. Again, in my 'prefs.py' file I have
the following:

#
# Standard GraphicObject parameters
#
line_style = {
    'name' : 'Default Style',
    'linetype' : ('Solid', None),
    'color' : '#ffffff',
    'thickness' : 1.0
}
line_thickness = 0.10000000000000001

So, the 'line_thickness' in the style is overriden; the value will be
0.1 instead of 1.0.

The 'prefs.py' file is parsed using routines found in the the 'imp'
module. The initial call to find_module() determines if the file
is there or not, and if it is the code is loaded via load_module().
The values of everything in the file can be examined by testing if
certain attributes exist within the newly loaded module. Using the
bits of my 'prefs.py' file above, the module 'prefs' is tested for
attributes 'autosplit', 'highlight_points', 'chamfer_length',
'fillet_radius', 'leader_arrow_size', 'line_style', etc. The complete
list of attributes is defined in the '_preflist' variable in
'preferences.py'. If the attribute is found, then the value defined
by that attribute gets picked up and placed into the 'global.prefs'
dictionary, so in my case global.prefs['AUTOSPLIT'] is True, 
global.prefs['HIGHLIGHT_POINTS'] is True, etc.

When the 'line_style' attribute is found, globals.prefs['LINE_STYLE]' 
gets set to a Style instance defined by the keys/values in 'line_style'.
If any overriden values were seen, as is the case above with
'line_thickness', then the matching key/value pair in globals.prefs
gets the override value. In my case, globals.prefs['LINE_THICKNESS']
is set to 0.1, overriding the value defined in the style (1.0).

I hope the explanation above sheds some light on the structure of
the 'prefs.py' file and how the values get pulled into and used by
PythonCAD.

Art
-- 
Man once surrendering his reason, has no remaining guard against absurdities
the most monstrous, and like a ship without rudder, is the sport of every wind.

-Thomas Jefferson to James Smith, 1822
_______________________________________________
PythonCAD mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pythoncad

Reply via email to