• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. My custom gui button is getting pressed even before hitting...

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 143
  • Views 8482
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

My custom gui button is getting pressed even before hitting the button.

Purbayan
Purbayan over 3 years ago

I wrote a code where i want to  takes the input from field SF1 and SF3 and when pressed the press me button the callback function will execute a function where it takes values from both the string field.

But the issue is that i when i create the display the form layout  even before pressing the press me button the callback function is getting executed.

I have also attached my code

I would love to have this call back function mapped to ok button but i am unable to do so

procedure(Create_input_form()
FORM2=hiCreateLayoutForm(
'NPN_
"NPN "

hiCreateFormLayout(
'main_layout
?spacing 10
?label_align 'center
?items (list
a=hiCreateStringField(
?name 'SF1
?prompt "SF1 "

?editable t)
hiCreateSeparatorField(
?name 'sep1)
hiCreateStringField(
?name 'SF2
?prompt "SF2"

?editable t)
b=hiCreateStringField(
?name 'SF3
?prompt "SF3"

?editable t)
hiCreateButton(
?name 'button
?buttonText "Press me"

?callback buttonCB(a b))

));main_layout
);display_form
hiDisplayForm(FORM2))

procedure(buttonCB(a b)

printf("Button pressed - field:%s scope:%s\n"
a~>value b~>value
)
)

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 3 years ago

    That's because you're calling the function when you use: ?callback buttonCB(a b). You need to pass either a string to be executed, or a function object. I thought initially (based on your definition of the callback) that you wanted to use the function object way of doing this, in which case you'd change the callback to:

    ?callback getd('buttonCB)

    but then the function would fail because the arguments are strings to the printf - you could fix that to be:

    procedure(buttonCB(a b)
      printf("Button pressed - field:%L scope:%L\n"
        a b
        ;a~>value b~>value
      )
    )

    but given that you're assigning two variables a and b as the fields are created, I suspect this is not what you want it to do. Passing a and b to the callback doesn't make much sense because it will likely get executed out of scope - although you have a and b being global variables, so it would work - but it would be poor code. You could just change

    ?callback "buttonCB(a b)"

    and keep your original buttonCB definition. It's not a field and scope being accessed then, so it's misleading.

    Better would be to change the code like this:

    procedure(Create_input_form()
      let((FORM2)
        FORM2=hiCreateLayoutForm( 
          'NPN_ 
          "NPN "
    
          hiCreateFormLayout( 
            'main_layout
            ?spacing 10 
            ?label_align 'center 
            ?items (list
              hiCreateStringField( 
                ?name 'SF1
                ?prompt "SF1 "
    
                ?editable t)
              hiCreateSeparatorField(
                ?name 'sep1)
                hiCreateStringField( 
                ?name 'SF2
                ?prompt "SF2"
    
                ?editable t)
              hiCreateStringField( 
                ?name 'SF3
                ?prompt "SF3"
    
                ?editable t)
              hiCreateButton(
                ?name 'button
                ?buttonText "Press me"
    
                ?callback "buttonCB(hiGetCurrentForm())"
              )
    
          ));main_layout
        );display_form
        hiDisplayForm(FORM2)
      )
    )
    
    procedure(buttonCB(form)
      printf("Button pressed - field1:%s field3:%s\n"
        form->SF1->value form->SF3->value
      )
    )

    You should also clean up your function names - with names like that you're likely to collide with some other code. Best practice is to start all your functions with a prefix, beginning with an uppercase letter so that you don't clash with other functions.

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 3 years ago

    That's because you're calling the function when you use: ?callback buttonCB(a b). You need to pass either a string to be executed, or a function object. I thought initially (based on your definition of the callback) that you wanted to use the function object way of doing this, in which case you'd change the callback to:

    ?callback getd('buttonCB)

    but then the function would fail because the arguments are strings to the printf - you could fix that to be:

    procedure(buttonCB(a b)
      printf("Button pressed - field:%L scope:%L\n"
        a b
        ;a~>value b~>value
      )
    )

    but given that you're assigning two variables a and b as the fields are created, I suspect this is not what you want it to do. Passing a and b to the callback doesn't make much sense because it will likely get executed out of scope - although you have a and b being global variables, so it would work - but it would be poor code. You could just change

    ?callback "buttonCB(a b)"

    and keep your original buttonCB definition. It's not a field and scope being accessed then, so it's misleading.

    Better would be to change the code like this:

    procedure(Create_input_form()
      let((FORM2)
        FORM2=hiCreateLayoutForm( 
          'NPN_ 
          "NPN "
    
          hiCreateFormLayout( 
            'main_layout
            ?spacing 10 
            ?label_align 'center 
            ?items (list
              hiCreateStringField( 
                ?name 'SF1
                ?prompt "SF1 "
    
                ?editable t)
              hiCreateSeparatorField(
                ?name 'sep1)
                hiCreateStringField( 
                ?name 'SF2
                ?prompt "SF2"
    
                ?editable t)
              hiCreateStringField( 
                ?name 'SF3
                ?prompt "SF3"
    
                ?editable t)
              hiCreateButton(
                ?name 'button
                ?buttonText "Press me"
    
                ?callback "buttonCB(hiGetCurrentForm())"
              )
    
          ));main_layout
        );display_form
        hiDisplayForm(FORM2)
      )
    )
    
    procedure(buttonCB(form)
      printf("Button pressed - field1:%s field3:%s\n"
        form->SF1->value form->SF3->value
      )
    )

    You should also clean up your function names - with names like that you're likely to collide with some other code. Best practice is to start all your functions with a prefix, beginning with an uppercase letter so that you don't clash with other functions.

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Children
  • Purbayan
    Purbayan over 3 years ago in reply to Andrew Beckett

    Thank you Andrew for the response and suggestions, those really helped me a lot.

    Yours

    Purbayan

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information