Overriding maya clipboard behavior

74 views
Skip to first unread message

vince touache

unread,
Aug 14, 2020, 4:11:44 PM8/14/20
to Python Programming for Autodesk Maya
hi guys, 

I'm working on a new tool, in which I would like to implement a ctl+c/ctl+v to duplicate some (non-serialized) data, e.g. QWidget, QGraphicsItem, etc...
So I'm getting the clipboard from the maya instance using QApplication.instance().clipboard(), works fine.

However, when I connect my clipboard.dataChanged signal and try to ctrl+c in my widget, it doesn't trigger the method I provided; instead, it just behaves like the regular maya clipboard, returning me an error because nothing is selected in my 3d viewport. Seems that ass soon as the focus in on my widget, maya understands it as if the focus was on the viewport instead. If I copy anything in maya, or even outside of maya, however, that'll trigger my slot... Looks like I'm missing some sort of "acceptClipboardEvent" in my widget...

Any idea what I'm missing here? 

Thank you

Marcus Ottosson

unread,
Aug 15, 2020, 2:22:14 AM8/15/20
to python_in...@googlegroups.com
Hey Vince :)

Try assigning a QShortcut to your QApplication instead of leveraging signals; they'll work better with keyboard and input in general, and they supersede any native Maya hotkey, at any level of the application.

1. On focus (e.g. window activation) create QShortcut
2. On deactivation delete QShortcut


--
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/d3fdc10c-9f54-4b76-aea0-9365b27f4c16n%40googlegroups.com.

vince touache

unread,
Aug 15, 2020, 4:10:17 PM8/15/20
to Python Programming for Autodesk Maya
hey Marcus =]

Thanks for the answer! this is what I ended up doing, I access the clipboard using QActions with shortcuts, and it works just fine! I'm still curious to understand better how maya interacts with QApplication exactly, I can't find much resource about.
Anyway, problem solved, thanks ^__^

Justin Israel

unread,
Aug 15, 2020, 5:39:57 PM8/15/20
to python_in...@googlegroups.com


On Sun, Aug 16, 2020, 8:10 AM vince touache <fruit...@gmail.com> wrote:
hey Marcus =]

Thanks for the answer! this is what I ended up doing, I access the clipboard using QActions with shortcuts, and it works just fine! I'm still curious to understand better how maya interacts with QApplication exactly, I can't find much resource about.
Anyway, problem solved, thanks ^__^

You could just consider Maya a generic QMainWindow application running a QApplication instance that your tool gets to share. There are a couple factors about the clipboard and event propagation. The QClipboard docs talk about ownership on X11 and where notifications are actually delivered. But specifically about the QShortcut approach that Marcus offered, it likely has to do with which widget emits and owns the ctrl+c and ctrl+v keypress event. If you don't define your own, then the event bubbles up to the first place that it is accepted, which ends up being the QMainWindow or any of Maya's own child widgets that implemented it as your parent widget (it also depends on under which widget you parented your tool). So when you define your own shortcut, it means you get to handle the keypress first when you are in focus. So you are the owner of the clipboard activity. 
That is my best attempt to explain it in a general non-maya-specific context. 


Le samedi 15 août 2020 à 02:22:14 UTC-4, Marcus Ottosson a écrit :
Hey Vince :)

Try assigning a QShortcut to your QApplication instead of leveraging signals; they'll work better with keyboard and input in general, and they supersede any native Maya hotkey, at any level of the application.

1. On focus (e.g. window activation) create QShortcut
2. On deactivation delete QShortcut


On Fri, 14 Aug 2020 at 21:11, vince touache <fruit...@gmail.com> wrote:
hi guys, 

I'm working on a new tool, in which I would like to implement a ctl+c/ctl+v to duplicate some (non-serialized) data, e.g. QWidget, QGraphicsItem, etc...
So I'm getting the clipboard from the maya instance using QApplication.instance().clipboard(), works fine.

However, when I connect my clipboard.dataChanged signal and try to ctrl+c in my widget, it doesn't trigger the method I provided; instead, it just behaves like the regular maya clipboard, returning me an error because nothing is selected in my 3d viewport. Seems that ass soon as the focus in on my widget, maya understands it as if the focus was on the viewport instead. If I copy anything in maya, or even outside of maya, however, that'll trigger my slot... Looks like I'm missing some sort of "acceptClipboardEvent" in my widget...

Any idea what I'm missing here? 

Thank you

--
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/d3fdc10c-9f54-4b76-aea0-9365b27f4c16n%40googlegroups.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.

vince touache

unread,
Aug 16, 2020, 8:26:01 PM8/16/20
to Python Programming for Autodesk Maya
Thanks for the detailed explanation Justin
" it likely has to do with which widget emits and owns the ctrl+c and ctrl+v keypress event. If you don't define your own, then the event bubbles up to the first place that it is accepted, which ends up being the QMainWindow"
I guess this is the part that doesn't make sense to me: with inheritance, I would expect to have priority if I override a behavior at child level (in this case, my widget), and therefore, to override the clipboard signal of the parent (maya main window). As for maya/qt interactions, it makes sense, it's actually pretty straight forward, I think I was overthinking it, also because I looked at the doc and saw this x11 thingy (and I don't know what that is!) and all the differences depending on the OS

anyway, thanks again for the explanation, much appreciated =]

Justin Israel

unread,
Aug 16, 2020, 9:53:58 PM8/16/20
to python_in...@googlegroups.com
On Mon, Aug 17, 2020 at 12:26 PM vince touache <fruit...@gmail.com> wrote:
Thanks for the detailed explanation Justin
" it likely has to do with which widget emits and owns the ctrl+c and ctrl+v keypress event. If you don't define your own, then the event bubbles up to the first place that it is accepted, which ends up being the QMainWindow"
I guess this is the part that doesn't make sense to me: with inheritance, I would expect to have priority if I override a behavior at child level (in this case, my widget), and therefore, to override the clipboard signal of the parent (maya main window). As for maya/qt interactions, it makes sense, it's actually pretty straight forward, I think I was overthinking it, also because I looked at the doc and saw this x11 thingy (and I don't know what that is!) and all the differences depending on the OS

Signals don't really have a concept of inheritence or overrides. They are just a list of callbacks that the sender iterates. "events" are the thing that works the way you described, where the event is delivered to the most relevant target. But if the event isn't accepted then it can travel up the chain until some parent accepts it or it falls off.  The QShortcut/QAction on your widget acts like the event definition  in this case, so your widget actually generates the clipboard event.
 
Reply all
Reply to author
Forward
0 new messages