Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clipboard read_value_finish #59

Open
gummybears opened this issue Oct 27, 2023 · 5 comments · Fixed by hugopl/gi-crystal#157
Open

Clipboard read_value_finish #59

gummybears opened this issue Oct 27, 2023 · 5 comments · Fixed by hugopl/gi-crystal#157
Labels
bug Something isn't working

Comments

@gummybears
Copy link

gummybears commented Oct 27, 2023

I am working on a Gtk4 Clipboard example and need to call the method clipboard.read_value_finish

  @[GObject::Virtual]
  def activate
    ui  = get_ui()
    builder     = Gtk::Builder.new_from_string(ui, ui.bytesize.to_i64)
    window      = Gtk::Window.cast(builder["window"])
    text_entry  = Gtk::Entry.cast(builder["source_text"])
    text_entry.changed_signal.connect do
      text_entry_changed(text_entry)
    end

    source_file    = Gtk::Button.cast(builder["source_file"])
    copy_button  = Gtk::Button.cast(builder["copy_button"])
    paste_button = Gtk::Button.cast(builder["paste_button"])
    combobox     = Gtk::DropDown.cast(builder["source_chooser"])
    source_stack = Gtk::Stack.cast(builder["source_stack"])
    dest_stack     = Gtk::Stack.cast(builder["dest_stack"])

    source_clipboard   = source_stack.clipboard
    visible_child_name = ""

    copy_button.clicked_signal.connect do
      visible_child      = source_stack.visible_child
      visible_child_name = source_stack.visible_child_name
      case visible_child_name
        when "Text"

          text = visible_child.as(Gtk::Editable).text
          source_clipboard.set(text)
        when "Color"
        when "Image"
        when "File"
      end
    end

    paste_button.clicked_signal.connect do
      dest_clipboard = dest_stack.clipboard
      case visible_child_name
        when "Text"
          result = Gio::AsyncResult.new # ?????
          value  = source_clipboard.read_value_finish(result)
          if value
            dest_stack.set_visible_child_name = "Text"
            child = dest_stack.visible_child
            child.as(Gtk::Label).text = value
          end
      end
    end

    window.application = self
    window.present
  end

Problem I have is that the argument result has to be of type Gio::AsyncResult which is a module

Platform
Linux 21
Crystal 1.9.2 [1908c816f] (2023-07-19)
libgtk-4-1

@hugopl
Copy link
Owner

hugopl commented Nov 2, 2023

for each module there's a Abstract<modulename> class, e.g. Gio::AbstractAsyncResult, but they exist to be used as return value for GTK functions that returns interfaces (i.e. Crystal modules).

Anyway, I didn't work to have these GTK async APIs "crystalized" yet because when I needed them I just used the non-async versions, that depending on the use case may not affect the application.

@hugopl hugopl added the bug Something isn't working label Nov 2, 2023
@gummybears
Copy link
Author

I found Gio::SimpleAsyncResult, see what happens.

If you are interested, the GTK4 demo repo I am working on is located at https://github.com/gummybears/gtk4_with_crystal

PS I am using version 0.15 of your shard.

@hugopl
Copy link
Owner

hugopl commented Nov 3, 2023

I think will be useful to link this tutorial on this shard README and on gi-crystal README as well.

@gummybears
Copy link
Author

The repo https://github.com/gummybears/gtk4_with_crystal is public, work in progress so caveat emptor but you are more than welcome to include it in your README.

@hugopl
Copy link
Owner

hugopl commented Jul 11, 2024

The PR above add support for _async functions, however a lot of _finish functions uses out parameters and out parameters still not fully implemented in GICrystal... I think now I must deserve some attention to they... anyway, monkey patch a function with out parameters is much easier than monkey patch a function that receives a callback, so I believe this patch will make things easier...

As usual I'll test it with Tijolo for few days before merging it...

hugopl added a commit to hugopl/gi-crystal that referenced this issue Jul 11, 2024
BigBoyBarney pushed a commit to BigBoyBarney/gi-crystal that referenced this issue Dec 27, 2024
BigBoyBarney pushed a commit to BigBoyBarney/gi-crystal that referenced this issue Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants