aesthete-team team mailing list archive
-
aesthete-team team
-
Mailing list archive
-
Message #00000
SpaceArray argument deletion
Sorry, for repetition, but just to check this out and get the list kicked
off:
Deleting SpaceArray argument to the left
__________________________________
Say, ent = self.attached_to ; then ent.get_ancestors() will give a list of
nested entities working outwards from ent to main_phrase (if the entity is
currently part of the tree, i.e. if ent.get_main_phrase() != None). All
being well (caveat emptor), the last entity is the relevant MainPhrase,
second-to-last is the main SpaceArray, third last is a phrase (say P) and
fourth last is a TargetPhrase.
GlypherBinaryExpression is the superclass of pretty much all n-ary
operations, including addition, multiplication, comma-separated arrays and
SpaceArray (all in BinaryExpression.py). One of its members is poss, which
contains an ordered list of phrases representing argument positions,
including P. [Another, incidentally, is syms, which contains (phrases
containing) all of the inter-argument symbols, such as GlypherSymbol('+')s].
So m = SA.poss.index(P) should tell you what number argument you're sitting
inside.
BE also provides remove_operand(n), which will orphan the nth argument,
translate the subsequent arguments leftwards and suitably renumber poss,
syms, etc. for you without any further fiddling. So, in theory,
remove_operand(m-1) or remove_operand(m+1) will do the trick and remove the
leftward or rightward argument (if I understand the proposition).
As I've currently broken my branch, this isn't tested, but my guess would be
something like this :
def delete_phrasegroup_to_left(
self) :
if self.phrased_to is None or self.phrased_to.get_main_phrase() is None :
return
t = self.phrased_to.get_ancestors()
if len(t) < 4 or not t[-1].am('space_array') : return
space_array = t[-1]
operand = t[-2]
m = t[-1].poss.index(operand)
space_array.remove_operand(m - 1)
By the by, you may notice that pretty much every class derived from Entity
has a constructor argument 'parent'. This isn't essential, in that you can
pass None. However, its purpose is to provide the Entity with a guide for
inherited properties (e.g. size scaling, font weight) so that when it is
subsequently appended to an element there may be less scaling and general
rejigging to do. It may disappear in the long run, but I try and pass a
parent, or close ancestor, where possible.