Blame platform-demos/de/weatherApp.js.page

Packit 1470ea
Packit 1470ea
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" type="guide" style="task" id="weatherApp.js" xml:lang="de">
Packit 1470ea
  <info>
Packit 1470ea
  <title type="text">Wetter-Anwendung (JavaScript)</title>
Packit 1470ea
    <link type="guide" xref="js#examples"/>
Packit 1470ea
    <revision version="0.1" date="2012-03-09" status="stub"/>
Packit 1470ea
Packit 1470ea
    <credit type="author copyright">
Packit 1470ea
      <name>Susanna Huhtanen</name>
Packit 1470ea
      <email its:translate="no">ihmis.suski@gmail.com</email>
Packit 1470ea
      <years>2012</years>
Packit 1470ea
    </credit>
Packit 1470ea
    <credit type="editor">
Packit 1470ea
      <name>Marta Maria Casetti</name>
Packit 1470ea
      <email its:translate="no">mmcasetti@gmail.com</email>
Packit 1470ea
      <years>2013</years>
Packit 1470ea
    </credit>
Packit 1470ea
Packit 1470ea
    <desc> How to plan an application that uses asynchronous calls. Asynchronous calls will be presented through a weather application.
Packit 1470ea
    </desc>
Packit 1470ea
Packit 1470ea
  
Packit 1470ea
    <mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
Packit 1470ea
      <mal:name>Mario Blättermann</mal:name>
Packit 1470ea
      <mal:email>mario.blaettermann@gmail.com</mal:email>
Packit 1470ea
      <mal:years>2011, 2013</mal:years>
Packit 1470ea
    </mal:credit>
Packit 1470ea
  </info>
Packit 1470ea
Packit 1470ea
  <title>Wetter-Anwendung</title>
Packit 1470ea
  <synopsis>
Packit 1470ea
    

In this guide well construct a weather application using asynchronous calls. Weather information in this example is fetched from geonames.org and the application is using the <link href="http://en.wikipedia.org/wiki/List_of_airports_by_ICAO_code:_E">ICAO codes </link> to place your weather request. To write and run all the code examples yourself, you need an editor to write code in, Terminal and GNOME 3 or higher installed into your computer. In this guide we we'll go through the following parts:

Packit 1470ea
Packit 1470ea
    <list>
Packit 1470ea
      <item>

<link xref="#planningUi">Planning the graphical user interface</link>

</item>
Packit 1470ea
      <item>

<link xref="#asynchronous">Asynchronous calls</link>

</item>
Packit 1470ea
      <item>

<link xref="#main">The main program file</link>

</item>
Packit 1470ea
      <item>

<link xref="#main">Local library GeoNames</link>

</item>
Packit 1470ea
      <item>

<link xref="#main">Autotools und Symbole</link>

</item>
Packit 1470ea
    </list>
Packit 1470ea
  </synopsis>
Packit 1470ea
Packit 1470ea
  

After reading this tutorial, you should see this in your screen:

Packit 1470ea
  <media type="image" mime="image/png" src="media/weatherAppJs.png"/>
Packit 1470ea
Packit 1470ea
  <section id="planningUi">
Packit 1470ea
    <title>Planung der grafischen Benutzeroberfläche</title>
Packit 1470ea
    

Structuring an application for GNOME 3 means you will be using <link href="http://developer.gnome.org/platform-overview/stable/gtk">GTK+</link>. The most important thing is to remember that the main window will only accept one widget. You must plan your structure accordingly (this example is using Gtk.Grid). A useful method is to draw out the main window and place every widget needed inside that box. By looking at an image of your future application it is easier to tell what are the relations between widgets. For example Gtk.Grid places your widgets in relation to other widgets, so after the first widget is in place, placing widgets can be done in relation to any widget on the grid.

Packit 1470ea
  </section>
Packit 1470ea
  <section id="asynchronous">
Packit 1470ea
    <title>Asynchrone Aufrufe</title>
Packit 1470ea
    

With many programming languages, all operations are run synchronously - you tell the program to do something, and it will wait until that action completes before proceeding. This is however bad for

Packit 1470ea
    graphical user interfaces, as then the whole application will be frozen while the program waits for
Packit 1470ea
    the operation. Going asynchronous (async) helps here. With async calls, your UI won't be blocked with any requests. Async calls make your application more flexible and better equipped to handle situations when calls take more time than expected or for some reason get jammed. Async calls can be used for example file system I/O and for slower calculations in the background.   

Packit 1470ea
    

In this example we have to get data from geonames.org. While we do that we want the rest of our program to continue. If we wouldn't get any information from geonames.org for the lack of internet connection and this would be a synchronous application we would never get to the point where our main_quit() is processed correctly and the application would have to killed from Terminal.

Packit 1470ea
  </section>
Packit 1470ea
  <section id="main">
Packit 1470ea
    <title>Die verschiedenen Teile des Programms</title>
Packit 1470ea
  </section>
Packit 1470ea
</page>