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