From 0bd33f0efed76d9a1d1996cd2e5055dca0d7fdb9 Mon Sep 17 00:00:00 2001 From: Gabriele Monaco Date: Fri, 25 Nov 2022 18:34:57 +0100 Subject: [PATCH 1/4] circlesclock: improved clkinfo handling --- apps/circlesclock/ChangeLog | 1 + apps/circlesclock/app.js | 13 +++++++------ apps/circlesclock/metadata.json | 2 +- apps/circlesclock/settings.js | 1 - 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/circlesclock/ChangeLog b/apps/circlesclock/ChangeLog index ea7266442..f840ca447 100644 --- a/apps/circlesclock/ChangeLog +++ b/apps/circlesclock/ChangeLog @@ -31,3 +31,4 @@ 0.16: Fix const error Use widget_utils if available 0.17: Load circles from clkinfo +0.18: Improved clkinfo handling diff --git a/apps/circlesclock/app.js b/apps/circlesclock/app.js index d4a170ce8..b5770df6c 100644 --- a/apps/circlesclock/app.js +++ b/apps/circlesclock/app.js @@ -690,17 +690,18 @@ function drawClkInfo(index, w) { return; } var item = info.items[circleItemNum[index-1]]; - //TODO do hide()+get() here item.show(); item.hide(); - item=item.get(); - var img = item.img; + var data=item.get(); + var img = data.img; + var percent = 1; //fill up if no range + var txt = data.text; if(!img) img = info.img; - let percent = (item.v-item.min) / item.max; - if(isNaN(percent)) percent = 1; //fill it up + if(item.hasRange) percent = (data.v-data.min) / (data.max-data.min); + if(item.short) txt = item.short; drawGauge(w, h3, percent, color); drawInnerCircleAndTriangle(w); - writeCircleText(w, item.text); + writeCircleText(w, txt); g.setColor(getCircleIconColor(type, color, percent)) .drawImage(img, w - iconOffset, h3 + radiusOuter - iconOffset, {scale: 16/24}); } diff --git a/apps/circlesclock/metadata.json b/apps/circlesclock/metadata.json index 490d6c4fb..fb743ae4c 100644 --- a/apps/circlesclock/metadata.json +++ b/apps/circlesclock/metadata.json @@ -1,7 +1,7 @@ { "id": "circlesclock", "name": "Circles clock", "shortName":"Circles clock", - "version":"0.17", + "version":"0.18", "description": "A clock with three or four circles for different data at the bottom in a probably familiar style", "icon": "app.png", "screenshots": [{"url":"screenshot-dark.png"}, {"url":"screenshot-light.png"}, {"url":"screenshot-dark-4.png"}, {"url":"screenshot-light-4.png"}], diff --git a/apps/circlesclock/settings.js b/apps/circlesclock/settings.js index ca26cb295..2006790b8 100644 --- a/apps/circlesclock/settings.js +++ b/apps/circlesclock/settings.js @@ -17,7 +17,6 @@ var valuesCircleTypes = ["empty","weather", "sunprogress"]; var namesCircleTypes = ["empty","weather", "sun"]; clock_info.load().forEach(e=>{ - //TODO filter for hasRange and other if(!e.items.length || !e.items[0].name) { //suppose unnamed are varying (like timers or events), pick the first item = e.items[0]; From 80bd13c1a2fc2a5387bc676b05f56260ca6a4c99 Mon Sep 17 00:00:00 2001 From: glemco <32201227+glemco@users.noreply.github.com> Date: Fri, 25 Nov 2022 19:13:38 +0100 Subject: [PATCH 2/4] Fixed short label and dynamic --- apps/circlesclock/app.js | 7 +++---- apps/circlesclock/settings.js | 4 +--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/apps/circlesclock/app.js b/apps/circlesclock/app.js index b5770df6c..80fda279e 100644 --- a/apps/circlesclock/app.js +++ b/apps/circlesclock/app.js @@ -659,9 +659,8 @@ function reloadMenu() { let parts = settings['circle'+i].split("/"); let infoName = parts[0], itemName = parts[1]; let infoNum = menu.findIndex(e=>e.name==infoName); - let itemNum = 0; - //suppose unnamed are varying (like timers or events), pick the first - if(itemName) + let itemNum = 0; //get first if dynamic + if(!menu[infoNum].dynamic) itemNum = menu[infoNum].items.findIndex(it=>it.name==itemName); circleInfoNum[i-1] = infoNum; circleItemNum[i-1] = itemNum; @@ -698,7 +697,7 @@ function drawClkInfo(index, w) { var txt = data.text; if(!img) img = info.img; if(item.hasRange) percent = (data.v-data.min) / (data.max-data.min); - if(item.short) txt = item.short; + if(data.short) txt = data.short; drawGauge(w, h3, percent, color); drawInnerCircleAndTriangle(w); writeCircleText(w, txt); diff --git a/apps/circlesclock/settings.js b/apps/circlesclock/settings.js index 2006790b8..9a8b43c49 100644 --- a/apps/circlesclock/settings.js +++ b/apps/circlesclock/settings.js @@ -17,9 +17,7 @@ var valuesCircleTypes = ["empty","weather", "sunprogress"]; var namesCircleTypes = ["empty","weather", "sun"]; clock_info.load().forEach(e=>{ - if(!e.items.length || !e.items[0].name) { - //suppose unnamed are varying (like timers or events), pick the first - item = e.items[0]; + if(e.dynamic) { valuesCircleTypes = valuesCircleTypes.concat([e.name+"/"]); namesCircleTypes = namesCircleTypes.concat([e.name]); } else { From 92bf3579f208b05d83e7318480e3b5c7cd9f4664 Mon Sep 17 00:00:00 2001 From: Gabriele Monaco Date: Wed, 30 Nov 2022 18:34:29 +0100 Subject: [PATCH 3/4] circlesclock: using the weather clkinfo instead of reading from the file --- apps/circlesclock/ChangeLog | 2 +- apps/circlesclock/app.js | 56 +++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/apps/circlesclock/ChangeLog b/apps/circlesclock/ChangeLog index f840ca447..8ec578fb6 100644 --- a/apps/circlesclock/ChangeLog +++ b/apps/circlesclock/ChangeLog @@ -31,4 +31,4 @@ 0.16: Fix const error Use widget_utils if available 0.17: Load circles from clkinfo -0.18: Improved clkinfo handling +0.18: Improved clkinfo handling and using it for the weather circle diff --git a/apps/circlesclock/app.js b/apps/circlesclock/app.js index 80fda279e..bb537a819 100644 --- a/apps/circlesclock/app.js +++ b/apps/circlesclock/app.js @@ -106,6 +106,10 @@ let circleItemNum = [ 2, // circle3 3, // circle4 ]; +let weatherCircleNum = 0; +let weatherCircleDataNum = 0; +let weatherCircleCondNum = 0; +let weatherCircleTempNum = 0; function hideWidgets() { /* @@ -323,6 +327,49 @@ function getImage(graphic, color) { } function drawWeather(w) { + if (!w) w = getCircleXPosition("weather"); + let weatherInfo = menu[weatherCircleNum]; + let weatherCond = weatherCircleCondNum >= 0? weatherInfo.items[weatherCircleCondNum]: undefined; + let weatherData = weatherCircleDataNum >= 0? weatherInfo.items[weatherCircleDataNum]: undefined; + let weatherTemp = weatherCircleTempNum >= 0? weatherInfo.items[weatherCircleTempNum]: undefined; + let color = getCircleColor("weather"); + let percent = 0; + let data = settings.weatherCircleData; + let tempString = "?", icon = undefined; + + if(weatherCond) { + weatherCond.show() + weatherCond.hide() + icon = weatherCond.get().img; + } + if(weatherTemp) { + weatherTemp.show() + weatherTemp.hide() + tempString = weatherTemp.get().text; + } + + drawCircleBackground(w); + + if(weatherData) { + weatherData.show(); + weatherData.hide(); + let data = weatherData.get(); + if(weatherData.hasRange) percent = (data.v-data.min) / (data.max-data.min); + drawGauge(w, h3, percent, color); + } + + drawInnerCircleAndTriangle(w); + + writeCircleText(w, tempString); + + if(icon) { + g.setColor(getCircleIconColor("weather", color, percent)) + .drawImage(icon, w - iconOffset, h3 + radiusOuter - iconOffset, {scale: 16/24}); + } else { + g.drawString("?", w, h3 + radiusOuter); + } +} +function drawWeatherOld(w) { if (!w) w = getCircleXPosition("weather"); let weather = getWeather(); let tempString = weather ? locale.temp(weather.temp - 273.15) : undefined; @@ -664,6 +711,11 @@ function reloadMenu() { itemNum = menu[infoNum].items.findIndex(it=>it.name==itemName); circleInfoNum[i-1] = infoNum; circleItemNum[i-1] = itemNum; + } else if(settings['circle'+i] == "weather") { + weatherCircleNum = menu.findIndex(e=>e.name.toLowerCase() == "weather"); + weatherCircleDataNum = menu[weatherCircleNum].items.findIndex(it=>it.name==settings.weatherCircleData); + weatherCircleCondNum = menu[weatherCircleNum].items.findIndex(it=>it.name=="condition"); + weatherCircleTempNum = menu[weatherCircleNum].items.findIndex(it=>it.name=="temperature"); } } //reload periodically for changes? @@ -684,11 +736,11 @@ function drawClkInfo(index, w) { if (!w) w = getCircleXPosition(type); drawCircleBackground(w); const color = getCircleColor(type); - if(!info || !info.items.length) { + var item = info.items[circleItemNum[index-1]]; + if(!info || !item) { drawEmpty(info? info.img : null, w, color); return; } - var item = info.items[circleItemNum[index-1]]; item.show(); item.hide(); var data=item.get(); From bd6f3c93048b61e6b314db08f2ddfa9cac977084 Mon Sep 17 00:00:00 2001 From: Gabriele Monaco Date: Thu, 1 Dec 2022 08:48:10 +0100 Subject: [PATCH 4/4] circlesclock: optional legacy weather icons --- apps/circlesclock/app.js | 10 ++++++++-- apps/circlesclock/settings.js | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/circlesclock/app.js b/apps/circlesclock/app.js index bb537a819..ee6741398 100644 --- a/apps/circlesclock/app.js +++ b/apps/circlesclock/app.js @@ -336,11 +336,17 @@ function drawWeather(w) { let percent = 0; let data = settings.weatherCircleData; let tempString = "?", icon = undefined; + let scale = 16/24; //our icons are 16x16 while clkinfo's are 24x24 if(weatherCond) { weatherCond.show() weatherCond.hide() - icon = weatherCond.get().img; + let data = weatherCond.get() + if(settings.legacyWeatherIcons) { //may disappear in future + icon = getWeatherIconByCode(data.v); + scale = 1; + } else + icon = data.img; } if(weatherTemp) { weatherTemp.show() @@ -364,7 +370,7 @@ function drawWeather(w) { if(icon) { g.setColor(getCircleIconColor("weather", color, percent)) - .drawImage(icon, w - iconOffset, h3 + radiusOuter - iconOffset, {scale: 16/24}); + .drawImage(icon, w - iconOffset, h3 + radiusOuter - iconOffset, {scale: scale}); } else { g.drawString("?", w, h3 + radiusOuter); } diff --git a/apps/circlesclock/settings.js b/apps/circlesclock/settings.js index 9a8b43c49..2ab655f01 100644 --- a/apps/circlesclock/settings.js +++ b/apps/circlesclock/settings.js @@ -82,6 +82,12 @@ }, onchange: x => save('updateInterval', x), }, + //TODO deprecated local icons, may disappear in future + /*LANG*/'legacy weather icons': { + value: !!settings.legacyWeatherIcons, + format: () => (settings.legacyWeatherIcons ? 'Yes' : 'No'), + onchange: x => save('legacyWeatherIcons', x), + }, /*LANG*/'show big weather': { value: !!settings.showBigWeather, format: () => (settings.showBigWeather ? 'Yes' : 'No'),