Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: GUIKit: user defined properties?

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

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 
represent
 > 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:

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

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 
define
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:

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


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)