def add_var(self, var_type, **kw): var = var_type(self.studio) item_count = len( list(filter(lambda x: x.var_type == var_type, self.variables))) + 1 name = kw.get('name', f"{var_type.__name__}_{item_count}") value = kw.get('value') item = VariableItem(self._variable_pane.body, var, name) item.bind("<Button-1>", lambda e: self.select(item)) if value is not None: item.set(value) VariableManager.add(item) self._show(item) self._show_overlay(False) self.select(item)
def set_up(self): VariableManager.editors.append(self) values = [i.var for i in VariableManager.variables()] self._spinner.set_item_class(Variable.VariableChoiceItem) self._spinner.set_values(( '', *values, ))
def set_up(self): # filter to obtain only string variables VariableManager.editors.append(self) values = [i.var for i in VariableManager.variables() if i.var.__class__ == StringVar] self._spinner.set_item_class(Variable.VariableChoiceItem) self._spinner.set_values(( '', *values, ))
def set(menu, index, value, prop): if isinstance(value, tk.Variable): menu.entryconfigure(index, **{prop: value}) else: variable = VariableManager.lookup(value) if isinstance(variable, VariableItem): menu.entryconfigure(index, **{prop: variable.var}) else: logging.debug(f'variable {value} not found')
def set(widget, value, prop): if hasattr(value, 'handle'): setattr(widget, f"__{prop}", value.handle.name) else: setattr(widget, f"__{prop}", value) if isinstance(value, str): var = list( filter(lambda x: x.name == value, VariableManager.variables())) if var: value = var[0].var widget.config(**{prop: value})
def destroy(self): VariableManager.remove_editor(self) super().destroy()
def get(menu, index, prop): return str(VariableManager.lookup(menu.entrycget(index, prop)))
def on_context_switch(self): VariableManager.set_context(self.studio.context) self.refresh()
def variables(self): return VariableManager.variables()
def delete_var(self, var): self._hide(var) VariableManager.remove(var)
def _variables_to_tree(self, parent): variables = VariableManager.variables(self.designer.context) for var_item in variables: VariableStudioAdapter.generate(var_item, parent)
def on_var_context_change(self): values = [i.var for i in VariableManager.variables() if i.var.__class__ == StringVar] self._spinner.set_values(( '', *values, ))
def on_var_context_change(self): values = [i.var for i in VariableManager.variables()] self._spinner.set_values(( '', *values, ))
def set(self, value): # Override default conversion of value to string by Choice class var = list(filter(lambda x: x.name == value, VariableManager.variables())) # if variable does not match anything in the variable manager presume as empty value = var[0].var if var else '' self._spinner.set(value)