之前博客提到了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()

Hiero中修改BinView中binitem对象名字的方法的更多相关文章

  1. 备忘:MySQL中修改表中某列的数据类型、删除外键约束

    -- MySQL中修改表中某列的数据类型 ALTER TABLE [COLUMN] 表名 MODIFY 列名 列定义; -- 删除外键约束 SHOW CREATE TABLE 表名; -- 复制CON ...

  2. 织梦dedecms中修改标题与简略标题长度的方法

    本文介绍了dedecms中修改标题与简略标题长度的方法,进入dedecms后台,系统——系统基本参数——其他选项——文档标题最大长度——在这修改为200或更大. 一.修改标题 进入dedecms后台, ...

  3. mutation中修改state中的状态值,却报[vuex] do not mutate vuex store state outside mutation handlers.

    网上百度说是在mutation外修改state中的状态值,会报下列错误,可我明明在mutations中修改的状态值,还是报错 接着百度,看到和我类似的问题,说mutations中只能用同步代码,异步用 ...

  4. Oracle中删除用户下所有对象的多种方法

      Oracle删除用户下所有对象的方法未必人人都会,下面就为您介绍两种常用的Oracle删除用户下所有对象的方法,希望对您学习Oracle删除用户方面能有所帮助. 方法1: drop user XX ...

  5. 在 Xcode中 修改文件中自动创建的Created by和Copyright

    在Xcode里创建的时候,会自动生成注释 //  Created byxxx on 15/7/10. //  Copyright (c) 2015年 xxxx. All rights reserved ...

  6. 在Intellij IDEA中修改模板中user变量名称

    在Intellij IDEA中的注释模板中的${user}名称是根据当前操作系统的登录名来取的,有时候登录名称和我们实际的user名称并不相同. 修改方法如下: 方法一:可以在settings的fil ...

  7. actionMode-theme中修改actionmode中more下拉框的背景颜色

    今天在做图库修改是,需要修改图库的actionbar某个按钮弹出来的下拉框的背景颜色,在网上找了个方法尝试下,没有打到自己的要求,不过阴差阳错的却修改了more下拉框的背景,再次记录下,也许以后能用的 ...

  8. 在springMVC的controller中获取request,response对象的一个方法

    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttr ...

  9. Javaweb项目中修改表单时数据回显方法

    1.前言 先来说下什么是数据回显,比如我要修改我的个人信息,点击修改按钮后进入修改界面,在这个界面中直接将原来的信息显示在表单中,而不是空表单,这就是数据回显 2.思路 当点击修改的时候,从数据库中查 ...

随机推荐

  1. SQL注入之Sqli-labs系列第五关和第六关(基于GET型的报错注入)

    废话不在多说  let's go! 开始挑战第五关(Double Query- Single Quotes- String) 和第六关(Double Query- Double Quotes- Str ...

  2. 转:C++ 类的静态成员详细讲解

    在C++中,静态成员是属于整个类的而不是某个对象,静态成员变量只存储一份供所有对象共用.所以在所有对象中都可以共享它.使用静态成员变量实现多个对象之间的数据共享不会破坏隐藏的原则,保证了安全性还可以节 ...

  3. 【leetcode】283. Move Zeroes

    problem 283. Move Zeroes solution 先把非零元素移到数组前面,其余补零即可. class Solution { public: void moveZeroes(vect ...

  4. WEBBASE篇: 第三篇, CSS知识1

    第三篇, CSS知识1 一,CSS 介绍 CSS: Cascading Style Sheets ---样式表 HTML: 搭建网页结构: CSS: 在网页结构基础上进行网页的美化: 二,CSS的使用 ...

  5. Atcode ABC105-C:Base -2 Number

    C - Base -2 Number Time Limit: 2 sec / Memory Limit: 1024 MB Score : 300300 points Problem Statement ...

  6. 启动tomcat报错:Failed to start component [StandardEngine[Catalina].StandardHost[localhost]

    1.右键点击需要启动的tomcat,选择Clean和Clean Tomcat Work Directory,清除即可!

  7. (20)jQuery的文档操作(创建,添加、设置样式和删除等)

    <!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>jq ...

  8. 《DSP using MATLAB》Problem 6.7

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  9. LeetCode - Diameter of Binary Tree

    Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a b ...

  10. Js 字符串拼接的两种方法

    字符串拼接的两种方法 用数组的方法的好处是:避免变量重新定义.赋值 <!DOCTYPE html> <html lang="en"> <head> ...