Hiero中versionscanner模块结构图

花了两周读这个模块,终于把结构理清楚了,当然新功能也搞定了,可以搜索条件更宽松,可以找到binitem对象中更多的版本,截图如下:

当然功能也做出来啦:

代码如下:

##########################################################################################################################################

# ScanForVersions is the action responsible for scanning for versions.
# This action is added to the BinView context menu.
# The code responsible for the scanning is located in hiero.core.VersionScanner

import hiero.core
import hiero.core.log
import VersionScanner_vhq
import hiero.ui
import PySide.QtGui
import PySide.QtCore

import foundry.ui
import threading
import time

class VersionScannerThreaded (object):
  ‘‘‘Class to run a threaded scan to discover additional versions for a set of versioned clips‘‘‘

_scanner = VersionScanner_vhq.VersionScanner_vhq()

def scanForVersions_vhq(self, versions, postScanFunc, shouldDisplayResults):
    ‘‘‘Scan for versions starting from the specified version
       @param versions - set of versions to scan. Note that the versions listed belong to different bin items
       @param postScanFunc - optional post scan update function
       @param shouldDisplayResults - Whether we should display how many versions were discovered‘‘‘

task = foundry.ui.ProgressTask("Finding Versions...")

# Rescan clip file ranges for all existing versions
    for version in versions:
      hiero.core.executeInMainThreadWithResult(self.rescanClipRanges, version)

# Find all the files to be added as versions
    numNewFiles = 0
    newVersionFiles = []
    numNewVersions = 0

# For each version find the additional files
    for version in versions:
      newFiles = self._scanner.findVersionFiles_vhq(version)
      newVersionFiles.append ( [ version, newFiles ] )
      numNewFiles += len(newFiles)

# Now create the clips for the additional files
    fileIndex = 0
    for versionFile in newVersionFiles:
      newClips = []

version, newFiles = versionFile

for newFile in newFiles:
        # If the user has hit cancel then drop out
        if task.isCancelled():
          return

fileIndex += 1
        task.setProgress(int(100.0*(float(fileIndex)/float(numNewFiles))))
        newClip = hiero.core.executeInMainThreadWithResult(self._scanner.createClip, newFile)
        
        # Filter out any invalid clips
        if newClip is not None:
          newClips.append(newClip)

versionFile.append ( newClips )

# Now create the additional versions from the clips and add them to the version list
    for versionFile in newVersionFiles:
      version  = versionFile[0]
      newClips = versionFile[2]

binitem = version.parent()

# Now add the clips as new versions
      newVersions = hiero.core.executeInMainThreadWithResult(self._scanner.insertClips, binitem, newClips)

hiero.core.log.info("InsertClips - Versions found for %s: %s", version, newVersions)

numNewVersions += len(newVersions)

# If we have a post scan function then run it (version up/down, min/max)
    if (postScanFunc is not None):
      oldClip = version.item()
      hiero.core.executeInMainThreadWithResult(postScanFunc)
      newClip = binitem.activeVersion().item()

# Then update any viewers looking at the old clip to the new clip
      hiero.core.executeInMainThreadWithResult(hiero.ui.updateViewer, oldClip, newClip)

# If we‘re supposed to display results then do so
    if (shouldDisplayResults):
      hiero.core.executeInMainThreadWithResult(self.displayResults, numNewVersions)

# Display results
  def displayResults(self, numNewVersions):
    msgBox = PySide.QtGui.QMessageBox()
    msgBox.setText("Found " + str(numNewVersions) + " new versions")
    msgBox.setStandardButtons(PySide.QtGui.QMessageBox.Ok)
    msgBox.setDefaultButton(PySide.QtGui.QMessageBox.Ok)
    msgBox.exec_()

# From an active version, iterates through all the siblings inside the BinItem
  def rescanClipRanges(self, activeVersion):
    binItem = activeVersion.parent()
    if binItem:
      for version in binItem.items():
        clip = version.item()
        if clip:
          clip.rescan()

# Helper class to call thread with a arbitrary number of arguments
class FuncThread(threading.Thread):
  def __init__(self, target, *args):
    self._target = target
    self._args = args
    threading.Thread.__init__(self)

def run(self):
    self._target(*self._args)

def ScanAndNextVersion(version):
  ‘‘‘Scan then move to next version‘‘‘
  binitem = version.parent()
  _DoScanForVersions([version], binitem.nextVersion, False)

def ScanAndPrevVersion(version):
  ‘‘‘ Scan then move to prev version‘‘‘
  binitem = version.parent()
  _DoScanForVersions([version], binitem.prevVersion, False)

def ScanAndMinVersion(version):
  ‘‘‘Scan then move to min version‘‘‘
  binitem = version.parent()
  _DoScanForVersions([version], binitem.minVersion, False)

def ScanAndMaxVersion(version):
  ‘‘‘Scan then move to max version‘‘‘
  binitem = version.parent()
  _DoScanForVersions([version], binitem.maxVersion, False)

def ScanAndNextVersionTrackItem(version, trackItem):
  ‘‘‘Scan then move to next version on the track item‘‘‘
  _DoScanForVersions([version], trackItem.nextVersion, False)

def ScanAndPrevVersionTrackItem(version, trackItem):
  ‘‘‘Scan then move to prev version on the track item‘‘‘
  _DoScanForVersions([version], trackItem.prevVersion, False)

def ScanAndMinVersionTrackItem(version, trackItem):
  ‘‘‘Scan then move to min version on the track item‘‘‘
  _DoScanForVersions([version], trackItem.minVersion, False)

def ScanAndMaxVersionTrackItem(version, trackItem):
  ‘‘‘Scan then move to max version on the track item‘‘‘
  _DoScanForVersions([version], trackItem.maxVersion, False)

# Create threaded scan using VersionScannerThreaded
def _DoScanForVersions(versions, postUpdateFunc, shouldDisplayResults):

scanner = VersionScannerThreaded()

thread = FuncThread(scanner.scanForVersions_vhq, versions, postUpdateFunc, shouldDisplayResults)
  thread.start()

# Action to scan for new versions
class ScanForVersionsAction(PySide.QtGui.QAction):

_scanner = hiero.core.VersionScanner.VersionScanner()

def __init__(self):
      PySide.QtGui.QAction.__init__(self, "Scan For More Versions (VHQ)", None)
      self.triggered.connect(self.doit)
      hiero.core.events.registerInterest((hiero.core.events.EventType.kShowContextMenu, hiero.core.events.EventType.kBin), self.eventHandler)
      hiero.core.events.registerInterest((hiero.core.events.EventType.kShowContextMenu, hiero.core.events.EventType.kTimeline), self.eventHandler)

def doit(self):
    # get the currently selected versions from UI
    versions = self.selectedVersions()

if len(versions) == 0:
      hiero.core.log.info( "No valid versions found in selection" )
      return

# For each version, do:
    # - rescan any versions already loaded to find the maximum available range
    # - run _scanner.doScan which returns added versions
    # - compute the total count of new versions.
    _DoScanForVersions(versions, None, True)

def eventHandler(self, event):

enabled = False
    if hasattr(event.sender, ‘selection‘):
      s = event.sender.selection()
      if len(s)>=1:
        enabled = True

# enable/disable the action each time
      if enabled:
        hiero.ui.insertMenuAction( self, event.menu, after="foundry.project.rescanClips" ) # Insert after ‘Version‘ sub-menu

# Get all selected active versions
  def selectedVersions(self):
    selection = hiero.ui.currentContextMenuView().selection()
    versions = []
    self.findActiveVersions(selection, versions)
    return (versions)

#
  def alreadyHaveVersion(self, findversion, versions):
    newFilename = findversion.item().mediaSource().fileinfos()[0].filename()
    for version in versions:
      thisFilename = version.item().mediaSource().fileinfos()[0].filename()
      if (newFilename == thisFilename):
        return True

return False

# Find all active versions in container and append to versions
  def findActiveVersions(self, container, versions):
    # Iterate through selection
    if isinstance(container, (list,tuple)):
      for i in container:
        self.findActiveVersions(i, versions)
    # Dive into Projects to find clipsBin (NB: not strictly needed at the moment, we get RootBins from BinView)
    elif isinstance(container, hiero.core.Project):
      self.findActiveVersions(container.clipsBin(), versions)
    # Dive into Bins to find BinItems
    elif isinstance(container, hiero.core.Bin):
      for i in container.items():
        self.findActiveVersions(i, versions)
    elif isinstance(container, hiero.core.TrackItem) and isinstance(container.source(), hiero.core.Clip):
      activeVersion = container.currentVersion()
      if activeVersion and not activeVersion.isNull():
        if not self.alreadyHaveVersion(activeVersion, versions):
        #if activeVersion not in versions:
          versions.append(activeVersion)
    # Dive into BinItem to retrieve active Version
    elif isinstance(container, hiero.core.BinItem) and isinstance(container.activeItem(), hiero.core.Clip):
      activeVersion = container.activeVersion()
      if activeVersion:
        if not self.alreadyHaveVersion(activeVersion, versions):
        #if activeVersion not in versions:
          versions.append(activeVersion)

# Instantiate the action to get it to register itself.
action = ScanForVersionsAction()

时间: 2024-11-04 12:53:50

Hiero中versionscanner模块结构图的相关文章

Node.js中的模块机制

本文为读书笔记. 一.CommonJS的模块规范 Node与浏览器以及 W3C组织.CommonJS组织.ECMAScript之间的关系 Node借鉴CommonJS的Modules规范实现了一套模块系统,所以先来看看CommonJS的模块规范. CommonJS对模块的定义十分简单,主要分为模块引用.模块定义和模块标识3个部分. 1. 模块引用 模块引用的示例代码如下: var math = require('math'); 在CommonJS规范中,存在require()方法,这个方法接受模

Python中time模块详解

在Python中,与时间处理有关的模块就包括:time,datetime以及calendar.这篇文章,主要讲解time模块. 在开始之前,首先要说明这几点: 在Python中,通常有这几种方式来表示时间:1)时间戳 2)格式化的时间字符串 3)元组(struct_time)共九个元素.由于Python的time模块实现主要调用C库,所以各个平台可能有所不同. UTC(Coordinated Universal Time,世界协调时)亦即格林威治天文时间,世界标准时间.在中国为UTC+8.DST

Yii2中的模块、应用程序(Module,Application)

原文地址:http://www.kuitao8.com/20140626/2715.shtml 模块(Module ) 模块是一个功能独立的逻辑单元,每一个模块都可以包含有多个子模块,但每个模块只能有一个对应的父模块(如果有的话).它的定义在yii\base\Module 应用程序(Application) Yii2中的应用程序有两种:web应用程序(yii\web\Application)和控制台应用程序(yii\console\Application).他们都继承于yii\base\Appl

Python中ConfigParser模块应用

Python中ConfigParser模块应用 Python的ConfigParser模块定义了3个对INI文件进行操作的类 RawConfigParser,ConfigParser和SafeConfigParser.其中RawCnfigParser是最基础的INI文件读取类,ConfigParser.SafeConfigParser支持对%(value)s变量的解析. 下面看看怎样通过ConfigParser类来解析一个ini文件. 配置文件settings.cfg [DEFAULT] myk

python中的模块安装

python中的模块研究: 需要用import导入的模块都是用python实现的. 内建的部分是用c.c++实现的. pypi:第三方的python包. 在windows上安装python: 1.安装python到C:\PythonXX,添加系统环境变量path:C:\PythonXX. 安装pypi库的方法三种方法: 1.在pypi上下载安装包离线安装 cd  $package-dir python   setup.py  install 在windos的cmd上也可以这样安装. 3.用eas

跟我一起学extjs5(13--执行菜单命令在tabPanel中显示模块)

跟我一起学extjs5(13--执行菜单命令在tabPanel中显示模块) 上面设计好了一个模块的主界面,下面通过菜单命令的执行来把这个模块加入到主界面当中.在MainModule.js中有一个函数,生成了当前的菜单数据: // 根据data.systemMenu生成菜单条和菜单按钮下面使用的菜单数据 getMenus : function() { var items = []; var menuData = this.get('systemMenu'); // 取得定义好的菜单数据 Ext.A

AMD:浏览器中的模块规范

为实现与Node.js相同方式的模块写法,大牛们做了很多努力.但浏览器环境不同于服务器端,它的模块有一个HTTP请求过程(而Node.js的模块文件就在本地),这个请求过程多数使用script tag,script 默认的异步性导致很难实现与Node.js一模一样的模块格式.Modules/Wrappings 使得实现变为现实.虽然和Node.js的模块写法不完全一致,但也有很多相似之处,使得熟悉Node.js的程序员有一些亲切感.但Node.js终究是服务器端的JavaScript,没有必要把

解决centos7中python-pip模块不存在的问题

centos 7中python-pip模块不存在,是因为像centos这类衍生的发行版,源跟新滞后,或者不存在.即使使用yum去search python-pip也找不到软件包. 为了使用安装滞后或源中不存在的安装包,需要安装扩展源EPEL.扩展源EPEL(http://fedoraproject.org/wiki/EPEL) 是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS.Scientific Linux 等提供高质量软件包的项目. 安装扩展源:sudo yum -y

python中threading模块详解(一)

python中threading模块详解(一) 来源 http://blog.chinaunix.net/uid-27571599-id-3484048.html threading提供了一个比thread模块更高层的API来提供线程的并发性.这些线程并发运行并共享内存. 下面来看threading模块的具体用法: 一.Thread的使用 目标函数可以实例化一个Thread对象,每个Thread对象代表着一个线程,可以通过start()方法,开始运行. 这里对使用多线程并发,和不适用多线程并发做