enaml icon indicating copy to clipboard operation
enaml copied to clipboard

Allow out of order declaration of aliases

Open deepankarsharma opened this issue 11 years ago • 1 comments

Code pasted inline breaks currently.

from enaml.widgets.api import Window, Container, PushButton

enamldef Content(Container): """ The primary application content.

This 'button_foreground' alias provides access to the internal
push button's foreground color.

"""
alias button_bar: button.bar
PushButton: button:
    attr bar = 1

enamldef Main(Window): """ The main application window.

This window uses the 'button_foreground' alias of the central
content to bind to its internal push button's foreground color.

"""
title = 'Simple Attribute Alias'
Content: pass

deepankarsharma avatar Dec 05 '13 17:12 deepankarsharma

For my own personal notes:

Declaring the alias after the full definition of the PushButton would work, as would using a simple enamldef for the button to encapsulate the bar attr.

The Enaml compiler currently operates in two passes, the first pass builds an internal representation of the widget hierarchy, which is used to (among other things) instantiate the objects at runtime. The second pass adds the user-defined storage attributes and events, and wires up the aliases. This occurs in order of source code line number. The issue here is that the alias is being wired up before the storage attribute has been added to the push button.

I see two possible solutions 1) move the logic which adds the storage attributes to the first compiler pass, 2) move the alias wiring to a third compiler pass.

I would prefer solution number 1, but I can't recall at the moment if I had a good reason for adding the storage attributes during the second compiler pass.

sccolbert avatar Dec 05 '13 18:12 sccolbert