def demo_drag_toolcorner_expr_maker(world): #070106 improving the above # given an instance of World, return an expr for the "toolcorner" for use along with GraphDrawDemo_FixedToolOnArg1 (on the same World) expr = SimpleColumn( checkbox_pref(kluge_dragtool_state_prefs_key, "drag new nodes?", dflt=kluge_dragtool_state_prefs_default), checkbox_pref(kluge_dragtool_state_prefs_key + "bla", "make polyline?", dflt=False), checkbox_pref(kluge_dragtool_state_prefs_key + "bla2", "(make it closed?)", dflt=False), ## ActionButton( world._cmd_Clear, "button: clear") # works # 070108: try this variant which uses _cmd_Clear_nontrivial: will the If work as an Expr?? If_kluge should tell us #####k ####k also will the type tests inside ActionButton work with an If? Probably not -- that's a ###BUG but I'll put it off. ## 1. make this work later: ActionButton( world._cmd_Clear, If_kluge( world._cmd_Clear_nontrivial, "button: clear", "button (disabled): clear")) ## 2. this too: If_kluge( world._cmd_Clear_nontrivial, ## ActionButton( world._cmd_Clear, "button: clear"), ## ActionButton( world._cmd_Clear, "button (disabled): clear") ## ) If_kluge( getattr_Expr(world, '_cmd_Clear_nontrivial'), ActionButton(world._cmd_Clear, "button: clear"), ActionButton(world._cmd_Clear, "button (disabled): clear", enabled=False) ) # works, though text change is so slow I suspect there's actually a highlighting or update bug making it appear even slower... # update 070109: the bug seems to be that as long as the mouse stays on the button, it remains highlighted with the old highlight form. ) return expr
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
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 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