Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Also fetch weather on enter (sort of)

  • Loading branch information...
commit 93786e5904c3ccc7b3146d6613464b82d19bfc7b 1 parent 1542e48
cannonerd authored February 01, 2012

Showing 1 changed file with 32 additions and 20 deletions. Show diff stats Hide diff stats

  1. 52  weather/weatherapp.js
52  weather/weatherapp.js
@@ -56,31 +56,43 @@ weatherwindow.show();
56 56
 
57 57
 //some weather
58 58
 
59  
-button1.connect("clicked", function(){
60  
-var station = entry.get_text();
61  
-
62  
-var GeoNames = new WeatherService.GeoNames(station); //"EFHF";
63  
-
64  
-GeoNames.getWeather(function(error, weather) {
65  
-  //this here works bit like signals. This code will be run when we have weather.
66  
-  if (error) { 
67  
-    label2.set_text("Suggested ICAO station does not exist Try EFHF");
68  
-  return; }
69  
-  weatherIcon.file = GeoNames.getIcon(weather);
70  
-  
71  
-  label1.set_text("Temperature is " + weather.weatherObservation.temperature + " degrees.");
72  
-  if (weather.weatherObservation.weatherCondition !== "n/a"){
73  
-    label2.set_text("Looks like there is " + weather.weatherObservation.weatherCondition + " in the sky.");
74  
-    }
75  
-  else {
76  
-    label2.set_text("Looks like there is " + weather.weatherObservation.clouds + " in the sky.");
  59
+entry.connect("key_press_event", function(widget, event) {
  60
+  // FIXME: Get weather on enter (key 13)
  61
+  if (entry.get_text().length === 4) {
  62
+    // Enough is enough
  63
+    getWeatherForStation();
77 64
   }
78  
-  label3.set_text("Windspeed is " + weather.weatherObservation.windSpeed + " m/s")
79  
-  // ...
  65
+  return false;
80 66
 });
81 67
 
  68
+button1.connect("clicked", function(){
  69
+  getWeatherForStation();
82 70
 });
83 71
 
  72
+function getWeatherForStation() {
  73
+  var station = entry.get_text();
  74
+
  75
+  var GeoNames = new WeatherService.GeoNames(station); //"EFHF";
  76
+
  77
+  GeoNames.getWeather(function(error, weather) {
  78
+    //this here works bit like signals. This code will be run when we have weather.
  79
+    if (error) { 
  80
+      label2.set_text("Suggested ICAO station does not exist Try EFHF");
  81
+    return; }
  82
+    weatherIcon.file = GeoNames.getIcon(weather);
  83
+    
  84
+    label1.set_text("Temperature is " + weather.weatherObservation.temperature + " degrees.");
  85
+    if (weather.weatherObservation.weatherCondition !== "n/a"){
  86
+      label2.set_text("Looks like there is " + weather.weatherObservation.weatherCondition + " in the sky.");
  87
+      }
  88
+    else {
  89
+      label2.set_text("Looks like there is " + weather.weatherObservation.clouds + " in the sky.");
  90
+    }
  91
+    label3.set_text("Windspeed is " + weather.weatherObservation.windSpeed + " m/s")
  92
+    // ...
  93
+  });
  94
+}
  95
+
84 96
 //and run it
85 97
 Gtk.main();
86 98
 

0 notes on commit 93786e5

Please sign in to comment.
Something went wrong with that request. Please try again.