花了两周读这个模块,终于把结构理清楚了,当然新功能也搞定了,搜索条件更宽松,可以找到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()

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

  1. Hiero中的Events机制

    The hiero.core.events module allows you to register method callbacks to respond to events sent by Hi ...

  2. 第三十篇:SOUI模块结构图及SOUI框架图

    模块结构图: SOUI框架图:

  3. 隐藏进程中的模块绕过IceSword的检测

    标 题: [原创] 隐藏进程中的模块绕过IceSword的检测 作 者: xPLK 时 间: 2008-06-19,17:59:11 链 接: http://bbs.pediy.com/showthr ...

  4. 浅析JS中的模块规范(CommonJS,AMD,CMD)////////////////////////zzzzzz

    浅析JS中的模块规范(CommonJS,AMD,CMD)   如果你听过js模块化这个东西,那么你就应该听过或CommonJS或AMD甚至是CMD这些规范咯,我也听过,但之前也真的是听听而已.     ...

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

    centos 7中python-pip模块不存在,是因为像centos这类衍生的发行版,源跟新滞后,或者不存在.即使使用yum去search python-pip也找不到软件包. 为了使用安装滞后或源 ...

  6. Nodejs中cluster模块的多进程共享数据问题

    Nodejs中cluster模块的多进程共享数据问题 前述 nodejs在v0.6.x之后增加了一个模块cluster用于实现多进程,利用child_process模块来创建和管理进程,增加程序在多核 ...

  7. Python中optionParser模块的使用方法[转]

    本文以实例形式较为详尽的讲述了Python中optionParser模块的使用方法,对于深入学习Python有很好的借鉴价值.分享给大家供大家参考之用.具体分析如下: 一般来说,Python中有两个内 ...

  8. python中threading模块详解(一)

    python中threading模块详解(一) 来源 http://blog.chinaunix.net/uid-27571599-id-3484048.html threading提供了一个比thr ...

  9. Python中的模块与包

    标准库的安装路径 在import模块的时候,python是通过系统路径找到这些模块的,我们可以将这些路径打印出来: >>> pprint.pprint(sys.path) ['', ...

随机推荐

  1. SQL注入之Sqli-labs系列第二十六关(过滤空格、注释符、逻辑运算符注入)和第二十六A

    开始挑战第二十六关(Trick with comments and space) 0x1看看源代码 (1)过滤了#  or and  /**/  /  \ ,通过判断也过滤了空格 (2)这样一来只能看 ...

  2. Spring Boot 揭秘与实战(九) 应用监控篇 - 自定义监控端点

    文章目录 1. 继承 AbstractEndpoint 抽象类 2. 创建端点配置类 3. 运行 4. 源代码 Spring Boot 提供的端点不能满足我们的业务需求时,我们可以自定义一个端点. 本 ...

  3. POJ3070 Fibonacci(矩阵快速幂加速递推)【模板题】

    题目链接:传送门 题目大意: 求斐波那契数列第n项F(n). (F(0) = 0, F(1) = 1, 0 ≤ n ≤ 109) 思路: 用矩阵乘法加速递推. 算法竞赛进阶指南的模板: #includ ...

  4. MVC分别代表的含义

    MVC 是一种将应用程序的逻辑层和表现层进行分离的方法.ThinkPHP 也是基于MVC设计模式的.MVC只是一个抽象的概念,并没有特别明确的规定,ThinkPHP中的MVC分层大致体现在:模型(M) ...

  5. Liunx----vi编辑器

    关于vi编辑器基本的用法总结如下: vi是linux下的一款文编编辑器. 进入vi的方法:在系统启动起来后,直接键入vi或vi 文件名: 进去后输入内容方法:输入a或i,切换到编辑模式: 退出编辑模式 ...

  6. React中的Context——从父组件传递数据

    简介:在React中,数据可以以流的形式自上而下的传递,每当你使用一个组件的时候,你可以看到组件的props属性会自上而下的传递.但是,在某些情况下,我们不想通过父组件的props属性一级一级的往下传 ...

  7. linux杀死进程方法

    方法一: 根据pid ps -aux|grep 你的进程 方法二: 删除pid文件 [root@localhost ~]# /etc/init.d/redis_6380 start /var/run/ ...

  8. MySQL在登陆时出现ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)错误

    错误显示:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 解决方案: 1.找到配 ...

  9. Cassandra基础2

    ========================================================= gossip协议1.点对点(peer to perr)的网络通信协议,节点间地位相同 ...

  10. lerna import && add 使用&&常见问题解决

    使用lerna 的import 我们可以方便的将一个普通的npm 包倒入到lerna 管理的monorepo 中 环境准备 lerna init 注意必须是一个git 项目,同时需要commit ,不 ...