I'm new to Gnome development.
I am trying do create a button which, when pressed, will copy the content of its label to the clipboard and closes the app.
This is my code, where "self" is a class that extends Gtk.Window.
If I don't close the app, it works just fine.
Thank you
def copy_and_quit(self, button: Gtk.Button):
clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clip.set_text(button.get_label(), -1)
self.close()
Edit: I am a noob in Gtk development. I re-factorized my app to be a Gtk.Application with a Gtk.Window, following this example.
Now I do
def copy_and_quit(self, button: Gtk.Button):
clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clip.set_text(button.get_label(), -1)
Gtk.main_quit()
Which works.
Bye
By default, the clipboard content is stored in the app and is only copied to another app when you paste. This means when the program exits, the clipboard content is no longer available.
gtk_clipboard_store() stores the clipboard content outside the application to avoid this problem. GtkApplication calls it automatically when it shuts down, but if you're not using GtkApplication you need to call it manually.