Skip to content

Commit 692da08

Browse files
committed
Title editor: Use ColorPicker
1 parent 977b64b commit 692da08

File tree

1 file changed

+37
-27
lines changed

1 file changed

+37
-27
lines changed

src/windows/title_editor.py

+37-27
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import tempfile
3535
from xml.dom import minidom
3636

37-
from PyQt5.QtCore import Qt, QTimer
37+
from PyQt5.QtCore import Qt, pyqtSlot, QTimer
3838
from PyQt5 import QtGui
3939
from PyQt5.QtWidgets import (
4040
QGraphicsScene, QMessageBox, QDialog, QColorDialog, QFontDialog,
@@ -47,7 +47,9 @@
4747
from classes.logger import log
4848
from classes.app import get_app
4949
from classes.metrics import track_metric_screen
50+
5051
from windows.views.titles_listview import TitlesListView
52+
from windows.color_picker import ColorPicker
5153

5254
import json
5355

@@ -369,43 +371,51 @@ def writeToFile(self, xmldoc):
369371
except IOError as inst:
370372
log.error("Error writing SVG title: {}".format(inst))
371373

374+
def save_and_reload(self):
375+
"""Something changed, so update temp SVG and redisplay"""
376+
self.writeToFile(self.xmldoc)
377+
self.display_svg()
378+
379+
@pyqtSlot(QtGui.QColor)
380+
def color_callback(self, save_fn, refresh_fn, color):
381+
"""Update SVG color after user selection"""
382+
if not color or not color.isValid():
383+
return
384+
save_fn(color.name(), color.alphaF())
385+
refresh_fn()
386+
self.save_and_reload()
387+
372388
def btnFontColor_clicked(self):
373389
app = get_app()
374390
_ = app._tr
375391

392+
callback_func = functools.partial(
393+
self.color_callback,
394+
self.set_font_color_elements,
395+
self.update_font_color_button)
376396
# Get color from user
377-
col = QColorDialog.getColor(self.font_color_code, self, _("Select a Color"),
378-
QColorDialog.DontUseNativeDialog | QColorDialog.ShowAlphaChannel)
379-
380-
# Update SVG colors
381-
if col.isValid():
382-
self.set_font_color_elements(col.name(), col.alphaF())
383-
self.update_font_color_button()
384-
385-
# Something changed, so update temp SVG
386-
self.writeToFile(self.xmldoc)
387-
388-
# Display SVG again
389-
self.display_svg()
397+
log.debug("Launching color picker for %s", self.font_color_code.name())
398+
ColorPicker(
399+
self.font_color_code, parent=self,
400+
title=_("Select a Color"),
401+
extra_options=QColorDialog.ShowAlphaChannel,
402+
callback=callback_func)
390403

391404
def btnBackgroundColor_clicked(self):
392405
app = get_app()
393406
_ = app._tr
394407

408+
callback_func = functools.partial(
409+
self.color_callback,
410+
self.set_bg_style,
411+
self.update_background_color_button)
395412
# Get color from user
396-
col = QColorDialog.getColor(self.bg_color_code, self, _("Select a Color"),
397-
QColorDialog.DontUseNativeDialog | QColorDialog.ShowAlphaChannel)
398-
399-
# Update SVG colors
400-
if col.isValid():
401-
self.set_bg_style(col.name(), col.alphaF())
402-
self.update_background_color_button()
403-
404-
# Something changed, so update temp SVG
405-
self.writeToFile(self.xmldoc)
406-
407-
# Display SVG again
408-
self.display_svg()
413+
log.debug("Launching color picker for %s", self.bg_color_code.name())
414+
ColorPicker(
415+
self.bg_color_code, parent=self,
416+
title=_("Select a Color"),
417+
extra_options=QColorDialog.ShowAlphaChannel,
418+
callback=callback_func)
409419

410420
def btnFont_clicked(self):
411421
app = get_app()

0 commit comments

Comments
 (0)