Carsten,
You need to icon.create before you return icon from loadIcon (or at least,=
before you use button.icon=3D). The reason is that MainWindow.create calls=
icon.create for "first" icon as it a 'grand-child' of MainWindow at the=
moment that MainWindow is created. The "second" icon you load up later=
will need to be 'create'd manually before use. It doesn't matter if you=
create something too many times (I think it is just ignored), as long as=
it is done at least once before you attempt to use it.
bil
*********** REPLY SEPARATOR ***********
On 08/12/2003 at 19:40 Carsten Eckelmann wrote:
>Hi,
>
>I'm banging my head against this problem for days now: I have a button
>which displays an icon and then when the button is pressed it should
>display another icon. So the first icon is displayed fine but when I
>press the button the app chrashes with a segmentation fault. I'm testing
>this with the 'Pragmatic Installer 1.8.0-10' on Windows 2000.
>
>Here's the code:
>#------------------------------------------
>
>require 'fox'
>include Fox
>class MainWindow < FXMainWindow
> # load a png image from file
> def loadIcon(filename)
> begin
> icon =3D nil
> File.open(filename+".png", "rb") { |f|
> icon =3D FXPNGIcon.new(getApp(), f.read)
> }
> icon
> rescue
> raise RuntimeError, "Couldn't load icon: #{filename}"
> end
> end
> # initialize the window
> def initialize(app)
> super(app, "Test", nil, nil, DECOR_ALL, 0, 0, 0,0, 0, 0)
> button =3D FXButton.new(self,"")
> # set the buttons icon to the first image -> works well.
> button.icon =3D loadIcon("first")
> # when the button is pressed, change the icon
> # to the second image -> BOOM!
> button.connect(SEL_COMMAND) { button.icon =3D loadIcon("second") }
> end
> # create the window
> def create
> super
> show(PLACEMENT_SCREEN)
> end
>end
># create and run the application
>app =3D FXApp.new("Test", "Test")
>MainWindow.new(app)
>app.create
>app.run
>#------------------------------------------
>
>It also doesn't work for FXlabel and FXImageView. What am I doing wrong
>here?????? Help!
>
>Carsten.
>
>
>
>
>-------------------------------------------------------
>This SF.net email is sponsored by: SF.net Giveback Program.
>Does SourceForge.net help you be more productive? Does it
>help you create better code? SHARE THE LOVE, and help us help
>YOU! Click Here: http://sourceforge.net/donate/
>_______________________________________________
>Fxruby-users mailing list
>Fxr...@li...
>https://lists.sourceforge.net/lists/listinfo/fxruby-users
|