Re: Generic Button/Palette design pattern?
- To: mathgroup at smc.vnet.net
- Subject: [mg114944] Re: Generic Button/Palette design pattern?
- From: Jason Ledbetter <jasonbrent at gmail.com>
- Date: Thu, 23 Dec 2010 03:56:02 -0500 (EST)
- References: <AANLkTinE=OGgF+ED-TdWPTfd7-qFYFSq-Y8nKUd44Ese@mail.gmail.com>
I've now got this basically working. I was missing a ReleaseHold in the Button form. That said, "CreatePalette" seems to have a bug (at least per my expectations). --snip-- o = { { "button1", HoldForm[NotebookWrite[EvaluationNotebook[], Cell["button1 pressed"]]] }, {"button2", HoldForm[NotebookWrite[EvaluationNotebook[], Cell["button2 pressed"]]]} }; Button[#[[1]], ReleaseHold[#[[2]]]] & /@ o CreatePalette[%] --snip-- The two buttons that appear in the notebook act as I expect. The two buttons that appear in the palette only "beep" when I clicked. I'm not sure how to troubleshoot what's going on under this. -jbl On Wed, Dec 22, 2010 at 4:58 PM, Jason Ledbetter <jasonbrent at gmail.com>wrote: > 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 >
- Follow-Ups:
- Re: Generic Button/Palette design pattern?
- From: Jason Ledbetter <jasonbrent@gmail.com>
- Re: Generic Button/Palette design pattern?