MathGroup Archive 2010

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

Search the Archive

Generic Button/Palette design pattern?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114947] Generic Button/Palette design pattern?
  • From: Jason Ledbetter <jasonbrent at gmail.com>
  • Date: Thu, 23 Dec 2010 03:56:36 -0500 (EST)

Folk,

I'm trying to write a generic palette that accepts as input a nested list
with button names/actions.

Apparently my weak comprehension of M is winning once again.

First, I'm defining options as pair-wise values in a nested list:

o = {
  { "button1",
   HoldForm[NotebookWrite[EvaluationNotebook[], Cell["button1 pressed"]]] },
  {"button2",
   HoldForm[NotebookWrite[EvaluationNotebook[], Cell["button2 pressed"]]]}
  }


I would expect that one can then do the following:


Button[#[[1]],#[[2]]]&/@o


This generates two buttons but the action for those buttons isn't what I'd
expect. If I convert that output to "InputForm", the #[[2]] argument is
apparently "{"button1",

  HoldForm[NotebookWrite[EvaluationNotebook[], Cell["button1
pressed"]]]}[[2]]"


I can't fathom why.


If I run:


Print@#[[2]]&/@o


I receive just the output I expect. e.g.,
"NotebookWrite[EvaluationNotebook[], Cell[button1 pressed]]", etc.


The ultimate goal is to do something like:


CreatePalette[Button[Style[#[[1]], 12, FontFamily->"Times"], #[[2]],
Appearance->"Palette", ImageSize->120]& /@ o, Saveable->False, Spacings->0]


This allowing me to readily open a palette by just customizing what exists
in the 'o' list.


If anyone can point out what I'm missing that should apparently be obvious
here, I'd appreciate it (And I'm almost positive my HoldForm[] usage is not
correct yet).


Thanks,


-jbl


  • Prev by Date: Re: what's wrong with this?!!
  • Next by Date: Re: Complete uninstall of Mathematica 6/7/8 on a Mac
  • Previous by thread: Re: Map function with 2 variables
  • Next by thread: Re: Generic Button/Palette design pattern?