I''m trying to display one of two separate bitmap images along with some text. The images are a check and and a cross symbol and are displayed as FIRMWARE C or FIRMWARE X or FIRMWARE where C would be my checkmark image and X is the cross image. This is the code I am using to initially setup the Static bitmap and sizer. This is then added to a vertical box sizer containing a few other controls. Lastly for a test, I simply show the appropriate image as in @check_sb_firmware.show and @x_sb_firmware forthe other image. The problem that I am seeing is the first time I show the image, the image appears at the top of my panel, the second time I show the image it is in the correct position, just after my text. Am I handling this wrong or perhaps there is a better way? It seems like it should be a simple task. Thanks Mark def make_firmware_check(parent) firmware_check_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL) check_bm_firmware = Bitmap.new("images/check_icon.png", Wx::BITMAP_TYPE_ANY) @check_sb_firmware = Wx::StaticBitmap.new(parent, -1, check_bm_firmware) fw_text = Wx::StaticText.new(parent, ID_SERIAL_STATIC_TEXT, "FIRMWARE", Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, 0, "") x_bm_firmware = Bitmap.new("images/x_icon.png", Wx::BITMAP_TYPE_ANY) @x_sb_firmware = Wx::StaticBitmap.new(parent, -1, x_bm_firmware) firmware_check_sizer.add(fw_text, 1, Wx::RIGHT|Wx::TOP|Wx::ALIGN_LEFT, 5) firmware_check_sizer.add(@check_sb_firmware, 0, Wx::ALIGN_CENTER, 3) firmware_check_sizer.add(@x_sb_firmware, 0, Wx::ALIGN_CENTER, 3) @check_sb_firmware.hide @x_sb_firmware.hide return firmware_check_sizer end _______________________________________________ wxruby-users mailing list wxruby-users@rubyforge.org http://rubyforge.org/mailman/listinfo/wxruby-users
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 10.10.2011 20:36, schrieb Mark Barton:> def make_firmware_check(parent) firmware_check_sizer > Wx::BoxSizer.new(Wx::HORIZONTAL) check_bm_firmware > Bitmap.new("images/check_icon.png", Wx::BITMAP_TYPE_ANY) > @check_sb_firmware = Wx::StaticBitmap.new(parent, -1, > check_bm_firmware) fw_text = Wx::StaticText.new(parent, > ID_SERIAL_STATIC_TEXT, "FIRMWARE", Wx::DEFAULT_POSITION, > Wx::DEFAULT_SIZE, 0, "") x_bm_firmware > Bitmap.new("images/x_icon.png", Wx::BITMAP_TYPE_ANY) @x_sb_firmware > = Wx::StaticBitmap.new(parent, -1, x_bm_firmware) > firmware_check_sizer.add(fw_text, 1, > Wx::RIGHT|Wx::TOP|Wx::ALIGN_LEFT, 5) > firmware_check_sizer.add(@check_sb_firmware, 0, Wx::ALIGN_CENTER, > 3) firmware_check_sizer.add(@x_sb_firmware, 0, Wx::ALIGN_CENTER, > 3) @check_sb_firmware.hide @x_sb_firmware.hide return > firmware_check_sizer endDo yourself a favour and include the Wx module in your scope so you don''t have to always write that annoying Wx::*. Second, you should probably read this: http://wxruby.rubyforge.org/doc/wxruby_intro.html There''s no need to specify all that nasty default parameters for your wxRuby code, so e.g.> fw_text = Wx::StaticText.new(parent, ID_SERIAL_STATIC_TEXT, > "FIRMWARE", Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, 0, "")becomes> fw_text = StaticText.new(parent, :id => ID_SERIAL_STATIC_TEXT, > :label => "FIRMWARE")And you may leave out the ":id => ID_SERIAL_STATIC_TEXT" as well, because there''s usually no reason to assign IDs manually to widgets. Even for event handling you can usually just pass the control instance into the event handler. Next, the Wx::StaticBitmap class isn''t intended to draw normal images (as weird as it sounds). Quote from the docs:> A static bitmap control displays a bitmap. It is meant for display > of the small icons in the dialog boxes and is not meant to be a > general purpose image display control. In particular, under Windows > 9x the size of bitmap is limited to 64?64 pixels and thus you > should use your own control if you want to display larger images > portably.Finally I''m not sure how sizers work with hidden controls. Your code appears logically correct to me (although there are some stylistic problems as I already pointed out), maybe you''re running into an issue I''ve experienced some time ago as well: Changing a control''s contents doesn''t cause wxRuby to recalculate the sizer layout (in particular, the issue I was running into was that I had a right-aligned StaticText widget and the text could grow bigger and was then running out of the window). I *think* it is possible to make wxRuby relayout the GUI by calling Sizer#recalc_sizes, but I didn''t try this (the original code where I could have needed that has been removed already). Vale, Marvin -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJOk+hNAAoJELh1XLHFkqhaJ8AH/3g1ZNLcAxF+jzOU1I2uwfFr JwHQ50tL3dL8E9yTfheUpKH426DovnBXwLD47FrZNhtHaxDZY2WkiCRDvHqDi+b+ E06WlbTBej3jPTSFEfH0Rm3XRmsua6aozZPHC9XaoNz2bXwxwwdsJiao7OtoJ5bP 70s7DlsbaDnxoUPHi9R6izl2tLAB4P7VNi/HKMhy2m07PNDH7d5nzM+XfwUM3Gls EbcCRNoNGM0+fh/aqYXo78nJ3rhorknhH7HvKfbZUZkuOpIl804yIQE1C4WO9XIj WWPd9eTEfqR5YnaTNF7zlG2f9BZj/c26+/ndxqOt422vPBZEYLy4BXQgtKVQ83Y=2wH4 -----END PGP SIGNATURE-----
Alex Fenton
2011-Oct-11 07:49 UTC
[wxruby-users] having trouble show/hide bitmap in a sizer
On 10/10/11 19:36, Mark Barton wrote:> > This is the code I am using to initially setup the Static bitmap and > sizer. This is then added to a vertical box sizer containing a few > other controls. Lastly for a test, I simply show the appropriate image > as in @check_sb_firmware.show and @x_sb_firmware forthe other image. > The problem that I am seeing is the first time I show the image, the > image appears at the top of my panel, the second time I show the image > it is in the correct position, just after my text. Am I handling this > wrong or perhaps there is a better way?Just to check, you do call parent.sizer = firmware_check_sizer in the calling function to assign the BoxSizer to the panel? After hiding or deleting windows that are controlled by a sizer, you may need to call sizer.layout to re-assign the spacing correctly. alex -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20111011/cb39a05e/attachment-0001.html>
Mark Barton
2011-Oct-11 10:33 UTC
[wxruby-users] having trouble show/hide bitmap in a sizer
On 10/11/11 2:55 AM, Quintus wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Am 10.10.2011 20:36, schrieb Mark Barton: >> def make_firmware_check(parent) firmware_check_sizer >> Wx::BoxSizer.new(Wx::HORIZONTAL) check_bm_firmware >> Bitmap.new("images/check_icon.png", Wx::BITMAP_TYPE_ANY) >> @check_sb_firmware = Wx::StaticBitmap.new(parent, -1, >> check_bm_firmware) fw_text = Wx::StaticText.new(parent, >> ID_SERIAL_STATIC_TEXT, "FIRMWARE", Wx::DEFAULT_POSITION, >> Wx::DEFAULT_SIZE, 0, "") x_bm_firmware >> Bitmap.new("images/x_icon.png", Wx::BITMAP_TYPE_ANY) @x_sb_firmware >> = Wx::StaticBitmap.new(parent, -1, x_bm_firmware) >> firmware_check_sizer.add(fw_text, 1, >> Wx::RIGHT|Wx::TOP|Wx::ALIGN_LEFT, 5) >> firmware_check_sizer.add(@check_sb_firmware, 0, Wx::ALIGN_CENTER, >> 3) firmware_check_sizer.add(@x_sb_firmware, 0, Wx::ALIGN_CENTER, >> 3) @check_sb_firmware.hide @x_sb_firmware.hide return >> firmware_check_sizer end > Do yourself a favour and include the Wx module in your scope so you > don''t have to always write that annoying Wx::*. Second, you should > probably read this: http://wxruby.rubyforge.org/doc/wxruby_intro.html > There''s no need to specify all that nasty default parameters for your > wxRuby code, so e.g. > >> fw_text = Wx::StaticText.new(parent, ID_SERIAL_STATIC_TEXT, >> "FIRMWARE", Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, 0, "") > becomes > >> fw_text = StaticText.new(parent, :id => ID_SERIAL_STATIC_TEXT, >> :label => "FIRMWARE") > And you may leave out the ":id => ID_SERIAL_STATIC_TEXT" as well, > because there''s usually no reason to assign IDs manually to widgets. > Even for event handling you can usually just pass the control instance > into the event handler. > > Next, the Wx::StaticBitmap class isn''t intended to draw normal images > (as weird as it sounds). Quote from the docs: > >> A static bitmap control displays a bitmap. It is meant for display >> of the small icons in the dialog boxes and is not meant to be a >> general purpose image display control. In particular, under Windows >> 9x the size of bitmap is limited to 64?64 pixels and thus you >> should use your own control if you want to display larger images >> portably. > Finally I''m not sure how sizers work with hidden controls. Your code > appears logically correct to me (although there are some stylistic > problems as I already pointed out), maybe you''re running into an issue > I''ve experienced some time ago as well: Changing a control''s contents > doesn''t cause wxRuby to recalculate the sizer layout (in particular, > the issue I was running into was that I had a right-aligned StaticText > widget and the text could grow bigger and was then running out of the > window). I *think* it is possible to make wxRuby relayout the GUI by > calling Sizer#recalc_sizes, but I didn''t try this (the original code > where I could have needed that has been removed already). > > Vale, > Marvin > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.11 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iQEcBAEBAgAGBQJOk+hNAAoJELh1XLHFkqhaJ8AH/3g1ZNLcAxF+jzOU1I2uwfFr > JwHQ50tL3dL8E9yTfheUpKH426DovnBXwLD47FrZNhtHaxDZY2WkiCRDvHqDi+b+ > E06WlbTBej3jPTSFEfH0Rm3XRmsua6aozZPHC9XaoNz2bXwxwwdsJiao7OtoJ5bP > 70s7DlsbaDnxoUPHi9R6izl2tLAB4P7VNi/HKMhy2m07PNDH7d5nzM+XfwUM3Gls > EbcCRNoNGM0+fh/aqYXo78nJ3rhorknhH7HvKfbZUZkuOpIl804yIQE1C4WO9XIj > WWPd9eTEfqR5YnaTNF7zlG2f9BZj/c26+/ndxqOt422vPBZEYLy4BXQgtKVQ83Y> =2wH4 > -----END PGP SIGNATURE----- > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >Thanks Marvin for the helpful information. I think you have hit the nail on the head or at least very close. In my test I was changing the layout, sleeping , changing the layout and so forth without allowing WxRuby to complete its loop even though I was calling layout each time. The bitmap works as expected if I allow the loop to complete before making the next change. Again thanks for you help. Mark
Mark Barton
2011-Oct-12 11:55 UTC
[wxruby-users] having trouble show/hide bitmap in a sizer
On 10/11/11 3:49 AM, Alex Fenton wrote:> On 10/10/11 19:36, Mark Barton wrote: >> >> This is the code I am using to initially setup >> the Static bitmap and sizer. This is then added >> to a vertical box sizer containing a few other >> controls. Lastly for a test, I simply show the >> appropriate image as in @check_sb_firmware.show >> and @x_sb_firmware forthe other image. The >> problem that I am seeing is the first time I >> show the image, the image appears at the top of >> my panel, the second time I show the image it >> is in the correct position, just after my text. >> Am I handling this wrong or perhaps there is a >> better way? > > Just to check, you do call parent.sizer = > firmware_check_sizer in the calling function to > assign the BoxSizer to the panel? > > After hiding or deleting windows that are > controlled by a sizer, you may need to call > sizer.layout to re-assign the spacing correctly. > > alex > > > > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-usersHi Alex, Hummmm, well, what I have is two horizontal BoxSizers with the text and static bitmaps added to a vertical BoxSizer along with a couple other controls. This vertical sizer is added to the left side of a two column FlexGridSizer. The FlexGridSizer is attached to the panel with: main_panel.set_sizer(myFlexGridSizer) followed by a main_panel.layout. Currently I have only the bitmap initially hidden and this seem to work if I allow the app loop to complete after changing the layout. The puzzling part is it does not work if I also hide the text as well as the bitmap in my function. In this case, both the bitmaps and text appear at the top of the panel and are partially visible. Thanks Mark -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20111012/7b80788a/attachment.html>