diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index b85070445..7e4af3fc6 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -318,6 +318,7 @@ def create_separated_list(string_list): return translate('OpenLP.core.lib', '%s, %s', 'Locale list separator: start') % (string_list[0], merged) +from .colorbutton import ColorButton from .filedialog import FileDialog from .screen import ScreenList from .listwidgetwithdnd import ListWidgetWithDnD diff --git a/openlp/core/lib/colorbutton.py b/openlp/core/lib/colorbutton.py new file mode 100644 index 000000000..00ef9dffe --- /dev/null +++ b/openlp/core/lib/colorbutton.py @@ -0,0 +1,33 @@ +from PyQt4 import QtCore, QtGui + +class ColorButton(QtGui.QPushButton): + """ + Subclasses QPushbutton to create a "Color Chooser" button + """ + + colorChanged = QtCore.pyqtSignal(str) + + def __init__(self, parent): + super(ColorButton, self).__init__() + self._color = '#ffffff' + self.parent = parent + self.clicked.connect(self.on_clicked) + + def change_color(self, color): + self._color = color + self.setStyleSheet('background-color: %s' % color) + + @property + def color(self): + return self._color + + @color.setter + def color(self, color): + self.change_color(color) + + def on_clicked(self): + new_color = QtGui.QColorDialog.getColor(QtGui.QColor(self._color), self.parent) + if new_color.isValid() and self._color != new_color.name(): + self.change_color(new_color.name()) + print("changed") + self.colorChanged.emit(new_color.name()) \ No newline at end of file