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
fxrbu1 at gi2.herzkes.de
2006-Oct-18 07:23 UTC
[fxruby-users] Trouble updating image in an icon
Ray Bovet wrote:> Got a click on the image > testicon.rb:28: [BUG] Segmentation fault[...]> def displayImage( myViewFile, theApp, theImage) > iconFile = File.open( myViewFile, "rb") > theImage.icon = FXGIFIcon.new(theApp, iconFile.read) > iconFile.close > endInvoke method "create" on the new icon before the assignment. It would be nice if FXRuby detected this (it''s a common oversight) and called "create" on widgets if necessary. Or, raising an exception with an explanatory message would still be better than crashing the interpreter. Regards, Tobias
> def displayImage( myViewFile, theApp, theImage) > iconFile = File.open( myViewFile, "rb") > theImage.icon = FXGIFIcon.new(theApp, iconFile.read)# Here, you should have something like :'' theImage.icon.create() . Not needed before theApp.create()> iconFile.close > end----- Original Message ----- From: "Ray Bovet" <Ray at Bovet.org> To: <fxruby-users at rubyforge.org> Sent: Wednesday, October 18, 2006 6:17 AM Subject: [fxruby-users] Trouble updating image in an icon> 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 > > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users >
Many thanks to G?rard and to Tobias who both responded quickly to my plea! It works fine now. It''s wonderful to get such quick and helpful response!!! Ray G?rard M?nochet wrote:>> def displayImage( myViewFile, theApp, theImage) >> iconFile = File.open( myViewFile, "rb") >> theImage.icon = FXGIFIcon.new(theApp, iconFile.read) >> > > # Here, you should have something like :'' theImage.icon.create() . > Not needed before theApp.create() > > >> iconFile.close >> end >> > > > > > > ----- Original Message ----- > From: "Ray Bovet" <Ray at Bovet.org> > To: <fxruby-users at rubyforge.org> > Sent: Wednesday, October 18, 2006 6:17 AM > Subject: [fxruby-users] Trouble updating image in an icon > > > >> 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 >> >> _______________________________________________ >> fxruby-users mailing list >> fxruby-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/fxruby-users >> >> > > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users > > >