Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44246 > unrolled thread
| Started by | Sara Lochtie <sara.lochtie@gmail.com> |
|---|---|
| First post | 2013-04-23 23:22 -0700 |
| Last post | 2013-04-26 12:14 -0700 |
| Articles | 6 — 3 participants |
Back to article view | Back to comp.lang.python
QTableWidget updating columns in a single row Sara Lochtie <sara.lochtie@gmail.com> - 2013-04-23 23:22 -0700
Re: QTableWidget updating columns in a single row Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-04-24 09:58 +0200
Re: QTableWidget updating columns in a single row Sara Lochtie <sara.lochtie@gmail.com> - 2013-04-24 10:12 -0700
Re: QTableWidget updating columns in a single row Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-04-24 19:57 +0200
Re: QTableWidget updating columns in a single row Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2013-04-24 20:51 +0200
Re: QTableWidget updating columns in a single row Sara Lochtie <sara.lochtie@gmail.com> - 2013-04-26 12:14 -0700
| From | Sara Lochtie <sara.lochtie@gmail.com> |
|---|---|
| Date | 2013-04-23 23:22 -0700 |
| Subject | QTableWidget updating columns in a single row |
| Message-ID | <1a87f00d-636d-4795-80d5-7bf196d1177f@googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | Chris “Kwpolska” Warrick <kwpolska@gmail.com> |
|---|---|
| Date | 2013-04-24 09:58 +0200 |
| Message-ID | <mailman.1012.1366790338.3114.python-list@python.org> |
| In reply to | #44246 |
On Wed, Apr 24, 2013 at 8:22 AM, Sara Lochtie <sara.lochtie@gmail.com> 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. > > > -- > http://mail.python.org/mailman/listinfo/python-list My suggestion: compare the new data’s column A with the existing data (store a copy of the old data somewhere?). If it differs, add a new row; if it doesn’t, change an existing one. If you need help with the exact implementation, show the *entire* code. -- Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html
[toc] | [prev] | [next] | [standalone]
| From | Sara Lochtie <sara.lochtie@gmail.com> |
|---|---|
| Date | 2013-04-24 10:12 -0700 |
| Message-ID | <5c8ead62-ebc8-429c-a531-9592a958983d@googlegroups.com> |
| In reply to | #44246 |
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)))
[toc] | [prev] | [next] | [standalone]
| From | Chris “Kwpolska” Warrick <kwpolska@gmail.com> |
|---|---|
| Date | 2013-04-24 19:57 +0200 |
| Message-ID | <mailman.1028.1366826275.3114.python-list@python.org> |
| In reply to | #44273 |
On Wed, Apr 24, 2013 at 7:12 PM, Sara Lochtie <sara.lochtie@gmail.com> wrote: > 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. To a file? Just store it in a class attribute and you will be fine. You have it in self.data already. Unless that structure doesn’t work, then “mirror” your table in a Python array. (alternatively, you could query QTableWidgetItem.text() for every existing item, but that’s crazy.) -- Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html
[toc] | [prev] | [next] | [standalone]
| From | Vincent Vande Vyvre <vincent.vandevyvre@swing.be> |
|---|---|
| Date | 2013-04-24 20:51 +0200 |
| Message-ID | <mailman.1030.1366829923.3114.python-list@python.org> |
| In reply to | #44273 |
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 <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
[toc] | [prev] | [next] | [standalone]
| From | Sara Lochtie <sara.lochtie@gmail.com> |
|---|---|
| Date | 2013-04-26 12:14 -0700 |
| Message-ID | <2eebd06b-67d8-47ef-b297-5ed866f98582@googlegroups.com> |
| In reply to | #44283 |
On Wednesday, April 24, 2013 11:51:04 AM UTC-7, Vincent Vande Vyvre wrote:
Thanks. I think I should be able to figure out from here. I appreciate all of the help!
> 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 <https://launchpad.net/oqapy> . Qarte
>
> <https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web