On Thursday, November 8, 2018 at 7:04:05 AM UTC-6, Edward K. Ream wrote:

*How to communicate between components?*
>

[big snip]

Happily, flexx properties provide everything needed.  Apparently, 
> properties must be used to communicate even between different flx.Widgets.  
> That is, the ivars of one widget are not accessible to other flx.Widgets.  
> So the example code above might better be rewritten this way:
>
> class LeoMainWindow(flx.Widget):
>     
>     """
>     Leo's main window, that is, root.main_window.
>     
>     Each property x below is accessible as root.main_window.x.
>     """
>     
>     body = flx.AnyProp(settable=True)
>     log = flx.AnyProp(settable=True)
>     minibuffer = flx.AnyProp(settable=True)
>     status_line = flx.AnyProp(settable=True)
>     tree = flx.AnyProp(settable=True)
>
>     def init(self, body, outline):
>         with flx.VBox():
>             with flx.HBox(flex=1):
>                 tree = LeoTree(outline, flex=1)
>                 log = LeoLog(flex=1)
>             body = LeoBody(body, flex=1)
>             minibuffer = LeoMiniBuffer()
>             status_line = LeoStatusLine()
>         self._mutate_body(body)
>         self._mutate_log(log)
>         self._mutate_minibuffer(minibuffer)
>         self._mutate_status_line(status_line)
>         self._mutate_tree(tree)
>

I buried the lede big time here.  I wanted to emphasize that *all* 
flx.Widgets have a root ivar 
<https://flexx.readthedocs.io/en/stable/guide/widgets_components.html#the-root-component>,
 
which is the LeoApp instance.  So it's easy to add to the log widget!  For 
example, here is the event handler in the LeoTree class:

@flx.reaction(
    'tree.children**.checked',
    'tree.children**.selected',
    'tree.children**.collapsed',
)
def on_event(self, *events):
    
    log = self.root.main_window.log
    for ev in events:
        id_ = ev.source.title or ev.source.text
        kind = '' if ev.new_value else 'un-'
        s = kind + ev.type
        log.put('%s: %s' % (lpad(s, 15), id_))

Recall that pscript does not support features such as "10%s" which is why 
the code above does padding by hand using the global lpad function. 
Finally, here is log.put:

def put(self, s):
        self.ace.setValue(self.ace.getValue() + '\n' + s)

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to