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

44
LINES

< > BotCompany Repo | #1020313 // Show Definitions By Voice

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (8338L/44K).

!7

!include once #1020738 // Loadable Utils

srecord Definition(S word, S definition) {}

module DefinitionsByVoice > DynObjectTable<Definition> {
  bool voiceMode;
  
  visualize {
    ret withRightAlignedButtons(super.visualize(),
      dm_fieldCheckBox('voiceMode));
  }
  
  start {
    dm_useLocalMechListCopies();
    dontPersist();
    fieldsInOrder = true;
    dm_onTopInput(voidfunc(fS s) { reactTo(s) });
    reactTo(dm_getTopInput());
  }
  
  void _search(fS s) {
    bool wasEmpty = count() == 0;
    L<Definition> l = map(func(S def) -> Definition { Definition(s, def) }, dm_getDefinitions(s));
    if (empty(l)) ret;
    addAll(l);
    vmBus_send(wasEmpty ? 'firstResults : 'moreResults, this);
    if (voiceMode && wasEmpty)
      dm_say(first(l).definition);
  }

  // API
  
  void reactTo(fS s) enter {
    switch to q();
    clear();
    _search(s);
    new Matches m;
    for (S x : matchX_any_allRests(mL("Query Definition Patterns"), s))
      _search(x);
    if (nempty(data)) dm_showModule_noFocus();
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

-
Snippet ID: #1020313
Snippet name: Show Definitions By Voice
Eternal ID of this version: #1020313/17
Text MD5: 133c697da923f3fcb41ec9cbcd65a4a9
Transpilation MD5: 71fb3f1aad88bf89b847a5d879148166
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-01-01 18:56:07
Source code size: 1075 bytes / 44 lines
Pitched / IR pitched: No / No
Views / Downloads: 345 / 2598
Version history: 16 change(s)
Referenced in: