Couldn't get the WARNING icon in LcncDialog

  • millikari
  • Away
  • New Member
  • New Member
More
31 Mar 2025 11:14 - 31 Mar 2025 11:31 #325379 by millikari
Hi, I had a little trouble displaying the warning icon in a LcncDialog widget. I think it's caused by setting the default to INFO icon before checking WARNING and CRITICAL (dialog_widget.py in master 0fda49f):
# convert text descriptions to actual icons
if icon == 'QUESTION': icon = QMessageBox.Question
elif icon == 'INFO' or isinstance(icon,str): icon = QMessageBox.Information
elif icon == 'WARNING': icon = QMessageBox.Warning
elif icon == 'CRITICAL': icon = QMessageBox.Critical
self.setIcon(icon)


Changing the sequence of the statements lets me choose also the WARNING icon.
# convert text descriptions to actual icons
if icon == 'QUESTION': icon = QMessageBox.Question
elif icon == 'WARNING': icon = QMessageBox.Warning
elif icon == 'CRITICAL': icon = QMessageBox.Critical
elif icon == 'INFO' or isinstance(icon,str):icon = QMessageBox.Information
self.setIcon(icon)

Sorry, have some problems formatting the code passage in my message
Last edit: 31 Mar 2025 11:31 by millikari. Reason: Hopefully now fixed the formatting

Please Log in or Create an account to join the conversation.

More
31 Mar 2025 16:02 #325408 by snowgoer540
Replied by snowgoer540 on topic Couldn't get the WARNING icon in LcncDialog
It might be helpful to know how you are calling it?

Please Log in or Create an account to join the conversation.

  • millikari
  • Away
  • New Member
  • New Member
More
31 Mar 2025 19:55 - 31 Mar 2025 20:01 #325424 by millikari
Replied by millikari on topic Couldn't get the WARNING icon in LcncDialog
Yes, I call it by connecting STATUS 'general' message and the ACTION.CALL_DIALOG:
if STATUS.machine_is_on():
  mess = {'NAME':'UNHOME_MSG', 'ID':'UNHOME_DIALOG',
                'MESSAGE':'Really want to Un-Home?', 'TYPE':'YESNO', 'ICON':'WARNING'}
   ACTION.CALL_DIALOG(mess)

A LcncDialog widget with matching launch-ID is defined in the ui-file. I have already checked whether the value of the 'icon'-variable is set correctly right before the statement I have shown in my first post (first code box). It's all fine. Looking at the original code, I think, because 'icon' is an instance of string in all cases, the 'WARNING' and 'CRITICAL' cases can never be reached. So I changed the sequence in order to give WARNING and CRITICAL also a chance getting active. Am I right with my consideration or have i missed something?
Last edit: 31 Mar 2025 20:01 by millikari. Reason: Again formatting issues
The following user(s) said Thank You: snowgoer540

Please Log in or Create an account to join the conversation.

More
31 Mar 2025 22:39 - 31 Mar 2025 22:58 #325431 by snowgoer540
Replied by snowgoer540 on topic Couldn't get the WARNING icon in LcncDialog
I made a few minutes to take a look at this tonight.  

I do see the behavior you describe, although the order is not the root cause. 

In this line:  github.com/LinuxCNC/linuxcnc/blob/bd9034...ialog_widget.py#L201

elif icon == 'INFO' or isinstance(icon,str): icon = QMessageBox.Information


it's this part that is causing issue:

isinstance(icon,str)


The icon value is set correctly to 'WARNING' on the go-in, but because but because icon is of type str, the second condition "isinstance(icon, str)" evaluates to True, and therefore never gets to check for 'WARNING'.

Perhaps it’s meant to be a catch all, in that case I agree it should move to last, but I want Chris to weigh in before I change it as I'm not quite sure of the purpose (if typo should we tell the user there’s a typo?).
Last edit: 31 Mar 2025 22:58 by snowgoer540.

Please Log in or Create an account to join the conversation.

More
01 Apr 2025 01:55 #325445 by cmorley
Replied by cmorley on topic Couldn't get the WARNING icon in LcncDialog
Yes its a catchall that should be at the end.
I think I added warning and critical after the others and didn't think of the logic.
Good eye gents!
The following user(s) said Thank You: snowgoer540

Please Log in or Create an account to join the conversation.

More
01 Apr 2025 22:15 #325486 by snowgoer540
The following user(s) said Thank You: cmorley, millikari

Please Log in or Create an account to join the conversation.

Moderators: cmorley
Time to create page: 0.075 seconds
Powered by Kunena Forum