我想运行一个脚本,该脚本从PYQT中的函数获取目录。现在它被设置为使用sys.argv并希望它被调用,如
directory = createeditconvertorpage.selectFilecsvtoxml()
script1.py
directory = sys.argv[1]
print str(directory) + "this si string of directory"
def Main():
pyqtwindow.py
class createedditConvertorpage(QtGui.QMainWindow):
def __init__(self,parent = None):
QtGui.QWidget.__init__(self, parent)
def selectFilecsvtoxml(self):
directoryPath = QtGui.QFileDialog.getExistingDirectory(self, caption="Pick a folder", directory=QtCore.QDir.currentPath())
self.listDirPath.setText(directoryPath)
for file_name in os.listdir(directoryPath):
if not file_name.startswith("."):
print (file_name) + " this is selectFilcestoxml"
return directoryPath
def convertDirectory(self):
import longXmlEditor
longXmlEditor.Main()
答案 0 :(得分:1)
class createedditConvertorpage(QtGui.QMainWindow):
def __init__(self,parent = None):
QtGui.QWidget.__init__(self, parent)
@staticmethod
def browseFilecsvtoxml():
directoryPath = QtGui.QFileDialog.getExistingDirectory(caption="Pick a folder", directory=QtCore.QDir.currentPath())
return directoryPath
def selectFilecsvtoxml(self):
directoryPath = self.browseFilecsvtoxml()
self.listDirPath.setText(directoryPath)
for file_name in os.listdir(directoryPath):
if not file_name.startswith("."):
print (file_name) + " this is selectFilcestoxml"
return directoryPath
def convertDirectory(self):
import longXmlEditor
longXmlEditor.Main()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
dirpath = createedditConvertorpage.browseFilecsvtoxml()
print dirpath
sys.exit(app.exec_())
希望这个帮助,我只是在主要内部调用,但你也可以从另一个脚本调用。确保你有QApplication,因为它使用的是QtGui。否则它会失败。