logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

commondialog.py (1296B)


  1. # base class for tk common dialogues
  2. #
  3. # this module provides a base class for accessing the common
  4. # dialogues available in Tk 4.2 and newer. use filedialog,
  5. # colorchooser, and messagebox to access the individual
  6. # dialogs.
  7. #
  8. # written by Fredrik Lundh, May 1997
  9. #
  10. __all__ = ["Dialog"]
  11. from tkinter import Frame, _get_temp_root, _destroy_temp_root
  12. class Dialog:
  13. command = None
  14. def __init__(self, master=None, **options):
  15. if master is None:
  16. master = options.get('parent')
  17. self.master = master
  18. self.options = options
  19. def _fixoptions(self):
  20. pass # hook
  21. def _fixresult(self, widget, result):
  22. return result # hook
  23. def show(self, **options):
  24. # update instance options
  25. for k, v in options.items():
  26. self.options[k] = v
  27. self._fixoptions()
  28. master = self.master
  29. if master is None:
  30. master = _get_temp_root()
  31. try:
  32. self._test_callback(master) # The function below is replaced for some tests.
  33. s = master.tk.call(self.command, *master._options(self.options))
  34. s = self._fixresult(master, s)
  35. finally:
  36. _destroy_temp_root(master)
  37. return s
  38. def _test_callback(self, master):
  39. pass