%= html_header("Examples 2") %>
Select a location from the dropdown to display the current weather forecast. The program is available in the CVS repository.
The required libraries in this case are:
require "gtk"
require "gtk.http_co"
require "lxp"
require "gtk.strict"
"lxp" is LuaExpat, the binding to the expat xml parser. The following function is the handler for changes in the dropdown and starts an asynchronous HTTP request to fetch the weather info. The "_co" suffix indicates that a coroutine is used.
<%= copy_function("../weather/weather.lua", "on_location_changed") %>
The total code size of this example is about 270 lines, most of it concerned with parsing the response and building the GUI elements to show it.
This demo creates a GdkPixmap and draws on it using functions like draw_rectangle, draw_layout (for Pango layouts).
The code is interesting as it uses quite a few low level functions, accesses to structure elements and so forth. The following function is called to create the pixmap at a given size after size change of the window:
<%= copy_function("examples/pixmap.lua", "on_configure") %>