git-subtree-dir: labelImg git-subtree-mainline: dbe80aca780253f6ee1e5a2f8686407ca179e921 git-subtree-split: b33f965b6d14c14f1e46b247f1bf346e03f2e950
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
try:
|
|
from PyQt5.QtGui import *
|
|
from PyQt5.QtCore import *
|
|
from PyQt5.QtWidgets import QColorDialog, QDialogButtonBox
|
|
except ImportError:
|
|
from PyQt4.QtGui import *
|
|
from PyQt4.QtCore import *
|
|
|
|
BB = QDialogButtonBox
|
|
|
|
|
|
class ColorDialog(QColorDialog):
|
|
|
|
def __init__(self, parent=None):
|
|
super(ColorDialog, self).__init__(parent)
|
|
self.setOption(QColorDialog.ShowAlphaChannel)
|
|
# The Mac native dialog does not support our restore button.
|
|
self.setOption(QColorDialog.DontUseNativeDialog)
|
|
# Add a restore defaults button.
|
|
# The default is set at invocation time, so that it
|
|
# works across dialogs for different elements.
|
|
self.default = None
|
|
self.bb = self.layout().itemAt(1).widget()
|
|
self.bb.addButton(BB.RestoreDefaults)
|
|
self.bb.clicked.connect(self.check_restore)
|
|
|
|
def getColor(self, value=None, title=None, default=None):
|
|
self.default = default
|
|
if title:
|
|
self.setWindowTitle(title)
|
|
if value:
|
|
self.setCurrentColor(value)
|
|
return self.currentColor() if self.exec_() else None
|
|
|
|
def check_restore(self, button):
|
|
if self.bb.buttonRole(button) & BB.ResetRole and self.default:
|
|
self.setCurrentColor(self.default)
|