abstract sclass DynAskUserQuestions extends DynModule { S question, answer; bool speak, listen; transient JButton btnSubmit; transient S lastHeard; start { dm_onTopInput_q(voidfunc(S s) { if (listen) { if "next question" ret with newQuestion(); if "no idea" { setField(answer := s); submit(); } if (isYes_1(s)) { submit(); ret; } lastHeard = s; setField(answer := s); dm_showYesToAcceptPopupAbove(btnSubmit); dm_sayInEnglish(s); } }); } 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), btnSubmit = jbutton("Submit", rThread submit)), "", withBottomMargin(withTopMargin(20, rightAlignedButtons( dm_checkBox('listen), dm_checkBox('speak), "Ask me something else", rThread newQuestion))))); } abstract S makeAQuestion(); void newQuestion enter { dm_hideYesPopupForComponent(btnSubmit); 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_splitAtQuotes(question); } void submit enter { dm_hideYesPopupForComponent(btnSubmit); programLogStructure(litorderedmap(+question, +answer)); vmBus_send('userAnsweredQuestion, module(), question, answer); dm_addQAndA(question, answer); infoBox(confirmationText()); if (speak) dm_sayInEnglish(eq(lastHeard, answer) ? "confirmed" : answer); newQuestion(); } S confirmationText() { ret "[saved] " + question + " => " + answer; } }
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: | 297 / 836 |
Version history: | 19 change(s) |
Referenced in: | #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |