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
17 changes: 8 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
FROM debian
FROM python:latest
MAINTAINER Zach White <skullydazed@gmail.com>

EXPOSE 5000
RUN apt-get update && apt-get install --no-install-recommends -y \
git \
python \
python-pip \
python-setuptools \
&& rm -rf /var/lib/apt/lists/*
# RUN apt-get update && apt-get install --no-install-recommends -y \
# git \
# python3 \
# python3-pip \
# python3-setuptools \
# && rm -rf /var/lib/apt/lists/*

WORKDIR /
RUN git clone https://github.com/skullydazed/kalerator.git
WORKDIR /kalerator
RUN pip install git+https://github.com/skullydazed/kle2xy.git
RUN pip install -r requirements.txt
RUN pip3 install -r requirements.txt
WORKDIR /kalerator/src
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion src/kalerator/diode.py → diode.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# coding=UTF-8
from .keyboard import float_to_str
from keyboard import float_to_str


class Diode(object):
"""Abstraction for keyboard diodes.
"""

def __init__(self, name, coord_in, coord_mm, footprint,
switch_offset_board, switch_offset_schematic,
switch_pin_offset, pin_neg_offset, pin_pos_offset):
Expand Down
File renamed without changes.
21 changes: 11 additions & 10 deletions src/kalerator/keyboard.py → keyboard.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# coding=UTF-8
from copy import deepcopy
import logging
from .config import diode, switches
from .functions import float_to_str, translate_board_coords
from .keyboard_key import KeyboardKey
from kle2xy import KLE2xy
from copy import deepcopy

from config import diode
from functions import float_to_str, translate_board_coords
from keyboard_key import KeyboardKey
from kle2xy import KLE2xy

key_translation = {
'': 'SPACE',
Expand Down Expand Up @@ -112,9 +112,9 @@ def schematic_scr(self):
"""
if not self._schematic_scr:
self._schematic_scr = '\n'.join((self.schematic_preamble,
self.key_schematic_scr,
self.column_schematic_scr,
self.schematic_footer))
self.key_schematic_scr,
self.column_schematic_scr,
self.schematic_footer))

return self._schematic_scr

Expand Down Expand Up @@ -299,8 +299,9 @@ def parse_json(self):
coord = [key['column'], key['row']]
coord_mm = [key['x'], key['y']]
last_key = self[key_name] = KeyboardKey(key_name, last_key, next_key,
self.eagle_version, switch_footprint=footprint,
diode=self.diode_type, coord=coord, coord_mm=coord_mm, smd_led=self.smd_led)
self.eagle_version, switch_footprint=footprint,
diode=self.diode_type, coord=coord, coord_mm=coord_mm,
smd_led=self.smd_led)
self.rows[-1].append(key_name)
next_key = self.default_next_key.copy()

Expand Down
7 changes: 4 additions & 3 deletions src/kalerator/keyboard_key.py → keyboard_key.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# coding=UTF-8
from decimal import Decimal

from .config import key_spacing_in, key_spacing_mm
from .diode import Diode
from .functions import float_to_str, translate_board_coords
from config import key_spacing_mm
from diode import Diode
from functions import float_to_str, translate_board_coords


class KeyboardKey(object):
"""Abstraction for keyboard switches.
"""

def __init__(self, name, left_key, next_key, eagle_version, coord, coord_mm, switch_footprint, diode, smd_led):
self.name = name.replace(' ', '')
self.left_key = left_key
Expand Down
4 changes: 2 additions & 2 deletions bin/kle → kle.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# coding=UTF-8
import json
import logging
from argparse import ArgumentParser
from kalerator.keyboard import Keyboard

from keyboard import Keyboard

# Setup our environment
logging.basicConfig()
Expand Down
155 changes: 155 additions & 0 deletions kle2xy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
from decimal import Decimal

import hjson


class KLE2xy(list):
"""Abstract interface for interacting with a KLE layout.
"""

def __init__(self, layout=None, name='', invert_y=True):
super(KLE2xy, self).__init__()

self.name = name
self.invert_y = invert_y
self.key_width = Decimal('19.05')
self.key_skel = {
'decal': False,
'border_color': 'none',
'keycap_profile': '',
'keycap_color': 'grey',
'label_color': 'black',
'label_size': 3,
'label_style': 4,
'width': Decimal('1'), 'height': Decimal('1'),
'x': Decimal('0'), 'y': Decimal('0')
}
self.rows = Decimal(0)
self.columns = Decimal(0)

if layout:
self.parse_layout(layout)

@property
def width(self):
"""Returns the width of the keyboard plate.
"""
return (Decimal(self.columns) * self.key_width) + self.key_width / 2

@property
def height(self):
"""Returns the height of the keyboard plate.
"""
return (self.rows * self.key_width) + self.key_width / 2

@property
def size(self):
"""Returns the size of the keyboard plate.
"""
return (self.width, self.height)

def attrs(self, properties):
"""Parse the keyboard properties dictionary.
"""
# FIXME: Store more than just the keyboard name.
if 'name' in properties:
self.name = properties['name']

def parse_layout(self, layout):
# Wrap this in a dictionary so hjson will parse KLE raw data
layout = '{"layout": [' + layout + ']}'
layout = hjson.loads(layout)['layout']

# Initialize our state machine
current_key = self.key_skel.copy()
current_row = Decimal(0)
current_col = Decimal(0)
current_x = 0
current_y = self.key_width / 2

if isinstance(layout[0], dict):
self.attrs(layout[0])
layout = layout[1:]

for row_num, row in enumerate(layout):
self.append([])

# Process the current row
for key in row:
if isinstance(key, dict):
if 'w' in key and key['w'] != Decimal(1):
current_key['width'] = Decimal(key['w'])
if 'w2' in key and 'h2' in key and key['w2'] == 1.5 and key['h2'] == 1:
# FIXME: ISO Key uses these params: {x:0.25,w:1.25,h:2,w2:1.5,h2:1,x2:-0.25}
current_key['isoenter'] = True
if 'h' in key and key['h'] != Decimal(1):
current_key['height'] = Decimal(key['h'])
if 'a' in key:
current_key['label_style'] = self.key_skel['label_style'] = int(key['a'])
if current_key['label_style'] < 0:
current_key['label_style'] = 0
elif current_key['label_style'] > 9:
current_key['label_style'] = 9
if 'f' in key:
font_size = int(key['f'])
if font_size > 9:
font_size = 9
elif font_size < 1:
font_size = 1
current_key['label_size'] = self.key_skel['label_size'] = font_size
if 'p' in key:
current_key['keycap_profile'] = self.key_skel['keycap_profile'] = key['p']
if 'c' in key:
current_key['keycap_color'] = self.key_skel['keycap_color'] = key['c']
if 't' in key:
# FIXME: Need to do better validation, plus figure out how to support multiple colors
if '\n' in key['t']:
key['t'] = key['t'].split('\n')[0]
if key['t'] == "0":
key['t'] = "#000000"
current_key['label_color'] = self.key_skel['label_color'] = key['t']
if 'x' in key:
current_col += Decimal(key['x'])
current_x += Decimal(key['x']) * self.key_width
if 'y' in key:
current_row += Decimal(key['y'])
current_y += Decimal(key['y']) * self.key_width
if 'd' in key:
current_key['decal'] = True

else:
current_key['name'] = key
current_key['row'] = current_row
current_key['column'] = current_col

# Determine the X center
x_center = (current_key['width'] * self.key_width) / 2
current_x += x_center
current_key['x'] = current_x
current_x += x_center

# Determine the Y center
y_center = (current_key['height'] * self.key_width) / 2
y_offset = y_center - (self.key_width / 2)
current_key['y'] = (current_y + y_offset)

# Tend to our row/col count
current_col += current_key['width']
if current_col > self.columns:
self.columns = current_col

# Invert the y-axis if neccesary
if self.invert_y:
current_key['y'] = -current_key['y']

# Store this key
self[-1].append(current_key)
current_key = self.key_skel.copy()

# Move to the next row
current_x = 0
current_y += self.key_width
current_col = Decimal(0)
current_row += Decimal(1)
if current_row > self.rows:
self.rows = Decimal(current_row)
6 changes: 6 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env python3
from web.app import app

if __name__ == "__main_c_":
app.debug = True
app.run()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ greenlet
gevent
gunicorn
requests
hjson
6 changes: 3 additions & 3 deletions run-server.flask
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
from kalerator.web.app import app
#!/usr/bin/env python3
from web import app


if __name__ == "__main__":
app.debug = True
app.run()
app.app.run()
10 changes: 4 additions & 6 deletions run-server.gevent
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/usr/bin/env python
from gevent.wsgi import WSGIServer
from werkzeug.serving import run_with_reloader
from kalerator.web.app import app
#!/usr/bin/env python3
from gevent.pywsgi import WSGIServer
from web.app import app


@run_with_reloader
def run_server():
app.debug = True
ws = WSGIServer(listener=('0.0.0.0', 5000), application=app)
print ' * Listening on http://0.0.0.0:5000/'
print(' * Listening on http://0.0.0.0:5000/')
ws.serve_forever()


Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# Special thanks to Hynek Schlawack for providing excellent documentation:
#
# https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/
Expand All @@ -23,7 +23,7 @@ def read(*paths):
author_email='skullydazed@gmail.com',
install_requires=['flask', 'flask-csrf', 'greenlet', 'gevent', 'requests', 'kle2xy'],
packages=find_packages(),
scripts=['bin/kle'],
scripts=['bin/kle.py'],
include_package_data=True,
classifiers=[
'Development Status :: 5 - Production/Stable',
Expand Down
1 change: 0 additions & 1 deletion src/kalerator/web/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=UTF-8
import pytest
from kalerator.web.app import app as kalerator_app
from web.app import app as kalerator_app

@pytest.fixture
def app():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_diode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=UTF-8
from kalerator.config import diode
from kalerator.diode import Diode
from config import diode
from diode import Diode


def test_Diode():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=UTF-8
from kalerator.functions import float_to_str, to_imperial
from functions import float_to_str, to_imperial


def test_float_to_str():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=UTF-8
from kalerator.web.helpers import render_page
from web.helpers import render_page


def test_render_page(app):
Expand Down
Loading