mirror of
https://github.com/pbek/QOwnNotes.git
synced 2025-06-28 12:59:52 +00:00
more script tests
This commit is contained in:
parent
3c4a9867d2
commit
cfda04e6df
1 changed files with 91 additions and 38 deletions
|
@ -1,8 +1,7 @@
|
|||
import QtQml 2.0
|
||||
import QOwnNotesTypes 1.0
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Controls 2.0
|
||||
import QtQuick.Layouts 1.0
|
||||
import QtQuick 2.4
|
||||
import QtQuick.Controls 1.4
|
||||
|
||||
/**
|
||||
* This script shows current weather statistics in a "scripting label"
|
||||
|
@ -12,6 +11,7 @@ import QtQuick.Layouts 1.0
|
|||
*/
|
||||
|
||||
Item {
|
||||
id: item
|
||||
property string dockWidgetId: "weatherStats";
|
||||
property string dockWidgetTitle: "Weather Stats";
|
||||
|
||||
|
@ -36,39 +36,15 @@ Item {
|
|||
"default": false,
|
||||
},
|
||||
];
|
||||
|
||||
property string gWeatherCity: "unknown";
|
||||
|
||||
function init() {
|
||||
script.registerLabel("weather stats");
|
||||
weatherStats();
|
||||
}
|
||||
|
||||
function weatherStats() {
|
||||
var unitString = useFahrenheit ? "f" : "c"
|
||||
var json = script.downloadUrlToString("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22" + city + "%22)%20and%20u%3D%27" + unitString + "%27&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys");
|
||||
var weatherInfo = JSON.parse(json);
|
||||
|
||||
var temp = weatherInfo.query.results.channel.item.condition.temp
|
||||
var tempUnit = weatherInfo.query.results.channel.units.temperature;
|
||||
var conditionText = weatherInfo.query.results.channel.item.condition.text
|
||||
var weatherCity = weatherInfo.query.results.channel.location.city
|
||||
var windSpeed = weatherInfo.query.results.channel.wind.speed
|
||||
var windUnit = weatherInfo.query.results.channel.units.speed;
|
||||
|
||||
if (!useFahrenheit) {
|
||||
tempUnit = "°" + tempUnit;
|
||||
}
|
||||
|
||||
script.setLabelText("weather stats",
|
||||
"<table align='center' width='90%'>
|
||||
<tr>
|
||||
<td align='center'>
|
||||
Weather in <b>" + weatherCity + "</b>: " + conditionText + " at <b>" + temp + " " + tempUnit + "</b>
|
||||
(" + windSpeed + " " + windUnit + " wind)
|
||||
</tb>
|
||||
</tr>
|
||||
</table>")
|
||||
weatherLabel.weatherStats();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This starts a timer that triggers every 10min
|
||||
*/
|
||||
|
@ -84,13 +60,90 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
property int count: 0
|
||||
id: button1
|
||||
text: qsTr("Press Me")
|
||||
onClicked: function() {
|
||||
script.log("Button was pressed: " + count++);
|
||||
text = "Press " + count;
|
||||
Column {
|
||||
|
||||
Slider {
|
||||
|
||||
id: slider
|
||||
minimumValue: 0
|
||||
maximumValue: 100
|
||||
}
|
||||
|
||||
Label {
|
||||
|
||||
text: Math.floor(slider.value)
|
||||
}
|
||||
|
||||
Label {
|
||||
property string myText: "empty";
|
||||
id: weatherLabel
|
||||
// text: 'empty'
|
||||
//text: myText
|
||||
text: gWeatherCity
|
||||
// text: item.gWeatherCity
|
||||
font.pointSize: 24
|
||||
|
||||
function setText(newText) {
|
||||
script.log(newText);
|
||||
//text = newText;
|
||||
myText = newText;
|
||||
}
|
||||
|
||||
function weatherStats() {
|
||||
var unitString = useFahrenheit ? "f" : "c"
|
||||
var json = script.downloadUrlToString("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22" + city + "%22)%20and%20u%3D%27" + unitString + "%27&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys");
|
||||
var weatherInfo = JSON.parse(json);
|
||||
|
||||
var temp = weatherInfo.query.results.channel.item.condition.temp
|
||||
var tempUnit = weatherInfo.query.results.channel.units.temperature;
|
||||
var conditionText = weatherInfo.query.results.channel.item.condition.text
|
||||
var weatherCity = weatherInfo.query.results.channel.location.city
|
||||
var windSpeed = weatherInfo.query.results.channel.wind.speed
|
||||
var windUnit = weatherInfo.query.results.channel.units.speed;
|
||||
|
||||
if (!useFahrenheit) {
|
||||
tempUnit = "°" + tempUnit;
|
||||
}
|
||||
|
||||
//weatherLabel.text = weatherCity;
|
||||
gWeatherCity = weatherCity;
|
||||
text = weatherCity;
|
||||
|
||||
myText = weatherCity + "!";
|
||||
setText(weatherCity + "#");
|
||||
// weatherLabel.myText ="<table align='center' width='90%'>
|
||||
// <tr>
|
||||
// <td align='center'>
|
||||
// Weather in <b>" + weatherCity + "</b>: " + conditionText + " at <b>" + temp + " " + tempUnit + "</b>
|
||||
// (" + windSpeed + " " + windUnit + " wind)
|
||||
// </tb>
|
||||
// </tr>
|
||||
// </table>";
|
||||
|
||||
script.setLabelText("weather stats",
|
||||
"<table align='center' width='90%'>
|
||||
<tr>
|
||||
<td align='center'>
|
||||
Weather in <b>" + weatherCity + "</b>: " + conditionText + " at <b>" + temp + " " + tempUnit + "</b>
|
||||
(" + windSpeed + " " + windUnit + " wind)
|
||||
</tb>
|
||||
</tr>
|
||||
</table>");
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
property int count: 0
|
||||
id: button1
|
||||
text: qsTr("Press Me")
|
||||
onClicked: function() {
|
||||
script.log("Button was pressed: " + count++);
|
||||
text = "Press " + count;
|
||||
weatherLabel.weatherStats();
|
||||
//gWeatherCity = count;
|
||||
//weatherLabel.text = count + "#";
|
||||
//weatherLabel.setText(count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue