Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major Fix from branches [0008, 0014, 0018, 0019, 0020] #25

Merged
merged 14 commits into from
May 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions capture_gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ class PreviewWidget(QtWidgets.QWidget):
preview_width = 320
preview_height = 180

def __init__(self, options_getter, validater, parent=None):
def __init__(self, options_getter, validator, parent=None):
QtWidgets.QWidget.__init__(self, parent=parent)

# Add attributes
self.initialized = False
self.options_getter = options_getter
self.validater = validater
self.validator = validator
self.preview = ClickLabel()
self.preview.setFixedWidth(self.preview_width)
self.preview.setFixedHeight(self.preview_height)
Expand Down Expand Up @@ -71,8 +71,8 @@ def refresh(self):
cmds.currentTime(frame, update=True)

# check if plugin outputs are correct
validation = self.validater()
if not validation:
valid = self.validator()
if not valid:
return

with lib.no_undo():
Expand Down Expand Up @@ -374,6 +374,8 @@ def apply(self):
return

options = self.get_outputs()
if options["frame"] is not None:
options["raw_frame_numbers"] = True
filename = options.get("filename", None)

self.playblast_start.emit(options)
Expand Down Expand Up @@ -483,7 +485,6 @@ def get_outputs(self):
continue

for key, value in widget_outputs.items():
print key, value

# We merge dictionaries by updating them so we have
# the "mixed" values of both settings
Expand Down
102 changes: 96 additions & 6 deletions capture_gui/plugins/timeplugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import logging
import re

import maya.OpenMaya as om
from capture_gui.vendor.Qt import QtCore, QtWidgets
Expand All @@ -20,6 +21,7 @@ class TimePlugin(capture_gui.plugin.Plugin):
RangeTimeSlider = "Time Slider"
RangeStartEnd = "Start/End"
CurrentFrame = "CurrentFrame"
CustomFrames = "Custom Frames"

def __init__(self, parent=None):
super(TimePlugin, self).__init__(parent=parent)
Expand All @@ -33,16 +35,27 @@ def __init__(self, parent=None):
self.mode = QtWidgets.QComboBox()
self.mode.addItems([self.RangeTimeSlider,
self.RangeStartEnd,
self.CurrentFrame])
self.CurrentFrame,
self.CustomFrames])

frame_input_height = 20
self.start = QtWidgets.QSpinBox()
self.start.setRange(-sys.maxint, sys.maxint)
self.start.setFixedHeight(frame_input_height)
self.end = QtWidgets.QSpinBox()
self.end.setRange(-sys.maxint, sys.maxint)
self.end.setFixedHeight(frame_input_height)

# unique frames field
self.custom_frames = QtWidgets.QLineEdit()
self.custom_frames.setPlaceholderText("1-20,25;50;75,100-150")
self.custom_frames.setVisible(False)
self.custom_frames.setFixedHeight(frame_input_height)

self._layout.addWidget(self.mode)
self._layout.addWidget(self.start)
self._layout.addWidget(self.end)
self._layout.addWidget(self.custom_frames)

# Connect callbacks to ensure start is never higher then end
# and the end is never lower than start
Expand All @@ -61,6 +74,56 @@ def _ensure_start(self, value):
def _ensure_end(self, value):
self.end.setValue(max(self.end.value(), value))

def parse_frames(self, string):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's take this method out of the class and turn it into a function so the logic stays separate, especially because it's not using anything from the instance. It's only a simple algorithm.

"""Parse the resulting frames list from a frame list string.

Examples
>>> parse_frames("0-3;30")
[0, 1, 2, 3, 30]
>>> parse_frames("0,2,4,-10")
[0, 2, 4, -10]
>>> parse_frames("-10--5,-2")
[-10, -9, -8, -7, -6, -5, -2]

Args:
string (str): The string to parse for frames.

Returns:
list: A list of frames

"""

result = list()
for raw in re.split(";|,", string):

# Skip empty elements
value = raw.strip().replace(" ", "")
if not value:
if raw:
log.warning("Empty frame entry: '{0}'".format(raw))
continue

# Check for sequences (1-20) including negatives (-10--8)
sequence = re.search("(-?[0-9]+)-(-?[0-9]+)", value)

# Sequence
if sequence:
start, end = sequence.groups()
frames = range(int(start), int(end) + 1)
result.extend(frames)

# Single frame
else:
try:
frame = int(value)
except ValueError:
log.warning(
"Invalid frame description: '{0}'".format(value))
continue
result.append(frame)

return result

def on_mode_changed(self, emit=True):
"""
Update the GUI when the user updated the time range or settings
Expand All @@ -76,16 +139,31 @@ def on_mode_changed(self, emit=True):
start, end = capture_gui.lib.get_time_slider_range()
self.start.setEnabled(False)
self.end.setEnabled(False)
self.start.setVisible(True)
self.end.setVisible(True)
self.custom_frames.setVisible(False)
mode_values = int(start), int(end)
elif mode == self.RangeStartEnd:
self.start.setEnabled(True)
self.end.setEnabled(True)
self.start.setVisible(True)
self.end.setVisible(True)
self.custom_frames.setVisible(False)
mode_values = self.start.value(), self.end.value()

elif mode == self.CustomFrames:
self.start.setVisible(False)
self.end.setVisible(False)
self.custom_frames.setVisible(True)
mode_values = self.custom_frames.text()
else:
self.start.setEnabled(False)
self.end.setEnabled(False)
mode_values = "({})".format(
int(capture_gui.lib.get_current_frame()))
self.start.setVisible(True)
self.end.setVisible(True)
self.custom_frames.setVisible(False)
currentframe = int(capture_gui.lib.get_current_frame())
mode_values = "({})".format(currentframe)

# Update label
self.label = "Time Range {}".format(mode_values)
Expand All @@ -97,12 +175,15 @@ def on_mode_changed(self, emit=True):
def get_outputs(self, panel=""):
"""
Get the options of the Time Widget
:param panel:
:param panel: name of the panel
:type panel: str

:return: the settings in a dictionary
:rtype: dict
"""

mode = self.mode.currentText()
frames = None

if mode == self.RangeTimeSlider:
start, end = capture_gui.lib.get_time_slider_range()
Expand All @@ -116,28 +197,37 @@ def get_outputs(self, panel=""):
start = frame
end = frame

elif mode == self.CustomFrames:
frames = self.parse_frames(self.custom_frames.text())
start = None
end = None
else:
raise NotImplementedError("Unsupported time range mode: "
"{0}".format(mode))

return {"start_frame": start,
"end_frame": end}
"end_frame": end,
"frame": frames}

def get_inputs(self, as_preset):
return {"time": self.mode.currentText(),
"start_frame": self.start.value(),
"end_frame": self.end.value()}
"end_frame": self.end.value(),
"frame": self.custom_frames.text()}

def apply_inputs(self, settings):
# get values
mode = self.mode.findText(settings.get("time", self.RangeTimeSlider))
startframe = settings.get("start_frame", 1)
endframe = settings.get("end_frame", 120)
custom_frames = settings.get("frame", None)

# set values
self.mode.setCurrentIndex(mode)
self.start.setValue(int(startframe))
self.end.setValue(int(endframe))
if custom_frames:
self.custom_frames.setText(custom_frames)

def initialize(self):
self._register_callbacks()
Expand Down