colorDialog.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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. # The Mac native dialog does not support our restore button.
  9. self.setOption(QColorDialog.DontUseNativeDialog)
  10. ## Add a restore defaults button.
  11. # The default is set at invocation time, so that it
  12. # works across dialogs for different elements.
  13. self.default = None
  14. self.bb = self.layout().itemAt(1).widget()
  15. self.bb.addButton(BB.RestoreDefaults)
  16. self.bb.clicked.connect(self.checkRestore)
  17. def getColor(self, value=None, title=None, default=None):
  18. self.default = default
  19. if title:
  20. self.setWindowTitle(title)
  21. if value:
  22. self.setCurrentColor(value)
  23. return self.currentColor() if self.exec_() else None
  24. def checkRestore(self, button):
  25. if self.bb.buttonRole(button) & BB.ResetRole and self.default:
  26. self.setCurrentColor(self.default)