• Hiero中修改BinView中binitem对象名字的方法


    之前博客提到了scan for more version这样一个功能,该功能会放宽查询条件,这就会导致BinItem的名称与activeVersion的名称不符。这篇博客提供了一个方法去统一名称。

    该方法直接修改xml工程并关闭hiero,重新打开的时候就会发现binitem对象的名称全部都修改成当前activeversion的名称了,因为需要重启一下hiero,所以该功能还显得不完善,想要改善这个功能还需要好好学习PySide。

    代码如下:

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

    import hiero.core
    import xml.dom.minidom as xml
    import re
    import hiero.core
    from PySide.QtGui import *
    from PySide.QtCore import *

    class fixname_MenuAction:

        def __init__(self):

            self._binViewActionAddNoteToClipSequence = self.createMenuAction("Correct Name (VHQ)", self.Modify_XML)
            #add a events when left click the item
            hiero.core.events.registerInterest("kShowContextMenu/kBin", self.eventHandler)

        #This function is using to get the items from objects
        def get_item_list(self):
            list_a = [];list_A = [];indexlist = [];
            for item in hiero.core.projects()[-1].clipsBin().items():
                if isinstance(item,hiero.core.BinItem):
                    list_a.append(item.activeItem().name())
                else:
                    [list_a.append(items.activeItem().name()) for items in item.items()]
            for item in list_a:
                if re.match('(w+)(_[vV]d+)',item):
                    list_A.append(re.match('(w+)(_[vV]d+)',item).group(1))
                else:
                    list_A.append(item)
            return list_A

        
        #This function is using to get the items from xml
        def get_xml_list(self):
            #second way to get item rootname
            context = self.get_xml_context()
            list_b = [item.getAttribute('name') for item in context.getElementsByTagName('SequenceProjectItemRoot')]
            return list_b


        #This function is using to get the context of xml file
        def get_xml_context(self):
            xmlfile = xml.parse(hiero.core.projects()[-1].path())
            context = xmlfile.documentElement
            return context


        #This function is using to get the difference item's index in project
        def find_difference(self):
            indexlist = []
            list_A = self.get_item_list()
            list_B = self.get_xml_list()
            #Try to compare two list
            for i in range(len(list_A)):
                if list_A[i] != list_B[i]:
                    indexlist.append(i)
            return indexlist



        #This function is using to modify the xml file
        def Modify_XML(self):
            import sys
            reload(sys)
            sys.setdefaultencoding('utf-8')


            #save the project
            hiero.core.projects()[-1].save()
        
            #get parameter
            indexlist = self.find_difference()
        
            xmlfile = xml.parse(hiero.core.projects()[-1].path())
            context = xmlfile.documentElement
        
            #modify xml
            for index in indexlist:
                targetvalue = self.get_item_list()[index]
                print context.getElementsByTagName('SequenceProjectItemRoot')[index].getAttribute('name')
                context.getElementsByTagName('SequenceProjectItemRoot')[index].setAttribute('name',targetvalue)
                print context.getElementsByTagName('SequenceProjectItemRoot')[index].getAttribute('name')


            xmldata = open(hiero.core.projects()[-1].path(),'wb')
            #xmlrecode = codecs.lookup('utf-8')[3](xmldata)
            
            #xmlfile.writexml(xmlrecode,encoding = 'utf-8')
            
            #xmlfile.unlink()
            xmldata.write(xmlfile.toxml())
            xmldata.close()
        
            sys.setdefaultencoding('ASCII')
            hiero.core.quit()

            #del sys,xml,re,hiero.core



        def createMenuAction(self, title, method):
            action = QAction(title,None)
            action.triggered.connect( method )
            return action



        def eventHandler(self, event):
            self._binViewActionAddNoteToClipSequence.setEnabled(True)
            event.menu.addAction(self._binViewActionAddNoteToClipSequence)


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

  • 相关阅读:
    链式编程思想
    iOS开发:后台运行以及保持程序在后台长时间运行
    iOS懒加载
    mysql命令行的一些小技巧【实用:多屏显示,格式化输出等】
    iOS UITextField实时监听获取输入内容,中文状态去除预输入拼音字符
    'vector' file not found错误解决 && xcode archive 去掉dsym文件和添加dsym文件
    iOS APP 中H5视频默认全屏播放问题解决
    Sublime Text 3 插件的安装、升级和卸载,以及安装package control 出现问题解决过程记录
    ES5和ES6对象导出和导入(转载,待整理)
    react/React Native 在 import 导入时,有的带花括号{},有的不带原理解析
  • 原文地址:https://www.cnblogs.com/hksac/p/4868040.html
Copyright © 2020-2023  润新知