-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from gazoodle/main
Merge main to dev
- Loading branch information
Showing
224 changed files
with
141,032 additions
and
173,605 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "gazoodle/geckolib", | ||
"image": "mcr.microsoft.com/devcontainers/python:3.13", | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"charliermarsh.ruff", | ||
"github.vscode-pull-request-github", | ||
"ms-python.python", | ||
"ms-python.vscode-pylance", | ||
"ryanluker.vscode-coverage-gutters" | ||
], | ||
"settings": { | ||
"files.eol": "\n", | ||
"editor.tabSize": 4, | ||
"editor.formatOnPaste": true, | ||
"editor.formatOnSave": true, | ||
"editor.formatOnType": false, | ||
"files.trimTrailingWhitespace": true, | ||
"python.analysis.typeCheckingMode": "basic", | ||
"python.analysis.autoImportCompletions": true, | ||
"python.defaultInterpreterPath": "/usr/local/bin/python", | ||
"[python]": { | ||
"editor.defaultFormatter": "charliermarsh.ruff" | ||
} | ||
} | ||
} | ||
}, | ||
"remoteUser": "vscode", | ||
"features": { | ||
"ghcr.io/devcontainers-extra/features/apt-packages:1": { | ||
"packages": [ | ||
"ffmpeg", | ||
"libturbojpeg0", | ||
"libpcap-dev", | ||
"iputils-ping", | ||
] | ||
} | ||
}, | ||
"runArgs": [ | ||
"-v", | ||
"${env:HOME}${env:USERPROFILE}/.ssh:/tmp/.ssh", | ||
"--add-host", | ||
"spa=10.1.209.91" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pip>=21.3.1 | ||
ruff==0.9.1 | ||
requests==2.32.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# The contents of this file is based on https://github.com/home-assistant/core/blob/dev/pyproject.toml | ||
|
||
target-version = "py312" | ||
|
||
[lint] | ||
select = [ | ||
"ALL", | ||
] | ||
|
||
ignore = [ | ||
"ANN101", # Missing type annotation for `self` in method | ||
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed | ||
"D203", # no-blank-line-before-class (incompatible with formatter) | ||
"D212", # multi-line-summary-first-line (incompatible with formatter) | ||
"COM812", # incompatible with formatter | ||
"ISC001", # incompatible with formatter | ||
] | ||
|
||
[lint.flake8-pytest-style] | ||
fixture-parentheses = false | ||
|
||
[lint.pyupgrade] | ||
keep-runtime-typing = true | ||
|
||
[lint.mccabe] | ||
max-complexity = 25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,80 @@ | ||
""" Abstract curses display class for use in asyncio app - Thanks | ||
to https://gist.github.com/davesteele/8838f03e0594ef11c89f77a7bca91206 """ | ||
""" | ||
Abstract curses display class for use in asyncio app. | ||
Thanks to https://gist.github.com/davesteele/8838f03e0594ef11c89f77a7bca91206 | ||
""" | ||
|
||
import _curses | ||
import asyncio | ||
import logging | ||
from abc import ABC, abstractmethod | ||
from curses import ERR, KEY_RESIZE, curs_set | ||
from context_sample import GeckoConstants # type: ignore | ||
|
||
import _curses | ||
from context_sample import GeckoAsyncTaskMan | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class AbstractDisplay(ABC): | ||
def __init__(self, stdscr: "_curses._CursesWindow"): | ||
"""Abstract display class.""" | ||
|
||
def __init__(self, stdscr: _curses.window) -> None: | ||
"""Initialize the class.""" | ||
self.stdscr = stdscr | ||
self.done: bool = False | ||
self.done_event = asyncio.Event() | ||
self.queue = asyncio.Queue(5) | ||
|
||
@abstractmethod | ||
def make_display(self) -> None: | ||
pass | ||
"""Make a display.""" | ||
|
||
@abstractmethod | ||
async def handle_char(self, char: int) -> None: | ||
pass | ||
"""Handle a character.""" | ||
|
||
def set_exit(self) -> None: | ||
self.done = True | ||
"""Indicagte we can exit.""" | ||
self.done_event.set() | ||
|
||
async def enqueue_input(self) -> None: | ||
"""Get input and queue it up.""" | ||
while not self.done_event.is_set(): | ||
char = self.stdscr.getch() | ||
await self.queue.put(char) | ||
|
||
async def process_input(self) -> None: | ||
"""Get queue data and process it.""" | ||
try: | ||
while not self.done_event.is_set(): | ||
char = await self.queue.get() | ||
if char == ERR: | ||
# Do nothing and let the loop continue without sleeping continue | ||
pass | ||
elif char == KEY_RESIZE: | ||
self.make_display() | ||
else: | ||
await self.handle_char(char) | ||
self.queue.task_done() | ||
|
||
except asyncio.CancelledError: | ||
_LOGGER.debug("Input loop cancelled") | ||
raise | ||
|
||
async def run(self) -> None: | ||
except: # noqa | ||
_LOGGER.exception("Exception in input loop") | ||
raise | ||
|
||
finally: | ||
_LOGGER.debug("Input loop finished") | ||
|
||
async def run(self, taskman: GeckoAsyncTaskMan) -> None: | ||
"""Run the display class.""" | ||
curs_set(0) | ||
self.stdscr.nodelay(True) | ||
self.stdscr.nodelay(True) # noqa: FBT003 | ||
|
||
self.make_display() | ||
|
||
while not self.done: | ||
char = self.stdscr.getch() | ||
if char == ERR: | ||
await asyncio.sleep(GeckoConstants.ASYNCIO_SLEEP_TIMEOUT_FOR_YIELD) | ||
elif char == KEY_RESIZE: | ||
self.make_display() | ||
else: | ||
await self.handle_char(char) | ||
taskman.add_task(self.enqueue_input(), "Input gather", "CUI") | ||
taskman.add_task(self.process_input(), "Process input", "CUI") | ||
await self.done_event.wait() | ||
taskman.cancel_key_tasks("CUI") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.