Skip to content

Commit

Permalink
Batch of fixes for filters, matchers, and actions. (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcipriano committed Feb 24, 2020
1 parent 3877834 commit f347994
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/



package com.imageworks.spcue.servant;

import io.grpc.stub.StreamObserver;
Expand All @@ -42,7 +41,11 @@ public class ManageAction extends ActionInterfaceGrpc.ActionInterfaceImplBase {

@Override
public void delete(ActionDeleteRequest request, StreamObserver<ActionDeleteResponse> responseObserver) {
filterManager.deleteAction(ActionEntity.build(request.getAction()));
Action requestAction = request.getAction();
ActionEntity existingAction = filterManager.getAction(requestAction.getId());
FilterEntity filterEntity = filterManager.getFilter(existingAction);
ActionEntity actionToDelete = ActionEntity.build(filterEntity, requestAction, requestAction.getId());
filterManager.deleteAction(actionToDelete);
responseObserver.onNext(ActionDeleteResponse.newBuilder().build());
responseObserver.onCompleted();
}
Expand All @@ -58,8 +61,8 @@ public void getParentFilter(ActionGetParentFilterRequest request,
@Override
public void commit(ActionCommitRequest request, StreamObserver<ActionCommitResponse> responseObserver) {
Action requestAction = request.getAction();
ActionEntity requestEntity = ActionEntity.build(requestAction);
FilterEntity filterEntity = filterManager.getFilter(requestEntity);
ActionEntity existingAction = filterManager.getAction(requestAction.getId());
FilterEntity filterEntity = filterManager.getFilter(existingAction);
ActionEntity newAction = ActionEntity.build(filterEntity, requestAction, requestAction.getId());
filterManager.updateAction(newAction);
responseObserver.onNext(ActionCommitResponse.newBuilder().build());
Expand Down
4 changes: 2 additions & 2 deletions cuegui/cuegui/AbstractWidgetItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __lt__(self, other):
column = self.treeWidget().sortColumn()
if sortLambda:
try:
return sortLambda(self.rpcObject) > sortLambda(other.rpcObject)
return sortLambda(self.rpcObject) < sortLambda(other.rpcObject)
except:
logger.warning("Sort failed on column {}, using text sort.".format(column))
return str(self.text(column)) > str(other.text(column))
return str(self.text(column)) < str(other.text(column))
78 changes: 36 additions & 42 deletions cuegui/cuegui/FilterDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@

from builtins import map
from builtins import str
import re

from PySide2 import QtCore
from PySide2 import QtGui
from PySide2 import QtWidgets

import opencue
from opencue.compiled_proto.filter_pb2 import ActionType
from opencue.compiled_proto.filter_pb2 import FilterType
from opencue.compiled_proto.filter_pb2 import MatchSubject
from opencue.compiled_proto.filter_pb2 import MatchType
import opencue.compiled_proto.filter_pb2

import cuegui.AbstractTreeWidget
import cuegui.AbstractWidgetItem
Expand All @@ -47,12 +43,12 @@

logger = cuegui.Logger.getLogger(__file__)

MATCHSUBJECT = MatchSubject.keys()
MATCHSUBJECT = opencue.compiled_proto.filter_pb2.MatchSubject.keys()
DEFAULT_MATCHSUBJECT = MATCHSUBJECT.index('SHOT')
MATCHTYPE = MatchType.keys()
MATCHTYPE = opencue.compiled_proto.filter_pb2.MatchType.keys()
DEFAULT_MATCHTYPE = MATCHTYPE.index('IS')
ACTIONTYPE = ActionType.keys()
FILTERTYPE = FilterType.keys()
ACTIONTYPE = opencue.compiled_proto.filter_pb2.ActionType.keys()
FILTERTYPE = opencue.compiled_proto.filter_pb2.FilterType.keys()
PAUSETYPE = ["Pause", "Unpause"]
MEMOPTTYPE = ["Enabled", "Disabled"]

Expand Down Expand Up @@ -159,10 +155,10 @@ def _createItem(self, object):
"""Creates and returns the proper item"""
return FilterWidgetItem(object, self)

def _update(self):
def _processUpdate(self, work, rpcObjects):
"""Adds the feature of forcing the items to be sorted by the first
column"""
cuegui.AbstractTreeWidget.AbstractTreeWidget._update(self)
cuegui.AbstractTreeWidget.AbstractTreeWidget._processUpdate(self, work, rpcObjects)
self.sortByColumn(0, QtCore.Qt.AscendingOrder)

def _getUpdate(self):
Expand Down Expand Up @@ -233,14 +229,14 @@ def _getUpdate(self):
return []

def __getMatcherSubjectDialog(self):
return QtWidgets.QInputDialog.getItem(self, "Create Matcher",
"Please select the type of item to match",
MatchSubject.keys(), DEFAULT_MATCHSUBJECT, False)
return QtWidgets.QInputDialog.getItem(
self, "Create Matcher", "Please select the type of item to match",
opencue.compiled_proto.filter_pb2.MatchSubject.keys(), DEFAULT_MATCHSUBJECT, False)

def __getMatcherTypeDialog(self):
return QtWidgets.QInputDialog.getItem(self, "Create Matcher",
"Please select the type of match to perform",
MatchSubject.keys(), DEFAULT_MATCHTYPE, False)
return QtWidgets.QInputDialog.getItem(
self, "Create Matcher", "Please select the type of match to perform",
opencue.compiled_proto.filter_pb2.MatchType.keys(), DEFAULT_MATCHTYPE, False)

def createMatcher(self):
"""Prompts the user to create a new Matcher"""
Expand Down Expand Up @@ -309,7 +305,7 @@ def __bulkAddMatchers(self, title, deleteExisting):
if not dialog.exec_():
return

shots = self.__parseShotList(dialog.results().toAscii())
shots = self.__parseShotList(dialog.results())

if not shots:
return
Expand All @@ -324,9 +320,10 @@ def __bulkAddMatchers(self, title, deleteExisting):
oldMatchers = []

for shot in shots:
self.__filter.createMatcher(getattr(MatchSubject, str(matchSubject)),
getattr(MatchType, str(matchType)),
shot)
self.__filter.createMatcher(
opencue.compiled_proto.filter_pb2.MatchSubject.Value(matchSubject),
opencue.compiled_proto.filter_pb2.MatchType.Value(matchType),
shot)
if deleteExisting:
for matcher in oldMatchers:
matcher.delete()
Expand All @@ -341,7 +338,7 @@ class ActionMonitorTree(cuegui.AbstractTreeWidget.AbstractTreeWidget):
def __init__(self, show, filter, parent):
self.startColumnsForType(cuegui.Constants.TYPE_ACTION)
self.addColumn("Action Type", 210, id=1,
data=lambda action:(addSpaces(str(action.type()))))
data=lambda action:(opencue.compiled_proto.filter_pb2.ActionType.Name(action.type())))
self.addColumn("", 180, id=2)
self.addColumn("", 20, id=3)

Expand Down Expand Up @@ -394,8 +391,7 @@ def createAction(self):
"""Prompts the user to create a new action"""
if self.__filter:
(actionType, choice) = QtWidgets.QInputDialog.getItem(
self, "Create Action", "Please select the type of action to add:",
[addSpaces(action) for action in ACTIONTYPE], 0, False)
self, "Create Action", "Please select the type of action to add:", ACTIONTYPE, 0, False)
if choice:
value = None
actionType = getattr(opencue.api.filter_pb2, str(actionType).replace(" ", ""))
Expand Down Expand Up @@ -518,8 +514,8 @@ def update(self, object = None, parent = None):
cuegui.AbstractWidgetItem.AbstractWidgetItem.update(self, object, parent)
self.updateWidgets()

def setType(self, text):
self.rpcObject.setType(getattr(opencue.api.filter_pb2, str(text)))
def setType(self, filterType):
self.rpcObject.setType(filterType)

def setEnabled(self, value):
self.rpcObject.setEnabled(bool(value))
Expand Down Expand Up @@ -551,7 +547,7 @@ def updateWidgets(self):
combo.currentIndexChanged.connect(self.setType)
self.__widgets["type"] = combo

self.__widgets["type"].setCurrentIndex(FILTERTYPE.index(str(self.rpcObject.type())))
self.__widgets["type"].setCurrentIndex(self.rpcObject.type())
if self.rpcObject.isEnabled():
state = QtCore.Qt.Checked
else:
Expand All @@ -570,11 +566,11 @@ def update(self, object = None, parent = None):
cuegui.AbstractWidgetItem.AbstractWidgetItem.update(self, object, parent)
self.updateWidgets()

def setType(self, text):
self.rpcObject.setType(getattr(opencue.api.filter_pb2, str(text)))
def setType(self, matcherType):
self.rpcObject.setType(matcherType)

def setSubject(self, text):
self.rpcObject.setSubject(getattr(opencue.api.filter_pb2, str(text)))
def setSubject(self, matcherSubject):
self.rpcObject.setSubject(matcherSubject)

def setInput(self):
text = str(self.__widgets["input"].text())
Expand Down Expand Up @@ -621,8 +617,8 @@ def updateWidgets(self):
btn.clicked.connect(self.delete)
self.__widgets["delete"] = btn

self.__widgets["subject"].setCurrentIndex(MATCHSUBJECT.index(str(self.rpcObject.subject())))
self.__widgets["type"].setCurrentIndex(MATCHTYPE.index(str(self.rpcObject.type())))
self.__widgets["subject"].setCurrentIndex(self.rpcObject.subject())
self.__widgets["type"].setCurrentIndex(self.rpcObject.type())
# Only update input if user is not currently editing the value
if not self.__widgets["input"].hasFocus() or \
not self.__widgets["input"].isModified():
Expand Down Expand Up @@ -676,9 +672,10 @@ def __setValue(self, value = None):
value = str(widget.text())

elif self.rpcObject.type() in (opencue.api.filter_pb2.MOVE_JOB_TO_GROUP,):
group = self.treeWidget().groupNames[str(value)]
if self.rpcObject.value() != group:
self.rpcObject.setTypeAndValue(self.rpcObject.type(), group)
groupName = list(self.treeWidget().groupNames.keys())[value]
group = self.treeWidget().groupNames[groupName]
if self.rpcObject.value() != group.id():
self.rpcObject.setTypeAndValue(self.rpcObject.type(), group.data)
return

elif self.rpcObject.type() in (opencue.api.filter_pb2.SET_MEMORY_OPTIMIZER,):
Expand Down Expand Up @@ -761,9 +758,9 @@ def updateWidgets(self):
self.__widgets["ActionValue"].setValue(float(str(self.rpcObject.value())))

elif self.rpcObject.type() in (opencue.api.filter_pb2.MOVE_JOB_TO_GROUP,):
name = self.treeWidget().groupIds[self.rpcObject.value()].name()
index = list(self.treeWidget().groupNames.keys()).index(name)
self.__widgets["ActionValue"].setCurrentIndex(index)
groupName = self.treeWidget().groupIds[self.rpcObject.value()].name()
listIndex = list(self.treeWidget().groupNames.keys()).index(groupName)
self.__widgets["ActionValue"].setCurrentIndex(listIndex)

elif self.rpcObject.type() in (opencue.api.filter_pb2.SET_MEMORY_OPTIMIZER,):
self.__widgets["ActionValue"].setCurrentIndex(int(not self.rpcObject.value()))
Expand Down Expand Up @@ -794,6 +791,3 @@ def __init__(self, parent):

def wheelEvent(self, event):
event.ignore()

def addSpaces(value):
return re.sub(r'([a-z]*)([A-Z])',r'\1 \2', value).strip()
4 changes: 2 additions & 2 deletions cuegui/cuegui/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ def isRootGroup(object):
"""Returns true if the object is a root, false if not
@return: If the object is a root group
@rtype: bool"""
return object.__class__.__name__ in ["NestedGroup", "Group"] and not object.parent
return object.__class__.__name__ in ["NestedGroup", "Group"] and not object.hasParent()


def isGroup(object):
"""Returns true if the object is a group, false if not
@return: If the object is a group
@rtype: bool"""
return object.__class__.__name__ in ["NestedGroup", "Group"] and (not hasattr(object, "parent") or object.parent)
return object.__class__.__name__ in ["NestedGroup", "Group"] and object.hasParent()


def isHost(object):
Expand Down
12 changes: 7 additions & 5 deletions pycue/opencue/wrappers/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
from opencue.compiled_proto.filter_pb2 import MatchSubject
from opencue.compiled_proto.filter_pb2 import MatchType
from opencue.compiled_proto.filter_pb2 import Matcher as MatcherData
import opencue.wrappers.group


__all__ = ["Filter", "Action", "Matcher",
"FilterData", "ActionData", "MatcherData",
Expand Down Expand Up @@ -96,9 +98,9 @@ def createAction(self, actionType, value):
boolean_value=False
)

if isinstance(value, job_pb2.Group):
if isinstance(value, opencue.wrappers.group.Group):
action.value_type = filter_pb2.GROUP_TYPE
action.group_value = value.id
action.group_value = value.id()
elif isinstance(value, str):
action.value_type = filter_pb2.STRING_TYPE
action.string_value = value
Expand Down Expand Up @@ -271,9 +273,9 @@ def isNew(self):

def name(self):
if self.value() is None:
return "%s" % self.type()
return "%s" % ActionType.Name(self.type())
else:
return "%s %s" % (self.type(), self.value())
return "%s %s" % (ActionType.Name(self.type()), self.value())

def value(self):
valueType = self.data.value_type
Expand Down Expand Up @@ -385,7 +387,7 @@ def isNew(self):
return self.data is None

def name(self):
return "%s %s %s" % (self.data.subject, self.data.type, self.data.input)
return "%s %s %s" % (MatchSubject.Name(self.data.subject), MatchType.Name(self.data.type), self.data.input)

def subject(self):
return self.data.subject
Expand Down
8 changes: 8 additions & 0 deletions pycue/opencue/wrappers/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ def pendingJobs(self):
:return: total number of running jobs"""
return self.data.group_stats.pending_jobs

def hasParent(self):
"""Whether this Group/NestedGroup has a parent group.
:rtype: bool
:return: whether the group has a parent
"""
return self.data.HasField('parent')


class NestedGroup(Group):
"""This class contains information and actions related to a nested group."""
Expand Down
5 changes: 2 additions & 3 deletions pycue/tests/wrappers/filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,11 @@ def testName(self, getStubMock):
actionInt = opencue.wrappers.filter.Action(filter_pb2.Action(
id=TEST_ACTION_ID, type=filter_pb2.PAUSE_JOB, value_type=filter_pb2.INTEGER_TYPE,
integer_value=22))
expected = "1 22"
self.assertEqual(actionInt.name(), expected)
self.assertEqual(actionInt.name(), "PAUSE_JOB 22")

actionNone = opencue.wrappers.filter.Action(filter_pb2.Action(
id=TEST_ACTION_ID, type=filter_pb2.PAUSE_JOB, value_type=filter_pb2.NONE_TYPE))
self.assertEqual(actionNone.name(), str(actionNone.type()))
self.assertEqual(actionNone.name(), "PAUSE_JOB")

def testValue(self, getStubMock):
groupValue = 'testGroup'
Expand Down

0 comments on commit f347994

Please sign in to comment.