Numeric stepper in perspective

Hello!

I´m trying to replicate a numeric control with stepper up and down
image

To do so I added a NumericEntryField and 2 buttons on the side. All inside of a container.

In the container I created a custom property:
image

wich I bind from the NumericEntry Field
image

and in the decrease buttons I added a script event onclick

def runAction(self, event):

def runAction(self, event):
  currentValue = parent.custom.currentValue
    if currentValue > 0: 
        parent.custom.currentValue = currentValue - 1

and on the increase buttons I added a script event onclick

def runAction(self, event):
    currentValue = self.view.parent.custom.currentValue
    self.view.parent.custom.currentValue = currentValue + 1

NOne of the versions, with
parent.custom.
or
self.view.parent.custom

working
image

But I may missing something because is not working. Any ideas welcome.

Is your NumericEntryField binding bidirectional?

You can simplify your code:

def runAction(self, event):
    if parent.custom.currentValue > 0: 
        parent.custom.currentValue -= 1

Tip: as mentioned before, show the window title on your binding screenshots so we can see what exactly you are binding.

Also, the indentation is not correct on the first runAction script.

1 Like

Thanks! still not working

image

in:
image
we have this custom property
image

Sorry, error in my code. It should be,
if parent.custom.currentValue > 0:
Fixed.

I can't see any errors in your configuration.

Tips:

  • Always use onActionPerformed rather than onClick. onClick will execute even if the button is disabled. onActionPerformed doesn't.
  • Don't give your user options that won't work. On Button_1's props.enabled create an expression binding,
    parent.custom.currentValue > 0
    Now you don't need the if parent.custom.currentValue > 0: in your event script.
  • Do something similar with the Button_0.
  • Make sure that the button style changes when not enabled.
2 Likes

I think the problem is you have left out self.

def runAction(self, event):
	self.parent.custom.currentValue -= 1

Use the Browse Properties button in the script editor to avoid this kind of error.

2 Likes

Ok, great, working!

image

this was my problem. Thank you!