#FEATURE by exept
authorClaus Gittinger <cg@exept.de>
Tue, 01 Oct 2019 20:03:56 +0200
changeset 3775 0e44d27ee647
parent 3774 271887d2ed74
child 3776 371ad059085a
#FEATURE by exept class: ShowMeHowItWorks class definition comment/format in: #application: #findComponent: #intro changed:17 methods category of: #doCommand: #doStream: #nextCommand #possiblyTranslate: class: ShowMeHowItWorks class added: #application:do:
ShowMeHowItWorks.st
--- a/ShowMeHowItWorks.st	Tue Oct 01 10:53:24 2019 +0200
+++ b/ShowMeHowItWorks.st	Tue Oct 01 20:03:56 2019 +0200
@@ -6,7 +6,7 @@
 
 Object subclass:#ShowMeHowItWorks
 	instanceVariableNames:'application opStream lastComponentName lastComponent lastResult
-		voice translate'
+		voice translate language verifying'
 	classVariableNames:'IntroShownCount'
 	poolDictionaries:''
 	category:'Interface-Help'
@@ -54,6 +54,27 @@
 
 !ShowMeHowItWorks class methodsFor:'running'!
 
+application:anApplicationOrNilForAll do:specArray 
+    "spec contains a list of action commands (show: / moveTo: etc.)"
+
+    self new 
+        application:anApplicationOrNilForAll;
+        do:specArray 
+
+    "
+     ShowMeHowItWorks do:
+        #(
+            (language: de)
+            (show: 'üben üben üben')
+            (wait: 0.5)
+            (moveTo: NameOfComponent)
+        )    
+    "
+
+    "Created: / 19-07-2019 / 10:52:59 / Claus Gittinger"
+    "Modified (comment): / 23-07-2019 / 10:26:42 / Claus Gittinger"
+!
+
 do:specArray
     "spec contains a list of action commands (show: / moveTo: etc.)"
 
@@ -75,8 +96,10 @@
 
 !ShowMeHowItWorks methodsFor:'accessing'!
 
-application:something
-    application := something.
+application:anApplication
+    "if set, only that application is presented (widget search is limtied to that one)"
+
+    application := anApplication.
 ! !
 
 !ShowMeHowItWorks methodsFor:'commands'!
@@ -84,10 +107,15 @@
 intro
     <action>
 
+    verifying ifTrue:[^ self].
+
+    IntroShownCount := (IntroShownCount ? 0).
+
     "/ only say this a few times..
-    IntroShownCount := (IntroShownCount ? 0) + 1.
     IntroShownCount > 3 ifTrue:[^ self].
-    
+    IntroShownCount := IntroShownCount + 1.
+
+    self language:(Smalltalk language).    
     self tell:(self class classResources 
                 string:'You can stop this show, by pressing the SHIFT key').
 
@@ -100,6 +128,7 @@
 
     voice := OperatingSystem bestVoiceForLanguage:lang.
     translate := false.
+    language := lang.
 
     "Created: / 23-07-2019 / 10:27:02 / Claus Gittinger"
 !
@@ -164,7 +193,9 @@
             
             "/
             "/ allow speaker some headoff
-            Delay waitForSeconds:(xLatedMessage size / 15)+0.5.
+            verifying ifFalse:[
+                Delay waitForSeconds:(xLatedMessage size / 15)+0.5.
+            ].
         ].
 
         operationsOrNothing notEmptyOrNil ifTrue:[
@@ -192,6 +223,7 @@
 wait:seconds
     <action>
     
+    verifying ifTrue:[^ self].
     Delay waitForSeconds:seconds
 
     "Created: / 19-07-2019 / 15:09:45 / Claus Gittinger"
@@ -309,7 +341,9 @@
     <action>
 
     |idx|
-    
+
+    verifying ifTrue:[^ self].
+
     (lastComponent isKindOf:ComboView) ifTrue:[
         "/ click on the menubutton
         self movePointerToComponent:lastComponent menuButton.
@@ -357,6 +391,8 @@
 
     |widget y offset possibleWidgets|
 
+    verifying ifTrue:[^ self].
+
     (widget := widgetArg) isScrollWrapper ifTrue:[
         widget := widget scrolledView
     ].
@@ -425,6 +461,8 @@
 
     <action>
 
+    verifying ifTrue:[^ self].
+
     lastComponent simulateTextInput:aString at:(lastComponent extent // 2) sendDisplayEvent:false
 
     "Created: / 19-07-2019 / 15:50:40 / Claus Gittinger"
@@ -500,6 +538,8 @@
 !
 
 talking
+    verifying ifTrue:[^ false].
+
     "/ ^ Expecco::ExpeccoPreferences current speechEffectsEnabled
     ^ true
 
@@ -514,7 +554,9 @@
         'thank you, for watching'
         'thank you for watching'
         'thank you'
+        'thanks'
         'have a good day'
+        'have a nice day'
         'have fun'
         'have fun with expecco'
         'have fun with expecco, by the way: expecco comes from the latin word: peccare, which means: "to sin"'
@@ -522,12 +564,17 @@
         'happy hacking, I hope you liked what you saw'
         'hope you liked it'
         'see you again'
+        'be the source with you'
+        'be the force with you'
+        'may the force be with you'
+        'may the source be with you'
         'please give feedback, and let us know, if you liked it'
         'if you have any questions, please contact exept'
         'if you need more information, please take a look at the wiki'
     ) atRandom
 
     "
+     OperatingSystem speak:'may the source be with you'
      OperatingSystem speak:'have fun with expecco'
      OperatingSystem speak:'have fun with expecco, by the way: expecco comes from the latin word: peccare, which means: to sin'
      OperatingSystem speak:'happy hacking, I hope you liked what you saw'
@@ -555,6 +602,8 @@
     
     |screen|
 
+    verifying ifTrue:[^ self].
+
     screen := Screen current.
     
     screen setPointerPosition:position.    
@@ -613,6 +662,8 @@
             component := candidates first
         ] ifFalse:[    
             candidates notEmpty ifTrue:[
+                "/ multiple elements (probably there are multiple topviews open...
+                "/ check the current windowGroup
                 self error:'multiple components found by name: ',componentName.
             ]    
         ].    
@@ -724,7 +775,7 @@
     aWidgetOrMenuItem isView ifTrue:[
         position := aWidgetOrMenuItem screenBounds center rounded
     ] ifFalse:[
-        self halt.
+        self error:'not a widget: ',aWidgetOrMenuItem printString.
     ].    
     self circlePointerAroundScreenPosition:position
 
@@ -737,6 +788,8 @@
     
     |screen stepDelayTime numCircles circlingSpeed radius|
 
+    verifying ifTrue:[^ self].
+
     screen := Screen current.
     
     circlingSpeed := self circlingSpeed.    "/ time per round
@@ -804,7 +857,7 @@
     aWidgetOrMenuItem isView ifTrue:[
         position := aWidgetOrMenuItem screenBounds center rounded
     ] ifFalse:[
-        self halt.
+        self error:'not a widget: ',aWidgetOrMenuItem printString.
     ].    
     self movePointerToScreenPosition:position speed:pixelsPerSecond.
 
@@ -825,6 +878,8 @@
     
     |screen distance start numSteps moveTime stepDelayTime delta|
 
+    verifying ifTrue:[^ self].
+
     screen := Screen current.
     start := screen pointerPosition.   
 
@@ -872,6 +927,9 @@
 click:buttonNr inComponent:component clickTime:clickTime 
     "press-release in a component"
 
+    self assert:component notNil.
+    verifying ifTrue:[^ self].
+
     component simulateButtonPress:buttonNr at:(component extent // 2) sendDisplayEvent:false.
     Delay waitForSeconds:clickTime.
     component simulateButtonRelease:buttonNr at:(component extent // 2) sendDisplayEvent:false.
@@ -886,6 +944,8 @@
     
     |position screen x y|
 
+    verifying ifTrue:[^ self].
+
     screen := Screen current.
     position := screen pointerPosition.
     x := position x.
@@ -915,6 +975,8 @@
     
     |position screen x y|
 
+    verifying ifTrue:[^ self].
+
     screen := Screen current.
     position := screen pointerPosition.
     x := position x.
@@ -946,19 +1008,46 @@
      otherwise - if started by the app itself -
      no events will be processed while running"
 
-    self language:(Smalltalk language).
+    |wasActive|
+
+    (wasActive := ActiveHelp isActive) ifTrue:[
+        ActiveHelp stop.
+    ].
+
+    language isNil ifTrue:[
+        self language:(Smalltalk language).
+    ].
     translate := false.
     
     application isNil ifTrue:[
         application := WindowGroup activeMainApplication.
     ].
-    
+
+    "/ run in verifying mode
+    verifying := true.
     [
         Error handle:[:ex |
-            Dialog warn:(self class classResources stringWithCRs:'An error was encountered in the show:\\%1' with:ex description)
+            (Dialog confirm:(self class classResources stringWithCRs:'Error encountered while verifying:\\%1\\Debug?' with:ex description))
+            ifTrue:[ex reject].
         ] do:[
             self doStream:(specArray readStream)
         ].
+    ] ensure:[
+        verifying := false.
+        wasActive ifTrue:[ActiveHelp start].
+    ].
+
+    [
+        ActiveHelp stop.
+        [
+            Error handle:[:ex |
+                Dialog warn:(self class classResources stringWithCRs:'An error was encountered in the show:\\%1' with:ex description)
+            ] do:[
+                self doStream:(specArray readStream)
+            ].
+        ] ensure:[
+            wasActive ifTrue:[ActiveHelp start].
+        ].
     ] fork.
 
     "
@@ -971,7 +1060,9 @@
 
     "Created: / 23-07-2019 / 10:24:53 / Claus Gittinger"
     "Modified: / 25-07-2019 / 11:48:53 / Claus Gittinger"
-!
+! !
+
+!ShowMeHowItWorks methodsFor:'running - private'!
 
 doCommand:op
     "execute a single command"