/GUI/Generic/GAlerts.py

https://bitbucket.org/alsh/pygui-mirror · Python · 67 lines · 46 code · 17 blank · 4 comment · 0 complexity · ae3149c2625a4dced0289073dc5b538d MD5 · raw file

  1. #
  2. # Python GUI - Alerts - Generic
  3. #
  4. from BaseAlerts import BaseAlert
  5. from Buttons import Button
  6. from StdButtons import DefaultButton, CancelButton
  7. class Alert(BaseAlert):
  8. def __init__(self, kind, prompt,
  9. ok_label = "OK", default = 1, **kwds):
  10. BaseAlert.__init__(self, kind, prompt,
  11. button_labels = [ok_label], default = default, **kwds)
  12. def _create_buttons(self, ok_label):
  13. self.yes_button = DefaultButton(title = ok_label, action = self.yes)
  14. #self.default_button = self.ok_button
  15. def _layout_buttons(self):
  16. self.place(self.yes_button,
  17. right = self.label.right,
  18. top = self.label + self._label_button_spacing)
  19. class Alert2(BaseAlert):
  20. def __init__(self, kind, prompt,
  21. yes_label = "Yes", no_label = "No",
  22. default = 1, cancel = 0, **kwds):
  23. BaseAlert.__init__(self, kind, prompt,
  24. button_labels = [yes_label, no_label],
  25. default = default, cancel = cancel, **kwds)
  26. def _create_buttons(self, yes_label, no_label):
  27. self.yes_button = DefaultButton(title = yes_label, action = self.yes)
  28. self.no_button = CancelButton(title = no_label, action = self.no)
  29. def _layout_buttons(self):
  30. self.place_row([self.no_button, self.yes_button],
  31. right = self.label.right,
  32. top = self.label + self._label_button_spacing)
  33. class Alert3(BaseAlert):
  34. _minimum_width = 300
  35. def __init__(self, kind, prompt,
  36. yes_label = "Yes", no_label = "No", other_label = "Cancel",
  37. default = 1, cancel = -1, **kwds):
  38. BaseAlert.__init__(self, kind, prompt,
  39. button_labels = [yes_label, no_label, other_label],
  40. default = default, cancel = cancel, **kwds)
  41. def _create_buttons(self, yes_label, no_label, cancel_label):
  42. self.yes_button = DefaultButton(title = yes_label, action = self.yes)
  43. self.no_button = CancelButton(title = no_label, action = self.no)
  44. self.other_button = Button(title = cancel_label, action = self.other)
  45. def _layout_buttons(self):
  46. self.place_row([self.other_button, self.yes_button],
  47. right = self.label.right,
  48. top = self.label + self._label_button_spacing)
  49. self.place(self.no_button,
  50. left = self._left_margin, top = self.label + self._label_button_spacing)