Skip to main content
 首页 » 编程设计

python之QtiPlot 和 Python : global name 'QLocale' is not defined

2025年05月04日15jpfss

我正在开发一个 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,但在文档中找不到任何真正有用的内容。

请您参考如下方法:

将 locale=QLocale() 替换为文件 line 27 中的 locale=QtGui.QLocale(),因为 from PyQt4 import * 你必须提供模块名称..