def test_mydel(self): # test a simple use scenario # initialize mydel = Delegator(int) self.assertIs(mydel.delegate, int) self.assertEqual(mydel._Delegator__cache, set()) # add an attribute: self.assertRaises(AttributeError, mydel.__getattr__, 'xyz') bl = mydel.bit_length self.assertIs(bl, int.bit_length) self.assertIs(mydel.__dict__['bit_length'], int.bit_length) self.assertEqual(mydel._Delegator__cache, {'bit_length'}) # add a second attribute mydel.numerator self.assertEqual(mydel._Delegator__cache, {'bit_length', 'numerator'}) # delete the second (which, however, leaves it in the name cache) del mydel.numerator self.assertNotIn('numerator', mydel.__dict__) self.assertIn('numerator', mydel._Delegator__cache) # reset by calling .setdelegate, which calls .resetcache mydel.setdelegate(float) self.assertIs(mydel.delegate, float) self.assertNotIn('bit_length', mydel.__dict__) self.assertEqual(mydel._Delegator__cache, set())
def setdelegate(self, delegate): if self.delegate is not None: self.unbind("<<undo>>") self.unbind("<<redo>>") self.unbind("<<dump-undo-state>>") Delegator.setdelegate(self, delegate) if delegate is not None: self.bind("<<undo>>", self.undo_event) self.bind("<<redo>>", self.redo_event) self.bind("<<dump-undo-state>>", self.dump_event)
def setdelegate(self, delegate): if self.delegate is not None: self.unbind("<<toggle-auto-coloring>>") Delegator.setdelegate(self, delegate) if delegate is not None: self.config_colors() self.bind("<<toggle-auto-coloring>>", self.toggle_colorize_event) self.notify_range("1.0", "end") else: # No delegate - stop any colorizing self.stop_colorizing = True self.allow_colorizing = False
def __init__(self, text): # XXX would be nice to inherit from Delegator self.text = text self.redir = WidgetRedirector(text) self.top = self.bottom = Delegator(text) self.bottom.insert = self.redir.register("insert", self.insert) self.bottom.delete = self.redir.register("delete", self.delete) self.filters = []
def __init__(self, interactive=False): Delegator.__init__(self) self.prog = re.compile(make_pat(interactive), re.S) self.idprog = idprog self.argprog = argprog self.LoadTagDefs()
def __init__(self, name): self.name = name Delegator.__init__(self, None)
def __init__(self): Delegator.__init__(self) self.reset_undo()
def __init__(self, callback): Delegator.__init__(self) self.callback = callback self.paste = False