|
34 | 34 | import tempfile
|
35 | 35 | from xml.dom import minidom
|
36 | 36 |
|
37 |
| -from PyQt5.QtCore import Qt, QTimer |
| 37 | +from PyQt5.QtCore import Qt, pyqtSlot, QTimer |
38 | 38 | from PyQt5 import QtGui
|
39 | 39 | from PyQt5.QtWidgets import (
|
40 | 40 | QGraphicsScene, QMessageBox, QDialog, QColorDialog, QFontDialog,
|
|
47 | 47 | from classes.logger import log
|
48 | 48 | from classes.app import get_app
|
49 | 49 | from classes.metrics import track_metric_screen
|
| 50 | + |
50 | 51 | from windows.views.titles_listview import TitlesListView
|
| 52 | +from windows.color_picker import ColorPicker |
51 | 53 |
|
52 | 54 | import json
|
53 | 55 |
|
@@ -369,43 +371,51 @@ def writeToFile(self, xmldoc):
|
369 | 371 | except IOError as inst:
|
370 | 372 | log.error("Error writing SVG title: {}".format(inst))
|
371 | 373 |
|
| 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 | + |
372 | 388 | def btnFontColor_clicked(self):
|
373 | 389 | app = get_app()
|
374 | 390 | _ = app._tr
|
375 | 391 |
|
| 392 | + callback_func = functools.partial( |
| 393 | + self.color_callback, |
| 394 | + self.set_font_color_elements, |
| 395 | + self.update_font_color_button) |
376 | 396 | # 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) |
390 | 403 |
|
391 | 404 | def btnBackgroundColor_clicked(self):
|
392 | 405 | app = get_app()
|
393 | 406 | _ = app._tr
|
394 | 407 |
|
| 408 | + callback_func = functools.partial( |
| 409 | + self.color_callback, |
| 410 | + self.set_bg_style, |
| 411 | + self.update_background_color_button) |
395 | 412 | # 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) |
409 | 419 |
|
410 | 420 | def btnFont_clicked(self):
|
411 | 421 | app = get_app()
|
|
0 commit comments