Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ app_py = [
'status.py',
'unlock.py',
'volumeControl.py',
'weather.py'
]

app_css = [
Expand Down
31 changes: 31 additions & 0 deletions src/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from util import utils, trackers, settings
from util.eventHandler import EventHandler
from util.utils import DEBUG
from weather import WeatherWidget

class Stage(Gtk.Window):
"""
Expand Down Expand Up @@ -69,6 +70,7 @@ def __init__(self, manager, away_message):
self.overlay = None
self.clock_widget = None
self.albumart_widget = None
self.weather_widget = None
self.unlock_dialog = None
self.audio_panel = None
self.info_panel = None
Expand Down Expand Up @@ -291,6 +293,11 @@ def setup_delayed_components(self, data=None):
except Exception as e:
print("Problem setting up albumart widget: %s" % str(e))
self.albumart_widget = None
try:
self.setup_weather()
except Exception as e:
print("Problem setting up weather widget: %s" % str(e))
self.weather_widget = None
try:
self.setup_status_bars()
except Exception as e:
Expand Down Expand Up @@ -324,6 +331,12 @@ def destroy_children(self):
except Exception as e:
print(e)

try:
if self.weather_widget is not None:
self.weather_widget.destroy()
except Exception as e:
print(e)

try:
if self.info_panel is not None:
self.info_panel.destroy()
Expand All @@ -345,6 +358,7 @@ def destroy_children(self):
self.unlock_dialog = None
self.clock_widget = None
self.albumart_widget = None
self.weather_widget = None
self.info_panel = None
self.audio_panel = None
self.osk = None
Expand Down Expand Up @@ -504,6 +518,23 @@ def setup_albumart(self):
if settings.get_show_albumart():
self.albumart_widget.start_positioning()

def setup_weather(self):
"""
Construct the Weather widget and add it to the overlay, but only actually
show it if we're a) Not running a plug-in, and b) The user wants it via
preferences.

Initially invisible, regardless - its visibility is controlled via its
own positioning timer.
"""
self.weather_widget = WeatherWidget(status.screen.get_mouse_monitor())
self.add_child_widget(self.weather_widget)

self.floaters.append(self.weather_widget)

if settings.get_show_weather():
self.weather_widget.start_positioning()

def setup_osk(self):
self.osk = OnScreenKeyboard()

Expand Down
24 changes: 24 additions & 0 deletions src/util/geojs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import json
from types import SimpleNamespace

import requests

from util.location import LocationProvider, LocationData

URL = "https://get.geojs.io/v1/ip/geo.json"

class GeoJSLocationProvider(LocationProvider):
"""
LocationProvider implementation for geojs.io
"""

def __init__(self):
pass

@staticmethod
def GetLocation() -> LocationData:
response = requests.get(URL)

data = json.loads(response.text, object_hook=lambda d: SimpleNamespace(**d))

return LocationData(float(data.latitude), float(data.longitude), data.city, data.country, data.timezone, data.city)
19 changes: 19 additions & 0 deletions src/util/location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Optional


@dataclass
class LocationData:
lat: float
lon: float
city: Optional[str] = None
country: Optional[str] = None
timeZone: Optional[str] = None
entryText: Optional[str] = None


class LocationProvider(ABC):
@abstractmethod
def GetLocation(self) -> LocationData:
pass
7 changes: 6 additions & 1 deletion src/util/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ app_py = [
'eventHandler.py',
'fader.py',
'focusNavigator.py',
'geojs.py',
'keybindings.py',
'location.py',
'openweathermap.py',
'settings.py',
'trackers.py',
'utils.py'
'utils.py',
'weather.py',
'weather_types.py'
]

install_data(app_py, install_dir: join_paths(pkgdatadir, 'util'))
Loading