<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Oct 26, 2014, at 5:51 PM, Derek C. wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: 'Lucida Grande'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="font-family: Calibri, 'Segoe UI', Meiryo, 'Microsoft YaHei UI', 'Microsoft JhengHei UI', 'Malgun Gothic', sans-serif; font-size: 16px; "><div data-signatureblock="true">I am trying to get the value of a label after a button is clicked. I know that I can use (send x get-label) to get the value of the label, but it only gets the initial value of the label in my case "No Zip Code Entered".</div></span></span></blockquote><div><br></div><div>I don't know what you are asking. When I enter a zip code and click Submit, the zip code shows up in your text field. </div><div><br></div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: 'Lucida Grande'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="font-family: Calibri, 'Segoe UI', Meiryo, 'Microsoft YaHei UI', 'Microsoft JhengHei UI', 'Malgun Gothic', sans-serif; font-size: 16px; "><div data-signatureblock="true"> Also, after that button is pressed I would like to run code that queries an API and parses xml information using the zip code from the label. Below is my code:</div></span></span></blockquote><br></div><div>See below. I have marked some small changes and sketched a way to get this going. I also fixed some basic style issues. </div><div><br></div><div>Note: if this is homework, please forward the assignment so we can help more directly. If not, I recommend developing with testing in mind (see rackunit and submodules). </div><div><br></div><div>-- Matthias</div><div><br></div><div><br></div><div><br></div><br><div><br></div><div><div>#lang racket</div><div><br></div><div>(require racket/gui/base)</div><div><br></div><div>;; -> Void </div><div>(define (main) ;; don't run directly, wrap in main function from the beginning; work with (module+ main ...) if you want to always run </div><div> </div><div> ;; Creates a Frame called mainframe</div><div> (define mainframe </div><div> (new frame%</div><div> [label "Forecaster - Powered by Wunderground API"]</div><div> [width 500]</div><div> [height 500]</div><div> [stretchable-width 500]</div><div> [stretchable-height 500]))</div><div> </div><div> ;; Creates a Current Conditions group-box-panel</div><div> (define maingroup</div><div> (new group-box-panel%</div><div> [label "Current Conditions:"]</div><div> [parent mainframe]</div><div> [min-height 450]</div><div> [stretchable-height 450]))</div><div> </div><div> (define cclabel-text (new text%)) ; you want a editor here, not a message </div><div> [send cclabel-text insert "Insert Conditions Here from API"] ;; add your initial string, though I am not sure what for </div><div> (define cclabel ;; now put the editor into a canvas</div><div> (new editor-canvas%</div><div> [parent maingroup]</div><div> [label "current conditions"]</div><div> [editor cclabel-text]))</div><div> </div><div> ;; Creates a Zip Code group-box-panel</div><div> (define zipcodegroup </div><div> (new group-box-panel%</div><div> [label "Zip Code:"]</div><div> [parent mainframe]</div><div> [min-height 100]</div><div> [stretchable-height 100]))</div><div> </div><div> ;; Zip Code Message Label -- Defaults to No Zip Code Entered</div><div> (define zipcodelabel</div><div> (new message%</div><div> [parent zipcodegroup]</div><div> [label "No Zip Code Entered"] ))</div><div> </div><div> ;; Zip Code Text-Field</div><div> (define zipInput </div><div> (new text-field% </div><div> [parent zipcodegroup]</div><div> [label ""]</div><div> [init-value ""]</div><div> [min-width 5]</div><div> [stretchable-width 5]</div><div> [callback</div><div> (lambda(f ev)</div><div> (define v (send f get-value))</div><div> (unless (string->number v)</div><div> (send f set-value (regexp-replace* #rx"[^0-9]+" v ""))))]))</div><div> </div><div> ;; Submit Button</div><div> (define submit-button </div><div> (new button% </div><div> [parent zipcodegroup]</div><div> [label "Submit"]</div><div> [callback </div><div> (lambda (button event)</div><div> ;; use internal define over let only because it's easier</div><div> (define zip-code (send zipInput get-value))</div><div> (define weather (retrieve zip-code))</div><div> (send zipcodelabel set-label zip-code)</div><div> ;; now insert weather into the editor, but clear it first </div><div> (send cclabel-text select-all)</div><div> (send cclabel-text clear)</div><div> (send cclabel-text insert (prepare-as-text weather)))]))</div><div> ;; -- IN -- </div><div> (send mainframe show #t)) </div><div><br></div><div>;; helper but this may actually have to work on the editor directly to make it look good </div><div>(define (prepare-as-text list-of-pairs)</div><div> (string-join </div><div> (map (lambda (x) (format "~a ~a" (first x) (second x))) list-of-pairs)</div><div> "\n"))</div><div><br></div><div>;XML Parsing:</div><div>;</div><div>;#lang racket</div><div><br></div><div>;; this module should presumably provide a retrieve function that does the hard work: </div><div>;; (provide </div><div>;; ; ZipCode -> [Listof [List Symbol String]]</div><div>;; ; retrieve the information for the given zip code and deliver the result as an association list </div><div>;; ; -- examples here -- </div><div>;; retrieve)</div><div>(require net/url xml xml/path)</div><div><br></div><div>(define underground-url-format</div><div> "<a href="http://api.wunderground.com/api/*snip*/conditions/q/autoip.xml">http://api.wunderground.com/api/*snip*/conditions/q/autoip.xml</a>")</div><div><br></div><div>;; I am taking a short-cut here: </div><div>(define (retrieve zip-code)</div><div> (list (list 'Location: "Boston, MA") (list 'Conditions: "typical fall day") </div><div> (list 'Temperature: "57o F") (list 'Feels-Like: "damp, humid, earthy")</div><div> (list 'Humidity: "67%") (list 'Wind: "5mph, south-by-south-west")))</div><div><br></div><div>(define (retrieve-to-be-done zip-code) </div><div> (define curent-cond-url (string->url (format underground-url-format zip-code)))</div><div> (define current-cond-port (get-pure-port curent-cond-url))</div><div> (define response (port->string current-cond-port))</div><div> (close-input-port current-cond-port)</div><div> </div><div> (define data (xml->xexpr</div><div> ((eliminate-whitespace '(response))</div><div> (read-xml/element (open-input-string response)))))</div><div> </div><div> (define curr-location (se-path*/list '(display_location full) data))</div><div> (define curr-weather (se-path*/list '(current_observation weather) data))</div><div> (define curr-temp (se-path*/list '(current_observation temp_f) data))</div><div> (define curr-humidity (se-path*/list '(current_observation relative_humidity) data))</div><div> (define curr-wind (se-path*/list '(current_observation wind_string) data))</div><div> (define curr-feels-like (se-path*/list '(current_observation feelslike_f) data))</div><div> </div><div> (list (list 'Location: curr-location) (list 'Conditions: curr-weather) </div><div> (list 'Temperature: curr-temp) (list 'Feels-Like: curr-feels-like)</div><div> (list 'Humidity: curr-humidity) (list 'Wind: curr-wind)))</div></div></body></html>