-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbyoe-window.rkt
256 lines (207 loc) · 9.19 KB
/
byoe-window.rkt
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
246
247
248
249
250
251
252
253
254
255
#lang racket
(provide win-main%)
(require racket/gui
mrlib/path-dialog
)
(require "mvc.rkt"
"debug.rkt"
"version.rkt"
)
; ;; ;; ;; ;; ;; ;;
; ;;; ;;; ;; ;; ;;; ;;
; ;;;; ;;;; ;;;; ;; ;;;; ;;
; ;; ;; ;; ;; ;;;; ;; ;;;;; ;;
; ;; ;; ;; ;; ; ;; ;; ;; ;; ;;
; ;; ;;; ;; ;; ;; ;; ;; ;; ;;
; ;; ; ;; ;; ; ;; ;; ;; ;;
; ;; ;; ;;;;;;;; ;; ;; ;;;;;
; ;; ;; ;;;;;;;; ;; ;; ;;;;
; ;; ;; ;; ;; ;; ;; ;;;
; ;; ;; ;; ;; ;; ;; ;;
(define win-main%
(class view%
(init-field model)
(define first-check-or-compile? true)
(define f (new frame%
[label "Plumb @ concurrency.cc"]
[width 400]
[height 200]
))
#|
(define hortz1 (new horizontal-panel%
[parent f]))
(define host (new text-field%
[parent hortz1]
[label "Server"]
[init-value "ec2-54-226-131-120.compute-1.amazonaws.com"]
[stretchable-width true]
))
(define port (new text-field%
[parent hortz1]
[label ""]
[init-value "9000"]
[stretchable-width false]
))
|#
(define top-half (new vertical-panel%
[parent f]
[stretchable-height false]))
(define serial-port (new choice%
[parent top-half]
[label "Arduino Port"]
[choices
(send model get-arduino-ports)]))
(define board (new choice%
[parent top-half]
[label "Board Type"]
[choices (send model get-board-choices)]))
(define hortz2 (new horizontal-panel%
[parent top-half]))
(define choose-file (new button%
[parent hortz2]
[label "Choose Code"]
[stretchable-width true]
[callback (λ (b e)
(let* ([d (new path-dialog%
[label "occam code chooser"]
[message "Choose your main .occ file."]
[parent f]
[existing? true]
[directory (or (getenv "HOME")
(getenv "USERPROFILE"))]
[filters (list (list "occam files" "*.occ"))]
[dir? false])]
[f (send d run)])
(when f
(send model set-main-file f))
))]
))
(define check (new button%
[parent hortz2]
[label "Check"]
[stretchable-width true]
[enabled false]
[callback (λ (b e)
(send b enable false)
(send model set-error-message "")
(update-model)
(set-remote-host)
;; Set the main file
(debug 'CHECK-SYNTAX "Main file: ~a"
(send model get-main-file))
;; Compile
(when first-check-or-compile?
(set! first-check-or-compile? false)
;; This loads things from Bitbucket.
(send model load-error-regexps))
(send model check-syntax)
(send b enable true)
)]))
(define run (new button%
[parent hortz2]
[label "Run"]
[stretchable-width true]
[enabled false]
[callback (λ (b e)
(send b enable false)
(send model set-error-message "")
(update-model)
(set-remote-host)
;; Set the main file
(debug 'COMPILE "Main file: ~a"
(send model get-main-file))
(when first-check-or-compile?
(set! first-check-or-compile? false)
;; This loads things from Bitbucket.
(send model load-error-regexps))
;; Compile
(send model compile)
(send b enable true)
)]
))
(define messages (new message%
[parent f]
[stretchable-width true]
[auto-resize true]
(label "")))
(define bottom-half (new vertical-panel%
[parent f]
[stretchable-height true]))
(define err-msg-canvas (new editor-canvas%
(parent bottom-half)
(label "")
(stretchable-width true)
(line-count 5)
))
(define err-msg-text (new text% (auto-wrap true)))
(send err-msg-canvas set-editor err-msg-text)
; ;; ;; ;;;;;;; ;; ;; ;; ;; ;;
; ;;; ;;; ;;;;;;; ;;; ;; ;; ;; ;;;;;
; ;;;; ;;;; ;; ;;;; ;; ;; ;; ;; ;
; ;; ;; ;; ;; ;; ;;;;; ;; ;; ;; ;;
; ;; ;; ;; ;; ;;;;;; ;; ;; ;; ;; ;; ;;;
; ;; ;;; ;; ;;;;;; ;; ;; ;; ;; ;; ;;;
; ;; ; ;; ;; ;; ;; ;; ;; ;; ;;
; ;; ;; ;; ;; ;;;;; ;; ;; ;;
; ;; ;; ;; ;; ;;;; ;; ;; ; ;;
; ;; ;; ;; ;; ;;; ;;;;;;;; ;; ;;;
; ;; ;; ;;;;;;; ;; ;; ;;;; ;;;;
(define/public (get-frame)
f)
;; FIXME
;; No longer needed?
(define/public (set-remote-host)
'DoNothing
#|
(send model set-remote-host
(send host get-value)
(send port get-value))
|#
)
(define (populate-menu-bar)
(define help (new menu%
[label "&Help"]
[parent menu-bar]))
(new menu-item%
[label (format "Version: ~a" VERSION)]
[parent help]
[callback (λ (m e) '...)])
;; FIXME
;; Probably handled at app startup now.
;; In case we need it
;; (set-remote-host)
'JustDefine?
)
(define menu-bar (new menu-bar% [parent f]))
(populate-menu-bar)
;;;;;;;
(define (update-model)
'DoNothing
;; FIXME This can become a menu option.
(when (not (zero? (length (send model get-arduino-ports))))
(send model set-arduino-port
(send serial-port get-string
(send serial-port get-selection))))
(send model set-board-type
(send board get-string
(send board get-selection)))
)
(define/public (show bool)
(send f show bool))
(define/override (update)
;; When we have a file, we can check the syntax on it.
(when (send model main-file-set?)
(send check enable true))
;; When we have a file, and we have a serial port,
;; it is allowable to compile and upload something.
(when (and (send model main-file-set?)
(not (zero? (length (send model get-arduino-ports)))))
(send run enable true))
;; Do we have any messages to display?
(when (send model get-message)
(send messages set-label (send model get-message)))
(send err-msg-text erase)
(send err-msg-text insert (send model get-error-message))
)
(super-new)
))