-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleGui.rkt
More file actions
219 lines (182 loc) · 5.94 KB
/
simpleGui.rkt
File metadata and controls
219 lines (182 loc) · 5.94 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
#lang racket
(require browser)
(require racket/gui/base)
(require "yummlyCall.rkt")
(require racket/draw
net/url)
(require net/sendurl)
(define blank (read-bitmap (get-pure-port (string->url "http://hipsterhub.com/wp-content/uploads/2011/05/blue-pattern-ipad-wallpaper-300x300.jpg"))))
(define logo (read-bitmap (get-pure-port (string->url "http://racket-lang.org/logo.png"))))
(define frame (new frame%
[label "Simple Recipe"]
[width 850]
[height 1000]
))
; Title
(define title
(new message%
(parent frame)
(label "Welcome to Simple Recipe")
(vert-margin 10)
(min-width 0)
(font (make-object font% 18 'default))))
(define (getstr str)
(printf str))
;; http://stackoverflow.com/questions/16249705/get-the-selected-text-field-in-a-racket-gui
(define my-text-field%
(class text-field%
(super-new)
(define/override (on-focus on?)
(when on? (printf "~a\n" (send this get-label))))))
; Enter food likes here
(define recipe-food-items
(new message%
(parent frame)
(label "What ingredients do you have?")
(min-width 0)
(vert-margin 8)
(font (make-object font% 12 'default))))
(define field-likes (new text-field% [label ""] [parent frame] [min-width 60] [min-height 60]))
; Enter food dislikes here
(define recipe-food-dislike
(new message%
(parent frame)
(label "What ingredients do you dislike?")
(vert-margin 10)
(min-width 0)
(font (make-object font% 12 'default))))
(define field-dislikes (new text-field% [label ""] [parent frame] [min-width 60] [min-height 60]))
(define field-6 (new message% [label ""] [parent frame]))
(define (callback button event)
(define title-new-value (send field-likes get-value))
(when (not (equal? (car (regexp-split #px", " (string-append(send field-likes get-value)))) ""))
(add-ingredients(regexp-split #px", " (string-append(send field-likes get-value)))))
(when (not (equal? (car (regexp-split #px", " (string-append(send field-dislikes get-value)))) ""))
(addToBlacklist(regexp-split #px", " (string-append(send field-dislikes get-value)))))
(getRecipes)
;(printf yummlySearch)
;(printf "\n")
(printf (number->string counter))
(printf "\n")
(printf (getRecipeAttribute 'ingredients))
(printf "\n")
(printf (getRecipeAttribute 'image))
(printf "\n")
;(printf (getRecipeAttribute 'recipeName)))
(send recipe-name set-label (getRecipeAttribute 'name))
(send display-picture set-label (read-bitmap (get-pure-port (string->url (getRecipeAttribute 'image)))))
(send field-ingredients set-value (getRecipeAttribute 'ingredients))
(send field-nutritional-facts set-value (getRecipeAttribute 'nutrition))
(send field-url set-value (getRecipeAttribute 'url))
(iterateCounter)
(reset-yummly)
(printf "Done\n"))
(define button
(new button%
[label "Submit"]
[vert-margin 6]
[horiz-margin 0]
[parent frame]
[callback callback]))
;(define horizontal-line
; (new message%
; (parent frame)
; (label "------------------------------------------------------------------------------------------------------------------")
; (font (make-object font% 12 'default))))
(define main-panel
(new vertical-panel%
(parent frame)
(alignment (list 'left 'top))
[style (list 'vscroll 'border)]
(min-height 10)
))
(define horizontal-display-panel
(new horizontal-panel%
(parent main-panel)
(alignment (list 'left 'top))
;[style (list 'vscroll 'border)]
(min-height 10)
[stretchable-height #f]
))
(define display-picture
(new message%
(parent horizontal-display-panel)
(min-height 100)
(min-width 200)
(vert-margin 10)
(label logo)))
(define recipe-name
(new message%
(parent horizontal-display-panel)
(label "Recipe")
(min-width 500)
(vert-margin 10)
(font (make-object font% 15 'default))))
(define panel
(new vertical-panel%
(parent main-panel)
(alignment (list 'left 'center))
;[style (list 'vscroll)]
))
; Recipe name here
;(define recipe-name
; (new message%
; (parent panel)
; (vert-margin 10)
; (label "Recipe Name:")
; (min-width 0)
; (font (make-object font% 12 'default))))
; Required ingredients here
(define recipe-required
(new message%
(parent panel)
(vert-margin 10)
(label "Required ingredients")
(horiz-margin 10)
(min-width 0)
(font (make-object font% 12 'default))))
(define field-ingredients (new text-field% [label ""] [parent panel] [min-width 100] [min-height 100]))
; Recipe picture here
;(define recipe-picture
; (new message%
; (parent panel)
; (vert-margin 10)
; (label "Sample picture:")
; (min-width 0)
; (font (make-object font% 12 'default))))
;; Picture of recipe here
;(define display-picture
; (new message%
; (parent panel)
; (label blank)))
; Nutritional facts here
(define recipe-macros
(new message%
(parent panel)
(vert-margin 10)
(label "Nutritional facts")
(horiz-margin 10)
(min-width 0)
(font (make-object font% 12 'default))))
(define field-nutritional-facts (new text-field% [label ""] [parent panel] [min-width 100] [min-height 100]))
; Link to cooking instructions
(define recipe-instructions
(new message%
(parent panel)
(vert-margin 10)
(label "Instructions link")
(horiz-margin 10)
(min-width 0)
(font (make-object font% 12 'default))))
(define field-url (new text-field% [label ""] [parent panel]))
(define (url-callback button event)
(define new-url (send field-url get-value))
(send-url new-url))
(define url-button
(new button%
[label "Open"]
[parent panel]
(horiz-margin 425)
[callback url-callback]))
;; display the GUI
(send frame show #t)