McCode
McCode copied to clipboard
Floating point division causes Qt error
For the latest v3.1
release available for (at least) x86_64 linux and macOS, attempting to interactively configure an instrument via mcgui
raises a TypeError
.
Steps to reproduce the error
- Start
mcgui
and load an instrument*.instr
file with user-configurable parameters. - Click on
Run...
This results in an error message printed to stderr
and a seemingly-hung GUI with the status message Getting instrument params...
.
Commandline output showing the error traceback
[~]$ mcgui
loading system configuration
QSocketNotifier: Can only be used with threads started with QThread
Traceback (most recent call last):
File "/usr/local/mcstas/3.1/bin/../tools/Python/mcgui/mcgui.py", line 596, in handleRunOrInterruptSim
fixed_params, new_instr_params, inspect, mcdisplay, autoplotter = self.view.showStartSimDialog(
File "/usr/local/mcstas/3.1/tools/Python/mcgui/viewclasses.py", line 157, in showStartSimDialog
self.__ssd.createParamsWidgets(params)
File "/usr/local/mcstas/3.1/tools/Python/mcgui/viewclasses.py", line 798, in createParamsWidgets
self.ui.gridGrid.addWidget(lbl, y, x, 1, 1)
TypeError: arguments did not match any overloaded call:
addWidget(self, QWidget): too many arguments
addWidget(self, QWidget, int, int, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = Qt.Alignment()): argument 2 has unexpected type 'float'
addWidget(self, QWidget, int, int, int, int, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = Qt.Alignment()): argument 2 has unexpected type 'float'
Source of error
The layout-defining division
https://github.com/McStasMcXtrace/McCode/blob/0c15352d0d01015e96da2e93aa8c7e86a4e20833/tools/Python/mcgui/viewclasses.py#L792
results in a floating point value but an integer is required by addWidget
.
Proposed solution
Switch the floating point division for integer division, e.g., y = i // (int(mccode_config.configuration["GUICOLS"])*2)
.
Implementing the proposed solution in the insitu viewclasses.py
removes the TypeError
and allows the Start simulation
dialog box to appear as expectred.
Hi @g5t, thanks for both issue and proposed solution. :)
I OK with you, I might come by for a "demo" at your desk also, I think there may be (system/user) specifics to it alongside the evident code-problem.
@g5t now reproduced on vanilla Ubuntu 22.04 Arm. As we discussed, likely related to exact version of Qt/pyqt.
Will fix on master and mccode-3 branches toward next set of stable releases. Thanks!
A similar error appears via the pyqtgraph
variant of mcplot
at https://github.com/McStasMcXtrace/McCode/blob/0c15352d0d01015e96da2e93aa8c7e86a4e20833/tools/Python/mccodelib/pqtgfrontend.py#L80-L82
where w
and h
are expected to be int
valued in the call to resize
.
And in the contained function add_plot
which used floating point division
https://github.com/McStasMcXtrace/McCode/blob/0c15352d0d01015e96da2e93aa8c7e86a4e20833/tools/Python/mccodelib/pqtgfrontend.py#L384