Exemple #1
0
class test_StateArrayRefs_2(DelegatingInstanceOrExpr):  # testexpr_35a
    indices = range(4)
    ## heights = StateArrayRefs(Width, ORIGIN) ###KLUGE for now: this contains heights * DZ as Vectors, not just heights
    heights = StateArrayRefs(Width, 0.0)

    def _height_dragger_for_index(self, index):
        stateref = StateArrayRefs_getitem_as_stateref(self.heights, index)
        #e change to self.heights.getitem_as_stateref(index)? self.heights._staterefs[index]?? self.heights[index]???
        newindex = ('_height_dragger_for_index', index)
        return self.Instance(_height_dragger(stateref), newindex)

    delegate = SimpleRow(
        MapListToExpr(
            _self._height_dragger_for_index,  ###k _self needed??
            indices,
            KLUGE_for_passing_expr_classes_as_functions_to_ArgExpr(
                SimpleColumn)),
        #e SimpleGrid? 2d form of MapListToExpr?
        ActionButton(
            _self.printit, "button: print state"
        )  ###e idea: define on special attr, let UI assemble debug info viewer
    )

    def printit(self):  #e can PrintAction do this for us?
        print[
            h.value for i, h in sorted_items(self.heights)
        ]  ###KLUGE, assumes they're StateRefs -- maybe just rename StateArray -> StateArrayRefs

    pass
class _MT_try2_kids_helper(
        DelegatingInstanceOrExpr
):  # rewrote this 070302 (splitting out older one's alg as MapListToExpr) -- works!
    """
    [private helper expr class for MT_try2]
    One MT item kidlist view -- specific to one instance of _MT_try2_node_helper.
    [#e if we generalize MT_try2 to support a time-varying list of toplevel nodes,
     then we might use one of these at the top, instead of using a single node at the top --
     but more likely a variant of this (at least passing it an option), to turn off
     anything it might display in the left which only makes sense when it's elts are under a common parent node.]
    """
    # args
    kids = Arg(
        list_Expr,
        doc=
        "the sequence of 0 or more kid nodes to show (after filtering, reordering, etc, by _self.mt)"
    )
    mt = Arg(MT_try2, doc="the whole MT view (for central storage and prefs)"
             )  ###e let this be first arg, like self is for methods??
    parent_item = Arg(
        mt._MT_try2_node_helper,
        None,
        doc="the parent node item for these kid nodes")  #k needed??
    # formulae
    delegate = MapListToExpr(
        mt.MT_item_for_object, kids,
        KLUGE_for_passing_expr_classes_as_functions_to_ArgExpr(SimpleColumn))
    pass
Exemple #3
0
class test_StateArrayRefs_3( DelegatingInstanceOrExpr): # testexpr_35b, _35c
    indices = range(3)
    heights = StateArrayRefs(Width, 0.0)
    direction = Arg(Vector, DX, "direction of permitted motion -- DZ is the goal but DX is easier for testing")
        ### DX for initial test (testexpr_35b), then DZ (testexpr_35c)
    range = Option(tuple_Expr, None, doc = "range limit of height")
    msg = Option(str, "drag along a line")
    def _height_dragger_for_index(self, index):
        stateref = StateArrayRefs_getitem_as_stateref( self.heights, index )
            #e change to self.heights.getitem_as_stateref(index)? self.heights._staterefs[index]?? self.heights[index]???
        newindex = ('_height_dragger_3_for_index', index) 
        return self.Instance( _height_dragger_3( stateref, self.direction,
                                                 sbar_text = "%s (#%r)" % (self.msg, index,),
                                                 range = self.range
                                                ), newindex )
    delegate = SimpleRow(
        MapListToExpr( _self._height_dragger_for_index, ###k _self needed??
                       indices,
                       KLUGE_for_passing_expr_classes_as_functions_to_ArgExpr(SimpleColumn) ),
                           #e SimpleGrid? 2d form of MapListToExpr?
        ActionButton( _self.printit, "button: print state") ###e idea: define on special attr, let UI assemble debug info viewer
     )
    def printit(self): #e can PrintAction do this for us?
        print [h.value for i,h in sorted_items(self.heights)] ###KLUGE, assumes they're StateRefs -- maybe just rename StateArray -> StateArrayRefs
    pass
class test_StateArrayRefs(DelegatingInstanceOrExpr):  ### has some WRONGnesses
    indices = range(10)
    colors = StateArrayRefs(Color, pink)

    #e i want an arg for the index set... maybe even the initial set, or total set, so i can iter over it...
    # NOTE: at least one dictlike class has that feature - review the ones in py_utils, see what _CK_ uses
    def _color_toggler_for_index(
        self, index
    ):  #e should we use _CV_ for this?? if not, it must be too hard to use!!!
        #k or is it that it defines a dict rather than a func, but we need a func in MapListToExpr?
        stateref = StateArrayRefs_getitem_as_stateref(self.colors, index)
        newindex = ('_color_toggler_for_index', index)
        return self.Instance(_color_toggler(stateref), newindex)

    delegate = MapListToExpr(
        _self._color_toggler_for_index,  ###k _self needed??
        indices,
        KLUGE_for_passing_expr_classes_as_functions_to_ArgExpr(SimpleRow))
    pass
Exemple #5
0
class PM_from_groups(
        DelegatingInstanceOrExpr
):  ###e refile into demo_ui or so, and call it on [make_polyline3d_PG(somearg)]
    "Make a Property Manager UI from a list of groupbox content widgets (eg columns of field editors) and other info."
    # args
    groups = Arg(list_Expr)
    #e in future these groups need to come with more attrs, like group titles
    # (WAIT, they already do have a title attr which we don't use here!),
    # whether they're closable and if so whether initially closed...
    # and they might include their own Boxed already...
    # the type decl might say we want a list of PropertyGroupBoxes,
    # with autoconversion of ParameterGroups to those...
    message = Option(
        str, "(PM message goes here)"
    )  # this has to be already split into lines, for now; all indentation is stripped

    # formulae
    def _C_use_message(self):
        lines = self.message.split('\n')
        lines = [line.strip() for line in lines]
        lines = filter(None, lines)
        return '\n'.join(lines)

    use_message = _self.use_message
    # appearance
    message_box = Boxed(TextRect(use_message), gap=0, bordercolor=yellow)
    group_box_column = MapListToExpr(
        KLUGE_for_passing_expr_classes_as_functions_to_ArgExpr(
            Boxed),  ###e change to a GroupBox, with a title from the group...
        groups,
        KLUGE_for_passing_expr_classes_as_functions_to_ArgExpr(SimpleColumn))
    delegate = SimpleColumn(
        Left(message_box),
        Left(group_box_column),
    )
    pass
Exemple #6
0
class MainToolbar(Toolbar): ###e how is the Main one different from any other one??? not in any way I yet thought of...
    # unless its flyout feature is unique... or maybe it has the behavior of deciding what to look like, inside it??
    # Nah, its client needs to provide the spec that, even if MainToolbar then does the work... but if it *can* do the work,
    # that might count... maybe it's just that it has no parent toolbar?
    #e rename
    """The main toolbar that contains (for example) Features, Build, Sketch, Dimension (tool names passed as an arg),
    with their associated flyout toolbars,
    and maintains the state (passed as a stateref) of what tool/subtool is active.
    """
    # args
    registry = Arg( CommandRegistry, doc = "the place in which tool name -> tool code mapping is registered, and in which subtools are found")
    #e the app object in which the tools operate?
    #e the world which they affect?
    toolnames = Arg(list_Expr, doc = "list of names of main tools")
    toolstack_ref = Arg(StateRef, doc = "external state which should be maintained to show what tool & subtool is active now")
    # formulae
    # appearance
    delegate = SimpleRow(
        MapListToExpr( _self.toolbutton_for_toolname,                       
                      toolnames,
                      KLUGE_for_passing_expr_classes_as_functions_to_ArgExpr(SimpleRow) ),
        TextRect("flyout goes here")
     )
    def toolbutton_for_toolname(self, toolname):
        assert type(toolname) == type("")
        registry = self.registry
        ## expr = Boxed(TextRect(toolname)) # stub
        #e look up commands from registry ### LOGIC BUG: don't we get the toolname/cmd pair from the reg? if so,
        # then at this stage, just look up cmd from a local cache we made of cmds that go with our names for them.
        # But in current code, toolnames were passed in. Nevermind.
        command = registry.command_for_toolname(toolname) ###STUB - at least since retval might be None
            # [also, terms are messed up -- straighten out cmd vs tool, use same for main and sub]
            # [maybe: a command is something you do, and a command is "invoke a tool", ie start it (does not imply finishing it) --
            #  but i don't like that much -- what i look up here is the longlived-thing-maker (toolrun maker),
            #  not a subr that invokes it. otoh what abt toolbuttons that have immediate effect, no longlived thing created?
            #  their presence means i *do* have to look up a command, which when run *might* change toolstack state.]
        subtools = registry.subtools_for_command(command) ###STUB??
        expr = MainCommandToolButton( self, toolname, command, subtools)
        #e is it ok about MapListToExpr that it makes us instantiate this ourselves? Can't it guess a cache index on its own?
        #e related Q: can we make it easier, eg using nim InstanceDict or (working) _CV_ rule?
        instance = self.Instance( expr, "#" + toolname)
        return instance
    def _advise_got_pressed(self, button):
        print "my button %r with toolname %r says it got pressed" % (button, button.toolname)
        ###STUB - do the following:
        #e decide if legal at this time
        #e set it as the next running button
        
        #e unpress other buttons (and finish or cancel their runs if needed) (maybe only if their actions are incompat in parallel??)
        # e.g. something like:
        ## while toolstack_ref.get_value()[-1].is_incompatible_with(something):
        ##    didit = toolstack_ref.get_value()[-1].force_finish(something)
        ##    if not didit:
        ##        # oops, still in some prior command (and what about some we already popped out of? restore them?
        ##        # no, don't pop out yet, unless we want that...)
        
        #e start a new ToolRun of this button's command
        #e put it on the stack we were passed (that way its flyout gets displayed, and its pm gets displayed)
        #e update our flyout and PM if needed (for example, by figuring out what subcommands have been registered with this name)
        #e update other stuff not yet used, like a display/edit style, various filters...
        return
    pass