Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

64
LINES

< > BotCompany Repo | #1021117 // DynAskUserQuestions

JavaX fragment (include)

1  
abstract sclass DynAskUserQuestions extends DynModule {
2  
  S question, answer;
3  
  bool speak, listen;
4  
  transient JButton btnSubmit;
5  
  transient S lastHeard;
6  
  
7  
  start {
8  
    dm_onTopInput_q(voidfunc(S s) {
9  
      if (listen) {
10  
        if "next question" ret with newQuestion();
11  
        if "no idea" { setField(answer := s); submit(); }
12  
        if (isYes_1(s)) {
13  
          submit();
14  
          ret;
15  
        }
16  
        lastHeard = s;
17  
        setField(answer := s);
18  
        dm_showYesToAcceptPopupAbove(btnSubmit);
19  
        dm_sayInEnglish(s);
20  
      }
21  
    });
22  
  }
23  
  
24  
  visualize {
25  
    if (empty(question)) newQuestion();
26  
    JLabel lblQ = fontSizePlus(3, makeBold(dm_fieldLabel('question)));
27  
    componentPopupMenuItem(lblQ, "Suggest question...", r {
28  
      inputText("Question", question, voidfunc(S s) {
29  
        setField(question := s)
30  
      })
31  
    });
32  
    ret withRightMargin(makeForm2(
33  
      "", withBottomMargin(15, lblQ),
34  
      "Human answer:", centerAndEastWithMargin(onEnter(dm_fieldTextField('answer), rThread submit),
35  
        btnSubmit = jbutton("Submit", rThread submit)),
36  
      "", withBottomMargin(withTopMargin(20, rightAlignedButtons(
37  
        dm_checkBox('listen), dm_checkBox('speak), "Ask me something else", rThread newQuestion)))));
38  
  }
39  
  
40  
  abstract S makeAQuestion();
41  
  
42  
  void newQuestion enter {
43  
    dm_hideYesPopupForComponent(btnSubmit);
44  
    setFields(answer := "", question := makeAQuestion());
45  
    if (empty(question)) ret with infoBox("Got nothing to ask");
46  
    programLogStructure(litorderedmap(+question));
47  
    vmBus_send('showingQuestion, module(), question);
48  
    if (speak) dm_sayWithAutoLanguage_splitAtQuotes(question);
49  
  }
50  
  
51  
  void submit enter {
52  
    dm_hideYesPopupForComponent(btnSubmit);
53  
    programLogStructure(litorderedmap(+question, +answer));
54  
    vmBus_send('userAnsweredQuestion, module(), question, answer);
55  
    dm_addQAndA(question, answer);
56  
    infoBox(confirmationText());
57  
    if (speak) dm_sayInEnglish(eq(lastHeard, answer) ? "confirmed" : answer);
58  
    newQuestion();
59  
  }
60  
  
61  
  S confirmationText() {
62  
    ret "[saved] " + question + " => " + answer;
63  
  }
64  
}

Author comment

Began life as a copy of #1020045

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1021117
Snippet name: DynAskUserQuestions
Eternal ID of this version: #1021117/20
Text MD5: e9f938eddfe8307bc1edd6ab9e4a03e1
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-01-24 00:09:10
Source code size: 2160 bytes / 64 lines
Pitched / IR pitched: No / No
Views / Downloads: 298 / 837
Version history: 19 change(s)
Referenced in: [show references]