colorDialog.py 1011 B

123456789101112131415161718192021222324252627282930
  1. from PyQt4.QtGui import *
  2. from PyQt4.QtCore import *
  3. BB = QDialogButtonBox
  4. class ColorDialog(QColorDialog):
  5. def __init__(self, parent=None):
  6. super(ColorDialog, self).__init__(parent)
  7. self.setOption(QColorDialog.ShowAlphaChannel)
  8. ## Add a restore defaults button.
  9. # The default is set at invocation time, so that it
  10. # works across dialogs for different elements.
  11. self.default = None
  12. self.bb = self.layout().itemAt(1).widget()
  13. self.bb.addButton(BB.RestoreDefaults)
  14. self.bb.clicked.connect(self.checkRestore)
  15. def getColor(self, value=None, title=None, default=None):
  16. self.default = default
  17. if title:
  18. self.setWindowTitle(title)
  19. if value:
  20. self.setCurrentColor(value)
  21. return self.currentColor() if self.exec_() else None
  22. def checkRestore(self, button):
  23. if self.bb.buttonRole(button) & BB.ResetRole and self.default:
  24. self.setCurrentColor(self.default)