Re: GTK3 DND-Function don't except files

ulli bei Unity <[email protected]> Mon, 30 Sep 2019 11:10:56 +0200
Newsgroups gmane.comp.lang.ruby.general
Message-ID <[email protected]>
Hi,

enclosed  the snippet. I use ruby-gtk3 3.2.4-1 now.
With ruby-gtk3 2.2.5 all files would be accepted (pdf,txt, images).
Now only  url from browser.

Regards
UH

#---------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/env ruby


require "gtk3"
require "pry"


def create_drop_space cb
     cb.drag_dest_set( Gtk::DestDefaults::ALL, [['text/plain', 0, 0]], 
Gdk::DragAction::COPY)
     cb.signal_connect('drag_data_received') do |w, context, x, y, data, 
info, time|
         #Encoding.default_internal
         type=data.text[0..4]                # what is dropped ?
         path=data.text[0..data.text.length] # length of dropped
         p "i got it"
         save_dnd_data data
     end

end

# in the db and update the pathtree
def save_dnd_data data
     type=data.text[0..4]                # what is dropped ?
     path=data.text[0..data.text.length] # length of dropped
     case type
     when 'file:'
         p 'file'

     when 'https'
         p 'https'

     when 'http:'
            p 'http:'
     end

end


window = Gtk::Window.new("Gtk::ComboBox sample")
window.signal_connect("destroy") {Gtk.main_quit}

#
# Text only
#
@combo1 = Gtk::ComboBoxText.new()  #(:entry => true)
["foo", "bar", "fuga", "hoge"].each do |val|
   @combo1.append_text(val)
end
@combo1.active = 1

@combo1.signal_connect("changed") do
  # p "combo1: #{@combo1.active}, #{@combo1.active_iter[0]}"
#    @combo1.active = 1
   @combo1 = Gtk::ComboBoxText.new
     ["moon", "mars"].each do |val|
   @combo1.append_text(val)
end
     @combo1.active = 0
     @combo1.remove_all
end

button = Gtk::Button.new(:label => "close")
button.signal_connect("clicked") do
   @combo1.remove_all
   #Gtk.main_quit
end


# Show main window
  create_drop_space(@combo1)
vbox = Gtk::Box.new(:vertical)
vbox.add(@combo1)
vbox.add(button)
window.add(vbox).show_all

Gtk.main

#---------------------------------------------------------------------------------------------------------------------------




Am 29.09.19 um 00:41 schrieb Sutou Kouhei:
> Hi,
>
> Could you show runnable script instead of snippet?
>
>
> Thanks,
> --
> kou
>
> In <[email protected]>
>    "GTK3 DND-Function don't except files" on Sat, 28 Sep 2019 08:58:21 +0200,
>    ulli bei Unity <[email protected]> wrote:
>
>> Hi,
>>
>> up to now I worked with the following dnd function. It worked very
>> well, I could drop files and http-adresses from browser.
>>
>> Now I changed to Linux mint 19.2, dnd with files will not work
>> anymore.
>>
>> Unfortunately the dnd function aren't well described.
>>
>> UH
>>
>>
>> def create_drop_space cb
>>      cb.drag_dest_set( Gtk::DestDefaults::ALL, [['text/plain', 0, 0]],
>> Gdk::DragAction::COPY)
>>      cb.signal_connect('drag_data_received') do |w, context, x, y,
>> data, info, time|
>>          #Encoding.default_internal
>>          type=data.text[0..4]                # what is dropped ?
>>          path=data.text[0..data.text.length] # length of dropped
>>          aS=data.data
>>          kwords=cb.active_iter[0].split(',')
>>          save_dnd_data data, kwords
>>      end
>>
>> end
>>
> Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>


Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>