Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Using MMA we often come across situations like the following

cityLIST = CityData[#, "Name"] & /@ CityData[];

This code if you evaluate will emit some display pane to the front end until evaluation finishes. enter image description here This is really nice functionality of MMA. Now when I want some of my time consuming code to have the same functionality I thought of Monitor or PrintTemporary. But is there a streamlined way to use this functions or anything similar (e.g some magical Internal`Bag, Internal`StuffBag) to achieve such dynamic message display that is not controlled by some artificial Pause[n] for some $n$ seconds? It will be best to have a general purpose code that works like the following for Module or Block constructs.

       code snippet I;
       (* DynamicDisplayFunction must not affect the interdependent snippets I,II,..,n *)
       DynamicDisplayFunction[code snippet II];
       code snippet III;
       code snippet n;

If such a function say DynamicDisplayFunction is viable then it should show some user defined temporary display to the front end while the MMA kernel evaluates the computationally cumbersome code snippet II part of the above Module.

While trying with monitor I ended up copying the design of the display but could not get rid of the disturbing Pause[].

data = {{0.18, -0.13}, {0.84, -0.06}, {0.05,0.88}, {0.24, -0.63}, 
{0.67, 0.93}, {0.05, 0.88}, {0.65,0.92}, {0.01, 0.99}, {0.17, -0.04},
{0.23, -0.55}};
model[{a_, k_, w_, p_}][x_] = a Exp[-k x] Sin[w x + p];
Module[{vars = {a, k, w, p}}, 
       Monitor[FindFit[data, model[vars][x], vars, x,StepMonitor :> Pause[0.3]],
               Grid[{{"Curve fitting results will be ready shortly...."}}, 
                    Frame -> All, FrameStyle -> Darker[Blend[{Blue, Green}], .1],
                    ItemStyle -> {FontFamily -> "Helvetica", 
                    Directive[Darker[Blend[{Blue, Green}], .1], 11], None}, 
                    Background -> Lighter[Blend[{Blue, Green}], .9], 
                    Spacings -> {4.9, 2.2}]

enter image description here

I doubt a bit if this type of question is fully correct in its own right as we know designing an observer for a certain system that does not affect the system itself, not even minutely, is very difficult. During a code evaluation making the kernel transmit some constant "Busy" message to the front end is it a simple job? I am also not sure if similar question is already addressed in the SE by some fellow members?

share|improve this question

3 Answers 3

up vote 6 down vote accepted

I am not sure PrintTemporary doesn't do your job

Module[{pTmp, etc},
 pTmp = PrintTemporary["bla"];
 Pause[3];(* do your stuff *)
 NotebookDelete[pTmp]; PrintTemporary["blo"];
 Pause[2] (*do more stuff*)

Your function would be something like

SetAttributes[DynamicDisplayFunction, HoldFirst];
DynamicDisplayFunction[code_, message_] := 
 Module[{tmp = PrintTemporary[message], res = code},

And the Pause you had to put in, that's just because your computation was too fast, or I didn't get your point. I don't think the idea is for the real computation to get slower so that people can read your message, right?

share|improve this answer

The progress cell that you see when you load data from the Wolfram server is a "PrintTemporary" cell. The following example is based on what is used by Mathematica to print these cells. You can modify and adapt this to suit your use.

monitorCell[i_] := CellPrint@Cell[
        FrameBox[StyleBox[ToBoxes@StringForm["Progress: `1`", i],
             FontFamily -> "Verdana",
             FontSize -> 11,
             FontColor -> RGBColor[0.2, 0.4, 0.6]
        Background -> RGBColor[0.96, 0.98, 1.],
        FrameMargins -> {{24, 24}, {8, 8}},
        FrameStyle -> RGBColor[0.2, 0.4, 0.6],
        StripOnInput -> False]
    ], "PrintTemporary"

enter image description here

share|improve this answer

You need your evaluations to take enough time for this to display. For example this works fine for me:


  tmp = First @
    Import["http://www.census.gov/foreign-trade/balance/country.zip", "*"],

  Grid[{{"imported data being downloaded..."}}, Frame -> All, 
   FrameStyle -> Darker[Blend[{Blue, Green}], .1], 
   ItemStyle -> {FontFamily -> "Helvetica", 
     Directive[Darker[Blend[{Blue, Green}], .1], 11], None}, 
   Background -> Lighter[Blend[{Blue, Green}], .9], 
   Spacings -> {4.9, 2.2}]

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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