You could do it with a PythonPanel containing an Int_Knob, but that may be a 
little heavy for a simple case like this.

I would probably just wrap the nuke.getInput call to validate the string as a 
number and cast it on return.

import re
def getNumericInput():
    while True:
        raw = nuke.getInput('Enter a number:')
        if raw is None:
            return
        if re.match('^\d+$', raw):
            return int(raw)
        nuke.message('Not a valid number')

Obviously this only handles ints, but if you need a float, you can massage the 
regex a little.

Hope this helps.

-Nathan



From: Ron Ganbar 
Sent: Tuesday, May 15, 2012 11:48 AM
To: Nuke Python discussion 
Subject: Re: [Nuke-python] query a number from the user

Well, I wasn't in front of the computer before, and seems like there isn't a 
number only knob to inherit for the panel object. 
I tried this:

p = nuke.Panel( 'how many dudes?' )
p.addExpressionInput('dudes', '')
p.show()
result = p.value('dudes')
print p.value('dudes')

And it works, but you can type anything in there. Not just a number.
Anybody knows a knob that only expects numbers?

Ron Ganbar
email: [email protected]
tel: +44 (0)7968 007 309 [UK]
     +972 (0)54 255 9765 [Israel]
url: http://ronganbar.wordpress.com/




On 15 May 2012 20:27, Ron Ganbar <[email protected]> wrote:

  You can use a panel and create a knob that only permits numbers.

  R

  On May 15, 2012 6:20 PM, <[email protected]> wrote:

    Hiya.
    I Am looking for the way the get a pop up window asking me a value.
    I cheated by using
    val = int(nuke.getInput('enter the ref frame'))

    wich is normally a text box
    is there a better way for numbers ? I mean that will warn if something else 
than a number is entered

    cheers
    Olivier
    _______________________________________________
    Nuke-python mailing list
    [email protected], http://forums.thefoundry.co.uk/
    http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python




--------------------------------------------------------------------------------
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

Reply via email to