def add_widget_methods(self): for class_name in instantiable_widget_class_names: widget_class = eval(class_name) method = types.MethodType(gen_widget_method(widget_class), self, self.__class__) # take the class, get its name in string form, and convert to snake case method_name = to_snakecase(widget_class.__name__) setattr(self, method_name, method)
def __init__(self, parent, source_widget, name=None): if not name: name = to_snakecase(self.__class__.__name__) Widget.__init__(self, parent, name) # Note: source_widget must have a selected attribute. # eg, a radio button self.source_widget = source_widget self.widgets = [] self.add_widget_methods() self.contains()
def add_widget_methods(self): # Page is a special widget that needs to hold other widgets, # and sometimes those widgets inherit from Page. To avoid a circular # import, let's import all widgets here from sikwidgets.widgets import * from sikwidgets.widgets import instantiable_widget_class_names for class_name in instantiable_widget_class_names: widget_class = eval(class_name) method = types.MethodType(gen_widget_method(widget_class), self, self.__class__) # take the class, get its name in string form, and convert to snake case method_name = to_snakecase(widget_class.__name__) setattr(self, method_name, method)
def __str__(self): uri = to_snakecase(self.__class__.__name__) if self.parent: uri = os.path.join(str(self.parent), uri) return uri