kurianos

timeLine

Oct 26th, 2015
36
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from PyQt4 import QtGui, QtCore
  2. import maya.cmds as cmds
  3. import maya.OpenMayaUI as mui
  4. import sip
  5.  
  6. def convertToQT(controlName):
  7.     controlPoniter = mui.MQtUtil.findControl(controlName)
  8.     if controlPoniter is not None:
  9.         return sip.wrapinstance(long(controlPoniter), QtCore.QObject)
  10.  
  11. def getTimeline():
  12.     qtTimeline = convertToQT("timeControl1")
  13.     return qtTimeline
  14.  
  15. def getTimelineRange():
  16.     r = cmds.timeControl("timeControl1", query=True, ra=True)
  17.     return range(int(r[0]), int(r[1]))
  18.  
  19. class Markers(QtGui.QWidget):
  20.     def __init__(self, timeline=getTimeline()):
  21.         super(Markers, self).__init__(timeline)
  22.         layout = timeline.layout()
  23.         if not layout:
  24.             layout = QtGui.QVBoxLayout(timeline)
  25.             layout.setContentsMargins(0, 0, 0, 0)
  26.             timeline.setLayout(layout)
  27.         else:
  28.             for child in timeline.children():
  29.                 if child.objectName() == "timelineMarkers":
  30.                     child.deleteLater()
  31.         layout.addWidget(self)
  32.         self.setObjectName("timelineMarkers")
  33.         self.start  = None
  34.         self.end    = None
  35.         self.total  = None
  36.         self.step   = None
  37.         self.frames = []
  38.         self.colors = []
  39.         self.update()
  40.  
  41.     def paintEvent(self, event):
  42.         self.draw()
  43.  
  44.     def add(self):
  45.         color=[255, 0, 0]
  46.         for f in getTimelineRange():
  47.             if not f in self.frames:
  48.                 self.frames.append(f)
  49.                 self.colors.append(color)
  50.             else:
  51.                 index = self.frames.index(f)
  52.                 self.colors[index]   = color
  53.         self.update()
  54.  
  55.     def draw( self ):
  56.         self.start = cmds.playbackOptions(query=True, min=True)
  57.         self.end   = cmds.playbackOptions(query=True, max=True)
  58.         self.total = self.width()
  59.         self.step  = (self.total - (self.total * 0.01)) / (self.end - self.start + 1)
  60.         if not self.frames or not self.colors:
  61.             return
  62.         painter = QtGui.QPainter(self)
  63.         pen = QtGui.QPen()
  64.         pen.setWidth(self.step)
  65.         for f, c in zip(self.frames, self.colors):
  66.             pen.setColor(QtGui.QColor(255, 0, 0))
  67.             pos  = (f - self.start + 0.5) * self.step + (self.total * 0.005)
  68.             line = QtCore.QLineF(QtCore.QPointF(pos, 0), QtCore.QPointF(pos, 100))
  69.             painter.setPen(pen)
  70.             painter.drawLine(line)
  71.            
  72. def addMark():
  73.     global markers
  74.     markers=Markers()
  75.     markers.add()
  76. addMark()
RAW Paste Data