Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off PyQt Event Loop While Editing Table

I'm developing a GUI with PyQt. The GUI has a qListWidget, a qTableWidget, and a plot implemented with Mayavi. The list refers to shapes that are plotted (cylinders and cones for example). When a shape is selected in the list, I want the shape's properties to be loaded into the table (from a dictionary variable) and the shape to be highlighted in the plot. I've got the Mayavi plotting working fine. Also, if the table is edited, I need the shape to be re-plotted, to reflect the new property value (like for a cylinder, if the radius is changed).

So, when a list item is selected -> update the table with the item's properties (from a dictionary variable), highlight the item on the plot

When the table is edited -> update the dictionary variable and re-plot the item

The Problem: when I select a list item and load data into the table, the qTableWidget ItemChanged signal fires every time a cell is updated, which triggers re-plotting the shape numerous times with incomplete data.

Is there a typical means of disabling the GUI event loop while the table is being programmatically updated? (I have experience with Excel VBA, in that context setting Application.EnableEvents=False will prevent triggering a WorksheetChange event every time a cell is programmatically updated.) Should I have a "table update in progress" variable to prevent action from being taken while the table is being updated? Is there a way to update the Table Widget all at once instead of item by item? (I'll admit I'm intentionally avoiding Model-View framework for the moment, hence the qListWIdget and qTableWidget).

Any suggestions?

I'm a first time poster, but a long time user of StackOverflow, so I just want to say thanks in advance for being such an awesome community!

like image 550
flutefreak7 Avatar asked Dec 07 '12 22:12

flutefreak7


People also ask

How to use PyQt events?

PyQt events 1 Events. All GUI applications are event-driven. ... 2 Signals & slots. Here’s a simple example to demonstrate PyQt5’s signal and slot. ... 3 Event sender event send. To facilitate differentiation of multiple event sources connected to the same event target, the sender () method can be used in PyQt5. 4 Customized emission signals. ...

Does PyQt5 have an exec keyword?

Note: PyQt was first developed to target Python 2, which has an exec keyword. To avoid a name conflict on those earlier versions of PyQt, an underscore was added to the end of .exec_ (). Even though PyQt5 targets only Python 3, which doesn’t have an exec keyword, the library provides two methods to start an application’s event loop:

What is the main thread of execution in PyQt?

In PyQt applications, the main thread of execution is also known as the GUI thread because it handles all widgets and other GUI components. You start this thread by calling.exec () on your QApplication object. The main thread runs the application’s event loop and also your Python code.

What is signal and slot in PyQt5?

PyQt5 uses a unique signal and slot mechanism to handle events. Signals and slots are used for communication between objects, and when a particular event occurs, the signal is fired. The slot can be any Python call. The connection to the slot is called while the signal is transmitting. Here’s a simple example to demonstrate PyQt5’s signal and slot.


1 Answers

Signals can be temporarily blocked for any object that inherits QObject:

self.tableWidget.blockSignals(True)
# perform updates, etc
self.tableWidget.blockSignals(False)
like image 198
ekhumoro Avatar answered Oct 08 '22 09:10

ekhumoro