Run component A event from component B event

Is there a way to script a button to run the onClick mouse event script of a different component when the button is clicked??

Classic mistake.

Put the logic into a function in a script module and then call that function any time you need it.

6 Likes

Yes but what if the logic involves altering props of components. Like I have a label that does this when clicked: `def runAction(self, event):

def runAction(self, event):
	# Clear table 
	self.getSibling('Samples').props.selection.selectedRow = -1
	self.getSibling('Samples').props.selection.selectedColumn = -1
	self.getSibling('Samples').props.selection.selectedRow = None
	self.getSibling('Samples').props.selection.selectedColumn = None
	
	# Clear dropdowns
	self.getSibling('ScheduleTypeDropdown').props.value = 0
	
	# Clear entry fields
	self.getSibling('IntervalEntryField').props.value = 0
	self.getSibling('OffsetEntryField').props.value = 0
	
	# Clear labels
	self.getSibling('StatusLBL').props.text = ""
	

I have a button as well that is going to close the popup. Instead of copying and pasting that code I didnt know if I could just trigger it in a one liner.

Put a custom method on the highest level container that contains all your components and invoke it (ideally indirectly using messaging).

Strongly consider separating the UI update portions of your scripts from any "business logic" (put something in the DB, update X tags, etc), which should reside in functionally pure scripts in the project library.

2 Likes

You could also consider "lifting" this logic up to a custom method (defined on, let's say, the root window).

You could then invoke this "local" shared method from other components in your view.

4 Likes

Or, in the specific example you posted, just broadcast a "clear" message and have each component implement a handler that clears itself. Then you can add and remove components more easily.

1 Like

Ok thanks

I like this way. How do you call one of these custom methods ??

There is some guidance here on Perspective Custom Methods (there are matching constructs in Vision too, fwiw).

A basic example is shown below (and pictures are nice, so... :grin:):

2 Likes

Beautiful. Happy Monday

Hi, insuppose you can implement a msgHandlaer tomdo that.

@Welcome back, @cesma2000. Is this a question, a comment, an answer or gobbledygook? There's an edit button (pencil icon) below your post to clean it up.

1 Like