Pull in Python panel/wallpaper from 1.2.x

This commit is contained in:
K. Lange 2018-10-03 08:11:23 +09:00
parent ffe0aa2448
commit b189bfa659
25 changed files with 1781 additions and 0 deletions

1
base/etc/default.desktop Normal file
View File

@ -0,0 +1 @@
utilities-terminal,terminal,Terminal

7
base/etc/weather.json Normal file
View File

@ -0,0 +1,7 @@
{
"city": "Tokyo",
"units": "metric",
"--comment": "The key below is provided for use in ToaruOS for free from OpenWeatherMap.org. We must provide the key so that the weather widget can make API queries. Use of this key for other purposes is against OpenWeatherMap's terms of service.",
"key": "78c832cfada2b0337f516891afb4f13b"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1 @@
02d.bmp

View File

@ -0,0 +1 @@
02n.bmp

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1 @@
09d.bmp

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1 @@
10d.bmp

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1 @@
11d.bmp

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1 @@
13d.bmp

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1 @@
50d.bmp

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,42 @@
#!/usr/bin/python3.6
"""
Toaru OS UI theming.
"""
panel_widget_foreground = 0xFFE6E6E6
panel_widget_hilight = 0xFF8EDBFF
menu_entry_text = 0xFF000000
panel_window_shadow = (0xFF000000, 2, 1, 1, 3.0)
panel_window_gradient_top = (0.0,72/255,167/255,255/255,0.7)
panel_window_gradient_low = (1.0,72/255,167/255,255/255,0.0)
panel_window_divider_top = (0.1,1,1,1,0.0)
panel_window_divider_mid = (0.5,1,1,1,1.0)
panel_window_divider_low = (0.9,1,1,1,0.0)
desktop_icon_hilight = (0x8E/0xFF,0xD8/0xFF,1,0.3)
desktop_icon_shadow = (0xFF000000, 2, 1, 1, 3.0)
desktop_icon_text = 0xFFFFFFFF
alt_tab_text = 0xFFE6E6E6
alt_tab_background = (0,0,0,0.7)
alt_tab_extra_text = '0x888888'
def as_rgb_tuple(color):
r = ((color & 0xFF0000) >> 16) / 0xFF
g = ((color & 0xFF00) >> 8) / 0xFF
b = ((color & 0xFF)) / 0xFF
return (r,g,b)
def as_rgba_tuple(color):
a = ((color & 0xFF000000) >> 24) / 0xFF
r = ((color & 0xFF0000) >> 16) / 0xFF
g = ((color & 0xFF00) >> 8) / 0xFF
b = ((color & 0xFF)) / 0xFF
return (r,g,b,a)
if __name__ == '__main__':
print("...")

View File

@ -0,0 +1,115 @@
#!/usr/bin/python3
"""
Tool to asynchronously fetch weather data from OpenWeatherMap.org
"""
import json
import subprocess
import os
import sys
with open('/etc/weather.json','r') as f:
config = json.loads(f.read())
home = os.environ['HOME']
if os.path.exists(f'{home}/.weather.json'):
with open(f'{home}/.weather.json','r') as f:
x_config = json.loads(f.read())
for k in x_config:
config[k] = x_config[k]
else:
x_config = {}
key = config['key']
city = config['city']
units = config['units']
def write_config():
with open(f'{home}/.weather.json','w') as f:
f.write(json.dumps(x_config))
def write_out(data):
with open('/tmp/weather.json','w') as f:
f.write(data)
try:
os.chmod('/tmp/weather.json',0o666) # Ensure users can write this, too, for now.
# Obviously a better approach would be a per-user file, but whatever.
except:
pass
def update_weather():
with open('/proc/netif','r') as f:
lines = f.readlines()
if len(lines) < 4 or "no network" in lines[0]:
with open('/tmp/weather.json','w') as f:
f.write("")
sys.exit(1)
try:
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={key}&units={units}"
data = subprocess.check_output(['fetch',url]).decode('utf-8').strip()
weather = json.loads(data)
if 'weather' in weather and len(weather['weather']) >= 1:
conditions = weather['weather'][0]
else:
conditions = None
temp = round(weather['main']['temp'])
output = {
'temp': weather['main']['temp'],
'temp_r': round(weather['main']['temp']),
'conditions': conditions['main'] if conditions else None,
'icon': conditions['icon'] if conditions else None,
'humidity': weather['main']['humidity'],
'clouds': weather['clouds']['all'] if 'all' in weather['clouds'] else None,
'city': city,
}
with open('/tmp/weather.json','w') as f:
f.write(json.dumps(output))
return True
except:
with open('/tmp/weather.json','w') as f:
f.write("")
return False
if __name__ == "__main__":
if "--config" in sys.argv:
import yutani
import yutani_mainloop
from input_box import TextInputWindow
if __name__ == '__main__':
yutani.Yutani()
d = yutani.Decor()
def quit():
sys.exit(0)
def set_units(inputbox):
global units
x_config['units'] = inputbox.text()
units = x_config['units']
inputbox.close()
write_config()
update_weather()
quit()
def set_city(inputbox):
global city
x_config['city'] = inputbox.text()
city = x_config['city']
inputbox.close()
TextInputWindow(d,"What units would you like? (metric, imperial, kelvin)","",text=units,callback=set_units, cancel_callback=quit)
TextInputWindow(d,"What city are you in?","",text=city,callback=set_city,cancel_callback=quit)
yutani_mainloop.mainloop()
sys.exit(0)
else:
if not update_weather():
sys.exit(1)