QTableWidget效率

时间:2017-08-17 19:39:23

标签: python csv pyqt5

我使用下面的代码来读取和呈现一个大型CSV文件(2002行包含大量数据)。这是我到目前为止的代码,它的工作原理。但是,并不像我想的那么快。在我的Mac上,应用程序变为“无响应”,并且在加载数据之前我被困在彩虹轮上一段时间。有什么办法可以让这段代码更有效率吗?

class OpenCSV(QtWidgets.QTableWidget): 
    def __init__(self, r, c):
        super().__init__(r, c)
        self.check_change = True
        self.init_ui()

    def init_ui(self):
        self.cellChanged.connect(self.c_current)
        self.show()

    def c_current(self):
        if self.check_change:
            row = self.currentRow()                    
            row = self.rowCount()
            value = self.emails(row,col)
            value = value.text()
            print("The email in the box is: ", value)

    def open_sheet(self):        
        self.check_change = False
        path = QtWidgets.QFileDialog.getOpenFileName(self,'Open File',os.getenv('Home'), 'CSV(*.csv)')
        if path [0] != '':
            with open(path[0],'rU') as csv_file:
                self.setRowCount(0)
                self.setColumnCount(1)
                load_file = csv.reader(csv_file, delimiter=',')
                for emails in load_file:
                    row = self.rowCount()                    
                    emails = re.findall(r'[\w_]+@[\w_]+\.[\w_]+', open(path[0]).read())                    
                    self.insertRow(row)
                    for row, stuff in enumerate(emails):
                        item = QtWidgets.QTableWidgetItem(stuff)
                        self.setItem(row, 1, item)
        self.check_change = True 

0 个答案:

没有答案