Prevent GtkTreeRow from being selected when toggleButton is clicked - events

I use a Gtk Cell Renderer Toggle inside a treeView. When I click on the toggle button, the row where the toggle button is placed gets selected. I want to prevent this behaviour. I tried it by returning FALSE when the toggled signal is fired, so the event shouldn't be propageted through the parent widgets of the checkbox (the row, the treeView)...but it didn't work.
I want to keep selection feature enabled, so disabling this feature is not a solution
Here is how I did it:
renderer = gtk_cell_renderer_toggle_new();;
g_signal_connect (G_OBJECT(renderer), "toggled", (GCallback)(update_result_list_model), NULL);
And here is the callback, and it doesn't stop event propagation:
extern "C" gboolean update_result_list_model(GtkCellRendererToggle *cell,
gchar *path_str,
gpointer data)
{
// Do some job....
return false;
}
Thanks

Finally, I got it by using a boolean flag that I called "selectingCheckbox". Initially I set it to FALSE. On toggled signal callback I set it to TRUE. On row selection callback (not in toggled signal callback), I check the value of this flag. If the flag is FALSE, i let the row being selected by returning true. If the flag is true, I don't let the row being selected by returning false, and I set the flag to false

Related

Validation in a Datagridview

I have an application with a datagrid view
This datagrid is filled by code, not binded to a datasource.
All cells are editable
when a user edits a value in a cell, then i need to perform an action
Private Sub dgView_CellValidated(sender As Object, e As DataGridViewCellEventArgs)
Handles dgView.CellValidated
Dim nColumnIndex As Integer
DIm nRowIndex as Integer
If sender.iscurrentRowDirty Then
nRowIndex = e.RowIndex
nColumnIndex = e.ColumnIndex
Call UpdateRowData(nRowIndex, nColumnIndex)
End If
End Sub
The Function UpdateRowData is called when user edits en then leave the cell, but if he goes to a cell in the same row. Then this routine will be called again when the user again goes to another cell without any editing
I want this function only called once
How are you going to know if the cell’s value had “actually” changed from its original value? And what is this “action” that is taken if the cell “was” changed? Is what I am getting at… is that it is unclear “what” this “action” is doing? If it is an extensive process that may take some time and you want to avoid this “action” if the cells value doesn’t “actually” change. Then you will need to know if a cells value actually DID change. And this will require a different event and some additional code implementation on your part.
On the other hand, if the “action” is simply to update something with the new value, then it may take MORE execution steps to actually “check” if the value has changed as opposed to simply overwriting the same values. So, if the “action” is trivial, I wouldn’t bother “checking” if the values have changed.
However, if you DID need to make sure that the user “actually” did change the cells value… Then below is a crude, yet simple, solution for this.
One possible issue is if the user clicked into a cell and edited it by “actually” typing some characters, but, after the user finishes typing characters they had ended up simply re-typing what the original value was… then “technically” from the grids perspective… THAT cells value DID change. In other words, We will need to somehow get the original value of the cell “BEFORE” the user starts to edit the cell. Then we could “compare” the new value with the original value when the user tries to leave the cell.
Fortunately, there is a grid event that should make this fairly trivial to implement. The event I suggest using is the grids CurrentCellDirtyStateChanged event. This event will actually fire TWICE. The event will fire once when the cell goes into “edit” mode. And it will fire again when the user ends the same cells edit mode.
Therefore, we can take advantage of this, however, we will need to know that WHEN the event fires… is it fired when the user “enters” the cells edit mode… OR … is the event fired because the user is “ending” the cells edit mode. I do not think the event keeps track of this internally so we need to create our own “mechanism” to be able to distinguish when the event is fired on the “begin” edit and the “end” edit.
One possible solution to make this work is to create two global variables… one a bool variable called FirstIn and a string variable called OriginalValue… When the event fires the first time to “begin” the cells edit mode, we can check the FirstIn variable. If it is true then we know the cell is “beginning” the edit of the cell… this is where we would capture the cells current value and set the OrignalValue string variable so we can “check” it against the final cells value when the user ends the cells edit mode.
Capturing the current cells value and setting FirstIn to false is all we need to do. We now wait until the user ends the cells edit mode and the event fires for the second time. When it fires the second time… again we check the FirstIn variable and in this case it is false which means the cells is ending its edit mode. Here we could check the OriginalValue with the cells current value and do your “action” if they are different. And finally setting FirstIn to true to start the whole process over.
Below is an example of what is described above.
bool FirstIn = true;
string OriginalValue;
private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e) {
if (FirstIn) {
FirstIn = false;
OriginalValue = dataGridView1.CurrentCell.Value.ToString();
}
else {
string NewValue = dataGridView1.CurrentCell.Value.ToString();
FirstIn = true;
if (OriginalValue.Equals(NewValue)) {
MessageBox.Show("NO changes were made in the cell edit");
}
else {
MessageBox.Show("YES changes were made in the cell edit");
}
}
}
Sorry but I wrote this in C#, below is a VB version.
Dim FirstIn As Boolean = True
Dim OriginalValue As String
Private Sub DataGridView1_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged
If (FirstIn) Then
FirstIn = False
OriginalValue = DataGridView1.CurrentCell.Value.ToString()
Else
Dim NewValue As String = DataGridView1.CurrentCell.Value.ToString()
FirstIn = True
If (OriginalValue.Equals(NewValue)) Then
MessageBox.Show("NO changes were made in the cell edit")
Else
MessageBox.Show("YES changes were made in the cell edit")
End If
End If
End Sub

Create and coding animator script with Unity

i have a three animation state and two bool parameters.
I want to circle of that.
The entry state "BeklemeAtakYap" there is in nothing animation.
Firstly, i set bool "Bekle" true, "Saldir" false.
The animation starting "Bekleme" state.
I am setting on the script "Bekle" false and "Saldir" true.
Animation contiunning "Saldir" state.
And i make a translation "Saldir" and "BeklemeAtakYap".
When the "Saldir" state end and the "BeklemeAtakYap" starting, i want the bool parameters "Bekle" true "Saldir" false how can do that?
You can add an AnimationEvent at the end of Saldir state.
just right click on the top of the timeline just below times and select add AnimationEvent.
Then write a function in a script which is attached to the AnimationController and assign it to the AnimationEvent. In that function you can manually set animation parameters.
GetComponent<Animator>().SetBool("Saldir", false);
By the way please use English words in your question for better readability.
I click "BeklemeAtakYap" state and click the Add Behavior-> Add Script.
Open the script and write;
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
animator.SetBool ("Saldir", false);
animator.SetBool ("Bekle", true);
}
That's work.

I have 3 buttons that can be in either clicked or not-clicked state. How do I keep state that signals if ANY of them are clicked?

This is more of algorithms question. I have 3 buttons:
button1 button2 button3
They can each be in clicked or not-clicked state. When the first is clicked, it goes into clicked state, but if I click it again, it goes back into non-clicked state.
I want to keep a global variable that answers if ANY of the buttons is clicked.
Knowing when to set global variable to clicked is pretty easy:
When I click button1 I can set variable clicked to true.
When I click button2 I can set variable clicked to true.
When I click button3 I can set variable clicked to true.
Now the difficult part is to set global variable to non-clicked:
When I click button1 again it becomes non-clicked, but button2 or button3 can be still clicked, so I can't just set variable to non-clicked.
When I click button2 again it becomes non-clicked, but button1 or button3 can be still clicked, so I can't just set variable to non-clicked.
When I click button3 again it becomes non-clicked, but button1 or button2 can be still clicked, so I can't just set variable to non-clicked.
It's difficult to keep state of non-clicked global status of all buttons.
Any ideas how to solve this problem? Should I somehow use xor? Or some other logical operation?
Set and clear a different bit in the word per button. That way if the word is non-zero, one or more of the buttons is pressed, and you can detect which one(s) by examining the bits.
Hard to see the point.
I figured out answer to my own question.
The answer is to keep global variable with value 0 in it:
int button_counter = 0;
When any button is clicked the following operation is performed:
button_counter = button_counter + 1;
When any button is unclicked the following operation is performed:
button_counter = button_counter - 1;
Now if value of button_counter is 0, then all buttons are unclicked.
If value of button_counter is 1, 2 or 3, then either one, two or three buttons are clicked and they are not all unclicked.
Here's how to check if they're all unclicked:
if (button_counter == 0) {
// all buttons are unclicked
}
else {
// at least 1 button is clicked
}
Thank you all for help!

LiveCycle drop-down list change event only works on second change

I want a Text Field to appear when a certain item is chosen from a drop-down list. I'm using a change event.
if(this.rawValue == 1){
Tolerance.presence = "visible";
}
else{
Tolerance.presence = "hidden";
}
The problem is that the Text Field presence does not change immediately when a selection is made, but only after I go back to the list box and select again (any value, not just the same one).
The new value of the dropdown only registers after the change event. This means this.rawValue points to the old value of the dropdown in a change event.
Either move your script dropdown exit event or make use of the event.newText in the if conditional in the change event.

How do I prevent jqGrid from restoring the row after saving

I have a jqGrid in inline editing mode. When the user hits Enter, the record is sent to the server to save. The server returns a success:true or false which I handle in successFunc as follows:
function successFunc(data) {
d = jQuery.parseJSON(data.responseText);
if (!d.success) { alert(d.message); }
return d.success;
}
What I would like is that when d.success is false, the jqGrid should remain in edit mode and not restore. I tried adding a throw "exit" call after the alert. It works, but the Esc and Enter keys do not work any longer.
Is there any way to prevent jqGrid from restoring the row after save?
Thanks
The call to saveRow supports an afterrestorefunc callback:
afterrestorefunc if defined, this function is called in restoreRow (in case the row is not saved with success) method after restoring the row. To this function we pass the rowid
So you could let the grid call restoreRow and then in your callback you can call editRow to force the grid back in to edit mode. Not an ideal solution, but the transition will happen so fast the user probably will not notice.

Resources