abstract sclass DynAskUserQuestions extends DynModule { S question, answer; bool speak; visualize { if (empty(question)) newQuestion(); JLabel lblQ = fontSizePlus(3, makeBold(dm_fieldLabel('question))); componentPopupMenuItem(lblQ, "Suggest question...", r { inputText("Question", question, voidfunc(S s) { setField(question := s) }) }); ret withRightMargin(makeForm2( "", withBottomMargin(15, lblQ), "Human answer:", centerAndEastWithMargin(onEnter(dm_fieldTextField('answer), rThread submit), jbutton("Submit", rThread submit)), "", withBottomMargin(withTopMargin(20, rightAlignedButtons( dm_checkBox('speak), "Ask me something else", rThread newQuestion))))); } abstract S makeAQuestion(); void newQuestion enter { setFields(answer := "", question := makeAQuestion()); if (empty(question)) ret with infoBox("Got nothing to ask"); programLogStructure(litorderedmap(+question)); vmBus_send('showingQuestion, module(), question); if (speak) dm_sayWithAutoLanguage(question); } void submit enter { programLogStructure(litorderedmap(+question, +answer)); vmBus_send('userAnsweredQuestion, module(), question, answer); dm_addQAndA(question, answer); infoBox(confirmationText()); if (speak) dm_sayInEnglish(answer); newQuestion(); } S confirmationText() { ret "[saved] " + question + " => " + answer; } }