Note that there are some explanatory texts on larger screens.

plurals
  1. POPopulating a table in PyQt with file attributes
    primarykey
    data
    text
    <p>I'm trying to populate a QTableWidget with the attributes of a file opened elsewhere in the script. I've successfully set the file attributes read in from the file using the following code:</p> <pre><code>class FileHeader(object): fileheader_fields=( "filetype","fileversion","numframes", "framerate","resolution","numbeams", "samplerate","samplesperchannel","receivergain", "windowstart","winlengthsindex","reverse", "serialnumber","date","idstring","ID1","ID2", "ID3","ID4","framestart","frameend","timelapse", "recordInterval","radioseconds","frameinterval","userassigned") fileheader_formats=( 'S3','B','i4','i4','i4','i4','f','i4','i4','i4', 'i4','i4','i4','S32','S256','i4','i4','i4','i4', 'i4','i4','i4','i4','i4','i4','S136') IMAGE_HEADER_BYTES = 256 IMAGES_DATA_BYTES = 49152 def __init__(self,filename=''): self.filename = filename if filename: self.setFile(filename) else: # initialize our attributes to None for field in self.fileheader_fields: setattr(self,field,None) def setFile(self, f): self.infile=open(f, 'rb') dtype=dict(names=self.fileheader_fields, formats=self.fileheader_formats) self.fileheader=np.fromfile(self.infile, dtype=dtype, count=1) self.fileheader_length=self.infile.tell() for field in self.fileheader_fields: setattr(self,field,self.fileheader[field]) </code></pre> <p>I've used this code to populate the table but I keep getting a "FileHeader has no attribute fileheader" error.</p> <pre><code>from fileheader import FileHeader, Frame from echogram import QEchogram from PyQt4.QtGui import * from PyQt4.QtCore import * import os, sys class MainWindow(QWidget): def __init__(self, parent=None): self.fileheader_fields=FileHeader.fileheader_fields self.fileheader_values=FileHeader.fileheader[field] self.fileheader={field: "value of" + field for field in self.fileheader_fields} super(MainWindow, self).__init__(parent) self.fileheader_table=QTableWidget() layout=QVBoxLayout() layout.addWidget(self.fileheader_table) self.setLayout(layout) self.populate def populate(self): self.fileheader_table.setRowCount(len(self.fileheader_fields)) self.fileheader_table.sestColumnCount(2) self.fileheader_table.setHorizontalHeaderLabels(['name','value']) for i,field in enumerate(self.fileheader_fields): name=QTableWidgetItem(field) value=QTableWidgetItem(self.fileheader[field]) self.fileheader_table.setItem(i,0,name) self.fileheader_table.setItem(i,1,value) if __name__=="__main__": app=QApplication(sys.argv) filename=str(QFileDialog.getOpenFileName(None,"open file","C:/vprice/DIDSON/DIDSON Data","*.ddf")) wnd=MainWindow() wnd.resize(640,480) wnd.show() #echoGram=QEchogram() #echoGram.initFromFile(filename) #fileName="test.png" #echoGram.processEchogram() #dataH=echoGram.data #print "Horizontal data", dataH </code></pre> <p>Bear with me-- I just started with all of the Python stuff about a month ago... </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload