Package: kabaret.flow-contextaul-dict
kabaret.flow_contextual_dictThis package provide theContextualViewclass and theget_contextual_dictfunction.Together, they give your flow users the ability to use defined value
anywhere in the branch underneeth and override those values where you
see fit in the branches.Everything is explained here, but if your of the kind that prefers to read and execute code, there is a demo flow in the package for that. Install the package an create a new project with the typekabaret.flow_contextual_dict.demo_flow.DemoFlow.ConceptHere is a quick example with this classic structure wheresettingsareContextualViewObjects:Project
    settings
    episodes
        ep001
            settings
            sequences
                seq001
                    settings
                    shots
                        shot001
                            settings
                            anim
                                settings
                                init_action
                                bake_action
                            lighting
                                settings
                                init_action
                                render_action
                            comp
                                settings
                                init_action
                                render_action
                        shot002
                seq002
                    ...
        ep002
            ...Let's say in theProject.settingsdefinesfps=24and apool="ANY".
Every object in the episodes branch can callget_contextual_dict()to receive a dict like{fps:24, pool:"ANY"}.
Most likely, action of every step/department of every shot will use this.Now let's say the sequenceseq002is in a hurry and you want to dispatch all actions on your farm's "SUPER_COMPUTERS" pool. All you need is to "override" withpool="SUPER_COMPUTERS"inep002.settings.You can do this in eachsettingsin the flow, and you can also "add" values in each of them (those "overrides" and "adds" are called "edits").In a nutshell, it's a cascading dict, or as some call it: acontextual dict.Installpip install kabaret.flow_contextual_dictPlease use a virtual env, it is good for you and your karma ^^UsageDefining ContextsIn order to add a contextual dict in your flow, you just need to add
a Child relation to aContextualView:class Shot(flow.Object):

    settings = flow.Child(contextualView)
    ...The name of the relation is very important:Overrides stacking is based on this name so you need to use the same
name along your branch in order for overrides to work as expected.It defines the "context_name" argument to use forget_contextual_dict()calls.So this will not work:Project
    settings
    episodes
        ep001
            episode_settingsBut this will:Project 
    settings
    episodes
        ep001
            settingsNote that you can useChild().ui(label="Episode Settings")if youreallywant to display a different name in the GUI.This gives the ability to use several contexts in the same flow.
In this structure, all * marked item areContextualView. There is two
context defined:settingsandconfig. The first one drives values bysequencesandshots, the second one only affectsepisodes.Project
    settings *
    config *
    episodes
        ep001
        config *
        sequences
            seq001
                settings *
                shots
                    shot001
                        settings *Editing Context ValuesOnce your flow is salted withContextualView, the user will be able to
add value using the"Add"action and to edit values by double clicking on them.If you want, for debug or inquiry, you can inspect the edits done thru aContectualViewby using its "Show Edits" actions. It will bring you to
a page showing only values defined here. Double-clicking one of those items
will show you more information, especiallythe history of modificationfor this value (what changed, who did it, and when).
You will also be able to change the override value, as well as disable/enable it.You can also programatically edit the context by definingget_default_contextual_edits(context_name)methods returning a dict of value to use if no override exists for them.In other words: user edits made withContextualViewactions will override values returned by a local or upstreamget_default_contextual_edits()method.Using Context ValuesIn order to get a context dict, you just need to callget_contextual_dict(leaf, context_name). Theleafis the point in the branch where you want the value to be evaluated. It will most of the time beself.Here is an example in an Action.run():class SubmitRender(flow.Action):

    render_settings = flow.Child(ContextualView)

    def run(self, button):
        if button == 'Confirm':
            context = get_contextual_dict(
                self, 'render_settings'
            )
            my_dispatcher.submit(
                scene=self.get_scene_path(),
                fps=context.get('fps', 24),
                pool=context.get('pool', 'ANY'),
            )Note that the second arg of theget_contextual_dict()call must match
the name of eachContextualViewto evaluate in the upstream branch.Also note that using aContextualViewas the Action Child has drawbacks in term of UX. We're waiting for a update ofkabaretto fix this.Default ValueAt the base of your context, you will probably want to have a set of default values.You will do this by adding a 'get_default_contextual_edits()` method returning the default value.Let's say yourProjectis the first level for you settings. You would
do something like:class Project(flow.Object):

    settings = flow.Child(ContextualView)
    episodes = flow.Child(Episodes)

    def get_default_contextual_edits(self, context_name):
        if context_name == 'settings':
            return dict(
                fps=30,
                pool="ANY"
            )Special CaseSometimes, you will want to put the visualisation/edition of the contextual values aside from the branch it affect.An example would be the settings of a project. They affect theWHOLE UNIVERSEso maybe you wouldn't want them to show on the first page all users land to...A classic aproach is to use anadmingroup and shove all geeky stuff in it:Project
    word_of_the_day
    episodes
        ...
    admin
        settings
        config
        preferencesIn this case, thesettingsobject is not inside theepisodesbranch so it does not affect it. This is a fail at being usefull :/To fix this, you can define insideProjectaget_contextual_viewmethod that returns aContextViewto consider as if it was its Child:class Project(flow.Object):
    
    word_of_the_day = flow.Chid(WOTD)
    episodes = flow.Child(Episodes)
    admin = flow.Child(ProjectAdmin)

    def get_contextual_view(self, context_name):
        if context_name == 'settings':
            return self.admin.settings
        elif context_name == 'config'
            return self.admin.config

    def get_default_contextual_edits(self, context_name):
        if context_name == 'settings':
            return dict(
                fps=30,
                pool="ANY"
            )Notethat the default value must still be provided by theProjectclass !