Raj Sahae
2007-Mar-07 21:49 UTC
[fxruby-users] my button.connect(SEL_COMMAND) isn''t working
Is it because I''m also using the DND stuff for the same button? Does
the LEFBUTTONPRESS and LEFTBUTTONRELEASE mess up SEL_COMMAND?
def display(stack, requesting_player)
self.set_target(stack)
#set drag type, clear the viewer, prep the stack
remove_previous_images(@stackViewer)
cards = stack.cards.flatten
data_sent = false
#for each index in the flattened stack, open the file
cards.each do |card|
if card.commander == requesting_player or card.face_up?
filename= card.face
else
filename = card.back
end
until filename.length >= 4
filename = ''0'' + filename
end
file = File.open(filename, "rb")
#create the imageframe and icon from the file
imageView= FXButton.new(@stackViewer, nil, nil, nil, 0,
LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT|BUTTON_NORMAL, 0,0,
357, 497)
imageView.icon = FXJPGIcon.new(self.getApp(), file.read,
IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP)
imageView.tipText "Commanded By: #{card.commander}
Owned By: #{card.owner}
Status: #{card.status}
Stopped: #{card.stopped}"
imageView.buttonStyle = BUTTON_AUTOGRAY if card.stopped
#set DND for cards in viewer
imageView.connect(SEL_LEFTBUTTONPRESS) do
imageView.grab
dragTypes = [@image_drag_type]
imageView.beginDrag(dragTypes)
end
imageView.connect(SEL_MOTION) do |sender, sel, event|
if imageView.dragging?
imageView.handleDrag(event.root_x, event.root_y)
unless imageView.didAccept == DRAG_REJECT
imageView.dragCursor =
self.getApp().getDefaultCursor(DEF_DNDMOVE_CURSOR)
else
imageView.dragCursor =
self.getApp().getDefaultCursor(DEF_DNDSTOP_CURSOR)
end
end
end
imageView.connect(SEL_DND_REQUEST) do |sender, sel, event|
if event.target == @image_drag_type
imageView.setDNDData(FROM_DRAGNDROP, @image_drag_type,
Fox.fxencodeStringData(YAML.dump(card)))
data_sent = true
end
end
imageView.connect(SEL_LEFTBUTTONRELEASE) do
imageView.ungrab
imageView.endDrag
stack.remove(card) if data_sent
self.display(stack, requesting_player)
end
#set action for selected button
imageView.connect(SEL_COMMAND) do
puts stack.inspect
puts card.inspect
puts imageView.inspect
end
imageView.create
end
@display_label.text "Showing: #{cards.empty? ? "" :
cards[0].commander}''s
#{stack.get_class} (#{cards.size})"
stack
end
Lyle Johnson
2007-Mar-07 22:13 UTC
[fxruby-users] my button.connect(SEL_COMMAND) isn''t working
On 3/7/07, Raj Sahae <rajsahae at gmail.com> wrote:> Is it because I''m also using the DND stuff for the same button? Does > the LEFBUTTONPRESS and LEFTBUTTONRELEASE mess up SEL_COMMAND?I thought I had responded to this question when you posted it to ruby-talk, but I can''t find it in the archives now. Yes, if you completely override the handler for SEL_LEFTBUTTONRELEASE, the button will never get to fire its SEL_COMMAND message. You should however be able to avoid that happening by making sure that your SEL_LEFTBUTTONRELEASE handler returns false, e.g. imageView.connect(SEL_LEFTBUTTONRELEASE) do imageView.ungrab imageView.endDrag stack.remove(card) if data_sent self.display(stack, requesting_player) false # added this line end Hope this helps, Lyle