[PyQt] file dialog as input to io.read.array in scipy
massimo di stefano
massimodisasha at yahoo.it
Mon Oct 29 02:52:53 GMT 2007
Apologize me for a little sintax error in the previouse post , i
corrected it to :
Il giorno 29/ott/07, alle ore 03:28, massimo di stefano ha scritto:
> hi,
>
> i'm tring to write a gui for a python module,
>
>
> the module run fine in the python shall.
>
> i'm using it in this manner :
>
> from affine import affine
> print affine('/path/tu/file_1', '/path/tu/file_2', '/path/tu/
> file_3', '/path/tu/file_4')
>
>
>
>
> the module affine is like :
>
> #!/usr/bin/env python
> from scipy import io, linalg
> from numpy import *
> from pylab import save
> def affine(input_uno, input_due, input_tre, output):
> L = io.read_array(input_uno)
> M = io.read_array(input_due)
> N = io.read_array(input_tre)
> O = io.read_array(output)
>
>
>
this module is just an example, it is not the complete module
i'm using this beacouse the error is about the function io.read_array()
this can be used as test to reproduce my error.
>
> the gui code is :
>
>
> #!/usr/bin/env python
>
> """PyQt4 port of the dialogs/standarddialogs example from Qt v4.x"""
>
> import sys
> from PyQt4 import QtCore, QtGui
> from affine import affine
> from conforme import conforme
>
>
>
> class Dialog(QtGui.QDialog):
> MESSAGE = QtCore.QT_TR_NOOP("<p>Message boxes have a caption, a
> text, and up to "
> "three buttons, each with standard
> or custom texts.</p>"
> "<p>Click a button or press Esc.</p>")
>
> def __init__(self, parent=None):
> QtGui.QDialog.__init__(self, parent)
> self.openFilesPath = QtCore.QString()
> self.errorMessageDialog = QtGui.QErrorMessage(self)
>
> frameStyle = QtGui.QFrame.Sunken | QtGui.QFrame.Panel
>
>
>
> self.exit = QtGui.QPushButton("Exit", self)
>
> self.exit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
>
> self.connect(self.exit, QtCore.SIGNAL("clicked()"),
> QtGui.qApp, QtCore.SLOT("quit()"))
>
>
> self.convert = QtGui.QPushButton("Convert", self)
>
> self.convert.setFont(QtGui.QFont("Times", 18,
> QtGui.QFont.Bold))
>
> self.connect(self.convert, QtCore.SIGNAL("clicked()"),
> self.saveFunction)
>
> self.affineRadioButton = QtGui.QRadioButton(self.tr("Affine"))
> self.conformeRadioButton = QtGui.QRadioButton(self.tr
> ("Conforme"))
>
> self.openFileNameLabel = QtGui.QLabel()
> self.openFileNameLabel.setFrameStyle(frameStyle)
> self.openFileNameButton = QtGui.QPushButton(self.tr
> ("file_datum_1"))
> self.connect(self.openFileNameButton, QtCore.SIGNAL("clicked
> ()"), self.setOpenFileName)
>
> self.openFileNameLabel_2 = QtGui.QLabel()
> self.openFileNameLabel_2.setFrameStyle(frameStyle)
> self.openFileNameButton_2 = QtGui.QPushButton(self.tr
> ("file_datum_2"))
> self.connect(self.openFileNameButton_2, QtCore.SIGNAL
> ("clicked()"), self.setOpenFileName_2)
>
> self.openFileNameLabel_3 = QtGui.QLabel()
> self.openFileNameLabel_3.setFrameStyle(frameStyle)
> self.openFileNameButton_3 = QtGui.QPushButton(self.tr
> ("file_datum_3"))
> self.connect(self.openFileNameButton_3, QtCore.SIGNAL
> ("clicked()"), self.setOpenFileName_3)
>
> self.saveFileNameLabel = QtGui.QLabel()
> self.saveFileNameLabel.setFrameStyle(frameStyle)
> self.saveFileNameButton = QtGui.QPushButton(self.tr
> ("file_to_save"))
> self.connect(self.saveFileNameButton, QtCore.SIGNAL("clicked
> ()"), self.setSaveFileName)
>
> layout = QtGui.QGridLayout()
> layout.setColumnStretch(1, 1)
> layout.setColumnMinimumWidth(1, 250)
>
> layout.addWidget(self.openFileNameButton, 1, 0)
> layout.addWidget(self.openFileNameLabel, 1, 1)
> layout.addWidget(self.openFileNameButton_2, 2, 0)
> layout.addWidget(self.openFileNameLabel_2, 2, 1)
> layout.addWidget(self.openFileNameButton_3, 3, 0)
> layout.addWidget(self.openFileNameLabel_3, 3, 1)
> layout.addWidget(self.saveFileNameButton, 4, 0)
> layout.addWidget(self.saveFileNameLabel, 4, 1)
> layout.addWidget(self.exit, 5, 0)
> layout.addWidget(self.exit, 5, 1)
> layout.addWidget(self.convert, 6, 0)
> layout.addWidget(self.convert, 6, 1)
> layout.addWidget(self.affineRadioButton, 7, 0)
> layout.addWidget(self.conformeRadioButton, 8, 0)
>
> self.setLayout(layout)
> self.setWindowTitle(self.tr("DATUM CONVERTER"))
>
>
> def saveFunction(self):
> my_file_1=QtCore.QFile(self.openFileNameLabel.text())
> my_file_2=QtCore.QFile(self.openFileNameLabel.text())
> my_file_3=QtCore.QFile(self.openFileNameLabel.text())
> my_file_4=QtCore.QFile(self.saveFileNameLabel.text())
> # print my_file_1,self.openFileNameLabel_2.text
> (),self.openFileNameLabel_3.text(),self.saveFileNameLabel.text()
> print affine(my_file_1, my_file_2, my_file_3, my_file_4)
>
>
> def setOpenFileName_3(self):
> fileName_3 = QtGui.QFileDialog.getOpenFileName(self,
> self.tr("file_datum_3"),
> self.openFileNameLabel_3.text(),
> self.tr("ALL Files (*);;Text Files (*.txt)"))
> if not fileName_3.isEmpty():
> self.openFileNameLabel_3.setText(fileName_3)
>
>
>
>
> def setOpenFileName(self):
> fileName = QtGui.QFileDialog.getOpenFileName(self,
> self.tr("file_datum_1"),
> self.openFileNameLabel.text(),
> self.tr("All Files (*);;Text Files (*.txt)"))
> if not fileName.isEmpty():
> self.openFileNameLabel.setText(fileName)
>
>
> def setOpenFileName_2(self):
> fileName_2 = QtGui.QFileDialog.getOpenFileName(self,
> self.tr("file_datum_2"),
> self.openFileNameLabel_2.text(),
> self.tr("ALL Files (*);;Text Files (*.txt)"))
> if not fileName_2.isEmpty():
> self.openFileNameLabel_2.setText(fileName_2)
>
> def setSaveFileName(self):
> fileName = QtGui.QFileDialog.getSaveFileName(self,
> self.tr("file_to_save"),
> self.saveFileNameLabel.text(),
> self.tr("All Files (*);;Text Files (*.txt)"))
> if not fileName.isEmpty():
> self.saveFileNameLabel.setText(fileName)
>
> if __name__ == '__main__':
> app = QtGui.QApplication(sys.argv)
> dialog = Dialog()
> sys.exit(dialog.exec_())
>
>
>
> but i've this error :
>
> Error in sys.excepthook:
> Traceback (most recent call last):
> File "/Applications/TextMate.app/Contents/SharedSupport/Bundles/
> Python.tmbundle/Support/PyMate/sitecustomize.py", line 66, in
> tm_excepthook
> io = fdopen(error_fd, 'w')
> OSError: [Errno 9] Bad file descriptor
>
> Original exception was:
> Traceback (most recent call last):
> File "/Users/epifanio/Desktop/pyconvertgui.py", line 94, in
> saveFunction
> print affineg(my_file_1, my_file_2, my_file_3, my_file_4)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/tring.py", line 7, in tring
> L = io.read_array(input_uno)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/scipy/io/array_import.py", line 363, in
> read_array
> ascii_object = ascii_stream(fileobject, lines=lines,
> comment=comment, linesep=linesep)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/scipy/io/array_import.py", line 142, in
> __init__
> self._pos = self.file.tell()
> AttributeError: tell
>
>
> seems that io.read_array fail to load my files :-(
>
> maybe it want an object file as input, but the gui pass it the
> input as a string ... but i have not clue about.
>
> thanks for all the qt peole that help me on irc,
and for
> any suggestion abot my error !
if you want try to execute it,
le me know, i can upload the files to the list.
>
> massimo.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20071029/0396630a/attachment-0001.html
More information about the PyQt
mailing list