Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'read.': 0.03; 'url:launchpad': 0.05; 'column': 0.07; 'error:': 0.07; 'table.': 0.07; 'lines:': 0.09; 'self.data': 0.09; 'runs': 0.10; 'gui': 0.12; '23,': 0.16; 'added.': 0.16; 'columns': 0.16; 'first:': 0.16; 'from:addr:swing.be': 0.16; 'from:addr:vincent.vandevyvre': 0.16; 'from:name:vincent vande vyvre': 0.16; 'item)': 0.16; 'message-id:@swing.be': 0.16; 'oqapy': 0.16; 'paqager': 0.16; 'received:mobistar.be': 0.16; 'run:': 0.16; 'skip:q 50': 0.16; 'url:oqapy': 0.16; 'url:paqager': 0.16; 'url:qarte': 0.16; 'v.v.': 0.16; '\xe9crit': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'have:': 0.19; 'replacing': 0.19; 'written': 0.21; 'portion': 0.22; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'entries': 0.24; 'replace': 0.24; 'file.': 0.24; 'changes,': 0.26; 'compare': 0.26; 'post': 0.26; 'gets': 0.27; 'header:In-Reply- To:1': 0.27; 'idea': 0.28; 'point': 0.28; 'chris': 0.29; 'code': 0.31; 'anyone': 0.31; 'table': 0.34; 'problem': 0.35; 'display': 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'done.': 0.35; 'entry': 0.36; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'tips': 0.61; 'new': 0.61; 'first': 0.61; 'real': 0.63; 'saving': 0.69; 'sara': 0.84; '2013': 0.98 Date: Wed, 24 Apr 2013 20:51:04 +0200 From: Vincent Vande Vyvre User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: python-list@python.org Subject: Re: QTableWidget updating columns in a single row References: <1a87f00d-636d-4795-80d5-7bf196d1177f@googlegroups.com> <5c8ead62-ebc8-429c-a531-9592a958983d@googlegroups.com> In-Reply-To: <5c8ead62-ebc8-429c-a531-9592a958983d@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366829923 news.xs4all.nl 15965 [2001:888:2000:d::a6]:45382 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44283 Le 24/04/2013 19:12, Sara Lochtie a écrit : > On Tuesday, April 23, 2013 11:22:29 PM UTC-7, Sara Lochtie wrote: >> I have written a GUI that gets data sent to it in real time and this data is displayed in a table. Every time data is sent in it is displayed in the table in a new row. My problem is that I would like to have the data just replace the old in the first row. >> >> >> >> The table has 6 columns (A, B, C, D, E, F) I want the new data to continue replacing the old data in the same row unless the data that goes under column A changes, at which point a new row would be added. >> >> >> >> Does anyone have tips on how to approach this? I can post a portion of my code to get a better idea of what I have done. > So that is where I am stuck. I don't how to compare them and I am trying to avoiding saving the data to a file. > > This is the code that I have: > > > > > > if msg.arg2() != ERROR: > entry = (A, B, C, D, E, F) > self.data.append(entry) > > data = self.data > > # Display how many runs occurred > self.statusBar().showMessage('Data read. %s Run(s) Occurred.' % self.runCount) > > # Populates table by adding only new entries to the end of the table > lastRow = self.table.rowCount() > self.table.setRowCount(len(data)) > for entryPos in range(lastRow, len(data)): > for fieldPos in range(6): > item = QtGui.QTableWidgetItem(str(data[entryPos][fieldPos])) > self.table.setItem(entryPos, fieldPos, item) > self.table.resizeColumnsToContents() > self.table.horizontalHeader().setStretchLastSection(True) > self.currentRunLabel.setText('Current Run: ' + str(self.runCount)) > self.currentLineLabel.setText('Number of lines: ' + str(len(self.data))) > print('End of %s. run: %s. entries found' % (self.runCount, len(self.data))) As sayed by Chris "Kwpolska", you can compare the new data with the data of the first row. Something like that: # Get the content of row 0, column A first = str(self.table.item(0, 0).text()) for entryPos in range(lastRow, len(data)): if str(data[entryPos][0]) == first: self.update_first_row(data[entryPos]) else: self.add_new_row(data[entryPos]) -- Vincent V.V. Oqapy . Qarte . PaQager