Skip to content

Commit

Permalink
qtvcp calc: prevent display input, fix check for None
Browse files Browse the repository at this point in the history
Currently inputting text directly into the display (5+5 for example) and clilcking = will cause a crash.  In the future perhaps this can be sorted out to accept this, for now it's best to prevent input into this box.

The newly added preference stores "None" as a string, fix the check to check for "None" instead of None.
  • Loading branch information
snowgoer540 committed Mar 1, 2025
1 parent 9ff4280 commit a69e45a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/python/qtvcp/widgets/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, parent=None):

self.display = QLineEdit('0')
self.display.setMinimumHeight(30)
self.display.setReadOnly(False)
self.display.setReadOnly(True)
self.display.setAlignment(Qt.AlignRight)
self.display.setMaxLength(15)

Expand Down Expand Up @@ -116,7 +116,7 @@ def __init__(self, parent=None):

if self.PREFS_:
constValues = self.PREFS_.getpref('constValuesList', None, str, self.PREF_SECTION)
if constValues is not None:
if constValues != 'None':
self.constButtons = []
constValues = ''.join(constValues.split())
for value in constValues.split(',')[:6]:
Expand Down

3 comments on commit a69e45a

@tangentaudio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take a look at improving the behavior with physical keyboard input since that's a feature I want to have working. I have a few approaches in mind...

  • simply try to evaluate the contents of the QLineEdit and if it's not a number, indicate that and don't allow the "Apply"
  • limiting the input with the QLineEdit inputMask and catching key events for the operator keys so they call the operator functions
  • getting fancy and actually interpreting mathematical expressions in the text

@tangentaudio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some good progress this morning, I should have a PR later today.

@snowgoer540
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things...

  1. I perhaps may have err'd in disabling the display. Sorry about that. But still, the crashing was no good.
  2. When it crashed, there was no way to click Abort.
  3. I did miss one more preference compare for self.behaviorOnShow to "is not None" instead of != 'None'
  4. I am not sure what the Apply button does? Both Cancel and Apply seem to just close the window. Of course I am calling it from QtPlasmaC so perhaps my implementation to test the widget is not as intended.
  5. Looking forward to seeing what you come up with; keep up the good work!

Please sign in to comment.