Subwidget class. This is used to mirror child widgets automatically created by Tix/Tk as part of a mega-widget in Python (which is not informed of this)
| 414 | # In python, we have to create these subwidgets manually to mirror their |
| 415 | # existence in Tk/Tix. |
| 416 | class TixSubWidget(TixWidget): |
| 417 | """Subwidget class. |
| 418 | |
| 419 | This is used to mirror child widgets automatically created |
| 420 | by Tix/Tk as part of a mega-widget in Python (which is not informed |
| 421 | of this)""" |
| 422 | |
| 423 | def __init__(self, master, name, |
| 424 | destroy_physically=1, check_intermediate=1): |
| 425 | if check_intermediate: |
| 426 | path = master._subwidget_name(name) |
| 427 | try: |
| 428 | path = path[len(master._w)+1:] |
| 429 | plist = path.split('.') |
| 430 | except: |
| 431 | plist = [] |
| 432 | |
| 433 | if not check_intermediate: |
| 434 | # immediate descendant |
| 435 | TixWidget.__init__(self, master, None, None, {'name' : name}) |
| 436 | else: |
| 437 | # Ensure that the intermediate widgets exist |
| 438 | parent = master |
| 439 | for i in range(len(plist) - 1): |
| 440 | n = '.'.join(plist[:i+1]) |
| 441 | try: |
| 442 | w = master._nametowidget(n) |
| 443 | parent = w |
| 444 | except KeyError: |
| 445 | # Create the intermediate widget |
| 446 | parent = TixSubWidget(parent, plist[i], |
| 447 | destroy_physically=0, |
| 448 | check_intermediate=0) |
| 449 | # The Tk widget name is in plist, not in name |
| 450 | if plist: |
| 451 | name = plist[-1] |
| 452 | TixWidget.__init__(self, parent, None, None, {'name' : name}) |
| 453 | self.destroy_physically = destroy_physically |
| 454 | |
| 455 | def destroy(self): |
| 456 | # For some widgets e.g., a NoteBook, when we call destructors, |
| 457 | # we must be careful not to destroy the frame widget since this |
| 458 | # also destroys the parent NoteBook thus leading to an exception |
| 459 | # in Tkinter when it finally calls Tcl to destroy the NoteBook |
| 460 | for c in list(self.children.values()): c.destroy() |
| 461 | if self._name in self.master.children: |
| 462 | del self.master.children[self._name] |
| 463 | if self._name in self.master.subwidget_list: |
| 464 | del self.master.subwidget_list[self._name] |
| 465 | if self.destroy_physically: |
| 466 | # This is bypassed only for a few widgets |
| 467 | self.tk.call('destroy', self._w) |
| 468 | |
| 469 | |
| 470 | # Useful class to create a display style - later shared by many items. |