def _get_print_viewport_bounds(self): info = omu.MGraphEditorInfo() leftSu = om.MScriptUtil(0.0) leftPtr = leftSu.asDoublePtr() rightSu = om.MScriptUtil(0.0) rightPtr = rightSu.asDoublePtr() bottomSu = om.MScriptUtil(0.0) bottomPtr = bottomSu.asDoublePtr() topSu = om.MScriptUtil(0.0) topPtr = topSu.asDoublePtr() info.getViewportBounds(leftPtr, rightPtr, bottomPtr, topPtr) frame_left = om.MScriptUtil(leftPtr).asDouble() frame_right = om.MScriptUtil(rightPtr).asDouble() value_buttom = om.MScriptUtil(bottomPtr).asDouble() value_top = om.MScriptUtil(topPtr).asDouble() return frame_left, frame_right, value_buttom, value_top
def paintEvent(self, paint_event): parent = self.parentWidget() if parent: # --------------------------------------------------------------- # # Basic frame geometry stuff self.setGeometry(parent.geometry()) frame_width = self.ge_widget.frameSize().width() frame_height = self.ge_widget.frameSize().height() # Get initial frame range of GE panel # Taken from the maya docs for MGraphEditorInfo() leftSu = om.MScriptUtil(0.0) leftPtr = leftSu.asDoublePtr() rightSu = om.MScriptUtil(0.0) rightPtr = rightSu.asDoublePtr() bottomSu = om.MScriptUtil(0.0) bottomPtr = bottomSu.asDoublePtr() topSu = om.MScriptUtil(0.0) topPtr = topSu.asDoublePtr() omui.MGraphEditorInfo().getViewportBounds(leftPtr, rightPtr, bottomPtr, topPtr) ge_left_frame = om.MScriptUtil(leftPtr).asDouble() ge_right_frame = om.MScriptUtil(rightPtr).asDouble() # Distance in numbers of frames visible in the widget total_visible_frames = ge_right_frame - ge_left_frame # It floats! # --------------------------------------------------------------- # # Painter widgets painter = QtGui.QPainter(self) fill_color = QtGui.QColor(*self.active_color) fill_color.setAlpha(self.alpha) pen = painter.pen() pen.setWidth(1) highlight_color = \ [self._clamp(x + 10, 0, 255) for x in self.active_color] pen_color = QtGui.QColor(*highlight_color) pen_color.setAlpha(self._clamp(self.alpha * 2, 0, 255)) pen.setColor(pen_color) painter.setPen(pen) for frame_group in list(self._group(self.frame_times)): # Start frame calculated against the width of the frame ratio_left_side = (frame_group[0] - ge_left_frame)\ / total_visible_frames left_side_geometry = ratio_left_side * frame_width # End frame calculated against the width of the frame ratio_right_side = (frame_group[-1] - ge_left_frame + 1)\ / total_visible_frames right_side_geometry = ratio_right_side * frame_width painter.fillRect( left_side_geometry, 0, # From the top right_side_geometry - left_side_geometry, frame_height, # To the bottom fill_color) painter.drawRect( left_side_geometry, -1, # Watch out for stroke thickness right_side_geometry - left_side_geometry, frame_height + 2)