8
$\begingroup$

GUIs may generate warnings while internal evaluations are processed. In this example I intentionally introduce a line that will generate a warning. Warnings are useful, so I don't want to quiet them nor I can ensure that a fairly complicated GUI (thousands of lines of code) will never generate one. The problem is that once I read the warning I would like to remove the pink background from the GUI without having to recreate it all.

The lines below will generate the problem when the Checkbox is clicked. I want to remove the pink background after I see it, or maybe I want to fix the code such that the pink background never appears but the warning messages remain printed to the console.

As a side note, this program doesn't work in Windows if I remove the brackets from or rename menuItems[] to menuItems.

CreateDocument[
 Panel@
  DynamicModule[{gui, opt = 1, dummyList = {3, 4}, changeTabQ = True, 
    menuItems},
   menuItems[] := Block[{}, Rest@dummyList; {1, 2}];
   Labeled[Checkbox[Dynamic[changeTabQ,
      (dummyList = {}; changeTabQ = #;) &]]
    ,
    Dynamic[Refresh[
      Replace[changeTabQ,
       {True -> Panel@
          PopupMenu[Dynamic[opt, (opt = #;
              ) &]
           , {1, 2}
           ]
        , False -> PopupMenu[Dynamic[opt, (opt = #;) &], menuItems[]]
        }
       ]
      , TrackedSymbols :> {changeTabQ}
      ]
     ]
    ]
   ]
 , WindowSize -> {Scaled@.3, Scaled@0.3}
 , DockedCells -> Cell["Docked"]
 , WindowMargins -> {{0, Scaled@1}, {Scaled@0.8, 0}}
 , WindowElements -> {"VerticalScrollBar", "HorizontalScrollBar", 
   "StatusArea", "MagnificationPopUp"}
 , Deployed -> True
 , Editable -> False
 , Selectable -> False
 , WindowTitle -> "Test UI"
 ]
$\endgroup$
  • 1
    $\begingroup$ I should emphasize that the code in this example has been written with the purpose of triggering the problem, so using PaneSelector or other funcitons to "improve" the code may hide the problem I'm trying to highlight. $\endgroup$ – Ariel Sepulveda May 18 '15 at 18:05
  • $\begingroup$ Comments under this question should explain your side question: 66767 $\endgroup$ – Kuba May 18 '15 at 18:08
  • $\begingroup$ I've often found that Dynamic[Refresh[code, TrackedSymbols->{symbols}]] often doesn't work as expected unless the symbols tracked have DownValues (i.e. end with a square bracket). In this example I had such behavior, so to make it work I added the [] at the end of the variable changeTabQ. Additionally, alternating the use or Rule[TrackedSymbols,{symbols}] and RuleDelayed[TrackedSymbols, {symbols}] may also make a difference at the time of "making things work" as expected. $\endgroup$ – Ariel Sepulveda May 18 '15 at 18:16
  • 1
    $\begingroup$ Is Preferences -> Messages -> Formatting error indications--> None the answer? $\endgroup$ – Kuba May 20 '15 at 17:48
  • 1
    $\begingroup$ It seems like those options partially solve the problem as the pink background is gone. The Cell Bracket still contains the evidence of the warning message which I would also like to remove somehow. I assume that those preferences can also also be set in a programmatic way. That would be the best such that the user doesn't have to deal with that, but the programmer can handle that for all potential users. $\endgroup$ – Ariel Sepulveda May 22 '15 at 13:00
4
$\begingroup$

Suppress formatting errors by setting the necessary options for the actual notebook or for the front-end:

SetOptions[EvaluationNotebook[], AutoStyleOptions -> {
     "FormattingErrorStyle" -> {FontColor -> RGBColor[1., 0.33, 0.33], 
             Background -> RGBColor[1., 0.33, 0.33, 0.15]},
     "FormattingErrorTooltips" -> False,
     "HighlightFormattingErrors" -> False
     }]
$\endgroup$
  • $\begingroup$ @Kuba Yes, thanks, I copied it from another answer directly, forgot to modify. However, I have no clue how to suppress the bracket-indication. $\endgroup$ – István Zachar Jun 20 '16 at 7:09
  • $\begingroup$ OP needs that gone too but at least first part is shown in programmatical way. $\endgroup$ – Kuba Jun 20 '16 at 7:19
  • $\begingroup$ @Kuba Well, I'm aware of that, but for now, this is my half-answer. Though one can always turn off cell brackets entirely via "ShowCellBracket". $\endgroup$ – István Zachar Jun 20 '16 at 9:39
  • $\begingroup$ Yes, sorry, I thought so but future readers are not aware of that from the answer content only. Don't want to be picky either but after several months, future reader may wonder why the bracket is still orange. Maybe I'm overreacting :) $\endgroup$ – Kuba Jun 20 '16 at 9:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.