Hello,
The GUI widget produced with pyside2 programming will be located on panel below. But one widget will be produced after every debugging process, and if I debug 10 times, and there will be 10 widgets on the panel.
How to deal with it if I want just only the last one widget on the panel?
Hi!
I’m not used to UIs in general, but a workaround might be to encapsulate your widget creation in a function and associate a global variable widget_already_exist
that would be set to True
on first execution.
Maybe a *.py
file like:
from PySide2 import QtCore, QtGui, QtWidgets, shiboken2
import itasca as it
it.command("python-reset-state false")
global widget_already_exists
def make_my_widget():
widget_already_exists= globals().get('widget_already_exist ', False)
if not widget_already_exists:
dockWidget = it.dockWidget("Demo GUI","",True)
dockWidget = shiboken2.wrapInstance(int(dockWidget),QtWidgets.QDockWidget)
widget = dockWidget.widget()
widget_already_exists = True
# Your code
I’m pretty sure that PyQt offers the possibility to check if a widget already exists but I am not familiar with this library.
Global variables is not the best idea in Python, but can help in your situation if you do not want to dive into PyQt’s documentation.
Regards,
Théophile
Thanks for your reply, but it does’t seem to be working…
You’re using FLAC3Dv9 or v7?
What you can do is to check if there is any widget with the same name (using findChildren) and remove if needed. To delete a widget, you can remove the widget from its parent (using setParent(None)) then delete (using deleteLater())
Thanks for your reply!
I am using the FLAC2D v9.0.