guile-pstk

A Tk interface for Guile (A fork of (and hopefully a future merge?) https://github.com/kikyTokamuro/guile-pstk/).
Log | Files | Refs | README | LICENSE

weather.scm (1521B)


      1 ; PS/Tk Example Program "Weather"
      2 ; Copyright (C) 2022 Daniil Archangelsky aka Kiky Tokamuro
      3 ; See the PS/Tk license for conditions of use.
      4 
      5 (add-to-load-path
      6  (string-append
      7   (dirname (current-filename))
      8   "/../"))
      9 
     10 (use-modules (pstk)
     11 	     (web client)
     12 	     (ice-9 regex)
     13 	     (ice-9 receive))
     14 
     15 (define (get-weather city)
     16   (receive (response-status response-body)
     17       (http-request (apply string-append
     18 			   (list "https://wttr.in/"
     19 				 (regexp-substitute/global #f "[ \t]+" city 'pre "+" 'post)
     20 				 "?format=%C+%t")))
     21     response-body))
     22 
     23 (tk-start)
     24 
     25 (tk/wm 'title tk "Weather")
     26 (tk/wm 'resizable tk 0 0)
     27 (tk 'configure 'background: "#ffffff")
     28 
     29 (ttk-map-widgets 'all)
     30 (ttk/set-theme "clam")
     31 
     32 (let* ((label   (tk 'create-widget 'label
     33 		    'text: "Location:"
     34 		    'font: "Hack 10"
     35 		    'background: "#ffffff"))
     36        (entry   (tk 'create-widget 'entry
     37 		    'width: 20))
     38        (result  (tk 'create-widget 'label
     39 		    'width: 0
     40 		    'text: ""
     41 		    'font: "Hack 15"
     42 		    'justify: "center"
     43 		    'background: "#ffffff"))
     44        (btn-get (tk 'create-widget 'button
     45 		    'text: "Get weather"
     46                     'command: (lambda ()
     47 				(result 'configure
     48 					'text: (get-weather (entry 'get)))))))
     49   (tk/grid label 'column: 1 'row: 1 'sticky: 'we 'padx: 5 'pady: 5)
     50   (tk/grid entry 'column: 2 'row: 1 'sticky: 'we 'padx: 5 'pady: 5)
     51   (tk/grid result 'columnspan: 3 'row: 2 'sticky: 'we 'padx: 5 'pady: 5)
     52   (tk/grid btn-get 'columnspan: 3 'row: 3 'sticky: 'we 'padx: 5 'pady: 5)
     53   (tk-event-loop))
     54