[KWWidgets] suggestion for icon method

Sebastien BARRE sebastien.barre at kitware.com
Sat Jul 21 10:40:58 EDT 2007


At 7/20/2007 07:38 PM, Steve Pieper wrote:
>Hi -
>
>Today I had a situation where I wanted to use a vtkImageData to set 
>the image for an vtkKWPushButton, but I couldn't find any easy way 
>to do it.  All of the vtkKWIcon::SetImage methods take lower-level 
>arguments.  So I added the following routine to one of my classes as 
>a helper.  Once I have the image in the icon, I use 
>vtkKWPushButton::SetImageToIcon to load it into the button.

I see what you mean.

In the past, the rational for not adding this new SetImage method is 
that it does not bring enough (it only saves you 2 or 3 lines of code 
for something that is typically not big at all compared to the rest 
of the UI code), and is not orthogonal.

But the problem is that the current methods are actually all bad :) 
At the end of the day what we needed is a resource framework, where 
you can refer to bitmaps and images to assign to buttons or labels as 
a simple resource name (which is what SetImageToPredefinedIcon is the 
closest to) . The resource framework would be a class to load bitmaps 
in memory, create collections of them, eventually assign them to 
namespace, etc.
http://www.kwwidgets.org/Wiki/KWWidgets/Resource_Manager

As you pointed out accurately, this is all too low level. Bear in 
mind that in the past all buttons had some different methods (or 
none) to assign images to them, it was a mess. We tried to unify it 
with a set of methods that you see now, while trying not to add 
*tons* of them. There are already *4* methods to assign an image to a 
button, that's a lot, and each time several classes have to be 
synchronized with the same API because they do not (cannot) share the 
same superclass (say labels and buttons). By keeping the number of 
methods low, this would make much easier to transition to the 
resource framework.

I know this is not in our/your TODO, but last week for example Wendy 
asked how to set her custom checkbutton/radiobutton to an image, and 
I could only direct her to painfully create a Tk photo with 
vtkKWTkUtilities, then assign it to the button using 
SetConfigurationOption("-image"...). This is way too low level sadly, 
and that where a resource framework would be neat.




More information about the KWWidgets mailing list