Skip to content

Commit

Permalink
bugfix: Fix spinboxes accepting non-digit characters
Browse files Browse the repository at this point in the history
  • Loading branch information
IoeCmcomc committed Feb 13, 2025
1 parent 437cfba commit f3c2c1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
8 changes: 5 additions & 3 deletions nbstool.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,11 @@ def initVarsAndCallbacksFrom(self, builder: Builder):
builder.import_variables(self)
builder.connect_callbacks(self)

def isInteger(self, value) -> bool:
def isInteger(self, value: str) -> bool:
return value == '' or value.isdigit()

def isRequiredInteger(self, value: str) -> bool:
return value.isdigit()

def getSelectedFilesVersion(self, selection: Iterable) -> int:
fileVersion = -1
Expand Down Expand Up @@ -1068,7 +1071,7 @@ def collapseNotes(self, notes) -> None:
note.layer = layer
prevNote = note

def insertImage(self, imgPath: str, song: NbsSong, x: int, y: int, width: int, height: int):
def insertImage(self, imgPath: str, song: NbsSong, x: int, y: int, width: int, height: int) -> None:
img = Image.open(imgPath)
img.thumbnail((width, height), Image.Resampling.NEAREST)
width, height = img.size
Expand All @@ -1081,7 +1084,6 @@ def insertImage(self, imgPath: str, song: NbsSong, x: int, y: int, width: int, h
r, g, b, a = color
if a <= 25:
continue

nearestColor = Color('srgb', (r / 255, g / 255, b / 255)).closest(NBS_INST_NOTE_COLORS)
inst = NBS_NOTE_COLORS_TO_INST[nearestColor.to_string(hex=True)]
song.notes.append(Note(x + i, y + j, inst, 0, 0))
Expand Down
20 changes: 12 additions & 8 deletions ui/toplevel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@
<property name="state">disabled</property>
<property name="textvariable">string:headerAutosaveInterval</property>
<property name="to">255</property>
<property name="validate">focusout</property>
<property name="validate">key</property>
<property name="validatecommand" type="command" cbtype="entry_validate" args="%P">isInteger</property>
<property name="width">4</property>
<layout manager="grid">
Expand Down Expand Up @@ -390,7 +390,7 @@
<property name="increment">1</property>
<property name="textvariable">string:headerMinuteSpent</property>
<property name="to">2147483647</property>
<property name="validate">focusout</property>
<property name="validate">key</property>
<property name="validatecommand" type="command" cbtype="entry_validate" args="%P">isInteger</property>
<property name="width">11</property>
<layout manager="grid">
Expand All @@ -408,7 +408,7 @@
</property>
<property name="textvariable">string:headerLeftClicks</property>
<property name="to">2147483647</property>
<property name="validate">focusout</property>
<property name="validate">key</property>
<property name="validatecommand" type="command" cbtype="entry_validate" args="%P">isInteger</property>
<property name="width">11</property>
<layout manager="grid">
Expand All @@ -424,7 +424,7 @@
<property name="increment">1</property>
<property name="textvariable">string:headerRightClicks</property>
<property name="to">2147483647</property>
<property name="validate">focusout</property>
<property name="validate">key</property>
<property name="validatecommand" type="command" cbtype="entry_validate" args="%P">isInteger</property>
<property name="width">11</property>
<layout manager="grid">
Expand All @@ -440,7 +440,7 @@
<property name="increment">1</property>
<property name="textvariable">string:headerBlockAdded</property>
<property name="to">2147483647</property>
<property name="validate">focusout</property>
<property name="validate">key</property>
<property name="validatecommand" type="command" cbtype="entry_validate" args="%P">isInteger</property>
<property name="width">11</property>
<layout manager="grid">
Expand All @@ -456,7 +456,7 @@
<property name="increment">1</property>
<property name="textvariable">string:headerBlockRemoved</property>
<property name="to">2147483647</property>
<property name="validate">focusout</property>
<property name="validate">key</property>
<property name="validatecommand" type="command" cbtype="entry_validate" args="%P">isInteger</property>
<property name="width">11</property>
<layout manager="grid">
Expand Down Expand Up @@ -523,7 +523,7 @@
<property name="increment">1</property>
<property name="textvariable">string:headerLoopCount</property>
<property name="to">255</property>
<property name="validate">focusout</property>
<property name="validate">key</property>
<property name="validatecommand" type="command" cbtype="entry_validate" args="%P">isInteger</property>
<property name="width">4</property>
<layout manager="grid">
Expand All @@ -540,7 +540,7 @@
<property name="textvariable">string:headerLoopStart</property>
<property name="to">32767
</property>
<property name="validate">focusout</property>
<property name="validate">key</property>
<property name="validatecommand" type="command" cbtype="entry_validate" args="%P">isInteger</property>
<property name="width">6</property>
<layout manager="grid">
Expand Down Expand Up @@ -885,6 +885,8 @@
<property name="state">disabled</property>
<property name="textvariable">int:imgInsertPosTickVar</property>
<property name="to">65536</property>
<property name="validate">key</property>
<property name="validatecommand" type="command" cbtype="entry_validate" args="%P">isRequiredInteger</property>
<property name="width">6</property>
<layout manager="pack">
<property name="side">left</property>
Expand All @@ -906,6 +908,8 @@
<property name="state">disabled</property>
<property name="textvariable">int:imgInsertPosLayerVar</property>
<property name="to">65536</property>
<property name="validate">key</property>
<property name="validatecommand" type="command" cbtype="entry_validate" args="%P">isRequiredInteger</property>
<property name="width">6</property>
<layout manager="pack">
<property name="side">left</property>
Expand Down

0 comments on commit f3c2c1b

Please sign in to comment.