Merge branch '2.x/develop' into develop

This commit is contained in:
iLLiCiTiT 2020-07-08 11:16:33 +02:00
commit 7e07bf2892
48 changed files with 1129 additions and 292 deletions

View file

@ -1,5 +1,7 @@
from Qt import QtCore
EXPANDER_WIDTH = 20
def flags(*args, **kwargs):
type_name = kwargs.pop("type_name", "Flags")

View file

@ -5,7 +5,7 @@ from Qt import QtWidgets, QtGui, QtCore
from . import model
from .awesome import tags as awesome
from .constants import (
PluginStates, InstanceStates, PluginActionStates, Roles
PluginStates, InstanceStates, PluginActionStates, Roles, EXPANDER_WIDTH
)
colors = {
@ -14,12 +14,16 @@ colors = {
"ok": QtGui.QColor("#77AE24"),
"active": QtGui.QColor("#99CEEE"),
"idle": QtCore.Qt.white,
"font": QtGui.QColor("#DDD"),
"inactive": QtGui.QColor("#888"),
"hover": QtGui.QColor(255, 255, 255, 10),
"selected": QtGui.QColor(255, 255, 255, 20),
"outline": QtGui.QColor("#333"),
"group": QtGui.QColor("#333")
"group": QtGui.QColor("#333"),
"group-hover": QtGui.QColor("#3c3c3c"),
"group-selected-hover": QtGui.QColor("#555555"),
"expander-bg": QtGui.QColor("#222"),
"expander-hover": QtGui.QColor("#2d6c9f"),
"expander-selected-hover": QtGui.QColor("#3784c5")
}
scale_factors = {"darwin": 1.5}
@ -279,14 +283,169 @@ class InstanceItemDelegate(QtWidgets.QStyledItemDelegate):
return QtCore.QSize(option.rect.width(), 20)
class OverviewGroupSection(QtWidgets.QStyledItemDelegate):
"""Generic delegate for section header"""
class InstanceDelegate(QtWidgets.QStyledItemDelegate):
"""Generic delegate for instance header"""
item_class = None
radius = 8.0
def __init__(self, parent):
super(OverviewGroupSection, self).__init__(parent)
self.item_delegate = self.item_class(parent)
super(InstanceDelegate, self).__init__(parent)
self.item_delegate = InstanceItemDelegate(parent)
def paint(self, painter, option, index):
if index.data(Roles.TypeRole) in (
model.InstanceType, model.PluginType
):
self.item_delegate.paint(painter, option, index)
return
self.group_item_paint(painter, option, index)
def group_item_paint(self, painter, option, index):
"""Paint text
_
My label
"""
body_rect = QtCore.QRectF(option.rect)
bg_rect = QtCore.QRectF(
body_rect.left(), body_rect.top() + 1,
body_rect.width() - 5, body_rect.height() - 2
)
expander_rect = QtCore.QRectF(bg_rect)
expander_rect.setWidth(EXPANDER_WIDTH)
remainder_rect = QtCore.QRectF(
expander_rect.x() + expander_rect.width(),
expander_rect.y(),
bg_rect.width() - expander_rect.width(),
expander_rect.height()
)
width = float(expander_rect.width())
height = float(expander_rect.height())
x_pos = expander_rect.x()
y_pos = expander_rect.y()
x_radius = min(self.radius, width / 2)
y_radius = min(self.radius, height / 2)
x_radius2 = x_radius * 2
y_radius2 = y_radius * 2
expander_path = QtGui.QPainterPath()
expander_path.moveTo(x_pos, y_pos + y_radius)
expander_path.arcTo(
x_pos, y_pos,
x_radius2, y_radius2,
180.0, -90.0
)
expander_path.lineTo(x_pos + width, y_pos)
expander_path.lineTo(x_pos + width, y_pos + height)
expander_path.lineTo(x_pos + x_radius, y_pos + height)
expander_path.arcTo(
x_pos, y_pos + height - y_radius2,
x_radius2, y_radius2,
270.0, -90.0
)
expander_path.closeSubpath()
width = float(remainder_rect.width())
height = float(remainder_rect.height())
x_pos = remainder_rect.x()
y_pos = remainder_rect.y()
x_radius = min(self.radius, width / 2)
y_radius = min(self.radius, height / 2)
x_radius2 = x_radius * 2
y_radius2 = y_radius * 2
remainder_path = QtGui.QPainterPath()
remainder_path.moveTo(x_pos + width, y_pos + height - y_radius)
remainder_path.arcTo(
x_pos + width - x_radius2, y_pos + height - y_radius2,
x_radius2, y_radius2,
0.0, -90.0
)
remainder_path.lineTo(x_pos, y_pos + height)
remainder_path.lineTo(x_pos, y_pos)
remainder_path.lineTo(x_pos + width - x_radius, y_pos)
remainder_path.arcTo(
x_pos + width - x_radius2, y_pos,
x_radius2, y_radius2,
90.0, -90.0
)
remainder_path.closeSubpath()
painter.fillPath(expander_path, colors["expander-bg"])
painter.fillPath(remainder_path, colors["group"])
mouse_pos = option.widget.mapFromGlobal(QtGui.QCursor.pos())
selected = option.state & QtWidgets.QStyle.State_Selected
hovered = option.state & QtWidgets.QStyle.State_MouseOver
if selected and hovered:
if expander_rect.contains(mouse_pos):
painter.fillPath(
expander_path, colors["expander-selected-hover"]
)
else:
painter.fillPath(
remainder_path, colors["group-selected-hover"]
)
elif hovered:
if expander_rect.contains(mouse_pos):
painter.fillPath(expander_path, colors["expander-hover"])
else:
painter.fillPath(remainder_path, colors["group-hover"])
text_height = font_metrics["awesome6"].height()
adjust_value = (expander_rect.height() - text_height) / 2
expander_rect.adjust(
adjust_value + 1.5, adjust_value - 0.5,
-adjust_value + 1.5, -adjust_value - 0.5
)
offset = (remainder_rect.height() - font_metrics["h5"].height()) / 2
label_rect = QtCore.QRectF(remainder_rect.adjusted(
5, offset - 1, 0, 0
))
expander_icon = icons["plus-sign"]
expanded = self.parent().isExpanded(index)
if expanded:
expander_icon = icons["minus-sign"]
label = index.data(QtCore.Qt.DisplayRole)
label = font_metrics["h5"].elidedText(
label, QtCore.Qt.ElideRight, label_rect.width()
)
# Maintain reference to state, so we can restore it once we're done
painter.save()
painter.setFont(fonts["awesome6"])
painter.setPen(QtGui.QPen(colors["idle"]))
painter.drawText(expander_rect, QtCore.Qt.AlignCenter, expander_icon)
# Draw label
painter.setFont(fonts["h5"])
painter.drawText(label_rect, label)
# Ok, we're done, tidy up.
painter.restore()
def sizeHint(self, option, index):
return QtCore.QSize(option.rect.width(), 20)
class PluginDelegate(QtWidgets.QStyledItemDelegate):
"""Generic delegate for plugin header"""
def __init__(self, parent):
super(PluginDelegate, self).__init__(parent)
self.item_delegate = PluginItemDelegate(parent)
def paint(self, painter, option, index):
if index.data(Roles.TypeRole) in (
@ -310,7 +469,14 @@ class OverviewGroupSection(QtWidgets.QStyledItemDelegate):
radius = 8.0
bg_path = QtGui.QPainterPath()
bg_path.addRoundedRect(bg_rect, radius, radius)
painter.fillPath(bg_path, colors["group"])
hovered = option.state & QtWidgets.QStyle.State_MouseOver
selected = option.state & QtWidgets.QStyle.State_Selected
if hovered and selected:
painter.fillPath(bg_path, colors["group-selected-hover"])
elif hovered:
painter.fillPath(bg_path, colors["group-hover"])
else:
painter.fillPath(bg_path, colors["group"])
expander_rect = QtCore.QRectF(bg_rect)
expander_rect.setWidth(expander_rect.height())
@ -343,18 +509,12 @@ class OverviewGroupSection(QtWidgets.QStyledItemDelegate):
painter.setFont(fonts["awesome6"])
painter.setPen(QtGui.QPen(colors["idle"]))
painter.drawText(expander_rect, expander_icon)
painter.drawText(expander_rect, QtCore.Qt.AlignCenter, expander_icon)
# Draw label
painter.setFont(fonts["h5"])
painter.drawText(label_rect, label)
if option.state & QtWidgets.QStyle.State_MouseOver:
painter.fillPath(bg_path, colors["hover"])
if option.state & QtWidgets.QStyle.State_Selected:
painter.fillPath(bg_path, colors["selected"])
# Ok, we're done, tidy up.
painter.restore()
@ -362,16 +522,6 @@ class OverviewGroupSection(QtWidgets.QStyledItemDelegate):
return QtCore.QSize(option.rect.width(), 20)
class PluginDelegate(OverviewGroupSection):
"""Generic delegate for model items in proxy tree view"""
item_class = PluginItemDelegate
class InstanceDelegate(OverviewGroupSection):
"""Generic delegate for model items in proxy tree view"""
item_class = InstanceItemDelegate
class ArtistDelegate(QtWidgets.QStyledItemDelegate):
"""Delegate used on Artist page"""

View file

@ -319,7 +319,7 @@ class PluginItem(QtGui.QStandardItem):
return False
self.plugin.active = value
self.emitDataChanged()
return True
return
elif role == Roles.PluginActionProgressRole:
if isinstance(value, list):
@ -652,14 +652,14 @@ class InstanceItem(QtGui.QStandardItem):
def setData(self, value, role=(QtCore.Qt.UserRole + 1)):
if role == QtCore.Qt.CheckStateRole:
if not self.data(Roles.IsEnabledRole):
return False
return
self.instance.data["publish"] = value
self.emitDataChanged()
return True
return
if role == Roles.IsEnabledRole:
if not self.instance.optional:
return False
return
if role == Roles.PublishFlagsRole:
if isinstance(value, list):
@ -692,12 +692,12 @@ class InstanceItem(QtGui.QStandardItem):
self.instance._publish_states = value
self.emitDataChanged()
return True
return
if role == Roles.LogRecordsRole:
self.instance._logs = value
self.emitDataChanged()
return True
return
return super(InstanceItem, self).setData(value, role)

View file

@ -1,6 +1,6 @@
from Qt import QtCore, QtWidgets
from . import model
from .constants import Roles
from .constants import Roles, EXPANDER_WIDTH
# Imported when used
widgets = None
@ -84,8 +84,6 @@ class OverviewView(QtWidgets.QTreeView):
self.setRootIsDecorated(False)
self.setIndentation(0)
self.clicked.connect(self.item_expand)
def event(self, event):
if not event.type() == QtCore.QEvent.KeyPress:
return super(OverviewView, self).event(event)
@ -113,6 +111,24 @@ class OverviewView(QtWidgets.QTreeView):
def focusOutEvent(self, event):
self.selectionModel().clear()
def mouseReleaseEvent(self, event):
if event.button() in (QtCore.Qt.LeftButton, QtCore.Qt.RightButton):
# Deselect all group labels
indexes = self.selectionModel().selectedIndexes()
for index in indexes:
if index.data(Roles.TypeRole) == model.GroupType:
self.selectionModel().select(
index, QtCore.QItemSelectionModel.Deselect
)
return super(OverviewView, self).mouseReleaseEvent(event)
class PluginView(OverviewView):
def __init__(self, *args, **kwargs):
super(PluginView, self).__init__(*args, **kwargs)
self.clicked.connect(self.item_expand)
def item_expand(self, index):
if index.data(Roles.TypeRole) == model.GroupType:
if self.isExpanded(index):
@ -125,23 +141,86 @@ class OverviewView(QtWidgets.QTreeView):
indexes = self.selectionModel().selectedIndexes()
if len(indexes) == 1:
index = indexes[0]
# If instance or Plugin
if index.data(Roles.TypeRole) in (
model.InstanceType, model.PluginType
pos_index = self.indexAt(event.pos())
# If instance or Plugin and is selected
if (
index == pos_index
and index.data(Roles.TypeRole) == model.PluginType
):
if event.pos().x() < 20:
self.toggled.emit(index, None)
elif event.pos().x() > self.width() - 20:
self.show_perspective.emit(index)
# Deselect all group labels
for index in indexes:
if index.data(Roles.TypeRole) == model.GroupType:
self.selectionModel().select(
index, QtCore.QItemSelectionModel.Deselect
)
return super(PluginView, self).mouseReleaseEvent(event)
return super(OverviewView, self).mouseReleaseEvent(event)
class InstanceView(OverviewView):
def __init__(self, parent=None):
super(InstanceView, self).__init__(parent)
self.viewport().setMouseTracking(True)
def mouseMoveEvent(self, event):
index = self.indexAt(event.pos())
if index.data(Roles.TypeRole) == model.GroupType:
self.update(index)
super(InstanceView, self).mouseMoveEvent(event)
def item_expand(self, index, expand=None):
if expand is None:
expand = not self.isExpanded(index)
if expand:
self.expand(index)
else:
self.collapse(index)
def group_toggle(self, index):
model = index.model()
chilren_indexes_checked = []
chilren_indexes_unchecked = []
for idx in range(model.rowCount(index)):
child_index = model.index(idx, 0, index)
if not child_index.data(Roles.IsEnabledRole):
continue
if child_index.data(QtCore.Qt.CheckStateRole):
chilren_indexes_checked.append(child_index)
else:
chilren_indexes_unchecked.append(child_index)
if chilren_indexes_checked:
to_change_indexes = chilren_indexes_checked
new_state = False
else:
to_change_indexes = chilren_indexes_unchecked
new_state = True
for index in to_change_indexes:
model.setData(index, new_state, QtCore.Qt.CheckStateRole)
self.toggled.emit(index, new_state)
def mouseReleaseEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
indexes = self.selectionModel().selectedIndexes()
if len(indexes) == 1:
index = indexes[0]
pos_index = self.indexAt(event.pos())
if index == pos_index:
# If instance or Plugin
if index.data(Roles.TypeRole) == model.InstanceType:
if event.pos().x() < 20:
self.toggled.emit(index, None)
elif event.pos().x() > self.width() - 20:
self.show_perspective.emit(index)
else:
if event.pos().x() < EXPANDER_WIDTH:
self.item_expand(index)
else:
self.group_toggle(index)
self.item_expand(index, True)
return super(InstanceView, self).mouseReleaseEvent(event)
class TerminalView(QtWidgets.QTreeView):

View file

@ -160,14 +160,14 @@ class Window(QtWidgets.QDialog):
# TODO add parent
overview_page = QtWidgets.QWidget()
overview_instance_view = view.OverviewView(parent=overview_page)
overview_instance_view = view.InstanceView(parent=overview_page)
overview_instance_delegate = delegate.InstanceDelegate(
parent=overview_instance_view
)
overview_instance_view.setItemDelegate(overview_instance_delegate)
overview_instance_view.setModel(instance_model)
overview_plugin_view = view.OverviewView(parent=overview_page)
overview_plugin_view = view.PluginView(parent=overview_page)
overview_plugin_delegate = delegate.PluginDelegate(
parent=overview_plugin_view
)

View file

@ -3,8 +3,7 @@ import sys
import platform
from avalon import style
from Qt import QtCore, QtGui, QtWidgets, QtSvg
from pype.resources import get_resource
from pype.api import config, Logger
from pype.api import config, Logger, resources
class TrayManager:
@ -37,9 +36,15 @@ class TrayManager:
self.modules_usage = {}
self.log.critical("Couldn't find modules usage data.")
self.icon_run = QtGui.QIcon(get_resource("circle_green.png"))
self.icon_stay = QtGui.QIcon(get_resource("circle_orange.png"))
self.icon_failed = QtGui.QIcon(get_resource("circle_red.png"))
self.icon_run = QtGui.QIcon(
resources.get_resource("icons", "circle_green.png")
)
self.icon_stay = QtGui.QIcon(
resources.get_resource("icons", "circle_orange.png")
)
self.icon_failed = QtGui.QIcon(
resources.get_resource("icons", "circle_red.png")
)
def process_presets(self):
"""Add modules to tray by presets.
@ -354,12 +359,7 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
:type parent: QtWidgets.QMainWindow
"""
def __init__(self, parent):
if os.getenv("PYPE_DEV"):
icon_file_name = "icon_dev.png"
else:
icon_file_name = "icon.png"
self.icon = QtGui.QIcon(get_resource(icon_file_name))
self.icon = QtGui.QIcon(resources.pype_icon_filepath())
QtWidgets.QSystemTrayIcon.__init__(self, self.icon, parent)
@ -423,7 +423,7 @@ class TrayMainWindow(QtWidgets.QMainWindow):
self.trayIcon.show()
def set_working_widget(self):
image_file = get_resource('working.svg')
image_file = resources.get_resource("icons", "working.svg")
img_pix = QtGui.QPixmap(image_file)
if image_file.endswith('.svg'):
widget = QtSvg.QSvgWidget(image_file)
@ -513,11 +513,7 @@ class PypeTrayApplication(QtWidgets.QApplication):
splash_widget.hide()
def set_splash(self):
if os.getenv("PYPE_DEV"):
splash_file_name = "splash_dev.png"
else:
splash_file_name = "splash.png"
splash_pix = QtGui.QPixmap(get_resource(splash_file_name))
splash_pix = QtGui.QPixmap(resources.pype_splash_filepath())
splash = QtWidgets.QSplashScreen(splash_pix)
splash.setMask(splash_pix.mask())
splash.setEnabled(False)