2

我正在开发一个 Python 脚本,它将在名为 QtiPlot 的应用程序中运行。我搜索了 Qtiplot 的 Python API 文档,它使用 PyQt 4。我将脚本编码如下:

#! /usr/bin/env python

# A python script to be used in QtiPlot to convert .dat files into .jpg graphs and these ones into .avi movie

import os
import re
import glob
from PyQt4 import uic
from PyQt4 import *

def chooseInputFolder():
    input_folder = QtGui.QFileDialog.getExistingDirectory(qti.app, "Choose Working Folder")
    ui.inputFolderLine.setText(input_folder)
    return input_folder

def chooseOutputFile():
    output_file = QtGui.QFileDialog.getSaveFileName(qti.app, "Choose Output File")
    ui.outputFileLine.setText(output_file)
    return output_file

def createVideoFromJPG():
    input_folder_name = ui.inputFolderLine.text()
    output_file_name = ui.outputFileLine.text()
    dirList = os.listdir(input_folder_name)
    for fname in dirList:
        t = newTable()
        t.importASCII(input_folder_name+fname,sep="\t",ignoreLines=0,renameCols=False,stripSpaces=True,simplifySpace=False,importComments=False,comment="#",readOnly=False,importAs=Table.Overwrite,locale=QLocale(),endLine=0,maxRows=-1)
#       g = plot(t, 2, 0)
#       cmd = 'mencoder "mf://*.jpg" -mf fps=25 -o %s -ovc lavc -lavcopts vcodec=mpeg4' % output_file
#       os.system(cmd)

ui = uic.loadUi("/home/kurumin/Scripts/python/dat2vid.ui")
ui.connect(ui.inputFolderButton, QtCore.SIGNAL("clicked()"),chooseInputFolder)
ui.connect(ui.outputFileButton, QtCore.SIGNAL("clicked()"),chooseOutputFile)
ui.connect(ui.createVideo, QtCore.SIGNAL("clicked()"),createVideoFromJPG)
ui.show()

这是输出:

Traceback (most recent call last):

File "<>", line 27, in createVideoFromJPG

NameError
: 
global name 'QLocale' is not defined

我试图定义 QLocale 但我在文档中找不到任何真正有用的东西。

4

1 回答 1

1

替换文件locale=QLocale()locale=QtGui.QLocale()27 行,因为from PyQt4 import *您必须提供模块名称..

于 2012-12-16T02:49:22.417 回答