Isotropix Forums

click btn and transfer a variabe to a class

Clarisse Scripting related topics

click btn and transfer a variabe to a class

Unread postby qinyao » Fri Jan 11, 2019 11:11 am

Without a btn, it works.
Code: Select all
class EVT_1(ix.api.EventObject):
    def on_click(self,x):
        print x
evt = EVT_1()
evt.on_click("abcdefg")


When I use a btn to transfer, something wrong:
Code: Select all
...
class EVT_1(ix.api.EventObject):
    def on_click(self,x):
        print x
evt = EVT_1()
evt.connect(my_btn,'EVT_ID_PUSH_BUTTON_CLICK',evt.on_click("abcdefg") )


Can any one tell me where is wrong,thank you .
And another question is how to find the Event ID name from the help document such as 'EVT_ID_PUSH_BUTTON_CLICK'.
qinyao
 
Posts: 72
Joined: Fri Aug 26, 2016 11:29 am

Re: click btn and transfer a variabe to a class

Unread postby ayanik » Fri Jan 11, 2019 12:07 pm

Have a look at the code in this topic how buttons are created and events are handled:

https://forum.isotropix.com/viewtopic.php?f=21&t=2671

You should not call the function. The callback function gets called when you click.
ayanik
 
Posts: 57
Joined: Wed Nov 26, 2014 9:10 pm

Re: click btn and transfer a variabe to a class

Unread postby qinyao » Fri Jan 11, 2019 1:51 pm

I checked the post, But I just want add a custom data to a button. I found there is a function in guiPushButon called: add_custom_data, but I don't know how to use.
qinyao
 
Posts: 72
Joined: Fri Aug 26, 2016 11:29 am

Re: click btn and transfer a variabe to a class

Unread postby bvaldes » Fri Jan 11, 2019 3:44 pm

Hi,

Take a look to this script:

python code

class EventRewire(ix.api.EventObject):
def result(self, sender, evtid):
if sender.infos == 'info1': # Check the info field +> sender = the clicked button
print 'do something'

if sender.infos == 'info2': # Check the info field +> sender = the clicked button
print 'do something else'


class CustomButton(ix.api.GuiPushButton):
def __init__(self, parent, x, y, w, h, label, info=''):
ix.api.GuiPushButton.__init__(self, parent, x, y, w, h, label)
# Little work around, the sender should be the class "CustomButton" but
# python return "ix.api.GuiPushButton". on_click() make the convertion
# for us
self.connect(self, 'EVT_ID_PUSH_BUTTON_CLICK', self.on_click)
self.infos = info

def on_click(self, sender, evtid):
# replace the sender by self to get the info variable
event_rewire.result(self, evtid)


event_rewire = EventRewire()
clarisse_win = ix.application.get_event_window()
window = ix.api.GuiWindow(clarisse_win, 900, 450, 230, 40)
window.set_title('My perfect Window')
panel = ix.api.GuiPanel(window, 0, 0, window.get_width(), window.get_height())
panel.set_constraints(ix.api.GuiWidget.CONSTRAINT_LEFT, ix.api.GuiWidget.CONSTRAINT_TOP,
ix.api.GuiWidget.CONSTRAINT_RIGHT, ix.api.GuiWidget.CONSTRAINT_BOTTOM)

# the last argument is the special argument you wanted to add son can but
# everything you want
button1 = CustomButton(panel, 10, 10, 100, 22, "Button", 'info1')
# the last argument is the special argument you wanted to add son can but
# everything you want
button2 = CustomButton(panel, 120, 10, 100, 22, "Button", 'info2')

window.show()
while window.is_shown():
ix.application.check_for_events()
window.destroy()


I hope that this is what your need, tell me if not.

Best regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Re: click btn and transfer a variabe to a class

Unread postby qinyao » Sat Jan 12, 2019 2:34 pm

Thank you very much, that's what I want.
qinyao
 
Posts: 72
Joined: Fri Aug 26, 2016 11:29 am


Return to Scripting