From frank at ohufx.com Thu Oct 10 18:33:05 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Thu, 10 Oct 2013 18:33:05 +0200 Subject: [PySide] simple QTableView example Message-ID: <5256D6C1.70508@ohufx.com> Hi all, after a bit of a break from PySide I am trying to wrap my head around the model/view stuff again and am trying to understand how a very simple example would work where a QStandarItem has properties "title", "priority" and "finished" which are displayed via a QStandardTableView. I am struggling with understanding how to properly display the above three properties in the table's columns. I tried setting the data() method on the model like this: / def data(self, index, role=QtCore.Qt.DisplayRole):// // '''Return data based on index and role'''// // item = self.itemFromIndex(index)// // if index.column() == 0:// // return item.title// // elif index.column() == 1:// // return item.finished// // elif index.column() == 2:// // return item.priority/ but for some reason it errors saying item does not have attribute "finished" even though my item object s declared like this: /class TaskItem(QtGui.QStandardItem):// // '''Item to hold a task for the todo list'''// //// // def __init__(self, title, finished=False, priority=1):// // super(TaskItem, self).__init__(title)// // self.title = title// // self.finished = finished// // self.priority = priority/ When printing the item's attributes via dir() I see that, when the model is populated, the last item it attempts to call is not my custom item object, but something else with less attributes and methods. Clearly there is something I haven't quite understood about this process. Also, if I use the models data() method as pointed out above, I get checkboxes in the cells which I don't want at this stage. Can somebody please help me understand where I go wrong? Attached is the whole test code. Cheers, frank P.S.: I am aware that the controller code shouldn't necessarily live in the QWidget's methods, this is just for testing which I will clean up once I get how it all connects again -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ToDoPanel.py Type: text/x-python-script Size: 2706 bytes Desc: not available URL: From frank at ohufx.com Thu Oct 10 18:34:29 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Thu, 10 Oct 2013 18:34:29 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <5256D6C1.70508@ohufx.com> References: <5256D6C1.70508@ohufx.com> Message-ID: <5256D715.5020301@ohufx.com> I meant QTableView not QStandardTableView :/ On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: > Hi all, > > after a bit of a break from PySide I am trying to wrap my head around > the model/view stuff again and am trying to understand how a very > simple example would work where a QStandarItem has properties "title", > "priority" and "finished" which are displayed via a QStandardTableView. > > I am struggling with understanding how to properly display the above > three properties in the table's columns. I tried setting the data() > method on the model like this: > > / def data(self, index, role=QtCore.Qt.DisplayRole):// > // '''Return data based on index and role'''// > // item = self.itemFromIndex(index)// > // if index.column() == 0:// > // return item.title// > // elif index.column() == 1:// > // return item.finished// > // elif index.column() == 2:// > // return item.priority/ > > but for some reason it errors saying item does not have attribute > "finished" even though my item object s declared like this: > > /class TaskItem(QtGui.QStandardItem):// > // '''Item to hold a task for the todo list'''// > //// > // def __init__(self, title, finished=False, priority=1):// > // super(TaskItem, self).__init__(title)// > // self.title = title// > // self.finished = finished// > // self.priority = priority/ > > > When printing the item's attributes via dir() I see that, when the > model is populated, the last item it attempts to call is not my custom > item object, but something else with less attributes and methods. > Clearly there is something I haven't quite understood about this process. > > Also, if I use the models data() method as pointed out above, I get > checkboxes in the cells which I don't want at this stage. > > Can somebody please help me understand where I go wrong? > Attached is the whole test code. > > Cheers, > frank > > P.S.: I am aware that the controller code shouldn't necessarily live > in the QWidget's methods, this is just for testing which I will clean > up once I get how it all connects again > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at ohufx.com Thu Oct 10 19:37:48 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Thu, 10 Oct 2013 19:37:48 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <5256D715.5020301@ohufx.com> References: <5256D6C1.70508@ohufx.com> <5256D715.5020301@ohufx.com> Message-ID: <5256E5EC.5070806@ohufx.com> After looking at some more examples I think my approach of storing multiple values in one item is fundamentally flawed. Instead I should be using one item per cell and assign the respective data, right?! I shall re-write the example accordingly, sorry for the noise. frank On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: > I meant QTableView not QStandardTableView :/ > > On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: >> Hi all, >> >> after a bit of a break from PySide I am trying to wrap my head around >> the model/view stuff again and am trying to understand how a very >> simple example would work where a QStandarItem has properties >> "title", "priority" and "finished" which are displayed via a >> QStandardTableView. >> >> I am struggling with understanding how to properly display the above >> three properties in the table's columns. I tried setting the data() >> method on the model like this: >> >> / def data(self, index, role=QtCore.Qt.DisplayRole):// >> // '''Return data based on index and role'''// >> // item = self.itemFromIndex(index)// >> // if index.column() == 0:// >> // return item.title// >> // elif index.column() == 1:// >> // return item.finished// >> // elif index.column() == 2:// >> // return item.priority/ >> >> but for some reason it errors saying item does not have attribute >> "finished" even though my item object s declared like this: >> >> /class TaskItem(QtGui.QStandardItem):// >> // '''Item to hold a task for the todo list'''// >> //// >> // def __init__(self, title, finished=False, priority=1):// >> // super(TaskItem, self).__init__(title)// >> // self.title = title// >> // self.finished = finished// >> // self.priority = priority/ >> >> >> When printing the item's attributes via dir() I see that, when the >> model is populated, the last item it attempts to call is not my >> custom item object, but something else with less attributes and >> methods. Clearly there is something I haven't quite understood about >> this process. >> >> Also, if I use the models data() method as pointed out above, I get >> checkboxes in the cells which I don't want at this stage. >> >> Can somebody please help me understand where I go wrong? >> Attached is the whole test code. >> >> Cheers, >> frank >> >> P.S.: I am aware that the controller code shouldn't necessarily live >> in the QWidget's methods, this is just for testing which I will clean >> up once I get how it all connects again >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From kandraitibold at gmail.com Thu Oct 10 23:44:06 2013 From: kandraitibold at gmail.com (=?utf-8?Q?Tibold_Kandrai?=) Date: Thu, 10 Oct 2013 21:44:06 +0000 Subject: [PySide] =?utf-8?q?simple_QTableView_example?= In-Reply-To: <5256E5EC.5070806@ohufx.com> References: <5256D6C1.70508@ohufx.com> <5256D715.5020301@ohufx.com>,<5256E5EC.5070806@ohufx.com> Message-ID: <52572219.82eccc0a.55f2.ffff8462@mx.google.com> Hey, I’m not sure I understand the problem correctly. If you want to store data in a cell or a QStandardItem, then you need to use setData() and data(). Generally you shouldn’t need to subclass QStandardItem or QStandardItemModel. Here is an example how: # Define roles FINISHED_ROLE = QtCore.Qt.UserRole + 1 PRIORITY_ROLE = QtCore.Qt.UserRole + 2 # Create model model = QtGui.QStandardItemModel() item = QtGui.QStandarItem() model.appendRow(item) item_index = item.index() # Store data using the item item.setData(finished, FINISHED_ROLE) item.setData(priority, PRIORITY_ROLE) # Store data using the model model.setData(item_index, finished, FINISHED_ROLE) model.setData(item_index, priority, PRIORITY_ROLE) # Retrieve data using the item finished = item.data(FINISHED_ROLE) priority = item.data(PRIORITY_ROLE) # Retrieve data using the model finished = model.data(item_index, FINISHED_ROLE) priority = model.data(item_index, PRIORITY_ROLE) In some cases like click event handlers, you have the model and the item index, there it’s easier to use the model methods instead of finding the item and then getting the data. 😉 Hope it helps. Cheers, Tibold From: Frank Rueter | OHUfx Sent: ‎2013‎ ‎October‎ ‎10‎, ‎Thursday ‎19‎:‎37 To: pyside at qt-project.org After looking at some more examples I think my approach of storing multiple values in one item is fundamentally flawed. Instead I should be using one item per cell and assign the respective data, right?! I shall re-write the example accordingly, sorry for the noise. frank On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: I meant QTableView not QStandardTableView :/ On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: Hi all, after a bit of a break from PySide I am trying to wrap my head around the model/view stuff again and am trying to understand how a very simple example would work where a QStandarItem has properties "title", "priority" and "finished" which are displayed via a QStandardTableView. I am struggling with understanding how to properly display the above three properties in the table's columns. I tried setting the data() method on the model like this: def data(self, index, role=QtCore.Qt.DisplayRole): '''Return data based on index and role''' item = self.itemFromIndex(index) if index.column() == 0: return item.title elif index.column() == 1: return item.finished elif index.column() == 2: return item.priority but for some reason it errors saying item does not have attribute "finished" even though my item object s declared like this: class TaskItem(QtGui.QStandardItem): '''Item to hold a task for the todo list''' def __init__(self, title, finished=False, priority=1): super(TaskItem, self).__init__(title) self.title = title self.finished = finished self.priority = priority When printing the item's attributes via dir() I see that, when the model is populated, the last item it attempts to call is not my custom item object, but something else with less attributes and methods. Clearly there is something I haven't quite understood about this process. Also, if I use the models data() method as pointed out above, I get checkboxes in the cells which I don't want at this stage. Can somebody please help me understand where I go wrong? Attached is the whole test code. Cheers, frank P.S.: I am aware that the controller code shouldn't necessarily live in the QWidget's methods, this is just for testing which I will clean up once I get how it all connects again _______________________________________________ PySide mailing list PySide at qt-project.org http://lists.qt-project.org/mailman/listinfo/pyside _______________________________________________ PySide mailing list PySide at qt-project.org http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at ohufx.com Fri Oct 11 11:35:45 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Fri, 11 Oct 2013 11:35:45 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <52572219.82eccc0a.55f2.ffff8462@mx.google.com> References: <5256D6C1.70508@ohufx.com> <5256D715.5020301@ohufx.com>, <5256E5EC.5070806@ohufx.com> <52572219.82eccc0a.55f2.ffff8462@mx.google.com> Message-ID: <5257C671.7070601@ohufx.com> Great, thanks Tibold! On 10/10/13 11:44 PM, Tibold Kandrai wrote: > Hey, > I’m not sure I understand the problem correctly. > If you want to store data in a cell or a QStandardItem, then you need > to use setData() and data(). > Generally you shouldn’t need to subclass QStandardItem or > QStandardItemModel. > Here is an example how: > # Define roles > FINISHED_ROLE = QtCore.Qt.UserRole + 1 > PRIORITY_ROLE = QtCore.Qt.UserRole + 2 > # Create model > model = QtGui.QStandardItemModel() > item = QtGui.QStandarItem() > model.appendRow(item) > item_index = item.index() > # Store data using the item > item.setData(finished, FINISHED_ROLE) > item.setData(priority, PRIORITY_ROLE) > # Store data using the model > model.setData(item_index, finished, FINISHED_ROLE) > model.setData(item_index, priority, PRIORITY_ROLE) > # Retrieve data using the item > finished = item.data(FINISHED_ROLE) > priority = item.data(PRIORITY_ROLE) > # Retrieve data using the model > finished = model.data(item_index, FINISHED_ROLE) > priority = model.data(item_index, PRIORITY_ROLE) > In some cases like click event handlers, you have the model and the > item index, there it’s easier to use the model methods instead of > finding the item and then getting the data. 😉 > Hope it helps. > Cheers, > Tibold > *From:* Frank Rueter | OHUfx > *Sent:* ‎2013‎ ‎October‎ ‎10‎, ‎Thursday ‎19‎:‎37 > *To:* pyside at qt-project.org > After looking at some more examples I think my approach of storing > multiple values in one item is fundamentally flawed. > Instead I should be using one item per cell and assign the respective > data, right?! > > I shall re-write the example accordingly, sorry for the noise. > > frank > > On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: > > I meant QTableView not QStandardTableView :/ > > On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: > > Hi all, > > after a bit of a break from PySide I am trying to wrap my head > around the model/view stuff again and am trying to understand > how a very simple example would work where a QStandarItem has > properties "title", "priority" and "finished" which are > displayed via a QStandardTableView. > > I am struggling with understanding how to properly display the > above three properties in the table's columns. I tried setting > the data() method on the model like this: > > / def data(self, index, role=QtCore.Qt.DisplayRole):// > // '''Return data based on index and role'''// > // item = self.itemFromIndex(index)// > // if index.column() == 0:// > // return item.title// > // elif index.column() == 1:// > // return item.finished// > // elif index.column() == 2:// > // return item.priority/ > > but for some reason it errors saying item does not have > attribute "finished" even though my item object s declared > like this: > > /class TaskItem(QtGui.QStandardItem):// > // '''Item to hold a task for the todo list'''// > //// > // def __init__(self, title, finished=False, priority=1):// > // super(TaskItem, self).__init__(title)// > // self.title = title// > // self.finished = finished// > // self.priority = priority/ > > > When printing the item's attributes via dir() I see that, when > the model is populated, the last item it attempts to call is > not my custom item object, but something else with less > attributes and methods. Clearly there is something I haven't > quite understood about this process. > > Also, if I use the models data() method as pointed out above, > I get checkboxes in the cells which I don't want at this stage. > > Can somebody please help me understand where I go wrong? > Attached is the whole test code. > > Cheers, > frank > > P.S.: I am aware that the controller code shouldn't > necessarily live in the QWidget's methods, this is just for > testing which I will clean up once I get how it all connects again > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside > > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at ohufx.com Fri Oct 11 14:35:52 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Fri, 11 Oct 2013 14:35:52 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <52572219.82eccc0a.55f2.ffff8462@mx.google.com> References: <5256D6C1.70508@ohufx.com> <5256D715.5020301@ohufx.com>, <5256E5EC.5070806@ohufx.com> <52572219.82eccc0a.55f2.ffff8462@mx.google.com> Message-ID: <5257F0A8.80303@ohufx.com> one more silly question if I may: So if I have a task like this: newTask = {'title':'new task', 'priority':1, 'status':False} and need to store the data in one row in the model I should use three different items, one for each value, right?! e.g.: newTask = {'title':'new task', 'priority':1, 'status':False} row = self.model.rowCount() for column, attr in enumerate(['title', 'priority', 'status']): newItem = QtGui.QStandardItem(newTask[attr]) self.model.setItem(row, column, newItem) then juggle delegates or widgets to use a spin box for the integer and a checkbox for the boolean... Thanks for the help! Cheers, frank On 10/10/13 11:44 PM, Tibold Kandrai wrote: > Hey, > I’m not sure I understand the problem correctly. > If you want to store data in a cell or a QStandardItem, then you need > to use setData() and data(). > Generally you shouldn’t need to subclass QStandardItem or > QStandardItemModel. > Here is an example how: > # Define roles > FINISHED_ROLE = QtCore.Qt.UserRole + 1 > PRIORITY_ROLE = QtCore.Qt.UserRole + 2 > # Create model > model = QtGui.QStandardItemModel() > item = QtGui.QStandarItem() > model.appendRow(item) > item_index = item.index() > # Store data using the item > item.setData(finished, FINISHED_ROLE) > item.setData(priority, PRIORITY_ROLE) > # Store data using the model > model.setData(item_index, finished, FINISHED_ROLE) > model.setData(item_index, priority, PRIORITY_ROLE) > # Retrieve data using the item > finished = item.data(FINISHED_ROLE) > priority = item.data(PRIORITY_ROLE) > # Retrieve data using the model > finished = model.data(item_index, FINISHED_ROLE) > priority = model.data(item_index, PRIORITY_ROLE) > In some cases like click event handlers, you have the model and the > item index, there it’s easier to use the model methods instead of > finding the item and then getting the data. 😉 > Hope it helps. > Cheers, > Tibold > *From:* Frank Rueter | OHUfx > *Sent:* ‎2013‎ ‎October‎ ‎10‎, ‎Thursday ‎19‎:‎37 > *To:* pyside at qt-project.org > After looking at some more examples I think my approach of storing > multiple values in one item is fundamentally flawed. > Instead I should be using one item per cell and assign the respective > data, right?! > > I shall re-write the example accordingly, sorry for the noise. > > frank > > On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: > > I meant QTableView not QStandardTableView :/ > > On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: > > Hi all, > > after a bit of a break from PySide I am trying to wrap my head > around the model/view stuff again and am trying to understand > how a very simple example would work where a QStandarItem has > properties "title", "priority" and "finished" which are > displayed via a QStandardTableView. > > I am struggling with understanding how to properly display the > above three properties in the table's columns. I tried setting > the data() method on the model like this: > > / def data(self, index, role=QtCore.Qt.DisplayRole):// > // '''Return data based on index and role'''// > // item = self.itemFromIndex(index)// > // if index.column() == 0:// > // return item.title// > // elif index.column() == 1:// > // return item.finished// > // elif index.column() == 2:// > // return item.priority/ > > but for some reason it errors saying item does not have > attribute "finished" even though my item object s declared > like this: > > /class TaskItem(QtGui.QStandardItem):// > // '''Item to hold a task for the todo list'''// > //// > // def __init__(self, title, finished=False, priority=1):// > // super(TaskItem, self).__init__(title)// > // self.title = title// > // self.finished = finished// > // self.priority = priority/ > > > When printing the item's attributes via dir() I see that, when > the model is populated, the last item it attempts to call is > not my custom item object, but something else with less > attributes and methods. Clearly there is something I haven't > quite understood about this process. > > Also, if I use the models data() method as pointed out above, > I get checkboxes in the cells which I don't want at this stage. > > Can somebody please help me understand where I go wrong? > Attached is the whole test code. > > Cheers, > frank > > P.S.: I am aware that the controller code shouldn't > necessarily live in the QWidget's methods, this is just for > testing which I will clean up once I get how it all connects again > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside > > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From backup.rlacko at gmail.com Fri Oct 11 14:51:51 2013 From: backup.rlacko at gmail.com (Roman Lacko) Date: Fri, 11 Oct 2013 14:51:51 +0200 Subject: [PySide] New PySide 1.2.1 packages for Windows Message-ID: Hi, I have uploaded new Windows packages for PySide. The binary packages are now available for all supported Python versions 2.6, 2.7, 3.2 and 3.3 for both 32 and 64bit versions. Also, from now you can use pip to install new wheel binary package format: $ pip install --use-wheel pyside Enjoy -Roman -------------- next part -------------- An HTML attachment was scrubbed... URL: From kandraitibold at gmail.com Fri Oct 11 16:00:06 2013 From: kandraitibold at gmail.com (Tibold Kandrai) Date: Fri, 11 Oct 2013 07:00:06 -0700 Subject: [PySide] simple QTableView example Message-ID: <848951203488568137@unknownmsgid> If you mean to use a QStandardItem per cell then yes. Also for storing values that you want to display, use the Qt.DisplayRole as role. Cheers, Tibold Kandrai ------------------------------ From: Frank Rueter | OHUfx Sent: ‎11/‎10/‎2013 14:35 To: Tibold Kandrai Cc: pyside at qt-project.org Subject: Re: [PySide] simple QTableView example one more silly question if I may: So if I have a task like this: newTask = {'title':'new task', 'priority':1, 'status':False} and need to store the data in one row in the model I should use three different items, one for each value, right?! e.g.: newTask = {'title':'new task', 'priority':1, 'status':False} row = self.model.rowCount() for column, attr in enumerate(['title', 'priority', 'status']): newItem = QtGui.QStandardItem(newTask[attr]) self.model.setItem(row, column, newItem) then juggle delegates or widgets to use a spin box for the integer and a checkbox for the boolean... Thanks for the help! Cheers, frank On 10/10/13 11:44 PM, Tibold Kandrai wrote: Hey, I’m not sure I understand the problem correctly. If you want to store data in a cell or a QStandardItem, then you need to use setData() and data(). Generally you shouldn’t need to subclass QStandardItem or QStandardItemModel. Here is an example how: # Define roles FINISHED_ROLE = QtCore.Qt.UserRole + 1 PRIORITY_ROLE = QtCore.Qt.UserRole + 2 # Create model model = QtGui.QStandardItemModel() item = QtGui.QStandarItem() model.appendRow(item) item_index = item.index() # Store data using the item item.setData(finished, FINISHED_ROLE) item.setData(priority, PRIORITY_ROLE) # Store data using the model model.setData(item_index, finished, FINISHED_ROLE) model.setData(item_index, priority, PRIORITY_ROLE) # Retrieve data using the item finished = item.data(FINISHED_ROLE) priority = item.data(PRIORITY_ROLE) # Retrieve data using the model finished = model.data(item_index, FINISHED_ROLE) priority = model.data(item_index, PRIORITY_ROLE) In some cases like click event handlers, you have the model and the item index, there it’s easier to use the model methods instead of finding the item and then getting the data. 😉 Hope it helps. Cheers, Tibold *From:* Frank Rueter | OHUfx *Sent:* ‎2013‎ ‎October‎ ‎10‎, ‎Thursday ‎19‎:‎37 *To:* pyside at qt-project.org After looking at some more examples I think my approach of storing multiple values in one item is fundamentally flawed. Instead I should be using one item per cell and assign the respective data, right?! I shall re-write the example accordingly, sorry for the noise. frank On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: I meant QTableView not QStandardTableView :/ On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: Hi all, after a bit of a break from PySide I am trying to wrap my head around the model/view stuff again and am trying to understand how a very simple example would work where a QStandarItem has properties "title", "priority" and "finished" which are displayed via a QStandardTableView. I am struggling with understanding how to properly display the above three properties in the table's columns. I tried setting the data() method on the model like this: * def data(self, index, role=QtCore.Qt.DisplayRole):** ** '''Return data based on index and role'''** ** item = self.itemFromIndex(index)** ** if index.column() == 0:** ** return item.title** ** elif index.column() == 1:** ** return item.finished** ** elif index.column() == 2:** ** return item.priority* but for some reason it errors saying item does not have attribute "finished" even though my item object s declared like this: *class TaskItem(QtGui.QStandardItem):** ** '''Item to hold a task for the todo list'''** ** ** ** def __init__(self, title, finished=False, priority=1):** ** super(TaskItem, self).__init__(title)** ** self.title = title** ** self.finished = finished** ** self.priority = priority* When printing the item's attributes via dir() I see that, when the model is populated, the last item it attempts to call is not my custom item object, but something else with less attributes and methods. Clearly there is something I haven't quite understood about this process. Also, if I use the models data() method as pointed out above, I get checkboxes in the cells which I don't want at this stage. Can somebody please help me understand where I go wrong? Attached is the whole test code. Cheers, frank P.S.: I am aware that the controller code shouldn't necessarily live in the QWidget's methods, this is just for testing which I will clean up once I get how it all connects again _______________________________________________ PySide mailing listPySide at qt-project.orghttp://lists.qt-project.org/mailman/listinfo/pyside _______________________________________________ PySide mailing listPySide at qt-project.orghttp://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at ohufx.com Sat Oct 12 22:49:25 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Sat, 12 Oct 2013 22:49:25 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <848951203488568137@unknownmsgid> References: <848951203488568137@unknownmsgid> Message-ID: <5259B5D5.8000505@ohufx.com> Is this the best way to do it though? I.e. having one item per cell? s there another way at all? I'm still a bit lost in the model/view design and can't find the answer online. I'm simply trying to have each row represent a "task" with a title/description (string), a status (boolean) and a priority (integer). For the integer I need a spin box and for the boolean I need a checkbox. The examples I found online all seem to be doing something slightly different and often use different ways which makes matters more confusing. Here is what I have at the moment: http://pastebin.com/H3GD0xVB The "status" and "priority" values don't display currnelty as I haven't figured out how to properly assign a delegate to just those cells. At the top I tried to define a n item delegete for a spin box but I'm not sure how to properly assign it. Do I have to make the delegate draw different widgets (spin box / checkbox) depending on data type, or can/should I use a different delegate for each cell? I'm sure the answer is right in front of me, could you please help one more time please?! Cheers, frank On 11/10/13 4:00 PM, Tibold Kandrai wrote: > If you mean to use a QStandardItem per cell then yes. > Also for storing values that you want to display, use the > Qt.DisplayRole as role. > > Cheers, > Tibold Kandrai > ------------------------------------------------------------------------ > From: Frank Rueter | OHUfx > Sent: ‎11/‎10/‎2013 14:35 > To: Tibold Kandrai > Cc: pyside at qt-project.org > Subject: Re: [PySide] simple QTableView example > > one more silly question if I may: > So if I have a task like this: > newTask = {'title':'new task', 'priority':1, 'status':False} > > and need to store the data in one row in the model I should use three > different items, one for each value, right?! > > e.g.: > > newTask = {'title':'new task', 'priority':1, 'status':False} > row = self.model.rowCount() > for column, attr in enumerate(['title', 'priority', 'status']): > newItem = QtGui.QStandardItem(newTask[attr]) > self.model.setItem(row, column, newItem) > > then juggle delegates or widgets to use a spin box for the integer and > a checkbox for the boolean... > > Thanks for the help! > > Cheers, > frank > > On 10/10/13 11:44 PM, Tibold Kandrai wrote: >> Hey, >> I’m not sure I understand the problem correctly. >> If you want to store data in a cell or a QStandardItem, then you need >> to use setData() and data(). >> Generally you shouldn’t need to subclass QStandardItem or >> QStandardItemModel. >> Here is an example how: >> # Define roles >> FINISHED_ROLE = QtCore.Qt.UserRole + 1 >> PRIORITY_ROLE = QtCore.Qt.UserRole + 2 >> # Create model >> model = QtGui.QStandardItemModel() >> item = QtGui.QStandarItem() >> model.appendRow(item) >> item_index = item.index() >> # Store data using the item >> item.setData(finished, FINISHED_ROLE) >> item.setData(priority, PRIORITY_ROLE) >> # Store data using the model >> model.setData(item_index, finished, FINISHED_ROLE) >> model.setData(item_index, priority, PRIORITY_ROLE) >> # Retrieve data using the item >> finished = item.data(FINISHED_ROLE) >> priority = item.data(PRIORITY_ROLE) >> # Retrieve data using the model >> finished = model.data(item_index, FINISHED_ROLE) >> priority = model.data(item_index, PRIORITY_ROLE) >> In some cases like click event handlers, you have the model and the >> item index, there it’s easier to use the model methods instead of >> finding the item and then getting the data. 😉 >> Hope it helps. >> Cheers, >> Tibold >> *From:* Frank Rueter | OHUfx >> *Sent:* ‎2013‎ ‎October‎ ‎10‎, ‎Thursday ‎19‎:‎37 >> *To:* pyside at qt-project.org >> After looking at some more examples I think my approach of storing >> multiple values in one item is fundamentally flawed. >> Instead I should be using one item per cell and assign the respective >> data, right?! >> >> I shall re-write the example accordingly, sorry for the noise. >> >> frank >> >> On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: >> >> I meant QTableView not QStandardTableView :/ >> >> On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: >> >> Hi all, >> >> after a bit of a break from PySide I am trying to wrap my >> head around the model/view stuff again and am trying to >> understand how a very simple example would work where a >> QStandarItem has properties "title", "priority" and >> "finished" which are displayed via a QStandardTableView. >> >> I am struggling with understanding how to properly display >> the above three properties in the table's columns. I tried >> setting the data() method on the model like this: >> >> / def data(self, index, role=QtCore.Qt.DisplayRole):// >> // '''Return data based on index and role'''// >> // item = self.itemFromIndex(index)// >> // if index.column() == 0:// >> // return item.title// >> // elif index.column() == 1:// >> // return item.finished// >> // elif index.column() == 2:// >> // return item.priority/ >> >> but for some reason it errors saying item does not have >> attribute "finished" even though my item object s declared >> like this: >> >> /class TaskItem(QtGui.QStandardItem):// >> // '''Item to hold a task for the todo list'''// >> //// >> // def __init__(self, title, finished=False, priority=1):// >> // super(TaskItem, self).__init__(title)// >> // self.title = title// >> // self.finished = finished// >> // self.priority = priority/ >> >> >> When printing the item's attributes via dir() I see that, >> when the model is populated, the last item it attempts to >> call is not my custom item object, but something else with >> less attributes and methods. Clearly there is something I >> haven't quite understood about this process. >> >> Also, if I use the models data() method as pointed out above, >> I get checkboxes in the cells which I don't want at this stage. >> >> Can somebody please help me understand where I go wrong? >> Attached is the whole test code. >> >> Cheers, >> frank >> >> P.S.: I am aware that the controller code shouldn't >> necessarily live in the QWidget's methods, this is just for >> testing which I will clean up once I get how it all connects >> again >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside >> >> >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kandraitibold at gmail.com Sun Oct 13 00:06:55 2013 From: kandraitibold at gmail.com (=?utf-8?Q?Tibold_Kandrai?=) Date: Sat, 12 Oct 2013 22:06:55 +0000 Subject: [PySide] =?utf-8?q?simple_QTableView_example?= In-Reply-To: <5259B5D5.8000505@ohufx.com> References: <848951203488568137@unknownmsgid>,<5259B5D5.8000505@ohufx.com> Message-ID: <5259c8d3.486b0e0a.0d06.ffffc793@mx.google.com> If you ask me personally, I wouldn’t use QTableWidget. Look into QTreeView or QListWidget. I think they are more suitable for such tasks and are easier to handle. With QTreeView you can use QItemDelegate, to create a special rendering. With QListWidget you can simply add a widget per row and inside the widget you can put whatever. ATM I’m in the middle of a 2000 km road trip so I can’t rally provide you sample's, but if you need help next week I’m glad to give you samples how to use these widgets. Cheers, Tibold Kandrai From: Frank Rueter | OHUfx Sent: ‎Saturday‎, ‎12‎ ‎October‎ ‎2013 ‎22‎:‎49 To: Tibold Kandrai Cc: pyside at qt-project.org Is this the best way to do it though? I.e. having one item per cell? s there another way at all? I'm still a bit lost in the model/view design and can't find the answer online. I'm simply trying to have each row represent a "task" with a title/description (string), a status (boolean) and a priority (integer). For the integer I need a spin box and for the boolean I need a checkbox. The examples I found online all seem to be doing something slightly different and often use different ways which makes matters more confusing. Here is what I have at the moment: http://pastebin.com/H3GD0xVB The "status" and "priority" values don't display currnelty as I haven't figured out how to properly assign a delegate to just those cells. At the top I tried to define a n item delegete for a spin box but I'm not sure how to properly assign it. Do I have to make the delegate draw different widgets (spin box / checkbox) depending on data type, or can/should I use a different delegate for each cell? I'm sure the answer is right in front of me, could you please help one more time please?! Cheers, frank On 11/10/13 4:00 PM, Tibold Kandrai wrote: If you mean to use a QStandardItem per cell then yes. Also for storing values that you want to display, use the Qt.DisplayRole as role. Cheers, Tibold Kandrai From: Frank Rueter | OHUfx Sent: ‎11/‎10/‎2013 14:35 To: Tibold Kandrai Cc: pyside at qt-project.org Subject: Re: [PySide] simple QTableView example one more silly question if I may: So if I have a task like this: newTask = {'title':'new task', 'priority':1, 'status':False} and need to store the data in one row in the model I should use three different items, one for each value, right?! e.g.: newTask = {'title':'new task', 'priority':1, 'status':False} row = self.model.rowCount() for column, attr in enumerate(['title', 'priority', 'status']): newItem = QtGui.QStandardItem(newTask[attr]) self.model.setItem(row, column, newItem) then juggle delegates or widgets to use a spin box for the integer and a checkbox for the boolean... Thanks for the help! Cheers, frank On 10/10/13 11:44 PM, Tibold Kandrai wrote: Hey, I’m not sure I understand the problem correctly. If you want to store data in a cell or a QStandardItem, then you need to use setData() and data(). Generally you shouldn’t need to subclass QStandardItem or QStandardItemModel. Here is an example how: # Define roles FINISHED_ROLE = QtCore.Qt.UserRole + 1 PRIORITY_ROLE = QtCore.Qt.UserRole + 2 # Create model model = QtGui.QStandardItemModel() item = QtGui.QStandarItem() model.appendRow(item) item_index = item.index() # Store data using the item item.setData(finished, FINISHED_ROLE) item.setData(priority, PRIORITY_ROLE) # Store data using the model model.setData(item_index, finished, FINISHED_ROLE) model.setData(item_index, priority, PRIORITY_ROLE) # Retrieve data using the item finished = item.data(FINISHED_ROLE) priority = item.data(PRIORITY_ROLE) # Retrieve data using the model finished = model.data(item_index, FINISHED_ROLE) priority = model.data(item_index, PRIORITY_ROLE) In some cases like click event handlers, you have the model and the item index, there it’s easier to use the model methods instead of finding the item and then getting the data. 😉 Hope it helps. Cheers, Tibold From: Frank Rueter | OHUfx Sent: ‎2013‎ ‎October‎ ‎10‎, ‎Thursday ‎19‎:‎37 To: pyside at qt-project.org After looking at some more examples I think my approach of storing multiple values in one item is fundamentally flawed. Instead I should be using one item per cell and assign the respective data, right?! I shall re-write the example accordingly, sorry for the noise. frank On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: I meant QTableView not QStandardTableView :/ On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: Hi all, after a bit of a break from PySide I am trying to wrap my head around the model/view stuff again and am trying to understand how a very simple example would work where a QStandarItem has properties "title", "priority" and "finished" which are displayed via a QStandardTableView. I am struggling with understanding how to properly display the above three properties in the table's columns. I tried setting the data() method on the model like this: def data(self, index, role=QtCore.Qt.DisplayRole): '''Return data based on index and role''' item = self.itemFromIndex(index) if index.column() == 0: return item.title elif index.column() == 1: return item.finished elif index.column() == 2: return item.priority but for some reason it errors saying item does not have attribute "finished" even though my item object s declared like this: class TaskItem(QtGui.QStandardItem): '''Item to hold a task for the todo list''' def __init__(self, title, finished=False, priority=1): super(TaskItem, self).__init__(title) self.title = title self.finished = finished self.priority = priority When printing the item's attributes via dir() I see that, when the model is populated, the last item it attempts to call is not my custom item object, but something else with less attributes and methods. Clearly there is something I haven't quite understood about this process. Also, if I use the models data() method as pointed out above, I get checkboxes in the cells which I don't want at this stage. Can somebody please help me understand where I go wrong? Attached is the whole test code. Cheers, frank P.S.: I am aware that the controller code shouldn't necessarily live in the QWidget's methods, this is just for testing which I will clean up once I get how it all connects again _______________________________________________ PySide mailing list PySide at qt-project.org http://lists.qt-project.org/mailman/listinfo/pyside _______________________________________________ PySide mailing list PySide at qt-project.org http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From a.richi at bluewin.ch Sun Oct 13 00:39:11 2013 From: a.richi at bluewin.ch (Aaron Richiger) Date: Sun, 13 Oct 2013 00:39:11 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <5259c8d3.486b0e0a.0d06.ffffc793@mx.google.com> References: <848951203488568137@unknownmsgid>, <5259B5D5.8000505@ohufx.com> <5259c8d3.486b0e0a.0d06.ffffc793@mx.google.com> Message-ID: <5259CF8F.9090602@bluewin.ch> Hello! Tibolds approach would work (and could result in a nicer UI). Both solutions are possible, some thoughts about the QTableView approach: - your app smells like a future database app. QTableView is in advantage then, because by using QSqlTableModel, you get all the mapping betwenn the db and the model for free. - By using QTableView, sorting, filtering etc. is already included and if your table has manymany rows, it will be much faster than any self implemented filtering/sorting algorithm. But as long, as your todo list doesn't have thousands of entries (and I hope so for you:-), performance isn't an argument. Changes to your code to have the spinbox in the middle column only: priorityDelegate = SpinBoxDelegate(tableView) tableView.setItemDelegateForColumn(1, priorityDelegate) Like this, the first column remains "text-editable", and for the last column with the checkbox, you don't even necessarily have to implement a new delegate, reimplementing .flags(), setData() and data() methods of your model is enough (but if you want a pure checkbox without a label next to it, you have to write your own delegate, I could send you the code). Feel free to choose what ever way you want, both are perfectly doable, having advantages where the other variant has disadvantages... Cheers Aaron Am 13.10.2013 00:06, schrieb Tibold Kandrai: > If you ask me personally, I wouldn't use QTableWidget. Look into > QTreeView or QListWidget. > I think they are more suitable for such tasks and are easier to handle. > With QTreeView you can use QItemDelegate, to create a special rendering. > With QListWidget you can simply add a widget per row and inside the > widget you can put whatever. > ATM I'm in the middle of a 2000 km road trip so I can't rally provide > you sample's, but if you need help next week I'm glad to give you > samples how to use these widgets. > Cheers, > Tibold Kandrai > *From:* Frank Rueter | OHUfx > *Sent:* ?Saturday?, ?12? ?October? ?2013 ?22?:?49 > *To:* Tibold Kandrai > *Cc:* pyside at qt-project.org > Is this the best way to do it though? I.e. having one item per cell? s > there another way at all? > I'm still a bit lost in the model/view design and can't find the > answer online. > > I'm simply trying to have each row represent a "task" with a > title/description (string), a status (boolean) and a priority > (integer). For the integer I need a spin box and for the boolean I > need a checkbox. The examples I found online all seem to be doing > something slightly different and often use different ways which makes > matters more confusing. > > Here is what I have at the moment: > http://pastebin.com/H3GD0xVB > > The "status" and "priority" values don't display currnelty as I > haven't figured out how to properly assign a delegate to just those > cells. At the top I tried to define a n item delegete for a spin box > but I'm not sure how to properly assign it. > > Do I have to make the delegate draw different widgets (spin box / > checkbox) depending on data type, or can/should I use a different > delegate for each cell? > > I'm sure the answer is right in front of me, could you please help one > more time please?! > > Cheers, > frank > > > On 11/10/13 4:00 PM, Tibold Kandrai wrote: > > If you mean to use a QStandardItem per cell then yes. > Also for storing values that you want to display, use the > Qt.DisplayRole as role. > > Cheers, > Tibold Kandrai > ------------------------------------------------------------------------ > From: Frank Rueter | OHUfx > Sent: ?11/?10/?2013 14:35 > To: Tibold Kandrai > Cc: pyside at qt-project.org > Subject: Re: [PySide] simple QTableView example > > one more silly question if I may: > So if I have a task like this: > newTask = {'title':'new task', 'priority':1, 'status':False} > > and need to store the data in one row in the model I should use > three different items, one for each value, right?! > > e.g.: > > newTask = {'title':'new task', 'priority':1, 'status':False} > row = self.model.rowCount() > for column, attr in enumerate(['title', 'priority', > 'status']): > newItem = QtGui.QStandardItem(newTask[attr]) > self.model.setItem(row, column, newItem) > > then juggle delegates or widgets to use a spin box for the integer > and a checkbox for the boolean... > > Thanks for the help! > > Cheers, > frank > > On 10/10/13 11:44 PM, Tibold Kandrai wrote: > > Hey, > I'm not sure I understand the problem correctly. > If you want to store data in a cell or a QStandardItem, then > you need to use setData() and data(). > Generally you shouldn't need to subclass QStandardItem or > QStandardItemModel. > Here is an example how: > # Define roles > FINISHED_ROLE = QtCore.Qt.UserRole + 1 > PRIORITY_ROLE = QtCore.Qt.UserRole + 2 > # Create model > model = QtGui.QStandardItemModel() > item = QtGui.QStandarItem() > model.appendRow(item) > item_index = item.index() > # Store data using the item > item.setData(finished, FINISHED_ROLE) > item.setData(priority, PRIORITY_ROLE) > # Store data using the model > model.setData(item_index, finished, FINISHED_ROLE) > model.setData(item_index, priority, PRIORITY_ROLE) > # Retrieve data using the item > finished = item.data(FINISHED_ROLE) > priority = item.data(PRIORITY_ROLE) > # Retrieve data using the model > finished = model.data(item_index, FINISHED_ROLE) > priority = model.data(item_index, PRIORITY_ROLE) > In some cases like click event handlers, you have the model > and the item index, there it's easier to use the model methods > instead of finding the item and then getting the data. ? > Hope it helps. > Cheers, > Tibold > *From:* Frank Rueter | OHUfx > *Sent:* ?2013? ?October? ?10?, ?Thursday ?19?:?37 > *To:* pyside at qt-project.org > After looking at some more examples I think my approach of > storing multiple values in one item is fundamentally flawed. > Instead I should be using one item per cell and assign the > respective data, right?! > > I shall re-write the example accordingly, sorry for the noise. > > frank > > On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: > > I meant QTableView not QStandardTableView :/ > > On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: > > Hi all, > > after a bit of a break from PySide I am trying to wrap > my head around the model/view stuff again and am > trying to understand how a very simple example would > work where a QStandarItem has properties "title", > "priority" and "finished" which are displayed via a > QStandardTableView. > > I am struggling with understanding how to properly > display the above three properties in the table's > columns. I tried setting the data() method on the > model like this: > > / def data(self, index, role=QtCore.Qt.DisplayRole):// > // '''Return data based on index and role'''// > // item = self.itemFromIndex(index)// > // if index.column() == 0:// > // return item.title// > // elif index.column() == 1:// > // return item.finished// > // elif index.column() == 2:// > // return item.priority/ > > but for some reason it errors saying item does not > have attribute "finished" even though my item object s > declared like this: > > /class TaskItem(QtGui.QStandardItem):// > // '''Item to hold a task for the todo list'''// > //// > // def __init__(self, title, finished=False, > priority=1):// > // super(TaskItem, self).__init__(title)// > // self.title = title// > // self.finished = finished// > // self.priority = priority/ > > > When printing the item's attributes via dir() I see > that, when the model is populated, the last item it > attempts to call is not my custom item object, but > something else with less attributes and methods. > Clearly there is something I haven't quite understood > about this process. > > Also, if I use the models data() method as pointed out > above, I get checkboxes in the cells which I don't > want at this stage. > > Can somebody please help me understand where I go wrong? > Attached is the whole test code. > > Cheers, > frank > > P.S.: I am aware that the controller code shouldn't > necessarily live in the QWidget's methods, this is > just for testing which I will clean up once I get how > it all connects again > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside > > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside > > > > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From sebastian at risefx.com Sun Oct 13 00:43:02 2013 From: sebastian at risefx.com (Sebastian Elsner) Date: Sun, 13 Oct 2013 00:43:02 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <5259B5D5.8000505@ohufx.com> References: <848951203488568137@unknownmsgid> <5259B5D5.8000505@ohufx.com> Message-ID: <5259D076.8050002@risefx.com> Hi all, the approach I like most is described in this blog entry: http://www.saltycrane.com/blog/2007/06/pyqt-42-qabstracttablemodelqtableview/ I think this is what you want. Cheers Sebastian Am 12.10.2013 22:49, schrieb Frank Rueter | OHUfx: > Is this the best way to do it though? I.e. having one item per cell? s > there another way at all? > I'm still a bit lost in the model/view design and can't find the > answer online. > > I'm simply trying to have each row represent a "task" with a > title/description (string), a status (boolean) and a priority > (integer). For the integer I need a spin box and for the boolean I > need a checkbox. The examples I found online all seem to be doing > something slightly different and often use different ways which makes > matters more confusing. > > Here is what I have at the moment: > http://pastebin.com/H3GD0xVB > > The "status" and "priority" values don't display currnelty as I > haven't figured out how to properly assign a delegate to just those > cells. At the top I tried to define a n item delegete for a spin box > but I'm not sure how to properly assign it. > > Do I have to make the delegate draw different widgets (spin box / > checkbox) depending on data type, or can/should I use a different > delegate for each cell? > > I'm sure the answer is right in front of me, could you please help one > more time please?! > > Cheers, > frank > > > On 11/10/13 4:00 PM, Tibold Kandrai wrote: >> If you mean to use a QStandardItem per cell then yes. >> Also for storing values that you want to display, use the >> Qt.DisplayRole as role. >> >> Cheers, >> Tibold Kandrai >> ------------------------------------------------------------------------ >> From: Frank Rueter | OHUfx >> Sent: ?11/?10/?2013 14:35 >> To: Tibold Kandrai >> Cc: pyside at qt-project.org >> Subject: Re: [PySide] simple QTableView example >> >> one more silly question if I may: >> So if I have a task like this: >> newTask = {'title':'new task', 'priority':1, 'status':False} >> >> and need to store the data in one row in the model I should use three >> different items, one for each value, right?! >> >> e.g.: >> >> newTask = {'title':'new task', 'priority':1, 'status':False} >> row = self.model.rowCount() >> for column, attr in enumerate(['title', 'priority', 'status']): >> newItem = QtGui.QStandardItem(newTask[attr]) >> self.model.setItem(row, column, newItem) >> >> then juggle delegates or widgets to use a spin box for the integer >> and a checkbox for the boolean... >> >> Thanks for the help! >> >> Cheers, >> frank >> >> On 10/10/13 11:44 PM, Tibold Kandrai wrote: >>> Hey, >>> I'm not sure I understand the problem correctly. >>> If you want to store data in a cell or a QStandardItem, then you >>> need to use setData() and data(). >>> Generally you shouldn't need to subclass QStandardItem or >>> QStandardItemModel. >>> Here is an example how: >>> # Define roles >>> FINISHED_ROLE = QtCore.Qt.UserRole + 1 >>> PRIORITY_ROLE = QtCore.Qt.UserRole + 2 >>> # Create model >>> model = QtGui.QStandardItemModel() >>> item = QtGui.QStandarItem() >>> model.appendRow(item) >>> item_index = item.index() >>> # Store data using the item >>> item.setData(finished, FINISHED_ROLE) >>> item.setData(priority, PRIORITY_ROLE) >>> # Store data using the model >>> model.setData(item_index, finished, FINISHED_ROLE) >>> model.setData(item_index, priority, PRIORITY_ROLE) >>> # Retrieve data using the item >>> finished = item.data(FINISHED_ROLE) >>> priority = item.data(PRIORITY_ROLE) >>> # Retrieve data using the model >>> finished = model.data(item_index, FINISHED_ROLE) >>> priority = model.data(item_index, PRIORITY_ROLE) >>> In some cases like click event handlers, you have the model and the >>> item index, there it's easier to use the model methods instead of >>> finding the item and then getting the data. ? >>> Hope it helps. >>> Cheers, >>> Tibold >>> *From:* Frank Rueter | OHUfx >>> *Sent:* ?2013? ?October? ?10?, ?Thursday ?19?:?37 >>> *To:* pyside at qt-project.org >>> After looking at some more examples I think my approach of storing >>> multiple values in one item is fundamentally flawed. >>> Instead I should be using one item per cell and assign the >>> respective data, right?! >>> >>> I shall re-write the example accordingly, sorry for the noise. >>> >>> frank >>> >>> On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: >>> >>> I meant QTableView not QStandardTableView :/ >>> >>> On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: >>> >>> Hi all, >>> >>> after a bit of a break from PySide I am trying to wrap my >>> head around the model/view stuff again and am trying to >>> understand how a very simple example would work where a >>> QStandarItem has properties "title", "priority" and >>> "finished" which are displayed via a QStandardTableView. >>> >>> I am struggling with understanding how to properly display >>> the above three properties in the table's columns. I tried >>> setting the data() method on the model like this: >>> >>> / def data(self, index, role=QtCore.Qt.DisplayRole):// >>> // '''Return data based on index and role'''// >>> // item = self.itemFromIndex(index)// >>> // if index.column() == 0:// >>> // return item.title// >>> // elif index.column() == 1:// >>> // return item.finished// >>> // elif index.column() == 2:// >>> // return item.priority/ >>> >>> but for some reason it errors saying item does not have >>> attribute "finished" even though my item object s declared >>> like this: >>> >>> /class TaskItem(QtGui.QStandardItem):// >>> // '''Item to hold a task for the todo list'''// >>> //// >>> // def __init__(self, title, finished=False, priority=1):// >>> // super(TaskItem, self).__init__(title)// >>> // self.title = title// >>> // self.finished = finished// >>> // self.priority = priority/ >>> >>> >>> When printing the item's attributes via dir() I see that, >>> when the model is populated, the last item it attempts to >>> call is not my custom item object, but something else with >>> less attributes and methods. Clearly there is something I >>> haven't quite understood about this process. >>> >>> Also, if I use the models data() method as pointed out above, >>> I get checkboxes in the cells which I don't want at this stage. >>> >>> Can somebody please help me understand where I go wrong? >>> Attached is the whole test code. >>> >>> Cheers, >>> frank >>> >>> P.S.: I am aware that the controller code shouldn't >>> necessarily live in the QWidget's methods, this is just for >>> testing which I will clean up once I get how it all connects >>> again >>> >>> >>> _______________________________________________ >>> PySide mailing list >>> PySide at qt-project.org >>> http://lists.qt-project.org/mailman/listinfo/pyside >>> >>> >>> >>> >>> _______________________________________________ >>> PySide mailing list >>> PySide at qt-project.org >>> http://lists.qt-project.org/mailman/listinfo/pyside >>> >>> >> > > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at ohufx.com Sun Oct 13 12:57:25 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Sun, 13 Oct 2013 12:57:25 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <5259D076.8050002@risefx.com> References: <848951203488568137@unknownmsgid> <5259B5D5.8000505@ohufx.com> <5259D076.8050002@risefx.com> Message-ID: <525A7C95.4070702@ohufx.com> Thanks Sebastian, I don't see en editor in this though, so the result for me in PySide (after removing the QVariant references) is a static, non-ediablte table. On 13/10/13 12:43 AM, Sebastian Elsner wrote: > Hi all, > > the approach I like most is described in this blog entry: > http://www.saltycrane.com/blog/2007/06/pyqt-42-qabstracttablemodelqtableview/ > > I think this is what you want. > > Cheers > > Sebastian > > > Am 12.10.2013 22:49, schrieb Frank Rueter | OHUfx: >> Is this the best way to do it though? I.e. having one item per cell? >> s there another way at all? >> I'm still a bit lost in the model/view design and can't find the >> answer online. >> >> I'm simply trying to have each row represent a "task" with a >> title/description (string), a status (boolean) and a priority >> (integer). For the integer I need a spin box and for the boolean I >> need a checkbox. The examples I found online all seem to be doing >> something slightly different and often use different ways which makes >> matters more confusing. >> >> Here is what I have at the moment: >> http://pastebin.com/H3GD0xVB >> >> The "status" and "priority" values don't display currnelty as I >> haven't figured out how to properly assign a delegate to just those >> cells. At the top I tried to define a n item delegete for a spin box >> but I'm not sure how to properly assign it. >> >> Do I have to make the delegate draw different widgets (spin box / >> checkbox) depending on data type, or can/should I use a different >> delegate for each cell? >> >> I'm sure the answer is right in front of me, could you please help >> one more time please?! >> >> Cheers, >> frank >> >> >> On 11/10/13 4:00 PM, Tibold Kandrai wrote: >>> If you mean to use a QStandardItem per cell then yes. >>> Also for storing values that you want to display, use the >>> Qt.DisplayRole as role. >>> >>> Cheers, >>> Tibold Kandrai >>> ------------------------------------------------------------------------ >>> >>> From: Frank Rueter | OHUfx >>> Sent: ?11/?10/?2013 14:35 >>> To: Tibold Kandrai >>> Cc: pyside at qt-project.org >>> Subject: Re: [PySide] simple QTableView example >>> >>> one more silly question if I may: >>> So if I have a task like this: >>> newTask = {'title':'new task', 'priority':1, 'status':False} >>> >>> and need to store the data in one row in the model I should use >>> three different items, one for each value, right?! >>> >>> e.g.: >>> >>> newTask = {'title':'new task', 'priority':1, 'status':False} >>> row = self.model.rowCount() >>> for column, attr in enumerate(['title', 'priority', 'status']): >>> newItem = QtGui.QStandardItem(newTask[attr]) >>> self.model.setItem(row, column, newItem) >>> >>> then juggle delegates or widgets to use a spin box for the integer >>> and a checkbox for the boolean... >>> >>> Thanks for the help! >>> >>> Cheers, >>> frank >>> >>> On 10/10/13 11:44 PM, Tibold Kandrai wrote: >>>> Hey, >>>> I'm not sure I understand the problem correctly. >>>> If you want to store data in a cell or a QStandardItem, then you >>>> need to use setData() and data(). >>>> Generally you shouldn't need to subclass QStandardItem or >>>> QStandardItemModel. >>>> Here is an example how: >>>> # Define roles >>>> FINISHED_ROLE = QtCore.Qt.UserRole + 1 >>>> PRIORITY_ROLE = QtCore.Qt.UserRole + 2 >>>> # Create model >>>> model = QtGui.QStandardItemModel() >>>> item = QtGui.QStandarItem() >>>> model.appendRow(item) >>>> item_index = item.index() >>>> # Store data using the item >>>> item.setData(finished, FINISHED_ROLE) >>>> item.setData(priority, PRIORITY_ROLE) >>>> # Store data using the model >>>> model.setData(item_index, finished, FINISHED_ROLE) >>>> model.setData(item_index, priority, PRIORITY_ROLE) >>>> # Retrieve data using the item >>>> finished = item.data(FINISHED_ROLE) >>>> priority = item.data(PRIORITY_ROLE) >>>> # Retrieve data using the model >>>> finished = model.data(item_index, FINISHED_ROLE) >>>> priority = model.data(item_index, PRIORITY_ROLE) >>>> In some cases like click event handlers, you have the model and the >>>> item index, there it's easier to use the model methods instead of >>>> finding the item and then getting the data. ? >>>> Hope it helps. >>>> Cheers, >>>> Tibold >>>> *From:* Frank Rueter | OHUfx >>>> *Sent:* ?2013? ?October? ?10?, ?Thursday ?19?:?37 >>>> *To:* pyside at qt-project.org >>>> After looking at some more examples I think my approach of storing >>>> multiple values in one item is fundamentally flawed. >>>> Instead I should be using one item per cell and assign the >>>> respective data, right?! >>>> >>>> I shall re-write the example accordingly, sorry for the noise. >>>> >>>> frank >>>> >>>> On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: >>>> >>>> I meant QTableView not QStandardTableView :/ >>>> >>>> On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: >>>> >>>> Hi all, >>>> >>>> after a bit of a break from PySide I am trying to wrap my >>>> head around the model/view stuff again and am trying to >>>> understand how a very simple example would work where a >>>> QStandarItem has properties "title", "priority" and >>>> "finished" which are displayed via a QStandardTableView. >>>> >>>> I am struggling with understanding how to properly display >>>> the above three properties in the table's columns. I tried >>>> setting the data() method on the model like this: >>>> >>>> / def data(self, index, role=QtCore.Qt.DisplayRole):// >>>> // '''Return data based on index and role'''// >>>> // item = self.itemFromIndex(index)// >>>> // if index.column() == 0:// >>>> // return item.title// >>>> // elif index.column() == 1:// >>>> // return item.finished// >>>> // elif index.column() == 2:// >>>> // return item.priority/ >>>> >>>> but for some reason it errors saying item does not have >>>> attribute "finished" even though my item object s declared >>>> like this: >>>> >>>> /class TaskItem(QtGui.QStandardItem):// >>>> // '''Item to hold a task for the todo list'''// >>>> //// >>>> // def __init__(self, title, finished=False, priority=1):// >>>> // super(TaskItem, self).__init__(title)// >>>> // self.title = title// >>>> // self.finished = finished// >>>> // self.priority = priority/ >>>> >>>> >>>> When printing the item's attributes via dir() I see that, >>>> when the model is populated, the last item it attempts to >>>> call is not my custom item object, but something else with >>>> less attributes and methods. Clearly there is something I >>>> haven't quite understood about this process. >>>> >>>> Also, if I use the models data() method as pointed out above, >>>> I get checkboxes in the cells which I don't want at this >>>> stage. >>>> >>>> Can somebody please help me understand where I go wrong? >>>> Attached is the whole test code. >>>> >>>> Cheers, >>>> frank >>>> >>>> P.S.: I am aware that the controller code shouldn't >>>> necessarily live in the QWidget's methods, this is just for >>>> testing which I will clean up once I get how it all connects >>>> again >>>> >>>> >>>> _______________________________________________ >>>> PySide mailing list >>>> PySide at qt-project.org >>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> PySide mailing list >>>> PySide at qt-project.org >>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>> >>>> >>> >> >> >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From sebastian at risefx.com Sun Oct 13 13:16:22 2013 From: sebastian at risefx.com (Sebastian Elsner) Date: Sun, 13 Oct 2013 13:16:22 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <525A7C95.4070702@ohufx.com> References: <848951203488568137@unknownmsgid> <5259B5D5.8000505@ohufx.com> <5259D076.8050002@risefx.com> <525A7C95.4070702@ohufx.com> Message-ID: <525A8106.80700@risefx.com> This is correct. From the docs: Editable models need to implement setData (), and implement flags () to return a value containing Qt::ItemIsEditable . http://stackoverflow.com/questions/11736560/edit-table-in-pyqt-using-qabstracttablemodel Am 13.10.2013 12:57, schrieb Frank Rueter | OHUfx: > Thanks Sebastian, > > I don't see en editor in this though, so the result for me in PySide > (after removing the QVariant references) is a static, non-ediablte table. > > > On 13/10/13 12:43 AM, Sebastian Elsner wrote: >> Hi all, >> >> the approach I like most is described in this blog entry: >> http://www.saltycrane.com/blog/2007/06/pyqt-42-qabstracttablemodelqtableview/ >> >> I think this is what you want. >> >> Cheers >> >> Sebastian >> >> >> Am 12.10.2013 22:49, schrieb Frank Rueter | OHUfx: >>> Is this the best way to do it though? I.e. having one item per cell? >>> s there another way at all? >>> I'm still a bit lost in the model/view design and can't find the >>> answer online. >>> >>> I'm simply trying to have each row represent a "task" with a >>> title/description (string), a status (boolean) and a priority >>> (integer). For the integer I need a spin box and for the boolean I >>> need a checkbox. The examples I found online all seem to be doing >>> something slightly different and often use different ways which >>> makes matters more confusing. >>> >>> Here is what I have at the moment: >>> http://pastebin.com/H3GD0xVB >>> >>> The "status" and "priority" values don't display currnelty as I >>> haven't figured out how to properly assign a delegate to just those >>> cells. At the top I tried to define a n item delegete for a spin box >>> but I'm not sure how to properly assign it. >>> >>> Do I have to make the delegate draw different widgets (spin box / >>> checkbox) depending on data type, or can/should I use a different >>> delegate for each cell? >>> >>> I'm sure the answer is right in front of me, could you please help >>> one more time please?! >>> >>> Cheers, >>> frank >>> >>> >>> On 11/10/13 4:00 PM, Tibold Kandrai wrote: >>>> If you mean to use a QStandardItem per cell then yes. >>>> Also for storing values that you want to display, use the >>>> Qt.DisplayRole as role. >>>> >>>> Cheers, >>>> Tibold Kandrai >>>> ------------------------------------------------------------------------ >>>> >>>> From: Frank Rueter | OHUfx >>>> Sent: ?11/?10/?2013 14:35 >>>> To: Tibold Kandrai >>>> Cc: pyside at qt-project.org >>>> Subject: Re: [PySide] simple QTableView example >>>> >>>> one more silly question if I may: >>>> So if I have a task like this: >>>> newTask = {'title':'new task', 'priority':1, 'status':False} >>>> >>>> and need to store the data in one row in the model I should use >>>> three different items, one for each value, right?! >>>> >>>> e.g.: >>>> >>>> newTask = {'title':'new task', 'priority':1, 'status':False} >>>> row = self.model.rowCount() >>>> for column, attr in enumerate(['title', 'priority', >>>> 'status']): >>>> newItem = QtGui.QStandardItem(newTask[attr]) >>>> self.model.setItem(row, column, newItem) >>>> >>>> then juggle delegates or widgets to use a spin box for the integer >>>> and a checkbox for the boolean... >>>> >>>> Thanks for the help! >>>> >>>> Cheers, >>>> frank >>>> >>>> On 10/10/13 11:44 PM, Tibold Kandrai wrote: >>>>> Hey, >>>>> I'm not sure I understand the problem correctly. >>>>> If you want to store data in a cell or a QStandardItem, then you >>>>> need to use setData() and data(). >>>>> Generally you shouldn't need to subclass QStandardItem or >>>>> QStandardItemModel. >>>>> Here is an example how: >>>>> # Define roles >>>>> FINISHED_ROLE = QtCore.Qt.UserRole + 1 >>>>> PRIORITY_ROLE = QtCore.Qt.UserRole + 2 >>>>> # Create model >>>>> model = QtGui.QStandardItemModel() >>>>> item = QtGui.QStandarItem() >>>>> model.appendRow(item) >>>>> item_index = item.index() >>>>> # Store data using the item >>>>> item.setData(finished, FINISHED_ROLE) >>>>> item.setData(priority, PRIORITY_ROLE) >>>>> # Store data using the model >>>>> model.setData(item_index, finished, FINISHED_ROLE) >>>>> model.setData(item_index, priority, PRIORITY_ROLE) >>>>> # Retrieve data using the item >>>>> finished = item.data(FINISHED_ROLE) >>>>> priority = item.data(PRIORITY_ROLE) >>>>> # Retrieve data using the model >>>>> finished = model.data(item_index, FINISHED_ROLE) >>>>> priority = model.data(item_index, PRIORITY_ROLE) >>>>> In some cases like click event handlers, you have the model and >>>>> the item index, there it's easier to use the model methods instead >>>>> of finding the item and then getting the data. ? >>>>> Hope it helps. >>>>> Cheers, >>>>> Tibold >>>>> *From:* Frank Rueter | OHUfx >>>>> *Sent:* ?2013? ?October? ?10?, ?Thursday ?19?:?37 >>>>> *To:* pyside at qt-project.org >>>>> After looking at some more examples I think my approach of storing >>>>> multiple values in one item is fundamentally flawed. >>>>> Instead I should be using one item per cell and assign the >>>>> respective data, right?! >>>>> >>>>> I shall re-write the example accordingly, sorry for the noise. >>>>> >>>>> frank >>>>> >>>>> On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: >>>>> >>>>> I meant QTableView not QStandardTableView :/ >>>>> >>>>> On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: >>>>> >>>>> Hi all, >>>>> >>>>> after a bit of a break from PySide I am trying to wrap my >>>>> head around the model/view stuff again and am trying to >>>>> understand how a very simple example would work where a >>>>> QStandarItem has properties "title", "priority" and >>>>> "finished" which are displayed via a QStandardTableView. >>>>> >>>>> I am struggling with understanding how to properly display >>>>> the above three properties in the table's columns. I tried >>>>> setting the data() method on the model like this: >>>>> >>>>> / def data(self, index, role=QtCore.Qt.DisplayRole):// >>>>> // '''Return data based on index and role'''// >>>>> // item = self.itemFromIndex(index)// >>>>> // if index.column() == 0:// >>>>> // return item.title// >>>>> // elif index.column() == 1:// >>>>> // return item.finished// >>>>> // elif index.column() == 2:// >>>>> // return item.priority/ >>>>> >>>>> but for some reason it errors saying item does not have >>>>> attribute "finished" even though my item object s declared >>>>> like this: >>>>> >>>>> /class TaskItem(QtGui.QStandardItem):// >>>>> // '''Item to hold a task for the todo list'''// >>>>> //// >>>>> // def __init__(self, title, finished=False, >>>>> priority=1):// >>>>> // super(TaskItem, self).__init__(title)// >>>>> // self.title = title// >>>>> // self.finished = finished// >>>>> // self.priority = priority/ >>>>> >>>>> >>>>> When printing the item's attributes via dir() I see that, >>>>> when the model is populated, the last item it attempts to >>>>> call is not my custom item object, but something else with >>>>> less attributes and methods. Clearly there is something I >>>>> haven't quite understood about this process. >>>>> >>>>> Also, if I use the models data() method as pointed out above, >>>>> I get checkboxes in the cells which I don't want at this >>>>> stage. >>>>> >>>>> Can somebody please help me understand where I go wrong? >>>>> Attached is the whole test code. >>>>> >>>>> Cheers, >>>>> frank >>>>> >>>>> P.S.: I am aware that the controller code shouldn't >>>>> necessarily live in the QWidget's methods, this is just for >>>>> testing which I will clean up once I get how it all connects >>>>> again >>>>> >>>>> >>>>> _______________________________________________ >>>>> PySide mailing list >>>>> PySide at qt-project.org >>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>> >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> PySide mailing list >>>>> PySide at qt-project.org >>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>> >>>>> >>>> >>> >>> >>> >>> >>> _______________________________________________ >>> PySide mailing list >>> PySide at qt-project.org >>> http://lists.qt-project.org/mailman/listinfo/pyside >> >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside > > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at ohufx.com Sun Oct 13 13:18:06 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Sun, 13 Oct 2013 13:18:06 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <5259CF8F.9090602@bluewin.ch> References: <848951203488568137@unknownmsgid>, <5259B5D5.8000505@ohufx.com> <5259c8d3.486b0e0a.0d06.ffffc793@mx.google.com> <5259CF8F.9090602@bluewin.ch> Message-ID: <525A816E.2050200@ohufx.com> Great, thanks Tibold and Aaron! That all makes sense. Incidentally I do have planned a bit more than just the standard table UI but thought I'd leave that for when I'm more comfortable with the basic concepts again. So am keen to test all suggested approaches and have a feeling I might have to go with a custom solution as I want some animation to happen when sorting (each line moving to it's new position) - but that's for later, for now I will stick to the basics. Aaron, when trying the setItemDelegateForColumn (sorry, how could I not have seen this one before) things work fine but I have to cast the incoming data to int() explicitly in side the setEditorData. The setModelData method seems to automatically cast the integer back to a string. Is this the right way to do it? def setEditorData(self, spinBox, index): value = index.model().data(index) spinBox.setValue(*int(value)*)*# cast string to int* def setModelData(self, spinBox, model, index): spinBox.interpretText() value = spinBox.value() model.setData(index, *value*)*# no need to cast int back to string?* Looking ahead: If I want to make the rows/tasks animate to their new positions upon sorting, can I re-implement the paint methods of, say, a QAbstractItemView or do I have to go back further and do more manual work? I need to stick to the standard PySide package for this for various reasons. Cheers and thanks again Tibold, Aaron and Sebastian, you are a great help as usual! frank On 13/10/13 12:39 AM, Aaron Richiger wrote: > Hello! > > Tibolds approach would work (and could result in a nicer UI). Both > solutions are possible, some thoughts about the QTableView approach: > > - your app smells like a future database app. QTableView is in > advantage then, because by using QSqlTableModel, you get all the > mapping betwenn the db and the model for free. > - By using QTableView, sorting, filtering etc. is already included and > if your table has manymany rows, it will be much faster than any self > implemented filtering/sorting algorithm. But as long, as your todo > list doesn't have thousands of entries (and I hope so for you:-), > performance isn't an argument. > > Changes to your code to have the spinbox in the middle column only: > > priorityDelegate = SpinBoxDelegate(tableView) > tableView.setItemDelegateForColumn(1, priorityDelegate) > > Like this, the first column remains "text-editable", and for the last > column with the checkbox, you don't even necessarily have to implement > a new delegate, reimplementing .flags(), setData() and data() methods > of your model is enough (but if you want a pure checkbox without a > label next to it, you have to write your own delegate, I could send > you the code). > > Feel free to choose what ever way you want, both are perfectly doable, > having advantages where the other variant has disadvantages... > > Cheers > Aaron > > > Am 13.10.2013 00:06, schrieb Tibold Kandrai: >> If you ask me personally, I wouldn't use QTableWidget. Look into >> QTreeView or QListWidget. >> I think they are more suitable for such tasks and are easier to handle. >> With QTreeView you can use QItemDelegate, to create a special rendering. >> With QListWidget you can simply add a widget per row and inside the >> widget you can put whatever. >> ATM I'm in the middle of a 2000 km road trip so I can't rally provide >> you sample's, but if you need help next week I'm glad to give you >> samples how to use these widgets. >> Cheers, >> Tibold Kandrai >> *From:* Frank Rueter | OHUfx >> *Sent:* ?Saturday?, ?12? ?October? ?2013 ?22?:?49 >> *To:* Tibold Kandrai >> *Cc:* pyside at qt-project.org >> Is this the best way to do it though? I.e. having one item per cell? >> s there another way at all? >> I'm still a bit lost in the model/view design and can't find the >> answer online. >> >> I'm simply trying to have each row represent a "task" with a >> title/description (string), a status (boolean) and a priority >> (integer). For the integer I need a spin box and for the boolean I >> need a checkbox. The examples I found online all seem to be doing >> something slightly different and often use different ways which makes >> matters more confusing. >> >> Here is what I have at the moment: >> http://pastebin.com/H3GD0xVB >> >> The "status" and "priority" values don't display currnelty as I >> haven't figured out how to properly assign a delegate to just those >> cells. At the top I tried to define a n item delegete for a spin box >> but I'm not sure how to properly assign it. >> >> Do I have to make the delegate draw different widgets (spin box / >> checkbox) depending on data type, or can/should I use a different >> delegate for each cell? >> >> I'm sure the answer is right in front of me, could you please help >> one more time please?! >> >> Cheers, >> frank >> >> >> On 11/10/13 4:00 PM, Tibold Kandrai wrote: >> >> If you mean to use a QStandardItem per cell then yes. >> Also for storing values that you want to display, use the >> Qt.DisplayRole as role. >> >> Cheers, >> Tibold Kandrai >> ------------------------------------------------------------------------ >> From: Frank Rueter | OHUfx >> Sent: ?11/?10/?2013 14:35 >> To: Tibold Kandrai >> Cc: pyside at qt-project.org >> Subject: Re: [PySide] simple QTableView example >> >> one more silly question if I may: >> So if I have a task like this: >> newTask = {'title':'new task', 'priority':1, 'status':False} >> >> and need to store the data in one row in the model I should use >> three different items, one for each value, right?! >> >> e.g.: >> >> newTask = {'title':'new task', 'priority':1, 'status':False} >> row = self.model.rowCount() >> for column, attr in enumerate(['title', 'priority', >> 'status']): >> newItem = QtGui.QStandardItem(newTask[attr]) >> self.model.setItem(row, column, newItem) >> >> then juggle delegates or widgets to use a spin box for the >> integer and a checkbox for the boolean... >> >> Thanks for the help! >> >> Cheers, >> frank >> >> On 10/10/13 11:44 PM, Tibold Kandrai wrote: >> >> Hey, >> I'm not sure I understand the problem correctly. >> If you want to store data in a cell or a QStandardItem, then >> you need to use setData() and data(). >> Generally you shouldn't need to subclass QStandardItem or >> QStandardItemModel. >> Here is an example how: >> # Define roles >> FINISHED_ROLE = QtCore.Qt.UserRole + 1 >> PRIORITY_ROLE = QtCore.Qt.UserRole + 2 >> # Create model >> model = QtGui.QStandardItemModel() >> item = QtGui.QStandarItem() >> model.appendRow(item) >> item_index = item.index() >> # Store data using the item >> item.setData(finished, FINISHED_ROLE) >> item.setData(priority, PRIORITY_ROLE) >> # Store data using the model >> model.setData(item_index, finished, FINISHED_ROLE) >> model.setData(item_index, priority, PRIORITY_ROLE) >> # Retrieve data using the item >> finished = item.data(FINISHED_ROLE) >> priority = item.data(PRIORITY_ROLE) >> # Retrieve data using the model >> finished = model.data(item_index, FINISHED_ROLE) >> priority = model.data(item_index, PRIORITY_ROLE) >> In some cases like click event handlers, you have the model >> and the item index, there it's easier to use the model >> methods instead of finding the item and then getting the data. ? >> Hope it helps. >> Cheers, >> Tibold >> *From:* Frank Rueter | OHUfx >> *Sent:* ?2013? ?October? ?10?, ?Thursday ?19?:?37 >> *To:* pyside at qt-project.org >> After looking at some more examples I think my approach of >> storing multiple values in one item is fundamentally flawed. >> Instead I should be using one item per cell and assign the >> respective data, right?! >> >> I shall re-write the example accordingly, sorry for the noise. >> >> frank >> >> On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: >> >> I meant QTableView not QStandardTableView :/ >> >> On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: >> >> Hi all, >> >> after a bit of a break from PySide I am trying to >> wrap my head around the model/view stuff again and am >> trying to understand how a very simple example would >> work where a QStandarItem has properties "title", >> "priority" and "finished" which are displayed via a >> QStandardTableView. >> >> I am struggling with understanding how to properly >> display the above three properties in the table's >> columns. I tried setting the data() method on the >> model like this: >> >> / def data(self, index, role=QtCore.Qt.DisplayRole):// >> // '''Return data based on index and role'''// >> // item = self.itemFromIndex(index)// >> // if index.column() == 0:// >> // return item.title// >> // elif index.column() == 1:// >> // return item.finished// >> // elif index.column() == 2:// >> // return item.priority/ >> >> but for some reason it errors saying item does not >> have attribute "finished" even though my item object >> s declared like this: >> >> /class TaskItem(QtGui.QStandardItem):// >> // '''Item to hold a task for the todo list'''// >> //// >> // def __init__(self, title, finished=False, >> priority=1):// >> // super(TaskItem, self).__init__(title)// >> // self.title = title// >> // self.finished = finished// >> // self.priority = priority/ >> >> >> When printing the item's attributes via dir() I see >> that, when the model is populated, the last item it >> attempts to call is not my custom item object, but >> something else with less attributes and methods. >> Clearly there is something I haven't quite understood >> about this process. >> >> Also, if I use the models data() method as pointed >> out above, I get checkboxes in the cells which I >> don't want at this stage. >> >> Can somebody please help me understand where I go wrong? >> Attached is the whole test code. >> >> Cheers, >> frank >> >> P.S.: I am aware that the controller code shouldn't >> necessarily live in the QWidget's methods, this is >> just for testing which I will clean up once I get how >> it all connects again >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside >> >> >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside >> >> >> >> >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From a.richi at bluewin.ch Sun Oct 13 13:52:14 2013 From: a.richi at bluewin.ch (Aaron Richiger) Date: Sun, 13 Oct 2013 13:52:14 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <525A816E.2050200@ohufx.com> References: <848951203488568137@unknownmsgid>, <5259B5D5.8000505@ohufx.com> <5259c8d3.486b0e0a.0d06.ffffc793@mx.google.com> <5259CF8F.9090602@bluewin.ch> <525A816E.2050200@ohufx.com> Message-ID: <525A896E.9060902@bluewin.ch> Hello Frank! You're welcome. I will send you more details later (do not have too much time for the moment). But just to give you the direction: If the animation is a must-have, I would not go the way with QTableView nor the way with QListView or QTreeView. Without animation, those are perfect, but if you really want the fancy animations, I would do it like this: - Implement a widget to show a TODO-Item - Show them absolutely positioned one after the other - Implement buttons for "Add new", "Sort", "Filter" - In case of sort or filtering: calculate new position for each item, animate it to new position using QParallelAnimationGroup See you later! Aaron Am 13.10.2013 13:18, schrieb Frank Rueter | OHUfx: > Great, thanks Tibold and Aaron! That all makes sense. > > Incidentally I do have planned a bit more than just the standard table > UI but thought I'd leave that for when I'm more comfortable with the > basic concepts again. > So am keen to test all suggested approaches and have a feeling I might > have to go with a custom solution as I want some animation to happen > when sorting (each line moving to it's new position) - but that's for > later, for now I will stick to the basics. > > Aaron, when trying the setItemDelegateForColumn (sorry, how could I > not have seen this one before) things work fine but I have to cast the > incoming data to int() explicitly in side the setEditorData. The > setModelData method seems to automatically cast the integer back to a > string. Is this the right way to do it? > > def setEditorData(self, spinBox, index): > value = index.model().data(index) > spinBox.setValue(*int(value)*)*# cast string to int* > > def setModelData(self, spinBox, model, index): > spinBox.interpretText() > value = spinBox.value() > model.setData(index, *value*)*# no need to cast int back to > string?* > > > Looking ahead: If I want to make the rows/tasks animate to their new > positions upon sorting, can I re-implement the paint methods of, say, > a QAbstractItemView or do I have to go back further and do more manual > work? > I need to stick to the standard PySide package for this for various > reasons. > > Cheers and thanks again Tibold, Aaron and Sebastian, you are a great > help as usual! > > frank > > > > On 13/10/13 12:39 AM, Aaron Richiger wrote: >> Hello! >> >> Tibolds approach would work (and could result in a nicer UI). Both >> solutions are possible, some thoughts about the QTableView approach: >> >> - your app smells like a future database app. QTableView is in >> advantage then, because by using QSqlTableModel, you get all the >> mapping betwenn the db and the model for free. >> - By using QTableView, sorting, filtering etc. is already included >> and if your table has manymany rows, it will be much faster than any >> self implemented filtering/sorting algorithm. But as long, as your >> todo list doesn't have thousands of entries (and I hope so for >> you:-), performance isn't an argument. >> >> Changes to your code to have the spinbox in the middle column only: >> >> priorityDelegate = SpinBoxDelegate(tableView) >> tableView.setItemDelegateForColumn(1, priorityDelegate) >> >> Like this, the first column remains "text-editable", and for the last >> column with the checkbox, you don't even necessarily have to >> implement a new delegate, reimplementing .flags(), setData() and >> data() methods of your model is enough (but if you want a pure >> checkbox without a label next to it, you have to write your own >> delegate, I could send you the code). >> >> Feel free to choose what ever way you want, both are perfectly >> doable, having advantages where the other variant has disadvantages... >> >> Cheers >> Aaron >> >> >> Am 13.10.2013 00:06, schrieb Tibold Kandrai: >>> If you ask me personally, I wouldn't use QTableWidget. Look into >>> QTreeView or QListWidget. >>> I think they are more suitable for such tasks and are easier to handle. >>> With QTreeView you can use QItemDelegate, to create a special rendering. >>> With QListWidget you can simply add a widget per row and inside the >>> widget you can put whatever. >>> ATM I'm in the middle of a 2000 km road trip so I can't rally >>> provide you sample's, but if you need help next week I'm glad to >>> give you samples how to use these widgets. >>> Cheers, >>> Tibold Kandrai >>> *From:* Frank Rueter | OHUfx >>> *Sent:* ?Saturday?, ?12? ?October? ?2013 ?22?:?49 >>> *To:* Tibold Kandrai >>> *Cc:* pyside at qt-project.org >>> Is this the best way to do it though? I.e. having one item per cell? >>> s there another way at all? >>> I'm still a bit lost in the model/view design and can't find the >>> answer online. >>> >>> I'm simply trying to have each row represent a "task" with a >>> title/description (string), a status (boolean) and a priority >>> (integer). For the integer I need a spin box and for the boolean I >>> need a checkbox. The examples I found online all seem to be doing >>> something slightly different and often use different ways which >>> makes matters more confusing. >>> >>> Here is what I have at the moment: >>> http://pastebin.com/H3GD0xVB >>> >>> The "status" and "priority" values don't display currnelty as I >>> haven't figured out how to properly assign a delegate to just those >>> cells. At the top I tried to define a n item delegete for a spin box >>> but I'm not sure how to properly assign it. >>> >>> Do I have to make the delegate draw different widgets (spin box / >>> checkbox) depending on data type, or can/should I use a different >>> delegate for each cell? >>> >>> I'm sure the answer is right in front of me, could you please help >>> one more time please?! >>> >>> Cheers, >>> frank >>> >>> >>> On 11/10/13 4:00 PM, Tibold Kandrai wrote: >>> >>> If you mean to use a QStandardItem per cell then yes. >>> Also for storing values that you want to display, use the >>> Qt.DisplayRole as role. >>> >>> Cheers, >>> Tibold Kandrai >>> ------------------------------------------------------------------------ >>> From: Frank Rueter | OHUfx >>> Sent: ?11/?10/?2013 14:35 >>> To: Tibold Kandrai >>> Cc: pyside at qt-project.org >>> Subject: Re: [PySide] simple QTableView example >>> >>> one more silly question if I may: >>> So if I have a task like this: >>> newTask = {'title':'new task', 'priority':1, 'status':False} >>> >>> and need to store the data in one row in the model I should use >>> three different items, one for each value, right?! >>> >>> e.g.: >>> >>> newTask = {'title':'new task', 'priority':1, 'status':False} >>> row = self.model.rowCount() >>> for column, attr in enumerate(['title', 'priority', >>> 'status']): >>> newItem = QtGui.QStandardItem(newTask[attr]) >>> self.model.setItem(row, column, newItem) >>> >>> then juggle delegates or widgets to use a spin box for the >>> integer and a checkbox for the boolean... >>> >>> Thanks for the help! >>> >>> Cheers, >>> frank >>> >>> On 10/10/13 11:44 PM, Tibold Kandrai wrote: >>> >>> Hey, >>> I'm not sure I understand the problem correctly. >>> If you want to store data in a cell or a QStandardItem, then >>> you need to use setData() and data(). >>> Generally you shouldn't need to subclass QStandardItem or >>> QStandardItemModel. >>> Here is an example how: >>> # Define roles >>> FINISHED_ROLE = QtCore.Qt.UserRole + 1 >>> PRIORITY_ROLE = QtCore.Qt.UserRole + 2 >>> # Create model >>> model = QtGui.QStandardItemModel() >>> item = QtGui.QStandarItem() >>> model.appendRow(item) >>> item_index = item.index() >>> # Store data using the item >>> item.setData(finished, FINISHED_ROLE) >>> item.setData(priority, PRIORITY_ROLE) >>> # Store data using the model >>> model.setData(item_index, finished, FINISHED_ROLE) >>> model.setData(item_index, priority, PRIORITY_ROLE) >>> # Retrieve data using the item >>> finished = item.data(FINISHED_ROLE) >>> priority = item.data(PRIORITY_ROLE) >>> # Retrieve data using the model >>> finished = model.data(item_index, FINISHED_ROLE) >>> priority = model.data(item_index, PRIORITY_ROLE) >>> In some cases like click event handlers, you have the model >>> and the item index, there it's easier to use the model >>> methods instead of finding the item and then getting the data. ? >>> Hope it helps. >>> Cheers, >>> Tibold >>> *From:* Frank Rueter | OHUfx >>> *Sent:* ?2013? ?October? ?10?, ?Thursday ?19?:?37 >>> *To:* pyside at qt-project.org >>> After looking at some more examples I think my approach of >>> storing multiple values in one item is fundamentally flawed. >>> Instead I should be using one item per cell and assign the >>> respective data, right?! >>> >>> I shall re-write the example accordingly, sorry for the noise. >>> >>> frank >>> >>> On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: >>> >>> I meant QTableView not QStandardTableView :/ >>> >>> On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: >>> >>> Hi all, >>> >>> after a bit of a break from PySide I am trying to >>> wrap my head around the model/view stuff again and >>> am trying to understand how a very simple example >>> would work where a QStandarItem has properties >>> "title", "priority" and "finished" which are >>> displayed via a QStandardTableView. >>> >>> I am struggling with understanding how to properly >>> display the above three properties in the table's >>> columns. I tried setting the data() method on the >>> model like this: >>> >>> / def data(self, index, >>> role=QtCore.Qt.DisplayRole):// >>> // '''Return data based on index and role'''// >>> // item = self.itemFromIndex(index)// >>> // if index.column() == 0:// >>> // return item.title// >>> // elif index.column() == 1:// >>> // return item.finished// >>> // elif index.column() == 2:// >>> // return item.priority/ >>> >>> but for some reason it errors saying item does not >>> have attribute "finished" even though my item object >>> s declared like this: >>> >>> /class TaskItem(QtGui.QStandardItem):// >>> // '''Item to hold a task for the todo list'''// >>> //// >>> // def __init__(self, title, finished=False, >>> priority=1):// >>> // super(TaskItem, self).__init__(title)// >>> // self.title = title// >>> // self.finished = finished// >>> // self.priority = priority/ >>> >>> >>> When printing the item's attributes via dir() I see >>> that, when the model is populated, the last item it >>> attempts to call is not my custom item object, but >>> something else with less attributes and methods. >>> Clearly there is something I haven't quite >>> understood about this process. >>> >>> Also, if I use the models data() method as pointed >>> out above, I get checkboxes in the cells which I >>> don't want at this stage. >>> >>> Can somebody please help me understand where I go wrong? >>> Attached is the whole test code. >>> >>> Cheers, >>> frank >>> >>> P.S.: I am aware that the controller code shouldn't >>> necessarily live in the QWidget's methods, this is >>> just for testing which I will clean up once I get >>> how it all connects again >>> >>> >>> _______________________________________________ >>> PySide mailing list >>> PySide at qt-project.org >>> http://lists.qt-project.org/mailman/listinfo/pyside >>> >>> >>> >>> >>> _______________________________________________ >>> PySide mailing list >>> PySide at qt-project.org >>> http://lists.qt-project.org/mailman/listinfo/pyside >>> >>> >>> >>> >>> >>> >>> _______________________________________________ >>> PySide mailing list >>> PySide at qt-project.org >>> http://lists.qt-project.org/mailman/listinfo/pyside >> >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at ohufx.com Sun Oct 13 13:54:29 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Sun, 13 Oct 2013 13:54:29 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <525A896E.9060902@bluewin.ch> References: <848951203488568137@unknownmsgid>, <5259B5D5.8000505@ohufx.com> <5259c8d3.486b0e0a.0d06.ffffc793@mx.google.com> <5259CF8F.9090602@bluewin.ch> <525A816E.2050200@ohufx.com> <525A896E.9060902@bluewin.ch> Message-ID: <525A89F5.2000404@ohufx.com> sweet, that was my hunch, just didn't want to barge in the wrong direction. I will keep doing some more basics as per the suggestions from you and the others before embarking on this one, but have an idea now how to tackle it. Cheers, frank On 13/10/13 1:52 PM, Aaron Richiger wrote: > Hello Frank! > > You're welcome. I will send you more details later (do not have too > much time for the moment). But just to give you the direction: > > If the animation is a must-have, I would not go the way with > QTableView nor the way with QListView or QTreeView. Without animation, > those are perfect, but if you really want the fancy animations, I > would do it like this: > > - Implement a widget to show a TODO-Item > - Show them absolutely positioned one after the other > - Implement buttons for "Add new", "Sort", "Filter" > - In case of sort or filtering: calculate new position for each item, > animate it to new position using QParallelAnimationGroup > > See you later! > Aaron > > > > > > Am 13.10.2013 13:18, schrieb Frank Rueter | OHUfx: >> Great, thanks Tibold and Aaron! That all makes sense. >> >> Incidentally I do have planned a bit more than just the standard >> table UI but thought I'd leave that for when I'm more comfortable >> with the basic concepts again. >> So am keen to test all suggested approaches and have a feeling I >> might have to go with a custom solution as I want some animation to >> happen when sorting (each line moving to it's new position) - but >> that's for later, for now I will stick to the basics. >> >> Aaron, when trying the setItemDelegateForColumn (sorry, how could I >> not have seen this one before) things work fine but I have to cast >> the incoming data to int() explicitly in side the setEditorData. The >> setModelData method seems to automatically cast the integer back to a >> string. Is this the right way to do it? >> >> def setEditorData(self, spinBox, index): >> value = index.model().data(index) >> spinBox.setValue(*int(value)*)*# cast string to int* >> >> def setModelData(self, spinBox, model, index): >> spinBox.interpretText() >> value = spinBox.value() >> model.setData(index, *value*)*# no need to cast int back to >> string?* >> >> >> Looking ahead: If I want to make the rows/tasks animate to their new >> positions upon sorting, can I re-implement the paint methods of, say, >> a QAbstractItemView or do I have to go back further and do more >> manual work? >> I need to stick to the standard PySide package for this for various >> reasons. >> >> Cheers and thanks again Tibold, Aaron and Sebastian, you are a great >> help as usual! >> >> frank >> >> >> >> On 13/10/13 12:39 AM, Aaron Richiger wrote: >>> Hello! >>> >>> Tibolds approach would work (and could result in a nicer UI). Both >>> solutions are possible, some thoughts about the QTableView approach: >>> >>> - your app smells like a future database app. QTableView is in >>> advantage then, because by using QSqlTableModel, you get all the >>> mapping betwenn the db and the model for free. >>> - By using QTableView, sorting, filtering etc. is already included >>> and if your table has manymany rows, it will be much faster than any >>> self implemented filtering/sorting algorithm. But as long, as your >>> todo list doesn't have thousands of entries (and I hope so for >>> you:-), performance isn't an argument. >>> >>> Changes to your code to have the spinbox in the middle column only: >>> >>> priorityDelegate = SpinBoxDelegate(tableView) >>> tableView.setItemDelegateForColumn(1, priorityDelegate) >>> >>> Like this, the first column remains "text-editable", and for the >>> last column with the checkbox, you don't even necessarily have to >>> implement a new delegate, reimplementing .flags(), setData() and >>> data() methods of your model is enough (but if you want a pure >>> checkbox without a label next to it, you have to write your own >>> delegate, I could send you the code). >>> >>> Feel free to choose what ever way you want, both are perfectly >>> doable, having advantages where the other variant has disadvantages... >>> >>> Cheers >>> Aaron >>> >>> >>> Am 13.10.2013 00:06, schrieb Tibold Kandrai: >>>> If you ask me personally, I wouldn't use QTableWidget. Look into >>>> QTreeView or QListWidget. >>>> I think they are more suitable for such tasks and are easier to handle. >>>> With QTreeView you can use QItemDelegate, to create a special >>>> rendering. >>>> With QListWidget you can simply add a widget per row and inside the >>>> widget you can put whatever. >>>> ATM I'm in the middle of a 2000 km road trip so I can't rally >>>> provide you sample's, but if you need help next week I'm glad to >>>> give you samples how to use these widgets. >>>> Cheers, >>>> Tibold Kandrai >>>> *From:* Frank Rueter | OHUfx >>>> *Sent:* ?Saturday?, ?12? ?October? ?2013 ?22?:?49 >>>> *To:* Tibold Kandrai >>>> *Cc:* pyside at qt-project.org >>>> Is this the best way to do it though? I.e. having one item per >>>> cell? s there another way at all? >>>> I'm still a bit lost in the model/view design and can't find the >>>> answer online. >>>> >>>> I'm simply trying to have each row represent a "task" with a >>>> title/description (string), a status (boolean) and a priority >>>> (integer). For the integer I need a spin box and for the boolean I >>>> need a checkbox. The examples I found online all seem to be doing >>>> something slightly different and often use different ways which >>>> makes matters more confusing. >>>> >>>> Here is what I have at the moment: >>>> http://pastebin.com/H3GD0xVB >>>> >>>> The "status" and "priority" values don't display currnelty as I >>>> haven't figured out how to properly assign a delegate to just those >>>> cells. At the top I tried to define a n item delegete for a spin >>>> box but I'm not sure how to properly assign it. >>>> >>>> Do I have to make the delegate draw different widgets (spin box / >>>> checkbox) depending on data type, or can/should I use a different >>>> delegate for each cell? >>>> >>>> I'm sure the answer is right in front of me, could you please help >>>> one more time please?! >>>> >>>> Cheers, >>>> frank >>>> >>>> >>>> On 11/10/13 4:00 PM, Tibold Kandrai wrote: >>>> >>>> If you mean to use a QStandardItem per cell then yes. >>>> Also for storing values that you want to display, use the >>>> Qt.DisplayRole as role. >>>> >>>> Cheers, >>>> Tibold Kandrai >>>> ------------------------------------------------------------------------ >>>> From: Frank Rueter | OHUfx >>>> Sent: ?11/?10/?2013 14:35 >>>> To: Tibold Kandrai >>>> Cc: pyside at qt-project.org >>>> Subject: Re: [PySide] simple QTableView example >>>> >>>> one more silly question if I may: >>>> So if I have a task like this: >>>> newTask = {'title':'new task', 'priority':1, >>>> 'status':False} >>>> >>>> and need to store the data in one row in the model I should use >>>> three different items, one for each value, right?! >>>> >>>> e.g.: >>>> >>>> newTask = {'title':'new task', 'priority':1, >>>> 'status':False} >>>> row = self.model.rowCount() >>>> for column, attr in enumerate(['title', 'priority', >>>> 'status']): >>>> newItem = QtGui.QStandardItem(newTask[attr]) >>>> self.model.setItem(row, column, newItem) >>>> >>>> then juggle delegates or widgets to use a spin box for the >>>> integer and a checkbox for the boolean... >>>> >>>> Thanks for the help! >>>> >>>> Cheers, >>>> frank >>>> >>>> On 10/10/13 11:44 PM, Tibold Kandrai wrote: >>>> >>>> Hey, >>>> I'm not sure I understand the problem correctly. >>>> If you want to store data in a cell or a QStandardItem, >>>> then you need to use setData() and data(). >>>> Generally you shouldn't need to subclass QStandardItem or >>>> QStandardItemModel. >>>> Here is an example how: >>>> # Define roles >>>> FINISHED_ROLE = QtCore.Qt.UserRole + 1 >>>> PRIORITY_ROLE = QtCore.Qt.UserRole + 2 >>>> # Create model >>>> model = QtGui.QStandardItemModel() >>>> item = QtGui.QStandarItem() >>>> model.appendRow(item) >>>> item_index = item.index() >>>> # Store data using the item >>>> item.setData(finished, FINISHED_ROLE) >>>> item.setData(priority, PRIORITY_ROLE) >>>> # Store data using the model >>>> model.setData(item_index, finished, FINISHED_ROLE) >>>> model.setData(item_index, priority, PRIORITY_ROLE) >>>> # Retrieve data using the item >>>> finished = item.data(FINISHED_ROLE) >>>> priority = item.data(PRIORITY_ROLE) >>>> # Retrieve data using the model >>>> finished = model.data(item_index, FINISHED_ROLE) >>>> priority = model.data(item_index, PRIORITY_ROLE) >>>> In some cases like click event handlers, you have the model >>>> and the item index, there it's easier to use the model >>>> methods instead of finding the item and then getting the >>>> data. ? >>>> Hope it helps. >>>> Cheers, >>>> Tibold >>>> *From:* Frank Rueter | OHUfx >>>> *Sent:* ?2013? ?October? ?10?, ?Thursday ?19?:?37 >>>> *To:* pyside at qt-project.org >>>> After looking at some more examples I think my approach of >>>> storing multiple values in one item is fundamentally flawed. >>>> Instead I should be using one item per cell and assign the >>>> respective data, right?! >>>> >>>> I shall re-write the example accordingly, sorry for the noise. >>>> >>>> frank >>>> >>>> On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: >>>> >>>> I meant QTableView not QStandardTableView :/ >>>> >>>> On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: >>>> >>>> Hi all, >>>> >>>> after a bit of a break from PySide I am trying to >>>> wrap my head around the model/view stuff again and >>>> am trying to understand how a very simple example >>>> would work where a QStandarItem has properties >>>> "title", "priority" and "finished" which are >>>> displayed via a QStandardTableView. >>>> >>>> I am struggling with understanding how to properly >>>> display the above three properties in the table's >>>> columns. I tried setting the data() method on the >>>> model like this: >>>> >>>> / def data(self, index, >>>> role=QtCore.Qt.DisplayRole):// >>>> // '''Return data based on index and role'''// >>>> // item = self.itemFromIndex(index)// >>>> // if index.column() == 0:// >>>> // return item.title// >>>> // elif index.column() == 1:// >>>> // return item.finished// >>>> // elif index.column() == 2:// >>>> // return item.priority/ >>>> >>>> but for some reason it errors saying item does not >>>> have attribute "finished" even though my item >>>> object s declared like this: >>>> >>>> /class TaskItem(QtGui.QStandardItem):// >>>> // '''Item to hold a task for the todo list'''// >>>> //// >>>> // def __init__(self, title, finished=False, >>>> priority=1):// >>>> // super(TaskItem, self).__init__(title)// >>>> // self.title = title// >>>> // self.finished = finished// >>>> // self.priority = priority/ >>>> >>>> >>>> When printing the item's attributes via dir() I see >>>> that, when the model is populated, the last item it >>>> attempts to call is not my custom item object, but >>>> something else with less attributes and methods. >>>> Clearly there is something I haven't quite >>>> understood about this process. >>>> >>>> Also, if I use the models data() method as pointed >>>> out above, I get checkboxes in the cells which I >>>> don't want at this stage. >>>> >>>> Can somebody please help me understand where I go >>>> wrong? >>>> Attached is the whole test code. >>>> >>>> Cheers, >>>> frank >>>> >>>> P.S.: I am aware that the controller code shouldn't >>>> necessarily live in the QWidget's methods, this is >>>> just for testing which I will clean up once I get >>>> how it all connects again >>>> >>>> >>>> _______________________________________________ >>>> PySide mailing list >>>> PySide at qt-project.org >>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> PySide mailing list >>>> PySide at qt-project.org >>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>> >>>> >>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> PySide mailing list >>>> PySide at qt-project.org >>>> http://lists.qt-project.org/mailman/listinfo/pyside >>> >>> >>> >>> _______________________________________________ >>> PySide mailing list >>> PySide at qt-project.org >>> http://lists.qt-project.org/mailman/listinfo/pyside >> >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at ohufx.com Sun Oct 13 14:01:20 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Sun, 13 Oct 2013 14:01:20 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <525A8106.80700@risefx.com> References: <848951203488568137@unknownmsgid> <5259B5D5.8000505@ohufx.com> <5259D076.8050002@risefx.com> <525A7C95.4070702@ohufx.com> <525A8106.80700@risefx.com> Message-ID: <525A8B90.1090709@ohufx.com> aaah, clouds are slowly parting in my head :) thanks! On 13/10/13 1:16 PM, Sebastian Elsner wrote: > This is correct. From the docs: Editable models need to implement > setData > (), > and implement flags > () > to return a value containing Qt::ItemIsEditable > . > > http://stackoverflow.com/questions/11736560/edit-table-in-pyqt-using-qabstracttablemodel > > > Am 13.10.2013 12:57, schrieb Frank Rueter | OHUfx: >> Thanks Sebastian, >> >> I don't see en editor in this though, so the result for me in PySide >> (after removing the QVariant references) is a static, non-ediablte >> table. >> >> >> On 13/10/13 12:43 AM, Sebastian Elsner wrote: >>> Hi all, >>> >>> the approach I like most is described in this blog entry: >>> http://www.saltycrane.com/blog/2007/06/pyqt-42-qabstracttablemodelqtableview/ >>> >>> I think this is what you want. >>> >>> Cheers >>> >>> Sebastian >>> >>> >>> Am 12.10.2013 22:49, schrieb Frank Rueter | OHUfx: >>>> Is this the best way to do it though? I.e. having one item per >>>> cell? s there another way at all? >>>> I'm still a bit lost in the model/view design and can't find the >>>> answer online. >>>> >>>> I'm simply trying to have each row represent a "task" with a >>>> title/description (string), a status (boolean) and a priority >>>> (integer). For the integer I need a spin box and for the boolean I >>>> need a checkbox. The examples I found online all seem to be doing >>>> something slightly different and often use different ways which >>>> makes matters more confusing. >>>> >>>> Here is what I have at the moment: >>>> http://pastebin.com/H3GD0xVB >>>> >>>> The "status" and "priority" values don't display currnelty as I >>>> haven't figured out how to properly assign a delegate to just those >>>> cells. At the top I tried to define a n item delegete for a spin >>>> box but I'm not sure how to properly assign it. >>>> >>>> Do I have to make the delegate draw different widgets (spin box / >>>> checkbox) depending on data type, or can/should I use a different >>>> delegate for each cell? >>>> >>>> I'm sure the answer is right in front of me, could you please help >>>> one more time please?! >>>> >>>> Cheers, >>>> frank >>>> >>>> >>>> On 11/10/13 4:00 PM, Tibold Kandrai wrote: >>>>> If you mean to use a QStandardItem per cell then yes. >>>>> Also for storing values that you want to display, use the >>>>> Qt.DisplayRole as role. >>>>> >>>>> Cheers, >>>>> Tibold Kandrai >>>>> ------------------------------------------------------------------------ >>>>> >>>>> From: Frank Rueter | OHUfx >>>>> Sent: ?11/?10/?2013 14:35 >>>>> To: Tibold Kandrai >>>>> Cc: pyside at qt-project.org >>>>> Subject: Re: [PySide] simple QTableView example >>>>> >>>>> one more silly question if I may: >>>>> So if I have a task like this: >>>>> newTask = {'title':'new task', 'priority':1, 'status':False} >>>>> >>>>> and need to store the data in one row in the model I should use >>>>> three different items, one for each value, right?! >>>>> >>>>> e.g.: >>>>> >>>>> newTask = {'title':'new task', 'priority':1, 'status':False} >>>>> row = self.model.rowCount() >>>>> for column, attr in enumerate(['title', 'priority', >>>>> 'status']): >>>>> newItem = QtGui.QStandardItem(newTask[attr]) >>>>> self.model.setItem(row, column, newItem) >>>>> >>>>> then juggle delegates or widgets to use a spin box for the integer >>>>> and a checkbox for the boolean... >>>>> >>>>> Thanks for the help! >>>>> >>>>> Cheers, >>>>> frank >>>>> >>>>> On 10/10/13 11:44 PM, Tibold Kandrai wrote: >>>>>> Hey, >>>>>> I'm not sure I understand the problem correctly. >>>>>> If you want to store data in a cell or a QStandardItem, then you >>>>>> need to use setData() and data(). >>>>>> Generally you shouldn't need to subclass QStandardItem or >>>>>> QStandardItemModel. >>>>>> Here is an example how: >>>>>> # Define roles >>>>>> FINISHED_ROLE = QtCore.Qt.UserRole + 1 >>>>>> PRIORITY_ROLE = QtCore.Qt.UserRole + 2 >>>>>> # Create model >>>>>> model = QtGui.QStandardItemModel() >>>>>> item = QtGui.QStandarItem() >>>>>> model.appendRow(item) >>>>>> item_index = item.index() >>>>>> # Store data using the item >>>>>> item.setData(finished, FINISHED_ROLE) >>>>>> item.setData(priority, PRIORITY_ROLE) >>>>>> # Store data using the model >>>>>> model.setData(item_index, finished, FINISHED_ROLE) >>>>>> model.setData(item_index, priority, PRIORITY_ROLE) >>>>>> # Retrieve data using the item >>>>>> finished = item.data(FINISHED_ROLE) >>>>>> priority = item.data(PRIORITY_ROLE) >>>>>> # Retrieve data using the model >>>>>> finished = model.data(item_index, FINISHED_ROLE) >>>>>> priority = model.data(item_index, PRIORITY_ROLE) >>>>>> In some cases like click event handlers, you have the model and >>>>>> the item index, there it's easier to use the model methods >>>>>> instead of finding the item and then getting the data. ? >>>>>> Hope it helps. >>>>>> Cheers, >>>>>> Tibold >>>>>> *From:* Frank Rueter | OHUfx >>>>>> *Sent:* ?2013? ?October? ?10?, ?Thursday ?19?:?37 >>>>>> *To:* pyside at qt-project.org >>>>>> After looking at some more examples I think my approach of >>>>>> storing multiple values in one item is fundamentally flawed. >>>>>> Instead I should be using one item per cell and assign the >>>>>> respective data, right?! >>>>>> >>>>>> I shall re-write the example accordingly, sorry for the noise. >>>>>> >>>>>> frank >>>>>> >>>>>> On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: >>>>>> >>>>>> I meant QTableView not QStandardTableView :/ >>>>>> >>>>>> On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: >>>>>> >>>>>> Hi all, >>>>>> >>>>>> after a bit of a break from PySide I am trying to wrap my >>>>>> head around the model/view stuff again and am trying to >>>>>> understand how a very simple example would work where a >>>>>> QStandarItem has properties "title", "priority" and >>>>>> "finished" which are displayed via a QStandardTableView. >>>>>> >>>>>> I am struggling with understanding how to properly display >>>>>> the above three properties in the table's columns. I tried >>>>>> setting the data() method on the model like this: >>>>>> >>>>>> / def data(self, index, role=QtCore.Qt.DisplayRole):// >>>>>> // '''Return data based on index and role'''// >>>>>> // item = self.itemFromIndex(index)// >>>>>> // if index.column() == 0:// >>>>>> // return item.title// >>>>>> // elif index.column() == 1:// >>>>>> // return item.finished// >>>>>> // elif index.column() == 2:// >>>>>> // return item.priority/ >>>>>> >>>>>> but for some reason it errors saying item does not have >>>>>> attribute "finished" even though my item object s declared >>>>>> like this: >>>>>> >>>>>> /class TaskItem(QtGui.QStandardItem):// >>>>>> // '''Item to hold a task for the todo list'''// >>>>>> //// >>>>>> // def __init__(self, title, finished=False, >>>>>> priority=1):// >>>>>> // super(TaskItem, self).__init__(title)// >>>>>> // self.title = title// >>>>>> // self.finished = finished// >>>>>> // self.priority = priority/ >>>>>> >>>>>> >>>>>> When printing the item's attributes via dir() I see that, >>>>>> when the model is populated, the last item it attempts to >>>>>> call is not my custom item object, but something else with >>>>>> less attributes and methods. Clearly there is something I >>>>>> haven't quite understood about this process. >>>>>> >>>>>> Also, if I use the models data() method as pointed out >>>>>> above, >>>>>> I get checkboxes in the cells which I don't want at this >>>>>> stage. >>>>>> >>>>>> Can somebody please help me understand where I go wrong? >>>>>> Attached is the whole test code. >>>>>> >>>>>> Cheers, >>>>>> frank >>>>>> >>>>>> P.S.: I am aware that the controller code shouldn't >>>>>> necessarily live in the QWidget's methods, this is just for >>>>>> testing which I will clean up once I get how it all connects >>>>>> again >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> PySide mailing list >>>>>> PySide at qt-project.org >>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> PySide mailing list >>>>>> PySide at qt-project.org >>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>>> >>>>>> >>>>> >>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> PySide mailing list >>>> PySide at qt-project.org >>>> http://lists.qt-project.org/mailman/listinfo/pyside >>> >>> >>> >>> _______________________________________________ >>> PySide mailing list >>> PySide at qt-project.org >>> http://lists.qt-project.org/mailman/listinfo/pyside >> >> >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From a.richi at bluewin.ch Mon Oct 14 14:22:04 2013 From: a.richi at bluewin.ch (Aaron Richiger) Date: Mon, 14 Oct 2013 14:22:04 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <525A89F5.2000404@ohufx.com> References: <848951203488568137@unknownmsgid>, <5259B5D5.8000505@ohufx.com> <5259c8d3.486b0e0a.0d06.ffffc793@mx.google.com> <5259CF8F.9090602@bluewin.ch> <525A816E.2050200@ohufx.com> <525A896E.9060902@bluewin.ch> <525A89F5.2000404@ohufx.com> Message-ID: <525BE1EC.5000400@bluewin.ch> Hello Frank! I just implemented the approach I told you yesterday (without QTableView, QListView, etc because you wanted animations). You can see the code of the working app in the attachment, it's in a classical MVC setup. Because dealing with databases is a bit more work when not using QSqlTableModel, I save and load tasks and user settings between sessions using pickle. I did not spend much time on a nice design, it's just to give you some sample code in case you really want the animations. With some more lines of code, you can pimp the design according to your wishes. Have a nice day! Aaron Am 13.10.2013 13:54, schrieb Frank Rueter | OHUfx: > sweet, that was my hunch, just didn't want to barge in the wrong > direction. > I will keep doing some more basics as per the suggestions from you and > the others before embarking on this one, but have an idea now how to > tackle it. > > Cheers, > frank > > On 13/10/13 1:52 PM, Aaron Richiger wrote: >> Hello Frank! >> >> You're welcome. I will send you more details later (do not have too >> much time for the moment). But just to give you the direction: >> >> If the animation is a must-have, I would not go the way with >> QTableView nor the way with QListView or QTreeView. Without >> animation, those are perfect, but if you really want the fancy >> animations, I would do it like this: >> >> - Implement a widget to show a TODO-Item >> - Show them absolutely positioned one after the other >> - Implement buttons for "Add new", "Sort", "Filter" >> - In case of sort or filtering: calculate new position for each item, >> animate it to new position using QParallelAnimationGroup >> >> See you later! >> Aaron >> >> >> >> >> >> Am 13.10.2013 13:18, schrieb Frank Rueter | OHUfx: >>> Great, thanks Tibold and Aaron! That all makes sense. >>> >>> Incidentally I do have planned a bit more than just the standard >>> table UI but thought I'd leave that for when I'm more comfortable >>> with the basic concepts again. >>> So am keen to test all suggested approaches and have a feeling I >>> might have to go with a custom solution as I want some animation to >>> happen when sorting (each line moving to it's new position) - but >>> that's for later, for now I will stick to the basics. >>> >>> Aaron, when trying the setItemDelegateForColumn (sorry, how could I >>> not have seen this one before) things work fine but I have to cast >>> the incoming data to int() explicitly in side the setEditorData. The >>> setModelData method seems to automatically cast the integer back to >>> a string. Is this the right way to do it? >>> >>> def setEditorData(self, spinBox, index): >>> value = index.model().data(index) >>> spinBox.setValue(*int(value)*)*# cast string to int* >>> >>> def setModelData(self, spinBox, model, index): >>> spinBox.interpretText() >>> value = spinBox.value() >>> model.setData(index, *value*)*# no need to cast int back to >>> string?* >>> >>> >>> Looking ahead: If I want to make the rows/tasks animate to their new >>> positions upon sorting, can I re-implement the paint methods of, >>> say, a QAbstractItemView or do I have to go back further and do more >>> manual work? >>> I need to stick to the standard PySide package for this for various >>> reasons. >>> >>> Cheers and thanks again Tibold, Aaron and Sebastian, you are a great >>> help as usual! >>> >>> frank >>> >>> >>> >>> On 13/10/13 12:39 AM, Aaron Richiger wrote: >>>> Hello! >>>> >>>> Tibolds approach would work (and could result in a nicer UI). Both >>>> solutions are possible, some thoughts about the QTableView approach: >>>> >>>> - your app smells like a future database app. QTableView is in >>>> advantage then, because by using QSqlTableModel, you get all the >>>> mapping betwenn the db and the model for free. >>>> - By using QTableView, sorting, filtering etc. is already included >>>> and if your table has manymany rows, it will be much faster than >>>> any self implemented filtering/sorting algorithm. But as long, as >>>> your todo list doesn't have thousands of entries (and I hope so for >>>> you:-), performance isn't an argument. >>>> >>>> Changes to your code to have the spinbox in the middle column only: >>>> >>>> priorityDelegate = SpinBoxDelegate(tableView) >>>> tableView.setItemDelegateForColumn(1, priorityDelegate) >>>> >>>> Like this, the first column remains "text-editable", and for the >>>> last column with the checkbox, you don't even necessarily have to >>>> implement a new delegate, reimplementing .flags(), setData() and >>>> data() methods of your model is enough (but if you want a pure >>>> checkbox without a label next to it, you have to write your own >>>> delegate, I could send you the code). >>>> >>>> Feel free to choose what ever way you want, both are perfectly >>>> doable, having advantages where the other variant has disadvantages... >>>> >>>> Cheers >>>> Aaron >>>> >>>> >>>> Am 13.10.2013 00:06, schrieb Tibold Kandrai: >>>>> If you ask me personally, I wouldn't use QTableWidget. Look into >>>>> QTreeView or QListWidget. >>>>> I think they are more suitable for such tasks and are easier to >>>>> handle. >>>>> With QTreeView you can use QItemDelegate, to create a special >>>>> rendering. >>>>> With QListWidget you can simply add a widget per row and inside >>>>> the widget you can put whatever. >>>>> ATM I'm in the middle of a 2000 km road trip so I can't rally >>>>> provide you sample's, but if you need help next week I'm glad to >>>>> give you samples how to use these widgets. >>>>> Cheers, >>>>> Tibold Kandrai >>>>> *From:* Frank Rueter | OHUfx >>>>> *Sent:* ?Saturday?, ?12? ?October? ?2013 ?22?:?49 >>>>> *To:* Tibold Kandrai >>>>> *Cc:* pyside at qt-project.org >>>>> Is this the best way to do it though? I.e. having one item per >>>>> cell? s there another way at all? >>>>> I'm still a bit lost in the model/view design and can't find the >>>>> answer online. >>>>> >>>>> I'm simply trying to have each row represent a "task" with a >>>>> title/description (string), a status (boolean) and a priority >>>>> (integer). For the integer I need a spin box and for the boolean I >>>>> need a checkbox. The examples I found online all seem to be doing >>>>> something slightly different and often use different ways which >>>>> makes matters more confusing. >>>>> >>>>> Here is what I have at the moment: >>>>> http://pastebin.com/H3GD0xVB >>>>> >>>>> The "status" and "priority" values don't display currnelty as I >>>>> haven't figured out how to properly assign a delegate to just >>>>> those cells. At the top I tried to define a n item delegete for a >>>>> spin box but I'm not sure how to properly assign it. >>>>> >>>>> Do I have to make the delegate draw different widgets (spin box / >>>>> checkbox) depending on data type, or can/should I use a different >>>>> delegate for each cell? >>>>> >>>>> I'm sure the answer is right in front of me, could you please help >>>>> one more time please?! >>>>> >>>>> Cheers, >>>>> frank >>>>> >>>>> >>>>> On 11/10/13 4:00 PM, Tibold Kandrai wrote: >>>>> >>>>> If you mean to use a QStandardItem per cell then yes. >>>>> Also for storing values that you want to display, use the >>>>> Qt.DisplayRole as role. >>>>> >>>>> Cheers, >>>>> Tibold Kandrai >>>>> ------------------------------------------------------------------------ >>>>> From: Frank Rueter | OHUfx >>>>> Sent: ?11/?10/?2013 14:35 >>>>> To: Tibold Kandrai >>>>> Cc: pyside at qt-project.org >>>>> Subject: Re: [PySide] simple QTableView example >>>>> >>>>> one more silly question if I may: >>>>> So if I have a task like this: >>>>> newTask = {'title':'new task', 'priority':1, >>>>> 'status':False} >>>>> >>>>> and need to store the data in one row in the model I should >>>>> use three different items, one for each value, right?! >>>>> >>>>> e.g.: >>>>> >>>>> newTask = {'title':'new task', 'priority':1, >>>>> 'status':False} >>>>> row = self.model.rowCount() >>>>> for column, attr in enumerate(['title', 'priority', >>>>> 'status']): >>>>> newItem = QtGui.QStandardItem(newTask[attr]) >>>>> self.model.setItem(row, column, newItem) >>>>> >>>>> then juggle delegates or widgets to use a spin box for the >>>>> integer and a checkbox for the boolean... >>>>> >>>>> Thanks for the help! >>>>> >>>>> Cheers, >>>>> frank >>>>> >>>>> On 10/10/13 11:44 PM, Tibold Kandrai wrote: >>>>> >>>>> Hey, >>>>> I'm not sure I understand the problem correctly. >>>>> If you want to store data in a cell or a QStandardItem, >>>>> then you need to use setData() and data(). >>>>> Generally you shouldn't need to subclass QStandardItem or >>>>> QStandardItemModel. >>>>> Here is an example how: >>>>> # Define roles >>>>> FINISHED_ROLE = QtCore.Qt.UserRole + 1 >>>>> PRIORITY_ROLE = QtCore.Qt.UserRole + 2 >>>>> # Create model >>>>> model = QtGui.QStandardItemModel() >>>>> item = QtGui.QStandarItem() >>>>> model.appendRow(item) >>>>> item_index = item.index() >>>>> # Store data using the item >>>>> item.setData(finished, FINISHED_ROLE) >>>>> item.setData(priority, PRIORITY_ROLE) >>>>> # Store data using the model >>>>> model.setData(item_index, finished, FINISHED_ROLE) >>>>> model.setData(item_index, priority, PRIORITY_ROLE) >>>>> # Retrieve data using the item >>>>> finished = item.data(FINISHED_ROLE) >>>>> priority = item.data(PRIORITY_ROLE) >>>>> # Retrieve data using the model >>>>> finished = model.data(item_index, FINISHED_ROLE) >>>>> priority = model.data(item_index, PRIORITY_ROLE) >>>>> In some cases like click event handlers, you have the >>>>> model and the item index, there it's easier to use the >>>>> model methods instead of finding the item and then getting >>>>> the data. ? >>>>> Hope it helps. >>>>> Cheers, >>>>> Tibold >>>>> *From:* Frank Rueter | OHUfx >>>>> *Sent:* ?2013? ?October? ?10?, ?Thursday ?19?:?37 >>>>> *To:* pyside at qt-project.org >>>>> After looking at some more examples I think my approach of >>>>> storing multiple values in one item is fundamentally flawed. >>>>> Instead I should be using one item per cell and assign the >>>>> respective data, right?! >>>>> >>>>> I shall re-write the example accordingly, sorry for the noise. >>>>> >>>>> frank >>>>> >>>>> On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: >>>>> >>>>> I meant QTableView not QStandardTableView :/ >>>>> >>>>> On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: >>>>> >>>>> Hi all, >>>>> >>>>> after a bit of a break from PySide I am trying to >>>>> wrap my head around the model/view stuff again and >>>>> am trying to understand how a very simple example >>>>> would work where a QStandarItem has properties >>>>> "title", "priority" and "finished" which are >>>>> displayed via a QStandardTableView. >>>>> >>>>> I am struggling with understanding how to properly >>>>> display the above three properties in the table's >>>>> columns. I tried setting the data() method on the >>>>> model like this: >>>>> >>>>> / def data(self, index, >>>>> role=QtCore.Qt.DisplayRole):// >>>>> // '''Return data based on index and role'''// >>>>> // item = self.itemFromIndex(index)// >>>>> // if index.column() == 0:// >>>>> // return item.title// >>>>> // elif index.column() == 1:// >>>>> // return item.finished// >>>>> // elif index.column() == 2:// >>>>> // return item.priority/ >>>>> >>>>> but for some reason it errors saying item does not >>>>> have attribute "finished" even though my item >>>>> object s declared like this: >>>>> >>>>> /class TaskItem(QtGui.QStandardItem):// >>>>> // '''Item to hold a task for the todo list'''// >>>>> //// >>>>> // def __init__(self, title, finished=False, >>>>> priority=1):// >>>>> // super(TaskItem, self).__init__(title)// >>>>> // self.title = title// >>>>> // self.finished = finished// >>>>> // self.priority = priority/ >>>>> >>>>> >>>>> When printing the item's attributes via dir() I >>>>> see that, when the model is populated, the last >>>>> item it attempts to call is not my custom item >>>>> object, but something else with less attributes >>>>> and methods. Clearly there is something I haven't >>>>> quite understood about this process. >>>>> >>>>> Also, if I use the models data() method as pointed >>>>> out above, I get checkboxes in the cells which I >>>>> don't want at this stage. >>>>> >>>>> Can somebody please help me understand where I go >>>>> wrong? >>>>> Attached is the whole test code. >>>>> >>>>> Cheers, >>>>> frank >>>>> >>>>> P.S.: I am aware that the controller code >>>>> shouldn't necessarily live in the QWidget's >>>>> methods, this is just for testing which I will >>>>> clean up once I get how it all connects again >>>>> >>>>> >>>>> _______________________________________________ >>>>> PySide mailing list >>>>> PySide at qt-project.org >>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>> >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> PySide mailing list >>>>> PySide at qt-project.org >>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> PySide mailing list >>>>> PySide at qt-project.org >>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>> >>>> >>>> >>>> _______________________________________________ >>>> PySide mailing list >>>> PySide at qt-project.org >>>> http://lists.qt-project.org/mailman/listinfo/pyside >>> >>> >>> >>> _______________________________________________ >>> PySide mailing list >>> PySide at qt-project.org >>> http://lists.qt-project.org/mailman/listinfo/pyside >> >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: todo_list.py Type: text/x-python Size: 10051 bytes Desc: not available URL: From frank at ohufx.com Mon Oct 14 15:30:31 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Mon, 14 Oct 2013 15:30:31 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <525BE1EC.5000400@bluewin.ch> References: <848951203488568137@unknownmsgid>, <5259B5D5.8000505@ohufx.com> <5259c8d3.486b0e0a.0d06.ffffc793@mx.google.com> <5259CF8F.9090602@bluewin.ch> <525A816E.2050200@ohufx.com> <525A896E.9060902@bluewin.ch> <525A89F5.2000404@ohufx.com> <525BE1EC.5000400@bluewin.ch> Message-ID: <525BF1F7.3010507@ohufx.com> WOW. that is more than I was aiming for, thank you so much!! I will take a look at your code soon (am just about to hop on a plane for a 30 hour flight). I wrote a standard approach without animation and the default MVC classes which is working as well, and now was about to embark on researching the fancy way, so I have a great start now. Thanks heaps again! frank On 14/10/13 2:22 PM, Aaron Richiger wrote: > Hello Frank! > > I just implemented the approach I told you yesterday (without > QTableView, QListView, etc because you wanted animations). You can see > the code of the working app in the attachment, it's in a classical MVC > setup. Because dealing with databases is a bit more work when not > using QSqlTableModel, I save and load tasks and user settings between > sessions using pickle. I did not spend much time on a nice design, > it's just to give you some sample code in case you really want the > animations. With some more lines of code, you can pimp the design > according to your wishes. > > Have a nice day! > Aaron > > > > Am 13.10.2013 13:54, schrieb Frank Rueter | OHUfx: >> sweet, that was my hunch, just didn't want to barge in the wrong >> direction. >> I will keep doing some more basics as per the suggestions from you >> and the others before embarking on this one, but have an idea now how >> to tackle it. >> >> Cheers, >> frank >> >> On 13/10/13 1:52 PM, Aaron Richiger wrote: >>> Hello Frank! >>> >>> You're welcome. I will send you more details later (do not have too >>> much time for the moment). But just to give you the direction: >>> >>> If the animation is a must-have, I would not go the way with >>> QTableView nor the way with QListView or QTreeView. Without >>> animation, those are perfect, but if you really want the fancy >>> animations, I would do it like this: >>> >>> - Implement a widget to show a TODO-Item >>> - Show them absolutely positioned one after the other >>> - Implement buttons for "Add new", "Sort", "Filter" >>> - In case of sort or filtering: calculate new position for each >>> item, animate it to new position using QParallelAnimationGroup >>> >>> See you later! >>> Aaron >>> >>> >>> >>> >>> >>> Am 13.10.2013 13:18, schrieb Frank Rueter | OHUfx: >>>> Great, thanks Tibold and Aaron! That all makes sense. >>>> >>>> Incidentally I do have planned a bit more than just the standard >>>> table UI but thought I'd leave that for when I'm more comfortable >>>> with the basic concepts again. >>>> So am keen to test all suggested approaches and have a feeling I >>>> might have to go with a custom solution as I want some animation to >>>> happen when sorting (each line moving to it's new position) - but >>>> that's for later, for now I will stick to the basics. >>>> >>>> Aaron, when trying the setItemDelegateForColumn (sorry, how could I >>>> not have seen this one before) things work fine but I have to cast >>>> the incoming data to int() explicitly in side the setEditorData. >>>> The setModelData method seems to automatically cast the integer >>>> back to a string. Is this the right way to do it? >>>> >>>> def setEditorData(self, spinBox, index): >>>> value = index.model().data(index) >>>> spinBox.setValue(*int(value)*)*# cast string to int* >>>> >>>> def setModelData(self, spinBox, model, index): >>>> spinBox.interpretText() >>>> value = spinBox.value() >>>> model.setData(index, *value*)*# no need to cast int back to >>>> string?* >>>> >>>> >>>> Looking ahead: If I want to make the rows/tasks animate to their >>>> new positions upon sorting, can I re-implement the paint methods >>>> of, say, a QAbstractItemView or do I have to go back further and do >>>> more manual work? >>>> I need to stick to the standard PySide package for this for various >>>> reasons. >>>> >>>> Cheers and thanks again Tibold, Aaron and Sebastian, you are a >>>> great help as usual! >>>> >>>> frank >>>> >>>> >>>> >>>> On 13/10/13 12:39 AM, Aaron Richiger wrote: >>>>> Hello! >>>>> >>>>> Tibolds approach would work (and could result in a nicer UI). Both >>>>> solutions are possible, some thoughts about the QTableView approach: >>>>> >>>>> - your app smells like a future database app. QTableView is in >>>>> advantage then, because by using QSqlTableModel, you get all the >>>>> mapping betwenn the db and the model for free. >>>>> - By using QTableView, sorting, filtering etc. is already included >>>>> and if your table has manymany rows, it will be much faster than >>>>> any self implemented filtering/sorting algorithm. But as long, as >>>>> your todo list doesn't have thousands of entries (and I hope so >>>>> for you:-), performance isn't an argument. >>>>> >>>>> Changes to your code to have the spinbox in the middle column only: >>>>> >>>>> priorityDelegate = SpinBoxDelegate(tableView) >>>>> tableView.setItemDelegateForColumn(1, priorityDelegate) >>>>> >>>>> Like this, the first column remains "text-editable", and for the >>>>> last column with the checkbox, you don't even necessarily have to >>>>> implement a new delegate, reimplementing .flags(), setData() and >>>>> data() methods of your model is enough (but if you want a pure >>>>> checkbox without a label next to it, you have to write your own >>>>> delegate, I could send you the code). >>>>> >>>>> Feel free to choose what ever way you want, both are perfectly >>>>> doable, having advantages where the other variant has disadvantages... >>>>> >>>>> Cheers >>>>> Aaron >>>>> >>>>> >>>>> Am 13.10.2013 00:06, schrieb Tibold Kandrai: >>>>>> If you ask me personally, I wouldn't use QTableWidget. Look into >>>>>> QTreeView or QListWidget. >>>>>> I think they are more suitable for such tasks and are easier to >>>>>> handle. >>>>>> With QTreeView you can use QItemDelegate, to create a special >>>>>> rendering. >>>>>> With QListWidget you can simply add a widget per row and inside >>>>>> the widget you can put whatever. >>>>>> ATM I'm in the middle of a 2000 km road trip so I can't rally >>>>>> provide you sample's, but if you need help next week I'm glad to >>>>>> give you samples how to use these widgets. >>>>>> Cheers, >>>>>> Tibold Kandrai >>>>>> *From:* Frank Rueter | OHUfx >>>>>> *Sent:* ?Saturday?, ?12? ?October? ?2013 ?22?:?49 >>>>>> *To:* Tibold Kandrai >>>>>> *Cc:* pyside at qt-project.org >>>>>> Is this the best way to do it though? I.e. having one item per >>>>>> cell? s there another way at all? >>>>>> I'm still a bit lost in the model/view design and can't find the >>>>>> answer online. >>>>>> >>>>>> I'm simply trying to have each row represent a "task" with a >>>>>> title/description (string), a status (boolean) and a priority >>>>>> (integer). For the integer I need a spin box and for the boolean >>>>>> I need a checkbox. The examples I found online all seem to be >>>>>> doing something slightly different and often use different ways >>>>>> which makes matters more confusing. >>>>>> >>>>>> Here is what I have at the moment: >>>>>> http://pastebin.com/H3GD0xVB >>>>>> >>>>>> The "status" and "priority" values don't display currnelty as I >>>>>> haven't figured out how to properly assign a delegate to just >>>>>> those cells. At the top I tried to define a n item delegete for a >>>>>> spin box but I'm not sure how to properly assign it. >>>>>> >>>>>> Do I have to make the delegate draw different widgets (spin box / >>>>>> checkbox) depending on data type, or can/should I use a different >>>>>> delegate for each cell? >>>>>> >>>>>> I'm sure the answer is right in front of me, could you please >>>>>> help one more time please?! >>>>>> >>>>>> Cheers, >>>>>> frank >>>>>> >>>>>> >>>>>> On 11/10/13 4:00 PM, Tibold Kandrai wrote: >>>>>> >>>>>> If you mean to use a QStandardItem per cell then yes. >>>>>> Also for storing values that you want to display, use the >>>>>> Qt.DisplayRole as role. >>>>>> >>>>>> Cheers, >>>>>> Tibold Kandrai >>>>>> ------------------------------------------------------------------------ >>>>>> From: Frank Rueter | OHUfx >>>>>> Sent: ?11/?10/?2013 14:35 >>>>>> To: Tibold Kandrai >>>>>> Cc: pyside at qt-project.org >>>>>> Subject: Re: [PySide] simple QTableView example >>>>>> >>>>>> one more silly question if I may: >>>>>> So if I have a task like this: >>>>>> newTask = {'title':'new task', 'priority':1, >>>>>> 'status':False} >>>>>> >>>>>> and need to store the data in one row in the model I should >>>>>> use three different items, one for each value, right?! >>>>>> >>>>>> e.g.: >>>>>> >>>>>> newTask = {'title':'new task', 'priority':1, >>>>>> 'status':False} >>>>>> row = self.model.rowCount() >>>>>> for column, attr in enumerate(['title', 'priority', >>>>>> 'status']): >>>>>> newItem = QtGui.QStandardItem(newTask[attr]) >>>>>> self.model.setItem(row, column, newItem) >>>>>> >>>>>> then juggle delegates or widgets to use a spin box for the >>>>>> integer and a checkbox for the boolean... >>>>>> >>>>>> Thanks for the help! >>>>>> >>>>>> Cheers, >>>>>> frank >>>>>> >>>>>> On 10/10/13 11:44 PM, Tibold Kandrai wrote: >>>>>> >>>>>> Hey, >>>>>> I'm not sure I understand the problem correctly. >>>>>> If you want to store data in a cell or a QStandardItem, >>>>>> then you need to use setData() and data(). >>>>>> Generally you shouldn't need to subclass QStandardItem or >>>>>> QStandardItemModel. >>>>>> Here is an example how: >>>>>> # Define roles >>>>>> FINISHED_ROLE = QtCore.Qt.UserRole + 1 >>>>>> PRIORITY_ROLE = QtCore.Qt.UserRole + 2 >>>>>> # Create model >>>>>> model = QtGui.QStandardItemModel() >>>>>> item = QtGui.QStandarItem() >>>>>> model.appendRow(item) >>>>>> item_index = item.index() >>>>>> # Store data using the item >>>>>> item.setData(finished, FINISHED_ROLE) >>>>>> item.setData(priority, PRIORITY_ROLE) >>>>>> # Store data using the model >>>>>> model.setData(item_index, finished, FINISHED_ROLE) >>>>>> model.setData(item_index, priority, PRIORITY_ROLE) >>>>>> # Retrieve data using the item >>>>>> finished = item.data(FINISHED_ROLE) >>>>>> priority = item.data(PRIORITY_ROLE) >>>>>> # Retrieve data using the model >>>>>> finished = model.data(item_index, FINISHED_ROLE) >>>>>> priority = model.data(item_index, PRIORITY_ROLE) >>>>>> In some cases like click event handlers, you have the >>>>>> model and the item index, there it's easier to use the >>>>>> model methods instead of finding the item and then >>>>>> getting the data. ? >>>>>> Hope it helps. >>>>>> Cheers, >>>>>> Tibold >>>>>> *From:* Frank Rueter | OHUfx >>>>>> *Sent:* ?2013? ?October? ?10?, ?Thursday ?19?:?37 >>>>>> *To:* pyside at qt-project.org >>>>>> After looking at some more examples I think my approach >>>>>> of storing multiple values in one item is fundamentally >>>>>> flawed. >>>>>> Instead I should be using one item per cell and assign >>>>>> the respective data, right?! >>>>>> >>>>>> I shall re-write the example accordingly, sorry for the >>>>>> noise. >>>>>> >>>>>> frank >>>>>> >>>>>> On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: >>>>>> >>>>>> I meant QTableView not QStandardTableView :/ >>>>>> >>>>>> On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: >>>>>> >>>>>> Hi all, >>>>>> >>>>>> after a bit of a break from PySide I am trying to >>>>>> wrap my head around the model/view stuff again >>>>>> and am trying to understand how a very simple >>>>>> example would work where a QStandarItem has >>>>>> properties "title", "priority" and "finished" >>>>>> which are displayed via a QStandardTableView. >>>>>> >>>>>> I am struggling with understanding how to >>>>>> properly display the above three properties in >>>>>> the table's columns. I tried setting the data() >>>>>> method on the model like this: >>>>>> >>>>>> / def data(self, index, >>>>>> role=QtCore.Qt.DisplayRole):// >>>>>> // '''Return data based on index and role'''// >>>>>> // item = self.itemFromIndex(index)// >>>>>> // if index.column() == 0:// >>>>>> // return item.title// >>>>>> // elif index.column() == 1:// >>>>>> // return item.finished// >>>>>> // elif index.column() == 2:// >>>>>> // return item.priority/ >>>>>> >>>>>> but for some reason it errors saying item does >>>>>> not have attribute "finished" even though my item >>>>>> object s declared like this: >>>>>> >>>>>> /class TaskItem(QtGui.QStandardItem):// >>>>>> // '''Item to hold a task for the todo list'''// >>>>>> //// >>>>>> // def __init__(self, title, finished=False, >>>>>> priority=1):// >>>>>> // super(TaskItem, self).__init__(title)// >>>>>> // self.title = title// >>>>>> // self.finished = finished// >>>>>> // self.priority = priority/ >>>>>> >>>>>> >>>>>> When printing the item's attributes via dir() I >>>>>> see that, when the model is populated, the last >>>>>> item it attempts to call is not my custom item >>>>>> object, but something else with less attributes >>>>>> and methods. Clearly there is something I haven't >>>>>> quite understood about this process. >>>>>> >>>>>> Also, if I use the models data() method as >>>>>> pointed out above, I get checkboxes in the cells >>>>>> which I don't want at this stage. >>>>>> >>>>>> Can somebody please help me understand where I go >>>>>> wrong? >>>>>> Attached is the whole test code. >>>>>> >>>>>> Cheers, >>>>>> frank >>>>>> >>>>>> P.S.: I am aware that the controller code >>>>>> shouldn't necessarily live in the QWidget's >>>>>> methods, this is just for testing which I will >>>>>> clean up once I get how it all connects again >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> PySide mailing list >>>>>> PySide at qt-project.org >>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> PySide mailing list >>>>>> PySide at qt-project.org >>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> PySide mailing list >>>>>> PySide at qt-project.org >>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> PySide mailing list >>>>> PySide at qt-project.org >>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>> >>>> >>>> >>>> _______________________________________________ >>>> PySide mailing list >>>> PySide at qt-project.org >>>> http://lists.qt-project.org/mailman/listinfo/pyside >>> >>> >>> >>> _______________________________________________ >>> PySide mailing list >>> PySide at qt-project.org >>> http://lists.qt-project.org/mailman/listinfo/pyside >> >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From zaharid at gmail.com Tue Oct 15 00:45:28 2013 From: zaharid at gmail.com (Zahari Dim) Date: Tue, 15 Oct 2013 00:45:28 +0200 Subject: [PySide] Working with the clipboard cross-plattafrom Message-ID: Hi, I need to programatically fill the clipboard with content that has custom mime types. I could make it work with PyQt4 (with some cabarets). But when I try the same for PySide, the application I try to paste to just freezes, both under windows and linux. How could make this work with PySide: #This works from PyQt4 import QtCore, QtGui #This doesn't #from PySide import QtCore, QtGui def start_app(): app = QtCore.QCoreApplication.instance() if app is None: print "app" app = QtGui.QApplication([]) return app #@run_in_qt def set_clipboard(content, mime = 'text/plain'): mymime = QtCore.QMimeData() mymime.setData(mime, QtCore.QByteArray(content.encode('utf-8'))) app = start_app() clipboard = app.clipboard() clipboard.setMimeData(mymime) def get_clipboard(): content = QtGui.QApplication.clipboard().mimeData() avaiable_formats = content.formats() return {fmt:content.data(fmt) for fmt in avaiable_formats} #PyQt4 doesn't work without this line _outside_ any of the functions.... __app = start_app() Any help would be appreciated. Zahari Dimitrov. -------------- next part -------------- An HTML attachment was scrubbed... URL: From a.richi at bluewin.ch Tue Oct 15 01:57:47 2013 From: a.richi at bluewin.ch (Aaron Richiger) Date: Tue, 15 Oct 2013 01:57:47 +0200 Subject: [PySide] Working with the clipboard cross-plattafrom In-Reply-To: References: Message-ID: <525C84FB.5060005@bluewin.ch> Hello Zahari! First my personal meaning when working with Python + Qt: - Qt is great for classical GUI tasks, so solve graphical things using qt - BUT: As soon as it comes to surrounding task (networking, etc.), Qt offers tools too which may be great helpers in the C++ world, but since we are using python, my experience is, that other libraries are much more flexible and comfortable to use. Your question about cross platform use of the clipboard could be one of the tasks where it is better to use other python tools: pyperclip. In the attachment, you can find 3 files, one containing an app for copying to the clipboard, one containing an app for pasting from the clipboard and one file containing the code of pyperclip. Start the apps for copying and pasting in parallel (I tried it on my Ubuntu by running the scripts from two different terminals). Per default, they use Qt to copy to the clipboard. By changing the USE_PYPERCLIP variable in both scripts, you can achieve the same using pyperclip. On my machine, both ways work perfectly fine. But on yours probably only the pyperclip approach will work without freeze/crash!? Hope it helps! Aaron Am 15.10.2013 00:45, schrieb Zahari Dim: > Hi, > > I need to programatically fill the clipboard with content that has > custom mime types. I could make it work with PyQt4 (with some > cabarets). But when I try the same for PySide, the application I try > to paste to just freezes, both under windows and linux. How could > make this work with PySide: > > > #This works > from PyQt4 import QtCore, QtGui > #This doesn't > #from PySide import QtCore, QtGui > > def start_app(): > app = QtCore.QCoreApplication.instance() > if app is None: > print "app" > app = QtGui.QApplication([]) > return app > > > #@run_in_qt > def set_clipboard(content, mime = 'text/plain'): > > mymime = QtCore.QMimeData() > mymime.setData(mime, QtCore.QByteArray(content.encode('utf-8'))) > app = start_app() > clipboard = app.clipboard() > clipboard.setMimeData(mymime) > > > def get_clipboard(): > content = QtGui.QApplication.clipboard().mimeData() > avaiable_formats = content.formats() > return {fmt:content.data(fmt) for fmt in avaiable_formats} > > > #PyQt4 doesn't work without this line _outside_ any of the functions.... > __app = start_app() > > > Any help would be appreciated. > > Zahari Dimitrov. > > > > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: pyperclip.py Type: text/x-python Size: 5604 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: clipboard_paste.py Type: text/x-python Size: 949 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: clipboard_copy.py Type: text/x-python Size: 930 bytes Desc: not available URL: From tismer at stackless.com Fri Oct 18 04:47:33 2013 From: tismer at stackless.com (Christian Tismer) Date: Fri, 18 Oct 2013 04:47:33 +0200 Subject: [PySide] 1.2.1 build failure OS X Message-ID: <5260A145.4020005@stackless.com> Hi friends, I tried to do a PySide build of the 1.2.1 version on OS X 10.8. Used homebrew to install Qt 4.8.5 and a fresh checkout of the pyside-setup repository. this always ends up with > /Users/tismer/src/pyside-setup/sources/pyside/plugins/customwidget.h:27:10: > fatal error: 'QtDesigner/QtDesigner' file not found > #include > ^ > 2 warnings and 1 error generated. > make[2]: *** [plugins/CMakeFiles/uiplugin.dir/customwidgets.cpp.o] Error 1 > make[1]: *** [plugins/CMakeFiles/uiplugin.dir/all] Error 2 > make: *** [all] Error 2 > error: Error compiling pyside This is similar to trying a setup with pip. Any clues? Is that a problem with homebrew, maybe? thanks for any hint, I'm feeling dumb -- chris -- Christian Tismer :^) Software Consulting : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de phone +49 173 24 18 776 fax +49 (30) 700143-0023 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From tismer at stackless.com Fri Oct 18 07:31:59 2013 From: tismer at stackless.com (Christian Tismer) Date: Fri, 18 Oct 2013 07:31:59 +0200 Subject: [PySide] 1.2.1 build failure OS X In-Reply-To: <5260A145.4020005@stackless.com> References: <5260A145.4020005@stackless.com> Message-ID: <5260C7CF.2070700@stackless.com> Found it! Homebrew has a non-default QTDIR, and pyside-setup does not find that out from alone, although it could do that. The quick work-around is export QTDIR=$HOMEBREW_PATH/Cellar/qt/4.8.5/ and then do your build. Actually this should not be necessary at all, because there is a variable QT_INSTALL_HEADERS with exactly that information. See the output of $ qmake -query pyside-setup just does not use this and takes some heuristics. I will build a small patch that fixes this. cheers - chris On 18.10.13 04:47, Christian Tismer wrote: > Hi friends, > > I tried to do a PySide build of the 1.2.1 version on OS X 10.8. > > Used homebrew to install Qt 4.8.5 > and a fresh checkout of the pyside-setup repository. > > this always ends up with > >> /Users/tismer/src/pyside-setup/sources/pyside/plugins/customwidget.h:27:10: >> fatal error: 'QtDesigner/QtDesigner' file not found >> #include >> ^ >> 2 warnings and 1 error generated. >> make[2]: *** [plugins/CMakeFiles/uiplugin.dir/customwidgets.cpp.o] Error 1 >> make[1]: *** [plugins/CMakeFiles/uiplugin.dir/all] Error 2 >> make: *** [all] Error 2 >> error: Error compiling pyside > This is similar to trying a setup with pip. > > Any clues? Is that a problem with homebrew, maybe? > > thanks for any hint, I'm feeling dumb -- chris > -- Christian Tismer :^) Software Consulting : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de phone +49 173 24 18 776 fax +49 (30) 700143-0023 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From tismer at stackless.com Fri Oct 18 08:11:22 2013 From: tismer at stackless.com (Christian Tismer) Date: Fri, 18 Oct 2013 08:11:22 +0200 Subject: [PySide] 1.2.1 build failure OS X In-Reply-To: <5260C7CF.2070700@stackless.com> References: <5260A145.4020005@stackless.com> <5260C7CF.2070700@stackless.com> Message-ID: <5260D10A.4040107@stackless.com> Howdy, Here is a small patch that removes the need to set QTDIR when using homebrew. https://github.com/ctismer/pyside-setup/commit/6f49a93f59b930be858cd1cc9174de74f38ff393 cheers -- chris On 18.10.13 07:31, Christian Tismer wrote: > Found it! > > Homebrew has a non-default QTDIR, and pyside-setup does not find that out > from alone, although it could do that. > > The quick work-around is > > export QTDIR=$HOMEBREW_PATH/Cellar/qt/4.8.5/ > and then do your build. > > Actually this should not be necessary at all, because there is a variable > QT_INSTALL_HEADERS > with exactly that information. See the output of > > $ qmake -query > > pyside-setup just does not use this and takes some heuristics. > I will build a small patch that fixes this. > > cheers - chris > > On 18.10.13 04:47, Christian Tismer wrote: >> Hi friends, >> >> I tried to do a PySide build of the 1.2.1 version on OS X 10.8. >> >> Used homebrew to install Qt 4.8.5 >> and a fresh checkout of the pyside-setup repository. >> >> this always ends up with >> >>> /Users/tismer/src/pyside-setup/sources/pyside/plugins/customwidget.h:27:10: >>> fatal error: 'QtDesigner/QtDesigner' file not found >>> #include >>> ^ >>> 2 warnings and 1 error generated. >>> make[2]: *** [plugins/CMakeFiles/uiplugin.dir/customwidgets.cpp.o] Error 1 >>> make[1]: *** [plugins/CMakeFiles/uiplugin.dir/all] Error 2 >>> make: *** [all] Error 2 >>> error: Error compiling pyside >> This is similar to trying a setup with pip. >> >> Any clues? Is that a problem with homebrew, maybe? >> >> thanks for any hint, I'm feeling dumb -- chris >> > > > -- > Christian Tismer :^) > Software Consulting : Have a break! Take a ride on Python's > Karl-Liebknecht-Str. 121 : *Starship*http://starship.python.net/ > 14482 Potsdam : PGP key ->http://pgp.uni-mainz.de > phone +49 173 24 18 776 fax +49 (30) 700143-0023 > PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 > whom do you want to sponsor today?http://www.stackless.com/ > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -- Christian Tismer :^) Software Consulting : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de phone +49 173 24 18 776 fax +49 (30) 700143-0023 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at ohufx.com Fri Oct 18 08:20:11 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Fri, 18 Oct 2013 19:20:11 +1300 Subject: [PySide] simple QTableView example In-Reply-To: <525BE1EC.5000400@bluewin.ch> References: <848951203488568137@unknownmsgid>, <5259B5D5.8000505@ohufx.com> <5259c8d3.486b0e0a.0d06.ffffc793@mx.google.com> <5259CF8F.9090602@bluewin.ch> <525A816E.2050200@ohufx.com> <525A896E.9060902@bluewin.ch> <525A89F5.2000404@ohufx.com> <525BE1EC.5000400@bluewin.ch> Message-ID: <5260D31B.2050309@ohufx.com> Hi Aaron, thanks again for this example, it's a huge help! I have re-written everything from scratch following your example and everything is going well, I just can't figure out how to make the TaskWidget scale horizontally when the main application window is scaled. I have tried re-implementing sizeHint() on the container widget but to no avail. What am I missing? Cheers, frank On 15/10/13 1:22 AM, Aaron Richiger wrote: > Hello Frank! > > I just implemented the approach I told you yesterday (without > QTableView, QListView, etc because you wanted animations). You can see > the code of the working app in the attachment, it's in a classical MVC > setup. Because dealing with databases is a bit more work when not > using QSqlTableModel, I save and load tasks and user settings between > sessions using pickle. I did not spend much time on a nice design, > it's just to give you some sample code in case you really want the > animations. With some more lines of code, you can pimp the design > according to your wishes. > > Have a nice day! > Aaron > > > > Am 13.10.2013 13:54, schrieb Frank Rueter | OHUfx: >> sweet, that was my hunch, just didn't want to barge in the wrong >> direction. >> I will keep doing some more basics as per the suggestions from you >> and the others before embarking on this one, but have an idea now how >> to tackle it. >> >> Cheers, >> frank >> >> On 13/10/13 1:52 PM, Aaron Richiger wrote: >>> Hello Frank! >>> >>> You're welcome. I will send you more details later (do not have too >>> much time for the moment). But just to give you the direction: >>> >>> If the animation is a must-have, I would not go the way with >>> QTableView nor the way with QListView or QTreeView. Without >>> animation, those are perfect, but if you really want the fancy >>> animations, I would do it like this: >>> >>> - Implement a widget to show a TODO-Item >>> - Show them absolutely positioned one after the other >>> - Implement buttons for "Add new", "Sort", "Filter" >>> - In case of sort or filtering: calculate new position for each >>> item, animate it to new position using QParallelAnimationGroup >>> >>> See you later! >>> Aaron >>> >>> >>> >>> >>> >>> Am 13.10.2013 13:18, schrieb Frank Rueter | OHUfx: >>>> Great, thanks Tibold and Aaron! That all makes sense. >>>> >>>> Incidentally I do have planned a bit more than just the standard >>>> table UI but thought I'd leave that for when I'm more comfortable >>>> with the basic concepts again. >>>> So am keen to test all suggested approaches and have a feeling I >>>> might have to go with a custom solution as I want some animation to >>>> happen when sorting (each line moving to it's new position) - but >>>> that's for later, for now I will stick to the basics. >>>> >>>> Aaron, when trying the setItemDelegateForColumn (sorry, how could I >>>> not have seen this one before) things work fine but I have to cast >>>> the incoming data to int() explicitly in side the setEditorData. >>>> The setModelData method seems to automatically cast the integer >>>> back to a string. Is this the right way to do it? >>>> >>>> def setEditorData(self, spinBox, index): >>>> value = index.model().data(index) >>>> spinBox.setValue(*int(value)*)*# cast string to int* >>>> >>>> def setModelData(self, spinBox, model, index): >>>> spinBox.interpretText() >>>> value = spinBox.value() >>>> model.setData(index, *value*)*# no need to cast int back to >>>> string?* >>>> >>>> >>>> Looking ahead: If I want to make the rows/tasks animate to their >>>> new positions upon sorting, can I re-implement the paint methods >>>> of, say, a QAbstractItemView or do I have to go back further and do >>>> more manual work? >>>> I need to stick to the standard PySide package for this for various >>>> reasons. >>>> >>>> Cheers and thanks again Tibold, Aaron and Sebastian, you are a >>>> great help as usual! >>>> >>>> frank >>>> >>>> >>>> >>>> On 13/10/13 12:39 AM, Aaron Richiger wrote: >>>>> Hello! >>>>> >>>>> Tibolds approach would work (and could result in a nicer UI). Both >>>>> solutions are possible, some thoughts about the QTableView approach: >>>>> >>>>> - your app smells like a future database app. QTableView is in >>>>> advantage then, because by using QSqlTableModel, you get all the >>>>> mapping betwenn the db and the model for free. >>>>> - By using QTableView, sorting, filtering etc. is already included >>>>> and if your table has manymany rows, it will be much faster than >>>>> any self implemented filtering/sorting algorithm. But as long, as >>>>> your todo list doesn't have thousands of entries (and I hope so >>>>> for you:-), performance isn't an argument. >>>>> >>>>> Changes to your code to have the spinbox in the middle column only: >>>>> >>>>> priorityDelegate = SpinBoxDelegate(tableView) >>>>> tableView.setItemDelegateForColumn(1, priorityDelegate) >>>>> >>>>> Like this, the first column remains "text-editable", and for the >>>>> last column with the checkbox, you don't even necessarily have to >>>>> implement a new delegate, reimplementing .flags(), setData() and >>>>> data() methods of your model is enough (but if you want a pure >>>>> checkbox without a label next to it, you have to write your own >>>>> delegate, I could send you the code). >>>>> >>>>> Feel free to choose what ever way you want, both are perfectly >>>>> doable, having advantages where the other variant has disadvantages... >>>>> >>>>> Cheers >>>>> Aaron >>>>> >>>>> >>>>> Am 13.10.2013 00:06, schrieb Tibold Kandrai: >>>>>> If you ask me personally, I wouldn't use QTableWidget. Look into >>>>>> QTreeView or QListWidget. >>>>>> I think they are more suitable for such tasks and are easier to >>>>>> handle. >>>>>> With QTreeView you can use QItemDelegate, to create a special >>>>>> rendering. >>>>>> With QListWidget you can simply add a widget per row and inside >>>>>> the widget you can put whatever. >>>>>> ATM I'm in the middle of a 2000 km road trip so I can't rally >>>>>> provide you sample's, but if you need help next week I'm glad to >>>>>> give you samples how to use these widgets. >>>>>> Cheers, >>>>>> Tibold Kandrai >>>>>> *From:* Frank Rueter | OHUfx >>>>>> *Sent:* ?Saturday?, ?12? ?October? ?2013 ?22?:?49 >>>>>> *To:* Tibold Kandrai >>>>>> *Cc:* pyside at qt-project.org >>>>>> Is this the best way to do it though? I.e. having one item per >>>>>> cell? s there another way at all? >>>>>> I'm still a bit lost in the model/view design and can't find the >>>>>> answer online. >>>>>> >>>>>> I'm simply trying to have each row represent a "task" with a >>>>>> title/description (string), a status (boolean) and a priority >>>>>> (integer). For the integer I need a spin box and for the boolean >>>>>> I need a checkbox. The examples I found online all seem to be >>>>>> doing something slightly different and often use different ways >>>>>> which makes matters more confusing. >>>>>> >>>>>> Here is what I have at the moment: >>>>>> http://pastebin.com/H3GD0xVB >>>>>> >>>>>> The "status" and "priority" values don't display currnelty as I >>>>>> haven't figured out how to properly assign a delegate to just >>>>>> those cells. At the top I tried to define a n item delegete for a >>>>>> spin box but I'm not sure how to properly assign it. >>>>>> >>>>>> Do I have to make the delegate draw different widgets (spin box / >>>>>> checkbox) depending on data type, or can/should I use a different >>>>>> delegate for each cell? >>>>>> >>>>>> I'm sure the answer is right in front of me, could you please >>>>>> help one more time please?! >>>>>> >>>>>> Cheers, >>>>>> frank >>>>>> >>>>>> >>>>>> On 11/10/13 4:00 PM, Tibold Kandrai wrote: >>>>>> >>>>>> If you mean to use a QStandardItem per cell then yes. >>>>>> Also for storing values that you want to display, use the >>>>>> Qt.DisplayRole as role. >>>>>> >>>>>> Cheers, >>>>>> Tibold Kandrai >>>>>> ------------------------------------------------------------------------ >>>>>> From: Frank Rueter | OHUfx >>>>>> Sent: ?11/?10/?2013 14:35 >>>>>> To: Tibold Kandrai >>>>>> Cc: pyside at qt-project.org >>>>>> Subject: Re: [PySide] simple QTableView example >>>>>> >>>>>> one more silly question if I may: >>>>>> So if I have a task like this: >>>>>> newTask = {'title':'new task', 'priority':1, >>>>>> 'status':False} >>>>>> >>>>>> and need to store the data in one row in the model I should >>>>>> use three different items, one for each value, right?! >>>>>> >>>>>> e.g.: >>>>>> >>>>>> newTask = {'title':'new task', 'priority':1, >>>>>> 'status':False} >>>>>> row = self.model.rowCount() >>>>>> for column, attr in enumerate(['title', 'priority', >>>>>> 'status']): >>>>>> newItem = QtGui.QStandardItem(newTask[attr]) >>>>>> self.model.setItem(row, column, newItem) >>>>>> >>>>>> then juggle delegates or widgets to use a spin box for the >>>>>> integer and a checkbox for the boolean... >>>>>> >>>>>> Thanks for the help! >>>>>> >>>>>> Cheers, >>>>>> frank >>>>>> >>>>>> On 10/10/13 11:44 PM, Tibold Kandrai wrote: >>>>>> >>>>>> Hey, >>>>>> I'm not sure I understand the problem correctly. >>>>>> If you want to store data in a cell or a QStandardItem, >>>>>> then you need to use setData() and data(). >>>>>> Generally you shouldn't need to subclass QStandardItem or >>>>>> QStandardItemModel. >>>>>> Here is an example how: >>>>>> # Define roles >>>>>> FINISHED_ROLE = QtCore.Qt.UserRole + 1 >>>>>> PRIORITY_ROLE = QtCore.Qt.UserRole + 2 >>>>>> # Create model >>>>>> model = QtGui.QStandardItemModel() >>>>>> item = QtGui.QStandarItem() >>>>>> model.appendRow(item) >>>>>> item_index = item.index() >>>>>> # Store data using the item >>>>>> item.setData(finished, FINISHED_ROLE) >>>>>> item.setData(priority, PRIORITY_ROLE) >>>>>> # Store data using the model >>>>>> model.setData(item_index, finished, FINISHED_ROLE) >>>>>> model.setData(item_index, priority, PRIORITY_ROLE) >>>>>> # Retrieve data using the item >>>>>> finished = item.data(FINISHED_ROLE) >>>>>> priority = item.data(PRIORITY_ROLE) >>>>>> # Retrieve data using the model >>>>>> finished = model.data(item_index, FINISHED_ROLE) >>>>>> priority = model.data(item_index, PRIORITY_ROLE) >>>>>> In some cases like click event handlers, you have the >>>>>> model and the item index, there it's easier to use the >>>>>> model methods instead of finding the item and then >>>>>> getting the data. ? >>>>>> Hope it helps. >>>>>> Cheers, >>>>>> Tibold >>>>>> *From:* Frank Rueter | OHUfx >>>>>> *Sent:* ?2013? ?October? ?10?, ?Thursday ?19?:?37 >>>>>> *To:* pyside at qt-project.org >>>>>> After looking at some more examples I think my approach >>>>>> of storing multiple values in one item is fundamentally >>>>>> flawed. >>>>>> Instead I should be using one item per cell and assign >>>>>> the respective data, right?! >>>>>> >>>>>> I shall re-write the example accordingly, sorry for the >>>>>> noise. >>>>>> >>>>>> frank >>>>>> >>>>>> On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: >>>>>> >>>>>> I meant QTableView not QStandardTableView :/ >>>>>> >>>>>> On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: >>>>>> >>>>>> Hi all, >>>>>> >>>>>> after a bit of a break from PySide I am trying to >>>>>> wrap my head around the model/view stuff again >>>>>> and am trying to understand how a very simple >>>>>> example would work where a QStandarItem has >>>>>> properties "title", "priority" and "finished" >>>>>> which are displayed via a QStandardTableView. >>>>>> >>>>>> I am struggling with understanding how to >>>>>> properly display the above three properties in >>>>>> the table's columns. I tried setting the data() >>>>>> method on the model like this: >>>>>> >>>>>> / def data(self, index, >>>>>> role=QtCore.Qt.DisplayRole):// >>>>>> // '''Return data based on index and role'''// >>>>>> // item = self.itemFromIndex(index)// >>>>>> // if index.column() == 0:// >>>>>> // return item.title// >>>>>> // elif index.column() == 1:// >>>>>> // return item.finished// >>>>>> // elif index.column() == 2:// >>>>>> // return item.priority/ >>>>>> >>>>>> but for some reason it errors saying item does >>>>>> not have attribute "finished" even though my item >>>>>> object s declared like this: >>>>>> >>>>>> /class TaskItem(QtGui.QStandardItem):// >>>>>> // '''Item to hold a task for the todo list'''// >>>>>> //// >>>>>> // def __init__(self, title, finished=False, >>>>>> priority=1):// >>>>>> // super(TaskItem, self).__init__(title)// >>>>>> // self.title = title// >>>>>> // self.finished = finished// >>>>>> // self.priority = priority/ >>>>>> >>>>>> >>>>>> When printing the item's attributes via dir() I >>>>>> see that, when the model is populated, the last >>>>>> item it attempts to call is not my custom item >>>>>> object, but something else with less attributes >>>>>> and methods. Clearly there is something I haven't >>>>>> quite understood about this process. >>>>>> >>>>>> Also, if I use the models data() method as >>>>>> pointed out above, I get checkboxes in the cells >>>>>> which I don't want at this stage. >>>>>> >>>>>> Can somebody please help me understand where I go >>>>>> wrong? >>>>>> Attached is the whole test code. >>>>>> >>>>>> Cheers, >>>>>> frank >>>>>> >>>>>> P.S.: I am aware that the controller code >>>>>> shouldn't necessarily live in the QWidget's >>>>>> methods, this is just for testing which I will >>>>>> clean up once I get how it all connects again >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> PySide mailing list >>>>>> PySide at qt-project.org >>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> PySide mailing list >>>>>> PySide at qt-project.org >>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> PySide mailing list >>>>>> PySide at qt-project.org >>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> PySide mailing list >>>>> PySide at qt-project.org >>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>> >>>> >>>> >>>> _______________________________________________ >>>> PySide mailing list >>>> PySide at qt-project.org >>>> http://lists.qt-project.org/mailman/listinfo/pyside >>> >>> >>> >>> _______________________________________________ >>> PySide mailing list >>> PySide at qt-project.org >>> http://lists.qt-project.org/mailman/listinfo/pyside >> >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From a.richi at bluewin.ch Fri Oct 18 12:29:15 2013 From: a.richi at bluewin.ch (Aaron Richiger) Date: Fri, 18 Oct 2013 12:29:15 +0200 Subject: [PySide] simple QTableView example In-Reply-To: <5260D31B.2050309@ohufx.com> References: <848951203488568137@unknownmsgid>, <5259B5D5.8000505@ohufx.com> <5259c8d3.486b0e0a.0d06.ffffc793@mx.google.com> <5259CF8F.9090602@bluewin.ch> <525A816E.2050200@ohufx.com> <525A896E.9060902@bluewin.ch> <525A89F5.2000404@ohufx.com> <525BE1EC.5000400@bluewin.ch> <5260D31B.2050309@ohufx.com> Message-ID: <52610D7B.3030209@bluewin.ch> Hi Frank! You're welcome! By catching the resizeEvent in the MainWindow, you can then update() it. def resizeEvent(self, event): self.update() When resizing taskContainer in the update() method, you of course should replace the fix value of 300 by something more dynamic, "self.scrollArea.width() - 2" works perfectly for me. Minus 2 because of the border width of the scrollarea, otherwise a horizontal scrollbar shows up... Therefore I made scrollArea a class member. You get the entire code in the attachment. Cheers! Aaron Am 18.10.2013 08:20, schrieb Frank Rueter | OHUfx: > Hi Aaron, > > thanks again for this example, it's a huge help! > I have re-written everything from scratch following your example and > everything is going well, I just can't figure out how to make the > TaskWidget scale horizontally when the main application window is scaled. > I have tried re-implementing sizeHint() on the container widget but to > no avail. > What am I missing? > > Cheers, > frank > > On 15/10/13 1:22 AM, Aaron Richiger wrote: >> Hello Frank! >> >> I just implemented the approach I told you yesterday (without >> QTableView, QListView, etc because you wanted animations). You can >> see the code of the working app in the attachment, it's in a >> classical MVC setup. Because dealing with databases is a bit more >> work when not using QSqlTableModel, I save and load tasks and user >> settings between sessions using pickle. I did not spend much time on >> a nice design, it's just to give you some sample code in case you >> really want the animations. With some more lines of code, you can >> pimp the design according to your wishes. >> >> Have a nice day! >> Aaron >> >> >> >> Am 13.10.2013 13:54, schrieb Frank Rueter | OHUfx: >>> sweet, that was my hunch, just didn't want to barge in the wrong >>> direction. >>> I will keep doing some more basics as per the suggestions from you >>> and the others before embarking on this one, but have an idea now >>> how to tackle it. >>> >>> Cheers, >>> frank >>> >>> On 13/10/13 1:52 PM, Aaron Richiger wrote: >>>> Hello Frank! >>>> >>>> You're welcome. I will send you more details later (do not have too >>>> much time for the moment). But just to give you the direction: >>>> >>>> If the animation is a must-have, I would not go the way with >>>> QTableView nor the way with QListView or QTreeView. Without >>>> animation, those are perfect, but if you really want the fancy >>>> animations, I would do it like this: >>>> >>>> - Implement a widget to show a TODO-Item >>>> - Show them absolutely positioned one after the other >>>> - Implement buttons for "Add new", "Sort", "Filter" >>>> - In case of sort or filtering: calculate new position for each >>>> item, animate it to new position using QParallelAnimationGroup >>>> >>>> See you later! >>>> Aaron >>>> >>>> >>>> >>>> >>>> >>>> Am 13.10.2013 13:18, schrieb Frank Rueter | OHUfx: >>>>> Great, thanks Tibold and Aaron! That all makes sense. >>>>> >>>>> Incidentally I do have planned a bit more than just the standard >>>>> table UI but thought I'd leave that for when I'm more comfortable >>>>> with the basic concepts again. >>>>> So am keen to test all suggested approaches and have a feeling I >>>>> might have to go with a custom solution as I want some animation >>>>> to happen when sorting (each line moving to it's new position) - >>>>> but that's for later, for now I will stick to the basics. >>>>> >>>>> Aaron, when trying the setItemDelegateForColumn (sorry, how could >>>>> I not have seen this one before) things work fine but I have to >>>>> cast the incoming data to int() explicitly in side the >>>>> setEditorData. The setModelData method seems to automatically cast >>>>> the integer back to a string. Is this the right way to do it? >>>>> >>>>> def setEditorData(self, spinBox, index): >>>>> value = index.model().data(index) >>>>> spinBox.setValue(*int(value)*)*# cast string to int* >>>>> >>>>> def setModelData(self, spinBox, model, index): >>>>> spinBox.interpretText() >>>>> value = spinBox.value() >>>>> model.setData(index, *value*)*# no need to cast int back >>>>> to string?* >>>>> >>>>> >>>>> Looking ahead: If I want to make the rows/tasks animate to their >>>>> new positions upon sorting, can I re-implement the paint methods >>>>> of, say, a QAbstractItemView or do I have to go back further and >>>>> do more manual work? >>>>> I need to stick to the standard PySide package for this for >>>>> various reasons. >>>>> >>>>> Cheers and thanks again Tibold, Aaron and Sebastian, you are a >>>>> great help as usual! >>>>> >>>>> frank >>>>> >>>>> >>>>> >>>>> On 13/10/13 12:39 AM, Aaron Richiger wrote: >>>>>> Hello! >>>>>> >>>>>> Tibolds approach would work (and could result in a nicer UI). >>>>>> Both solutions are possible, some thoughts about the QTableView >>>>>> approach: >>>>>> >>>>>> - your app smells like a future database app. QTableView is in >>>>>> advantage then, because by using QSqlTableModel, you get all the >>>>>> mapping betwenn the db and the model for free. >>>>>> - By using QTableView, sorting, filtering etc. is already >>>>>> included and if your table has manymany rows, it will be much >>>>>> faster than any self implemented filtering/sorting algorithm. But >>>>>> as long, as your todo list doesn't have thousands of entries (and >>>>>> I hope so for you:-), performance isn't an argument. >>>>>> >>>>>> Changes to your code to have the spinbox in the middle column only: >>>>>> >>>>>> priorityDelegate = SpinBoxDelegate(tableView) >>>>>> tableView.setItemDelegateForColumn(1, priorityDelegate) >>>>>> >>>>>> Like this, the first column remains "text-editable", and for the >>>>>> last column with the checkbox, you don't even necessarily have to >>>>>> implement a new delegate, reimplementing .flags(), setData() and >>>>>> data() methods of your model is enough (but if you want a pure >>>>>> checkbox without a label next to it, you have to write your own >>>>>> delegate, I could send you the code). >>>>>> >>>>>> Feel free to choose what ever way you want, both are perfectly >>>>>> doable, having advantages where the other variant has >>>>>> disadvantages... >>>>>> >>>>>> Cheers >>>>>> Aaron >>>>>> >>>>>> >>>>>> Am 13.10.2013 00:06, schrieb Tibold Kandrai: >>>>>>> If you ask me personally, I wouldn't use QTableWidget. Look into >>>>>>> QTreeView or QListWidget. >>>>>>> I think they are more suitable for such tasks and are easier to >>>>>>> handle. >>>>>>> With QTreeView you can use QItemDelegate, to create a special >>>>>>> rendering. >>>>>>> With QListWidget you can simply add a widget per row and inside >>>>>>> the widget you can put whatever. >>>>>>> ATM I'm in the middle of a 2000 km road trip so I can't rally >>>>>>> provide you sample's, but if you need help next week I'm glad to >>>>>>> give you samples how to use these widgets. >>>>>>> Cheers, >>>>>>> Tibold Kandrai >>>>>>> *From:* Frank Rueter | OHUfx >>>>>>> *Sent:* ?Saturday?, ?12? ?October? ?2013 ?22?:?49 >>>>>>> *To:* Tibold Kandrai >>>>>>> *Cc:* pyside at qt-project.org >>>>>>> Is this the best way to do it though? I.e. having one item per >>>>>>> cell? s there another way at all? >>>>>>> I'm still a bit lost in the model/view design and can't find the >>>>>>> answer online. >>>>>>> >>>>>>> I'm simply trying to have each row represent a "task" with a >>>>>>> title/description (string), a status (boolean) and a priority >>>>>>> (integer). For the integer I need a spin box and for the boolean >>>>>>> I need a checkbox. The examples I found online all seem to be >>>>>>> doing something slightly different and often use different ways >>>>>>> which makes matters more confusing. >>>>>>> >>>>>>> Here is what I have at the moment: >>>>>>> http://pastebin.com/H3GD0xVB >>>>>>> >>>>>>> The "status" and "priority" values don't display currnelty as I >>>>>>> haven't figured out how to properly assign a delegate to just >>>>>>> those cells. At the top I tried to define a n item delegete for >>>>>>> a spin box but I'm not sure how to properly assign it. >>>>>>> >>>>>>> Do I have to make the delegate draw different widgets (spin box >>>>>>> / checkbox) depending on data type, or can/should I use a >>>>>>> different delegate for each cell? >>>>>>> >>>>>>> I'm sure the answer is right in front of me, could you please >>>>>>> help one more time please?! >>>>>>> >>>>>>> Cheers, >>>>>>> frank >>>>>>> >>>>>>> >>>>>>> On 11/10/13 4:00 PM, Tibold Kandrai wrote: >>>>>>> >>>>>>> If you mean to use a QStandardItem per cell then yes. >>>>>>> Also for storing values that you want to display, use the >>>>>>> Qt.DisplayRole as role. >>>>>>> >>>>>>> Cheers, >>>>>>> Tibold Kandrai >>>>>>> ------------------------------------------------------------------------ >>>>>>> From: Frank Rueter | OHUfx >>>>>>> Sent: ?11/?10/?2013 14:35 >>>>>>> To: Tibold Kandrai >>>>>>> Cc: pyside at qt-project.org >>>>>>> Subject: Re: [PySide] simple QTableView example >>>>>>> >>>>>>> one more silly question if I may: >>>>>>> So if I have a task like this: >>>>>>> newTask = {'title':'new task', 'priority':1, >>>>>>> 'status':False} >>>>>>> >>>>>>> and need to store the data in one row in the model I should >>>>>>> use three different items, one for each value, right?! >>>>>>> >>>>>>> e.g.: >>>>>>> >>>>>>> newTask = {'title':'new task', 'priority':1, >>>>>>> 'status':False} >>>>>>> row = self.model.rowCount() >>>>>>> for column, attr in enumerate(['title', 'priority', >>>>>>> 'status']): >>>>>>> newItem = QtGui.QStandardItem(newTask[attr]) >>>>>>> self.model.setItem(row, column, newItem) >>>>>>> >>>>>>> then juggle delegates or widgets to use a spin box for the >>>>>>> integer and a checkbox for the boolean... >>>>>>> >>>>>>> Thanks for the help! >>>>>>> >>>>>>> Cheers, >>>>>>> frank >>>>>>> >>>>>>> On 10/10/13 11:44 PM, Tibold Kandrai wrote: >>>>>>> >>>>>>> Hey, >>>>>>> I'm not sure I understand the problem correctly. >>>>>>> If you want to store data in a cell or a QStandardItem, >>>>>>> then you need to use setData() and data(). >>>>>>> Generally you shouldn't need to subclass QStandardItem >>>>>>> or QStandardItemModel. >>>>>>> Here is an example how: >>>>>>> # Define roles >>>>>>> FINISHED_ROLE = QtCore.Qt.UserRole + 1 >>>>>>> PRIORITY_ROLE = QtCore.Qt.UserRole + 2 >>>>>>> # Create model >>>>>>> model = QtGui.QStandardItemModel() >>>>>>> item = QtGui.QStandarItem() >>>>>>> model.appendRow(item) >>>>>>> item_index = item.index() >>>>>>> # Store data using the item >>>>>>> item.setData(finished, FINISHED_ROLE) >>>>>>> item.setData(priority, PRIORITY_ROLE) >>>>>>> # Store data using the model >>>>>>> model.setData(item_index, finished, FINISHED_ROLE) >>>>>>> model.setData(item_index, priority, PRIORITY_ROLE) >>>>>>> # Retrieve data using the item >>>>>>> finished = item.data(FINISHED_ROLE) >>>>>>> priority = item.data(PRIORITY_ROLE) >>>>>>> # Retrieve data using the model >>>>>>> finished = model.data(item_index, FINISHED_ROLE) >>>>>>> priority = model.data(item_index, PRIORITY_ROLE) >>>>>>> In some cases like click event handlers, you have the >>>>>>> model and the item index, there it's easier to use the >>>>>>> model methods instead of finding the item and then >>>>>>> getting the data. ? >>>>>>> Hope it helps. >>>>>>> Cheers, >>>>>>> Tibold >>>>>>> *From:* Frank Rueter | OHUfx >>>>>>> *Sent:* ?2013? ?October? ?10?, ?Thursday ?19?:?37 >>>>>>> *To:* pyside at qt-project.org >>>>>>> After looking at some more examples I think my approach >>>>>>> of storing multiple values in one item is fundamentally >>>>>>> flawed. >>>>>>> Instead I should be using one item per cell and assign >>>>>>> the respective data, right?! >>>>>>> >>>>>>> I shall re-write the example accordingly, sorry for the >>>>>>> noise. >>>>>>> >>>>>>> frank >>>>>>> >>>>>>> On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: >>>>>>> >>>>>>> I meant QTableView not QStandardTableView :/ >>>>>>> >>>>>>> On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: >>>>>>> >>>>>>> Hi all, >>>>>>> >>>>>>> after a bit of a break from PySide I am trying >>>>>>> to wrap my head around the model/view stuff >>>>>>> again and am trying to understand how a very >>>>>>> simple example would work where a QStandarItem >>>>>>> has properties "title", "priority" and >>>>>>> "finished" which are displayed via a >>>>>>> QStandardTableView. >>>>>>> >>>>>>> I am struggling with understanding how to >>>>>>> properly display the above three properties in >>>>>>> the table's columns. I tried setting the data() >>>>>>> method on the model like this: >>>>>>> >>>>>>> / def data(self, index, >>>>>>> role=QtCore.Qt.DisplayRole):// >>>>>>> // '''Return data based on index and >>>>>>> role'''// >>>>>>> // item = self.itemFromIndex(index)// >>>>>>> // if index.column() == 0:// >>>>>>> // return item.title// >>>>>>> // elif index.column() == 1:// >>>>>>> // return item.finished// >>>>>>> // elif index.column() == 2:// >>>>>>> // return item.priority/ >>>>>>> >>>>>>> but for some reason it errors saying item does >>>>>>> not have attribute "finished" even though my >>>>>>> item object s declared like this: >>>>>>> >>>>>>> /class TaskItem(QtGui.QStandardItem):// >>>>>>> // '''Item to hold a task for the todo list'''// >>>>>>> //// >>>>>>> // def __init__(self, title, finished=False, >>>>>>> priority=1):// >>>>>>> // super(TaskItem, self).__init__(title)// >>>>>>> // self.title = title// >>>>>>> // self.finished = finished// >>>>>>> // self.priority = priority/ >>>>>>> >>>>>>> >>>>>>> When printing the item's attributes via dir() I >>>>>>> see that, when the model is populated, the last >>>>>>> item it attempts to call is not my custom item >>>>>>> object, but something else with less attributes >>>>>>> and methods. Clearly there is something I >>>>>>> haven't quite understood about this process. >>>>>>> >>>>>>> Also, if I use the models data() method as >>>>>>> pointed out above, I get checkboxes in the cells >>>>>>> which I don't want at this stage. >>>>>>> >>>>>>> Can somebody please help me understand where I >>>>>>> go wrong? >>>>>>> Attached is the whole test code. >>>>>>> >>>>>>> Cheers, >>>>>>> frank >>>>>>> >>>>>>> P.S.: I am aware that the controller code >>>>>>> shouldn't necessarily live in the QWidget's >>>>>>> methods, this is just for testing which I will >>>>>>> clean up once I get how it all connects again >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> PySide mailing list >>>>>>> PySide at qt-project.org >>>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> PySide mailing list >>>>>>> PySide at qt-project.org >>>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> PySide mailing list >>>>>>> PySide at qt-project.org >>>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> PySide mailing list >>>>>> PySide at qt-project.org >>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> PySide mailing list >>>>> PySide at qt-project.org >>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>> >>>> >>>> >>>> _______________________________________________ >>>> PySide mailing list >>>> PySide at qt-project.org >>>> http://lists.qt-project.org/mailman/listinfo/pyside >>> >>> >>> >>> _______________________________________________ >>> PySide mailing list >>> PySide at qt-project.org >>> http://lists.qt-project.org/mailman/listinfo/pyside >> >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: todo_list.py Type: text/x-python Size: 10158 bytes Desc: not available URL: From tismer at stackless.com Fri Oct 18 18:07:44 2013 From: tismer at stackless.com (Christian Tismer) Date: Fri, 18 Oct 2013 18:07:44 +0200 Subject: [PySide] 1.2.1 build failure OS X In-Reply-To: <52614DBD.2040104@kitware.com> References: <5260A145.4020005@stackless.com> <5260C7CF.2070700@stackless.com> <5260D10A.4040107@stackless.com> <52614DBD.2040104@kitware.com> Message-ID: <52615CD0.3000709@stackless.com> On 18.10.13 17:03, Matthew Woehlke wrote: > On 2013-10-18 02:11, Christian Tismer wrote: >> Here is a small patch that removes the need to set QTDIR >> when using homebrew. >> >> https://github.com/ctismer/pyside-setup/commit/6f49a93f59b930be858cd1cc9174de74f38ff393 >> > > Chris, can you push this to pyside's gerrit? See > http://qt-project.org/wiki/Setting-up-Gerrit. It is already under review as a pull request. My path is a bit rigorous because it completely removes a nice workaround that I in the end found obsolete, because qmake provides a variable that is just not exposed by qtinfo.py for use by setup.py . I checked that it works with homebrew, but I did not test with another way to install QT. After that is confirmed, I think we can go for it. cheers -- chris -- Christian Tismer :^) Software Consulting : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de phone +49 173 24 18 776 fax +49 (30) 700143-0023 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From matthew.woehlke at kitware.com Fri Oct 18 18:50:18 2013 From: matthew.woehlke at kitware.com (Matthew Woehlke) Date: Fri, 18 Oct 2013 12:50:18 -0400 Subject: [PySide] 1.2.1 build failure OS X In-Reply-To: <52615CD0.3000709@stackless.com> References: <5260A145.4020005@stackless.com> <5260C7CF.2070700@stackless.com> <5260D10A.4040107@stackless.com> <52614DBD.2040104@kitware.com> <52615CD0.3000709@stackless.com> Message-ID: On 2013-10-18 12:07, Christian Tismer wrote: > On 18.10.13 17:03, Matthew Woehlke wrote: >> On 2013-10-18 02:11, Christian Tismer wrote: >>> Here is a small patch that removes the need to set QTDIR >>> when using homebrew. >>> >>> https://github.com/ctismer/pyside-setup/commit/6f49a93f59b930be858cd1cc9174de74f38ff393 >>> >> >> Chris, can you push this to pyside's gerrit? See >> http://qt-project.org/wiki/Setting-up-Gerrit. > > It is already under review as a pull request. Last I knew, the canonical upstream was git://gitorious.org/pyside and contributions get approved/merged through Qt's gerrit. Did I miss something? Is https://github.com/PySide now canonical? -- Matthew From jpe at wingware.com Fri Oct 18 19:00:32 2013 From: jpe at wingware.com (John Ehresman) Date: Fri, 18 Oct 2013 13:00:32 -0400 Subject: [PySide] 1.2.1 build failure OS X In-Reply-To: References: <5260A145.4020005@stackless.com> <5260C7CF.2070700@stackless.com> <5260D10A.4040107@stackless.com> <52614DBD.2040104@kitware.com> <52615CD0.3000709@stackless.com> Message-ID: <52616930.4050700@wingware.com> On 10/18/13 12:50 PM, Matthew Woehlke wrote: > On 2013-10-18 12:07, Christian Tismer wrote: >> On 18.10.13 17:03, Matthew Woehlke wrote: >>> On 2013-10-18 02:11, Christian Tismer wrote: >>>> Here is a small patch that removes the need to set QTDIR >>>> when using homebrew. >>>> >>>> https://github.com/ctismer/pyside-setup/commit/6f49a93f59b930be858cd1cc9174de74f38ff393 >>>> >>> >>> Chris, can you push this to pyside's gerrit? See >>> http://qt-project.org/wiki/Setting-up-Gerrit. >> >> It is already under review as a pull request. > > Last I knew, the canonical upstream was git://gitorious.org/pyside and > contributions get approved/merged through Qt's gerrit. > > Did I miss something? Is https://github.com/PySide now canonical? This is pyside-setup, which is still separate from pyside. Cheers, John From matthew.woehlke at kitware.com Fri Oct 18 20:24:42 2013 From: matthew.woehlke at kitware.com (Matthew Woehlke) Date: Fri, 18 Oct 2013 14:24:42 -0400 Subject: [PySide] 1.2.1 build failure OS X In-Reply-To: <52616930.4050700@wingware.com> References: <5260A145.4020005@stackless.com> <5260C7CF.2070700@stackless.com> <5260D10A.4040107@stackless.com> <52614DBD.2040104@kitware.com> <52615CD0.3000709@stackless.com> <52616930.4050700@wingware.com> Message-ID: On 2013-10-18 13:00, John Ehresman wrote: > On 10/18/13 12:50 PM, Matthew Woehlke wrote: >> On 2013-10-18 12:07, Christian Tismer wrote: >>> On 18.10.13 17:03, Matthew Woehlke wrote: >>>> On 2013-10-18 02:11, Christian Tismer wrote: >>>>> Here is a small patch that removes the need to set QTDIR >>>>> when using homebrew. >>>>> >>>>> https://github.com/ctismer/pyside-setup/commit/6f49a93f59b930be858cd1cc9174de74f38ff393 >>>>> >>>> >>>> Chris, can you push this to pyside's gerrit? See >>>> http://qt-project.org/wiki/Setting-up-Gerrit. >>> >>> It is already under review as a pull request. >> >> Last I knew, the canonical upstream was git://gitorious.org/pyside and >> contributions get approved/merged through Qt's gerrit. >> >> Did I miss something? Is https://github.com/PySide now canonical? > > This is pyside-setup, which is still separate from pyside. Ah, I see... and now that I look closer, the pyside and shiboken repos there are clearly quite outdated... Please pardon my confusion :-). -- Matthew From frank at ohufx.com Sat Oct 19 00:35:20 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Sat, 19 Oct 2013 11:35:20 +1300 Subject: [PySide] simple QTableView example In-Reply-To: <52610D7B.3030209@bluewin.ch> References: <848951203488568137@unknownmsgid>, <5259B5D5.8000505@ohufx.com> <5259c8d3.486b0e0a.0d06.ffffc793@mx.google.com> <5259CF8F.9090602@bluewin.ch> <525A816E.2050200@ohufx.com> <525A896E.9060902@bluewin.ch> <525A89F5.2000404@ohufx.com> <525BE1EC.5000400@bluewin.ch> <5260D31B.2050309@ohufx.com> <52610D7B.3030209@bluewin.ch> Message-ID: <5261B7A8.6080106@ohufx.com> Perfect, thanks once again! On 18/10/13 11:29 PM, Aaron Richiger wrote: > Hi Frank! > > You're welcome! By catching the resizeEvent in the MainWindow, you can > then update() it. > > def resizeEvent(self, event): > self.update() > > When resizing taskContainer in the update() method, you of course > should replace the fix value of 300 by something more dynamic, > "self.scrollArea.width() - 2" works perfectly for me. Minus 2 because > of the border width of the scrollarea, otherwise a horizontal > scrollbar shows up... Therefore I made scrollArea a class member. You > get the entire code in the attachment. > > Cheers! > Aaron > > > > Am 18.10.2013 08:20, schrieb Frank Rueter | OHUfx: >> Hi Aaron, >> >> thanks again for this example, it's a huge help! >> I have re-written everything from scratch following your example and >> everything is going well, I just can't figure out how to make the >> TaskWidget scale horizontally when the main application window is scaled. >> I have tried re-implementing sizeHint() on the container widget but >> to no avail. >> What am I missing? >> >> Cheers, >> frank >> >> On 15/10/13 1:22 AM, Aaron Richiger wrote: >>> Hello Frank! >>> >>> I just implemented the approach I told you yesterday (without >>> QTableView, QListView, etc because you wanted animations). You can >>> see the code of the working app in the attachment, it's in a >>> classical MVC setup. Because dealing with databases is a bit more >>> work when not using QSqlTableModel, I save and load tasks and user >>> settings between sessions using pickle. I did not spend much time on >>> a nice design, it's just to give you some sample code in case you >>> really want the animations. With some more lines of code, you can >>> pimp the design according to your wishes. >>> >>> Have a nice day! >>> Aaron >>> >>> >>> >>> Am 13.10.2013 13:54, schrieb Frank Rueter | OHUfx: >>>> sweet, that was my hunch, just didn't want to barge in the wrong >>>> direction. >>>> I will keep doing some more basics as per the suggestions from you >>>> and the others before embarking on this one, but have an idea now >>>> how to tackle it. >>>> >>>> Cheers, >>>> frank >>>> >>>> On 13/10/13 1:52 PM, Aaron Richiger wrote: >>>>> Hello Frank! >>>>> >>>>> You're welcome. I will send you more details later (do not have >>>>> too much time for the moment). But just to give you the direction: >>>>> >>>>> If the animation is a must-have, I would not go the way with >>>>> QTableView nor the way with QListView or QTreeView. Without >>>>> animation, those are perfect, but if you really want the fancy >>>>> animations, I would do it like this: >>>>> >>>>> - Implement a widget to show a TODO-Item >>>>> - Show them absolutely positioned one after the other >>>>> - Implement buttons for "Add new", "Sort", "Filter" >>>>> - In case of sort or filtering: calculate new position for each >>>>> item, animate it to new position using QParallelAnimationGroup >>>>> >>>>> See you later! >>>>> Aaron >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> Am 13.10.2013 13:18, schrieb Frank Rueter | OHUfx: >>>>>> Great, thanks Tibold and Aaron! That all makes sense. >>>>>> >>>>>> Incidentally I do have planned a bit more than just the standard >>>>>> table UI but thought I'd leave that for when I'm more comfortable >>>>>> with the basic concepts again. >>>>>> So am keen to test all suggested approaches and have a feeling I >>>>>> might have to go with a custom solution as I want some animation >>>>>> to happen when sorting (each line moving to it's new position) - >>>>>> but that's for later, for now I will stick to the basics. >>>>>> >>>>>> Aaron, when trying the setItemDelegateForColumn (sorry, how could >>>>>> I not have seen this one before) things work fine but I have to >>>>>> cast the incoming data to int() explicitly in side the >>>>>> setEditorData. The setModelData method seems to automatically >>>>>> cast the integer back to a string. Is this the right way to do it? >>>>>> >>>>>> def setEditorData(self, spinBox, index): >>>>>> value = index.model().data(index) >>>>>> spinBox.setValue(*int(value)*)*# cast string to int* >>>>>> >>>>>> def setModelData(self, spinBox, model, index): >>>>>> spinBox.interpretText() >>>>>> value = spinBox.value() >>>>>> model.setData(index, *value*)*# no need to cast int back >>>>>> to string?* >>>>>> >>>>>> >>>>>> Looking ahead: If I want to make the rows/tasks animate to their >>>>>> new positions upon sorting, can I re-implement the paint methods >>>>>> of, say, a QAbstractItemView or do I have to go back further and >>>>>> do more manual work? >>>>>> I need to stick to the standard PySide package for this for >>>>>> various reasons. >>>>>> >>>>>> Cheers and thanks again Tibold, Aaron and Sebastian, you are a >>>>>> great help as usual! >>>>>> >>>>>> frank >>>>>> >>>>>> >>>>>> >>>>>> On 13/10/13 12:39 AM, Aaron Richiger wrote: >>>>>>> Hello! >>>>>>> >>>>>>> Tibolds approach would work (and could result in a nicer UI). >>>>>>> Both solutions are possible, some thoughts about the QTableView >>>>>>> approach: >>>>>>> >>>>>>> - your app smells like a future database app. QTableView is in >>>>>>> advantage then, because by using QSqlTableModel, you get all the >>>>>>> mapping betwenn the db and the model for free. >>>>>>> - By using QTableView, sorting, filtering etc. is already >>>>>>> included and if your table has manymany rows, it will be much >>>>>>> faster than any self implemented filtering/sorting algorithm. >>>>>>> But as long, as your todo list doesn't have thousands of entries >>>>>>> (and I hope so for you:-), performance isn't an argument. >>>>>>> >>>>>>> Changes to your code to have the spinbox in the middle column only: >>>>>>> >>>>>>> priorityDelegate = SpinBoxDelegate(tableView) >>>>>>> tableView.setItemDelegateForColumn(1, priorityDelegate) >>>>>>> >>>>>>> Like this, the first column remains "text-editable", and for the >>>>>>> last column with the checkbox, you don't even necessarily have >>>>>>> to implement a new delegate, reimplementing .flags(), setData() >>>>>>> and data() methods of your model is enough (but if you want a >>>>>>> pure checkbox without a label next to it, you have to write your >>>>>>> own delegate, I could send you the code). >>>>>>> >>>>>>> Feel free to choose what ever way you want, both are perfectly >>>>>>> doable, having advantages where the other variant has >>>>>>> disadvantages... >>>>>>> >>>>>>> Cheers >>>>>>> Aaron >>>>>>> >>>>>>> >>>>>>> Am 13.10.2013 00:06, schrieb Tibold Kandrai: >>>>>>>> If you ask me personally, I wouldn't use QTableWidget. Look >>>>>>>> into QTreeView or QListWidget. >>>>>>>> I think they are more suitable for such tasks and are easier to >>>>>>>> handle. >>>>>>>> With QTreeView you can use QItemDelegate, to create a special >>>>>>>> rendering. >>>>>>>> With QListWidget you can simply add a widget per row and inside >>>>>>>> the widget you can put whatever. >>>>>>>> ATM I'm in the middle of a 2000 km road trip so I can't rally >>>>>>>> provide you sample's, but if you need help next week I'm glad >>>>>>>> to give you samples how to use these widgets. >>>>>>>> Cheers, >>>>>>>> Tibold Kandrai >>>>>>>> *From:* Frank Rueter | OHUfx >>>>>>>> *Sent:* ?Saturday?, ?12? ?October? ?2013 ?22?:?49 >>>>>>>> *To:* Tibold Kandrai >>>>>>>> *Cc:* pyside at qt-project.org >>>>>>>> Is this the best way to do it though? I.e. having one item per >>>>>>>> cell? s there another way at all? >>>>>>>> I'm still a bit lost in the model/view design and can't find >>>>>>>> the answer online. >>>>>>>> >>>>>>>> I'm simply trying to have each row represent a "task" with a >>>>>>>> title/description (string), a status (boolean) and a priority >>>>>>>> (integer). For the integer I need a spin box and for the >>>>>>>> boolean I need a checkbox. The examples I found online all seem >>>>>>>> to be doing something slightly different and often use >>>>>>>> different ways which makes matters more confusing. >>>>>>>> >>>>>>>> Here is what I have at the moment: >>>>>>>> http://pastebin.com/H3GD0xVB >>>>>>>> >>>>>>>> The "status" and "priority" values don't display currnelty as I >>>>>>>> haven't figured out how to properly assign a delegate to just >>>>>>>> those cells. At the top I tried to define a n item delegete for >>>>>>>> a spin box but I'm not sure how to properly assign it. >>>>>>>> >>>>>>>> Do I have to make the delegate draw different widgets (spin box >>>>>>>> / checkbox) depending on data type, or can/should I use a >>>>>>>> different delegate for each cell? >>>>>>>> >>>>>>>> I'm sure the answer is right in front of me, could you please >>>>>>>> help one more time please?! >>>>>>>> >>>>>>>> Cheers, >>>>>>>> frank >>>>>>>> >>>>>>>> >>>>>>>> On 11/10/13 4:00 PM, Tibold Kandrai wrote: >>>>>>>> >>>>>>>> If you mean to use a QStandardItem per cell then yes. >>>>>>>> Also for storing values that you want to display, use the >>>>>>>> Qt.DisplayRole as role. >>>>>>>> >>>>>>>> Cheers, >>>>>>>> Tibold Kandrai >>>>>>>> ------------------------------------------------------------------------ >>>>>>>> From: Frank Rueter | OHUfx >>>>>>>> Sent: ?11/?10/?2013 14:35 >>>>>>>> To: Tibold Kandrai >>>>>>>> Cc: pyside at qt-project.org >>>>>>>> Subject: Re: [PySide] simple QTableView example >>>>>>>> >>>>>>>> one more silly question if I may: >>>>>>>> So if I have a task like this: >>>>>>>> newTask = {'title':'new task', 'priority':1, >>>>>>>> 'status':False} >>>>>>>> >>>>>>>> and need to store the data in one row in the model I should >>>>>>>> use three different items, one for each value, right?! >>>>>>>> >>>>>>>> e.g.: >>>>>>>> >>>>>>>> newTask = {'title':'new task', 'priority':1, >>>>>>>> 'status':False} >>>>>>>> row = self.model.rowCount() >>>>>>>> for column, attr in enumerate(['title', 'priority', >>>>>>>> 'status']): >>>>>>>> newItem = QtGui.QStandardItem(newTask[attr]) >>>>>>>> self.model.setItem(row, column, newItem) >>>>>>>> >>>>>>>> then juggle delegates or widgets to use a spin box for the >>>>>>>> integer and a checkbox for the boolean... >>>>>>>> >>>>>>>> Thanks for the help! >>>>>>>> >>>>>>>> Cheers, >>>>>>>> frank >>>>>>>> >>>>>>>> On 10/10/13 11:44 PM, Tibold Kandrai wrote: >>>>>>>> >>>>>>>> Hey, >>>>>>>> I'm not sure I understand the problem correctly. >>>>>>>> If you want to store data in a cell or a QStandardItem, >>>>>>>> then you need to use setData() and data(). >>>>>>>> Generally you shouldn't need to subclass QStandardItem >>>>>>>> or QStandardItemModel. >>>>>>>> Here is an example how: >>>>>>>> # Define roles >>>>>>>> FINISHED_ROLE = QtCore.Qt.UserRole + 1 >>>>>>>> PRIORITY_ROLE = QtCore.Qt.UserRole + 2 >>>>>>>> # Create model >>>>>>>> model = QtGui.QStandardItemModel() >>>>>>>> item = QtGui.QStandarItem() >>>>>>>> model.appendRow(item) >>>>>>>> item_index = item.index() >>>>>>>> # Store data using the item >>>>>>>> item.setData(finished, FINISHED_ROLE) >>>>>>>> item.setData(priority, PRIORITY_ROLE) >>>>>>>> # Store data using the model >>>>>>>> model.setData(item_index, finished, FINISHED_ROLE) >>>>>>>> model.setData(item_index, priority, PRIORITY_ROLE) >>>>>>>> # Retrieve data using the item >>>>>>>> finished = item.data(FINISHED_ROLE) >>>>>>>> priority = item.data(PRIORITY_ROLE) >>>>>>>> # Retrieve data using the model >>>>>>>> finished = model.data(item_index, FINISHED_ROLE) >>>>>>>> priority = model.data(item_index, PRIORITY_ROLE) >>>>>>>> In some cases like click event handlers, you have the >>>>>>>> model and the item index, there it's easier to use the >>>>>>>> model methods instead of finding the item and then >>>>>>>> getting the data. ? >>>>>>>> Hope it helps. >>>>>>>> Cheers, >>>>>>>> Tibold >>>>>>>> *From:* Frank Rueter | OHUfx >>>>>>>> *Sent:* ?2013? ?October? ?10?, ?Thursday ?19?:?37 >>>>>>>> *To:* pyside at qt-project.org >>>>>>>> After looking at some more examples I think my approach >>>>>>>> of storing multiple values in one item is fundamentally >>>>>>>> flawed. >>>>>>>> Instead I should be using one item per cell and assign >>>>>>>> the respective data, right?! >>>>>>>> >>>>>>>> I shall re-write the example accordingly, sorry for the >>>>>>>> noise. >>>>>>>> >>>>>>>> frank >>>>>>>> >>>>>>>> On 10/10/13 6:34 PM, Frank Rueter | OHUfx wrote: >>>>>>>> >>>>>>>> I meant QTableView not QStandardTableView :/ >>>>>>>> >>>>>>>> On 10/10/13 6:33 PM, Frank Rueter | OHUfx wrote: >>>>>>>> >>>>>>>> Hi all, >>>>>>>> >>>>>>>> after a bit of a break from PySide I am trying >>>>>>>> to wrap my head around the model/view stuff >>>>>>>> again and am trying to understand how a very >>>>>>>> simple example would work where a QStandarItem >>>>>>>> has properties "title", "priority" and >>>>>>>> "finished" which are displayed via a >>>>>>>> QStandardTableView. >>>>>>>> >>>>>>>> I am struggling with understanding how to >>>>>>>> properly display the above three properties in >>>>>>>> the table's columns. I tried setting the data() >>>>>>>> method on the model like this: >>>>>>>> >>>>>>>> / def data(self, index, >>>>>>>> role=QtCore.Qt.DisplayRole):// >>>>>>>> // '''Return data based on index and >>>>>>>> role'''// >>>>>>>> // item = self.itemFromIndex(index)// >>>>>>>> // if index.column() == 0:// >>>>>>>> // return item.title// >>>>>>>> // elif index.column() == 1:// >>>>>>>> // return item.finished// >>>>>>>> // elif index.column() == 2:// >>>>>>>> // return item.priority/ >>>>>>>> >>>>>>>> but for some reason it errors saying item does >>>>>>>> not have attribute "finished" even though my >>>>>>>> item object s declared like this: >>>>>>>> >>>>>>>> /class TaskItem(QtGui.QStandardItem):// >>>>>>>> // '''Item to hold a task for the todo list'''// >>>>>>>> //// >>>>>>>> // def __init__(self, title, finished=False, >>>>>>>> priority=1):// >>>>>>>> // super(TaskItem, self).__init__(title)// >>>>>>>> // self.title = title// >>>>>>>> // self.finished = finished// >>>>>>>> // self.priority = priority/ >>>>>>>> >>>>>>>> >>>>>>>> When printing the item's attributes via dir() I >>>>>>>> see that, when the model is populated, the last >>>>>>>> item it attempts to call is not my custom item >>>>>>>> object, but something else with less attributes >>>>>>>> and methods. Clearly there is something I >>>>>>>> haven't quite understood about this process. >>>>>>>> >>>>>>>> Also, if I use the models data() method as >>>>>>>> pointed out above, I get checkboxes in the >>>>>>>> cells which I don't want at this stage. >>>>>>>> >>>>>>>> Can somebody please help me understand where I >>>>>>>> go wrong? >>>>>>>> Attached is the whole test code. >>>>>>>> >>>>>>>> Cheers, >>>>>>>> frank >>>>>>>> >>>>>>>> P.S.: I am aware that the controller code >>>>>>>> shouldn't necessarily live in the QWidget's >>>>>>>> methods, this is just for testing which I will >>>>>>>> clean up once I get how it all connects again >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> PySide mailing list >>>>>>>> PySide at qt-project.org >>>>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> PySide mailing list >>>>>>>> PySide at qt-project.org >>>>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> PySide mailing list >>>>>>>> PySide at qt-project.org >>>>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>>>> >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> PySide mailing list >>>>>>> PySide at qt-project.org >>>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> PySide mailing list >>>>>> PySide at qt-project.org >>>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> PySide mailing list >>>>> PySide at qt-project.org >>>>> http://lists.qt-project.org/mailman/listinfo/pyside >>>> >>>> >>>> >>>> _______________________________________________ >>>> PySide mailing list >>>> PySide at qt-project.org >>>> http://lists.qt-project.org/mailman/listinfo/pyside >>> >>> >>> >>> _______________________________________________ >>> PySide mailing list >>> PySide at qt-project.org >>> http://lists.qt-project.org/mailman/listinfo/pyside >> >> >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From tismer at stackless.com Sun Oct 20 06:07:22 2013 From: tismer at stackless.com (Christian Tismer) Date: Sun, 20 Oct 2013 06:07:22 +0200 Subject: [PySide] [Stackless] PySide problem, take #2: typeobject clash In-Reply-To: References: <50C3B4D8.3020103@stackless.com> Message-ID: <526356FA.1050108@stackless.com> Howdy, friends!, today, I solved it! Made a Stackless Python 2.7.5 that works with PySide. (or maybe vice-versa?) Yappa-Dappa-Duu !! The patch is not that large, but it was a bit involved, to say the least ;-) Hey, life is great, and Stackless is my future, forever! All the best -- Chris -------------------------------------------------------------------- The current version is online at https://bitbucket.org/pydica/pyside-setup/ (official) and will be submitted as a pull request on github, tomorrow. (p.s.: I'm trying to keep this patch as small as possible, but still it involves quite a lot of PySide, going criss-cross over the sub-modules. I have to say that this is a design flaw and not my initial fault. PySide should not poke into internal data structures which are undocumented. I will re-work this ASAP. But for now, I'M INCREDIBLY HAPPY (sorry for screaming) ) cheerioh -- chris (live long and prosper with Stackless PySide) p.p.s.: I can understand if this patch will not be accepted for PySide mainstream, since it is very directly targeted. On the other hand, it is a step towards removal of certain structures that we should abandon. However you decide, I can live with it (and am used to it, you know ;-) ) p.p.p.s.: It is still a bit crazy to know that the compatibility patch for PyQT is just 4 lines -- as it should be ... On 10.12.12 12:39, Kristján Valur Jónsson wrote: > Yes. > But, stackless tries to detect if a type has the proper stackless extensions, by a flag in the type's 'flag' entry: > Py_TPFLAGS_HAVE_STACKLESS_EXTENSION > Therefore, there shouldn't be confusion: > > 1) if Stackless sees a type defined by Shiboken, even with the shiboken extension, it shouldn't have this flag, and stackless should ignore it. > 2) If Shiboken sees a type object from stackless, it won't do anything with it because it only adds the sbk extensions to its own types. > The issue is, imho, likely to be a problem with 1), a yet unidentified case in stackless where we assume all internal types to have the extension, i.e. fail to check for the presence of the flag. > > K > >> -----Original Message----- >> From: Christian Tismer [mailto:tismer at stackless.com] >> Sent: 8. desember 2012 21:45 >> To: stackless at stackless.com; Kristján Valur Jónsson; Richard Tew; lars van >> Gemerden >> Subject: PySide problem, take #2: typeobject clash >> >> Hi again, >> >> after some more investigation, I think I found it. >> See thread [PySide violates Python API - PyQt does not!] The first message >> was not correct, but the second one very likely is. >> >> As said there, the PyHeapTypeObject is extended like so: >> >>> /// PyTypeObject extended with C++ multiple inheritance information. >>> struct LIBSHIBOKEN_API SbkObjectType >>> { >>> PyHeapTypeObject super; >>> SbkObjectTypePrivate* d; >>> }; >> This additional pointer gets aliased to the first 4 bytes (win 32 bit) of >> >> typedef struct _slp_methodflags { >> signed char tp_itemsize; >> signed char tp_weaklistoffset; >> signed char tp_dictoffset; >> signed char nb_add; >> signed char nb_subtract; >> signed char nb_multiply; >> signed char nb_divide; >> signed char nb_remainder; >> ... >> >> >> The first three seem irrelevant. But the nb_add might influence the way how >> __add__ is interpreted. Due to the pointer value, stackless tries to call >> __add__ using the soft-switching protocol, which then fails miserably. >> >> The macro that tries this is: >> >> #define STACKLESS_PROMOTE_METHOD(obj, meth) \ >> (obj->ob_type->tp_flags & Py_TPFLAGS_HAVE_STACKLESS_EXTENSION ? >> \ >> slp_try_stackless = stackless & obj->ob_type->slpflags.meth : 0) >> >> and it is used by >> >> #define STACKLESS_PROPOSE_METHOD(obj, meth) \ >> { \ >> int stackless = STACKLESS_POSSIBLE(); \ >> STACKLESS_PROMOTE_METHOD(obj, meth); \ >> } >> >> Unfortunately, I could not find out if there is a way for Stackless to fall into >> this trap. But a good thing would be a little test: >> >> Lars, Richard: >> Can you please try your crashing examples, by putting >>> import stackless >>> stackless.enable_softswitch(False) >> right after the program start? >> >> That makes sure that stackless support of the interpreter is completely >> disabled, so the misinterpreted frags are of no influence. >> >> If that leads to significantly less crashes, then there is a quick fix for PySide: >> Insert a dummy void* into object.h before slpflags: >> >>> PyObject *ht_name, *ht_slots; >>> slp_methodflags slpflags; >>> #endif >>> } PyTypeObject; >> Hope this helps, but I'm not confident -- Chris >> >> -- >> Christian Tismer :^) >> Software Consulting : Have a break! Take a ride on Python's >> Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ >> 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de >> phone +49 173 24 18 776 fax +49 (30) 700143-0023 >> PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 >> whom do you want to sponsor today? http://www.stackless.com/ >> > > > _______________________________________________ > Stackless mailing list > Stackless at stackless.com > http://www.stackless.com/mailman/listinfo/stackless -- Christian Tismer :^) Software Consulting : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de phone +49 173 24 18 776 fax +49 (30) 700143-0023 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From tismer at stackless.com Sun Oct 20 06:52:16 2013 From: tismer at stackless.com (Christian Tismer) Date: Sun, 20 Oct 2013 06:52:16 +0200 Subject: [PySide] [Stackless] PySide problem, take #2: typeobject clash In-Reply-To: <526356FA.1050108@stackless.com> References: <50C3B4D8.3020103@stackless.com> <526356FA.1050108@stackless.com> Message-ID: <52636180.8070800@stackless.com> On 20.10.13 06:07, Christian Tismer wrote: > Howdy, friends!, > > today, I solved it! > Made a Stackless Python 2.7.5 that works with PySide. > (or maybe vice-versa?) > > Yappa-Dappa-Duu !! > > The patch is not that large, but it was a bit involved, to say the least ;-) > > Hey, life is great, and Stackless is my future, forever! > > All the best -- Chris > > -------------------------------------------------------------------- > The current version is online at > > https://bitbucket.org/pydica/pyside-setup/ (official) Actually, pyside-setup is not involved here at all. It is shiboken: > https://bitbucket.org/pydica/shiboken and pyside: > https://bitbucket.org/pydica/pyside Will be cloned as a pull request on github, tomorrow. cheers -- Chris -- Christian Tismer :^) Software Consulting : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de phone +49 173 24 18 776 fax +49 (30) 700143-0023 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From frank at ohufx.com Sun Oct 20 07:37:25 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Sun, 20 Oct 2013 18:37:25 +1300 Subject: [PySide] combining two default widgets Message-ID: <52636C15.8060107@ohufx.com> Hi all, I have written a custom comboBox which renders like a progress bar. Depending on which item is chosen, the progress bar is updated accordingly: http://pastebin.com/yWACCHH0) Initially I thought I'd be cheeky and try to inherit both QComboBox and QProgessBar (in that order) to see if this is the easiest way to do this, but the app crashed as soon as I used self.setItems() in the constructor. I don't have a lot of experience with inheriting more than one object, so thought I'd ask you guys for general guide lines (if there are any). I'd imagine it's only safe to do if you know that none of the respective attributes cause conflicts?! Also, is the above code an ok way of doing this? I would just like to know if this is how the pros would do it and avoid bad habits. Cheers, frank From sebastian at risefx.com Sun Oct 20 11:10:55 2013 From: sebastian at risefx.com (Sebastian Elsner) Date: Sun, 20 Oct 2013 11:10:55 +0200 Subject: [PySide] combining two default widgets In-Reply-To: <52636C15.8060107@ohufx.com> References: <52636C15.8060107@ohufx.com> Message-ID: <52639E1F.6050307@risefx.com> Hi, I have never tried multiple inheritance in Qt and I have never seen it anywhere in the docs or online, so I guess its not a good option. Also how should the system know what to paint where and how. I have created an example on how I would approach this. It uses standard Qt paint controls and also stays in-style on different platforms: http://pastebin.com/vbk9y2JZ Cheers Sebastian Am 20.10.2013 07:37, schrieb Frank Rueter | OHUfx: > Hi all, > > I have written a custom comboBox which renders like a progress bar. > Depending on which item is chosen, the progress bar is updated accordingly: > http://pastebin.com/yWACCHH0) > > Initially I thought I'd be cheeky and try to inherit both QComboBox and > QProgessBar (in that order) to see if this is the easiest way to do > this, but the app crashed as soon as I used self.setItems() in the > constructor. > > I don't have a lot of experience with inheriting more than one object, > so thought I'd ask you guys for general guide lines (if there are any). > I'd imagine it's only safe to do if you know that none of the respective > attributes cause conflicts?! > > > Also, is the above code an ok way of doing this? I would just like to > know if this is how the pros would do it and avoid bad habits. > > Cheers, > frank > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside From a.richi at bluewin.ch Sun Oct 20 11:13:42 2013 From: a.richi at bluewin.ch (Aaron Richiger) Date: Sun, 20 Oct 2013 11:13:42 +0200 Subject: [PySide] combining two default widgets In-Reply-To: <52636C15.8060107@ohufx.com> References: <52636C15.8060107@ohufx.com> Message-ID: <52639EC6.5070603@bluewin.ch> Hello Frank! Tried your code and it works fine (BTW: if you want to check us some code, it would be nice if the code is executable and shows a working example of your widget, otherwise all of us first have to write some lines of code to show your widget and chances are smaller that anybody tries it at all...). There are no general guidelines about multiple inheritance, it's an endless discussion whether it's a good or a bad thing... I can just give you my guidelines, others will contradict:-) - in your case, it's definitively the wrong choice (see below) - use it wisely and rarely (I've only used it in two cases in my entire Python life...) - learn about the internals (e.g. how conflicting function names are resolved, etc.) Reason, why it's definitively not a good idea here: You wanted a mix of both looks and feels. The visual appearance should be somewhere between a combobox and a progress bar. So you want e.g. the paintEvent() of both classes to be executed. But since QComboBox is first in the inheritance order, only QComboBox.paintEvent() would be executed, your widget would never look like a progress bar. And this is just one example of conflicting methods. Implementing your own widget starting from QComboBox or from QProgressBar as you did now is the way I would choose. Cheers! Aaron Am 20.10.2013 07:37, schrieb Frank Rueter | OHUfx: > Hi all, > > I have written a custom comboBox which renders like a progress bar. > Depending on which item is chosen, the progress bar is updated accordingly: > http://pastebin.com/yWACCHH0) > > Initially I thought I'd be cheeky and try to inherit both QComboBox and > QProgessBar (in that order) to see if this is the easiest way to do > this, but the app crashed as soon as I used self.setItems() in the > constructor. > > I don't have a lot of experience with inheriting more than one object, > so thought I'd ask you guys for general guide lines (if there are any). > I'd imagine it's only safe to do if you know that none of the respective > attributes cause conflicts?! > > > Also, is the above code an ok way of doing this? I would just like to > know if this is how the pros would do it and avoid bad habits. > > Cheers, > frank > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside From frank at ohufx.com Sun Oct 20 21:27:59 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Mon, 21 Oct 2013 08:27:59 +1300 Subject: [PySide] combining two default widgets In-Reply-To: <52639E1F.6050307@risefx.com> References: <52636C15.8060107@ohufx.com> <52639E1F.6050307@risefx.com> Message-ID: <52642EBF.3010806@ohufx.com> Cool, thanks Sebastian! I had a hunch there would be something like a QStyleOptionProgressBar just had no idea where to find it. On 20/10/13 22:10, Sebastian Elsner wrote: > Hi, > > I have never tried multiple inheritance in Qt and I have never seen it > anywhere in the docs or online, so I guess its not a good option. Also > how should the system know what to paint where and how. I have created > an example on how I would approach this. It uses standard Qt paint > controls and also stays in-style on different platforms: > http://pastebin.com/vbk9y2JZ > > Cheers > > Sebastian > > > Am 20.10.2013 07:37, schrieb Frank Rueter | OHUfx: >> Hi all, >> >> I have written a custom comboBox which renders like a progress bar. >> Depending on which item is chosen, the progress bar is updated accordingly: >> http://pastebin.com/yWACCHH0) >> >> Initially I thought I'd be cheeky and try to inherit both QComboBox and >> QProgessBar (in that order) to see if this is the easiest way to do >> this, but the app crashed as soon as I used self.setItems() in the >> constructor. >> >> I don't have a lot of experience with inheriting more than one object, >> so thought I'd ask you guys for general guide lines (if there are any). >> I'd imagine it's only safe to do if you know that none of the respective >> attributes cause conflicts?! >> >> >> Also, is the above code an ok way of doing this? I would just like to >> know if this is how the pros would do it and avoid bad habits. >> >> Cheers, >> frank >> >> _______________________________________________ >> PySide mailing list >> PySide at qt-project.org >> http://lists.qt-project.org/mailman/listinfo/pyside > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside From jpe at wingware.com Mon Oct 21 17:54:58 2013 From: jpe at wingware.com (John Ehresman) Date: Mon, 21 Oct 2013 11:54:58 -0400 Subject: [PySide] [Stackless] PySide problem, take #2: typeobject clash In-Reply-To: <526356FA.1050108@stackless.com> References: <50C3B4D8.3020103@stackless.com> <526356FA.1050108@stackless.com> Message-ID: <52654E52.8030507@wingware.com> I took a look at the patch and can't quite understand it (I must admit I didn't apply it). Can someone explain why it's needed? Thanks, John On 10/20/13 12:07 AM, Christian Tismer wrote: > Howdy, friends!, > > today, I solved it! > Made a Stackless Python 2.7.5 that works with PySide. > (or maybe vice-versa?) > > Yappa-Dappa-Duu !! > > The patch is not that large, but it was a bit involved, to say the least > ;-) > > Hey, life is great, and Stackless is my future, forever! > > All the best -- Chris > > -------------------------------------------------------------------- > The current version is online at > > https://bitbucket.org/pydica/pyside-setup/ (official) > > and will be submitted as a pull request on github, tomorrow. > > > (p.s.: I'm trying to keep this patch as small as possible, but still it > involves > quite a lot of PySide, going criss-cross over the sub-modules. > I have to say that this is a design flaw and not my initial fault. > PySide should not > poke into internal data structures which are undocumented. > I will re-work this ASAP. > But for now, I'M INCREDIBLY HAPPY (sorry for screaming) > ) > > cheerioh -- chris (live long and prosper with Stackless PySide) > > > p.p.s.: I can understand if this patch will not be accepted for PySide > mainstream, > since it is very directly targeted. On the other hand, it is a step > towards removal > of certain structures that we should abandon. > However you decide, I can live with it (and am used to it, you know ;-) ) > > p.p.p.s.: It is still a bit crazy to know that the compatibility patch for > PyQT is just 4 lines -- as it should be ... > > On 10.12.12 12:39, Kristján Valur Jónsson wrote: >> Yes. >> But, stackless tries to detect if a type has the proper stackless >> extensions, by a flag in the type's 'flag' entry: >> Py_TPFLAGS_HAVE_STACKLESS_EXTENSION >> Therefore, there shouldn't be confusion: >> >> 1) if Stackless sees a type defined by Shiboken, even with the >> shiboken extension, it shouldn't have this flag, and stackless should >> ignore it. >> 2) If Shiboken sees a type object from stackless, it won't do anything >> with it because it only adds the sbk extensions to its own types. >> The issue is, imho, likely to be a problem with 1), a yet unidentified >> case in stackless where we assume all internal types to have the >> extension, i.e. fail to check for the presence of the flag. >> >> K >> >>> -----Original Message----- >>> From: Christian Tismer [mailto:tismer at stackless.com] >>> Sent: 8. desember 2012 21:45 >>> To: stackless at stackless.com; Kristján Valur Jónsson; Richard Tew; >>> lars van >>> Gemerden >>> Subject: PySide problem, take #2: typeobject clash >>> >>> Hi again, >>> >>> after some more investigation, I think I found it. >>> See thread [PySide violates Python API - PyQt does not!] The first >>> message >>> was not correct, but the second one very likely is. >>> >>> As said there, the PyHeapTypeObject is extended like so: >>> >>>> /// PyTypeObject extended with C++ multiple inheritance information. >>>> struct LIBSHIBOKEN_API SbkObjectType >>>> { >>>> PyHeapTypeObject super; >>>> SbkObjectTypePrivate* d; >>>> }; >>> This additional pointer gets aliased to the first 4 bytes (win 32 >>> bit) of >>> >>> typedef struct _slp_methodflags { >>> signed char tp_itemsize; >>> signed char tp_weaklistoffset; >>> signed char tp_dictoffset; >>> signed char nb_add; >>> signed char nb_subtract; >>> signed char nb_multiply; >>> signed char nb_divide; >>> signed char nb_remainder; >>> ... >>> >>> >>> The first three seem irrelevant. But the nb_add might influence the >>> way how >>> __add__ is interpreted. Due to the pointer value, stackless tries to >>> call >>> __add__ using the soft-switching protocol, which then fails miserably. >>> >>> The macro that tries this is: >>> >>> #define STACKLESS_PROMOTE_METHOD(obj, meth) \ >>> (obj->ob_type->tp_flags & Py_TPFLAGS_HAVE_STACKLESS_EXTENSION ? >>> \ >>> slp_try_stackless = stackless & obj->ob_type->slpflags.meth : 0) >>> >>> and it is used by >>> >>> #define STACKLESS_PROPOSE_METHOD(obj, meth) \ >>> { \ >>> int stackless = STACKLESS_POSSIBLE(); \ >>> STACKLESS_PROMOTE_METHOD(obj, meth); \ >>> } >>> >>> Unfortunately, I could not find out if there is a way for Stackless >>> to fall into >>> this trap. But a good thing would be a little test: >>> >>> Lars, Richard: >>> Can you please try your crashing examples, by putting >>>> import stackless >>>> stackless.enable_softswitch(False) >>> right after the program start? >>> >>> That makes sure that stackless support of the interpreter is completely >>> disabled, so the misinterpreted frags are of no influence. >>> >>> If that leads to significantly less crashes, then there is a quick >>> fix for PySide: >>> Insert a dummy void* into object.h before slpflags: >>> >>>> PyObject *ht_name, *ht_slots; >>>> slp_methodflags slpflags; >>>> #endif >>>> } PyTypeObject; >>> Hope this helps, but I'm not confident -- Chris >>> >>> -- >>> Christian Tismer :^) >>> Software Consulting : Have a break! Take a ride on Python's >>> Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ >>> 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de >>> phone +49 173 24 18 776 fax +49 (30) 700143-0023 >>> PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 >>> whom do you want to sponsor today? http://www.stackless.com/ >>> >> >> >> _______________________________________________ >> Stackless mailing list >> Stackless at stackless.com >> http://www.stackless.com/mailman/listinfo/stackless > > From tismer at stackless.com Mon Oct 21 18:44:11 2013 From: tismer at stackless.com (Christian Tismer) Date: Mon, 21 Oct 2013 18:44:11 +0200 Subject: [PySide] [Stackless] PySide problem, take #2: typeobject clash In-Reply-To: <52654E52.8030507@wingware.com> References: <50C3B4D8.3020103@stackless.com> <526356FA.1050108@stackless.com> <52654E52.8030507@wingware.com> Message-ID: <526559DB.7080403@stackless.com> On 21.10.13 17:54, John Ehresman wrote: > I took a look at the patch and can't quite understand it (I must admit > I didn't apply it). Can someone explain why it's needed? It is all about stackless' different frame layout. This is the minimal patch to be able to compile pyside for stackless python. It is explained in the bug report. https://bugreports.qt-project.org/browse/PYSIDE-199 ciao - chris -- Christian Tismer :^) Software Consulting : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de phone +49 173 24 18 776 fax +49 (30) 700143-0023 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From tismer at stackless.com Mon Oct 21 18:57:37 2013 From: tismer at stackless.com (Christian Tismer) Date: Mon, 21 Oct 2013 18:57:37 +0200 Subject: [PySide] [Stackless] PySide problem, take #2: typeobject clash In-Reply-To: <526559DB.7080403@stackless.com> References: <50C3B4D8.3020103@stackless.com> <526356FA.1050108@stackless.com> <52654E52.8030507@wingware.com> <526559DB.7080403@stackless.com> Message-ID: <52655D01.9070202@stackless.com> On 21.10.13 18:44, Christian Tismer wrote: > On 21.10.13 17:54, John Ehresman wrote: >> I took a look at the patch and can't quite understand it (I must >> admit I didn't apply it). Can someone explain why it's needed? > > It is all about stackless' different frame layout. > This is the minimal patch to be able to compile pyside for stackless > python. > It is explained in the bug report. > > https://bugreports.qt-project.org/browse/PYSIDE-199 > Just to explain it better: There is _no_ change of PySide at all, not the least. This is all about syntactic sugar to make PySide compile with Stackless. The binaries compiled for normal Python will stay identical, so there is nothing to expect. It is an important no-op ;-) ciao - chris -- Christian Tismer :^) Software Consulting : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de phone +49 173 24 18 776 fax +49 (30) 700143-0023 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From jpe at wingware.com Mon Oct 21 18:57:59 2013 From: jpe at wingware.com (John Ehresman) Date: Mon, 21 Oct 2013 12:57:59 -0400 Subject: [PySide] [Stackless] PySide problem, take #2: typeobject clash In-Reply-To: <526559DB.7080403@stackless.com> References: <50C3B4D8.3020103@stackless.com> <526356FA.1050108@stackless.com> <52654E52.8030507@wingware.com> <526559DB.7080403@stackless.com> Message-ID: <52655D17.8040005@wingware.com> On 10/21/13 12:44 PM, Christian Tismer wrote: > On 21.10.13 17:54, John Ehresman wrote: >> I took a look at the patch and can't quite understand it (I must admit >> I didn't apply it). Can someone explain why it's needed? > > It is all about stackless' different frame layout. > This is the minimal patch to be able to compile pyside for stackless > python. > It is explained in the bug report. > > https://bugreports.qt-project.org/browse/PYSIDE-199 I think I'm confused -- I see changes to how SbkTypeObject fields are referenced (SbkTypeObject is a C level extension of the PyHeapTypeObject struct). I don't think I see changes to frames. Cheers, John From tismer at stackless.com Mon Oct 21 19:07:21 2013 From: tismer at stackless.com (Christian Tismer) Date: Mon, 21 Oct 2013 19:07:21 +0200 Subject: [PySide] [Stackless] PySide problem, take #2: typeobject clash In-Reply-To: <52655D17.8040005@wingware.com> References: <50C3B4D8.3020103@stackless.com> <526356FA.1050108@stackless.com> <52654E52.8030507@wingware.com> <526559DB.7080403@stackless.com> <52655D17.8040005@wingware.com> Message-ID: <52655F49.7040502@stackless.com> On 21.10.13 18:57, John Ehresman wrote: > On 10/21/13 12:44 PM, Christian Tismer wrote: >> On 21.10.13 17:54, John Ehresman wrote: >>> I took a look at the patch and can't quite understand it (I must admit >>> I didn't apply it). Can someone explain why it's needed? >> >> It is all about stackless' different frame layout. >> This is the minimal patch to be able to compile pyside for stackless >> python. >> It is explained in the bug report. >> >> https://bugreports.qt-project.org/browse/PYSIDE-199 > > I think I'm confused -- I see changes to how SbkTypeObject fields are > referenced (SbkTypeObject is a C level extension of the > PyHeapTypeObject struct). I don't think I see changes to frames. Hoppla, you are right, no frames at all. Did I say that? geee No, it is about the type layout, there are (ah, here came the word frame again?! ) there are type fields in CPython that stackless does not have. Well, and because these structures are different in size, pyside must be compiled using stackless, otherwise it crashes ugly. (bzzt, no frames -- what's up with my brain? like a shortcut, I need rewiring) ciao - chris -- Christian Tismer :^) Software Consulting : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de phone +49 173 24 18 776 fax +49 (30) 700143-0023 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From matthew.woehlke at kitware.com Mon Oct 21 21:28:13 2013 From: matthew.woehlke at kitware.com (Matthew Woehlke) Date: Mon, 21 Oct 2013 15:28:13 -0400 Subject: [PySide] combining two default widgets In-Reply-To: <52636C15.8060107@ohufx.com> References: <52636C15.8060107@ohufx.com> Message-ID: On 2013-10-20 01:37, Frank Rueter | OHUfx wrote: > I have written a custom comboBox which renders like a progress bar. > Depending on which item is chosen, the progress bar is updated accordingly: > http://pastebin.com/yWACCHH0) > > Initially I thought I'd be cheeky and try to inherit both QComboBox and > QProgessBar (in that order) to see if this is the easiest way to do > this, but the app crashed as soon as I used self.setItems() in the > constructor. In C++, inheriting from QObject more than once is explicitly forbidden. While it *might* be possible to make this work in PySide, I wouldn't count on it, nor would I particularly recommend it. What is the purpose of inheriting from both? You may be better off having one as an internal object of the other, similar to how there is an internal QLineEdit of QComboBox. -- Matthew From jpe at wingware.com Mon Oct 21 22:10:08 2013 From: jpe at wingware.com (John Ehresman) Date: Mon, 21 Oct 2013 16:10:08 -0400 Subject: [PySide] [Stackless] PySide problem, take #2: typeobject clash In-Reply-To: <52655F49.7040502@stackless.com> References: <50C3B4D8.3020103@stackless.com> <526356FA.1050108@stackless.com> <52654E52.8030507@wingware.com> <526559DB.7080403@stackless.com> <52655D17.8040005@wingware.com> <52655F49.7040502@stackless.com> Message-ID: <52658A20.1040403@wingware.com> On 10/21/13 1:07 PM, Christian Tismer wrote: > No, it is about the type layout, there are (ah, here came the word frame > again?! ) there are type fields in CPython that stackless does not have. > > Well, and because these structures are different in size, pyside must > be compiled using stackless, otherwise it crashes ugly. I think I see the problem; to me, at least, it's useful to see the stackless version of object.h at http://www.stackless.com/browser/Include/object.h It looks like stackless moves the fields defined in PyHeapTypeObject into PyTypeObject, adds at least one additional field, and then #define's PyHeapTypeObject to PyTypeObject. This leads to two problems, which are somewhat separable -- 1) When compiling, there is no ht_type field in PyHeapTypeObject. This is what Christian's patch addresses. 2) At runtime, both pyside and stackless assume they can store additional type data in the same place after the PyTypeObject data. pyside stores a pointer to a separate structure here. I think it might be worth trying to fix #2 as well as #1 so there's no need for separate pyside builds for stackless. It may be possible to allocate these type objects on the heap so the length of the base object can be determined at runtime. I haven't thought this all the way through, but think it might work, though it might or might not require an ABI break. As for the current patch, I think it needs motivating comments to at least point developers who aren't familiar with the stackless changes to PyTypeObject in the right direction. Cheers, John From tismer at stackless.com Mon Oct 21 22:33:37 2013 From: tismer at stackless.com (Christian Tismer) Date: Mon, 21 Oct 2013 22:33:37 +0200 Subject: [PySide] [Stackless] PySide problem, take #2: typeobject clash In-Reply-To: <52658A20.1040403@wingware.com> References: <50C3B4D8.3020103@stackless.com> <526356FA.1050108@stackless.com> <52654E52.8030507@wingware.com> <526559DB.7080403@stackless.com> <52655D17.8040005@wingware.com> <52655F49.7040502@stackless.com> <52658A20.1040403@wingware.com> Message-ID: <52658FA1.7050908@stackless.com> On 21.10.13 22:10, John Ehresman wrote: > On 10/21/13 1:07 PM, Christian Tismer wrote: >> No, it is about the type layout, there are (ah, here came the word frame >> again?! ) there are type fields in CPython that stackless does not have. >> >> Well, and because these structures are different in size, pyside must >> be compiled using stackless, otherwise it crashes ugly. > > I think I see the problem; to me, at least, it's useful to see the > stackless version of object.h at > http://www.stackless.com/browser/Include/object.h It looks like > stackless moves the fields defined in PyHeapTypeObject into > PyTypeObject, adds at least one additional field, and then #define's > PyHeapTypeObject to PyTypeObject. This leads to two problems, which > are somewhat separable -- > > 1) When compiling, there is no ht_type field in PyHeapTypeObject. This > is what Christian's patch addresses. > > 2) At runtime, both pyside and stackless assume they can store > additional type data in the same place after the PyTypeObject data. > pyside stores a pointer to a separate structure here. > > I think it might be worth trying to fix #2 as well as #1 so there's no > need for separate pyside builds for stackless. It may be possible to > allocate these type objects on the heap so the length of the base > object can be determined at runtime. I haven't thought this all the > way through, but think it might work, though it might or might not > require an ABI break. > > As for the current patch, I think it needs motivating comments to at > least point developers who aren't familiar with the stackless changes > to PyTypeObject in the right direction. Yes I agree very much. For me, the main concern was that there is something weird going on that prevends PySide from working with stackless. #1 was the way to convince myself that there is no principal problem with Stackless. Of course it would be much nicer to solve it completely so that the extra compilation goes away. Interestingly, PyQT has that solution since years, and the patch for stackless is a single #ifdef around the type declaration. The problem with PySide is that it directly pokes into types that it should not touch at all. Anyway, I'm happy that I can use both projects together. Maybe the effort to get that into the official release is not worth it before solving #2. cheers - chris -- Christian Tismer :^) Software Consulting : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de phone +49 173 24 18 776 fax +49 (30) 700143-0023 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From frank at ohufx.com Tue Oct 22 03:01:15 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Tue, 22 Oct 2013 14:01:15 +1300 Subject: [PySide] combining two default widgets In-Reply-To: References: <52636C15.8060107@ohufx.com> Message-ID: <5265CE5B.5040202@ohufx.com> yes, that's indeed more sensible. I am just inheriting from QComboBox now and drawing a simple progress bar myself. Cheers, frank On 22/10/13 08:28, Matthew Woehlke wrote: > On 2013-10-20 01:37, Frank Rueter | OHUfx wrote: >> I have written a custom comboBox which renders like a progress bar. >> Depending on which item is chosen, the progress bar is updated accordingly: >> http://pastebin.com/yWACCHH0) >> >> Initially I thought I'd be cheeky and try to inherit both QComboBox and >> QProgessBar (in that order) to see if this is the easiest way to do >> this, but the app crashed as soon as I used self.setItems() in the >> constructor. > In C++, inheriting from QObject more than once is explicitly forbidden. > While it *might* be possible to make this work in PySide, I wouldn't > count on it, nor would I particularly recommend it. > > What is the purpose of inheriting from both? You may be better off > having one as an internal object of the other, similar to how there is > an internal QLineEdit of QComboBox. > From frank at ohufx.com Tue Oct 22 07:29:54 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Tue, 22 Oct 2013 18:29:54 +1300 Subject: [PySide] fading a widget on and off Message-ID: <52660D52.80200@ohufx.com> Hi all, once again I'm looking for a nudge in the right direction please: I'd like to be able to fade a widget on and off (based on the state of a checkbox), and am wondering if I should write a custom paintEvent that renders the widget as a pixmap at the respective transparency or if I should look into QState and QStateMachine instead?! I have never used states but it sounds like that will enable me to subsequently use QtCore.QPropertyAnimation on a custom property (like opacity), is that correct? Or is there another way I should be exploring? Cheers, frank From jpe at wingware.com Tue Oct 22 16:24:56 2013 From: jpe at wingware.com (John Ehresman) Date: Tue, 22 Oct 2013 10:24:56 -0400 Subject: [PySide] [Stackless] PySide problem, take #2: typeobject clash In-Reply-To: <52658FA1.7050908@stackless.com> References: <50C3B4D8.3020103@stackless.com> <526356FA.1050108@stackless.com> <52654E52.8030507@wingware.com> <526559DB.7080403@stackless.com> <52655D17.8040005@wingware.com> <52655F49.7040502@stackless.com> <52658A20.1040403@wingware.com> <52658FA1.7050908@stackless.com> Message-ID: <52668AB8.30805@wingware.com> > On 21.10.13 22:10, John Ehresman wrote: >> >> I think I see the problem; to me, at least, it's useful to see the >> stackless version of object.h at >> http://www.stackless.com/browser/Include/object.h It looks like >> stackless moves the fields defined in PyHeapTypeObject into >> PyTypeObject, adds at least one additional field, and then #define's >> PyHeapTypeObject to PyTypeObject. This leads to two problems, which >> are somewhat separable -- >> >> 1) When compiling, there is no ht_type field in PyHeapTypeObject. This >> is what Christian's patch addresses. Wouldn't it be possible to use something like the following in shiboken's basewrapper.h (untested code below): /// PyTypeObject extended with C++ multiple inheritance information. #ifndef STACKLESS struct LIBSHIBOKEN_API SbkObjectType { PyHeapTypeObject super; SbkObjectTypePrivate* d; }; #else // STACKLESS // Work around stackless's modification of PyTypeObject and PyHeapTypeObject struct LIBSHIBOKEN_API SbkObjectType { struct { PyTypeObject ht_type; } super; SbkObjectTypePrivate* d; }; #endif This would have the advantage of not sprinkling macros across the code base. It does not address the binary compatibility problem. Cheers, John From tismer at stackless.com Tue Oct 22 18:27:00 2013 From: tismer at stackless.com (Christian Tismer) Date: Tue, 22 Oct 2013 18:27:00 +0200 Subject: [PySide] [Stackless] PySide problem, take #2: typeobject clash In-Reply-To: <52668AB8.30805@wingware.com> References: <50C3B4D8.3020103@stackless.com> <526356FA.1050108@stackless.com> <52654E52.8030507@wingware.com> <526559DB.7080403@stackless.com> <52655D17.8040005@wingware.com> <52655F49.7040502@stackless.com> <52658A20.1040403@wingware.com> <52658FA1.7050908@stackless.com> <52668AB8.30805@wingware.com> Message-ID: <5266A754.40901@stackless.com> On 22.10.13 16:24, John Ehresman wrote: >> On 21.10.13 22:10, John Ehresman wrote: >>> >>> I think I see the problem; to me, at least, it's useful to see the >>> stackless version of object.h at >>> http://www.stackless.com/browser/Include/object.h It looks like >>> stackless moves the fields defined in PyHeapTypeObject into >>> PyTypeObject, adds at least one additional field, and then #define's >>> PyHeapTypeObject to PyTypeObject. This leads to two problems, which >>> are somewhat separable -- >>> >>> 1) When compiling, there is no ht_type field in PyHeapTypeObject. This >>> is what Christian's patch addresses. > > Wouldn't it be possible to use something like the following in > shiboken's basewrapper.h (untested code below): > > /// PyTypeObject extended with C++ multiple inheritance information. > #ifndef STACKLESS > > struct LIBSHIBOKEN_API SbkObjectType > { > PyHeapTypeObject super; > SbkObjectTypePrivate* d; > }; > > #else // STACKLESS > > // Work around stackless's modification of PyTypeObject and > PyHeapTypeObject > struct LIBSHIBOKEN_API SbkObjectType > { > struct { > PyTypeObject ht_type; > } super; > SbkObjectTypePrivate* d; > }; > > #endif > > This would have the advantage of not sprinkling macros across the code > base. It does not address the binary compatibility problem. Hmm, good idea! That would really be a minimal patch with much less ugliness and clutter. Well, not sure yet if I want to try that really right now...maybe ciao - chris -- Christian Tismer :^) Software Consulting : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de phone +49 173 24 18 776 fax +49 (30) 700143-0023 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From matthew.woehlke at kitware.com Tue Oct 22 20:19:12 2013 From: matthew.woehlke at kitware.com (Matthew Woehlke) Date: Tue, 22 Oct 2013 14:19:12 -0400 Subject: [PySide] fading a widget on and off In-Reply-To: <52660D52.80200@ohufx.com> References: <52660D52.80200@ohufx.com> Message-ID: On 2013-10-22 01:29, Frank Rueter | OHUfx wrote: > once again I'm looking for a nudge in the right direction please: > > I'd like to be able to fade a widget on and off (based on the state of a > checkbox), and am wondering if I should write a custom paintEvent that > renders the widget as a pixmap at the respective transparency or if I > should look into QState and QStateMachine instead?! I have never used > states but it sounds like that will enable me to subsequently use > QtCore.QPropertyAnimation on a custom property (like opacity), is that > correct? So... I have a widget floating around that does something similar. However, the least broken way I was able to find to do this is to render the widget background, by telling the top level widget to render itself, clipped to the region of your widget, into a pixmap, then painting your widget as normal, and lastly overpainting the background pixmap at the desired opacity. If you render your own widget into a pixmap, IME it doesn't render the same as rendering on-screen (specifically I recall that text sub-pixel antialiasing isn't used). You can probably get away with doing the top level widget render only once, when you start the transition. That said, I wonder what setting CSS 'opacity' on a widget does... (not sure it is supported, however). You should be able to use QAnimation straight up to do the fade. I don't see how QStateMachine would be useful (other than as gratuitous overkill, maybe) here. -- Matthew From frank at ohufx.com Tue Oct 22 20:33:23 2013 From: frank at ohufx.com (Frank Rueter | OHUfx) Date: Wed, 23 Oct 2013 07:33:23 +1300 Subject: [PySide] fading a widget on and off In-Reply-To: References: <52660D52.80200@ohufx.com> Message-ID: <5266C4F3.9020307@ohufx.com> Ok, thanks Matt On 23/10/13 07:19, Matthew Woehlke wrote: > On 2013-10-22 01:29, Frank Rueter | OHUfx wrote: >> once again I'm looking for a nudge in the right direction please: >> >> I'd like to be able to fade a widget on and off (based on the state of a >> checkbox), and am wondering if I should write a custom paintEvent that >> renders the widget as a pixmap at the respective transparency or if I >> should look into QState and QStateMachine instead?! I have never used >> states but it sounds like that will enable me to subsequently use >> QtCore.QPropertyAnimation on a custom property (like opacity), is that >> correct? > So... I have a widget floating around that does something similar. > However, the least broken way I was able to find to do this is to render > the widget background, by telling the top level widget to render itself, > clipped to the region of your widget, into a pixmap, then painting your > widget as normal, and lastly overpainting the background pixmap at the > desired opacity. > > If you render your own widget into a pixmap, IME it doesn't render the > same as rendering on-screen (specifically I recall that text sub-pixel > antialiasing isn't used). > > You can probably get away with doing the top level widget render only > once, when you start the transition. > > That said, I wonder what setting CSS 'opacity' on a widget does... (not > sure it is supported, however). > > You should be able to use QAnimation straight up to do the fade. I don't > see how QStateMachine would be useful (other than as gratuitous > overkill, maybe) here. > From tismer at stackless.com Tue Oct 22 21:42:22 2013 From: tismer at stackless.com (Christian Tismer) Date: Tue, 22 Oct 2013 21:42:22 +0200 Subject: [PySide] [Stackless] PySide problem, take #2: typeobject clash In-Reply-To: <5266A754.40901@stackless.com> References: <50C3B4D8.3020103@stackless.com> <526356FA.1050108@stackless.com> <52654E52.8030507@wingware.com> <526559DB.7080403@stackless.com> <52655D17.8040005@wingware.com> <52655F49.7040502@stackless.com> <52658A20.1040403@wingware.com> <52658FA1.7050908@stackless.com> <52668AB8.30805@wingware.com> <5266A754.40901@stackless.com> Message-ID: <5266D51E.7040808@stackless.com> On 22.10.13 18:27, Christian Tismer wrote: > On 22.10.13 16:24, John Ehresman wrote: >>> On 21.10.13 22:10, John Ehresman wrote: >>>> >>>> I think I see the problem; to me, at least, it's useful to see the >>>> stackless version of object.h at >>>> http://www.stackless.com/browser/Include/object.h It looks like >>>> stackless moves the fields defined in PyHeapTypeObject into >>>> PyTypeObject, adds at least one additional field, and then #define's >>>> PyHeapTypeObject to PyTypeObject. This leads to two problems, which >>>> are somewhat separable -- >>>> >>>> 1) When compiling, there is no ht_type field in PyHeapTypeObject. This >>>> is what Christian's patch addresses. >> >> Wouldn't it be possible to use something like the following in >> shiboken's basewrapper.h (untested code below): >> >> /// PyTypeObject extended with C++ multiple inheritance information. >> #ifndef STACKLESS >> >> struct LIBSHIBOKEN_API SbkObjectType >> { >> PyHeapTypeObject super; >> SbkObjectTypePrivate* d; >> }; >> >> #else // STACKLESS >> >> // Work around stackless's modification of PyTypeObject and >> PyHeapTypeObject >> struct LIBSHIBOKEN_API SbkObjectType >> { >> struct { >> PyTypeObject ht_type; >> } super; >> SbkObjectTypePrivate* d; >> }; >> >> #endif >> >> This would have the advantage of not sprinkling macros across the >> code base. It does not address the binary compatibility problem. > > Hmm, good idea! > That would really be a minimal patch with much less ugliness and clutter. > Well, not sure yet if I want to try that really right now...maybe Tried this -- does not work. While a good idea, the introduced differences are too big to go away with this simple trick. The thing breaks in for instance > /Users/tismer/src/pyside-setup/pyside_build/py2.7-qt4.8.5-64bit-release/pyside/PySide/QtCore/PySide/QtCore/qbitarray_wrapper.cpp:1626:38: > error: no member named 'as_number' in 'SbkObjectType:: struct at > /Users/tismer/src/pyside-setup/pyside_install/py2.7-qt4.8.5-64bit-release/include/shiboken/basewrapper.h:99:5>' > memset(&Sbk_QBitArray_Type.super.as_number, 0, > sizeof(PyNumberMethods)); > ~~~~~~~~~~~~~~~~~~~~~~~~ ^ The problem is difficult because in stackless object.h we have at the end of typeobject: 415 #ifdef STACKLESS 416 /* we need the extended structure right here */ 417 PyNumberMethods as_number; 418 PyMappingMethods as_mapping; 419 PySequenceMethods as_sequence; /* as_sequence comes after as_mapping, 420 so that the mapping wins when both 421 the mapping and the sequence define 422 a given operator (e.g. __getitem__). 423 see add_operators() in typeobject.c . */ 424 PyBufferProcs as_buffer; 425 PyObject *ht_name, *ht_slots; 426 slp_methodflags slpflags; 427 #endif 428 } PyTypeObject; These fields are embedded into typeobject, without the ht_type around it. I tried the following: // Work around stackless's modification of PyTypeObject and PyHeapTypeObject struct LIBSHIBOKEN_API SbkObjectType { union { struct { PyTypeObject ht_type; } super; PyTypeObject super; }; SbkObjectTypePrivate* d; }; but that doesn't work, because "super" may not occur twice. A possible, but even more ugly solution would be to do a union, where we have the following layout: // Work around stackless's modification of PyTypeObject and PyHeapTypeObject struct LIBSHIBOKEN_API SbkObjectType { union { struct { PyTypeObject ht_type; }; } super; SbkObjectTypePrivate* d; }; I tried this modification and it works! Unfortunately with verbose copying of all fields... This is a bit ugly, but could be made better by a little script that extracts all the fields from object.h and builds an include file dynamically. I have the impression that changing it this way would make the patch even worse. And all the things that have now my macroes, will eventually change, anyway, when we go to Version 2 with runtime compatibile layout. On the other hand: I could put this whole craziness into stackless itself. That would then work without changing PySide at all, just recompile... What do you think? cheers - Chris (patch attached) -- Christian Tismer :^) Software Consulting : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de phone +49 173 24 18 776 fax +49 (30) 700143-0023 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- From 26dbbe41fcda3cc2d16baed6c0268f97e4f2451c Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Sun, 20 Oct 2013 21:19:15 +0200 Subject: [PATCH] combined stackless patch About this patch ---------------- This is a minimal patch that makes compilation of PySide work with Stackless Python. It involves PySide and Shiboken, so the one cannot go without the other. The change ids are: Shiboken: Change-Id: I9f713dbadaee8227bc27b932a5623325c98020a9 PySide: Change-Id: I636a086e57eb5b02ef1918ecdafd70676eb544ba The problem was the different layout of frames in stackless, where the field "ht_type" does not exist. Instead, stackless always uses the extended type, and all fields are accessible without "ht_type". For more details about the structure differences, see http://stackless.com/browser/Include/object.h I introduced a few macros which put these differences into a central place: sbkpython.h and made sure that this file is always included, also in all generated files. This is actually just syntactic sugar: The generated code is identical for CPython. Tested to build correctly on OS X with stackless on python 2.7.5 plain python 2.7.5 plain python 3.3 Migration of this patch ----------------------- The reason that I wrote this was to convince myself that Stackless Python and PySide can work together. As mentioned on the mailing list, this is just a proof of concept. The real solution is to change PySide in a way that the same binaries work with CPython and Stackless Python. As soon as I can come up with a better solution that works without an extra compilation, I will migrate to a new patch. I know it can be done, because some other well-known project already does it. At the moment I'm happy that this works, and I would like to be able to tell people that they can use this interims solution to work with Stackless PySide at all. Cheers - Chris Change-Id: I9f713dbadaee8227bc27b932a5623325c98020a9 --- libshiboken/basewrapper.h | 120 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h index 7885c50..d9c6cfb 100644 --- a/libshiboken/basewrapper.h +++ b/libshiboken/basewrapper.h @@ -81,13 +81,133 @@ extern LIBSHIBOKEN_API SbkObjectType SbkObject_Type; struct SbkObjectTypePrivate; + /// PyTypeObject extended with C++ multiple inheritance information. +#ifndef STACKLESS + struct LIBSHIBOKEN_API SbkObjectType { PyHeapTypeObject super; SbkObjectTypePrivate* d; }; +#else // STACKLESS + +// Work around stackless's modification of PyTypeObject and PyHeapTypeObject +struct LIBSHIBOKEN_API SbkObjectType +{ + union { + struct { + PyTypeObject ht_type; + }; + struct { + PyObject_VAR_HEAD + const char *tp_name; /* For printing, in format "." */ + Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */ + + /* Methods to implement standard operations */ + + destructor tp_dealloc; + printfunc tp_print; + getattrfunc tp_getattr; + setattrfunc tp_setattr; + void *tp_reserved; /* formerly known as tp_compare */ + reprfunc tp_repr; + + /* Method suites for standard classes */ + + PyNumberMethods *tp_as_number; + PySequenceMethods *tp_as_sequence; + PyMappingMethods *tp_as_mapping; + + /* More standard operations (here for binary compatibility) */ + + hashfunc tp_hash; + ternaryfunc tp_call; + reprfunc tp_str; + getattrofunc tp_getattro; + setattrofunc tp_setattro; + + /* Functions to access object as input/output buffer */ + PyBufferProcs *tp_as_buffer; + + /* Flags to define presence of optional/expanded features */ + long tp_flags; + + const char *tp_doc; /* Documentation string */ + + /* Assigned meaning in release 2.0 */ + /* call function for all accessible objects */ + traverseproc tp_traverse; + + /* delete references to contained objects */ + inquiry tp_clear; + + /* Assigned meaning in release 2.1 */ + /* rich comparisons */ + richcmpfunc tp_richcompare; + + /* weak reference enabler */ + Py_ssize_t tp_weaklistoffset; + + /* Iterators */ + getiterfunc tp_iter; + iternextfunc tp_iternext; + + /* Attribute descriptor and subclassing stuff */ + struct PyMethodDef *tp_methods; + struct PyMemberDef *tp_members; + struct PyGetSetDef *tp_getset; + struct _typeobject *tp_base; + PyObject *tp_dict; + descrgetfunc tp_descr_get; + descrsetfunc tp_descr_set; + Py_ssize_t tp_dictoffset; + initproc tp_init; + allocfunc tp_alloc; + newfunc tp_new; + freefunc tp_free; /* Low-level free-memory routine */ + inquiry tp_is_gc; /* For PyObject_IS_GC */ + PyObject *tp_bases; + PyObject *tp_mro; /* method resolution order */ + PyObject *tp_cache; + PyObject *tp_subclasses; + PyObject *tp_weaklist; + destructor tp_del; + + /* Type attribute cache version tag. Added in version 2.6 */ + unsigned int tp_version_tag; + +#ifdef COUNT_ALLOCS + /* these must be last and never explicitly initialized */ + Py_ssize_t tp_allocs; + Py_ssize_t tp_frees; + Py_ssize_t tp_maxalloc; + struct _typeobject *tp_prev; + struct _typeobject *tp_next; +#endif +#ifdef STACKLESS + /* we need the extended structure right here */ + PyNumberMethods as_number; + PyMappingMethods as_mapping; + PySequenceMethods as_sequence; /* as_sequence comes after as_mapping, + so that the mapping wins when both + the mapping and the sequence define + a given operator (e.g. __getitem__). + see add_operators() in typeobject.c . */ + PyBufferProcs as_buffer; + PyObject *ht_name, *ht_slots, *ht_qualname; + struct _dictkeysobject *ht_cached_keys; + /* here are optional user slots, followed by the members. */ + slp_methodflags slpflags; +#endif + }; + } super; + SbkObjectTypePrivate* d; +}; + +#endif + LIBSHIBOKEN_API PyObject* SbkObjectTpNew(PyTypeObject* subtype, PyObject*, PyObject*); } // extern "C" -- 1.7.11.1 From Fun_Extra_300 at gmx.net Thu Oct 24 16:03:03 2013 From: Fun_Extra_300 at gmx.net (Robert Schilling) Date: Thu, 24 Oct 2013 16:03:03 +0200 (CEST) Subject: [PySide] Create wheel packages Message-ID: An HTML attachment was scrubbed... URL: From backup.rlacko at gmail.com Thu Oct 24 16:31:15 2013 From: backup.rlacko at gmail.com (Roman Lacko) Date: Thu, 24 Oct 2013 16:31:15 +0200 Subject: [PySide] Create wheel packages In-Reply-To: References: Message-ID: Hi Robert, 2013/10/24 Robert Schilling > Hi, > > How to create the wheel packages for python which are provided at > http://download.qt-project.org/official_releases/pyside/ > install the wheel package: $ pip install wheel then you can build the wheel via: $ python setup.py bdist_wheel ... I use the following command on my windows system to build the wheel distribution: $ c:\Python27\python.exe setup.py bdist_wheel --qmake=c:\Qt\qt-4.8.5-msvc2008-x32\bin\qmake.exe --openssl=c:\Libs\OpenSSL32bit\bin Regards -Roman > > Thanks Robert > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tismer at stackless.com Fri Oct 25 01:26:09 2013 From: tismer at stackless.com (Christian Tismer) Date: Fri, 25 Oct 2013 01:26:09 +0200 Subject: [PySide] Create wheel packages In-Reply-To: References: Message-ID: <5269AC91.9020702@stackless.com> On 24.10.13 16:31, Roman Lacko wrote: > Hi Robert, > > 2013/10/24 Robert Schilling > > > Hi, > How to create the wheel packages for python which are provided at > http://download.qt-project.org/official_releases/pyside/ > > > install the wheel package: > > $ pip install wheel > > then you can build the wheel via: > > $ python setup.py bdist_wheel ... > > I use the following command on my windows system to build the wheel > distribution: > > $ c:\Python27\python.exe setup.py bdist_wheel > --qmake=c:\Qt\qt-4.8.5-msvc2008-x32\bin\qmake.exe > --openssl=c:\Libs\OpenSSL32bit\bin Without further investigation, just to mention: I tried something similar on OS X 10.9 with the latest version of pyside-setup and my newly created stackless build: $ ~/src/slptest/qtslp27/bin/python setup.py bdist_wheel --plat-name=macosx-10.8-x86_64_slp With bdist_egg it all works fine on 10.9. But bdist_wheel ends with: ... > running install_scripts > creating build/bdist.macosx-10.8-x86_64/wheel/PySide-1.3.0dev.data > creating build/bdist.macosx-10.8-x86_64/wheel/PySide-1.3.0dev.data/scripts > copying build/scripts-2.7/pyside_postinstall.py -> build/bdist.macosx-10.8-x86_64/wheel/PySide-1.3.0dev.data/scripts > changing mode of build/bdist.macosx-10.8-x86_64/wheel/PySide-1.3.0dev.data/scripts/pyside_postinstall.py to 755 > Installing pyside-uic script to build/bdist.macosx-10.8-x86_64/wheel/PySide-1.3.0dev.data/scripts > Traceback (most recent call last): > File "setup.py", line 966, in > ext_package = 'PySide', > File "/Users/tismer/src/slptest/lib/python2.7/distutils/core.py", line 152, in setup > dist.run_commands() > File "/Users/tismer/src/slptest/lib/python2.7/distutils/dist.py", line 953, in run_commands > self.run_command(cmd) > File "/Users/tismer/src/slptest/lib/python2.7/distutils/dist.py", line 972, in run_command > cmd_obj.run() > File "/Users/tismer/src/slptest/qtslp27/lib/python2.7/site-packages/wheel/bdist_wheel.py", line 207, in run > archive_basename = self.get_archive_basename() > File "/Users/tismer/src/slptest/qtslp27/lib/python2.7/site-packages/wheel/bdist_wheel.py", line 156, in get_archive_basename > impl_tag, abi_tag, plat_tag = self.get_tag() > File "/Users/tismer/src/slptest/qtslp27/lib/python2.7/site-packages/wheel/bdist_wheel.py", line 150, in get_tag > assert tag == supported_tags[0] > AssertionError Because there seems to be no documentation what supported_tags should be and where to look further, I refuse this time to dig through this and stick with .egg until wheel is more rugged or verbosely telling what's wrong ;-) cheers - chris -- Christian Tismer :^) Software Consulting : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de phone +49 173 24 18 776 fax +49 (30) 700143-0023 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jingsong at fivestars.com Fri Oct 25 01:37:29 2013 From: jingsong at fivestars.com (Jingsong Wang) Date: Thu, 24 Oct 2013 16:37:29 -0700 Subject: [PySide] Qt 4.8 version compatibility with PySide 1.1.1 on Windows Message-ID: Anyone definitively know if Qt 4.8 is compatible with PySide 1.1.1 on Windows, specifically XP? According to the PyPI site for PySide 1.1.1 ( https://pypi.python.org/pypi/PySide/1.1.1qt474#compatibility), it isn't. -- Jingsong Wang Engineering (408) 712-6770 | jingsong at fivestars.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From zaharid at gmail.com Fri Oct 25 13:54:29 2013 From: zaharid at gmail.com (Zahari Dim) Date: Fri, 25 Oct 2013 13:54:29 +0200 Subject: [PySide] Fwd: Working with the clipboard cross-plattafrom In-Reply-To: References: <525C8588.4050802@bluewin.ch> <525C891C.9010509@bluewin.ch> Message-ID: ---------- Forwarded message ---------- From: Zahari Dim Date: Tue, Oct 15, 2013 at 3:23 PM Subject: Re: [PySide] Working with the clipboard cross-plattafrom To: Aaron Richiger Hi Aaron, Your example works well. However, when I try to paste plain text to the paste app with my set_clipboard function, it freezes. It does work with PyQt4, though. I don't know in which way to manage the event loop so that it allows me to run the function in an interactive way (ie without entering the qt event loop forever) and if possible also inside ipython qtconsole (spyder) when ran with pyside. I have tried something like this (with quite some tweaking) to no avail: def start_app(): app = QtCore.QCoreApplication.instance() if app is None: print "app" app = QtGui.QApplication([]) return app def exec_app(app): try: from IPython.lib.guisupport import start_event_loop_qt4 start_event_loop_qt4(app) except ImportError: app.exec_() def run_in_qt (f, *args, **kwargs): def _f(*args, **kwargs): app = start_app() def _exe(): f(*args, **kwargs) app.quit() QtCore.QTimer.singleShot(1, _exe) exec_app(app) return _f @run_in_qt def set_clipboard(content, mime = 'text/plain'): #app=QtGui.QApplication.instance() # checks if QApplication already exists #if not app: # create QApplication if it doesnt exist # app = QtGui.QApplication(sys.argv) mymime = QtCore.QMimeData() mymime.setData(mime, QtCore.QByteArray(content.encode('utf-8'))) app = start_app() clipboard = app.clipboard() clipboard.setMimeData(mymime) The function start_event_loop_qt4(app) basically exec_'s the app only if none is already running. I can't understand what does pyside do with the registers in which it stores the clipboard. For example, I can paste after I close your copy app, but it's not the same here... On Tue, Oct 15, 2013 at 2:15 AM, Aaron Richiger wrote: > Ah... From your code, I thougt plaintext to be enough. For different > mime types, qt may be the best solution:-/ > Did you try my example with USE_PYPERCLIP = False? Because this uses qt > and works perfectly on my machine and I guess it would do so too when using > other mime types. > Aaron > > Am 15.10.2013 02:10, schrieb Zahari Dim: > > Hi Aaron, > > Thank you for your reply! The problem with pyperclip is that unfortunately > it doesn't support custom mime types. > > I would like to be able to something like set_clipboard(lyxcontent, > mime=«application/x-lyx») to paste content for different applications which > treat differently their mimes and plain text. I am not aware of any easier > toolkit for this problem... > Best regards, > > Zahari > On Oct 15, 2013 2:00 AM, "Aaron Richiger" wrote: > >> Hello Zahari! >> >> Sorry, just saw, that the USE_PYPERCLIP flag was set to True in the files >> I sent you. So change it to False first to be consistent with >> clipboard_copy.py and then change both to True. Sorry for the noise, sent >> you a previous version... >> Aaron >> >> Am 15.10.2013 00:45, schrieb Zahari Dim: >> >> Hi, >> >> I need to programatically fill the clipboard with content that has >> custom mime types. I could make it work with PyQt4 (with some cabarets). >> But when I try the same for PySide, the application I try to paste to just >> freezes, both under windows and linux. How could make this work with >> PySide: >> >> >> #This works >> from PyQt4 import QtCore, QtGui >> #This doesn't >> #from PySide import QtCore, QtGui >> >> def start_app(): >> app = QtCore.QCoreApplication.instance() >> if app is None: >> print "app" >> app = QtGui.QApplication([]) >> return app >> >> >> #@run_in_qt >> def set_clipboard(content, mime = 'text/plain'): >> >> mymime = QtCore.QMimeData() >> mymime.setData(mime, QtCore.QByteArray(content.encode('utf-8'))) >> app = start_app() >> clipboard = app.clipboard() >> clipboard.setMimeData(mymime) >> >> >> def get_clipboard(): >> content = QtGui.QApplication.clipboard().mimeData() >> avaiable_formats = content.formats() >> return {fmt:content.data(fmt) for fmt in avaiable_formats} >> >> >> #PyQt4 doesn't work without this line _outside_ any of the functions.... >> __app = start_app() >> >> >> Any help would be appreciated. >> >> Zahari Dimitrov. >> >> >> >> >> >> >> _______________________________________________ >> PySide mailing listPySide at qt-project.orghttp://lists.qt-project.org/mailman/listinfo/pyside >> >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jpe at wingware.com Fri Oct 25 20:01:48 2013 From: jpe at wingware.com (John Ehresman) Date: Fri, 25 Oct 2013 14:01:48 -0400 Subject: [PySide] [Stackless] PySide problem, take #2: typeobject clash In-Reply-To: <5266D51E.7040808@stackless.com> References: <50C3B4D8.3020103@stackless.com> <526356FA.1050108@stackless.com> <52654E52.8030507@wingware.com> <526559DB.7080403@stackless.com> <52655D17.8040005@wingware.com> <52655F49.7040502@stackless.com> <52658A20.1040403@wingware.com> <52658FA1.7050908@stackless.com> <52668AB8.30805@wingware.com> <5266A754.40901@stackless.com> <5266D51E.7040808@stackless.com> Message-ID: <526AB20C.50107@wingware.com> On 10/22/13 3:42 PM, Christian Tismer wrote: >> That would really be a minimal patch with much less ugliness and clutter. >> Well, not sure yet if I want to try that really right now...maybe > > Tried this -- does not work. > While a good idea, the introduced differences are too big to go away with > this simple trick. > The thing breaks in for instance > >> /Users/tismer/src/pyside-setup/pyside_build/py2.7-qt4.8.5-64bit-release/pyside/PySide/QtCore/PySide/QtCore/qbitarray_wrapper.cpp:1626:38: >> error: no member named 'as_number' in 'SbkObjectType::> struct at >> /Users/tismer/src/pyside-setup/pyside_install/py2.7-qt4.8.5-64bit-release/include/shiboken/basewrapper.h:99:5>' >> memset(&Sbk_QBitArray_Type.super.as_number, 0, >> sizeof(PyNumberMethods)); I looked at this a bit more and it's a bit of a mess (as many things with shiboken are so I'm not surprised). Looking at at, I think there's a good possibility the the use of PyHeapTypeObject isn't needed. The as_number initialization above can, I think, be replaced by declaring a static PyNumberMethods sruct and then setting the tp_as_number pointer to it. The same can be done for the other tp_as_* pointers. With this generation change, you shouldn't have any references to super.* fields other than super.ht_type. I also think it's worth trying to fix the binary compatibility problems. If not, we should add something so a library for cpython fails to load into a stackless interpreter and vice versa so that things fail early rather than in obscure ways later. But back to my original assumption, does anyone know if PyHeapTypeObjects need to be used directly by shiboken (as opposed to plain PyTypeObjects)? Thanks, John From dmccombs at dyn.com Fri Oct 25 21:13:10 2013 From: dmccombs at dyn.com (Dan McCombs) Date: Fri, 25 Oct 2013 15:13:10 -0400 Subject: [PySide] Fwd: Creating and deleting instances of QApplication within unit tests In-Reply-To: References: Message-ID: Hey all, I've been struggling with unit testing my PySide application. My tests run fine, but if I have more than one test, Python segfaults on quit. It seems the solution would be to destroy/create the QApplication instance on each test run, as I've seen people mentioning in the case of PyQT such as: http://stuvel.eu/blog/127/multiple-instances-of-qapplication-in-one-process I've tried doing something similar in PySide with the following lines in my setUp for each test: QtGui.qApp = QtGui.QApplication([]) And the following in my tearDown: QtGui.quit() QtGui.qApp = none However, the instance still exists (I can get it via QtGui.QApplication.instance()) and when the second test setUp starts to run, I get an exception that "A QApplication instance already exists.". How can I fully remove the QApplication instance between tests? Thanks, -Dan -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthew.woehlke at kitware.com Fri Oct 25 22:09:46 2013 From: matthew.woehlke at kitware.com (Matthew Woehlke) Date: Fri, 25 Oct 2013 16:09:46 -0400 Subject: [PySide] Fwd: Creating and deleting instances of QApplication within unit tests In-Reply-To: References: Message-ID: On 2013-10-25 15:13, Dan McCombs wrote: > I've been struggling with unit testing my PySide application. My tests run > fine, but if I have more than one test, Python segfaults on quit. It seems > the solution would be to destroy/create the QApplication instance on each > test run, as I've seen people mentioning in the case of PyQT such as: > > http://stuvel.eu/blog/127/multiple-instances-of-qapplication-in-one-process > > I've tried doing something similar in PySide with the following lines in my > setUp for each test: > > QtGui.qApp = QtGui.QApplication([]) Um... this wouldn't work in C++, and I rather suspect it's not the right way to go about it in Python either. In C++, qApp is an alias for QApplication::instance(). I believe the case for Python is similar. Probably when you assign to QtGui.qApp in Python you are replacing the convenience accessor with a reference to your own instance, which does nothing to actually get rid of the QApplication instance. Normally you should just construct a QApplication instance and assign it to some variable. Did you try this? app = QtGui.QApplication([]) ... delete app -- Matthew From dmccombs at dyn.com Sat Oct 26 14:01:40 2013 From: dmccombs at dyn.com (Dan McCombs) Date: Sat, 26 Oct 2013 08:01:40 -0400 Subject: [PySide] Creating and deleting instances of QApplication within unit tests In-Reply-To: References: Message-ID: Hi Matthew, Yes, the first thing I tried was: app = QtGui.QApplication([]) ... del app But, the next test raises the exception about there already being a QApplication instance when it runs that first line. That's why I resorted to poking around trying to figure out where PySide is keeping track of that original instance causing it to raise that exception. -Dan -- Dan McCombs Senior Software Engineer / Dyn http://dyn.com/ Are you prepared for website disaster? Find out in two minutes: http://dyn.com/dynedu-disaster-planning/ On Fri, Oct 25, 2013 at 3:13 PM, Dan McCombs wrote: > Hey all, > > I've been struggling with unit testing my PySide application. My tests run > fine, but if I have more than one test, Python segfaults on quit. It seems > the solution would be to destroy/create the QApplication instance on each > test run, as I've seen people mentioning in the case of PyQT such as: > > http://stuvel.eu/blog/127/multiple-instances-of-qapplication-in-one-process > > I've tried doing something similar in PySide with the following lines in > my setUp for each test: > > QtGui.qApp = QtGui.QApplication([]) > > And the following in my tearDown: > > QtGui.quit() > QtGui.qApp = none > > However, the instance still exists (I can get it via > QtGui.QApplication.instance()) and when the second test setUp starts to > run, I get an exception that "A QApplication instance already exists.". > > How can I fully remove the QApplication instance between tests? > > Thanks, > > -Dan > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tismer at stackless.com Mon Oct 28 00:58:34 2013 From: tismer at stackless.com (Christian Tismer) Date: Mon, 28 Oct 2013 00:58:34 +0100 Subject: [PySide] [Stackless] PySide problem, take #2: typeobject clash In-Reply-To: <526AB20C.50107@wingware.com> References: <50C3B4D8.3020103@stackless.com> <526356FA.1050108@stackless.com> <52654E52.8030507@wingware.com> <526559DB.7080403@stackless.com> <52655D17.8040005@wingware.com> <52655F49.7040502@stackless.com> <52658A20.1040403@wingware.com> <52658FA1.7050908@stackless.com> <52668AB8.30805@wingware.com> <5266A754.40901@stackless.com> <5266D51E.7040808@stackless.com> <526AB20C.50107@wingware.com> Message-ID: <526DA8AA.9040403@stackless.com> On 25.10.13 20:01, John Ehresman wrote: > On 10/22/13 3:42 PM, Christian Tismer wrote: >>> That would really be a minimal patch with much less ugliness and >>> clutter. >>> Well, not sure yet if I want to try that really right now...maybe >> >> Tried this -- does not work. >> While a good idea, the introduced differences are too big to go away >> with >> this simple trick. >> The thing breaks in for instance >> >>> /Users/tismer/src/pyside-setup/pyside_build/py2.7-qt4.8.5-64bit-release/pyside/PySide/QtCore/PySide/QtCore/qbitarray_wrapper.cpp:1626:38: >>> >>> error: no member named 'as_number' in 'SbkObjectType::>> struct at >>> /Users/tismer/src/pyside-setup/pyside_install/py2.7-qt4.8.5-64bit-release/include/shiboken/basewrapper.h:99:5>' >>> >>> memset(&Sbk_QBitArray_Type.super.as_number, 0, >>> sizeof(PyNumberMethods)); > > I looked at this a bit more and it's a bit of a mess (as many things > with shiboken are so I'm not surprised). Looking at at, I think > there's a good possibility the the use of PyHeapTypeObject isn't > needed. The as_number initialization above can, I think, be replaced > by declaring a static PyNumberMethods sruct and then setting the > tp_as_number pointer to it. The same can be done for the other > tp_as_* pointers. > > With this generation change, you shouldn't have any references to > super.* fields other than super.ht_type. Unfortunately it is more than that: minimax:pyside-setup tismer$ grep -r ht_type sources/ sources//pyside/libpyside/pysidesignal.cpp: PyObject* typeDict = wrapperType->super.ht_type.tp_dict; sources//pyside/PySide/phonon/typesystem_phonon.xml: PyDict_SetItemString(Sbk_Phonon_BackendCapabilities_NotifierWrapper_Type.super.ht_type.tp_dict, "capabilitiesChanged", (PyObject*)signal_item); sources//pyside/PySide/phonon/typesystem_phonon.xml: PyDict_SetItemString( Sbk_Phonon_BackendCapabilities_NotifierWrapper_Type.super.ht_type.tp_dict, "availableAudioOutputDevicesChanged", (PyObject*)signal_item); sources//pyside/PySide/QtGui/typesystem_gui_common.xml: PyDict_SetItemString(Sbk_QGraphicsItem_Type.super.ht_type.tp_dict, "UserType", userTypeConstant); sources//shiboken/generator/shiboken/cppgenerator.cpp: s << ")->super.ht_type.tp_dict, \"" << enumValue->name() << "\", anonEnumItem) < 0)" << endl; sources//shiboken/generator/shiboken/cppgenerator.cpp: s << INDENT << pyTypeName << ".super.ht_type.tp_as_number = &" << pyTypeName << ".super.as_number;" << endl; sources//shiboken/generator/shiboken/cppgenerator.cpp: s << INDENT << pyTypeName << ".super.ht_type.tp_as_sequence = &" << pyTypeName << ".super.as_sequence;" << endl; sources//shiboken/generator/shiboken/cppgenerator.cpp: s << INDENT << pyTypeName << ".super.ht_type.tp_as_mapping = &" << pyTypeName << ".super.as_mapping;" << endl; sources//shiboken/generator/shiboken/cppgenerator.cpp: s << INDENT << "PyDict_SetItemString(" + cpythonTypeName(metaClass) + ".super.ht_type.tp_dict, \""; sources//shiboken/generator/shiboken/shibokengenerator.cpp: code.replace("%PYTHONTYPEOBJECT", cpythonTypeName(context) + ".super.ht_type"); sources//shiboken/generator/shiboken/shibokengenerator.cpp: code.replace("%PYTHONTYPEOBJECT", cpythonTypeName(func->implementingClass()) + ".super.ht_type"); sources//shiboken/libshiboken/basewrapper.cpp: type->super.ht_type.tp_base = (PyTypeObject*)baseType; sources//shiboken/libshiboken/basewrapper.cpp: type->super.ht_type.tp_bases = baseTypes; sources//shiboken/libshiboken/basewrapper.h: PyTypeObject ht_type; sources//shiboken/libshiboken/bindingmanager.cpp: file << '"' << (*j)->super.ht_type.tp_name << "\" -> \"" << node1->super.ht_type.tp_name << "\"\n"; sources//shiboken/libshiboken/sbkenum.cpp: if (enumType && PyDict_SetItemString(scope->super.ht_type.tp_dict, name, (PyObject*)enumType) < 0) sources//shiboken/libshiboken/sbkenum.cpp: if (flagsType && PyDict_SetItemString(scope->super.ht_type.tp_dict, flagsType->tp_name, (PyObject*)flagsType) < 0) sources//shiboken/libshiboken/sbkenum.cpp: if (PyDict_SetItemString(scope->super.ht_type.tp_dict, itemName, enumItem) < 0) minimax:pyside-setup tismer$ At the moment, the alternative patch seems to be the one that gives the minimum change so far. cheers - chris -- Christian Tismer :^) Software Consulting : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de phone +49 173 24 18 776 fax +49 (30) 700143-0023 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From tismer at stackless.com Mon Oct 28 04:56:00 2013 From: tismer at stackless.com (Christian Tismer) Date: Mon, 28 Oct 2013 04:56:00 +0100 Subject: [PySide] Finale (Re: [Stackless] PySide problem, take #2: typeobject clash) In-Reply-To: <526DA8AA.9040403@stackless.com> References: <50C3B4D8.3020103@stackless.com> <526356FA.1050108@stackless.com> <52654E52.8030507@wingware.com> <526559DB.7080403@stackless.com> <52655D17.8040005@wingware.com> <52655F49.7040502@stackless.com> <52658A20.1040403@wingware.com> <52658FA1.7050908@stackless.com> <52668AB8.30805@wingware.com> <5266A754.40901@stackless.com> <5266D51E.7040808@stackless.com> <526AB20C.50107@wingware.com> <526DA8AA.9040403@stackless.com> Message-ID: <526DE050.2000507@stackless.com> Howdy, today I found the final solution. Yay !-) Very few lines of code, and binary compatible with CPython and Stackless. That means you need not compile different versions if you switch to Stackless. This was the end of a long journey, until I realized: - PySide does not directly use any structure that stackless changes. - the only problem is that PySide wants to extend PyType_Type, but stackless wants to do the same. Solution: - turn stackless off in PySide, by defining STACKLESS_OFF - add the needed padding to SbkObjectType By definition, STACKLESS_OFF has the effect of producing vanilla CPython, so it is not even needed to test more than one version. It _is_ already a plain CPython extension, and if it runs on stackless, it also runs on CPython. End of a long journey... ... and I should better remember solutions which were prepared since a decade. Well, this use case of STACKLESS_OFF was in fact not known before. cheers - Chris -- Christian Tismer :^) Software Consulting : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de phone +49 173 24 18 776 fax +49 (30) 700143-0023 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From jsteele at cert.org Mon Oct 28 16:07:24 2013 From: jsteele at cert.org (Jonathan Steele) Date: Mon, 28 Oct 2013 15:07:24 +0000 Subject: [PySide] Deploying a PySide app on OS X Message-ID: I have a PySide application that I'm struggling to build into an application (.app) that other OS X users can run, and hoped that someone here might have some tips to get me going. I'm running OS X 10.6, python 2.7, and PySide 4.8.4. I have very little experience with this side of things, but here is what I've tried so far: 1. Using py2app. I generated a basic setup.py and tried to use it to build the app. The dependencies seem to copy fine, but then I get this error: /usr/bin/strip: the __LINKEDIT segment does not cover the end of the file (can't be processed) in: /Users/jsteele/work/releases/ipfixview-0.1.0/dist/main.app/Contents/Framewo rks/QtCore.framework/Versions/4/QtCore Some googling left me with the impression that there's an architecture mismatch between the way the QtCore library is built and what py2app is trying to build, but I'm not clear on how to proceed to resolve this. 2. Ryan Kelly's myppy. This seemed like a promising idea, but after installing myppy, I got an error trying to init a workspace: BUILDING FOR ARCH ppc /usr/bin/gcc -Os -arch ppc -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -I/Users/jsteele/work/myppy/ipfixview.app/Contents/Frameworks/Python.framew ork/Versions/2.7/include -I. -c -o example.o test/example.c In file included from ./zconf.h:427, from ./zlib.h:34, from test/example.c:8: /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory In file included from test/example.c:8: ./zlib.h:1758: error: expected declaration specifiers or Œ...¹ before Œva_list¹ make: *** [example.o] Error 1 3. Using cx_Freeze. I initially had a problem getting the dependencies copied correctly because cx_Freeze runs "otool -L" to find them and expects an absolute path, but the pyside libraries returned only the library name with no path. I fixed that using install_name_tool -change to specify the full path, and then seemed to successfully generate the .app. It runs correctly on my machine. However, when I gave it to a colleague to try, he got this error: LSOpenURLsWithRole() failed with error -10810 The error code of -10810 translates to "An unknown error has occurred", which doesn't exactly help point me towards a resolution! Recommendations on how to proceed would be gratefully received. Thanks! --Jon From hedieh.ebrahimi at amphos21.com Mon Oct 28 16:35:43 2013 From: hedieh.ebrahimi at amphos21.com (Hedieh Ebrahimi) Date: Mon, 28 Oct 2013 16:35:43 +0100 Subject: [PySide] Fwd: PyQt Designer In-Reply-To: References: Message-ID: Hi, I have problems using ScrollArea in PyQt . I have the following object. 1. Frame 2. Scroll Area 3. tab object 4.Group Box 5. My Buttons I am trying to make the ScrollBar appear but it doesn´t. Then, I put my frame and scrollArea smaller than my tab widget, but still the scroll bar doesn´t appear. Also I have set the minimum size of the tab widget object and the groupbox to their original size. I have attached my ui file with this email.Could somebody please take a look at my file and please let me know what I could be doing wrong. Thanks in Advance -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test2.ui Type: application/octet-stream Size: 5393 bytes Desc: not available URL: From matthew.woehlke at kitware.com Mon Oct 28 18:08:05 2013 From: matthew.woehlke at kitware.com (Matthew Woehlke) Date: Mon, 28 Oct 2013 13:08:05 -0400 Subject: [PySide] Fwd: PyQt Designer In-Reply-To: References: Message-ID: On 2013-10-28 11:35, Hedieh Ebrahimi wrote: > I have problems using ScrollArea in PyQt . I have the following object. > > 1. Frame > 2. Scroll Area > 3. tab object > 4.Group Box > 5. My Buttons > > I am trying to make the ScrollBar appear but it doesn´t. You are completely lacking in any layouts. As a result, none of your controls will resize automatically. In Qt, free-floating controls are almost always a sign that you're doing something wrong. I would recommend that you read up on layouts. Several of the top hits of http://www.google.com/search?q=qt+using+layouts look promising... -- Matthew From tismer at stackless.com Mon Oct 28 19:29:29 2013 From: tismer at stackless.com (Christian Tismer) Date: Mon, 28 Oct 2013 19:29:29 +0100 Subject: [PySide] Deploying a PySide app on OS X In-Reply-To: References: Message-ID: <1CAA02A4-A5AA-4CF6-8CCB-85D2375BBD36@stackless.com> You did not tell which system you have. It looks like you have no intel machine? There was ppc mentioned in the logs. I use the pyinstaller right now. Current installers seem to use the RPATH feature which was introduced with 10.5. After using homebrew for Python, I needed to build my own and had to learn this the hard way: When I'm building Python on Mountain Lion, I set something like export MACOSX_DEPLOYMENT_TARGET=10.6 or higher. That is crucial. Maybe it helps Sent from my Ei4Steve > On Oct 28, 2013, at 16:07, Jonathan Steele wrote: > > I have a PySide application that I'm struggling to build into an > application (.app) that other OS X users can run, and hoped that someone > here might have some tips to get me going. I'm running OS X 10.6, python > 2.7, and PySide 4.8.4. I have very little experience with this side of > things, but here is what I've tried so far: > > 1. Using py2app. I generated a basic setup.py and tried to use it to > build the app. The dependencies seem to copy fine, but then I get this > error: > > /usr/bin/strip: the __LINKEDIT segment does not cover the end of the file > (can't be processed) in: > /Users/jsteele/work/releases/ipfixview-0.1.0/dist/main.app/Contents/Framewo > rks/QtCore.framework/Versions/4/QtCore > > Some googling left me with the impression that there's an architecture > mismatch between the way the QtCore library is built and what py2app is > trying to build, but I'm not clear on how to proceed to resolve this. > > 2. Ryan Kelly's myppy. This seemed like a promising idea, but after > installing myppy, I got an error trying to init a workspace: > > BUILDING FOR ARCH ppc > /usr/bin/gcc -Os -arch ppc -mmacosx-version-min=10.4 -isysroot > /Developer/SDKs/MacOSX10.4u.sdk > -I/Users/jsteele/work/myppy/ipfixview.app/Contents/Frameworks/Python.framew > ork/Versions/2.7/include -I. -c -o example.o test/example.c > In file included from ./zconf.h:427, > from ./zlib.h:34, > from test/example.c:8: > /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: > stdarg.h: No such file or directory > In file included from test/example.c:8: > ./zlib.h:1758: error: expected declaration specifiers or Œ...¹ before > Œva_list¹ > make: *** [example.o] Error 1 > > > > 3. Using cx_Freeze. I initially had a problem getting the dependencies > copied correctly because cx_Freeze runs "otool -L" to find them and > expects an absolute path, but the pyside libraries returned only the > library name with no path. I fixed that using install_name_tool -change > to specify the full path, and then seemed to successfully generate the > .app. It runs correctly on my machine. However, when I gave it to a > colleague to try, he got this error: > > LSOpenURLsWithRole() failed with error -10810 > > The error code of -10810 translates to "An unknown error has occurred", > which doesn't exactly help point me towards a resolution! > > Recommendations on how to proceed would be gratefully received. Thanks! > > --Jon > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside From dmccombs at dyn.com Mon Oct 28 19:35:22 2013 From: dmccombs at dyn.com (Dan McCombs) Date: Mon, 28 Oct 2013 14:35:22 -0400 Subject: [PySide] Deploying a PySide app on OS X In-Reply-To: <1CAA02A4-A5AA-4CF6-8CCB-85D2375BBD36@stackless.com> References: <1CAA02A4-A5AA-4CF6-8CCB-85D2375BBD36@stackless.com> Message-ID: That's a good point. I set macosx_deployment_target to 10.6 in my macports.conf file before building Python and freezing my app. Otherwise, the app will not run on anything lower than the version of OS X you're running, and if you don't have that explicitly set in your Info.plist, it just silently fails to open on older machines. -Dan -- Dan McCombs Senior Software Engineer / Dyn http://dyn.com/ Are you prepared for website disaster? Find out in two minutes: http://dyn.com/dynedu-disaster-planning/ On Mon, Oct 28, 2013 at 2:29 PM, Christian Tismer wrote: > You did not tell which system you have. It looks like you have no intel > machine? There was ppc mentioned in the logs. > > I use the pyinstaller right now. > Current installers seem to use the > RPATH feature which was introduced with 10.5. > > After using homebrew for Python, I needed to build my own and had to > learn this the hard way: > > When I'm building Python on Mountain Lion, I set something > like export MACOSX_DEPLOYMENT_TARGET=10.6 or higher. That is crucial. > > Maybe it helps > > Sent from my Ei4Steve > > > On Oct 28, 2013, at 16:07, Jonathan Steele wrote: > > > > I have a PySide application that I'm struggling to build into an > > application (.app) that other OS X users can run, and hoped that someone > > here might have some tips to get me going. I'm running OS X 10.6, python > > 2.7, and PySide 4.8.4. I have very little experience with this side of > > things, but here is what I've tried so far: > > > > 1. Using py2app. I generated a basic setup.py and tried to use it to > > build the app. The dependencies seem to copy fine, but then I get this > > error: > > > > /usr/bin/strip: the __LINKEDIT segment does not cover the end of the file > > (can't be processed) in: > > > /Users/jsteele/work/releases/ipfixview-0.1.0/dist/main.app/Contents/Framewo > > rks/QtCore.framework/Versions/4/QtCore > > > > Some googling left me with the impression that there's an architecture > > mismatch between the way the QtCore library is built and what py2app is > > trying to build, but I'm not clear on how to proceed to resolve this. > > > > 2. Ryan Kelly's myppy. This seemed like a promising idea, but after > > installing myppy, I got an error trying to init a workspace: > > > > BUILDING FOR ARCH ppc > > /usr/bin/gcc -Os -arch ppc -mmacosx-version-min=10.4 -isysroot > > /Developer/SDKs/MacOSX10.4u.sdk > > > -I/Users/jsteele/work/myppy/ipfixview.app/Contents/Frameworks/Python.framew > > ork/Versions/2.7/include -I. -c -o example.o test/example.c > > In file included from ./zconf.h:427, > > from ./zlib.h:34, > > from test/example.c:8: > > /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: > > stdarg.h: No such file or directory > > In file included from test/example.c:8: > > ./zlib.h:1758: error: expected declaration specifiers or Œ...¹ before > > Œva_list¹ > > make: *** [example.o] Error 1 > > > > > > > > 3. Using cx_Freeze. I initially had a problem getting the dependencies > > copied correctly because cx_Freeze runs "otool -L" to find them and > > expects an absolute path, but the pyside libraries returned only the > > library name with no path. I fixed that using install_name_tool -change > > to specify the full path, and then seemed to successfully generate the > > .app. It runs correctly on my machine. However, when I gave it to a > > colleague to try, he got this error: > > > > LSOpenURLsWithRole() failed with error -10810 > > > > The error code of -10810 translates to "An unknown error has occurred", > > which doesn't exactly help point me towards a resolution! > > > > Recommendations on how to proceed would be gratefully received. Thanks! > > > > --Jon > > > > _______________________________________________ > > PySide mailing list > > PySide at qt-project.org > > http://lists.qt-project.org/mailman/listinfo/pyside > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ltanure at gmail.com Mon Oct 28 23:19:43 2013 From: ltanure at gmail.com (Lucas Tanure) Date: Mon, 28 Oct 2013 20:19:43 -0200 Subject: [PySide] [Pyside][ Bug ]Signal calls with no arguments Message-ID: Hi, I use Arch Linux, and Pyside 1.2.1 . And if I do: @QtCore.Slot() def on_motor_group1_power_slider_valueChanged(self, value): print value Where motor_group1_power_slider is a QSlider. I got : TypeError: on_motor_group1_power_slider_valueChanged() takes exactly 2 arguments (1 given) And this happens with many classes in PySide. There is one bug in Pyside, that the signals doesn't have arguments anymore ? This source code is in github: https://github.com/lucastanure/GoGo-Real-Software Thanks -- Lucas A. Tanure Alves +55 (19) 988176559 -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthew.woehlke at kitware.com Tue Oct 29 00:22:36 2013 From: matthew.woehlke at kitware.com (Matthew Woehlke) Date: Mon, 28 Oct 2013 19:22:36 -0400 Subject: [PySide] [Pyside][ Bug ]Signal calls with no arguments In-Reply-To: References: Message-ID: On 2013-10-28 18:19, Lucas Tanure wrote: > if I do: > > @QtCore.Slot() > def on_motor_group1_power_slider_valueChanged(self, value): > print value > > I got : > > TypeError: on_motor_group1_power_slider_valueChanged() takes exactly 2 > arguments (1 given) Do I miss something? It looks like you have declared a method taking one argument as a slot taking no arguments. I'm not surprised this doesn't work. I think you meant to either give an argument in your "@QtCore.Slot()", or else to not give the slot function an argument. -- Matthew From hedieh.ebrahimi at amphos21.com Tue Oct 29 10:50:30 2013 From: hedieh.ebrahimi at amphos21.com (Hedieh Ebrahimi) Date: Tue, 29 Oct 2013 10:50:30 +0100 Subject: [PySide] Fwd: PyQt Designer In-Reply-To: References: Message-ID: Hi Matthew , Thanks, I read your link and applied layouts (from top window to lower widgets ) and enforced minimum widget size and now its working as I wanted. Thanks On 28 October 2013 18:08, Matthew Woehlke wrote: > On 2013-10-28 11:35, Hedieh Ebrahimi wrote: > > I have problems using ScrollArea in PyQt . I have the following object. > > > > 1. Frame > > 2. Scroll Area > > 3. tab object > > 4.Group Box > > 5. My Buttons > > > > I am trying to make the ScrollBar appear but it doesn´t. > > You are completely lacking in any layouts. As a result, none of your > controls will resize automatically. > > In Qt, free-floating controls are almost always a sign that you're doing > something wrong. > > I would recommend that you read up on layouts. Several of the top hits > of http://www.google.com/search?q=qt+using+layouts look promising... > > -- > Matthew > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hedieh.ebrahimi at amphos21.com Tue Oct 29 12:50:10 2013 From: hedieh.ebrahimi at amphos21.com (Hedieh Ebrahimi) Date: Tue, 29 Oct 2013 12:50:10 +0100 Subject: [PySide] Defining your own signal Message-ID: Hi, class MainAppWindow(QMainWindow): def __init__(self, parent=None): super(MainAppWindow, self).__init__() self.ui = Ui_MainWindow.Ui_MainWindow() self.ui.setupUi(self) pushed=QtCore.Signal() self.connect(self.ui.X_Vel_pushButton, QtCore.SIGNAL("pushed()"), self.askforfileBTN(self.ui.X_Vel_lineEdit)) -------------- next part -------------- An HTML attachment was scrubbed... URL: From hedieh.ebrahimi at amphos21.com Tue Oct 29 12:55:40 2013 From: hedieh.ebrahimi at amphos21.com (Hedieh Ebrahimi) Date: Tue, 29 Oct 2013 12:55:40 +0100 Subject: [PySide] Fwd: Defining your own signal In-Reply-To: References: Message-ID: Hi, I have a pushbutton which i want to add my own signal and my own defined signal to it. So this is how I added it. The idea is when the pushbutton is clicked , a file dialog opens that asks for a file. I have my ui objects in a separate file which i import in this file. The problem is my file dialog opens before my main window. Could anybody please help me to fix this. Thanks in Advance. class MainAppWindow(QMainWindow): def __init__(self, parent=None): super(MainAppWindow, self).__init__() self.ui = Ui_MainWindow.Ui_MainWindow() self.ui.setupUi(self) pushed=QtCore.Signal() self.connect(self.ui.X_Vel_pushButton, QtCore.SIGNAL("pushed()"), self.askforfileBTN(self.ui.X_Vel_lineEdit)) This is the class that runs it : import sys from PySide.QtGui import QApplication from MainAppWindow import MainAppWindow curApp = QApplication(sys.argv) mainView = MainAppWindow() mainView.show() sys.exit(curApp.exec_()) -------------- next part -------------- An HTML attachment was scrubbed... URL: From ltanure at gmail.com Tue Oct 29 14:24:05 2013 From: ltanure at gmail.com (Lucas Tanure) Date: Tue, 29 Oct 2013 14:24:05 +0100 Subject: [PySide] [Pyside][ Bug ]Signal calls with no arguments In-Reply-To: References: Message-ID: Hi, Thanks, On previus version of Pyside I didn't need this @QtCore.Slot(), but know only works with this. There is any place where I can find more information ? It will be like @QtCore.Slot(int) ?? Thanks -- Lucas A. Tanure Alves +55 (19) 988176559 On Tue, Oct 29, 2013 at 12:22 AM, Matthew Woehlke < matthew.woehlke at kitware.com> wrote: > On 2013-10-28 18:19, Lucas Tanure wrote: > > if I do: > > > > @QtCore.Slot() > > def on_motor_group1_power_slider_valueChanged(self, value): > > print value > > > > I got : > > > > TypeError: on_motor_group1_power_slider_valueChanged() takes exactly 2 > > arguments (1 given) > > Do I miss something? It looks like you have declared a method taking one > argument as a slot taking no arguments. I'm not surprised this doesn't > work. > > I think you meant to either give an argument in your "@QtCore.Slot()", > or else to not give the slot function an argument. > > -- > Matthew > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hedieh.ebrahimi at amphos21.com Tue Oct 29 15:27:50 2013 From: hedieh.ebrahimi at amphos21.com (Hedieh Ebrahimi) Date: Tue, 29 Oct 2013 15:27:50 +0100 Subject: [PySide] User defined signals and slots Message-ID: Hi all, In my User Interface, I have many pushButtons. When one of these pushButtons is clicked, a function is called that will open a QFileDialog that will let you browse for a file as below: def askforfile(self): curFileName=self.ui.X_Vel_lineEdit.text() (fileName, _selectedFilter) = QtGui.QFileDialog.getOpenFileName(self, filter="*.txt;;*.*",viewMode="Detail") As I have so many of these browse buttons, I was thinking to edit the " askforfile" method so that it would take the QEditLine that is operating on as an argument. Then I understood that Clicked which is a pushButton predefined thing, doesn´t accept arguments and I can not have the following line in my code. self.ui.X_Vel_pushButton.pushed.connect(self.askforfileBTN(self.ui.X_Vel_lineEdit)) as the self.askforfileBTN(self.ui.X_Vel_lineEdit)) has self.ui.X_Vel_lineEdit as its argument. , so finally I defined the following signal and then i connected it. pushed=QtCore.Signal(self.ui.X_Vel_lineEdit) self.connect(self.ui.X_Vel_pushButton, QtCore.SIGNAL("pushed()"), self.askforfileBTN(self.ui.X_Vel_lineEdit)) and now what happens is that the the fileDialog opens even before the main Window opens and before i even click the push button. Any ideas on what I might be doing wrong? Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From boris at pohlers-web.de Tue Oct 29 15:47:55 2013 From: boris at pohlers-web.de (Boris Pohler) Date: Tue, 29 Oct 2013 15:47:55 +0100 Subject: [PySide] User defined signals and slots In-Reply-To: References: Message-ID: <1383058075.1254.9.camel@localhost.localdomain> When you connect the signal to the slot you call the function self.askforfileBTN(self.ui.X_Vel_lineEdit). You want transmit the function as parameter instead like self.connect(self.ui.X_Vel_pushButton, QtCore.SIGNAL("pushed()"), self.askforfileBTN) btw, you are using the old style for connecting signals and slots, you better use the new style self.ui.X_Vel_pushButton.pushed.connect(self.askforfileBTN) HTH Boris Am Dienstag, den 29.10.2013, 15:27 +0100 schrieb Hedieh Ebrahimi: > Hi all, > > > In my User Interface, I have many pushButtons. When one of these > pushButtons is clicked, a function is called that will open a > QFileDialog that will let you browse for a file as below: > > def askforfile(self): > > curFileName=self.ui.X_Vel_lineEdit.text() > (fileName, _selectedFilter) = > QtGui.QFileDialog.getOpenFileName(self, > filter="*.txt;;*.*",viewMode="Detail") > > > > As I have so many of these browse buttons, I was thinking to edit the > " askforfile" method so that it would take the QEditLine that is > operating on as an argument. > > > Then I understood that Clicked which is a pushButton predefined thing, > doesn´t accept arguments and I can not have the following line in my > code. > > > self.ui.X_Vel_pushButton.pushed.connect(self.askforfileBTN(self.ui.X_Vel_lineEdit)) > > > as the self.askforfileBTN(self.ui.X_Vel_lineEdit)) has > self.ui.X_Vel_lineEdit as its argument. > > > , so finally I defined the following signal and then i connected it. > > pushed=QtCore.Signal(self.ui.X_Vel_lineEdit) > > self.connect(self.ui.X_Vel_pushButton, QtCore.SIGNAL("pushed()"), > self.askforfileBTN(self.ui.X_Vel_lineEdit)) > > > and now what happens is that the the fileDialog opens even before the > main Window opens and before i even click the push button. > > > Any ideas on what I might be doing wrong? > > > Thanks > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside From hedieh.ebrahimi at amphos21.com Tue Oct 29 16:02:04 2013 From: hedieh.ebrahimi at amphos21.com (Hedieh Ebrahimi) Date: Tue, 29 Oct 2013 16:02:04 +0100 Subject: [PySide] User defined signals and slots In-Reply-To: <1383058075.1254.9.camel@localhost.localdomain> References: <1383058075.1254.9.camel@localhost.localdomain> Message-ID: I have tried that, but if I transmit function as parameter with no arguments like this : self.connect(self.ui.X_Vel_pushButton, QtCore.SIGNAL("pushed()"), self.askforfileBTN) then my pushButton doesn´t do anything on click.. def askforfileBTN(self,myLineEdit): curFileName=myLineEdit.text() (fileName, _selectedFilter) = QtGui.QFileDialog.getOpenFileName(self, filter="*.txt;;*.*",viewMode="Detail") if fileName!="" and fileName!=curFileName: myLineEdit.setText(fileName) Also when i try the new style as this : self.ui.X_Vel_pushButton.pushed.connect(self.askforfileBTN) I get the following error: AttributeError: 'PySide.QtGui.QPushButton' object has no attribute 'pushed' any ideas what i might be doing wrong? Thanks On 29 October 2013 15:47, Boris Pohler wrote: > When you connect the signal to the slot you call the function > self.askforfileBTN(self.ui.X_Vel_lineEdit). You want transmit the > function as parameter instead like > > self.connect(self.ui.X_Vel_pushButton, QtCore.SIGNAL("pushed()"), > self.askforfileBTN) > > btw, you are using the old style for connecting signals and slots, you > better use the new style > > self.ui.X_Vel_pushButton.pushed.connect(self.askforfileBTN) > > HTH > Boris > > Am Dienstag, den 29.10.2013, 15:27 +0100 schrieb Hedieh Ebrahimi: > > Hi all, > > > > > > In my User Interface, I have many pushButtons. When one of these > > pushButtons is clicked, a function is called that will open a > > QFileDialog that will let you browse for a file as below: > > > > def askforfile(self): > > > > curFileName=self.ui.X_Vel_lineEdit.text() > > (fileName, _selectedFilter) = > > QtGui.QFileDialog.getOpenFileName(self, > > filter="*.txt;;*.*",viewMode="Detail") > > > > > > > > As I have so many of these browse buttons, I was thinking to edit the > > " askforfile" method so that it would take the QEditLine that is > > operating on as an argument. > > > > > > Then I understood that Clicked which is a pushButton predefined thing, > > doesn´t accept arguments and I can not have the following line in my > > code. > > > > > > > self.ui.X_Vel_pushButton.pushed.connect(self.askforfileBTN(self.ui.X_Vel_lineEdit)) > > > > > > as the self.askforfileBTN(self.ui.X_Vel_lineEdit)) has > > self.ui.X_Vel_lineEdit as its argument. > > > > > > , so finally I defined the following signal and then i connected it. > > > > pushed=QtCore.Signal(self.ui.X_Vel_lineEdit) > > > > self.connect(self.ui.X_Vel_pushButton, QtCore.SIGNAL("pushed()"), > > self.askforfileBTN(self.ui.X_Vel_lineEdit)) > > > > > > and now what happens is that the the fileDialog opens even before the > > main Window opens and before i even click the push button. > > > > > > Any ideas on what I might be doing wrong? > > > > > > Thanks > > > > _______________________________________________ > > PySide mailing list > > PySide at qt-project.org > > http://lists.qt-project.org/mailman/listinfo/pyside > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From boris at pohlers-web.de Tue Oct 29 16:27:42 2013 From: boris at pohlers-web.de (Boris Pohler) Date: Tue, 29 Oct 2013 16:27:42 +0100 Subject: [PySide] User defined signals and slots In-Reply-To: References: <1383058075.1254.9.camel@localhost.localdomain> Message-ID: <1383060462.1254.19.camel@localhost.localdomain> As the Traceback says your buttons have no signal pushed, so show us, how you added this signal to your buttons. Instead you could use a QSignalMapper http://pysnippet.blogspot.de/2010/06/qsignalmapper-at-your-service.html or the partial from the python module functools: http://stackoverflow.com/questions/9966731/pyside-pyqt-simple-way-to-bind-multiple-buttons-that-shares-the-same-function HTH Boris Am Dienstag, den 29.10.2013, 16:02 +0100 schrieb Hedieh Ebrahimi: > I have tried that, but if I transmit function as parameter with no > arguments like this : > > self.connect(self.ui.X_Vel_pushButton, QtCore.SIGNAL("pushed()"), > self.askforfileBTN) > > > then my pushButton doesn´t do anything on click.. > > def askforfileBTN(self,myLineEdit): > > curFileName=myLineEdit.text() > (fileName, _selectedFilter) = > QtGui.QFileDialog.getOpenFileName(self, > filter="*.txt;;*.*",viewMode="Detail") > if fileName!="" and fileName!=curFileName: > myLineEdit.setText(fileName) > > > > Also when i try the new style as this : > self.ui.X_Vel_pushButton.pushed.connect(self.askforfileBTN) > > > > I get the following error: > > AttributeError: 'PySide.QtGui.QPushButton' object has no attribute > 'pushed' > > > > any ideas what i might be doing wrong? > > > Thanks > > > > > On 29 October 2013 15:47, Boris Pohler wrote: > When you connect the signal to the slot you call the function > self.askforfileBTN(self.ui.X_Vel_lineEdit). You want transmit > the > function as parameter instead like > > self.connect(self.ui.X_Vel_pushButton, > QtCore.SIGNAL("pushed()"), > self.askforfileBTN) > > btw, you are using the old style for connecting signals and > slots, you > better use the new style > > self.ui.X_Vel_pushButton.pushed.connect(self.askforfileBTN) > > HTH > Boris > > Am Dienstag, den 29.10.2013, 15:27 +0100 schrieb Hedieh > Ebrahimi: > > Hi all, > > > > > > In my User Interface, I have many pushButtons. When one of > these > > pushButtons is clicked, a function is called that will open > a > > QFileDialog that will let you browse for a file as below: > > > > def askforfile(self): > > > > curFileName=self.ui.X_Vel_lineEdit.text() > > (fileName, _selectedFilter) = > > QtGui.QFileDialog.getOpenFileName(self, > > filter="*.txt;;*.*",viewMode="Detail") > > > > > > > > As I have so many of these browse buttons, I was thinking to > edit the > > " askforfile" method so that it would take the QEditLine > that is > > operating on as an argument. > > > > > > Then I understood that Clicked which is a pushButton > predefined thing, > > doesn´t accept arguments and I can not have the following > line in my > > code. > > > > > > > self.ui.X_Vel_pushButton.pushed.connect(self.askforfileBTN(self.ui.X_Vel_lineEdit)) > > > > > > as the self.askforfileBTN(self.ui.X_Vel_lineEdit)) has > > self.ui.X_Vel_lineEdit as its argument. > > > > > > , so finally I defined the following signal and then i > connected it. > > > > pushed=QtCore.Signal(self.ui.X_Vel_lineEdit) > > > > self.connect(self.ui.X_Vel_pushButton, > QtCore.SIGNAL("pushed()"), > > self.askforfileBTN(self.ui.X_Vel_lineEdit)) > > > > > > and now what happens is that the the fileDialog opens even > before the > > main Window opens and before i even click the push button. > > > > > > Any ideas on what I might be doing wrong? > > > > > > Thanks > > > > > _______________________________________________ > > PySide mailing list > > PySide at qt-project.org > > http://lists.qt-project.org/mailman/listinfo/pyside > > > > From matthew.woehlke at kitware.com Tue Oct 29 20:29:34 2013 From: matthew.woehlke at kitware.com (Matthew Woehlke) Date: Tue, 29 Oct 2013 15:29:34 -0400 Subject: [PySide] [Pyside][ Bug ]Signal calls with no arguments In-Reply-To: References: Message-ID: On 2013-10-29 09:24, Lucas Tanure wrote: > Thanks, On previus version of Pyside I didn't need this @QtCore.Slot(), but > know only works with this. Actually, I am also a little surprised the decorator is needed. Usually it isn't. > There is any place where I can find more information ? http://qt-project.org/wiki/Signals_and_Slots_in_PySide > It will be like @QtCore.Slot(int) ?? Based on the above, that looks right to me. -- Matthew From dmccombs at dyn.com Tue Oct 29 20:33:01 2013 From: dmccombs at dyn.com (Dan McCombs) Date: Tue, 29 Oct 2013 15:33:01 -0400 Subject: [PySide] Creating and deleting instances of QApplication within unit tests In-Reply-To: References: Message-ID: Ok, let me ask this question - Someone out there must be unit testing their PySide code. Could you give an example of a test class with multiple separate tests? Thanks! -Dan -- Dan McCombs Senior Software Engineer / Dyn http://dyn.com/ Are you prepared for website disaster? Find out in two minutes: http://dyn.com/dynedu-disaster-planning/ On Sat, Oct 26, 2013 at 8:01 AM, Dan McCombs wrote: > Hi Matthew, > > Yes, the first thing I tried was: > > app = QtGui.QApplication([]) > ... > del app > > But, the next test raises the exception about there already being a > QApplication instance when it runs that first line. That's why I resorted > to poking around trying to figure out where PySide is keeping track of that > original instance causing it to raise that exception. > > -Dan > > > -- > Dan McCombs > Senior Software Engineer / Dyn > http://dyn.com/ > > Are you prepared for website disaster? Find out in two minutes: > http://dyn.com/dynedu-disaster-planning/ > > > On Fri, Oct 25, 2013 at 3:13 PM, Dan McCombs wrote: > >> Hey all, >> >> I've been struggling with unit testing my PySide application. My tests >> run fine, but if I have more than one test, Python segfaults on quit. It >> seems the solution would be to destroy/create the QApplication instance on >> each test run, as I've seen people mentioning in the case of PyQT such as: >> >> >> http://stuvel.eu/blog/127/multiple-instances-of-qapplication-in-one-process >> >> I've tried doing something similar in PySide with the following lines in >> my setUp for each test: >> >> QtGui.qApp = QtGui.QApplication([]) >> >> And the following in my tearDown: >> >> QtGui.quit() >> QtGui.qApp = none >> >> However, the instance still exists (I can get it via >> QtGui.QApplication.instance()) and when the second test setUp starts to >> run, I get an exception that "A QApplication instance already exists.". >> >> How can I fully remove the QApplication instance between tests? >> >> Thanks, >> >> -Dan >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From a.richi at bluewin.ch Tue Oct 29 23:21:00 2013 From: a.richi at bluewin.ch (Aaron Richiger) Date: Tue, 29 Oct 2013 23:21:00 +0100 Subject: [PySide] Creating and deleting instances of QApplication within unit tests In-Reply-To: References: Message-ID: <527034CC.70008@bluewin.ch> Hello Dan! Sorry for not having replied to your question so far... Don't overestimate our testing capabilities;-) Below, you can see some example code with a class with multiple tests. Hope it helps... Aaron import unittest import sys from PySide.QtGui import * from PySide.QtCore import * from PySide.QtTest import * class TestDemo(unittest.TestCase): @classmethod def setUpClass(cls): try: cls.app = QApplication(sys.argv) except: pass def test_widget_1(self): w1 = QPushButton() w1.clicked.connect(self.slot) QTest.mouseClick(w1, Qt.LeftButton) self.assertTrue(self.clicked) def test_widget_2(self): w2 = QPushButton() w2.clicked.connect(self.slot) QTest.mouseClick(w2, Qt.LeftButton) self.assertTrue(self.clicked) def slot(self): self.clicked = True if __name__ == '__main__': unittest.main() Am 29.10.2013 20:33, schrieb Dan McCombs: > Ok, let me ask this question - > > Someone out there must be unit testing their PySide code. Could you > give an example of a test class with multiple separate tests? > > Thanks! > > -Dan > > -- > Dan McCombs > Senior Software Engineer / Dyn > http://dyn.com/ > > Are you prepared for website disaster? Find out in two minutes: > http://dyn.com/dynedu-disaster-planning/ > > > On Sat, Oct 26, 2013 at 8:01 AM, Dan McCombs > wrote: > > Hi Matthew, > > Yes, the first thing I tried was: > > app = QtGui.QApplication([]) > ... > del app > > But, the next test raises the exception about there already being > a QApplication instance when it runs that first line. That's why I > resorted to poking around trying to figure out where PySide is > keeping track of that original instance causing it to raise that > exception. > > -Dan > > > -- > Dan McCombs > Senior Software Engineer / Dyn > http://dyn.com/ > > Are you prepared for website disaster? Find out in two minutes: > http://dyn.com/dynedu-disaster-planning/ > > > On Fri, Oct 25, 2013 at 3:13 PM, Dan McCombs > wrote: > > Hey all, > > I've been struggling with unit testing my PySide application. > My tests run fine, but if I have more than one test, Python > segfaults on quit. It seems the solution would be to > destroy/create the QApplication instance on each test run, as > I've seen people mentioning in the case of PyQT such as: > > http://stuvel.eu/blog/127/multiple-instances-of-qapplication-in-one-process > > I've tried doing something similar in PySide with the > following lines in my setUp for each test: > > QtGui.qApp = QtGui.QApplication([]) > > And the following in my tearDown: > > QtGui.quit() > QtGui.qApp = none > > However, the instance still exists (I can get it via > QtGui.QApplication.instance()) and when the second test setUp > starts to run, I get an exception that "A QApplication > instance already exists.". > > How can I fully remove the QApplication instance between tests? > > Thanks, > > -Dan > > > > > > _______________________________________________ > PySide mailing list > PySide at qt-project.org > http://lists.qt-project.org/mailman/listinfo/pyside -------------- next part -------------- An HTML attachment was scrubbed... URL: From hedieh.ebrahimi at amphos21.com Thu Oct 31 15:56:56 2013 From: hedieh.ebrahimi at amphos21.com (Hedieh Ebrahimi) Date: Thu, 31 Oct 2013 15:56:56 +0100 Subject: [PySide] PySide QSignalMapper not working Message-ID: Hi all, I have 3 pushButtons and I have a function (askforfile) which I want to connect as SLOT to these 3 push buttons. So I tried to use QSignalMapper from QtCore. I don´t know how to connect my function (askforfile) as a map(). I have attached my script. I know that in this line : self.ui.pushButton.connect(self.ui.pushButton, QtCore.SIGNAL("clicked"), self.signalMapper, QtCore.SLOT("map()")) I am not connecting my function (askforfile) to my three buttons, but I don´t know the correct way to do this. I have attached my script. I would really appreciate if anybody could help me correct my script. Thanks in Advance. Sincerely, -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: SignalMapperExample.py Type: application/octet-stream Size: 3513 bytes Desc: not available URL: