forked from ObjectProfile/PythonBridge
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPBCommand.class.st
More file actions
110 lines (93 loc) · 2.03 KB
/
PBCommand.class.st
File metadata and controls
110 lines (93 loc) · 2.03 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
101
102
103
104
105
106
107
108
109
110
Class {
#name : #PBCommand,
#superclass : #Object,
#instVars : [
'id',
'instructions',
'bindings',
'observers',
'promise',
'transformBlock'
],
#category : #'PythonBridge-Execution'
}
{ #category : #accessing }
PBCommand >> bindings [
^ bindings
]
{ #category : #accessing }
PBCommand >> bindings: bindingCol [
bindings := bindingCol
]
{ #category : #accessing }
PBCommand >> bindingsDictionary [
^ self bindings asDictionary
]
{ #category : #accessing }
PBCommand >> getObserver: observerId [
^ observers detect: [ :obs | obs id = observerId ]
]
{ #category : #accessing }
PBCommand >> id [
^ id
]
{ #category : #accessing }
PBCommand >> id: anObject [
id := anObject
]
{ #category : #initialization }
PBCommand >> initialize [
super initialize.
id := PBPlatform current newRandomName.
bindings := #().
observers := #().
instructions := OrderedCollection new.
transformBlock := #yourself
]
{ #category : #accessing }
PBCommand >> instructions [
^ instructions
]
{ #category : #accessing }
PBCommand >> instructions: anObject [
instructions := anObject
]
{ #category : #testing }
PBCommand >> isValid [
^ [ self id isString and: [
(self bindings allSatisfy: [ :assoc | assoc key isString ]) and: [
self observers allSatisfy: [ :obs | obs callback isBlock ] ] ] ] on: Error do: [ false ]
]
{ #category : #accessing }
PBCommand >> observers [
^ observers
]
{ #category : #accessing }
PBCommand >> observers: anObject [
observers := anObject
]
{ #category : #accessing }
PBCommand >> promise [
^ promise
]
{ #category : #accessing }
PBCommand >> promise: anObject [
promise := anObject
]
{ #category : #'as yet unclassified' }
PBCommand >> pythonCode [
| py3CodeStream |
py3CodeStream := String new writeStream.
self instructions do: [ :instr |
instr writePython3On: py3CodeStream.
py3CodeStream << String lf ].
^ py3CodeStream contents
]
{ #category : #accessing }
PBCommand >> transformBlock [
^ transformBlock
]
{ #category : #accessing }
PBCommand >> transformBlock: anObject [
transformBlock := anObject
]