Ejemplo n.º 1
0
def _expr_for_imagename(imagename):
    # WARNING: this is not optimized -- it recomputes and discards this expr on every access!
    # (But it looks like its caller, _expr_instance_for_imagename, caches the expr instances,
    #  so only the uninstantiated expr itself is recomputed each time, so it's probably ok.
    #  [bruce 080323 comment])
    
    if '/' not in imagename:
        imagename = os.path.join( "ui/confcorner", imagename)
    image_expr = _trans_image( imagename )
    return DrawInCorner(corner = UPPER_RIGHT)( image_expr )
Ejemplo n.º 2
0
class whatever(DelegatingInstanceOrExpr):  ###e rename
    # simulates the env that demo_ui will provide (stub version, evolving to be more like it)
    ui_and_world = Instance(World())  #####
    ###e following needs to permit cmd_DrawOnSurface to vary
    # (at least let it also be cmd_MakeRect; use a menu of options? or use one ActionButton per command, since more like a toolbar?)
    # -- but with Instance inside the variation, I think --
    # ie it should be a map from the desired cmd expr to the cmd instance -- or, make a new one each time, so it's a cmdrun...
    # maybe see how demo_ui/toolbar was planning to do it... ###e
    toolbar = SimpleColumn(
        ActionButton(
            _self.do_cmd_DrawOnSurface, "button: cmd_DrawOnSurface"
        ),  #e make the text from the command #e the running one should look pressed
        ActionButton(_self.do_cmd_MakeRect, "button: cmd_MakeRect"),
    )  ###e show it where? above PM for now?
    current_cmdrun = State(
        Anything, None
    )  # what is actually in here? an Instance of a "command run",   [btw is None needed??]

    # or of a command obj that handles multiple runs (ie a command_runner?)... up to it to not get messed up if that happens
    # (and for now, unfortunately, not remaking it is probably a significant speed optim)
    # (so should we let an outer command handler have the PM and get reused, but an inner CommandRun get remade? why bother?)
    def do_cmd_DrawOnSurface(
        self
    ):  #e which name is better: do_cmd or set_cmd? depends on type of command!
        self._do_cmd(cmd_DrawOnSurface)

    def do_cmd_MakeRect(self):
        self._do_cmd(cmd_MakeRect)

    def _do_cmd(self, cmd):
        "set self.current_cmdrun, etc..."
        # do we make a new one if button pressed when one already running?? yes for now.
        self.current_cmdrun = self.Instance(
            cmd(world=self.ui_and_world),
            id(cmd))  #e cache that expr? index ok? why cache instance?
        #old cmt: #e args? world? new object? does its super handle some? Command vs CommandRun?

    pm = current_cmdrun.property_manager
    corner_stuff = SimpleColumn(toolbar, pm)
    delegate = Overlay(
        current_cmdrun,
        DrawInCorner(corner_stuff, corner=PM_CORNER),
    )

    def _init_instance(self):
        super(whatever, self)._init_instance()
        self.do_cmd_MakeRect(
        )  # or at least set some command, preferably a "null" or "default" one
        # note that this resets the current tool state on reload -- not really desirable;
        # how was demo_ui planning to handle that? ###k

    pass
Ejemplo n.º 3
0
def _expr_for_overlay_imagename(imagename, dx=0, dy=0):
    # WARNING: this is not optimized (see comment for _expr_for_imagename()).
    image_expr = _overlay_image(imagename)
    # NOTE: If the desired dx,dy depends on other settings,
    # like whether one or two CC buttons are shown,
    # then it's simplest to make more variants of this expr,
    # with dx, dy hardcoded differently in each one.
    # Or if that's not practical, let me know and I'll
    # revise the code that draws this to accomodate that variability.
    # Also make sure to revise the code that calls each one
    # (i.e. a modified copy of _expr_instance_for_overlay_imagename)
    # to use a different "index" even when using the same imagename.
    # (For example, it could include dx,dy in the index.)
    # [bruce 080324]
    return DrawInCorner(corner=UPPER_RIGHT)(Overlay(
        Spacer(22 * PIXELS),
        Translate(image_expr, V_expr(dx * PIXELS, dy * PIXELS, 0)),
    ))
Ejemplo n.º 4
0
class main_ui_layout(DelegatingInstanceOrExpr):
    #e rename? is it not only the ui, but the entire app? (selection, files, etc)
    #e merge in the App obj from test.py, and the _recent_tests system in some form?

    # args (none yet)

    # internal state - permanent
    ###e note: when we reload and remake this instance, we'd prefer it if the world state stayed unchanged (as i presume it does)
    # but if the default_tool instance and toolstack state got remade. The lack of the latter has been confusing me
    # since changes to ui code aren't working. I think this is a difference between a ui and operations layer (should change)
    # vs model data layer (should not change even tho the op methods on it can change). So when I can put these things into layers
    # (not only State, but even Instance or attrs within them) and make those sensitive to reload, that will help.
    # In the meantime -- if I could kluge Instance and State to take an option to control this
    # (like index = exprs_globals.reload_counter)
    # it might help.... #####TRYIT SOMETIME, and BE CAREFUL UNTIL I DO.
    world = Instance(World())
    default_tool = Instance(DefaultToolRun())

    # internal state - varying
    toolstack = State(list_Expr, [
        default_tool
    ])  # always has at least one tool on it; a stack of Instances not exprs
    # maybe the better term for this is something like command & subcommand
    current_tool = toolstack[
        -1]  # last tool on the stack is current; exiting it will pop the stack (Instance not expr)
    ##e (add a type-assertion (as opposed to type-coercion) primitive, so I can say "this is an Instance" in the code?)
    # NOTE: this is not strictly speaking a tool, but ONE RUN of a tool. That might be important enough to rename it for,
    # to ToolRun or maybe ActiveTool or RunningTool or ToolInUse or ToolBeingUsed...
    # [but note, obj might remain around on history or in Undo stack, even when no longer being used],
    # since we also have to deal with Tools in the sense of Tool Run Producers, eg toolbuttons. ###e

    # parts of the appearance
    registry = find_or_make_global_command_registry(
    )  ## None ###STUB, will fail --
    ## AttributeError: 'NoneType' object has no attribute 'command_for_toolname'
    toolstack_ref = None  ###STUB
    toolbar = Instance(
        MainToolbar(registry, ["Features", "Build", "Sketch"],
                    toolstack_ref))  #e arg order?
    ###e args/opts for what tools to show -- maybe their cmdnames & it loads them from elsewhere
    #e add row of tool buttons, and flyout toolbar; use ChoiceRow?? the things should probably look pressed...
    # they might need cmenus (find out what the deal is with the cmenus i see in the ui mockup - related to flyouts?
    #    yes, it's like this: main tools have cmenus with subtools, and if you pick one, main tool and its subtool both look pressed
    # I'll need new specialized controls.py classes for these; new super Control for all kinds of controls?? (not sure why...)
    propmgr = SimpleColumn(
        TextRect(
            "(property manager)"),  #e possibly to become a tab control tab
        DebugPrintAttrs(
            current_tool.property_manager
        )  # must be None if we don't want one visible; otherwise an Instance
        ###BUG: DebugPrintAttrs shows that it's a spacer -- I guess IorE turns None into one when it instantiates? Make it a false one??
    )
    mt = SimpleColumn(
        TextRect(
            "(model tree)"
        ),  #e possibly to become a tab control tab, but only when we're in the left channel
        MT_try2(world)  #e rename to  "Feature Manager" ??
        ##e soon, MT should be not on whole world but on model or cur. part, a specific obj in the world
    )
    graphics_area = _self.world
    ##e ditto for what we show here, except it might not be the exact same object, and it will really be shown in a way
    # that depends on both the current display style and the current tool (command & subcommand)
    graphics_area_topright_buttons = current_tool.graphics_area_topright_buttons
    # overall appearance
    delegate = Overlay(
        # stuff in the corners -- note, these don't use the corner constants for standalone tests like PM_CORNER
        DrawInCorner(corner=UPPER_LEFT)(
            SimpleColumn(
                toolbar,
                #e add tab control
                SimpleRow(
                    If(
                        current_tool.property_manager, Top(propmgr), None
                    ),  #k None?? prob ok now, see demo_MT comment 070302 ###k
                    Top(mt)
                ),  #e actually we'd then put a splitter & glpane-like-thing...
                #e anything just below the propmgr?
            )),
        DrawInCorner(corner=UPPER_RIGHT)
        (  ##e of graphics area, not entire screen...
            graphics_area_topright_buttons  ### WRONG, these should go under the main toolbar area on the right
            # (but we don't yet have any 2dwidgets which expand to fill the available space, except DrawInCorner of entire screen)
            # (this won't matter once the toolbar is done entirely in Qt, so we don't need to correct it for now)
        ),
        #e other corners? "... an area (view) on the right side
        # of the main window for accessing the part library, on-line documentation, etc"
        # the main graphics area
        #e [this too ought to go under the toolbar and to the right of the propmgr, but that can wait until they're fully in Qt]
        graphics_area)
    pass