ShowMeHowItWorks.st
changeset 3775 0e44d27ee647
parent 3739 9c7040099cfe
child 3776 371ad059085a
equal deleted inserted replaced
3774:271887d2ed74 3775:0e44d27ee647
     4 
     4 
     5 "{ NameSpace: Smalltalk }"
     5 "{ NameSpace: Smalltalk }"
     6 
     6 
     7 Object subclass:#ShowMeHowItWorks
     7 Object subclass:#ShowMeHowItWorks
     8 	instanceVariableNames:'application opStream lastComponentName lastComponent lastResult
     8 	instanceVariableNames:'application opStream lastComponentName lastComponent lastResult
     9 		voice translate'
     9 		voice translate language verifying'
    10 	classVariableNames:'IntroShownCount'
    10 	classVariableNames:'IntroShownCount'
    11 	poolDictionaries:''
    11 	poolDictionaries:''
    12 	category:'Interface-Help'
    12 	category:'Interface-Help'
    13 !
    13 !
    14 
    14 
    52     )
    52     )
    53 ! !
    53 ! !
    54 
    54 
    55 !ShowMeHowItWorks class methodsFor:'running'!
    55 !ShowMeHowItWorks class methodsFor:'running'!
    56 
    56 
    57 do:specArray
    57 application:anApplicationOrNilForAll do:specArray 
    58     "spec contains a list of action commands (show: / moveTo: etc.)"
    58     "spec contains a list of action commands (show: / moveTo: etc.)"
    59 
    59 
    60     self new do:specArray
    60     self new 
       
    61         application:anApplicationOrNilForAll;
       
    62         do:specArray 
    61 
    63 
    62     "
    64     "
    63      ShowMeHowItWorks do:
    65      ShowMeHowItWorks do:
    64         #(
    66         #(
    65             (language: de)
    67             (language: de)
    69         )    
    71         )    
    70     "
    72     "
    71 
    73 
    72     "Created: / 19-07-2019 / 10:52:59 / Claus Gittinger"
    74     "Created: / 19-07-2019 / 10:52:59 / Claus Gittinger"
    73     "Modified (comment): / 23-07-2019 / 10:26:42 / Claus Gittinger"
    75     "Modified (comment): / 23-07-2019 / 10:26:42 / Claus Gittinger"
       
    76 !
       
    77 
       
    78 do:specArray
       
    79     "spec contains a list of action commands (show: / moveTo: etc.)"
       
    80 
       
    81     self new do:specArray
       
    82 
       
    83     "
       
    84      ShowMeHowItWorks do:
       
    85         #(
       
    86             (language: de)
       
    87             (show: 'üben üben üben')
       
    88             (wait: 0.5)
       
    89             (moveTo: NameOfComponent)
       
    90         )    
       
    91     "
       
    92 
       
    93     "Created: / 19-07-2019 / 10:52:59 / Claus Gittinger"
       
    94     "Modified (comment): / 23-07-2019 / 10:26:42 / Claus Gittinger"
    74 ! !
    95 ! !
    75 
    96 
    76 !ShowMeHowItWorks methodsFor:'accessing'!
    97 !ShowMeHowItWorks methodsFor:'accessing'!
    77 
    98 
    78 application:something
    99 application:anApplication
    79     application := something.
   100     "if set, only that application is presented (widget search is limtied to that one)"
       
   101 
       
   102     application := anApplication.
    80 ! !
   103 ! !
    81 
   104 
    82 !ShowMeHowItWorks methodsFor:'commands'!
   105 !ShowMeHowItWorks methodsFor:'commands'!
    83 
   106 
    84 intro
   107 intro
    85     <action>
   108     <action>
    86 
   109 
       
   110     verifying ifTrue:[^ self].
       
   111 
       
   112     IntroShownCount := (IntroShownCount ? 0).
       
   113 
    87     "/ only say this a few times..
   114     "/ only say this a few times..
    88     IntroShownCount := (IntroShownCount ? 0) + 1.
       
    89     IntroShownCount > 3 ifTrue:[^ self].
   115     IntroShownCount > 3 ifTrue:[^ self].
    90     
   116     IntroShownCount := IntroShownCount + 1.
       
   117 
       
   118     self language:(Smalltalk language).    
    91     self tell:(self class classResources 
   119     self tell:(self class classResources 
    92                 string:'You can stop this show, by pressing the SHIFT key').
   120                 string:'You can stop this show, by pressing the SHIFT key').
    93 
   121 
    94     "Created: / 19-07-2019 / 15:49:19 / Claus Gittinger"
   122     "Created: / 19-07-2019 / 15:49:19 / Claus Gittinger"
    95     "Modified: / 23-07-2019 / 11:06:13 / Claus Gittinger"
   123     "Modified: / 23-07-2019 / 11:06:13 / Claus Gittinger"
    98 language:lang
   126 language:lang
    99     <action>
   127     <action>
   100 
   128 
   101     voice := OperatingSystem bestVoiceForLanguage:lang.
   129     voice := OperatingSystem bestVoiceForLanguage:lang.
   102     translate := false.
   130     translate := false.
       
   131     language := lang.
   103 
   132 
   104     "Created: / 23-07-2019 / 10:27:02 / Claus Gittinger"
   133     "Created: / 23-07-2019 / 10:27:02 / Claus Gittinger"
   105 !
   134 !
   106 
   135 
   107 pause
   136 pause
   162                 talkDone signal
   191                 talkDone signal
   163             ] fork.
   192             ] fork.
   164             
   193             
   165             "/
   194             "/
   166             "/ allow speaker some headoff
   195             "/ allow speaker some headoff
   167             Delay waitForSeconds:(xLatedMessage size / 15)+0.5.
   196             verifying ifFalse:[
       
   197                 Delay waitForSeconds:(xLatedMessage size / 15)+0.5.
       
   198             ].
   168         ].
   199         ].
   169 
   200 
   170         operationsOrNothing notEmptyOrNil ifTrue:[
   201         operationsOrNothing notEmptyOrNil ifTrue:[
   171             self doStream:(operationsOrNothing readStream).
   202             self doStream:(operationsOrNothing readStream).
   172         ].
   203         ].
   190 !
   221 !
   191 
   222 
   192 wait:seconds
   223 wait:seconds
   193     <action>
   224     <action>
   194     
   225     
       
   226     verifying ifTrue:[^ self].
   195     Delay waitForSeconds:seconds
   227     Delay waitForSeconds:seconds
   196 
   228 
   197     "Created: / 19-07-2019 / 15:09:45 / Claus Gittinger"
   229     "Created: / 19-07-2019 / 15:09:45 / Claus Gittinger"
   198 ! !
   230 ! !
   199 
   231 
   307     "    
   339     "    
   308 
   340 
   309     <action>
   341     <action>
   310 
   342 
   311     |idx|
   343     |idx|
   312     
   344 
       
   345     verifying ifTrue:[^ self].
       
   346 
   313     (lastComponent isKindOf:ComboView) ifTrue:[
   347     (lastComponent isKindOf:ComboView) ifTrue:[
   314         "/ click on the menubutton
   348         "/ click on the menubutton
   315         self movePointerToComponent:lastComponent menuButton.
   349         self movePointerToComponent:lastComponent menuButton.
   316         self click:1 inComponent:lastComponent menuButton.
   350         self click:1 inComponent:lastComponent menuButton.
   317         Delay waitForSeconds:0.3.
   351         Delay waitForSeconds:0.3.
   354     "    
   388     "    
   355 
   389 
   356     <action>
   390     <action>
   357 
   391 
   358     |widget y offset possibleWidgets|
   392     |widget y offset possibleWidgets|
       
   393 
       
   394     verifying ifTrue:[^ self].
   359 
   395 
   360     (widget := widgetArg) isScrollWrapper ifTrue:[
   396     (widget := widgetArg) isScrollWrapper ifTrue:[
   361         widget := widget scrolledView
   397         widget := widget scrolledView
   362     ].
   398     ].
   363     
   399     
   423 type:aString
   459 type:aString
   424     "enter text into the last component"
   460     "enter text into the last component"
   425 
   461 
   426     <action>
   462     <action>
   427 
   463 
       
   464     verifying ifTrue:[^ self].
       
   465 
   428     lastComponent simulateTextInput:aString at:(lastComponent extent // 2) sendDisplayEvent:false
   466     lastComponent simulateTextInput:aString at:(lastComponent extent // 2) sendDisplayEvent:false
   429 
   467 
   430     "Created: / 19-07-2019 / 15:50:40 / Claus Gittinger"
   468     "Created: / 19-07-2019 / 15:50:40 / Claus Gittinger"
   431 ! !
   469 ! !
   432 
   470 
   498 
   536 
   499     "Created: / 19-07-2019 / 15:21:29 / Claus Gittinger"
   537     "Created: / 19-07-2019 / 15:21:29 / Claus Gittinger"
   500 !
   538 !
   501 
   539 
   502 talking
   540 talking
       
   541     verifying ifTrue:[^ false].
       
   542 
   503     "/ ^ Expecco::ExpeccoPreferences current speechEffectsEnabled
   543     "/ ^ Expecco::ExpeccoPreferences current speechEffectsEnabled
   504     ^ true
   544     ^ true
   505 
   545 
   506     "Created: / 19-07-2019 / 14:31:14 / Claus Gittinger"
   546     "Created: / 19-07-2019 / 14:31:14 / Claus Gittinger"
   507     "Modified (comment): / 23-07-2019 / 09:45:35 / Claus Gittinger"
   547     "Modified (comment): / 23-07-2019 / 09:45:35 / Claus Gittinger"
   512 randomThankYou
   552 randomThankYou
   513     ^ #(
   553     ^ #(
   514         'thank you, for watching'
   554         'thank you, for watching'
   515         'thank you for watching'
   555         'thank you for watching'
   516         'thank you'
   556         'thank you'
       
   557         'thanks'
   517         'have a good day'
   558         'have a good day'
       
   559         'have a nice day'
   518         'have fun'
   560         'have fun'
   519         'have fun with expecco'
   561         'have fun with expecco'
   520         'have fun with expecco, by the way: expecco comes from the latin word: peccare, which means: "to sin"'
   562         'have fun with expecco, by the way: expecco comes from the latin word: peccare, which means: "to sin"'
   521         'happy hacking'
   563         'happy hacking'
   522         'happy hacking, I hope you liked what you saw'
   564         'happy hacking, I hope you liked what you saw'
   523         'hope you liked it'
   565         'hope you liked it'
   524         'see you again'
   566         'see you again'
       
   567         'be the source with you'
       
   568         'be the force with you'
       
   569         'may the force be with you'
       
   570         'may the source be with you'
   525         'please give feedback, and let us know, if you liked it'
   571         'please give feedback, and let us know, if you liked it'
   526         'if you have any questions, please contact exept'
   572         'if you have any questions, please contact exept'
   527         'if you need more information, please take a look at the wiki'
   573         'if you need more information, please take a look at the wiki'
   528     ) atRandom
   574     ) atRandom
   529 
   575 
   530     "
   576     "
       
   577      OperatingSystem speak:'may the source be with you'
   531      OperatingSystem speak:'have fun with expecco'
   578      OperatingSystem speak:'have fun with expecco'
   532      OperatingSystem speak:'have fun with expecco, by the way: expecco comes from the latin word: peccare, which means: to sin'
   579      OperatingSystem speak:'have fun with expecco, by the way: expecco comes from the latin word: peccare, which means: to sin'
   533      OperatingSystem speak:'happy hacking, I hope you liked what you saw'
   580      OperatingSystem speak:'happy hacking, I hope you liked what you saw'
   534      OperatingSystem speak:'please give feedback, and let us know, if you liked it'
   581      OperatingSystem speak:'please give feedback, and let us know, if you liked it'
   535      OperatingSystem speak:'if you have any questions, please contact exept'
   582      OperatingSystem speak:'if you have any questions, please contact exept'
   552 
   599 
   553 click:buttonNr atPosition:position
   600 click:buttonNr atPosition:position
   554     "press-release at position"
   601     "press-release at position"
   555     
   602     
   556     |screen|
   603     |screen|
       
   604 
       
   605     verifying ifTrue:[^ self].
   557 
   606 
   558     screen := Screen current.
   607     screen := Screen current.
   559     
   608     
   560     screen setPointerPosition:position.    
   609     screen setPointerPosition:position.    
   561     screen flush.
   610     screen flush.
   611         
   660         
   612         candidates size == 1 ifTrue:[
   661         candidates size == 1 ifTrue:[
   613             component := candidates first
   662             component := candidates first
   614         ] ifFalse:[    
   663         ] ifFalse:[    
   615             candidates notEmpty ifTrue:[
   664             candidates notEmpty ifTrue:[
       
   665                 "/ multiple elements (probably there are multiple topviews open...
       
   666                 "/ check the current windowGroup
   616                 self error:'multiple components found by name: ',componentName.
   667                 self error:'multiple components found by name: ',componentName.
   617             ]    
   668             ]    
   618         ].    
   669         ].    
   619     ].    
   670     ].    
   620     ^ component
   671     ^ component
   722     |position|
   773     |position|
   723     
   774     
   724     aWidgetOrMenuItem isView ifTrue:[
   775     aWidgetOrMenuItem isView ifTrue:[
   725         position := aWidgetOrMenuItem screenBounds center rounded
   776         position := aWidgetOrMenuItem screenBounds center rounded
   726     ] ifFalse:[
   777     ] ifFalse:[
   727         self halt.
   778         self error:'not a widget: ',aWidgetOrMenuItem printString.
   728     ].    
   779     ].    
   729     self circlePointerAroundScreenPosition:position
   780     self circlePointerAroundScreenPosition:position
   730 
   781 
   731     "Created: / 19-07-2019 / 13:12:35 / Claus Gittinger"
   782     "Created: / 19-07-2019 / 13:12:35 / Claus Gittinger"
   732     "Modified: / 23-07-2019 / 09:38:12 / Claus Gittinger"
   783     "Modified: / 23-07-2019 / 09:38:12 / Claus Gittinger"
   734 
   785 
   735 circlePointerAroundScreenPosition:position
   786 circlePointerAroundScreenPosition:position
   736     "circle around it a few times"
   787     "circle around it a few times"
   737     
   788     
   738     |screen stepDelayTime numCircles circlingSpeed radius|
   789     |screen stepDelayTime numCircles circlingSpeed radius|
       
   790 
       
   791     verifying ifTrue:[^ self].
   739 
   792 
   740     screen := Screen current.
   793     screen := Screen current.
   741     
   794     
   742     circlingSpeed := self circlingSpeed.    "/ time per round
   795     circlingSpeed := self circlingSpeed.    "/ time per round
   743     numCircles := self circlingCount.
   796     numCircles := self circlingCount.
   802     |position|
   855     |position|
   803     
   856     
   804     aWidgetOrMenuItem isView ifTrue:[
   857     aWidgetOrMenuItem isView ifTrue:[
   805         position := aWidgetOrMenuItem screenBounds center rounded
   858         position := aWidgetOrMenuItem screenBounds center rounded
   806     ] ifFalse:[
   859     ] ifFalse:[
   807         self halt.
   860         self error:'not a widget: ',aWidgetOrMenuItem printString.
   808     ].    
   861     ].    
   809     self movePointerToScreenPosition:position speed:pixelsPerSecond.
   862     self movePointerToScreenPosition:position speed:pixelsPerSecond.
   810 
   863 
   811     "Created: / 20-07-2019 / 08:12:49 / Claus Gittinger"
   864     "Created: / 20-07-2019 / 08:12:49 / Claus Gittinger"
   812     "Modified: / 23-07-2019 / 09:37:27 / Claus Gittinger"
   865     "Modified: / 23-07-2019 / 09:37:27 / Claus Gittinger"
   822 
   875 
   823 movePointerToScreenPosition:newPosition speed:pixelsPerSecond
   876 movePointerToScreenPosition:newPosition speed:pixelsPerSecond
   824     "move the mouse to newPosition, which is a screen position"
   877     "move the mouse to newPosition, which is a screen position"
   825     
   878     
   826     |screen distance start numSteps moveTime stepDelayTime delta|
   879     |screen distance start numSteps moveTime stepDelayTime delta|
       
   880 
       
   881     verifying ifTrue:[^ self].
   827 
   882 
   828     screen := Screen current.
   883     screen := Screen current.
   829     start := screen pointerPosition.   
   884     start := screen pointerPosition.   
   830 
   885 
   831     distance := start dist:newPosition.
   886     distance := start dist:newPosition.
   870 !
   925 !
   871 
   926 
   872 click:buttonNr inComponent:component clickTime:clickTime 
   927 click:buttonNr inComponent:component clickTime:clickTime 
   873     "press-release in a component"
   928     "press-release in a component"
   874 
   929 
       
   930     self assert:component notNil.
       
   931     verifying ifTrue:[^ self].
       
   932 
   875     component simulateButtonPress:buttonNr at:(component extent // 2) sendDisplayEvent:false.
   933     component simulateButtonPress:buttonNr at:(component extent // 2) sendDisplayEvent:false.
   876     Delay waitForSeconds:clickTime.
   934     Delay waitForSeconds:clickTime.
   877     component simulateButtonRelease:buttonNr at:(component extent // 2) sendDisplayEvent:false.
   935     component simulateButtonRelease:buttonNr at:(component extent // 2) sendDisplayEvent:false.
   878 
   936 
   879 "/    self click:buttonNr atPosition:(component extent // 2)
   937 "/    self click:buttonNr atPosition:(component extent // 2)
   883 
   941 
   884 press:buttonNr
   942 press:buttonNr
   885     "press at the current position"
   943     "press at the current position"
   886     
   944     
   887     |position screen x y|
   945     |position screen x y|
       
   946 
       
   947     verifying ifTrue:[^ self].
   888 
   948 
   889     screen := Screen current.
   949     screen := Screen current.
   890     position := screen pointerPosition.
   950     position := screen pointerPosition.
   891     x := position x.
   951     x := position x.
   892     y := position y.
   952     y := position y.
   913 release:buttonNr
   973 release:buttonNr
   914     "press-release at the current position"
   974     "press-release at the current position"
   915     
   975     
   916     |position screen x y|
   976     |position screen x y|
   917 
   977 
       
   978     verifying ifTrue:[^ self].
       
   979 
   918     screen := Screen current.
   980     screen := Screen current.
   919     position := screen pointerPosition.
   981     position := screen pointerPosition.
   920     x := position x.
   982     x := position x.
   921     y := position y.
   983     y := position y.
   922     
   984     
   944 do:specArray
  1006 do:specArray
   945     "must run as a separate process;
  1007     "must run as a separate process;
   946      otherwise - if started by the app itself -
  1008      otherwise - if started by the app itself -
   947      no events will be processed while running"
  1009      no events will be processed while running"
   948 
  1010 
   949     self language:(Smalltalk language).
  1011     |wasActive|
       
  1012 
       
  1013     (wasActive := ActiveHelp isActive) ifTrue:[
       
  1014         ActiveHelp stop.
       
  1015     ].
       
  1016 
       
  1017     language isNil ifTrue:[
       
  1018         self language:(Smalltalk language).
       
  1019     ].
   950     translate := false.
  1020     translate := false.
   951     
  1021     
   952     application isNil ifTrue:[
  1022     application isNil ifTrue:[
   953         application := WindowGroup activeMainApplication.
  1023         application := WindowGroup activeMainApplication.
   954     ].
  1024     ].
   955     
  1025 
       
  1026     "/ run in verifying mode
       
  1027     verifying := true.
   956     [
  1028     [
   957         Error handle:[:ex |
  1029         Error handle:[:ex |
   958             Dialog warn:(self class classResources stringWithCRs:'An error was encountered in the show:\\%1' with:ex description)
  1030             (Dialog confirm:(self class classResources stringWithCRs:'Error encountered while verifying:\\%1\\Debug?' with:ex description))
       
  1031             ifTrue:[ex reject].
   959         ] do:[
  1032         ] do:[
   960             self doStream:(specArray readStream)
  1033             self doStream:(specArray readStream)
       
  1034         ].
       
  1035     ] ensure:[
       
  1036         verifying := false.
       
  1037         wasActive ifTrue:[ActiveHelp start].
       
  1038     ].
       
  1039 
       
  1040     [
       
  1041         ActiveHelp stop.
       
  1042         [
       
  1043             Error handle:[:ex |
       
  1044                 Dialog warn:(self class classResources stringWithCRs:'An error was encountered in the show:\\%1' with:ex description)
       
  1045             ] do:[
       
  1046                 self doStream:(specArray readStream)
       
  1047             ].
       
  1048         ] ensure:[
       
  1049             wasActive ifTrue:[ActiveHelp start].
   961         ].
  1050         ].
   962     ] fork.
  1051     ] fork.
   963 
  1052 
   964     "
  1053     "
   965      ShowMeHowItWorks do:
  1054      ShowMeHowItWorks do:
   969         )    
  1058         )    
   970     "
  1059     "
   971 
  1060 
   972     "Created: / 23-07-2019 / 10:24:53 / Claus Gittinger"
  1061     "Created: / 23-07-2019 / 10:24:53 / Claus Gittinger"
   973     "Modified: / 25-07-2019 / 11:48:53 / Claus Gittinger"
  1062     "Modified: / 25-07-2019 / 11:48:53 / Claus Gittinger"
   974 !
  1063 ! !
       
  1064 
       
  1065 !ShowMeHowItWorks methodsFor:'running - private'!
   975 
  1066 
   976 doCommand:op
  1067 doCommand:op
   977     "execute a single command"
  1068     "execute a single command"
   978     
  1069     
   979     |numArgs sel args method|
  1070     |numArgs sel args method|