Detect what button is pressed - flutter

Suppose there are several buttons created programmatically, and there is a common button handler.
onButtonClicked(){
// print button attribute
}
How to understand inside the handler which button is pressed?
WITHOUT passing something special inside the function call. That won't do:
onButtonClicked("button" + i);
In JavaScript, for example, inside the handler, there is $(this), which immediately "understands" which button is pressed.
Maybe there is a similar mechanism in Flutter? I want to hang attributes on the button (without knowing which ones in advance), and then have access to them in the handler.

I think there is only one way to write the print('your function name') inside your function

Just pass the Parameter inside your method.
for example:-
onButtonClicked(Parameter){
// print button attribute
print("${parameter}");
}
And pass different parameter for different buttons.

Related

Is there a way to capture the key being pressed in a 'key_press_event'?

I am trying to build a basic interface using pyGTK, where based on the key being pressed, I evoke different functions.
I understand that using the 'connect' method, I can capture events such as a keypress or a click, like so:
self.btn1.connect("clicked", self.funcRec)
self.btn1.connect("key_press_event", self.funcRec)
Doing this will call the funcRec function when there is a key press event, or when the button is being clicked.
But I am not able to find a way to capture the actual key being pressed and trigger different functions. Is there a way to do this?
I found a way. I used a function that captures the event and gets the value of the key press event.
First you 'connect' and get the 'key_press_event' and trigger a callback function
self.connect("key-press-event", self.on_key_down)
where 'on_key_down' callback function is defined as,
def on_key_down(self, widget, event):
key = event.keyval
if key == gtk.keysyms.Right:
self.onRightPress(self, widget)
if key == gtk.keysyms.Left:
self.onRightPress(self, widget)

Get state of MATLAB GUI radiobuttons?

I have two radio buttons in my interface. I also have some pushbuttons. When ever I click a pushbutton I want it to call a function according to the selected radio button.
I tried adding the function given below
function rotation_SelectionChangeFcn(hObject, eventdata, handles)]
Tag = get(hObject, 'Tag');
disp(Tag);
But nothing is coming up when I change the selection. I want to know whether there is any mistake in the way I implemented the code or is there a better way of doing this?
Whenever you use radiobuttons you might want to regroup them in button groups, then it's quite easy to play with radio buttons, and you make sure that only 1 radio button per group gets selected at any time.
For radio buttons in button groups, you want to use the following:
get(eventdata.NewValue,'Tag')
to get the tag of the new value just being selected. You can also use OldValue as well if you want.
In the callback of your pushbutton, you can query whether a radio button is activated with its 'value', i.e. 1 if it is selected.
StateRadioButton = get(handles.RadioButton1,'Value'); %assuming the tag is "RadioButton1".
The hObject property is particular for the specific callback in which it is used, otherwise you need to use the handles structure to access elements from other functions.

TinyMCE capture click button event

is it possible in TinyMCE to know which button was clicked? so I could place specific action on specific event of a specific button.
the buttons here are default control-buttons like bold/italic/select-font not a custom button one.
probably in the init, but I have no idea what to call. I could capture the editor's events but not the button's.
For example, let's say I want a messagebox popped-up everytime bold button is clicked. How to capture the click event of bold button? is creating custom button the only way?
No, you can define an own command and call this command (+ the defualt action) on buttonklick. I do not know if you want a generic way for all buttons. But it is easy to do it just for one or two buttons.
Example: We want to put an action on the bold button.
First we define an own command in one of our own plugins (in the "init : function(ed, url)" -section):
ed.addCommand('my_bold', this.my_bold, this); //calls the function my_bold
Then we overwrite the default action with an the command:
if (ed.controlManager.get('bold')){
ed.controlManager.get('bold').settings.cmd='my_bold_action';
};
Now, we only need to define the function my bold
my_bold: function() {
// exectution of regular command
this.editor.execCommand('Bold');
// now do whatever you like here
...
},
ed.controlManager must be called in "onInit" methode :
ed.onInit.add(function(editor) {
.......
........
if (editor.controlManager.get('bold')){
editor.controlManager.get('bold').settings.cmd='my_bold_action';
};
});

Gtk object, name, type and so

I Created a window and vbox with 3 buttons in Glade. All buttons have connected "Clicked" event to same handler. Handler looks like this:
CLICKED_btn(GtkObject *object, gpointer user_data)
{
g_print("CLICKED\n");
}
CLICKED appears on terminal for any click to any button.
Is here a way, through object or other to know which button invokes event Clicked in case where all buttons uses same handler?
The object parameter refers to the object that generates the event, in your case the button. Then you can use gtk_widget_get_name() or any other GtkObject/GtkWidget/GtkButton function to make a difference.
UPDATE:
As it seems, newer versions of GTK/Glade do not set the name of the widgets to their id, so it is left to the default, that is the name of the type. In order to get the id of the object you can use the function gtk_buildable_get_name() that works with any buildable object.
With that you'll get button1, button2 or whatever name you put to these buttons.
Please, do not use the label to make a difference between the buttons. Yes, it works, but it is a bad habit: hard to maintain, bad with internationalization, and defeats the main purpose of Glade: to have the interface and the code separated.
First use the documentation to have the right prototype for the "clicked" signal of a GtkButton.
You then know that your callback's prototype should look like:
void on_button_cliked (GtkButton *button, gpointer user_data)
The button parameter is the object which received the signal, ie. the button on which you clicked.

JQgrid:Get the action from the pager

how can i get the action (what button was clicked) when a button is clicked in the pager?(edit, del, add...)
You probably means button of the navigation bar or navigator (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator).
You can implement what you want with at least three different ways:
You define your custom buttons which look like the original add/edit/del buttons (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_buttons) and use {add:false, edit: false, del: off} parameter of navGrid to switch off standard buttons.
You can use addfunc, editfunc and delfunc if you want replace the default add/edit/del functions.
You can use onclickSubmit or afterSubmit or some another supported events (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:form_editing#events) of add/edit/del button to do some additional action on click the buttont or on submit.
You can chose the way which is the best for your requirements.
You can use the grid onPaging event:
This event fires after click on [page
button] and before populating the
data. Also works when the user enters
a new page number in the page input
box (and presses [Enter]) and when the
number of requested records is changed
via the select box. To this event we
pass only one parameter pgButton
(string) which can be -
first,last,prev,next in case of button
click, records in case when a number
of requested rows is changed and user
when the user change the number of the
requested page.requested page.
Also there are beforeRequest and LoadComplete events. Examples that worked for me are as follows:
beforeRequest: function () {
$.blockUI();
//alert("before request");
},
loadComplete: function () {
//alert("load complete");
$.unblockUI();
}