Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Generic Button/Palette design pattern?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114957] Re: Generic Button/Palette design pattern?
  • From: John Fultz <jfultz at wolfram.com>
  • Date: Fri, 24 Dec 2010 04:11:44 -0500 (EST)
  • Reply-to: jfultz at wolfram.com

Hold would be more proper than HoldForm here (although both certainly work).  
HoldForm is generally about holding for display purposes, though, where Hold 
provides better feedback when you're just doing expression manipulation behind 
the scenes (by feedback, I mean that it's going to more easily show up in 
debugging outputs).

As for CreatePalette, there is no bug.  You're trying to do something which is 
illegal, and for good reason.

NotebookWrite[EvaluationNotebook[],...]

That's writing into the *palette*.  But palettes are not editable by default.  
You probably want to be writing to InputNotebook[], which is the notebook where 
palettes typically paste their output.

Sincerely,

John Fultz
jfultz at wolfram.com
User Interface Group
Wolfram Research, Inc.


On Thu, 23 Dec 2010 03:56:02 -0500 (EST), Jason Ledbetter wrote:
>
> 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




  • Prev by Date: Re: Mathematica daily WTF
  • Next by Date: Re: Query available max memory (RAM)?
  • Previous by thread: Re: Generic Button/Palette design pattern?
  • Next by thread: Export problem on complicated Animate