You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by danirod July 4, 2024
Hello there. I am looking for suggestions in regards to using the class methods for the GtkWidget class. In gtk-rs, these methods are part of the WidgetClassExt, but I can't get my head around how to get access to those methods. In my case, the goal is to have access to the add_shortcut method (docs.rs, GTK) so that I can install shortcuts into every instance of a specific widget.
I am writing a GTK 4 application and while GNU/Linux is the preferred platform, I am doing my best to make sure that the application looks and works right in Windows and macOS too. In GTK 4, the <Primary> keyboard modifier is bound to the Control key even on macOS, where most users would expect the <Meta> modifier. This means that, by default, the shortcuts for built-in actions like copy and paste from a text field are Ctrl-C and Ctrl-V rather than Cmd-C and Cmd-V, unless the application changes them.
In this specific example, Gaphor is using the following Python code to change the shortcuts of the selection.select-all action part of the Gtk.TextView widget class, so that every instance of Gtk.TextView uses the new shortcut (the code is actually more complex becuase they are using a function to encapsulate building the shortcut):
One of the benefits of the GObject introspection is that it is very easy to translate code from between languages. However, even if I suspect it cannot be that difficult, I can't call the add_shortcut function because I don't know how to get a code path to that method.
If this was a custom widget, I could just use the class_init function when implementing ObjectSubclass for my widget, because I have a Class parameter, but when I try to apply it to the GtkText and GtkTextView widgets like the code I show above, I am not having any luck.
For C and Python, the function calls are more obvious (gtk_widget_class_add_shortcut and Gtk.TextView.add_shortcut), but in Rust it is being a challenge. I don't know if I am supposed to just use gtk::TextView::add_shortcut() and make sure that I am using the WidgetClassExt trait in my file (on a first try, doesn't seem to work), or if I have to use a function to get the class first. I've played with the following, but it doesn't compile.
I've checked the source code for other programs written in gtk-rs to see if I can learn something from them, but it seems that none of them has had the need to use this function so far.
Any advice? Thanks in advance.
The text was updated successfully, but these errors were encountered:
Discussed in #1790
Originally posted by danirod July 4, 2024
Hello there. I am looking for suggestions in regards to using the class methods for the GtkWidget class. In gtk-rs, these methods are part of the WidgetClassExt, but I can't get my head around how to get access to those methods. In my case, the goal is to have access to the
add_shortcut
method (docs.rs, GTK) so that I can install shortcuts into every instance of a specific widget.I am writing a GTK 4 application and while GNU/Linux is the preferred platform, I am doing my best to make sure that the application looks and works right in Windows and macOS too. In GTK 4, the
<Primary>
keyboard modifier is bound to the Control key even on macOS, where most users would expect the<Meta>
modifier. This means that, by default, the shortcuts for built-in actions like copy and paste from a text field areCtrl-C
andCtrl-V
rather thanCmd-C
andCmd-V
, unless the application changes them.In this specific example, Gaphor is using the following Python code to change the shortcuts of the selection.select-all action part of the Gtk.TextView widget class, so that every instance of Gtk.TextView uses the new shortcut (the code is actually more complex becuase they are using a function to encapsulate building the shortcut):
One of the benefits of the GObject introspection is that it is very easy to translate code from between languages. However, even if I suspect it cannot be that difficult, I can't call the
add_shortcut
function because I don't know how to get a code path to that method.If this was a custom widget, I could just use the
class_init
function when implementingObjectSubclass
for my widget, because I have a Class parameter, but when I try to apply it to the GtkText and GtkTextView widgets like the code I show above, I am not having any luck.For C and Python, the function calls are more obvious (
gtk_widget_class_add_shortcut
andGtk.TextView.add_shortcut
), but in Rust it is being a challenge. I don't know if I am supposed to just usegtk::TextView::add_shortcut()
and make sure that I am using the WidgetClassExt trait in my file (on a first try, doesn't seem to work), or if I have to use a function to get the class first. I've played with the following, but it doesn't compile.I've checked the source code for other programs written in gtk-rs to see if I can learn something from them, but it seems that none of them has had the need to use this function so far.
Any advice? Thanks in advance.
The text was updated successfully, but these errors were encountered: