[fxruby-users] Trouble updating image in an icon

Ray Bovet Ray at Bovet.org
Wed Oct 18 00:17:02 EDT 2006


Okay, I've tried to figure this out on my own, but I'm not getting very 
far.  I'm sure I've made some utterly dumb newbie mistake - hopefully it 
won't take long for someone who understands FXRuby better than I do to 
set me straight.  I'm trying to write a program to display an image in a 
window.  Then, when you click on the window it should display the next 
image.  The FXRuby User's Guide has great information about setting up 
an icon and loading an image into it.  It also shows how to tie a 
command to a button press.  But I seem to be having lots of trouble 
displaying the new image after the button press.  Any comments on how to 
improve the code would be gratefully accepted!  The code below results 
in the messages below as soon as I click on the image once:

This application has requested the Runtime to terminate it in an unusual 
way.
Please contact the application's support team for more information.
Got a click on the image
testicon.rb:28: [BUG] Segmentation fault
ruby 1.8.4 (2006-04-14) [i386-mswin32]

 >Exit code: 3

Here's the code:

require 'rubygems'
require 'fox16'
include Fox

myViewFile = "starEdit.gif"

def displayImage( myViewFile, theApp, theImage)
    iconFile = File.open( myViewFile, "rb")
    theImage.icon = FXGIFIcon.new(theApp, iconFile.read)
    iconFile.close
end
   
theApp = FXApp.new
theMainWindow = FXMainWindow.new( theApp, "starShow")
count = 0
theImage = FXButton.new(theMainWindow, "image")
theImage.connect(SEL_COMMAND) do |sender, selector, data|
    count += 1
    STDERR.puts( "Got a click on the image")
    # imagine code here to update the image file.
    displayImage( myViewFile, theApp, theImage)
    theMainWindow.show
end

displayImage( myViewFile, theApp, theImage)
theApp.create
theMainWindow.show
theApp.run


Thanks for your help!

Ray Bovet



More information about the fxruby-users mailing list