Skip to content

Commit 977b64b

Browse files
committed
Properties: Use ColorPicker
1 parent 900e78c commit 977b64b

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

src/windows/views/properties_tableview.py

+27-19
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,27 @@
2626
"""
2727

2828
import os
29-
from functools import partial
29+
import functools
3030
from operator import itemgetter
31-
from PyQt5.QtCore import Qt, QRectF, QLocale, pyqtSignal, QTimer
31+
32+
from PyQt5.QtCore import Qt, QRectF, QLocale, pyqtSignal, pyqtSlot
3233
from PyQt5.QtGui import (
3334
QIcon, QColor, QBrush, QPen, QPalette, QPixmap,
3435
QPainter, QPainterPath, QLinearGradient, QFont, QFontInfo,
3536
)
3637
from PyQt5.QtWidgets import (
3738
QTableView, QAbstractItemView, QMenu, QSizePolicy,
38-
QHeaderView, QColorDialog, QItemDelegate, QStyle, QLabel,
39+
QHeaderView, QItemDelegate, QStyle, QLabel,
3940
QPushButton, QHBoxLayout, QFrame, QFontDialog
4041
)
4142

4243
from classes.logger import log
4344
from classes.app import get_app
4445
from classes import info
4546
from classes.query import Clip, Effect, Transition
47+
4648
from windows.models.properties_model import PropertiesModel
49+
from windows.color_picker import ColorPicker
4750

4851
import openshot
4952

@@ -297,6 +300,13 @@ def mouseReleaseEvent(self, event):
297300
self.lock_selection = False
298301
self.previous_x = -1
299302

303+
@pyqtSlot(QColor)
304+
def color_callback(self, newColor: QColor):
305+
# Set the new color keyframe
306+
if newColor.isValid():
307+
self.clip_properties_model.color_update(
308+
self.selected_item, newColor)
309+
300310
def doubleClickedCB(self, model_index):
301311
"""Double click handler for the property table"""
302312

@@ -322,12 +332,11 @@ def doubleClickedCB(self, model_index):
322332

323333
# Show color dialog
324334
currentColor = QColor(red, green, blue)
325-
newColor = QColorDialog.getColor(currentColor, self, _("Select a Color"),
326-
QColorDialog.DontUseNativeDialog)
327-
328-
# Set the new color keyframe
329-
if newColor.isValid():
330-
self.clip_properties_model.color_update(self.selected_item, newColor)
335+
log.debug("Launching ColorPicker for %s", currentColor.name())
336+
ColorPicker(
337+
currentColor, parent=self, title=_("Select a Color"),
338+
callback=self.color_callback)
339+
return
331340

332341
elif property_type == "font":
333342
# Get font from user
@@ -381,7 +390,7 @@ def filter_changed(self, value=None):
381390
self.clip_properties_model.update_model(value)
382391

383392
def contextMenuEvent(self, event):
384-
""" Display context menu, or release lock when menu displays """
393+
""" Display context menu """
385394
# Get property being acted on
386395
index = self.indexAt(event.pos())
387396
if not index.isValid():
@@ -469,6 +478,7 @@ def contextMenuEvent(self, event):
469478
track_name = track.get("label") or _("Track %s") % display_count
470479
self.choices.append({"name": track_name, "value": track.get("number"), "selected": False, "icon": None})
471480
display_count -= 1
481+
return
472482

473483
elif self.property_type == "font":
474484
# Get font from user
@@ -480,7 +490,6 @@ def contextMenuEvent(self, event):
480490
if ok and font:
481491
fontinfo = QFontInfo(font)
482492
self.clip_properties_model.value_updated(self.selected_item, value=fontinfo.family())
483-
return self.contextMenuEvent(event, release=True)
484493

485494
elif self.property_type == "color":
486495
# Get current value of color
@@ -490,13 +499,11 @@ def contextMenuEvent(self, event):
490499

491500
# Show color dialog
492501
currentColor = QColor(red, green, blue)
493-
newColor = QColorDialog.getColor(currentColor, self, _("Select a Color"),
494-
QColorDialog.DontUseNativeDialog)
495-
496-
# Set the new color keyframe
497-
if newColor.isValid():
498-
self.clip_properties_model.color_update(self.selected_item, newColor)
499-
return self.contextMenuEvent(event, release=True)
502+
log.debug("Launching ColorPicker for %s", currentColor.name())
503+
ColorPicker(
504+
currentColor, parent=self, title=_("Select a Color"),
505+
callback=self.color_callback)
506+
return
500507

501508
# Define bezier presets
502509
bezier_presets = [
@@ -540,7 +547,8 @@ def contextMenuEvent(self, event):
540547
Bezier_Menu = menu.AddMenu(self.bezier_icon, _("Bezier"))
541548
for bezier_preset in bezier_presets:
542549
preset_action = Bezier_Menu.addAction(bezier_preset[4])
543-
preset_action.triggered.connect(partial(self.Bezier_Action_Triggered, bezier_preset))
550+
preset_action.triggered.connect(functools.partial(
551+
self.Bezier_Action_Triggered, bezier_preset))
544552
Linear_Action = menu.addAction(self.linear_icon, _("Linear"))
545553
Linear_Action.triggered.connect(self.Linear_Action_Triggered)
546554
Constant_Action = menu.addAction(self.constant_icon, _("Constant"))

0 commit comments

Comments
 (0)