Skip to content

Commit

Permalink
Merge branch 'master' into nuitka_313
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
emcek committed Jan 7, 2025
2 parents e14cc4c + 1ebb0f1 commit 945d62e
Show file tree
Hide file tree
Showing 40 changed files with 617 additions and 233 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
.codspeed/

# Translations
*.mo
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ repos:
exclude: 'helpers.py'

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
rev: v1.14.1
hooks:
- id: mypy
exclude: '/qt_gui\.py$|/qtgui_rc\.py$|tests/|generate_ver_file\.py$'
additional_dependencies: [types-cffi, types-Pillow, types-psutil, types-pyinstaller, types-PyYAML, types-requests, lxml]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.3
rev: v0.8.6
hooks:
- id: ruff
exclude: '/qtgui_rc.py$|tests/'
Expand All @@ -51,7 +51,7 @@ repos:
exclude: '/qtgui_rc.py$|tests/'

- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
rev: v3.19.1
hooks:
- id: pyupgrade
exclude: '/qtgui_rc.py$'
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 3.6.2
* Initial support colors for G19 - @emcek
* Internal:
* Improve checking for new releases (pydantic model) - @emcek
* Only one branch stable version of DCS is preferred for new installs - @emcek
* Make Nuitka with Python 3.13 default when building executable - @emcek

## 3.6.1
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ mkdocs-material==9.5.49
mkdocs-plantuml==0.1.1
mkdocs-section-index==0.3.9
mkdocstrings==0.27.0
mkdocstrings-python==1.12.2
mkdocstrings-python==1.13.0
plantuml==0.3.0
20 changes: 10 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ dynamic = ['version']
dependencies = [
'cffi==1.17.1',
'eval-type-backport==0.2.0 ; python_version < "3.10"',
'gitpython==3.1.43',
'gitpython==3.1.44',
'lupapy==2.2',
'packaging==24.2',
'pillow==11.0.0',
'psutil==6.1.0',
'pydantic==2.10.3',
'pillow==11.1.0',
'psutil==6.1.1',
'pydantic==2.10.4',
'pyside6==6.8.1',
'pyyaml==6.0.2',
'requests==2.32.3',
Expand All @@ -71,20 +71,20 @@ test = [
'interrogate==1.7.0',
'isort==5.13.2',
'lxml==5.3.0',
'mypy==1.13.0',
'mypy==1.14.1',
'pip-audit==2.7.3',
'pycodestyle==2.12.1',
'pytest==8.3.4',
'pytest-codspeed==3.1.0',
'pytest-cov==6.0.0',
'pytest-qt==4.4.0 ; sys_platform == "win32"',
'pytest-randomly==3.16.0',
'ruff==0.8.3',
'types-cffi==1.16.0.20240331',
'ruff==0.8.6',
'types-cffi==1.16.0.20241221',
'types-pillow==10.2.0.20240822',
'types-psutil==6.1.0.20241102',
'types-psutil==6.1.0.20241221',
'types-pyinstaller==6.11.0.20241028',
'types-pyyaml==6.0.12.20240917',
'types-pyyaml==6.0.12.20241230',
'types-requests==2.32.0.20241016',
]
docs = [
Expand All @@ -96,7 +96,7 @@ docs = [
'mkdocs-plantuml==0.1.1',
'mkdocs-section-index==0.3.9',
'mkdocstrings==0.27.0',
'mkdocstrings-python==1.12.2',
'mkdocstrings-python==1.13.0',
'plantuml==0.3.0',
]

Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cffi==1.17.1
eval-type-backport==0.2.0; python_version < '3.10'
GitPython==3.1.43
GitPython==3.1.44
lupapy==2.2
packaging==24.2
pillow==11.0.0
psutil==6.1.0
pydantic==2.10.3
pillow==11.1.0
psutil==6.1.1
pydantic==2.10.4
PySide6==6.8.1
PyYAML==6.0.2
requests==2.32.3
Expand Down
2 changes: 1 addition & 1 deletion requirements_docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ mkdocs-material==9.5.49
mkdocs-plantuml==0.1.1
mkdocs-section-index==0.3.9
mkdocstrings==0.27.0
mkdocstrings-python==1.12.2
mkdocstrings-python==1.13.0
plantuml==0.3.0
10 changes: 5 additions & 5 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ flake8==7.1.1
interrogate==1.7.0
isort==5.13.2
lxml==5.3.0
mypy==1.13.0
mypy==1.14.1
pip-audit==2.7.3
pycodestyle==2.12.1
pytest==8.3.4
pytest-codspeed==3.1.0
pytest-cov==6.0.0
pytest-qt==4.4.0; sys_platform == "win32"
pytest-randomly==3.16.0
ruff==0.8.3
types-cffi==1.16.0.20240331
ruff==0.8.6
types-cffi==1.16.0.20241221
types-Pillow==10.2.0.20240822
types-psutil==6.1.0.20241102
types-psutil==6.1.0.20241221
types-pyinstaller==6.11.0.20241028
types-PyYAML==6.0.12.20240917
types-PyYAML==6.0.12.20241230
types-requests==2.32.0.20241016
4 changes: 2 additions & 2 deletions src/dcspy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
LOG.debug(f'{uname()}')
LOG.debug(f'Configuration: {_config} from: {default_yaml}')
LOG.info(f'dcspy {__version__} https://github.com/{DCSPY_REPO_NAME}')
dcs_type, dcs_ver = check_dcs_ver(Path(str(_config['dcs'])))
LOG.info(f'DCS {dcs_type} ver: {dcs_ver}')
dcs_ver = check_dcs_ver(Path(str(_config['dcs'])))
LOG.info(f'DCS ver: {dcs_ver}')


def get_config_yaml_item(key: str, /, default: ConfigValue | None = None) -> ConfigValue:
Expand Down
58 changes: 35 additions & 23 deletions src/dcspy/logitech.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import copy
from functools import partial
from importlib import import_module
from logging import getLogger
Expand All @@ -10,9 +11,10 @@

from dcspy import dcsbios, get_config_yaml_item
from dcspy.aircraft import BasicAircraft, MetaAircraft
from dcspy.models import KEY_DOWN, SEND_ADDR, SUPPORTED_CRAFTS, TIME_BETWEEN_REQUESTS, AnyButton, Gkey, LcdButton, LcdType, LogitechDeviceModel, MouseButton
from dcspy.models import (KEY_DOWN, SEND_ADDR, SUPPORTED_CRAFTS, TIME_BETWEEN_REQUESTS, AnyButton, Color, Gkey, LcdButton, LcdType, LogitechDeviceModel,
MouseButton)
from dcspy.sdk import key_sdk, lcd_sdk
from dcspy.utils import get_full_bios_for_plane, get_planes_list
from dcspy.utils import get_full_bios_for_plane, get_planes_list, rgba

LOG = getLogger(__name__)

Expand All @@ -35,7 +37,7 @@ def __init__(self, parser: dcsbios.ProtocolParser, sock: socket, model: Logitech
self.bios_name = ''
self.plane_detected = False
self.lcdbutton_pressed = False
self._display: list[str] = []
self._text: list[tuple[str, Color]] = []
self.model = model
self.lcd_sdk = lcd_sdk.LcdSdkManager(name='DCS World', lcd_type=self.model.lcd_info.type)
self.key_sdk = key_sdk.GkeySdkManager(self.gkey_callback_handler)
Expand All @@ -44,37 +46,46 @@ def __init__(self, parser: dcsbios.ProtocolParser, sock: socket, model: Logitech
self.plane = BasicAircraft(self.model.lcd_info)

@property
def display(self) -> list[str]:
def text(self) -> list[tuple[str, Color]]:
"""
Get the latest text from LCD.
:return: List of strings with data, row by row
"""
return self._display
return self._text

@display.setter
def display(self, message: list[str]) -> None:
@text.setter
def text(self, message: list[tuple[str, Color]]) -> None:
"""
Display a message as an image at LCD.
Display text message at LCD.
For G13/G15/G510 takes the first four (4) or fewer elements of a list and display as four (4) rows.
For G19 takes the first eight (8) or fewer elements of the list and display as eight (8) rows.
:param message: List of strings to display, row by row.
First element is title - used only for G19
For G13/G15/G510 takes elements two (2) to four (4).
For G19 takes the elements two (2) to eight (8).
:param message: List of tuples with strings and color to display, row by row.
"""
self._display = message
self._text = message
if self.model.lcd_info.type != LcdType.NONE:
self.lcd_sdk.update_display(self._prepare_image())
self.lcd_sdk.update_text(copy(message))

def text(self, message: list[str]) -> None:
@property
def messages(self) -> list[str]:
"""
Display message at LCD.
Get the text massages without tittle from LCD.
For G13/G15/G510 takes the first four (4) or fewer elements of the list and display as four (4) rows.
:return: List of strings with data, row by row
"""
return [pair[0] for pair in self._text][1:]

def display(self) -> None:
"""
Display a message as an image at LCD.
For G13/G15/G510 takes the first four (4) or fewer elements of a list and display as four (4) rows.
For G19 takes the first eight (8) or fewer elements of the list and display as eight (8) rows.
:param message: List of strings to display, row by row.
"""
if self.model.lcd_info.type != LcdType.NONE:
self.lcd_sdk.update_text(message)
self.lcd_sdk.update_display(self._prepare_image())

def detecting_plane(self, value: str) -> None:
"""
Expand All @@ -88,16 +99,16 @@ def detecting_plane(self, value: str) -> None:
planes_list = get_planes_list(bios_dir=Path(get_config_yaml_item('dcsbios')))
if self.plane_name in SUPPORTED_CRAFTS:
LOG.info(f'Advanced supported aircraft: {value}')
self.display = ['Detected aircraft:', SUPPORTED_CRAFTS[self.plane_name]['name']]
self.text = [(' DCSpy ', Color.orange), ('Detected aircraft:', Color.white), (SUPPORTED_CRAFTS[self.plane_name]['name'], Color.green)]
self.plane_detected = True
elif self.plane_name not in SUPPORTED_CRAFTS and value in planes_list:
LOG.info(f'Basic supported aircraft: {value}')
self.bios_name = value
self.display = ['Detected aircraft:', value]
self.text = [(' DCSpy ', Color.orange), ('Detected aircraft:', Color.white), (value, Color.green)]
self.plane_detected = True
elif value not in planes_list:
LOG.warning(f'Not supported aircraft: {value}')
self.display = ['Detected aircraft:', value, 'Not supported yet!']
self.text = [(' DCSpy ', Color.orange), ('Detected aircraft:', Color.white), (value, Color.green), ('Not supported yet!', Color.red)]

def unload_old_plane(self) -> None:
"""Unloads the previous plane by remove all callbacks and keep only one."""
Expand Down Expand Up @@ -214,8 +225,9 @@ def _prepare_image(self) -> Image.Image:
img = Image.new(mode=self.model.lcd_info.mode.value, color=self.model.lcd_info.background,
size=(self.model.lcd_info.width.value, self.model.lcd_info.height.value))
draw = ImageDraw.Draw(img)
for line_no, line in enumerate(self._display):
draw.text(xy=(0, self.model.lcd_info.line_spacing * line_no), text=line, fill=self.model.lcd_info.foreground, font=self.model.lcd_info.font_s)
for line_no, txt_and_color in enumerate(self._text[1:]):
draw.text(xy=(0, self.model.lcd_info.line_spacing * line_no), text=txt_and_color[0],
fill=rgba(txt_and_color[1], mode=self.model.lcd_info.mode), font=self.model.lcd_info.font_s) # type: ignore[arg-type]
return img

def __str__(self) -> str:
Expand Down
Loading

0 comments on commit 945d62e

Please sign in to comment.