ShowMeHowItWorks.st
changeset 3795 0b36f57fd1c9
parent 3794 49da17b54a22
child 3796 4ed3796c2d60
equal deleted inserted replaced
3794:49da17b54a22 3795:0b36f57fd1c9
     5 "{ NameSpace: Smalltalk }"
     5 "{ NameSpace: Smalltalk }"
     6 
     6 
     7 Object subclass:#ShowMeHowItWorks
     7 Object subclass:#ShowMeHowItWorks
     8 	instanceVariableNames:'application opStream streamStack lastComponentName lastComponent
     8 	instanceVariableNames:'application opStream streamStack lastComponentName lastComponent
     9 		lastResult voice translate language verifying
     9 		lastResult voice translate language verifying
    10 		closeApplicationWhenFinished defaultComponentWaitTime ui'
    10 		closeApplicationWhenFinished defaultComponentWaitTime ui
       
    11 		theShowFile'
    11 	classVariableNames:'IntroShownCount DebugMode StartLabel'
    12 	classVariableNames:'IntroShownCount DebugMode StartLabel'
    12 	poolDictionaries:''
    13 	poolDictionaries:''
    13 	category:'Interface-Help'
    14 	category:'Interface-Help'
    14 !
    15 !
    15 
    16 
    49         (showing: 'Enter a value (or expression) into "receiver" field' do:(
    50         (showing: 'Enter a value (or expression) into "receiver" field' do:(
    50             enter: '100'
    51             enter: '100'
    51         ))
    52         ))
    52 
    53 
    53     )
    54     )
       
    55 !
       
    56 
       
    57 scriptFormat
       
    58 "
       
    59 
       
    60     speaking:
       
    61         show:           'text'
       
    62 
       
    63     mouse movement:
       
    64         moveTo:         '<component>'       move there and circle around
       
    65         fastMoveTo:     '<component>'       move without circling
       
    66         (drag: '<fromComponent>' toComponent: '<toComponent>' dropAt:<pos> show:'text')
       
    67             pos is one of #topLeft, #topCenter, #topRght, #bottomLeft, #bottomCenter, #bottomRight
       
    68             text is spoken before the drop
       
    69 
       
    70     mouse actions:
       
    71         click
       
    72         click:          buttonNumber
       
    73         select:         itemsIndexOrLabelOrPattern
       
    74             itemsIndexOrLabelOrPattern can be an integer or text
       
    75 
       
    76     misc:
       
    77         wait:           seconds             just pause
       
    78 
       
    79         label:          'name'              for debugging, presentation can be started at some
       
    80                                             label, by setting the StartLabel class variable
       
    81 
       
    82         (waitFor: '<component>' timeout:seconds)
       
    83                                             wait for a component to appear
       
    84 
       
    85         open            'nameOfAppModelClass'
       
    86                                             open an application (class)
       
    87         intro           
       
    88 
       
    89 component naming:
       
    90     '<component>' can be:
       
    91         name of a component, as defined in the UI-spec's nameKey,
       
    92         helpKey
       
    93         title
       
    94         label
       
    95 
       
    96      a path like 'ProjectTree/ToolBar' will first find ProjectTrue, then ToolBar
       
    97      a menu item index like 'Toolbar/item[idx]'
       
    98 
       
    99 
       
   100 "
    54 ! !
   101 ! !
    55 
   102 
    56 !ShowMeHowItWorks class methodsFor:'running'!
   103 !ShowMeHowItWorks class methodsFor:'running'!
    57 
   104 
    58 application:anApplicationOrNilForAll do:specArray 
   105 application:anApplicationOrNilForAll do:specArray 
    59     "spec contains a list of action commands (show: / moveTo: etc.)"
   106     "spec contains a list of action commands (show: / moveTo: etc.)"
    60 
   107 
    61     self new 
   108     self new 
    62         application:anApplicationOrNilForAll;
   109         application:anApplicationOrNilForAll;
    63         do:specArray 
   110         do:specArray 
       
   111 
       
   112     "
       
   113      ShowMeHowItWorks do:
       
   114         #(
       
   115             (language: de)
       
   116             (show: 'üben üben üben')
       
   117             (wait: 0.5)
       
   118             (moveTo: NameOfComponent)
       
   119         )    
       
   120     "
       
   121 
       
   122     "Created: / 19-07-2019 / 10:52:59 / Claus Gittinger"
       
   123     "Modified (comment): / 23-07-2019 / 10:26:42 / Claus Gittinger"
       
   124 !
       
   125 
       
   126 application:anApplicationOrNilForAll doShowFile:aFilename 
       
   127     "spec contains a list of action commands (show: / moveTo: etc.)"
       
   128 
       
   129     self new 
       
   130         application:anApplicationOrNilForAll;
       
   131         doShowFile:aFilename 
    64 
   132 
    65     "
   133     "
    66      ShowMeHowItWorks do:
   134      ShowMeHowItWorks do:
    67         #(
   135         #(
    68             (language: de)
   136             (language: de)
   142 
   210 
   143 application:anApplication
   211 application:anApplication
   144     "if set, only that application is presented (widget search is limtied to that one)"
   212     "if set, only that application is presented (widget search is limtied to that one)"
   145 
   213 
   146     application := anApplication.
   214     application := anApplication.
       
   215 !
       
   216 
       
   217 setLanguage:lang
       
   218     voice := OperatingSystem bestVoiceForLanguage:lang.
       
   219     language := lang.
       
   220 
       
   221     "Created: / 23-07-2019 / 10:27:02 / Claus Gittinger"
   147 ! !
   222 ! !
   148 
   223 
   149 !ShowMeHowItWorks methodsFor:'commands'!
   224 !ShowMeHowItWorks methodsFor:'commands'!
   150 
   225 
   151 intro
   226 intro
   157 
   232 
   158     "/ only say this a few times..
   233     "/ only say this a few times..
   159     IntroShownCount > 3 ifTrue:[^ self].
   234     IntroShownCount > 3 ifTrue:[^ self].
   160     IntroShownCount := IntroShownCount + 1.
   235     IntroShownCount := IntroShownCount + 1.
   161 
   236 
   162     self language:(Smalltalk language).    
   237     language isNil ifTrue:[
       
   238         self setLanguage:(Smalltalk language). 
       
   239     ].
   163     self tell:(self class classResources 
   240     self tell:(self class classResources 
   164                 string:'You can stop this show, by pressing the SHIFT key').
   241                 string:'You can stop this show, by pressing the SHIFT key').
   165 
   242 
   166     "Created: / 19-07-2019 / 15:49:19 / Claus Gittinger"
   243     "Created: / 19-07-2019 / 15:49:19 / Claus Gittinger"
   167     "Modified: / 23-07-2019 / 11:06:13 / Claus Gittinger"
   244     "Modified: / 23-07-2019 / 11:06:13 / Claus Gittinger"
   174 !
   251 !
   175 
   252 
   176 language:lang
   253 language:lang
   177     <action>
   254     <action>
   178 
   255 
   179     voice := OperatingSystem bestVoiceForLanguage:lang.
   256     self setLanguage:lang.
   180     translate := false.
   257     translate := false.
   181     language := lang.
       
   182 
   258 
   183     "Created: / 23-07-2019 / 10:27:02 / Claus Gittinger"
   259     "Created: / 23-07-2019 / 10:27:02 / Claus Gittinger"
   184 !
   260 !
   185 
   261 
   186 open:applicationClassName
   262 open:applicationClassName
   617     Display ctrlDown ifTrue:[^ self].
   693     Display ctrlDown ifTrue:[^ self].
   618     self circlePointerAroundComponent:component.
   694     self circlePointerAroundComponent:component.
   619 
   695 
   620     "Created: / 19-07-2019 / 11:20:42 / Claus Gittinger"
   696     "Created: / 19-07-2019 / 11:20:42 / Claus Gittinger"
   621     "Modified: / 19-07-2019 / 15:38:11 / Claus Gittinger"
   697     "Modified: / 19-07-2019 / 15:38:11 / Claus Gittinger"
       
   698 !
       
   699 
       
   700 press:buttonNr
       
   701     <action>
       
   702 
       
   703     "press at the current position"
       
   704 
       
   705     self assert:(buttonNr isInteger).
       
   706     ^ self press:buttonNr inComponent:lastComponent.
       
   707 
       
   708 "/    "press at the current position"
       
   709 "/
       
   710 "/    |position screen x y|
       
   711 "/
       
   712 "/    verifying ifTrue:[^ self].
       
   713 "/
       
   714 "/    screen := Screen current.
       
   715 "/    position := screen pointerPosition.
       
   716 "/    x := position x.
       
   717 "/    y := position y.
       
   718 "/
       
   719 "/    "/ self movePointerToScreenPosition:position.
       
   720 "/
       
   721 "/    false "OperatingSystem isOSXlike" ifTrue:[
       
   722 "/        |osxPos|
       
   723 "/
       
   724 "/        osxPos := OperatingSystem getMousePosition.
       
   725 "/        x := osxPos x rounded.
       
   726 "/        y := osxPos y rounded.
       
   727 "/        OperatingSystem generateButtonEvent:buttonNr down:true x:x y:y.
       
   728 "/        ^ self.
       
   729 "/    ].
       
   730 "/
       
   731 "/    screen sendKeyOrButtonEvent:#buttonPress x:x y:y keyOrButton:buttonNr state:0 toViewId:(screen rootWindowId).
       
   732 "/    screen flush.
       
   733 "/
       
   734 "/    "Created: / 19-07-2019 / 13:52:38 / Claus Gittinger"
       
   735 "/    "Modified: / 23-07-2019 / 09:38:31 / Claus Gittinger"
       
   736 !
       
   737 
       
   738 release:buttonNr
       
   739     <action>
       
   740 
       
   741     "release at the current position"
       
   742     
       
   743     <action>
       
   744 
       
   745     self assert:(buttonNr isInteger).
       
   746     ^ self press:buttonNr inComponent:lastComponent.
       
   747 "/    |position screen x y|
       
   748 "/
       
   749 "/    verifying ifTrue:[^ self].
       
   750 "/
       
   751 "/    screen := Screen current.
       
   752 "/    position := screen pointerPosition.
       
   753 "/    x := position x.
       
   754 "/    y := position y.
       
   755 "/    
       
   756 "/    self movePointerToScreenPosition:position.
       
   757 "/
       
   758 "/    false "OperatingSystem isOSXlike" ifTrue:[
       
   759 "/        |osxPos|
       
   760 "/
       
   761 "/        osxPos := OperatingSystem getMousePosition.
       
   762 "/        x := osxPos x rounded.
       
   763 "/        y := osxPos y rounded.
       
   764 "/        OperatingSystem generateButtonEvent:buttonNr down:false x:x y:y.
       
   765 "/        ^ self.
       
   766 "/    ].
       
   767 "/
       
   768 "/    screen sendKeyOrButtonEvent:#buttonRelease x:x y:y keyOrButton:buttonNr state:0 toViewId:(screen rootWindowId).
       
   769 "/    screen flush.
       
   770 
       
   771     "Created: / 19-07-2019 / 13:53:05 / Claus Gittinger"
       
   772     "Modified: / 23-07-2019 / 09:38:38 / Claus Gittinger"
   622 !
   773 !
   623 
   774 
   624 select:itemsIndexOrLabelOrPattern
   775 select:itemsIndexOrLabelOrPattern
   625     "select an item by label,
   776     "select an item by label,
   626      allowed after moving to:
   777      allowed after moving to:
  1245     "press-release in a component"
  1396     "press-release in a component"
  1246 
  1397 
  1247     |t|
  1398     |t|
  1248 
  1399 
  1249     t := self shortClickTime.
  1400     t := self shortClickTime.
  1250     (component isKindOf:Button) ifTrue:[
  1401     ((component isKindOf:Button) 
       
  1402       or:[(component askFor:#isMenuItem)]
       
  1403     )ifTrue:[
  1251         t := self longClickTime
  1404         t := self longClickTime
  1252     ].    
  1405     ].    
  1253     self click:buttonNr inComponent:component clickTime:t
  1406     self click:buttonNr inComponent:component clickTime:t
  1254 
  1407 
  1255     "Created: / 19-07-2019 / 13:18:27 / Claus Gittinger"
  1408     "Created: / 19-07-2019 / 13:18:27 / Claus Gittinger"
  1256     "Modified: / 19-07-2019 / 15:22:47 / Claus Gittinger"
  1409     "Modified: / 19-07-2019 / 15:22:47 / Claus Gittinger"
  1257 !
  1410 !
  1258 
  1411 
  1259 click:buttonNr inComponent:viewOrMenuItem clickTime:clickTime 
  1412 click:buttonNr inComponent:viewOrMenuItem clickTime:clickTime 
  1260     "press-release in a component"
  1413     "press-release in a component"
       
  1414 
       
  1415     self withViewAndPositionFor:viewOrMenuItem do:[:viewToClick :clickPos |
       
  1416         viewToClick simulateButtonPress:buttonNr at:clickPos sendDisplayEvent:false.
       
  1417         Delay waitForSeconds:clickTime.
       
  1418         viewToClick simulateButtonRelease:buttonNr at:clickPos sendDisplayEvent:false.
       
  1419     ].
       
  1420 !
       
  1421 
       
  1422 press:buttonNr inComponent:viewOrMenuItem 
       
  1423     "press in a component"
       
  1424 
       
  1425     self withViewAndPositionFor:viewOrMenuItem do:[:viewToClick :clickPos |
       
  1426         viewToClick simulateButtonPress:buttonNr at:clickPos sendDisplayEvent:false.
       
  1427     ]
       
  1428 !
       
  1429 
       
  1430 release:buttonNr inComponent:viewOrMenuItem 
       
  1431     "release in a component"
       
  1432 
       
  1433     self withViewAndPositionFor:viewOrMenuItem do:[:viewToClick :clickPos |
       
  1434         viewToClick simulateButtonRelease:buttonNr at:clickPos sendDisplayEvent:false.
       
  1435     ]
       
  1436 !
       
  1437 
       
  1438 withViewAndPositionFor:viewOrMenuItem do:aBlock
       
  1439     "helper for click, press and release"
  1261 
  1440 
  1262     |viewToClick clickPos|
  1441     |viewToClick clickPos|
  1263 
  1442 
  1264     self assert:viewOrMenuItem notNil.
  1443     self assert:viewOrMenuItem notNil.
  1265     verifying ifTrue:[^ self].
  1444     verifying ifTrue:[^ self].
  1270         self assert:(clickPos notNil).
  1449         self assert:(clickPos notNil).
  1271     ] ifFalse:[
  1450     ] ifFalse:[
  1272         viewToClick := viewOrMenuItem.
  1451         viewToClick := viewOrMenuItem.
  1273         clickPos := viewToClick extent // 2.
  1452         clickPos := viewToClick extent // 2.
  1274     ].
  1453     ].
  1275 
  1454     aBlock value:viewToClick value:clickPos.
  1276     viewToClick simulateButtonPress:buttonNr at:clickPos sendDisplayEvent:false.
       
  1277     Delay waitForSeconds:clickTime.
       
  1278     viewToClick simulateButtonRelease:buttonNr at:clickPos sendDisplayEvent:false.
       
  1279 
       
  1280 "/    self click:buttonNr atPosition:(component extent // 2)
       
  1281 
       
  1282     "Created: / 19-07-2019 / 15:21:05 / Claus Gittinger"
       
  1283 !
       
  1284 
       
  1285 press:buttonNr
       
  1286     "press at the current position"
       
  1287     
       
  1288     |position screen x y|
       
  1289 
       
  1290     verifying ifTrue:[^ self].
       
  1291 
       
  1292     screen := Screen current.
       
  1293     position := screen pointerPosition.
       
  1294     x := position x.
       
  1295     y := position y.
       
  1296     
       
  1297     "/ self movePointerToScreenPosition:position.
       
  1298 
       
  1299     false "OperatingSystem isOSXlike" ifTrue:[
       
  1300         |osxPos|
       
  1301 
       
  1302         osxPos := OperatingSystem getMousePosition.
       
  1303         x := osxPos x rounded.
       
  1304         y := osxPos y rounded.
       
  1305         OperatingSystem generateButtonEvent:buttonNr down:true x:x y:y.
       
  1306         ^ self.
       
  1307     ].
       
  1308 
       
  1309     screen sendKeyOrButtonEvent:#buttonPress x:x y:y keyOrButton:buttonNr state:0 toViewId:(screen rootWindowId).
       
  1310     screen flush.
       
  1311 
       
  1312     "Created: / 19-07-2019 / 13:52:38 / Claus Gittinger"
       
  1313     "Modified: / 23-07-2019 / 09:38:31 / Claus Gittinger"
       
  1314 !
       
  1315 
       
  1316 release:buttonNr
       
  1317     "press-release at the current position"
       
  1318     
       
  1319     |position screen x y|
       
  1320 
       
  1321     verifying ifTrue:[^ self].
       
  1322 
       
  1323     screen := Screen current.
       
  1324     position := screen pointerPosition.
       
  1325     x := position x.
       
  1326     y := position y.
       
  1327     
       
  1328     "/ self movePointerToScreenPosition:position.
       
  1329 
       
  1330     false "OperatingSystem isOSXlike" ifTrue:[
       
  1331         |osxPos|
       
  1332 
       
  1333         osxPos := OperatingSystem getMousePosition.
       
  1334         x := osxPos x rounded.
       
  1335         y := osxPos y rounded.
       
  1336         OperatingSystem generateButtonEvent:buttonNr down:false x:x y:y.
       
  1337         ^ self.
       
  1338     ].
       
  1339 
       
  1340     screen sendKeyOrButtonEvent:#buttonRelease x:x y:y keyOrButton:buttonNr state:0 toViewId:(screen rootWindowId).
       
  1341     screen flush.
       
  1342 
       
  1343     "Created: / 19-07-2019 / 13:53:05 / Claus Gittinger"
       
  1344     "Modified: / 23-07-2019 / 09:38:38 / Claus Gittinger"
       
  1345 ! !
  1455 ! !
  1346 
  1456 
  1347 !ShowMeHowItWorks methodsFor:'helpers - mouse movement'!
  1457 !ShowMeHowItWorks methodsFor:'helpers - mouse movement'!
  1348 
  1458 
  1349 circlePointerAroundComponent:aWidgetOrMenuItem
  1459 circlePointerAroundComponent:aWidgetOrMenuItem
  1587 
  1697 
  1588     "Created: / 23-07-2019 / 10:24:53 / Claus Gittinger"
  1698     "Created: / 23-07-2019 / 10:24:53 / Claus Gittinger"
  1589     "Modified: / 25-07-2019 / 11:48:53 / Claus Gittinger"
  1699     "Modified: / 25-07-2019 / 11:48:53 / Claus Gittinger"
  1590 !
  1700 !
  1591 
  1701 
       
  1702 doShowFile:aFilename
       
  1703     "the file from which the show was loaded"
       
  1704 
       
  1705     |spec|
       
  1706 
       
  1707     theShowFile := aFilename.
       
  1708     aFilename readingFileWithEncoding:#utf8 do:[:s |
       
  1709         spec := Array readFrom:s.
       
  1710     ].
       
  1711     self do:spec.
       
  1712 
       
  1713 
       
  1714 !
       
  1715 
  1592 prepare
  1716 prepare
  1593     language isNil ifTrue:[
  1717     language isNil ifTrue:[
  1594         self language:(Smalltalk language).
  1718         self setLanguage:(Smalltalk language).
  1595     ].
  1719     ].
  1596     translate := false.
  1720     translate := false.
  1597     
  1721     
  1598     application isNil ifTrue:[
  1722     application isNil ifTrue:[
  1599         application := WindowGroup activeMainApplication.
  1723         application := WindowGroup activeMainApplication.