Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
Add BlocksTests
Browse files Browse the repository at this point in the history
  • Loading branch information
richardbuckle committed May 25, 2020
1 parent dc33e2b commit 9aeb793
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
14 changes: 14 additions & 0 deletions test_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@ def getvalue(self, key):
self.assertEqual(bindings.Mode.invalid, mode)


class BlocksTests(TestCase):

def createBlockImage(self, device):
if device == 'Keyboard': return
bindings.createBlockImage(device, dryRun=True)

def testDS4IsValid(self):
self.createBlockImage('DS4') # should not raise

def testAllValid(self):
for device in bindings.supportedDevices.keys():
self.createBlockImage(device)


class ModiferStylesTests(TestCase):

def testZeroIndex(self):
Expand Down
42 changes: 22 additions & 20 deletions www/scripts/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def writeText(context, img, text, screenState, font, surround, newLine):
else:
screenState['currentX'] = screenState['currentX'] + width

def createBlockImage(supportedDeviceKey, strokeColor='Red', fillColor='LightGreen'):
def createBlockImage(supportedDeviceKey, strokeColor='Red', fillColor='LightGreen', dryRun=False):
supportedDevice = supportedDevices[supportedDeviceKey]
# Set up the path for our file
templateName = supportedDevice['Template']
Expand All @@ -373,31 +373,33 @@ def createBlockImage(supportedDeviceKey, strokeColor='Red', fillColor='LightGree

with Image(filename='../res/' + supportedDevice['Template'] + '.jpg') as sourceImg:
with Drawing() as context:
context.font = getFontPath('Regular', 'Normal')
context.text_antialias = True
context.font_style = 'normal'
if not dryRun:
context.font = getFontPath('Regular', 'Normal')
context.text_antialias = True
context.font_style = 'normal'
maxFontSize = 40

for keyDevice in supportedDevice.get('KeyDevices', supportedDevice.get('HandledDevices')):
for (keycode, box) in hotasDetails[keyDevice].items():
if keycode == 'displayName':
continue
context.stroke_width = 1
context.stroke_color = Color(strokeColor)
context.fill_color = Color(fillColor)
context.rectangle(top=box['y'], left=box['x'], width=box['width'], height=box.get('height', 54))
context.stroke_width = 0
context.fill_color = Color('Black')
sourceTexts = [{'Text': keycode, 'Group': 'General', 'Style': groupStyles['General']}]
texts = layoutText(sourceImg, context, sourceTexts, box, maxFontSize)
for text in texts:
context.font_size = text['Size']
# TODO dry this up
context.font = text['Style']['Font']
context.text(x=text['X'], y=text['Y'], body=text['Text'])

context.draw(sourceImg)
sourceImg.save(filename=str(filePath))
if not dryRun:
context.stroke_width = 1
context.stroke_color = Color(strokeColor)
context.fill_color = Color(fillColor)
context.rectangle(top=box['y'], left=box['x'], width=box['width'], height=box.get('height', 54))
context.stroke_width = 0
context.fill_color = Color('Black')
sourceTexts = [{'Text': keycode, 'Group': 'General', 'Style': groupStyles['General']}]
texts = layoutText(sourceImg, context, sourceTexts, box, maxFontSize)
for text in texts:
context.font_size = text['Size']
# TODO dry this up
context.font = text['Style']['Font']
context.text(x=text['X'], y=text['Y'], body=text['Text'])
if not dryRun:
context.draw(sourceImg)
sourceImg.save(filename=str(filePath))

# Return whether a binding is a redundant specialisation and thus can be hidden
def isRedundantSpecialisation(control, bind):
Expand Down

0 comments on commit 9aeb793

Please sign in to comment.