Skip to content

Commit

Permalink
extract 'consola.ttf' as constant
Browse files Browse the repository at this point in the history
  • Loading branch information
emcek committed Oct 17, 2023
1 parent fbebab9 commit e6b3860
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
7 changes: 5 additions & 2 deletions dcspy/aircraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from PIL import Image, ImageDraw, ImageFont

from dcspy import default_yaml, load_yaml
from dcspy.models import CycleButton, Gkey, LcdButton, LcdInfo, LcdType
from dcspy.models import DEFAULT_FONT_NAME, CycleButton, Gkey, LcdButton, LcdInfo, LcdType
from dcspy.sdk import lcd_sdk

LOG = getLogger(__name__)
Expand Down Expand Up @@ -457,7 +457,10 @@ def draw_for_lcd_color(self, img: Image.Image) -> None:
for i in range(1, 7):
offset = (i - 1) * 24
# todo: fix custom font for Color LCD
draw.text(xy=(0, offset), text=str(self.get_bios(f'F_UFC_LINE{i}_DISPLAY')), fill=self.lcd.foreground, font=ImageFont.truetype('consola.ttf', 29))
draw.text(xy=(0, offset),
text=str(self.get_bios(f'F_UFC_LINE{i}_DISPLAY')),
fill=self.lcd.foreground,
font=ImageFont.truetype(DEFAULT_FONT_NAME, 29))


class Ka50(AdvancedAircraft):
Expand Down
1 change: 1 addition & 0 deletions dcspy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
# Others
LOCAL_APPDATA = True
DCSPY_REPO_NAME = 'emcek/dcspy'
DEFAULT_FONT_NAME = 'consola.ttf'
DCS_BIOS_REPO_DIR = Path(gettempdir()) / 'dcsbios_git'
CTRL_LIST_SEPARATOR = '--'
SUPPORTED_CRAFTS = {
Expand Down
16 changes: 8 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pytest import fixture

from dcspy import aircraft, logitech, models
from dcspy.models import FontsConfig
from dcspy.models import DEFAULT_FONT_NAME, FontsConfig


def generate_plane_fixtures(plane, lcd_type_with_fonts):
Expand Down Expand Up @@ -45,18 +45,18 @@ def _fixture():
airplane = getattr(aircraft, plane_model)
lcd_type = getattr(models, lcd)
if lcd == 'LcdMono':
lcd_type.set_fonts(FontsConfig(name='consola.ttf', small=9, medium=11, large=16))
lcd_type.set_fonts(FontsConfig(name=DEFAULT_FONT_NAME, small=9, medium=11, large=16))
else:
lcd_type.set_fonts(FontsConfig(name='consola.ttf', small=18, medium=22, large=32))
lcd_type.set_fonts(FontsConfig(name=DEFAULT_FONT_NAME, small=18, medium=22, large=32))
name = f'{airplane.__name__.lower()}_{lcd_type.type.name.lower()}'
globals()[name] = generate_plane_fixtures(airplane, lcd_type)

for keyboard_model in ['G13', 'G510', 'G15v1', 'G15v2', 'G19']:
key = getattr(logitech, keyboard_model)
if keyboard_model == 'G19':
lcd_font = FontsConfig(name='consola.ttf', small=18, medium=22, large=32)
lcd_font = FontsConfig(name=DEFAULT_FONT_NAME, small=18, medium=22, large=32)
else:
lcd_font = FontsConfig(name='consola.ttf', small=9, medium=11, large=16)
lcd_font = FontsConfig(name=DEFAULT_FONT_NAME, small=9, medium=11, large=16)
globals()[keyboard_model] = generate_keyboard_fixtures(key, lcd_font)


Expand Down Expand Up @@ -102,13 +102,13 @@ def protocol_parser():
@fixture()
def lcd_font_mono():
"""Returns font configuration for mono LCD."""
return FontsConfig(name='consola.ttf', small=9, medium=11, large=16)
return FontsConfig(name=DEFAULT_FONT_NAME, small=9, medium=11, large=16)


@fixture()
def lcd_font_color(protocol_parser):
"""Returns font configuration for color LCD."""
return FontsConfig(name='consola.ttf', small=18, medium=22, large=32)
return FontsConfig(name=DEFAULT_FONT_NAME, small=18, medium=22, large=32)


@fixture()
Expand Down Expand Up @@ -194,7 +194,7 @@ def default_config():
from os import environ
return {'dcsbios': f'D:\\Users\\{environ.get("USERNAME", "UNKNOWN")}\\Saved Games\\DCS.openbeta\\Scripts\\DCS-BIOS',
'dcs': 'C:\\Program Files\\Eagle Dynamics\\DCS World OpenBeta', 'keyboard': 'G13', 'save_lcd': False, 'show_gui': True, 'autostart': False,
'verbose': False, 'check_bios': True, 'check_ver': True, 'font_name': 'consola.ttf', 'font_mono_s': 11, 'font_mono_xs': 9, 'font_mono_l': 16,
'verbose': False, 'check_bios': True, 'check_ver': True, 'font_name': DEFAULT_FONT_NAME, 'font_mono_s': 11, 'font_mono_xs': 9, 'font_mono_l': 16,
'font_color_s': 22, 'font_color_xs': 18, 'font_color_l': 32, 'f16_ded_font': True, 'git_bios': False, 'git_bios_ref': 'master',
'theme_mode': 'system', 'theme_color': 'dark-blue', 'completer_items': 20, 'current_plane': 'A-10A'}

Expand Down
22 changes: 11 additions & 11 deletions tests/test_logitech.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pytest import mark

from dcspy.logitech import G13, G19, G510, G15v1, G15v2
from dcspy.models import FontsConfig, Gkey, LcdButton, LcdInfo, LcdMode, LcdType, generate_gkey
from dcspy.models import DEFAULT_FONT_NAME, FontsConfig, Gkey, LcdButton, LcdInfo, LcdMode, LcdType, generate_gkey


def test_keyboard_base_basic_check(keyboard_base):
Expand Down Expand Up @@ -133,11 +133,11 @@ def test_keyboard_mono_detecting_plane(plane_str, plane, display, detect, keyboa


@mark.parametrize('mode, size, lcd_type, lcd_font, keyboard', [
(LcdMode.BLACK_WHITE, (160, 43), LcdType.MONO, FontsConfig(name='consola.ttf', small=9, medium=11, large=16), G13),
(LcdMode.BLACK_WHITE, (160, 43), LcdType.MONO, FontsConfig(name='consola.ttf', small=9, medium=11, large=16), G510),
(LcdMode.BLACK_WHITE, (160, 43), LcdType.MONO, FontsConfig(name='consola.ttf', small=9, medium=11, large=16), G15v1),
(LcdMode.BLACK_WHITE, (160, 43), LcdType.MONO, FontsConfig(name='consola.ttf', small=9, medium=11, large=16), G15v2),
(LcdMode.TRUE_COLOR, (320, 240), LcdType.COLOR, FontsConfig(name='consola.ttf', small=18, medium=22, large=32), G19),
(LcdMode.BLACK_WHITE, (160, 43), LcdType.MONO, FontsConfig(name=DEFAULT_FONT_NAME, small=9, medium=11, large=16), G13),
(LcdMode.BLACK_WHITE, (160, 43), LcdType.MONO, FontsConfig(name=DEFAULT_FONT_NAME, small=9, medium=11, large=16), G510),
(LcdMode.BLACK_WHITE, (160, 43), LcdType.MONO, FontsConfig(name=DEFAULT_FONT_NAME, small=9, medium=11, large=16), G15v1),
(LcdMode.BLACK_WHITE, (160, 43), LcdType.MONO, FontsConfig(name=DEFAULT_FONT_NAME, small=9, medium=11, large=16), G15v2),
(LcdMode.TRUE_COLOR, (320, 240), LcdType.COLOR, FontsConfig(name=DEFAULT_FONT_NAME, small=18, medium=22, large=32), G19),
], ids=[
'Mono G13',
'Mono G510',
Expand Down Expand Up @@ -165,11 +165,11 @@ def test_check_keyboard_display_and_prepare_image(mode, size, lcd_type, lcd_font


@mark.parametrize('lcd_font, keyboard', [
(FontsConfig(name='consola.ttf', small=9, medium=11, large=16), G13),
(FontsConfig(name='consola.ttf', small=9, medium=11, large=16), G510),
(FontsConfig(name='consola.ttf', small=9, medium=11, large=16), G15v1),
(FontsConfig(name='consola.ttf', small=9, medium=11, large=16), G15v2),
(FontsConfig(name='consola.ttf', small=18, medium=22, large=32), G19)
(FontsConfig(name=DEFAULT_FONT_NAME, small=9, medium=11, large=16), G13),
(FontsConfig(name=DEFAULT_FONT_NAME, small=9, medium=11, large=16), G510),
(FontsConfig(name=DEFAULT_FONT_NAME, small=9, medium=11, large=16), G15v1),
(FontsConfig(name=DEFAULT_FONT_NAME, small=9, medium=11, large=16), G15v2),
(FontsConfig(name=DEFAULT_FONT_NAME, small=18, medium=22, large=32), G19)
], ids=[
'Mono G13',
'Mono G510',
Expand Down
3 changes: 2 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pytest import mark

from dcspy import utils
from dcspy.models import DEFAULT_FONT_NAME


@mark.parametrize('online_tag, result', [
Expand Down Expand Up @@ -102,7 +103,7 @@ def test_dummy_save_load_set_defaults(tmpdir):
'verbose': False,
'check_bios': True,
'check_ver': True,
'font_name': 'consola.ttf',
'font_name': DEFAULT_FONT_NAME,
'font_mono_s': 11,
'font_mono_xs': 9,
'font_mono_l': 16,
Expand Down

0 comments on commit e6b3860

Please sign in to comment.