Mailing List Archive

Flush / update GUIs in PyQt5 during debugging in PyCharm
Hi Guys
I've written a GUI using PyQt5 and in there I use StyleSheets (css) for the buttons and labels to change their background- and foreground-colors and their states as well.
Because my program doesn't function correctly, I try to debug it in my IDE (PyCharm).
The problem is that during debugging, when I change some attributes of a button or label, let say its background-color, I can not see this modification of the color until the whole method or function is completed.
I believe that I have seen somewhere during my searches and googling that one can flush or update the GUI after each step/action is done.
But until now I couldn't manage it and I don't know where I have to invoke flush/update command in PyCharm.
If anyone has done this before and knows about it, I would very appreciate seeing his solution.

Regards
Mohsen
--
https://mail.python.org/mailman/listinfo/python-list
Re: Flush / update GUIs in PyQt5 during debugging in PyCharm [ In reply to ]
On 9/24/2021 12:46 AM, Mohsen Owzar wrote:
> Hi Guys
> I've written a GUI using PyQt5 and in there I use StyleSheets (css) for the buttons and labels to change their background- and foreground-colors and their states as well.
> Because my program doesn't function correctly, I try to debug it in my IDE (PyCharm).
> The problem is that during debugging, when I change some attributes of a button or label, let say its background-color, I can not see this modification of the color until the whole method or function is completed.
> I believe that I have seen somewhere during my searches and googling that one can flush or update the GUI after each step/action is done.
> But until now I couldn't manage it and I don't know where I have to invoke flush/update command in PyCharm.
> If anyone has done this before and knows about it, I would very appreciate seeing his solution.
>
> Regards
> Mohsen


screen:
form.repaint()

individual widgets:
form.widget.repaint()


--
https://mail.python.org/mailman/listinfo/python-list
Re: Flush / update GUIs in PyQt5 during debugging in PyCharm [ In reply to ]
DFS schrieb am Freitag, 24. September 2021 um 14:52:41 UTC+2:
> On 9/24/2021 12:46 AM, Mohsen Owzar wrote:
> > Hi Guys
> > I've written a GUI using PyQt5 and in there I use StyleSheets (css) for the buttons and labels to change their background- and foreground-colors and their states as well.
> > Because my program doesn't function correctly, I try to debug it in my IDE (PyCharm).
> > The problem is that during debugging, when I change some attributes of a button or label, let say its background-color, I can not see this modification of the color until the whole method or function is completed.
> > I believe that I have seen somewhere during my searches and googling that one can flush or update the GUI after each step/action is done.
> > But until now I couldn't manage it and I don't know where I have to invoke flush/update command in PyCharm.
> > If anyone has done this before and knows about it, I would very appreciate seeing his solution.
> >
> > Regards
> > Mohsen
> screen:
> form.repaint()
>
> individual widgets:
> form.widget.repaint()

@DFS
Hi
I tried to use your suggestion in my code, to see changes in the background-color of the widgets (buttons and labels).
Below is the link of two screenshots of my GUI:
https://imgur.com/a/5LIefN7
They show the start phase and after clicking the “All Active” button.
As I wrote before, I use Stylesheets for configuring widgets.
Here is the code snipped of the relevant part:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if state == 'All Active':
. . .
. . .
for i in range(7):
for j in range(6):
self.buttons_active[j].setText('Inactive')
self.buttons_active[j].setEnabled(True)
self.buttons_active[j].setChecked(True)
self.buttons_active[j].setStyleSheet(css_pushButton())
######################################################

self.buttons_reset[j].setChecked(True)
self.buttons_reset[j].setEnabled(False)
self.buttons_reset[j].setStyleSheet(css_pushButton())

#####################################################

if i > 0 and j < 6:
################################################
self.labels[i, j].setProperty('orange', True)
# self.labels[i, j].repaint()
# aaaa = 4
else:
################################################
self.labels[i, j].setProperty('yellow', True)
# self.labels[i, j].repaint()
# aaaa = 4

self.labels[i, j].setStyleSheet(css_Label())
self.labels[i, j].repaint()
aaa = 4
#####################################################

else:
. . .
. . .
for i in range(7):
for j in range(6):
self.buttons_active[j].setText('Active')
self.buttons_active[j].setEnabled(True)
self.buttons_active[j].setStyleSheet(css_pushButton())
######################################################

######################################################
self.buttons_reset[j].setChecked(False)
self.buttons_reset[j].setEnabled(True)
self.buttons_reset[j].setStyleSheet(css_pushButton())
######################################################

if i > 0:
##################################################
self.labels[i, j].setProperty('gray', True)
# self.labels[i, j].repaint()
# aaaa = 4
else:
self.labels[i, j].setProperty('yellow', True)
# self.labels[i, j].repaint()
# aaaa = 4

self.labels[i, j].setStyleSheet(css_Label())
self.labels[i, j].repaint()
aaa = 4
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
As you can see, the if-else part has to change the background-color of the gray labels (at the start) and the buttons “Active”, “Reset”, “All Active” and “Exit” to orange.
The problem is, after clicking on the “All Active” button all “Resets” and the gray labels change their background-color to orange as desired.
But when I afterwards click again on this button (Now its name is “All Inactive”), the “Resets” and “Exit” buttons change their color and not the 36 labels. They remain in orange.
Therefore I wanted to debug the code in PyCharm and used your suggestion, at first with “form.widget.repaint()” and then with “form.repaint()”.
It didn’t help. I put after the repaint() command line a dummy line to set a break point there. I have put the repair() attribute everywhere in the loop to see if it makes any difference. Nothing was changed.
As long as I was in the “for-loop” and the indices “I” and “j” did not have their end value, I couldn’t see any changes at the break point “aaa = 4”.
Do you know why it didn’t update the GUI?
Perhaps it is not possible to see any changes or updates in the debug mode!!

The CSS part is as below:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
def css_Label():
css = '''
QLabel {background-color: #E0E0E0;
color: black;
border-style: outset;
border-width: 2px;
border-radius: 5px;
border-color: blue;
font: bold 16px;
min-width: 5em;
padding: 4px;
}

QLabel[gray='true'] {background-color: #E0E0E0;
color: black;
border-style: outset;
border-width: 2px;
border-radius: 5px;
border-color: black;
font: bold 16px;
min-width: 5em;
padding: 4px;
}

QLabel[yellow='true'] {color: black;
background-color: yellow;
border-color: black;
font: bold 16px;}

QLabel[orange='true'] {color: black;
background-color: orange;
border-color: black;
font: bold 16px;}

'''
return css

def css_pushButton():
css = '''
QPushButton {
background-color: cyan;
border-style: outset;
border-width: 2px;
border-radius: 5px;
border-color: black;
font: bold 16px;
min-width: 5em;
padding: 4px;
}

QPushButton:disabled {color: blue;
background-color: orange;
font: bold 16px;}

QPushButton:hover {color: black;
background-color: lightgreen;}

QPushButton:hover:enabled {color: blue;
background-color: magenta;}

QPushButton:enabled {background-color: cyan;}

QPushButton:checked {background-color: '#00FF00';
color: red;
font: bold 16px;}
'''
return css
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Regards
Mohsen

--
https://mail.python.org/mailman/listinfo/python-list