Irc-Unix.net

Главная | Actual Topics | Обратная связь | В избранное | Сделать домашней | Антиспам ;)
Категории
 System & Utilities
 Unix News
 OS Emulator
 Developing
 Learning/Education
 Games
 Humour
Каталог статей
Все статьи

Antispam
Статьи
Биллу Гейтсу тоже предлагают избавиться ...
Вымогательство в борьбе со спамом
Календарь

December, 2018
ПнВтСрЧтПтСбВс
12
3456789
10111213141516
17181920212223
24252627282930
31
Опросы
Какой из этих ОС Вы отдаете большее предпочтение?

QNX
FreeBSD
Linux(any)
Solaris
Mac OS
Windows XP
Windows 2003
Что такое ОС? :)


Результаты
Другие опросы

Всего голосов: 327
Комментарии: 0
Ссылки

Архив Новостей
 December 2018 (4)
 November 2018 (7)
 October 2018 (13)
 September 2018 (8)
 August 2018 (8)
 July 2018 (11)
 June 2018 (13)
 May 2018 (10)
 April 2018 (14)
 March 2018 (11)
 February 2018 (13)
 January 2018 (13)
 December 2017 (14)
 November 2017 (15)
 October 2017 (19)
 September 2017 (18)
 August 2017 (13)
 February 2017 (14)
 January 2017 (19)
 December 2016 (16)
 November 2016 (16)
 October 2016 (21)
 September 2016 (18)
 August 2016 (16)
 July 2016 (16)
 June 2016 (20)
 May 2016 (18)
 April 2016 (15)
 March 2016 (22)
 February 2016 (17)
 January 2016 (15)
 December 2015 (15)
 November 2015 (22)
 October 2015 (20)
 September 2015 (17)
 August 2015 (25)
 July 2015 (20)
 June 2015 (23)
 May 2015 (21)
 April 2015 (17)
 March 2015 (19)
 February 2015 (9)
 January 2015 (23)
 December 2014 (9)
 November 2014 (13)
 October 2014 (12)
 September 2014 (18)
 August 2014 (20)
 July 2014 (10)
 June 2014 (12)
 May 2014 (12)
 April 2014 (10)
 March 2014 (22)
 February 2014 (10)
 January 2014 (8)
 December 2013 (26)
 November 2013 (53)
 October 2013 (40)
 September 2013 (48)
 August 2013 (63)
 July 2013 (56)
 June 2013 (52)
 May 2013 (49)
 April 2013 (67)
 March 2013 (74)
 February 2013 (63)
 January 2013 (62)
 December 2012 (62)
 November 2012 (66)
 October 2012 (68)
 September 2012 (48)
 August 2012 (75)
 July 2012 (60)
 June 2012 (71)
 May 2012 (69)
 April 2012 (85)
 March 2012 (86)
 February 2012 (90)
 January 2012 (81)
 December 2011 (103)
 November 2011 (118)
 October 2011 (74)
 September 2011 (2)
 June 2011 (110)
 May 2011 (118)
 April 2011 (111)
 March 2011 (112)
 February 2011 (101)
 January 2011 (119)
 December 2010 (117)
 November 2010 (118)
 October 2010 (131)
 September 2010 (117)
 August 2010 (226)
 July 2010 (351)
 June 2010 (305)
 May 2010 (319)
 April 2010 (343)
 March 2010 (329)
 February 2010 (311)
 January 2010 (312)
 December 2009 (266)
 November 2009 (156)
 July 2009 (101)
 June 2009 (279)
 May 2009 (365)
 April 2009 (348)
 March 2009 (347)
 February 2009 (323)
 January 2009 (318)
 December 2008 (237)
 November 2008 (155)
 October 2008 (334)
 September 2008 (310)
 August 2008 (343)
 July 2008 (362)
 June 2008 (322)
 May 2008 (456)
 April 2008 (1276)
 March 2008 (1658)
 February 2008 (250)
 January 2008 (6)
 November 2007 (1)
 September 2007 (1)
 June 2007 (1)
 May 2007 (1)
 March 2007 (1)
 January 2007 (2)
 December 2006 (1)
 October 2006 (2)
 September 2006 (1)
 August 2006 (2)

QML Weather

System & Utilities

I recently took some time to develop a photo frame style home automation control panel. The idea is to control some common tasks of my home assistant setup from a panel instead of having to rely on the phone. To hide the panel, it currently act as a photo frame until touched.

The build is based on a Raspberry Pi 2 with the official touch screen attached and a USB wifi dongle. Nothing fancy, but still good enough.

One of the features that I wanted was a weather forecast, so I decided to use Yr’s xml weather as a base for this. The result is the YrWeatherModel QML item.

The weather forecast overlay.

The presentation side of things is the fairly straight forward piece of QML shown below, resulting in the overlay shown above.

Row {
anchors.bottom: dateText.bottom
anchors.right: parent.right
anchors.rightMargin: 40

spacing: 20
Repeater {
delegate: Column {
spacing: 2
Text {
anchors.horizontalCenter: parent.horizontalCenter
color: \"white\"
font.pixelSize: 16
font.bold: true
text: {
switch (period) {
case 0:
\"00 - 06\"
break;
case 1:
\"06 - 12\"
break;
case 2:
\"12 - 18\"
break;
case 3:
default:
\"18 - 00\"
break;
}
}
}
Image {
anchors.horizontalCenter: parent.horizontalCenter
source: symbolSource
}
Text {
anchors.horizontalCenter: parent.horizontalCenter
color: \"white\"
font.pixelSize: 16
font.bold: true
text: precipitation + \"mm\"
}
Text {
anchors.horizontalCenter: parent.horizontalCenter
color: \"white\"
font.pixelSize: 16
font.bold: true
text: temperature + \"°C\"
}
}

model: weatherModel.model
}
}

This is followed by the model itself, and a small notice of the data source.

YrWeatherModel {
id: weatherModel
place: \"Sweden/V%C3%A4stra_G%C3%B6taland/Alings%C3%A5s\"
}

Text {
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.bottomMargin: 5
anchors.rightMargin: 40
text: weatherModel.dataSourceNotice
color: \"white\"
font.pixelSize: 16
font.italic: true
}

Diving into the model itself, we hit the interesting parts. The structure looks like this:

Item {
id: root

property alias model: weatherModel
property int refreshHour: 1 // How often is the model refreshed (in hours)
property int dataPoints: 6 // How many data points (max) are expected (in 6h periods)
property string place // Place, URL encoded and according to Yr web site, e.g. Sweden/V%C3%A4stra_G%C3%B6taland/Alings%C3%A5s
readonly property string dataSourceNotice: \"Data from MET Norway\"

ListModel {
id: weatherModel
}

Timer {
interval: 3600000 * root.refreshHour
running: true
repeat: true
onTriggered: {
_innerModel.reload();
}
}

XmlListModel {
id: _innerModel

query: \"/weatherdata/forecast/tabular/time\"

source: (place.length === 0)?\"\":(\"https://www.yr.no/place/\" + root.place + \"/forecast.xml\")

XmlRole { name: \"period\"; query: \"string(@period)\" }
XmlRole { name: \"symbol\"; query: \"symbol/string(@number)\"; }
XmlRole { name: \"temperature\"; query: \"temperature/string(@value)\"; }
XmlRole { name: \"precipitation\"; query: \"precipitation/string(@value)\"; }

onStatusChanged: {
// ...
}
}
}

As you can see, the model consists of an inner model of the type XmlListModel. This model is refreshed by a timer (don’t refresh too often – you will most likely be auto-banned by Yr). At the top, there is also a ListModel that is the actual model used by the user interface.

The reason for the ListModel to exist is that I wanted to be able to limit how many data points I show. Each data point represents a six hour window, and I’d like 6 of them, i.e. one and a half day of forecasting.

The onStatusChanged handler in the XmlListModel takes care of this in the following for loop:

onStatusChanged: {
if (status === XmlListModel.Ready)
{
for(var i = 0; i< root.dataPoints && i < count; ++i)
{
var symbol = get(i).symbol;
var period = parseInt(get(i).period);
var is_night = 0;

if (period === 3 || period === 0)
is_night = 1;

weatherModel.set(i, {
\"period\":period,
\"symbol\":symbol,
\"symbolSource\":\"https://api.met.no/weatherapi/weathericon/1.1/?symbol=\" + symbol + \"&is_night=\" + is_night + \"&content_type=image/png\",
\"temperature\":get(i).temperature,
\"precipitation\":get(i).precipitation
});
}
}
else if (status === XmlListModel.Error)
{
console.warn(\"Weather error\")
console.warn(errorString());
}
}

As you can tell, this code has *very* limited error handling. It is almost as it has been designed to break, but it works. The code also shows how convenient it is to connect to online services via QML to build simple, reusable, models that can be turned into beautiful user interfaces.

Next time I have some free time, I’ll look at interfacing with the public transport APIs. Then I will have to deal with JSON data and make explicit XmlHttpRequest calls.





  


Разместил: Planet KDE | Дата: 08.10.2018 | Прочитано: 63 | Раздел: System & Utilities   

Рейтинг статьи

Средняя оценка: 0.00/0Средняя оценка: 0Всего голосов:0

Отлично
Хорошо Нормально Пойдёт Плохо


Смотрите также связанные темы

Нет комментариев. Почему бы Вам не оставить свой?
Вы не можете отправить комментарий анонимно, пожалуйста зарегистрируйтесь.
Google Search
Google

Web irc-unix.net

Топ Новостей
1: Fedora and KDE/spin\'s treatment - Discussion
Hot NEWS!
Просмотров - 3101


2: Offline Vaults for an extra layer of protection
Просмотров - 775

3: KDE\'s Kirigami 2.0 Framework for Convergent UIs Enters Beta with New Features
Просмотров - 755

4: Akonadi/KMail issues on Tumbleweed?
Просмотров - 681

5: Netrunner Desktop 16.09 "Avalon" Linux OS Is Out with Kernel 4.7, KDE Plasma 5.7
Просмотров - 657

6: Debugging issues booting a PC in 2018
Просмотров - 655

7: KDevelop 5.0.2 released for Windows and Linux
Просмотров - 641

8: plib3.gui 0.9.9
Просмотров - 625

9: Konstruct
Просмотров - 613

10: Best Desktop Environment
Просмотров - 597

11: KDE Connect – State of the union
Просмотров - 594

12: KDE Connect Sprint
Просмотров - 590

13: Come dine with the KDE e.V. board in Berlin in October
Просмотров - 589

14: Help Canonical Test GNOME Patches, Android Apps Illegally Tracking Kids, MySQL 8.0 Released and More
Просмотров - 581

15: Multi-screen woes in Plasma 5.7
Просмотров - 580

Google 120X240
Ссылки

Главная | Actual Topics | Статьи | Обратная связь | Guest Book
Генерация: 1.690 сек. и 13 запросов к базе данных за 1.627 сек.
Powered by SLAED CMS © 2005-2007 SLAED. All rights reserved.