# Gdk::DataSelection, array?

**URL:** <https://www.ruby-forum.com/t/gdk-dataselection-array/205760>\
**Category:** Ruby-Gnome 2\
**Created:** [April 15, 2011, 12:58am UTC](https://www.ruby-forum.com/t/gdk-dataselection-array/205760 "2011-04-15T00:58:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [April 15, 2011, 12:58am UTC](https://www.ruby-forum.com/t/gdk-dataselection-array/205760/1 "2011-04-15T00:58:09Z")

</div>

hi all,

a question about setting #DataSelection in a drag and drop… can i  
drag an array?

i’m making a music directory browser, and i’ve got a TreeView with a  
bunch of song titles in it set as a drag source. the TreeView is set  
for multiple selection.  
the thing is, i’m not interested in dragging the titles, but rather  
the full paths to the songs - so…  
i set up a hash, with the keys being the song titles, and the paths as  
the values. then, in the TreeView#signal\_connect(“drag\_data\_get”)  
block, i load all the song titles selected into an array, which is then  
passed through a block which treats each song title as a key, and passes  
the key’s value (the song’s path) into another array.  
what i’m trying to do is pass this array of paths into the  
Gdk::DataSelection associated with the “drag\_data\_get” block.  
sorry if my explanation hasn’t made too much sense - basically i just  
want to drag an array!  
here’s a look at what i’m working with:

#############

# (@view is my TreeView, @listselection is the TreeView#selection

```
@selarray = []
@hash = {}
@dragdata = []

```

Gtk::Drag.source\_set(@view, Gdk::Window::BUTTON1\_MASK,  
[[“text/plain”, 0, 0]],  
Gdk::DragContext::ACTION\_COPY|Gdk::DragContext::ACTION\_MOVE  
)

@view.signal\_connect(“drag\_data\_get”) {|w, c, data, i, t|  
@listselection.selected\_each{|m, path, iter| @selarray \<\< iter[0]}  
@selarray.collect{|entry| @dragdata \<\< @hash[entry]}  
data.set(Gdk::Selection::TYPE\_STRING, @dragdata.to\_s)  
}  
##############

this _works_, but returns a string of the array (obviously, as the  
last line would indicate,) and not the array itself. i’ve searched  
through the Gdk::Selection types, and the Gdk::DataSelection methods,  
but haven’t seen anything that lets me pass the array as an array rather  
than a string.

any ideas? is this just a ridiculous thing to do in the first place?

thanks -

-j

---

<div class="post-metadata">

**Author:** ![lljk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a9a28c/32.png) [@lljk](https://www.ruby-forum.com/u/lljk)\
**Post date:** [April 15, 2011, 3:00am UTC](https://www.ruby-forum.com/t/gdk-dataselection-array/205760/2 "2011-04-15T03:00:50Z")

</div>

One thing off the top of my head is that using the  
title of the song as a key isn’t going to work all  
the time. I have several songs with the same name  
(for some reason if you are Japanese you _have_ to write  
a song called “Rainbow” 😉

What I have done in the past is create a ListStore where the first  
column is the actual object that I want to select. The  
remaining columns contain the data I want. I don’t render  
the first column. When a row is selected, I take the object  
out from the first column of the ListStore.

Hope that helps!

```
     MikeC
```

---

<div class="post-metadata">

**Author:** ![lljk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a9a28c/32.png) [@lljk](https://www.ruby-forum.com/u/lljk)\
**Post date:** [April 19, 2011, 10:32pm UTC](https://www.ruby-forum.com/t/gdk-dataselection-array/205760/3 "2011-04-19T22:32:52Z")

</div>

Ok, I have a weird one this wasn’t a problem under Ruby 1.8.6. On our  
newest release I am playing with  
See the subject line, when ever I am closing down my Ruby GTK app, it  
get the following message

warning instance variable \_\_windows\_\_not initialized  
Segmentation fault(core dump)

First off, I am running on RHEL 5.4, with Ruby 1.9.2-p180, and  
ruby-gnome2-all\_0.90.5  
(I am stuck on 0.90.5 because this app has lots of canvas objects in it)

The stack trace of the ruby interpreter doesn’t help me much. I think it  
is in the garbage collection. I have a very similar non GTK app that  
oesn’t have an of this problems.

So there are tons of variables in this. I was just wondering if anyone  
had seen this message before

warning instance variable \_\_windows\_\_not initialized

I did a google on it and found some old references. Anyone have a clue  
as to what this could be?

Thanks  
\

This electronic communication and any attachments may contain  
confidential and proprietary  
information of DigitalGlobe, Inc. If you are not the intended recipient,  
or an agent or employee  
responsible for delivering this communication to the intended recipient,  
or if you have received  
this communication in error, please do not print, copy, retransmit,  
disseminate or  
otherwise use the information. Please indicate to the sender that you  
have received this  
communication in error, and delete the copy you received. DigitalGlobe  
reserves the  
right to monitor any electronic communication sent or received by its  
employees, agents  
or representatives.

---

<div class="post-metadata">

**Author:** ![lljk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a9a28c/32.png) [@lljk](https://www.ruby-forum.com/u/lljk)\
**Post date:** [April 19, 2011, 11:06pm UTC](https://www.ruby-forum.com/t/gdk-dataselection-array/205760/4 "2011-04-19T23:06:18Z")

</div>

Not everything works fine in the app, it seems to be just on shutdown.  
And it seems to have gotten through all my code. It happens after the  
Gtk::Main\_quit

-grant

---

<div class="post-metadata">

**Author:** ![lljk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a9a28c/32.png) [@lljk](https://www.ruby-forum.com/u/lljk)\
**Post date:** [April 15, 2011, 3:40am UTC](https://www.ruby-forum.com/t/gdk-dataselection-array/205760/5 "2011-04-15T03:40:34Z")

</div>

Mike C. wrote in post #992904:

> One thing off the top of my head is that using the  
> title of the song as a key isn’t going to work all  
> the time.

good point…

> What I have done in the past is create a ListStore where the first  
> column is the actual object that I want to select.

good idea…

> Hope that helps!

sure does… thanks for the idea - i’ll get crackin’ on it and see  
what i come up with.

thanks again,

-j

---

<div class="post-metadata">

**Author:** ![lljk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a9a28c/32.png) [@lljk](https://www.ruby-forum.com/u/lljk)\
**Post date:** [April 19, 2011, 11:22pm UTC](https://www.ruby-forum.com/t/gdk-dataselection-array/205760/6 "2011-04-19T23:22:59Z")

</div>

Oops I meant to say everything works fine in the app. Its just at  
shutdown. As usual, ask a problem and you end up figuring it out  
yourself. I was missing my calling destroy on a class that had a bunch  
of Gtk::Menu.new objects. With Gtk 0.95 it still had the bug where not  
calling destroy on this guy make it core dump.

Anyways, sorry to waste your bandwidth.
