Hi all,
I’ve mocked up a method for serialising paths of widgets within a hierarchy of widgets into a Unix-style path, that can then be de-serialised back into its original widget.
Motivation is to be able to reference widgets within deeply nested hierarchies, both for better understanding and debugging but also for undo/redo and messaging.
I’m calling it qtpath for the lack of a better name. Before I make a big deal out of it, I wanted to reach out to you guys in case you’ve encountered anything similar, have ever found the need or can think of alternative methods of achieving the same goal.
https://github.com/abstractfactory/labs/tree/master/python/pyqt/qtpath
>> qtpath.abspath(window, button)
'/Win.Demo/Body.QWidget/Button.QPushButton'
Let me know what you think.
Best,
Marcus
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOC8yntWFgKpaEXDs8f%2BCvSLxvQXtJ1ZLLJABoZs9N8swQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Thanks Fredrik, I’ve also felt the need for something like this. Especially for debugging and CSS.
But this could of course sometimes become problematic if a class can have different parents.
Could you elaborate on this?
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWP4Pky3YFwS8O%2BgCEy_8GZH1mxat2M%3D%2BPWyrBEX06f-fw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Sure. But I was referring to what I usually do, and which could sometimes be problematic and where it looks like your qtpaths solves it (I think):
I set the parent from within a subclass with a parent like
self.mainName = parent
And then if this subclass is inherited I may set
self.mainName.subclassName = parent
And so on… and then I would make sure I can access these object names throughout my app. So from any class, I can access self.mainName.subclassName.widgetName
But in the case of e.g. an image viewer which loads the same widget n times (e.g. one per image), you can’t hard code names like that. That’s where I thought your solution seemed nice, cause then you could serialize on window or maybe parent widget.
On a slightly different note… if you load ui files into PySide vs PyQt the recommended ways of doing it – PySide/QUiLoader vs PyQt/uic.loadUi – this results in different ways of fetching the ui widgets. I solved this with by using PySide/pysideuic vs PyQT/uic, as shown in this boilerplate: https://github.com/fredrikaverpil/pyVFX-boilerplate
I wrote more about that in detail here: https://github.com/fredrikaverpil/pyVFX-boilerplate/wiki#why-pysideuic
Not sure if that is at all related to what you're doing but maybe worth taking into account.
// Fredrik
Ah, we might be referring to separate issues.
Have a look at this:
class Demo(QtWidgets.QWidget):
"""
Object hierarchy looks like this:
Win (Demo)
|-- Body (QWidget)
|-- Button (QPushButton)
Which translates into:
/Win.Demo/Body.QWidget/Button.QPushButton
"""
def __init__(self, parent=None):
super(Demo, self).__init__(parent)
body = QtWidgets.QWidget()
demo_button = QtWidgets.QPushButton('Hello Demo')
body_button = QtWidgets.QPushButton('Hello Body')
layout = QtWidgets.QHBoxLayout(body)
layout.addWidget(body_button)
layout = QtWidgets.QHBoxLayout(self)
layout.addWidget(demo_button)
layout.addWidget(body)
for widget_, name_ in {
self: 'Win',
body: 'Body',
demo_button: 'Button',
body_button: 'Button',
}.iteritems():
widget_.setObjectName(name_)
if __name__ == '__main__':
import sys
# Set-up PyQt application
app = QtWidgets.QApplication(sys.argv)
win = Demo()
# How we would normally find `Button` within `Demo`
find_button = win.findChild(QtWidgets.QPushButton, 'Button')
# Get an instance from `Demo` by serialised path
button = qtpath.instance(win, '/Body.QWidget/Button.QPushButton')
button = qtpath.instance(win, '/Button.QPushButton')
assert find_button == button
# Get back the serialised path from instance.
assert qtpath.abspath(win, button) == '/Win.Demo/Button.QPushButton'
# A path may return nothing
missing = qtpath.instance(win, '/Body.QWidget/Checkbox.QWidget')
assert missing is None
# findPath searches a hierarchy, regardless of proximity to root
# The following will return `Button` closest to `Win`, there is no
# way to directly reference the nested `Button`.
button = win.findChild(QtWidgets.QPushButton, 'Button')
assert button.parent() == win
button = qtpath.instance(win, '/Body.QWidget/Button.QPushButton')
assert button is not find_button
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWOdn%2BAXuffvp3MX49YfCEwfuaoDVCNm_pNRH3y4LPCn9A%40mail.gmail.com.
class Window(QtGui.QDialog):
def __init__(self):
super(Window, self).__init__()
self.button1 = QtGui.QPushButton("Button1", self)
self.button1.setObjectName("button")
self.button2 = QtGui.QPushButton("Button2", self)
self.button2.setObjectName("button")
layout = QtGui.QVBoxLayout(self)
layout.addWidget(self.button1)
layout.addWidget(self.button2)
self.button1.clicked.connect(self.me)
self.button2.clicked.connect(self.me)
def me(self):
print self.sender().objectName()
# button
# button
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCp_Sam8kik2ZJ4a1kE0T10KNrtjZn6RD0WC9m6OPXjxQ%40mail.gmail.com.
Ah, but I believe you’re missing the bigger picture.
Files and folders have absolute paths and we can reference them. But of course, coding anything to absolute paths is no good and I believe the same is true for object hierarchies. With files, we develop resolvers and expression to help decouple them from their roots; I believe the same could be true for object hierarchies.
The problem with directly referencing anything is the spaghetti of links you get between objects operating on other objects.
The need arose when working with many widgets composited within other widgets (think ItemViews) and where each item needed to signal an event up through a hierarchy. To keep everything perfectly decoupled, it made sense to not introduce a global variable or singleton and have each level instead receive a signal and forward it to its parent until eventually being handled by the topmost parent. Simple in theory.
In theory, theory and practice are the same. In practice, they are not. - Albert Einstein
What ends up happening is that whenever you introduce another widget in-between two widget, you’ll have to pick up those signals and forward them to the next, and so the story goes. Changing anything was a nightmare. To borrow terminology from Chad, it’s quite the PITA.
With qtpath, my thinking is that logical hierarchies can be decoupled from their physical hierarchy, in that widgets with no objectName are skipped during traversal. That way, programmers can design a hierarchy they wish to program against, regardless of any hierarchy Qt enforces upon you (e.g. QScrollArea having multiple unexpected children).
# Reference `button`, even though there may be multiple levels of unnamed parents inbetween.
$ /root.QWidget/button.QPushButton
As for your example, of two object names being identical, this is something I would consider poor programming effort and I’d entrust programmers to not get themselves in such a situation.
Thoughts?
Ah, but I believe you’re missing the bigger picture.
What ends up happening is that whenever you introduce another widget in-between two widget, you’ll have to pick up those signals and forward them to the next, and so the story goes. Changing anything was a nightmare. To borrow terminology from Chad, it’s quite the PITA.
With qtpath, my thinking is that logical hierarchies can be decoupled from their physical hierarchy, in that widgets with no objectName are skipped during traversal. That way, programmers can design a hierarchy they wish to program against, regardless of any hierarchy Qt enforces upon you (e.g. QScrollArea having multiple unexpected children).
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCWBbt%3DRNz2TMiehsHJCtWoSnF2zU7OCsYGpt3qXdCQDg%40mail.gmail.com.
Ah, but I believe you’re missing the bigger picture.
Files and folders have absolute paths and we can reference them. But of course, coding anything to absolute paths is no good and I believe the same is true for object hierarchies. With files, we develop resolvers and expression to help decouple them from their roots; I believe the same could be true for object hierarchies.
The problem with directly referencing anything is the spaghetti of links you get between objects operating on other objects.
The need arose when working with many widgets composited within other widgets (think ItemViews) and where each item needed to signal an event up through a hierarchy. To keep everything perfectly decoupled, it made sense to not introduce a global variable or singleton and have each level instead receive a signal and forward it to its parent until eventually being handled by the topmost parent. Simple in theory.
In theory, theory and practice are the same. In practice, they are not. - Albert Einstein
What ends up happening is that whenever you introduce another widget in-between two widget, you’ll have to pick up those signals and forward them to the next, and so the story goes. Changing anything was a nightmare. To borrow terminology from Chad, it’s quite the PITA.
With
qtpath, my thinking is that logical hierarchies can be decoupled from their physical hierarchy, in that widgets with no objectName are skipped during traversal. That way, programmers can design a hierarchy they wish to program against, regardless of any hierarchy Qt enforces upon you (e.g. QScrollArea having multiple unexpected children).# Reference `button`, even though there may be multiple levels of unnamed parents inbetween. $ /root.QWidget/button.QPushButtonAs for your example, of two object names being identical, this is something I would consider poor programming effort and I’d entrust programmers to not get themselves in such a situation.
Thoughts?
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCWBbt%3DRNz2TMiehsHJCtWoSnF2zU7OCsYGpt3qXdCQDg%40mail.gmail.com.
Thanks guys, good thoughts.
I had initially worked with QAbstractItem* classes but found them to be working against me in this particular instance. Of course, this could also mean that I don’t understand it well enough to make it work for me, but I figure at one point or another I’ll have to take a beat, make an assessment and move on. Hard to tell whether or not there was something I missed, maybe I’ll put up another thread with specifics. As a side-note; I have built several UIs with that implementation and overall find it amazingly over-engineered, but that’s another topic altogether.
About MVC; as I originally worked with the QAbstractItem* family, this was unavoidable. But I felt part of what made those classes fail me was partly due to their separation of concerns. Again, I can’t be sure whether I understand it well enough, but from my experiences it wasn’t fit for this purpose. Suffice to say I have considered these alternatives.
QEvents on the other hand. Admittedly, it took me a while to wrap my head around the difference between signals and events in Qt. Events is what I’m using currently in place of signals for things such as this, but not QEvent in particular.
The reason for not using QEvent is that I have objects communicating that lie outside of the graphical domain; i.e. classes not using Qt. What I am looking at however is pypubsub which is a wxPython-inspired implementation of event-handling. It’s different from Qt in that it does introduce globally accessible names (called topics, like with messaging), but I’m too early in to make an educated guess about whether or not it promotes bad design. The idea is to study it, evaluate it, and ultimately port it to ZMQ and unify events across the system.
Finally, on the topic of qtpath, the reason I’m looking to distil paths into strings is so that I can send snapshots about the whereabouts of an item within a hierarchy and from their make use if it and its neighbours. Consider this.
/Win.QWidget/Body.QWidget/John.QWidget
From here, I can browse it’s members, similar to a folder on disk.
John.QWidget
Name.QLineEdit
Age.QSpinBox
Address.QTextEdit
And with that, I can design hierarchies based on how I’d like to organise and access data. Like I would on a file-system.
Let me know what you think.
Best,
Marcus
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1j05Desyg208FvP0NLzN0PNWd%3DHbg1KfpYaw5tsLJVzA%40mail.gmail.com.
Ok, so I’ve mocked up an illustration of my requirements in terms of events into three flavours:
I had trouble with QEvent, maybe you guys have any ideas. The root of the problem seems to be that userdefined events are being accepted even though I’m not the one doing the accepting.
pypubsub is clearly the shortest, most concise and de-coupled variant, but then of course this is a minimal example. I suspect the potential issues are the same as those with any messaging workflow, where pypubsub in this case acts as the broker. As I’m dealing with these issues separately anyway, they aren’t as off-putting to me as they would otherwise be.
pyqtSignal, as discussed, is of course really bad and strongly-coupled.
Added an MVC example.
I’m storing an ID for each item in the model, similar to how I perceive QAbstractItemModel to be doing. Doing that made me realise that these ID’s (or “indexes“) are in fact absolute paths to the given item. The fact that they are obscured and binary does keep people from using me for anything other than temporary stuff, and the docs warn against doing anything persistent with them.
Do you think the same could be said about qtpaths? What if those ID’s actually looked like Unix-style paths? What would be the disadvantage, would it encourage developers to store them and create them manually? Is that bad?
About MVC; as I originally worked with the QAbstractItem* family, this was unavoidable. But I felt part of what made those classes fail me was partly due to their separation of concerns. Again, I can’t be sure whether I understand it well enough, but from my experiences it wasn’t fit for this purpose. Suffice to say I have considered these alternatives.
Finally, on the topic of qtpath, the reason I’m looking to distil paths into strings is so that I can send snapshots about the whereabouts of an item within a hierarchy and from their make use if it and its neighbours. Consider this.
I’m storing an ID for each item in the model, similar to how I perceive QAbstractItemModel to be doing. Doing that made me realise that these ID’s (or “indexes“) are in fact absolute paths to the given item. The fact that they are obscured and binary does keep people from using me for anything other than temporary stuff, and the docs warn against doing anything persistent with them.


To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD7VSM5QryHyqZuk4qHpK%3D0%2BLjuKa0LvE3vdj-LkuQNQw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAJhmvsTuvGihhMj4gU%2B_8kxYx%3DNEQp%2Bcg6oP8Q6AEOXY%3DJc3-A%40mail.gmail.com.
Top-down, here is roughly what I’m looking for in a final design, functionality-wise.
The navigational style is miller-columns; i.e. columns from left to right, like Finder on OSX. The central difference being that each item can potentially be drawn uniquely, based on metadata associated with what the item represents - which for the sake of argument is folders on disk.
A few priorities:
Put another way, I’m not interested in performance nor quantity of items and I’m not getting into looks until I’ve got something that works.
Some specifications; each item is drawn, or not drawn, based on metadata derived from disk; each item potentially unique in shape and content.
# Based on openmetadata
$ /home/marcus/.meta/hidden.bool
$ /home/marcus/.meta/life.float
With that out of the way, the method I’m currently using is to push/pull into objects from/to disk via a separate i/o module; it works something like this.

In that objects aren’t capable of reaching outside of themselves, in terms of access to network or file-system, but are instead fed (pushed) with data and data is further put (pushed) back out by a separate library.
The reason I’m in this signal-mess to begin with is due to this design. Works well in general coding, not so much embedded into graphics.
Thoughts so far?
Best,
Marcus
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODPBRXh%2BK6qjj52GMt6v-cKqV0O0x6gtUekc749cGAamg%40mail.gmail.com.
Added an MVC example.
I’m storing an ID for each item in the model, similar to how I perceive QAbstractItemModel to be doing. Doing that made me realise that these ID’s (or “indexes“) are in fact absolute paths to the given item. The fact that they are obscured and binary does keep people from using me for anything other than temporary stuff, and the docs warn against doing anything persistent with them.
Do you think the same could be said about qtpaths? What if those ID’s actually looked like Unix-style paths? What would be the disadvantage, would it encourage developers to store them and create them manually? Is that bad?
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD7VSM5QryHyqZuk4qHpK%3D0%2BLjuKa0LvE3vdj-LkuQNQw%40mail.gmail.com.
One thing though
Are you using QAbstractItemModels or the Qt “MVC” framework?
Could you clarify this? Is QAbstractItemModel not part of their MVC framework?
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODzSVxGxxgB2BKitoKs3_itn9N5dizRWdi7%2BmYwMHuFAQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3zhXd0-vC8UQCF-kR8n%2BVmk3yzEeMh7RQ%2B68TL0sAEBQ%40mail.gmail.com.
Are you using QAbstractItemModels or the Qt “MVC” framework?
Could you clarify this? Is QAbstractItemModel not part of their MVC framework?
I couldn't figure out how to get QAbstractItemModel to work without involving QModelIndexes, which is ok.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBUy5u_v1Co992DHu9p%3DCB8OKbnFMk77yUU6y-niRxwGQ%40mail.gmail.com.
Thanks Tony, and I’m sorry for sounding like a broken record here, but performance is of no concern to me. It isn’t that I don’t think performance is less important, but rather that now is not the time. And, again, the number of items in the mock-up I posted above is the mid-range of items ever visible to a user at any point in time, and regular widgets have proven more than capable of handling such low counts.
Yes, it is working, but like I said, it’s difficult to maintain and so I’m looking for alternatives - in design, not necessarily in vendor-specific implementations.
For the sake of argument, let’s consider the mockup above and have a look at how the first item in the list, “Snake”, expands into another list containing 3 main items; each of which is drawn differently. The top one consists of additional items, each of which is also drawn differently.
For me to click “run” and have that QPushButton signal to me that it is “snake” signalling “run” from his “stats”, say, wouldn’t I have to propagate a signal up through this hierarchy?
/MillerView/Column1/snake/stats/run
*Each of which has a corresponding path on disk.
If “run” were to signal the model directly, what would it tell the model in order to communicate this information?
Best,
Marcus
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAJhmvsRvvMoim0M%2B%3DdCr4nkz%2B09amAqYcxj_bGeoP41dhXh68g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODS4dhDAaeD7x0wPMBAw1DFkC14QCwF6QnPgi_x3Us3Sg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAJhmvsQb4cN7xHG1vQ1%2BOKmroXkNrxpgOYe%3D%2BCEAeYm64wMLTw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAE4Qynq%3DvzapMnuZ8f0Piqf2bvibRJR7UpAUm%3DNiqJkA%40mail.gmail.com.
Aw. :'( Ok, thanks again for sticking with me this long!

Yea sorry. Apparently I don't get it either. I was following Tony's reply and it made sense to me but I suppose was not applicable to you? I also saw it as a situation where child items in a model know their own context and their parent item. So when representing the "run" item, it knows the context of it being a "run command for snake within the stats location" because it all shares the same underlying data to know that. The fact that it is a button with a signal is part of the view/delegate aspect. A custom data role could give you back the "context" object that you need for the view or delegate to perform the action in response to the click.
Again, like Tony, I apologize if this sounds complicated or abstract. It still doesn't click for me that it needs to be a massive signal passing situation. Only so if you are purely working with widgets that are nested and don't know about each others logic as opposed to a model that already knows all the data in one place.
The performance and data aspects of the model aren't just about what is currently visible. It is also about all the data that is know but not visible. Like if you are modeling a filesystem, you may not be in a location viewing a ton of files and directories, but that doesn't mean the model couldn't resolve sibling or child directory listing ahead of time and have extra data available. Or that you could resolve info about parent locations that may not be displaying the data in a view, but have the data available in the model (like the listing of a directory for which you had just browsed through while navigating down).
I can see why in this situation you would need to pass a lot of dynamic signals, when widgets are completely autonomous. If you are sticking with that approach then it might be good to keep trying that customEvent propagation technique that people list online, and seeing if you can get it to work. Your custom widgets would probably have to have a customEvent method implemented to handle the event if they want. The manual propagation method you found gets around that need by continuing to drive it up the chain until someone handles it. I'm not sure off hand but maybe the customEvent default implementation accepts the event.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOA7Zp%2BOo74dB_xWmyLL_A6E%2BUjsVLFk9BGdAfor1Ww9Sw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2FdDYWO%3DscvYSpy8ACrig%3D9sdBupdg_wSRo_g1r1PkLw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCLF5dCi%3DPmE1ZKGOttM5dn3HqHCX0PXww5HHRdoFMBXg%40mail.gmail.com.
I wouldn't call it a magic bullet either. They are more complicated to set up for sure. But they do work well in situations where you have multiple views on the same data. I've done the Miller Column thing both using the built in QColumnView, and also setups that use the vertical layout with custom widgets, like you are doing. The QColumnView is pretty much a bunch of list views in a horizontal scroll that have their root item set to different levels of the same model. So multiple views share the same data. In the case of the custom widgets in vertical layouts, when I have done stuff like that, I have usually given the "run" button equivalent the context it needs to use when the click happens. Like giving it a prewrapped callback that it does not have to know about. But you obviously know at the time of its creation that it has a context.But ya lets just leave the whole model thing aside because it is a drastic mental shift than what you are already doing. Always something that can be played with later. I can try and take a more focused look at your code example tonight, but it does seem like something could be done with an event filter or customEvents. Ultimately as long as you get some sort of mechanism that pushes events up the chain, you would be good. I wasn't clear on the part where you said you didn't want to overload the event() method since you weren't sure of its logic. But I would think you could still do that and perform save operations, and then call the original event handler at the end.
On Fri, Jun 6, 2014 at 7:51 AM, Marcus Ottosson <konstr...@gmail.com> wrote:
Well, the general issue I see with the QAbstractItem* family is its complexity and that it seems better suited for massive datasets, for which I suspect it was designed.I believe it can be simpler if datasets aren't as large. (less than hundreds of items)If you have a look at the example I just posted, can you see where such a model would fail and where a QAbstractItem* approach would make it easier to maintain? Even if we disregard the low count in items, and disregard performance, can you see anywhere where this model would stop making sense?I'm trying hard to KISS, QAbstractItem* isn't simple enough. I really don't think it's as much of a silver bullet as it you're making it out to be.On 5 June 2014 20:44, Justin Israel <justin...@gmail.com> wrote:Yea sorry. Apparently I don't get it either. I was following Tony's reply and it made sense to me but I suppose was not applicable to you? I also saw it as a situation where child items in a model know their own context and their parent item. So when representing the "run" item, it knows the context of it being a "run command for snake within the stats location" because it all shares the same underlying data to know that. The fact that it is a button with a signal is part of the view/delegate aspect. A custom data role could give you back the "context" object that you need for the view or delegate to perform the action in response to the click.
Again, like Tony, I apologize if this sounds complicated or abstract. It still doesn't click for me that it needs to be a massive signal passing situation. Only so if you are purely working with widgets that are nested and don't know about each others logic as opposed to a model that already knows all the data in one place.
The performance and data aspects of the model aren't just about what is currently visible. It is also about all the data that is know but not visible. Like if you are modeling a filesystem, you may not be in a location viewing a ton of files and directories, but that doesn't mean the model couldn't resolve sibling or child directory listing ahead of time and have extra data available. Or that you could resolve info about parent locations that may not be displaying the data in a view, but have the data available in the model (like the listing of a directory for which you had just browsed through while navigating down).
I can see why in this situation you would need to pass a lot of dynamic signals, when widgets are completely autonomous. If you are sticking with that approach then it might be good to keep trying that customEvent propagation technique that people list online, and seeing if you can get it to work. Your custom widgets would probably have to have a customEvent method implemented to handle the event if they want. The manual propagation method you found gets around that need by continuing to drive it up the chain until someone handles it. I'm not sure off hand but maybe the customEvent default implementation accepts the event.
On Jun 6, 2014 3:40 AM, "Marcus Ottosson" <konstr...@gmail.com> wrote:--I'm making an appearance here too.On 5 June 2014 16:38, Marcus Ottosson <konstr...@gmail.com> wrote:
Aw. :'( Ok, thanks again for sticking with me this long!--
You received this message because you are subscribed to the Google Groups "Python Programmi
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCLF5dCi%3DPmE1ZKGOttM5dn3HqHCX0PXww5HHRdoFMBXg%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3gR-mwQBc7Q1L25GAcajvoJ2VeRA6oQAXkiP8ZrNABmA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
If you are doing Miller columns then that should be equivalent to multiple views of the same data. Presumably you are modeling a path hierarchy and each column is a view onto a different level of the same data model (presumably). Doesn't really matter but I just thought to mention it.
Event filtering means you can tell one object to receive all events first for a given QObject subclass. It can choose to do something based on the event and/or decide whether the event should continue to reach the original target. That means you could have logic all in one class that chooses to do things for other objects like when the mouse is pressed.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBAYw%2BLNYEqUsoFEtttMyEKctNoCsPXv9Vbyyp-wrbaiA%40mail.gmail.com.
If you are doing Miller columns then that should be equivalent to multiple views of the same data. Presumably you are modeling a path hierarchy and each column is a view onto a different level of the same data model (presumably). Doesn’t really matter but I just thought to mention it.
Not sure I’m following you here. Are you saying that:
data = ['item1', 'item2', 'item3']
model = MyModel()
model.setup(data)
view1 = MyView()
view1.setModel(model)
view2 = MyView()
view2.setModel(model)
Is the same as..
data = ['item1', 'item2', 'item3']
model1 = MyModel()
model1.setup(data)
model2 = MyModel()
model2.setup(data)
view1 = MyView()
view1.setModel(model1)
view2 = MyView()
view2.setModel(model2)
..due to both of them using the same set of data? I assumed what you mean with multiple views onto the same set of data involved using the same model, and having them both update according to it, rather than meaning that the file-system is some sort of model.
Event filtering means you can tell one object to receive all events first for a given QObject subclass. It can choose to do something based on the event and/or decide whether the event should continue to reach the original target. That means you could have logic all in one class that chooses to do things for other objects like when the mouse is pressed.
Yes, in my example this is what is happening, but without event filters. My question is, what would event filters do differently?
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2Qk6wJ41qzUymzxLTTJQuSp%2BXxLJ7W9VwkFk8mUmPemw%40mail.gmail.com.
On Jun 6, 2014 5:42 PM, "Marcus Ottosson" <konstr...@gmail.com> wrote:
>>
>> If you are doing Miller columns then that should be equivalent to multiple views of the same data. Presumably you are modeling a path hierarchy and each column is a view onto a different level of the same data model (presumably). Doesn’t really matter but I just thought to mention it.
>
> Not sure I’m following you here. Are you saying that:
>
> data = ['item1', 'item2', 'item3']
>
> model = MyModel()
> model.setup(data)
>
> view1 = MyView()
> view1.setModel(model)
>
> view2 = MyView()
> view2.setModel(model)
>
> Is the same as..
>
> data = ['item1', 'item2', 'item3']
>
> model1 = MyModel()
> model1.setup(data)
>
> model2 = MyModel()
> model2.setup(data)
>
> view1 = MyView()
> view1.setModel(model1)
>
> view2 = MyView()
> view2.setModel(model2)
>
> ..due to both of them using the same set of data? I assumed what you mean with multiple views onto the same set of data involved using the same model, and having them both update according to it, rather than meaning that the file-system is some sort of model.
>>
No those are two different views using two different models. I am talking about the first one, where a single model represents the state of things and different views can root at different levels of it and respond to the same changes in one place. This would be opposed to loading two models with duplicate data. In a Miller column I figured you were showing the hierarchy of a filesystem or file content meaning it is all the same data source which could use the same model, but with different list views showing different parts of the model
>> Event filtering means you can tell one object to receive all events first for a given QObject subclass. It can choose to do something based on the event and/or decide whether the event should continue to reach the original target. That means you could have logic all in one class that chooses to do things for other objects like when the mouse is pressed.
>
> Yes, in my example this is what is happening, but without event filters. My question is, what would event filters do differently?
>
>
In the event filtering approach you would need a custom subclass to use as a baseclass for all your widgets. You would have one class that can look at an event and decide what to do with the object and then install it as an event handler on any widget that needs it.
> To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOC4mxs67k6HMYGJ5AOPKORo4C1jDbfofgLFQbcXnFoY2Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA209ZfdtcpKvYD859-NksH1F8vs9DS%3D%3DoW9Yi2PuoYeBQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODeaBzZSSNw_b_o3KNaDk03YojnBs9Q523pgKzP%2BNAH2A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3XHidSdrqdZCNO0As7wtx2pu236Dg8oaNxG%2B0Pju%2B6_g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODjBeaFrJdJajgyK6q0XZxt_hqoXBpcs65s462oVHhb0Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2ysdc42UJLVEdSFyxwk7x6EJKSiyh9pZX2_nsmQW6LdQ%40mail.gmail.com.
The event filter uses the exact same mechanism that Qt is already using. It puts an event into the event loop. But ya custom events are not propagated, while built in events are.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAgwEaRh-W0_4fHAcLMtcVp5uYu%3DsEVXABqQZOEuAkzew%40mail.gmail.com.
And I wouldn't say it is a code smell since it is using documented and public mechanisms offered by Qt. The docs outline how to do event filtering and posting events.
To be perfectly honest, I don't know. I'd say keep the course and evaluate your available tools. If your aren't working against the grain and the framework is doing what you need in a clean and easy to reason about manner, then keep on keepin' on. It's hard to say if one tool is better than the other. I'm sure you are much better suited to evaluate your options than I as they apply to your application. The best we can do is present the options and our experiences with them.
Ok.Do you still think I'd be better off with QAbstractItem*?
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCr71o48h3-BVThRWUC3OSSMVE50vnHMG%2B9G5X6rYowXQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3_dw99Zu27gGQjB45XfYDu%2B__z91HvKKLXdEgnYKBNLQ%40mail.gmail.com.
Glad it was helpful to solve something! There are so many facets to Qt that it is hard to know them all. I haven't actually sized widgets much through CSS so I will keep that in mind. I use CSS for all the other look related stuff.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOB1oMtPyRAbcWSUb-PJ0TGwHDZ%2BpJPMoDvaNZTdqXDf-A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2_W7Ai79wJ9_NXqj-ypz3CJ%3DFb7MdcbvxAG84JFQumJg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAkwM7GD_W9278Dae-5EDh4Nb-_VNnpHu8oACo1ESGpZA%40mail.gmail.com.
Like keeping a bunch of template snippets that you recompose?
Not sure if you’re speaking from experience or just winging it, but this sounds like a really good idea.
I was going to say that no, css and dynamic properties don’t mix. Anything that has to change at run-time, I change via Python and in some cases by re-setting stylesheets via in-line css on particular widgets; generally avoiding re-setting stylesheets on the entire application due to performance concerns. Having “css snippets” sounds really powerful and aligns well with another methodology I use. I’m mocking up a new thread on CSS as we speak, let’s continue our discussions in there.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0hi00L9fs4z8fxc%2B1qZByvkUhJ5NxEnrtR5o1omX0DXw%40mail.gmail.com.
I will save my reply for that thread. Looking forward to it. Welcoming the chance to improve the CSS + Qt workflow
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBeC1xLLkm31eaz8M62ZHTw-C8EVc6fqy1rNPZqw7shmw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1U245ku_1buTkSNw8QeJqjO3_6KF%3DJLW7fBL-C9eWcOA%40mail.gmail.com.
8 months later, and I stumble across this.
import shiboken
from maya import OpenMayaUI as omui
channel_box_ptr = omui.MQtUtil.findControl("mainChannelBox")
print omui.MQtUtil.fullName(long(channel_box_ptr))
# MayaWindow|MainChannelsLayersLayout|ChannelsLayersPaneLayout|ChannelBoxForm|menuBarLayout1|frameLayout1|mainChannelBox
Got a little deja-vu there.
It’s possibly implemented for backwards compatibility and not really solving a real problem, as we established earlier in this thread. Just thought I’d share in case someone was thinking of heading down the same qt path. (pun!)
Hi all,
I’ve mocked up a method for serialising paths of widgets within a hierarchy of widgets into a Unix-style path, that can then be de-serialised back into its original widget.
Motivation is to be able to reference widgets within deeply nested hierarchies, both for better understanding and debugging but also for undo/redo and messaging.
I’m calling it qtpath for the lack of a better name. Before I make a big deal out of it, I wanted to reach out to you guys in case you’ve encountered anything similar, have ever found the need or can think of alternative methods of achieving the same goal.
https://github.com/abstractfactory/labs/tree/master/python/pyqt/qtpath
>> qtpath.abspath(window, button) '/Win.Demo/Body.QWidget/Button.QPushButton'Let me know what you think.
Best,
Marcus--