forked from ObjectProfile/PythonBridge
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPBApplication.class.st
More file actions
245 lines (204 loc) · 5.82 KB
/
PBApplication.class.st
File metadata and controls
245 lines (204 loc) · 5.82 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
Class {
#name : #PBApplication,
#superclass : #LanguageLinkApplication,
#classVars : [
'DebugMode'
],
#category : #'PythonBridge-Global'
}
{ #category : #accessing }
PBApplication class >> baseApplication [
^ PBApplication
]
{ #category : #debug }
PBApplication class >> debugMode [
^ DebugMode ifNil: [ false ]
]
{ #category : #debug }
PBApplication class >> debugMode: bool [
^ DebugMode := bool
]
{ #category : #initialization }
PBApplication class >> initialize [
SessionManager default registerToolClassNamed: self name
]
{ #category : #testing }
PBApplication class >> isWorking [
"Return true if my uniqueInstance works by evaluating 1+2 and checking the result is 3"
^ (self do: [ :app |
app newCommandFactory
<< (P3GBinaryOperator new
left: 1;
right: 2;
operator: $+;
yourself);
sendAndWait ]) = 3
]
{ #category : #accessing }
PBApplication class >> runtimeDirectory [
"This is the directory basename where the runtime files are located"
^ 'PythonBridgeRuntime'
]
{ #category : #'system startup & shutdown' }
PBApplication class >> shutDown: isImageQuitting [
isImageQuitting ifTrue: [ self stopAllInstances ]
]
{ #category : #'start-stop' }
PBApplication class >> start [
self isRunning ifTrue: [ ^ uniqueInstance ].
self stop.
uniqueInstance := self new.
uniqueInstance start.
^ uniqueInstance
]
{ #category : #'system startup & shutdown' }
PBApplication class >> startUp: isImageStarting [
isImageStarting ifTrue: [ self stopAllInstances ]
]
{ #category : #'system startup & shutdown' }
PBApplication class >> stopAllInstances [
self allInstancesDo: [ :each | each stop ]
]
{ #category : #testing }
PBApplication class >> test [
"Test and assert if my uniqueInstance isWorking"
self assert: self isWorking
]
{ #category : #utils }
PBApplication >> addMapping: pythonType to: pythonFunction [
| globals msgService |
globals := self newCommandFactory
<< (self pythonBridgePackage => 'bridge_globals') import;
<< (self pythonBridgePackage => 'bridge_globals' => 'bridge_globals') call;
sendAndWait.
msgService := globals at: #msg_service.
self newCommandFactory
sendAndWait: (msgService => #addMapping
callWith: (Array with: pythonType with: pythonFunction))
]
{ #category : #accessing }
PBApplication >> debuggerClientFor: anException [
"Answer the debugger client to be used by the Gt Post Mortem debugger"
^ GtPythonPostMortemDebugger new exception: anException
]
{ #category : #accessing }
PBApplication >> errorMessage [
"Fetch the error message from the stderr stream, from the processhander"
^ self serverStatus
]
{ #category : #accessing }
PBApplication >> evaluateSourceSequence: sourceString [
| cf lines |
cf := self newCommandStringFactory.
lines := (sourceString lines collect: #trimRight) reject: #isEmpty.
lines isEmpty ifTrue: [ ^ nil ].
lines size = 1
ifTrue: [
cf resultExpression: lines first ]
ifFalse: [
lines last first isSeparator
ifTrue: [
cf script: (String cr join: lines) ]
ifFalse: [
cf script: (String cr join: lines allButLast).
cf resultExpression: lines last ] ].
self isRunning ifFalse: [ self start ].
^ cf sendAndWait
]
{ #category : #ui }
PBApplication >> gtEditActionFor: anAction [
<gtAction>
^ anAction button
icon: BrGlamorousVectorIcons edit;
tooltip: 'Open LSP Editor';
priority: 20;
action: [ :element |
| model |
model := GtLSPPythonModel onDirectory: self settings workingDirectory.
element phlow spawnObject: model ]
]
{ #category : #accessing }
PBApplication >> gtPackage [
^ processHandler gtPackage
]
{ #category : #ui }
PBApplication >> gtViewInstalledModulesIn: composite [
<gtView>
^ composite forward
title: 'Modules';
priority: 55;
object: [ self processHandler ];
view: #gtViewInstalledModulesIn:
]
{ #category : #initialization }
PBApplication >> initialize [
super initialize.
settings := PBPlatform current defaultSettings.
self initializeHandlers.
]
{ #category : #initialization }
PBApplication >> initializeHandlers [
loggingHandler := LanguageLinkLoggingHandler application: self.
processHandler := PBPythonHandler application: self.
communicationHandler := PBCommunicationHandler application: self.
executionHandler := PBExecutionHandler application: self
]
{ #category : #utils }
PBApplication >> installModule: aModule [
"Install the supplied module aModule"
self processHandler installModule: aModule
]
{ #category : #'instance creation' }
PBApplication >> newCommandFactory [
^ self executionHandler newCommandFactory
]
{ #category : #'instance creation' }
PBApplication >> newCommandStringFactory [
^ self executionHandler newCommandStringFactory
]
{ #category : #accessing }
PBApplication >> pipenvPath [
"Answer the pipenvPath to be used for this application"
^ settings pipenvPath ifNil: [ processHandler pipenvPath ]
]
{ #category : #'start-stop' }
PBApplication >> postInitialization [
self processHandler applicationReady
]
{ #category : #printing }
PBApplication >> printOn: aStream [
super printOn: aStream.
aStream << '('.
self isRunning
ifFalse: [
aStream << 'not running)'.
^ self ].
aStream
print: settings serverSocketAddress;
<< ', ';
print: settings clientSocketAddress;
<< ')'
]
{ #category : #accessing }
PBApplication >> pythonBridgePackage [
^ processHandler pythonBridgePackage
]
{ #category : #accessing }
PBApplication >> runtimeDirectory [
"This is the directory basename where the runtime files are located"
^ self class runtimeDirectory
]
{ #category : #accessing }
PBApplication >> serverPath [
^ self pipenvPath
]
{ #category : #utils }
PBApplication >> uninstallModule: aModule [
"Uninstall the supplied module aModule"
self processHandler uninstallModule: aModule
]
{ #category : #accessing }
PBApplication >> workingDirectory [
^ settings workingDirectory ifNil:
[ FileLocator imageDirectory / self runtimeDirectory ]
]