How can I make my code wait until two actions are done?

4

This question was inspired by yode's question found here. I think yode asked the wrong question, so I am asking what I think is the right one.

Consider a situation in which the user has to choose two directories before a computation can move forward. We want to present the user with two file-name setters but have the code wait until the user has chosen one directory from each setter before proceeding. How can we do that?

m_goldberg

Posted 2016-12-23T03:32:36.447

Reputation: 104 223

If you have time, could you please check this for grammar and clarity?

– Szabolcs – 2017-04-05T11:35:53.080

@Szabolcs. I didn't find anything wrong with the grammar, but I have made what I hope is a clarification. Do you think it clear now? – m_goldberg – 2017-04-07T01:39:35.737

Answers

5

Update

My answer is to use Dynamic with the option UpdateInterval -> 1 to hold the code that checks the completion condition.

DynamicModule[{from, to},
  Column[
   {Dynamic @
      Row[
        {FileNameSetter[Dynamic[from], "Directory", Appearance -> "From where"],
         FileNameSetter[Dynamic[to], "Directory", Appearance -> "To where"],
         Button["Reset", Clear[from, to]]}],
    Dynamic[
      If[And @@ {ValueQ[from], ValueQ[to]}, 
        StringJoin[{from, "  ", to}], "Waiting ..."],
      UpdateInterval -> 1]}]]

Before the condition is fulfilled, the user sees

before

After the condition is fulfilled, the user sees

after

The Reset button lets the code be reused to pick another pair of directories.

m_goldberg

Posted 2016-12-23T03:32:36.447

Reputation: 104 223

Thanks.Good workaround,I think the Column save me. :) – yode – 2016-12-23T06:22:59.787