[fxruby-users] my button.connect(SEL_COMMAND) isn't working

Raj Sahae rajsahae at gmail.com
Wed Mar 7 16:49:03 EST 2007


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


More information about the fxruby-users mailing list