I'm trying to make a units palette to help with my various engineering courses. I thought about creating a "meta-palette" of sorts, maybe one that changes on the fly, or one where I can create all the buttons, arrange them on a grid and then export as a palette.
The first major hurdle I encountered and the issue at hand is that I can't for the life of me find a way to make the button's content "stick". Either the pasted content is left unevaluated, or it changes along with the InputField
or just plain out throws an error. I have tried with and without many, if not all, combinations of Dynamic
and non-Dynamic
versions of Module
, Setting
, Evaluate
, Defer
, and more.
Here's the snippet of my code:
Quantity; Module[{QN = {list, of, all units}
DynamicModule[{U = "", N = ""},
Grid@{{"Button:",
Quiet[PasteButton[Dynamic@N, Quantity[None, U (*Herein lies the issue*)]]]}, {"Label:",
InputField[Dynamic@N, String,
ContinuousAction -> True]}, {"Unit:",
InputField[Dynamic@U, String, ContinuousAction -> True,
FieldCompletionFunction ->
Select[QN,
StringContainsQ[#, IgnoreCase -> True]] &)]}}]]
I trimmed some unnecessary strings to reduce bulk.
The intended behavior of that button is to input the unit typed in the bottom text box. After this I might want to duplicate the button as a "static" one so that it can be reused later, but I think that solving this issue would simplify that goal.
I hope you guys can help me figure this one out, thanks in advance!