From: Magnus L. H. <ma...@he...> - 2004-01-11 13:50:58
|
Joerg Lehmann <jo...@us...>: > [snip] > Let us start with an important type of attributes for drawing paths in PyX, > the so-called decorators. These allow to specify > > - the kind of drawing (stroked, filled, or both) and > - modifications applied to the paths (at the moment only arrows, but many > more are conceivable) > > An important feature of the currently implemented decorators is that one can > modify their meaning by using constructs like > > - canvas.stroked(color.rgb.blue) > - canvas.filled(somepattern) > - canvas.earrow.normal(canvas.stroked(color.rgb.red), > canvas.filled(color.rgb.blue)) Is it possible to modify parts of the decorators? If not, could that be a possible extension while you're restructuring this anyway? The reason for the suggestion is that I'd like to be able to specify different decorators for the line and the arrowhead of an arrow, for example. [snip] > Cons: > - From the user perspective it does not make too much sense > to instantiate deco.stroked and deco.earrow.normal > - deco.earrow.normal() vs. style.linewidth.normal > - deco.earrow.normal(color.rgb.red, deco.stroked(color.rgb.blue)) > does not work Also, it seems odd to have to instantiate unspecialized decorations but not styles... > A possible alternative solution would consists of decorators, which > are already instantiated. Calling them would allow to change their > look. This would at least make the mechanism consistent across the two modules. I think this seems quite all right -- but you could, I guess, separate things by, for example, using deco.stroked.default instead of deco.stroked Then deco.stroked could still be a class, and deco.stroked.default could be the default instantiation. Similarly: deco.earrow.normal.default would be the default instantiation of the normal arrow. A bit awkward, though, especially in this arrow case. Or... If you don't like the use of __call__, you could use named method... E.g. deco.stroked vs. deco.stroked.with(color.rgb.red) Then it's quite clear that deco.stroked is an instance. It seems that 'with' could be an appropriate name for most decorators and styles, and it could simply return a clone which is modified according to the arguments. > - Should deco.earrow.normal(color.rgb.red, deco.stroked(color.rgb.blue)) and > thus deco.earrow.normal(color.rgb.red, angle=30) not? Not sure if I understand the question... :} > - Do deco.earrow and deco.earrow.normal behave identically when > being called? That would seem to be the logical conclusion (even with an explicitly named cloning/specialization method). > - Or should we do something completely different for the arrows? I don't see why arrows are so different? You could (in general) use positional arguments to supply other modifiers/decorators/styles and keyword arguments to set attributes (or something equivalent). That could go for all the classes, no? As for my previous note about arrowheads styled separately... One could perhaps do something like: One could, perhaps, use something like: canvas.stroke(p, style.linestyle.dashed, deco.earrow.normal(style.linestyle.solid)) or something (that is, with the solid part only applying to the arrowhead)? Possibly with a different syntax for the specialization, though (such as, for example, the 'with' method or the like :). Or maybe this stuff is already possible? Just some thoughts... -- Magnus Lie Hetland "The mind is not a vessel to be filled, http://hetland.org but a fire to be lighted." [Plutarch] |