Return a MultiCall class which inherits its methods from the given widget class (for example, Tkinter.Text). This is used instead of a templating mechanism.
(widget)
| 312 | |
| 313 | _multicall_dict = {} |
| 314 | def MultiCallCreator(widget): |
| 315 | """Return a MultiCall class which inherits its methods from the |
| 316 | given widget class (for example, Tkinter.Text). This is used |
| 317 | instead of a templating mechanism. |
| 318 | """ |
| 319 | if widget in _multicall_dict: |
| 320 | return _multicall_dict[widget] |
| 321 | |
| 322 | class MultiCall (widget): |
| 323 | assert issubclass(widget, tkinter.Misc) |
| 324 | |
| 325 | def __init__(self, *args, **kwargs): |
| 326 | widget.__init__(self, *args, **kwargs) |
| 327 | # a dictionary which maps a virtual event to a tuple with: |
| 328 | # 0. the function binded |
| 329 | # 1. a list of triplets - the sequences it is binded to |
| 330 | self.__eventinfo = {} |
| 331 | self.__binders = [_binder_classes[i](i, widget, self) |
| 332 | for i in range(len(_types))] |
| 333 | |
| 334 | def bind(self, sequence=None, func=None, add=None): |
| 335 | #print("bind(%s, %s, %s)" % (sequence, func, add), |
| 336 | # file=sys.__stderr__) |
| 337 | if type(sequence) is str and len(sequence) > 2 and \ |
| 338 | sequence[:2] == "<<" and sequence[-2:] == ">>": |
| 339 | if sequence in self.__eventinfo: |
| 340 | ei = self.__eventinfo[sequence] |
| 341 | if ei[0] is not None: |
| 342 | for triplet in ei[1]: |
| 343 | self.__binders[triplet[1]].unbind(triplet, ei[0]) |
| 344 | ei[0] = func |
| 345 | if ei[0] is not None: |
| 346 | for triplet in ei[1]: |
| 347 | self.__binders[triplet[1]].bind(triplet, func) |
| 348 | else: |
| 349 | self.__eventinfo[sequence] = [func, []] |
| 350 | return widget.bind(self, sequence, func, add) |
| 351 | |
| 352 | def unbind(self, sequence, funcid=None): |
| 353 | if type(sequence) is str and len(sequence) > 2 and \ |
| 354 | sequence[:2] == "<<" and sequence[-2:] == ">>" and \ |
| 355 | sequence in self.__eventinfo: |
| 356 | func, triplets = self.__eventinfo[sequence] |
| 357 | if func is not None: |
| 358 | for triplet in triplets: |
| 359 | self.__binders[triplet[1]].unbind(triplet, func) |
| 360 | self.__eventinfo[sequence][0] = None |
| 361 | return widget.unbind(self, sequence, funcid) |
| 362 | |
| 363 | def event_add(self, virtual, *sequences): |
| 364 | #print("event_add(%s, %s)" % (repr(virtual), repr(sequences)), |
| 365 | # file=sys.__stderr__) |
| 366 | if virtual not in self.__eventinfo: |
| 367 | self.__eventinfo[virtual] = [None, []] |
| 368 | |
| 369 | func, triplets = self.__eventinfo[virtual] |
| 370 | for seq in sequences: |
| 371 | triplet = _parse_sequence(seq) |
no outgoing calls
no test coverage detected
searching dependent graphs…