Closed will-hart closed 10 years ago
Implement processing messages. Fixes #43, Fixes #37
→ <<cset 7717c2462817>>
Original Comment By: Will Hart
Need to improve the list box. Something like this may be appropriate:
#!python
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore
from PyQt4 import QtGui
class MyRelationalDelegate(QtGui.QStyledItemDelegate):
def __init__(self, parent=None):
self.choices = {1: 'One', 2: 'Two', 3:'Three', 7: 'Seven'}
super(MyRelationalDelegate, self).__init__(parent)
def paint(self, painter, option, index):
styleOption = QtGui.QStyleOptionViewItemV4(option)
# define the text to be shown
text = self.choices[index.data(QtCore.Qt.DisplayRole).toInt()[0]] # value in choices dict corresponding to integer stored in tablewidget model
styleOption.text = text
# paint the cell
self.parent().style().drawControl(QtGui.QStyle.CE_ ItemViewItem, styleOption, painter)
def createEditor(self, parent, option, index):
combobox = QtGui.QComboBox(parent)
combobox.setEditable(True)
for c in sorted(self.choices.items()):
combobox.addItem(c[1], c[0]) # Add items to combobox, storing display text in DisplayRole and underlying value in UserRole
return combobox
def select_line_editor(self):
self.line_editor.setText("")
def setEditorData(self, editor, index):
pos = editor.findData(index.data().toInt()[0])
if pos == -1: #text not found, set cell value to first item in VALUES
pos = 0
editor.setCurrentIndex(pos)
def setModelData(self, editor, model, index):
model.setData(index, QtCore.QVariant(editor.itemData(editor.currentInde x()))) # editor.currentIndex es la posición actual en el combobox; itemData recupera (por default) la data UserRole almacenada allí, que en este caso es el valor del foreign key
class myWindow(QtGui.QDialog):
def __init__(self):
QtGui.QDialog.__init__(self)
DATA = [['First row', 1, 1], ['Second Row', 2, 2]]
self.table = QtGui.QTableWidget(self)
self.table.setSortingEnabled(False)
self.table.setRowCount(len(DATA))
self.table.setColumnCount(len(DATA[0]))
self.table.setItemDelegateForColumn(1, MyRelationalDelegate(self))
for row in range(len(DATA)):
for col in range(len(DATA[row])):
item = QtGui.QTableWidgetItem(str(DATA[row][col]))
self.table.setItem(row, col, item)
layout = QtGui.QVBoxLayout()
layout.addWidget(self.table)
self.setLayout(layout)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = myWindow()
window.show()
app.exec_()
Original Comment By: Will Hart
To reproduce: start / stop a logging session. Once it saves, open session list, click checkbox to download then immediately click the "Download" button. Mouse paused and then the exported CSV file was empty