Ooo, yes that looks slow, at least for anything more than a handful of
channels.

What you could do instead is employ a QAbstractTableModel and a QTableView,
probably wouldn't need a QStyledItemDelegate but could for pixel-level
control. The view would look like the Channel Box (which I presume is
already a QTableView) and the model would be able to output not only values
for each row, but also a background color like what the Channel Box is
doing.

The main hurdle in your case is listening to the data at a performant rate.
I think what needs to happen is two things.

1. Listen for connect/disconnect events, there's a callback you can use
that's nice and fast. Presumably what the Channel Box is using too
2. Once something is connected, listen for attribute change events.
Whenever it changes, you traverse the connection to the associated curve
node and query it for whether there's a key on the given frame.

In the case of (2) there's another optimisation you can, and probably have
to, make which is that you can only really visualise keys on connections
that go to curve nodes. Not connections that go to e.g. some other channel
on some other node. I.e. the ones that turn yellow/blue in the Channel Box.

Another optimisation is monitoring when that curve node is changing, and
then cache all of its values in your own app/window. Since there will
presumably be a frame change more often then keys changing, you should be
able to save some juice there.

Overall, it should be possible to get the same look, at a similar - if not
very similar - performance to the channel box doing it this way. But, if
what you have now is the equivalent a microwavable dish, then this approach
is akin to serving at a fine-dining restaurant, edible 24-carat gold
flakes, sweet potatoes topped with caviar, and squab alongside turkey. It's
hard, is what I'm saying xD

On Wed, 15 Jan 2020 at 01:24, yann19 <yangki...@gmail.com> wrote:

> I have a couple of QLineEdit in my GUI, created using the Qt Designer.
>
> For example, I have 3 QLineEdits in which they are connect to a node's
> translateX, translateY and translateZ.
> These line edits are working as what I have expected but currently I am
> trying to replicate the what Maya has where the channel box fields will
> turns red if the time slider is right on a particular keyed frame/ticks,
> pinkish if in-between of 2 animated frames.
>
> However, for me to update these QLineEdits with color, it seems that in
> almost all of my methods (eg. update_tx(), update_ty() etc) I will need to
> write something as follows:
> def update_tx(node):
>   palette = QtGui.QPalette()
>   palette.setColor(QtGui.QPalette.Base, QtGui.QColor())
>
>     all_frames = cmds.keyframe(node, attribute=attr_name, selected=False,
> query=True, timeChange=True) or []
>     current_frame = cmds.currentTime(query=True)
>
>     if current_frame in all_frames:
>       palette.setColor(QtGui.QPalette.Base, QtGui.QColor("red"))
>     else:
>     palette.setColor(QtGui.QPalette.Base, QtGui.QColor("pink"))
>
>     self.ui.transX_lineedit.setPalette(palette)
>
> Adding on, as I have also created some custom events too, some of the
> involved methods may also needs to be implemented in the same manner.
> As such, is there a better way that I can attempt this?
>
> --
> 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_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/d74766d2-29df-496c-9ccc-cd8d72ef81ad%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/d74766d2-29df-496c-9ccc-cd8d72ef81ad%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCZOmzENcY3CFpee-UqkTyhnVu1aykx_ceRYo4m5PPy4Q%40mail.gmail.com.

Reply via email to