Problem with closing more than one dock widget programmatically

419 views
Skip to first unread message

Marcos Duarte

unread,
Aug 24, 2015, 8:00:54 PM8/24/15
to pyqtgraph
Hi

First and foremost, thanks for the great package.

I am writing an application with pyqtgraph where the user can create and close many dock widgets and I am having problems when more than one dock is closed programmatically.

For example, when I simply use the DockArea.clear() method to close all docks, some of the docks are torn out from the main window (floated) and not closed.
When I close programmatically one dock per time (with a dialog asking for confirmation), it works fine most of the times but the behavior is erratic.
When I close each dock by pressing its close button, it works fine.

I am using pyqtgraph 0.9.10, PyQt 4.11.3, Qt 4.8.6, and Python 3.4.3 in Mac OS X or MS Windows 7.

The code attached reproduces this problem if one tries to close all docks. I tried different ways but none of them works (weirdly, it works a few times!).

So, my question is how to close more than one dock widget programmatically?

I'd appreciate any help.

Thanks

Marcos
closedocks.py

Mathew Schwartz

unread,
Aug 25, 2015, 2:21:45 AM8/25/15
to pyqt...@googlegroups.com
For me, changing line 55 to self.area.close() instead of clear() makes it work.  I get an error that there is no clear() method.

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/4bb03ced-4faa-4eaf-b10e-496f85558677%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vincent Le Saux

unread,
Aug 25, 2015, 5:33:12 AM8/25/15
to pyqtgraph
Hi,

Have a look at a previous post called Dock feature proposals.

Daniel proposed something on DockArea that may be usefor for you...

Vincent

Marcos Duarte

unread,
Aug 25, 2015, 12:41:30 PM8/25/15
to pyqtgraph
I forgot to mention that I am already using the bleeding edge version of pyqtgraph from its GitHub repo (which includes the changes after the post called Dock feature proposals).
Mathew, this is the reason why my DockArea class has a method .clear(), which is supposed to *delete* all docks, but it doesn't work for me.

If as suggested I use the method .close() for the DockArea instance in line 55 of my example, it works apparently. In this case what is being used is a .close() method from PyQt and not from the Dock class, but in fact the docks are not deleted, they are just hidden. You can check that adding these lines after line 55 (with self.area.close()):

    docks = self.area.findAll()[1]
    print(docks)

But the deletion of all docks will work if I add after the .close() method in line 55:

    for dock in docks.values():
        dock
.setParent(None)
        dock
.label.setParent(None)

But this a workaround because it is not using the builtin .close() method from the Dock class and it is going to wash out all the docks, closable or not.

What really works with the last version in the repo is to simply delete line 238 in Dock.py (self.label.setParent(None)).

To verify that with my example code, comment lines 66 and 104 where I overrode the .close() method (and you may change the number in line 3 to test different implementations).

I don't know if there are side effects with the removal of that line, but this is working so far for me.

thanks

Marcos

andreas.p...@fos4x.de

unread,
May 16, 2017, 5:22:03 AM5/16/17
to pyqtgraph
What works for me is this:

    def close_all_docks(self):
        active_docks = self.dock_area.findAll()[1]        
        for name in active_docks.keys():
            logger.debug('close dock window %s', name)
            active_docks[name].close()
            # fix: without this, last dock is floating and not closed
            QtCore.QCoreApplication.instance().processEvents()
Reply all
Reply to author
Forward
0 new messages