|
| 1 | +" |
| 2 | +PBCommandStringFactory is variant of the command factory that takes two strings to build the set of statements: |
| 3 | +
|
| 4 | +- script: a python script that will be evaluated on the remote. |
| 5 | +- resultExpression: a single python expression whose value will be returned. |
| 6 | +
|
| 7 | +Note that PBCommandStringFactory no longer uses the instructions instance variable from ${class:name=PBCommandFactory}$. |
| 8 | +
|
| 9 | +Example usage: |
| 10 | +
|
| 11 | +[[[ |
| 12 | +self application newCommandStringFactory |
| 13 | + script: |
| 14 | +'a = 4 |
| 15 | +b = 3'; |
| 16 | + resultExpression: 'a + b'; |
| 17 | + sendAndWait |
| 18 | +]]] |
| 19 | +" |
| 20 | +Class { |
| 21 | + #name : #PBCommandStringFactory, |
| 22 | + #superclass : #PBCommandFactory, |
| 23 | + #instVars : [ |
| 24 | + 'script', |
| 25 | + 'resultExpression' |
| 26 | + ], |
| 27 | + #category : #'PythonBridge-Execution' |
| 28 | +} |
| 29 | + |
| 30 | +{ #category : #streaming } |
| 31 | +PBCommandStringFactory >> << anObject [ |
| 32 | + |
| 33 | + self error: 'PBCommandStringFactory expects a single python script' |
| 34 | +] |
| 35 | + |
| 36 | +{ #category : #api } |
| 37 | +PBCommandStringFactory >> addAllBindings: aDictionary [ |
| 38 | + "Add the supplied key / value pairs as bindings to the receiver" |
| 39 | + |
| 40 | + aDictionary keysAndValuesDo: [ :key :value | |
| 41 | + self bindingAt: key put: value ] |
| 42 | +] |
| 43 | + |
| 44 | +{ #category : #streaming } |
| 45 | +PBCommandStringFactory >> append: aPythonStatement [ |
| 46 | + |
| 47 | + self error: 'PBCommandStringFactory expects a single python script' |
| 48 | +] |
| 49 | + |
| 50 | +{ #category : #accessing } |
| 51 | +PBCommandStringFactory >> instructionsWithNotifyAtEnd [ |
| 52 | + |
| 53 | + ^ String streamContents: [ :stream | |
| 54 | + stream |
| 55 | + << script withUnixLineEndings; |
| 56 | + lf; |
| 57 | + << 'notify('; |
| 58 | + << resultExpression; |
| 59 | + << ', '; |
| 60 | + print: command id; |
| 61 | + << ')' ]. |
| 62 | + |
| 63 | +] |
| 64 | + |
| 65 | +{ #category : #initialization } |
| 66 | +PBCommandStringFactory >> reset [ |
| 67 | + script := ''. |
| 68 | + resultExpression := #None. |
| 69 | + bindingsDictionary := Dictionary new. |
| 70 | + observers := OrderedCollection new. |
| 71 | + command := PBCommandString new. |
| 72 | + transformBlock := #yourself |
| 73 | +] |
| 74 | + |
| 75 | +{ #category : #accessing } |
| 76 | +PBCommandStringFactory >> resultExpression [ |
| 77 | + <return: #String> |
| 78 | + |
| 79 | + ^ resultExpression |
| 80 | +] |
| 81 | + |
| 82 | +{ #category : #accessing } |
| 83 | +PBCommandStringFactory >> resultExpression: aString [ |
| 84 | + |
| 85 | + resultExpression := aString |
| 86 | +] |
| 87 | + |
| 88 | +{ #category : #accessing } |
| 89 | +PBCommandStringFactory >> script [ |
| 90 | + <return: #String> |
| 91 | + |
| 92 | + ^ script |
| 93 | +] |
| 94 | + |
| 95 | +{ #category : #accessing } |
| 96 | +PBCommandStringFactory >> script: aString [ |
| 97 | + "Set the Python script to be executed on the remote" |
| 98 | + |
| 99 | + script := aString |
| 100 | +] |
0 commit comments