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
on 2011-04-15 00:58
on 2011-04-15 03:00
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
on 2011-04-15 03:40
Mike Charlton 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
on 2011-04-19 22:32
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.
on 2011-04-19 23:06
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
on 2011-04-19 23:22
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.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.