MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: GUIKit: user defined properties?

  • To: mathgroup at
  • Subject: [mg50156] Re: [mg50139] GUIKit: user defined properties?
  • From: Jeff Adams <jeffa at>
  • Date: Wed, 18 Aug 2004 01:20:04 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

Andrew Dabrowski wrote:
 > Hi,
 > I've just downloaded the new GUIKit and I'm trying to convert some 
palettes in
 > my old programs into the new GUIKit windows.
 > Palette buttons have a data field which is useful when the buttons 
 > different numerical values.  Is there a way to capture this feature 
with GUIKit?
 > Is there a way to define a custom property for a widget?
 > I've tried using Script to define a constant function, i.e.
 > Widget["Button",{"text"->Script[buttonData[] 
],Script[buttonData[]:="A"] } ],
 > but this prints "GUIKit`Private`Script31buttonData" in the button 
instead of "A".

Hello Andrew,

This widget definition is almost working, but the issue here is that 
within each Widget
definition the elements of the widget are visited and evaluated in 
order, from left to right,
so the buttonData[] function is being evaluated in Mathematica to set 
the "text"
property of the button before your definition is defined within the 
Mathematica kernel.
If you simply reverse the order of these elements the value will be 
assigned at
the time the button's text property is needed:

   Widget["Button", {Script[buttonData[] := "A"], "text" -> 

We are looking into allowing custom properties of a widget defined with 
top-level Mathematica
code for a future version of GUIKit, but Script[] blocks of Mathematica 
functions should
be able to provide a similar functionality for the time being.
Although many times some of these properties are
typically defined using the static strings themselves, you can build a 
set of
Mathematica functions to 'centralize' your widget properties if you 
desire to store
that information this way.

For example, the following example uses a top-level Script[] block to 
functions that return various button properties for multiple widgets in 
a window
which is just one of many alternative techniques to simply defining 
each button's
properties with static strings:

  Widget["Frame", {
      labels[i_] := {"One", "Two", "Three"}[[i]];
      tooltips[i_] := {"First", "Second", "Third"}[[i]];
    Widget["Button", {"text" -> Script[labels[1]], "tooltipText" -> 
    Widget["Button", {"text" -> Script[labels[2]], "tooltipText" -> 
    Widget["Button", {"text" -> Script[labels[3]], "tooltipText" -> 

Jeff Adams
Wolfram Research

  • Prev by Date: Re: Adaptive FunctionInterpolation[] ?
  • Next by Date: Re: Re: New user: Abs[] problem
  • Previous by thread: GUIKit: user defined properties?
  • Next by thread: FindMinimum and the minimum-radius circle (2)