I'm testing some signals with GTK+ 2.0. I'm looking for a way to get a signal emitted when I click on a GtkEntry.
if (widgets_info[i].action & IG_INPUT)
{
widget->frame[i] = gtk_entry_new_with_max_length(MAX_INPUT_LENGTH);
gtk_entry_set_text(widget->frame[i], widgets_info[i].text);
catch_signal(widget->frame[i], MY_SIGNAL, &change_entry, widget);
}
I have a pre-selected text in my entry (widgets_info[i].text) and i want this text to disappear if the user click on my GtkEntry.
Does someone know what is this signal?
(Sorry for my English)
Try focus-in-event, note that you must enable focus-tracking as described in the documentation.
The button-press-event signal should do what you need:
http://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-button-press-event
However, in GTK+ 3, GtkEntry now supports this idea of placeholder text, so you don't need to implement it yourself:
http://developer.gnome.org/gtk3/stable/GtkEntry.html#gtk-entry-set-placeholder-text
Related
GTK+ version: 3.18.9
I created a drawing area (GtkWidget) with following code
content = gtk_drawing_area_new();
gtk_widget_set_can_focus(content, TRUE);
gtk_widget_add_events(content, GDK_ALL_EVENTS_MASK);
g_signal_connect(content, "draw", G_CALLBACK(&drawCallback), ctx);
gtk_widget_realize(content);
// Add a filter for interception
gdk_window_add_filter(content, gtk_widget_get_window(content),
OnXEvent, NULL);
Problem is that when I clicked the wideget, I got sequence of XEvents as follows:
LeaveNotify
FocusIn
EnterNotify
ButtonPress
FocusOut // Lost focus!
ButtonRelease
Above FocusOut indicated we lost focus right away after clicking.
It implies we can't receive any keyboard events since they are available only within focus.
Is this limitation of GTK? If not, is there any tools/methodlogy to find out which widget/widow trigger the FocusOut?
References:
gdk_window_add_filter
As of GTK+ version 3.18.9, it uses an extra X window for toplevel window and any keyboard events are captured by the window. Thus a filter need to be added as a global one, i.e.
gdk_window_add_filter(NULL, OnXEvent, NULL)
Note that the API was removed in this commit in GTK+ 4.x.
Using WAA (Web Audio Api) I am using exponentialRampToValueAtTime to create a fade in and out that can be cancelled for the user pressing the "stop" button.
The stops function looks something like this:
this._gainNode.gain.cancelAndHoldAtTime(this._AudioContext.currentTime);
this._gainNode.gain.exponentialRampToValueAtTime(0.000001, this._AudioContext.currentTime + fadeDuration);
The complete function is wrapped in a Promise because I need to do something else after the stop (fadeDuration);
The problem is that in some browsers cancelAndHoldAtTime does not exit and I get some nasty clips that I do not know how to prevent. The same happens with cancelValuesAndHoldAtTime that is even less supported.
I tried with cancelScheduledValues but it does not help.
Is there a workaround or correct alternative to cancelAndHoldAtTime
You can do an approximation by calling setValueAtTime(v, t) where t is the context time at which the user pressed the stop button and v is the estimated value of the exponential at time t.
You'll probably still get a glitch, but it will probably be much better than using just cancelScheduledValues.
This is the reason why cancelAndHoldAtTime was added to the API.
Although maybe the best alternative for cancelAndHoldAtTime is the one recommended for Raymond Toy, to completely remove the clip and any glitches what I ended up doing was making a "Main Gain" between the oscillator Gain and the destination
OSC -> oscGain -> mainGain -> speakers.
Before I do anything I close the mainGain and then cancelScheduledValues and all the other stuff to the oscGain
I hope someone is able to help me with this.
Ableton Live when you set a clip's launch mode to gate, it only plays when you hold down the key. I'm using a patch that takes an OSC message to launch the clip, but it will not work as a gate - it needs to have the stop all clips message, and this won't help in my situation.
I need to "call fire" when 1 and "call stop all clips" when 0, but I'm not sure how to do this.
Can anyone help me with which object I should use? I've looked at various gates and swtiches, but I'm missing something.
Thanks.
Create a new object and type "togedge" or "select" (or its shorthand "sel"). Both of them will have 2 outputs: One for 0, one for not 0.
"togedge" will only output if the input changes.
"sel" will always output, and you can enter different numbers to match your input directly (like "sel 34 56").
Btw you can also use "call stop" on the clip_slot object directly instead of "stop_all_clips" on the track object.
After fiddling with the sel object, I discovered this: I needed to change the live.text object used to launch the clip from button to toggle.
In my Text Editor application, I save the users font format selection as a preference.
Signals and slots are first set up in the constructor, and then the preferences are read as in the code below:
Constructor:
boldAction->setCheckable(true);
italicAction->setCheckable(true);
underlineAction->setCheckable(true);
fontSizeSelector->setCheckable(false);
connect(boldAction,SIGNAL(changed()),this,SLOT(bold()));
connect(italicAction,SIGNAL(triggered()),this,SLOT(italic()));
connect(underlineAction,SIGNAL(triggered()),this,SLOT(underline()));
ReadUserPreferences():
void TextEditor::readUserPreferences()
{
QSettings userPreferences(QSettings::NativeFormat,QSettings::UserScope,ORGANIZATION_TITLE,APPLICATION_TITLE);
this->boldAction->setChecked( userPreferences.value("appearance/bold").toBool() );
this->italicAction->setChecked( userPreferences.value("appearance/italic").toBool() );
this->underlineAction->setChecked( userPreferences.value("appearance/underline").toBool());
//other code.
}
Now, in the readPreferences function, when boldAction->setChecked(true);, shouldn't the text become bold because the signal and slot mechanism has already been defined? If so, then why isn't it working on my application? The bold function itself works perfectly fine.
Is there a better way of doing this than what I'm doing? Thanks for your help
There appear to be two things wrong here.
Firstly, you are connecting to the wrong signals. The changed signal does not pass a value indicating the action's checked state, and triggered is not emitted at all when setChecked is called. You need to connect to the toggled signal.
Secondly, the signal will only be emitted if the checked state has changed. So if the action is already checked and the user preference evaluates to true, nothing will happen. You probably need to take steps to ensure the appropriate default state is set before connecting the signals.
I'm using Glade-3 for my GUI design, but I keep hitting this problem. I don't see anything in the GTK+ documentation mapping signals to events or in Glade-3 (3.4.5). Is there a place in the GTK+ source code to find this information?
Note: It is important in this question to recognize that events and signals are NOT the same thing in GTK.
Example:
I have an eventbox that requires the following events in order to receive the following signals. How do I determine what events are required by a given signal?
Events: GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK
Signals: leave_notify_event, enter_notify_event
Ok, I think I know what you mean now, I found this table matching up the gtk signals and gdk events. Here it is.
Assuming that I have interpreted your question correctly you are wanting to connect the signals you specified in the Glade file to the functions in the source code. How you do this depends if you are using libglade to load the files generate or GtkBuilder, both are similar but I will give samples in C just to be complete.
Using libglade you would do it like so:
GladeXml *xml = glade_xml_new(filename, NULL, NULL); // Load the file
glade_xml_signal_autoconnect(xml); // Connect the signals
Using GtkBuilder it would be like this:
GtkBuilder *xml = gtk_builder_new();
gtk_builder_add_from_file(xml, filename, NULL); // Load the file
gtk_builder_connect_signals(xml, NULL); // Connect the signals
When using GtkBuilder the second parameter in signal connect function can be replaced with a pointer to data which will then be passed to the signal handlers.
Going forward I would suggest using GtkBuilder as libglade is on its way to being deprecated.
Links
Here are the links to the relevent documentation about the two functions mentioned above
http://library.gnome.org/devel/libglade/stable/GladeXML.html#glade-xml-signal-autoconnect
http://library.gnome.org/devel/gtk/stable/GtkBuilder.html#gtk-builder-connect-signals
You can capture the events with gdk_event_handler_set()
First register your own GDK event handler on startup:
gdk_event_handler_set(my_gdk_event_handler, NULL, NULL);
... Then use it to print out any useful information, and don't forget to pass the event to GTK+ through gtk_main_do_event() like here:
void my_gdk_event_handler(GdkEvent *event, gpointer data)
{
printf("Received GdkEvent of type %d", event->type);
gtk_main_do_event(event); // Pass event to GTK+
}