initial weather support

git-svn-id: http://www.neo1973-germany.de/svn@226 46df4e5c-bc4e-4628-a0fc-830ba316316d
This commit is contained in:
fgau 2008-12-29 18:14:49 +00:00
parent 7938503330
commit abf191e441
5 changed files with 282 additions and 1 deletions

View file

@ -0,0 +1,204 @@
// weather_screen.edc
// this is a theme for epydial, a pyneo dialer and more
data {
item: "author" "thomasg [thomas (a) gstaedtner (.) net] , fgau (fgau@gau-net.de)";
item: "version" "prototype";
item: "name" "epydial_blackwhite";
}
fonts {
font: "Vera.ttf" "Vera";
font: "VeraBd.ttf" "VeraBd";
}
images {
image: "bg.png" COMP;
}
color_classes {
color_class {
name: "unvisible";
color: 0 0 0 0;
color2: 128 128 128 255;
color3: 128 128 128 255;
}
color_class {
name: "button_inactive";
color: 255 255 255 128;
color2: 128 128 128 255;
color3: 128 128 128 255;;
}
color_class {
name: "scale";
color: 255 255 255 64;
color2: 0 0 0 255;
color3: 0 0 0 255;
}
}
styles {
style {
name: "textblock_style";
base: "font=Vera font_size=20 align=left valign=top color=#fff";
tag: "h1" "+ font_size=28";
tag: "/h1" "- \n";
tag: "p" "+";
tag: "/p" "- \n";
tag: "em" "+ style=underline underline_color=#000A underline2_color=#0005";
tag: "/em" "-";
tag: "br" "\n";
tag: "c1" "+ color=#fff";
tag: "/c1" "-";
tag: "c2" "+ color=#f3f";
tag: "/c2" "-";
}
}
#define BUTTON(button_number, rel1x, rel1y, rel2x, rel2y, button_caption, color_class_caption, alignx, aligny) \
part { \
name: "button_"button_number; \
type: RECT; \
description { \
state: "default" 0; \
color_class: "unvisible"; \
rel1 { relative: rel1x rel1y; offset: 0 0; }; \
rel2 { relative: rel2x rel2y; offset: 0 0; }; \
} \
description { \
state: "default" 0.5; \
inherit: "default" 0; \
color_class: "unvisible"; \
rel1.offset: 0 -5; \
rel2.offset: 0 5; \
} \
description { \
state: "default" 1; \
inherit: "default" 0; \
} \
} \
part { \
name: "button_"button_number"_caption"; \
type: TEXT; \
mouse_events: 0; \
description { \
state: "default" 0; \
color_class: color_class_caption; \
rel1 { \
to: "button_"button_number; \
relative: 0 0; \
} \
rel2 { \
to: "button_"button_number; \
relative: 1 1; \
} \
text { \
text: button_caption; \
size: 18; \
font: "Sans:style=Bold,Edje-Vera"; \
fit: 1 1; \
} \
} \
} \
program { \
name: "button_"button_number"_animation"; \
signal: "mouse,down,*"; \
source: "button_"button_number; \
action: STATE_SET "default" 0.5; \
target: "button_"button_number; \
} \
program { \
name: "button_"button_number"_animation_end"; \
signal: "mouse,up,*"; \
source: "button_"button_number; \
action: STATE_SET "default" 1; \
target: "button_"button_number; \
transition: DECELERATE 0.1; \
} \
collections {
group {
name: "pyneo/weather/screen";
min: 100 100;
max: 800 800;
parts {
part {
name: "background";
type: IMAGE;
mouse_events: 0;
description {
state: "default" 0;
rel1 { relative: 0 0; offset: 0 0; };
rel2 { relative: 1 1; offset: 0 0; };
image { normal: "bg.png"; };
}
}
part {
name: "headline";
type: TEXT;
description {
state: "default" 0;
color_class: "button_inactive";
rel1 { relative: 1/20 1/20; }
rel2 { relative: 19/20 3/20; }
text {
text: "weather";
size: 20;
font: "VeraBd";
fit: 1 1;
}
}
}
part {
name: "location";
type: TEXT;
mouse_events: 0;
description {
state: "default" 0;
color_class: "button_inactive";
rel1 { relative: 1/20 3/20;}
rel2 { relative: 19/20 4/20; }
text {
text: "sorted by: date";
size: 10;
font: "Vera";
fit: 1 1;
}
}
}
part {
name: "current";
type: TEXTBLOCK;
mouse_events: 0;
description {
color_class: "button_inactive";
align: 0.5 0.5;
fixed: 1 1;
rel1 { relative: 0 4/20; }
rel2 { relative: 1 7/20; }
text {
text: "";
style: "textblock_style";
}
}
}
part {
name: "forecasts";
type: TEXTBLOCK;
mouse_events: 0;
description {
color_class: "button_inactive";
align: 0.5 0.5;
fixed: 1 1;
rel1 { relative: 0 8/20; }
rel2 { relative: 1 16/20; }
text {
text: "";
style: "textblock_style";
}
}
}
BUTTON(12, 0, 58/70 , 1/3, 68/70, "<", button_inactive, 0.5, 0.5);
}
}
}

View file

@ -132,6 +132,11 @@ class DialerScreen(EdjeGroup):
self.text =[]
self.part_text_set("numberdisplay_text", "".join(self.text))
PyneoController.show_pix_screen()
elif source == "dial" and ''.join(self.text) == "5":
print '--- Yahoo Weather Screen'
self.text = []
self.part_text_set("numberdisplay_text", "".join(self.text))
PyneoController.show_weather_screen()
elif source == "dial" and ''.join(self.text) == "6":
print '--- Hon Screen'
self.text = []

View file

@ -31,6 +31,7 @@ PIX_SCREEN_NAME = "pyneo/pix/screen"
CONTACTS_SCREEN_NAME = "pyneo/contacts/screen"
SMS_SCREEN_NAME = "pyneo/sms/screen"
SMS_DETAIL_SCREEN_NAME = "pyneo/sms/detail"
WEATHER_SCREEN_NAME = "pyneo/weather/screen"
from datetime import datetime
from dbus import SystemBus
@ -503,6 +504,10 @@ class PyneoController(object):
def show_sms_screen_detail(class_):
class_.notify_callbacks("show_sms_screen_detail")
@classmethod
def show_weather_screen(class_):
class_.notify_callbacks("show_weather_screen")
@classmethod
def vibrate_start(class_):
class_.pwr.Vibrate(10, 3, 1, dbus_interface=DIN_POWER)
@ -522,6 +527,7 @@ from pix_screen import *
from contacts_screen import *
from sms_screen import *
from sms_detail import *
from weather_screen import *
class Dialer(object):
screens = None
@ -548,6 +554,7 @@ class Dialer(object):
PyneoController.register_callback("show_contacts_screen", self.on_contacts_screen)
PyneoController.register_callback("show_sms_screen", self.on_sms_screen)
PyneoController.register_callback("show_sms_screen_detail", self.on_sms_screen_detail)
PyneoController.register_callback("show_weather_screen", self.on_weather_screen)
# Initialize the D-Bus interface to pyneo
dbus_ml = e_dbus.DBusEcoreMainLoop()
@ -622,6 +629,10 @@ class Dialer(object):
self.init_screen(SMS_DETAIL_SCREEN_NAME, SmsDetail(self))
self.show_screen(SMS_DETAIL_SCREEN_NAME)
def on_weather_screen(self):
self.init_screen(WEATHER_SCREEN_NAME, WeatherScreen(self))
self.show_screen(WEATHER_SCREEN_NAME)
class EvasCanvas(object):
def __init__(self, fullscreen, engine_name):

View file

@ -22,9 +22,10 @@ class SmsDetail(EdjeGroup):
connection.commit()
def on_show_sms_detail(self, sms_number, sms_status):
self.sms_offset = sms_number
connection = connect(DB_FILE_PATH)
cursor = connection.cursor()
cursor.execute("SELECT * FROM sms WHERE status='%s' ORDER BY time DESC LIMIT 1 OFFSET %s" %(sms_status, sms_number))
cursor.execute("SELECT * FROM sms WHERE status='%s' ORDER BY time DESC LIMIT 1 OFFSET %s" %(self.sms_offset, sms_number))
for row in cursor:
self.part_text_set("sms_text_1", row[2] + '<br>' + row[1] + '<br>' + row[3])
@ -35,5 +36,11 @@ class SmsDetail(EdjeGroup):
def on_edje_signal_dialer_status_triggered(self, emission, source):
if source == "button_10":
PyneoController.show_dialer_screen()
if source == "button_11":
self.sms_offset -= 1
PyneoController.show_sms_detail(self.sms_offset, self.sorted_by)
if source == "button_12":
self.sms_offset += 1
PyneoController.show_sms_detail(self.sms_offset, self.sorted_by)
print 'source: ', source

54
epydial/weather_screen.py Normal file
View file

@ -0,0 +1,54 @@
#!/usr/bin/env python2.5
# -*- coding: utf-8 -*-
__author__ = "Soeren Apel (abraxa@dar-clan.de), Frank Gau (fgau@gau-net.de), Thomas Gstaedner (thomas (a) gstaedtner (.) net)"
__version__ = "prototype"
__copyright__ = "Copyright (c) 2008"
__license__ = "GPL3"
ZIP_CODE = 'GMXX0007' #GMXX0007 Berlin, GMXX0049 Hamburg
TEMP_UNIT = 'c'
WEATHER_URL = 'http://xml.weather.yahoo.com/forecastrss?p=%s&u=%s'
WEATHER_NS = 'http://xml.weather.yahoo.com/ns/rss/1.0'
from epydial import *
import urllib
from xml.dom import minidom
class WeatherScreen(EdjeGroup):
def __init__(self, screen_manager):
EdjeGroup.__init__(self, screen_manager, WEATHER_SCREEN_NAME)
self.weather_for_zip(ZIP_CODE, TEMP_UNIT)
def weather_for_zip(self, zip_code, unit):
url = WEATHER_URL % (zip_code, unit)
dom = minidom.parse(urllib.urlopen(url))
forecasts = []
for node in dom.getElementsByTagNameNS(WEATHER_NS, 'forecast'):
forecasts.append({
'date': node.getAttribute('date'),
'low': node.getAttribute('low'),
'high': node.getAttribute('high'),
'condition': node.getAttribute('text')
})
ycondition = dom.getElementsByTagNameNS(WEATHER_NS, 'condition')[0]
self.part_text_set("location", "dom.getElementsByTagName('title')[0].firstChild.data[17:]")
self.part_text_set("current", "current condition: %s<br>current temp: %s" % (ycondition.getAttribute('text'), ycondition.getAttribute('temp')))
#print forecasts.pop(1)['date']
self.part_text_set("forecasts", "forecasts:<br>date: %s<br>low: %s<br>high: %s<br>condition: %s" % (forecasts[1]['date'], forecasts[1]['low'], forecasts[1]['high'], forecasts[1]['condition']))
# return {
# 'current_condition': ycondition.getAttribute('text'),
# 'current_temp': ycondition.getAttribute('temp'),
# 'forecasts': forecasts,
# 'title': dom.getElementsByTagName('title')[0].firstChild.data
# }
@edje.decorators.signal_callback("mouse,up,1", "*")
def on_edje_signal_dialer_status_triggered(self, emission, source):
if source == "button_12":
PyneoController.show_dialer_screen()
print 'source: ', source