wxPython check box not setting value - checkbox

So I have a wxPython window I've made that was working fine, until I tried to add a new check box to give the user an option for asymmetry.
import poser
import random
import wx
import wx.py
import wx.aui
scene = poser.Scene()
man = poser.WxAuiManager()
root = man.GetManagedWindow()
fig = scene.CurrentFigure()
allowAsymetric = False
paramList = []
lst = ["Full Body Morphs","All Head/Face", "Face Shape", "Forehead","Eyes", "Ear", "Nose", "Cheek", "Chin/Jaw", "Lips"]
# Our dialog box
class userInput(wx.Frame):
def __init__(self, parent) :
# Call the parent class initialisation method
wx.Frame.__init__(self, parent = parent, pos=wx.Point(675, 323), size=wx.Size(400, 400), style=wx.DEFAULT_FRAME_STYLE, title = "Random Hive")
global lst, allowAsymetric
# Set up the UI
#self.CenterOnScreen(wx.BOTH)
self.panel = wx.Panel(self,id=-1,size=(400,350))
self.panel.SetBackgroundColour("#4B4B4B")
# Checklist
self.lb = wx.CheckListBox(self.panel, -1, (20, 20), (350,200), lst)
#Select All Button
self.SelectALL = wx.Button(self.panel,id=100,pos=(20,260),size=(-1,- 1),label="Select All")
self.SelectALL.SetBackgroundColour("#5D5D5D")
self.SelectALL.SetForegroundColour("#CBCBCB")
self.SelectALL.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseOver)
self.SelectALL.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
self.Bind(wx.EVT_BUTTON, self.OnSelectALL, self.SelectALL)
#Select None Button
self.SelectNONE = wx.Button(self.panel,id=110,pos=(150,260),size=(-1,- 1),label="Select None")
self.SelectNONE.SetBackgroundColour("#5D5D5D")
self.SelectNONE.SetForegroundColour("#CBCBCB")
self.SelectNONE.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseOver)
self.SelectNONE.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
self.Bind(wx.EVT_BUTTON, self.OnSelectNONE, self.SelectNONE)
#Inversion Button
self.SelectINVERT = wx.Button(self.panel,id=120,pos=(275,260),size=(- 1,-1),label="Invert Selection")
self.SelectINVERT.SetBackgroundColour("#5D5D5D")
self.SelectINVERT.SetForegroundColour("#CBCBCB")
self.SelectINVERT.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseOver)
self.SelectINVERT.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
self.Bind(wx.EVT_BUTTON, self.OnSelectINVERT, self.SelectINVERT)
# Cancel button
self.Cancel = wx.Button(self.panel,id=140,pos=(20,310),size=(-1,-1),label="Close")
self.Cancel.SetBackgroundColour("#5D5D5D")
self.Cancel.SetForegroundColour("#CBCBCB")
self.Cancel.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseOver)
self.Cancel.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
self.Cancel.Bind(wx.EVT_BUTTON, self.OnSelectCancel, self.Cancel)
# Ok button
self.OK = wx.Button(self.panel,id=150, pos=(275,310),size=(-1,-1),label="Apply")
self.OK.SetDefault()
self.OK.SetBackgroundColour("#5D5D5D")
self.OK.SetForegroundColour("#CBCBCB")
self.OK.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseOver)
self.OK.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
self.Bind(wx.EVT_BUTTON, self.OnSelectOK, self.OK)
#Undoe Button
self.Undo = wx.Button(self.panel, id = 130, pos = (150,310), size= (-1,-1), label = "Undo Morphs")
self.Undo.SetBackgroundColour("#5D5D5D")
self.Undo.SetForegroundColour("#CBCBCB")
self.Undo.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseOver)
self.Undo.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
self.Bind(wx.EVT_BUTTON, self.OnUndo, self.Undo)
#static text
self.infoLable = wx.StaticText(self.panel, pos = (20,230),label = 'Enter Morph Value')
self.morphNumber = wx.TextCtrl(self.panel, pos = (150,230))
self.asym = wx.CheckBox(self.panel, label='Asymetric', pos=(275, 230))
#asym.SetValue(False)
#asym.Bind(wx.EVT_CHECKBOX, self.AsymetricOn)
self.Bind(wx.EVT_CHECKBOX, self.AsymetricOn, self.asym)
def AsymetricOn(self, event):
sender = event.GetEventObject()
if sender.GetValue() == True:
allowAsymetric = True
else:
allowAsymetric = False
print allowAsymetric
def OnSelectALL(self,event):
i=0
while i < len(lst):
self.lb.Check(i,True)
i=i+1
def OnSelectNONE(self,event):
i=0
while i < len(lst):
self.lb.Check(i,False)
i=i+1
def OnSelectINVERT(self,event):
i=0
while i < len(lst):
if self.lb.IsChecked(i) == True:
action = False
self.lb.Check(i,action)
i=i +1
continue
elif self.lb.IsChecked(i) == False:
action = True
self.lb.Check(i,action)
i=i+1
continue
i=i+1
def OnSelectOK(self,event):
fig.Memorize()
smn = self.morphNumber.GetString(0,self.morphNumber.GetLineLength(0))
try:
mN = float(smn)
print "before function choice asymetric is ", allowAsymetric
functionChoice(self.lb.GetCheckedStrings(), mN)
print "after is it ", allowAsymetric
except:
print 'Enter a morph value'
def OnUndo(self,event):
fig.Reset()
scene.Draw()
def OnSelectCancel(self,event):
#print "Cancel clicked"
self.Destroy()
def OnMouseOver(self,event):
element = event.GetEventObject()
element.SetBackgroundColour("#737373")
event.Skip()
def OnMouseLeave(self,event):
element = event.GetEventObject()
element.SetBackgroundColour("#5D5D5D")
event.Skip()
When the window pops up I can check and uncheck the box just fine, and I get printed out a correct value for allowAsymetry according to what I've clicked like so:
False
True
False
True
But as soon as I click my Ok/Apply button the value is false no matter what the check box shows:
before function choice asymetric is False
in function choice allowAsymetric is False
I can't figure out why the value of allowAsymetric keeps setting back to False.

Sadly your code will not run standalone, so I can't test it but it looks as if you have forgotten to declare global allowAsymetric in def AsymetricOn(self, event):
You can always access a global variable but if you are going to alter its value, you need to declare it as global or the variable simply becomes a local variable.

Related

How to bind an event to the checkbox in the objectlistview in wxpython

I'm using objectlistview in wxpython and I am very happy with it until now. I cannot find a way to add an event to the checkbox in my objectlistview. At the moment I have a workaround, the user have to click on a button and then something happens with the checked row. But I would like to make it happen when the user checks the checkbox. It have to toggle a graph in my plot.
A second question I have is how I can uncheck the checkboxes after the user clicked the button (this is for if there isn't a way to solve my first question).
My code (I just copied the necessary lines, because my program is very big)
self.tempmeasurements = ObjectListView(self, wx.ID_ANY, style=wx.LC_REPORT | wx.SUNKEN_BORDER)
self.tempmeasurements.SetColumns(microanalysis_options.TempMeasColumndefs)
self.tempmeasurements.CreateCheckStateColumn(0)
self.addbutton = wx.Button(self, wx.ID_ANY, "Add to plot")
self.rembutton = wx.Button(self, wx.ID_ANY,'Remove from plot')
self.Bind(wx.EVT_BUTTON, self.on_toggle_plotlist, self.addbutton)
self.Bind(wx.EVT_BUTTON, self.on_remove_from_plot,self.rembutton)
def on_toggle_plotlist(self, event):
objectsAddPlotList = self.tempmeasurements.GetCheckedObjects()
pub.sendMessage('MA_ADD_TO_PLOT', Container(origin=self, data=objectsAddPlotList)) #to microanalyse controller
self.tempmeasurements.SetCheckState(objectsAddPlotList,False)
def on_remove_from_plot(self,event):
objectsAddPlotList = self.tempmeasurements.GetCheckedObjects()
pub.sendMessage('MA_REM_FROM_PLOT', Container(origin=self, data=objectsAddPlotList)) # to microanalyse controller
The self.tempmeasurements.SetCheckState(objectsAddPlotList,False) line I tried to use to uncheck the checkboxes after the user clicked the button.
this is how the list looks like:
The key thing is to import OLVEvent and then bind your ObjectListView instance to OLVEvent.EVT_ITEM_CHECKED.
I went ahead and created a simple example:
import wx
from ObjectListView import ObjectListView, ColumnDefn, OLVEvent
class Results(object):
""""""
def __init__(self, tin, zip_code, plus4, name, address):
"""Constructor"""
self.tin = tin
self.zip_code = zip_code
self.plus4 = plus4
self.name = name
self.address = address
class MyPanel(wx.Panel):
""""""
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent=parent)
mainSizer = wx.BoxSizer(wx.VERTICAL)
self.test_data = [Results("123456789", "50158", "0065", "Patti Jones",
"111 Centennial Drive"),
Results("978561236", "90056", "7890", "Brian Wilson",
"555 Torque Maui"),
Results("456897852", "70014", "6545", "Mike Love",
"304 Cali Bvld")
]
self.results_olv = ObjectListView(self,
style=wx.LC_REPORT|wx.SUNKEN_BORDER)
self.results_olv.Bind(OLVEvent.EVT_ITEM_CHECKED, self.on_item_checked)
self.set_results()
mainSizer.Add(self.results_olv, 1, wx.EXPAND|wx.ALL, 5)
self.SetSizer(mainSizer)
def on_item_checked(self, event):
obj = self.results_olv.GetSelectedObject()
checked = 'Checked' if self.results_olv.IsChecked(obj) else 'Unchecked'
print('{} row is {}'.format(obj.name, checked))
def set_results(self):
""""""
self.results_olv.SetColumns([
ColumnDefn("TIN", "left", 100, "tin"),
ColumnDefn("Zip", "left", 75, "zip_code"),
ColumnDefn("+4", "left", 50, "plus4"),
ColumnDefn("Name", "left", 150, "name"),
ColumnDefn("Address", "left", 200, "address")
])
self.results_olv.CreateCheckStateColumn()
self.results_olv.SetObjects(self.test_data)
class MainFrame(wx.Frame):
""""""
def __init__(self):
"""Constructor"""
title = "OLV Checkbox Tutorial"
wx.Frame.__init__(self, parent=None, title=title,
size=(600, 400))
panel = MyPanel(self)
if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame()
frame.Show()
app.MainLoop()

setting label value on checkbox click event in wxPython

On checkbox click event set label as some text. If we click on Text checkbox it should set the label named abt_Metric as Text Collected.
boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
#adding checkBox
c1 = wx.CheckBox(panel, label="Text")
#c1.SetValue(True)
#abt_Metric= wx.StaticText(panel, label='')
#boxsizer.Add(abt_Metric, flag=wx.LEFT|wx.TOP,border=10)
#result.GetValue()
url_entered.SetForegroundColour(wx.BLUE)
c2 = wx.CheckBox(panel, label="HTML ")
#c2.SetValue(True)
c3 = wx.CheckBox(panel, label="NLP")
#c3.SetValue(True)
boxsizer.Add(c1,flag=wx.LEFT|wx.TOP, border=5)
boxsizer.Add(c2,flag=wx.LEFT, border=5)
boxsizer.Add(c3,flag=wx.LEFT|wx.BOTTOM, border=5)
sizer.Add(boxsizer, pos=(6, 0), span=(1, 5),flag=wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT , border=10)
abt_Metric= wx.StaticText(panel, label='')
sizer.Add(abt_Metric, pos=(7, 0), flag=wx.LEFT|wx.TOP,border=10)
Checkbox event handler
c1.Bind(wx.EVT_CHECKBOX, self.OntextMetric(c1),c1)
c2.Bind(wx.EVT_CHECKBOX, self.OntextMetric(c2),c2)
c3.Bind(wx.EVT_CHECKBOX, self.OntextMetric(c3),c3)
Implementation of def OntextMetric(self,e,c)
if c.GetValue() == True:
self.panel.abt_Metric.SetLabel(" Text collected")
elif c.GetValue() == True:
self.panel.abt_Metric.SetLabel("HTML collected")
elif c.GetValue() == True:
self.panel.abt_Metric.SetLabel("NLP Collected")
else:
self.panel.abt_Metric.SetLabel("")
Iam not able to understand your question clearly, but is this what you are looking for?
import wx
import matplotlib
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.NewId(), "Main")
panel = wx.Panel(self,1)
#sizer = wx.BoxSizer(wx.HORIZONTAL)
boxsizer = wx.BoxSizer(wx.VERTICAL)
c1 = wx.CheckBox(panel, label="Text")
c2 = wx.CheckBox(panel, label="HTML ")
c3 = wx.CheckBox(panel, label="NLP")
c1.Bind(wx.EVT_CHECKBOX, self.OntextMetric, c1)
c2.Bind(wx.EVT_CHECKBOX, self.OntextMetric,c2)
c3.Bind(wx.EVT_CHECKBOX, self.OntextMetric,c3)
self.abt_Metric= wx.StaticText(panel, label='')
boxsizer.Add(c1,flag=wx.LEFT, border=5)
boxsizer.Add(c2,flag=wx.LEFT, border=5)
boxsizer.Add(c3,flag=wx.LEFT, border=5)
boxsizer.Add(self.abt_Metric, flag = wx.LEFT)
panel.SetSizer(boxsizer)
def OntextMetric(self,event):
if event.IsChecked():
self.abt_Metric.SetLabel(event.GetEventObject().GetLabel() + "collected")
class MyApp(wx.App):
def OnInit(self):
frame = MainFrame()
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp(0)
app.MainLoop()

Use a button press to stop file execution

I want to have a button that starts execution of a file, and another button that stops execution. The below code does not work, the file continues executing. (The file, in this case, is just a loop that continuously prints out "hello world".) How can I achieve what I want?
import wx, sys
from threading import Thread
import time
class mywxframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None)
pnl = wx.Panel(self)
szr = wx.BoxSizer(wx.VERTICAL)
pnl.SetSizer(szr)
szr2 = self.sizer2(pnl)
szr.Add(szr2, 1, wx.ALL|wx.EXPAND, 10)
log = wx.TextCtrl(pnl, -1, style= wx.TE_MULTILINE, size = (300, -1))
szr.Add(log, 0, wx.ALL, 10)
btn3 = wx.Button(pnl, -1, "Stop")
btn3.Bind(wx.EVT_BUTTON, self.OnStop)
szr.Add(btn3, 0, wx.ALL, 10)
self.CreateStatusBar()
redir = RedirectText(log)
sys.stdout=redir
szr.Fit(self)
self.Show()
def sizer2(self, panel):
sizer = wx.BoxSizer(wx.HORIZONTAL)
self.tc2 = wx.TextCtrl(panel, -1, 'Set Range', size = (100, -1))
btn2 = wx.Button(panel, -1, "OK",)
self.Bind(wx.EVT_BUTTON, self.OnStart, btn2)
sizer.Add(self.tc2, 0, wx.ALL, 10)
sizer.Add(btn2, 0, wx.ALL, 10)
return sizer
def OnStart(self, event):
our_thread = Thread(target = self.WorkerThread)
our_thread.start()
def OnStop(self, event):
self.dead = True
def WorkerThread(self):
self.dead = False
while (not self.dead):
execfile("P:\Computing and networking\Python\Learning programs\hello_world.py")
if self.dead:
break
print "aborting"
class RedirectText(object):
def __init__(self, aWxTextCtrl):
self.out=aWxTextCtrl
def write(self, string):
wx.CallAfter(self.out.WriteText, string)
app = wx.App()
frm = mywxframe()
app.MainLoop()
Your GUI is becoming unresponsive. That means that your long running process is blocking the GUI's main loop. To get this to work, you need to sub-class Thread. Here is a version that worked for me:
import wx, sys
from threading import Thread
import time
class TestThread(Thread):
def __init__(self):
Thread.__init__(self)
self.dead = False
self.start()
def run(self):
while not self.dead:
print "hi"
print "aborted"
class mywxframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None)
pnl = wx.Panel(self)
szr = wx.BoxSizer(wx.VERTICAL)
pnl.SetSizer(szr)
szr2 = self.sizer2(pnl)
szr.Add(szr2, 1, wx.ALL|wx.EXPAND, 10)
log = wx.TextCtrl(pnl, -1, style= wx.TE_MULTILINE, size = (300, -1))
szr.Add(log, 0, wx.ALL, 10)
btn3 = wx.Button(pnl, -1, "Stop")
btn3.Bind(wx.EVT_BUTTON, self.OnStop)
szr.Add(btn3, 0, wx.ALL, 10)
self.CreateStatusBar()
redir = RedirectText(log)
#sys.stdout=redir
szr.Fit(self)
self.Show()
def sizer2(self, panel):
sizer = wx.BoxSizer(wx.HORIZONTAL)
self.tc2 = wx.TextCtrl(panel, -1, 'Set Range', size = (100, -1))
btn2 = wx.Button(panel, -1, "OK",)
self.Bind(wx.EVT_BUTTON, self.OnStart, btn2)
sizer.Add(self.tc2, 0, wx.ALL, 10)
sizer.Add(btn2, 0, wx.ALL, 10)
return sizer
def OnStart(self, event):
self.our_thread = TestThread()
def OnStop(self, event):
self.our_thread.dead = True
class RedirectText(object):
def __init__(self, aWxTextCtrl):
self.out=aWxTextCtrl
def write(self, string):
wx.CallAfter(self.out.WriteText, string)
app = wx.App()
frm = mywxframe()
app.MainLoop()
You may want to check out the following resources for additional information on wxPython and threads:
http://www.blog.pythonlibrary.org/2010/05/22/wxpython-and-threads/
http://wiki.wxpython.org/LongRunningTasks

Creating a custom dialog that allows me to select all files at once or a single file individually

I'm attempting to create a custom dialog in wxPython that mimics the wx.MultiChoiceDialog, yet only differs in allowing a user to select all files with the selection of a single check box. This seemed to be a straight forward process, but I've not had success with the textCntrl, checkboxes, or populating the files. Any and all help and direction is appreciated. Thanks!
Below, is one of my many attempts:
import wx
class Extract_file(wx.Dialog):
def __init__(self, parent, title):
wx.Dialog.__init__(self, parent, title=title, size=(345, 337))
self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE | wx.TE_RICH2)
wx.StaticText(self, -1, 'Files in c:\Extracted', (20,20))
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.HORIZONTAL)
chbox = wx.CheckBox(panel, -1, 'CheckBox')
sizer.Add(chbox, 0, wx.ALL, 10)
compute_btn = wx.Button(self, 1, 'Okay', (167, 272))
compute_btn.SetFocus()
clear_btn = wx.Button(self, 2, 'Cancel', (247, 272))
wx.EVT_BUTTON(self, 1, self.OnOkay)
wx.EVT_BUTTON(self, 2, self.OnQuit)
self.Centre()
self.ShowModal()
self.Destroy()
def OnOkay(self, event):
#do something
def OnQuit(self, event):
self.Close(True)
if __name__ == '__main__':
app = wx.App(False)
dlog = Extract_file(None, 'File Extraction')
app.MainLoop()
You don't need wx.TextCtrl to make this dialog. MultiChoiceDialog makes use of the control named wx.CheckBoxList. You can get many examples of its use on the net. Here is one more code snippet:
import wx
class MyMCD(wx.Dialog):
def __init__(self, parent, message, caption, choices=[]):
wx.Dialog.__init__(self, parent, -1)
self.SetTitle(caption)
sizer = wx.BoxSizer(wx.VERTICAL)
self.message = wx.StaticText(self, -1, message)
self.clb = wx.CheckListBox(self, -1, choices = choices)
self.chbox = wx.CheckBox(self, -1, 'Select all')
self.btns = self.CreateSeparatedButtonSizer(wx.OK | wx.CANCEL)
self.Bind(wx.EVT_CHECKBOX, self.EvtChBox, self.chbox)
sizer.Add(self.message, 0, wx.ALL | wx.EXPAND, 5)
sizer.Add(self.clb, 1, wx.ALL | wx.EXPAND, 5)
sizer.Add(self.chbox, 0, wx.ALL | wx.EXPAND, 5)
sizer.Add(self.btns, 0, wx.ALL | wx.EXPAND, 5)
self.SetSizer(sizer)
# self.Fit()
def GetSelections(self):
return self.clb.GetChecked()
def EvtChBox(self, event):
state = self.chbox.IsChecked()
for i in range(self.clb.GetCount()):
self.clb.Check(i, state)
if __name__ == '__main__':
l = ['AND', 'OR', 'XOR', 'NOT']
app = wx.PySimpleApp()
dlg = MyMCD(None, 'Choose as many as you wish', 'MCD Title', choices = l)
if dlg.ShowModal() == wx.ID_OK:
result = dlg.GetSelections()
wx.MessageBox(str(result) + ' were chosen')
dlg.Destroy()

QTableView with comboBox

I want my QTableView to have a column of comboBoxes. After a lot of try-outs, I've reached my goal : display the comboBoxes.
Now my problem is that they won't keep the selected item displayed.
I use a custom delegate to do it, below is the relevant code :
class ComboBoxDelegate(QtGui.QItemDelegate):
def __init__(self, owner, itemslist):
QtGui.QItemDelegate.__init__(self, owner)
self.itemslist = itemslist
def paint(self, painter, option, index):
# Get Item Data
value = index.data(QtCore.Qt.DisplayRole).toInt()[0]
# fill style options with item data
style = QtGui.QApplication.style()
opt = QtGui.QStyleOptionComboBox()
opt.currentText = str(self.itemslist[value])
opt.rect = option.rect
# draw item data as ComboBox
style.drawComplexControl(QtGui.QStyle.CC_ComboBox, opt, painter)
def createEditor(self, parent, option, index):
# create the ProgressBar as our editor.
editor = QtGui.QComboBox(parent)
editor.addItems(self.itemslist)
editor.setCurrentIndex(0)
editor.installEventFilter(self)
return editor
def setEditorData(self, editor, index):
value = index.data(QtCore.Qt.DisplayRole).toInt()[0]
editor.setCurrentIndex(value)
def setModelData(self,editor,model,index):
value = editor.currentIndex()
model.setData(index, QtCore.QVariant(value))
def updateEditorGeometry(self, editor, option, index):
editor.setGeometry(option.rect)
class SequenceGridModel(QtCore.QAbstractTableModel):
def __init__(self, datain, headerdata, parent=None, *args):
QtCore.QAbstractTableModel.__init__(self, parent, *args)
self.parent = parent
self.arraydata = datain
self.headerdata = headerdata
def flags(self, index):
if index.column() == 13:
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
return QtCore.QAbstractTableModel.flags(self, index)
def data(self, index, role = QtCore.Qt.DisplayRole):
if not index.isValid():
if role == QtCore.Qt.UserRole:
return None
else:
return QtCore.QVariant()
value = QtCore.QVariant(self.arraydata[index.row()][index.column()])
if QtCore.Qt.UserRole == role:
return value
elif role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
return QtCore.QVariant(value)
return QtCore.QVariant()
class SequenceGrid(QtGui.QTableView):
def __init__(self, parent=None):
QtGui.QTableView.__init__(self, parent)
self.selectedIndexes = []
self.parent = parent
self.checkValues = ['TODO', 'WAITING', 'RETAKE', 'OK']
self.model = SequenceGridModel(self.data, header, self)
self.setModel(self.model)
self.setEditTriggers(QtGui.QAbstractItemView.CurrentChanged)
self.viewport().installEventFilter(self)
self.setItemDelegateForColumn(13,ComboBoxDelegate(self, self.checkValues))
self.setColumnWidth(13, 64)
Thanks for your attention !

Resources