SG File Open Task List

Hello all! This has been brought up before but never addressed - When you navigate tasks in Shotgrid File Open under the Shots tab, it will jump back to the current task when you open the task list for another shot. I think I have found the root of the issue (the load_cache function in the data_handler is faster than the background worker thread) but I’m not sure if the fix here is to fork tk-framework-shotgunutils and modify the code, or if this will be patched in the future.

Editing with more info:
This behavior can be replicated by following these steps:

  1. In the File Open Menu, under Shots, open an arbitrary shot and actually select (highlight blue) a task
  2. Then, by only clicking the dropdown arrows, open another shot’s task view. The Display should jump back up to the top to the highlighted task.

This behavior implies that the fix would involve setting any expanded views to be considered “selected.”

Fork it, fix it and do a pull request?

This behaviour occurs only when there is a deferred model refresh.

More precisely, the jump(or I should say the behaviour You described) will only happen if You expand with dropdown arrow the item that wasn’t already fetched from the shotgrid.

Initially, only the top level of the displayed model(or the roots) is fetched from the shotgrid. Children are fetched only once they are requested(Hence children models are called “deferred models”).

If the deferred model for the children of the item exist(were fetched from shotgrid), there won’t be a model refresh, and the jump won’t happen.

There is a second part of the problem, and that is the way the tree view elements are defined inside the qt itself. The row consists of two totally unrelated items, the expander and the text. And both of them emit signals, when clicked on. The expander emits “expand” signal(might be named differently, but I’ll call it like this for the purpose of the reply). When the text part of the element is single clicked, it only selects the element. But when it’s double-clicked, since it uses some sort of timer mechanism under the hood to determine whether it’s a double click or not, initial signal is just a selection, the same as it would be for a single click. When it determines that two clicks were actually a double click, the selection signal is not removed, and instead the “expand” signal is emitted too, the same one as for the expander. So, the difference between the double click on an element and a single click on the expander is the selection signal, which only selects the element. Why I wrote this? Well, the workaround for the problem is to double-click on the element(the text part of it), instead of using the expand arrow, for elements that weren’t already expanded. Like I wrote above, once they are expanded for the first time, the jump will not happen again for that particular element. I know it doesn’t solve the issue, but it can help a bit. Also, all other functionalities for expanding an item work just fine(Yes, there are others), in all cases, because all of them involve selecting the item first, prior to expanding it. All except clicking on the expand arrow. I should also add here that the “expand” handler inside the code checks if the model for the child exists. If it doesn’t exist, it invokes fetching the data from the shotgrid, which subsequently invokes jumping back to the last selected item(if it still exists). On the other hand, if the child model exists, it only displays it.

This behaviour occurs because the implementation tries to navigate back to what You had selected if the model refresh was triggered(so that You don’t lose Your selection from the viewport). I assume this originates from some other functionality, but it got to the file open as well.

I’m not sure that the fix would be trivial, because it would involve one of the following

  1. Dealing with signals emitted in the code file open model code and propagating them throughout the code(which I would hate to do, because of other bugs that might occur)
  2. Writing custom tree view which would also emit selection signal when the extender part of the tree view element is clicked. From what I saw, it’s not easy to access the single-click slot for the expander, but I might be wrong, that’s where my investigations have stopped. So, writing a new Tree view component that would also emit the selection signal on expander single click might do the trick.

Hope this helps a bit

2 Likes

I have played a bit with the code and it seems that this is a good starting point for the implementation of the Custom Tree View

class MyTreeView(QtGui.QTreeView):
    def mousePressEvent(self, event):
        self.setCurrentIndex(self.indexAt(event.pos()))
        super().mousePressEvent(event)

From the documentation

Please note that this is just an idea and needs to be tested out thoroughly

2 Likes

So one more problem here.

If You don’t have QT creator/designer, however the blasted tool is named now, You will need to hack the hell out of it

This is the current status of my code:

# python/tk_multi_workfiles/entity_tree/entity_tree_form.py
# find the following line
self._ui.setupUi(self)

# after that line, the magic starts...
# Move old mouse press method to a new method
setattr(self._ui.entity_tree, "oldMousePressEvent", getattr(self._ui.entity_tree, "mousePressEvent"))

# Create a new method that will handle the event
def new_mouse_press_event(host, event):
    host.oldMousePressEvent(event)

    index_under_cursor = host.indexAt(event.pos())
    current_index = host.currentIndex()
    if current_index != index_under_cursor:
        host.selectionModel().setCurrentIndex(
            index_under_cursor, QtGui.QItemSelectionModel.ClearAndSelect
        )

# Register this method under the old one's name
import types
self._ui.entity_tree.mousePressEvent = types.MethodType(new_mouse_press_event, self._ui.entity_tree)

This will now select Your item even when You click on the arrow to expand…

I am not proud of this, to be honest.

And also there has to be a better way even without the QT creator/designer, however the blasted thing is named nowadays.