Exemple #1
0
def test_double_row():
    i = KLE2xy('["",{h:2},"",""],["",{h:2},"",""]')
    # Key 1, 1x1 in upper left
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-9.525')
    # Key 2, 1x2 in upper center
    assert i[0][1]['width'] == Decimal('1')
    assert i[0][1]['height'] == Decimal('2')
    assert i[0][1]['x'] == Decimal('28.575')
    assert i[0][1]['y'] == Decimal('-19.05')
    # Key 3, 1x1 in upper right
    assert i[0][2]['width'] == Decimal('1')
    assert i[0][2]['height'] == Decimal('1')
    assert i[0][2]['x'] == Decimal('47.625')
    assert i[0][2]['y'] == Decimal('-9.525')
    # Key 4, 1x1 in lower left
    assert i[1][0]['width'] == Decimal('1')
    assert i[1][0]['height'] == Decimal('1')
    assert i[1][0]['x'] == Decimal('9.525')
    assert i[1][0]['y'] == Decimal('-28.575')
    # Key 5, 1x2 in lower center
    assert i[1][1]['width'] == Decimal('1')
    assert i[1][1]['height'] == Decimal('2')
    assert i[1][1]['x'] == Decimal('28.575')
    assert i[1][1]['y'] == Decimal('-38.1')
    # Key 6, 1x1 in lower right
    assert i[1][2]['width'] == Decimal('1')
    assert i[1][2]['height'] == Decimal('1')
    assert i[1][2]['x'] == Decimal('47.625')
    assert i[1][2]['y'] == Decimal('-28.575')
Exemple #2
0
def test_1_00u_y():
    i = KLE2xy('[{y:1},""]')
    assert i.width == Decimal('28.575')
    assert i.height == Decimal('47.625')
    assert i.size == (Decimal('28.575'), Decimal(47.625))
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-28.575')
Exemple #3
0
def test_1_00u():
    i = KLE2xy('[""]')
    assert i.width == Decimal('28.575')
    assert i.height == Decimal('28.575')
    assert i.size == (Decimal('28.575'), Decimal('28.575'))
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-9.525')
Exemple #4
0
def test_1_00u_label_style_negative():
    i = KLE2xy('[{a:-1},""]')
    assert i.width == Decimal('28.575')
    assert i.height == Decimal('28.575')
    assert i.size == (Decimal('28.575'), Decimal('28.575'))
    assert i[0][0]['label_style'] == 0
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-9.525')
Exemple #5
0
def test_iso_enter():
    i = KLE2xy('[{x:0.25,a:7,w:1.25,h:2,w2:1.5,h2:1,x2:-0.25},"Enter"]')
    assert i.width == Decimal('33.3375')
    assert i.height == Decimal('28.575')
    assert i.size == (Decimal('33.3375'), Decimal('28.575'))
    assert i[0][0]['isoenter'] == True
    assert i[0][0]['width'] == Decimal('1.25')
    assert i[0][0]['height'] == Decimal('2')
    assert i[0][0]['x'] == Decimal('16.66875')
    assert i[0][0]['y'] == Decimal('-19.05')
Exemple #6
0
def test_1_00u_dict():
    i = KLE2xy('{name:"test_1_00u_dict"},[""]')
    assert i.width == Decimal('28.575')
    assert i.height == Decimal('28.575')
    assert i.size == (Decimal('28.575'), Decimal('28.575'))
    assert i.name == 'test_1_00u_dict'
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-9.525')
Exemple #7
0
def test_1_00u_decal():
    i = KLE2xy('[{d:true},""]')
    assert i.width == Decimal('28.575')
    assert i.height == Decimal('28.575')
    assert i.size == (Decimal('28.575'), Decimal('28.575'))
    assert i[0][0]['decal'] == True
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-9.525')
Exemple #8
0
def test_2_75u():
    i = KLE2xy('[""],[{w:2.75},""]')
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-9.525')
    assert i[1][0]['width'] == Decimal('2.75')
    assert i[1][0]['height'] == Decimal('1')
    assert i[1][0]['x'] == Decimal('26.19375')
    assert i[1][0]['y'] == Decimal('-28.575')
Exemple #9
0
def test_1_00u_label_color():
    i = KLE2xy('[{t:"#232323"},""]')
    assert i.width == Decimal('28.575')
    assert i.height == Decimal('28.575')
    assert i.size == (Decimal('28.575'), Decimal('28.575'))
    assert i[0][0]['label_color'] == '#232323'
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-9.525')
Exemple #10
0
def test_2_50u():
    i = KLE2xy('[""],[{w:2.5},""]')
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-9.525')
    assert i[1][0]['width'] == Decimal('2.5')
    assert i[1][0]['height'] == Decimal('1')
    assert i[1][0]['x'] == Decimal('23.8125')
    assert i[1][0]['y'] == Decimal('-28.575')
Exemple #11
0
def test_2_00u():
    i = KLE2xy('[""],[{w:2},""]')
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-9.525')
    assert i[1][0]['width'] == Decimal('2')
    assert i[1][0]['height'] == Decimal('1')
    assert i[1][0]['x'] == Decimal('19.05')
    assert i[1][0]['y'] == Decimal('-28.575')
Exemple #12
0
def test_1_75u():
    i = KLE2xy('[""],[{w:1.75},""]')
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-9.525')
    assert i[1][0]['width'] == Decimal('1.75')
    assert i[1][0]['height'] == Decimal('1')
    assert i[1][0]['x'] == Decimal('16.66875')
    assert i[1][0]['y'] == Decimal('-28.575')
Exemple #13
0
def test_1_00u_keycap_profile():
    i = KLE2xy('[{p:"SA"},""]')
    assert i.width == Decimal('28.575')
    assert i.height == Decimal('28.575')
    assert i.size == (Decimal('28.575'), Decimal('28.575'))
    assert i[0][0]['keycap_profile'] == 'SA'
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-9.525')
Exemple #14
0
def test_1_00u_font_size_too_large():
    i = KLE2xy('[{f:10},""]')
    assert i.width == Decimal('28.575')
    assert i.height == Decimal('28.575')
    assert i.size == (Decimal('28.575'), Decimal('28.575'))
    assert i[0][0]['label_size'] == 9
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-9.525')
Exemple #15
0
def kle2json(cli):
    """Convert a KLE layout to QMK's layout format.
    """  # If filename is a path
    if cli.args.filename.startswith("/") or cli.args.filename.startswith("./"):
        file_path = Path(cli.args.filename)
    # Otherwise assume it is a file name
    else:
        file_path = Path(os.environ['ORIG_CWD'], cli.args.filename)
    # Check for valid file_path for more graceful failure
    if not file_path.exists():
        return cli.log.error(
            'File {fg_cyan}%s{style_reset_all} was not found.', file_path)
    out_path = file_path.parent
    raw_code = file_path.open().read()
    # Check if info.json exists, allow overwrite with force
    if Path(out_path, "info.json").exists() and not cli.args.force:
        cli.log.error(
            'File {fg_cyan}%s/info.json{style_reset_all} already exists, use -f or --force to overwrite.',
            out_path)
        return False
    try:
        # Convert KLE raw to x/y coordinates (using kle2xy package from skullydazed)
        kle = KLE2xy(raw_code)
    except Exception as e:
        cli.log.error('Could not parse KLE raw data: %s', raw_code)
        cli.log.exception(e)
        # FIXME: This should be better
        return cli.log.error('Could not parse KLE raw data.')
    keyboard = OrderedDict(
        keyboard_name=kle.name,
        url='',
        maintainer='qmk',
        width=kle.columns,
        height=kle.rows,
        layouts={'LAYOUT': {
            'layout': 'LAYOUT_JSON_HERE'
        }},
    )
    # Initialize keyboard with json encoded from ordered dict
    keyboard = json.dumps(keyboard,
                          indent=4,
                          separators=(', ', ': '),
                          sort_keys=False,
                          cls=CustomJSONEncoder)
    # Initialize layout with kle2qmk from converter module
    layout = json.dumps(kle2qmk(kle),
                        separators=(', ', ':'),
                        cls=CustomJSONEncoder)
    # Replace layout in keyboard json
    keyboard = keyboard.replace('"LAYOUT_JSON_HERE"', layout)
    # Write our info.json
    file = open(out_path + "/info.json", "w")
    file.write(keyboard)
    file.close()
    cli.log.info('Wrote out {fg_cyan}%s/info.json', out_path)
Exemple #16
0
def kle2json(cli):
    """Convert a KLE layout to QMK's layout format.
    """  # If filename is a path
    if cli.args.filename.startswith("/") or cli.args.filename.startswith("./"):
        file_path = Path(cli.args.filename)
    # Otherwise assume it is a file name
    else:
        file_path = Path(os.environ['ORIG_CWD'], cli.args.filename)
    # Check for valid file_path for more graceful failure
    if not file_path.exists():
        cli.log.error('File {fg_cyan}%s{style_reset_all} was not found.',
                      file_path)
        return False
    out_path = file_path.parent
    raw_code = file_path.read_text(encoding='utf-8')
    # Check if info.json exists, allow overwrite with force
    if Path(out_path, "info.json").exists() and not cli.args.force:
        cli.log.error(
            'File {fg_cyan}%s/info.json{style_reset_all} already exists, use -f or --force to overwrite.',
            out_path)
        return False
    try:
        # Convert KLE raw to x/y coordinates (using kle2xy package from skullydazed)
        kle = KLE2xy(raw_code)
    except Exception as e:
        cli.log.error('Could not parse KLE raw data: %s', raw_code)
        cli.log.exception(e)
        return False
    keyboard = {
        'keyboard_name': kle.name,
        'url': '',
        'maintainer': 'qmk',
        'width': kle.columns,
        'height': kle.rows,
        'layouts': {
            'LAYOUT': {
                'layout': kle2qmk(kle)
            }
        },
    }

    # Write our info.json
    keyboard = json.dumps(keyboard,
                          indent=4,
                          separators=(', ', ': '),
                          sort_keys=False,
                          cls=InfoJSONEncoder)
    info_json_file = out_path / 'info.json'

    info_json_file.write_text(keyboard)
    cli.log.info('Wrote out {fg_cyan}%s/info.json', out_path)
Exemple #17
0
def test_60_r3():
    i = KLE2xy(v60_r3_code)

    assert i[0][0]['name'] == 'Caps Lock'
    assert i[0][0]['width'] == Decimal('1.75')
    assert i[0][0]['height'] == Decimal('1')
    assert i[0][0]['x'] == Decimal('16.66875')
    assert i[0][0]['y'] == Decimal('-9.525')
    assert i[0][0]['column'] == Decimal('0')

    assert i[0][12]['name'] == 'Enter'
    assert i[0][12]['width'] == Decimal('2.25')
    assert i[0][12]['height'] == Decimal('1')
    assert i[0][12]['x'] == Decimal('264.31875')
    assert i[0][12]['y'] == Decimal('-9.525')
    assert i[0][12]['column'] == Decimal('12.75')
Exemple #18
0
def POST_v1_converters_kle():
    """Convert a KLE layout to QMK's layout format.
    """
    data = request.get_json(force=True)
    if not data:
        return error("Invalid JSON data!")

    if 'id' in data:
        gist_id = data['id'].split('/')[-1]
        raw_code = fetch_kle_json(gist_id)[1:-1]
    elif 'raw' in data:
        raw_code = data['raw']
    else:
        return error('You must supply either "id" or "raw" labels.')

    try:
        kle = KLE2xy(raw_code)
    except Exception as e:
        logging.error('Could not parse KLE raw data: %s', raw_code)
        logging.exception(e)
        return error(
            'Could not parse KLE raw data.')  # FIXME: This should be better

    keyboard = OrderedDict(
        keyboard_name=kle.name,
        url='',
        maintainer='qmk',
        width=kle.columns,
        height=kle.rows,
        layouts={'LAYOUT': {
            'layout': 'LAYOUT_JSON_HERE'
        }},
    )
    keyboard = json.dumps(keyboard,
                          indent=4,
                          separators=(', ', ': '),
                          sort_keys=False,
                          cls=CustomJSONEncoder)
    layout = json.dumps(kle_to_qmk(kle),
                        separators=(', ', ':'),
                        cls=CustomJSONEncoder)
    keyboard = keyboard.replace('"LAYOUT_JSON_HERE"', layout)
    response = make_response(keyboard)
    response.mimetype = app.config['JSONIFY_MIMETYPE']

    return response
Exemple #19
0
    def __init__(self, rawdata, eagle_version, switch_footprint, diode_type,
                 smd_led):
        """Representation of a keyboard.

        :param rawdata: Keyboard object from keyboard-layout-editor.com
        """
        super(Keyboard, self).__init__()
        self.layout = KLE2xy(rawdata[1:-1])
        self.eagle_version = eagle_version
        self._switch_footprint = switch_footprint
        self.diode_type = diode[diode_type]
        self.smd_led = False if smd_led.lower() == 'no' else smd_led.lower()
        self.rows = []
        self.max_col = 0
        self.backcolor = None
        self.name = None
        self.author = None
        self.notes = None
        self._board_scr = []
        self._column_board_scr = []
        self._column_schematic_scr = []
        self._key_board_scr = []
        self._key_schematic_scr = []
        self._schematic_scr = []
        self.schematic_preamble = '\n'.join(
            ('GRID ON;', 'GRID IN 0.1 1;', 'GRID ALT IN 0.01;',
             'SET WIRE_BEND 2;', '', ''))
        self.schematic_footer = '\n\nWINDOW FIT;'
        self.board_preamble = '\n'.join(
            ('GRID ON;', 'GRID MM 1 10;', 'GRID ALT MM .1;', '', ''))
        self.board_footer = '\n\nRATSNEST;\nWINDOW FIT;'
        self.default_next_key = {
            'y': 0,
            'w': 1,
            'h': 1,
        }
        self.sch_col_offset = (-0.3, 0.1)  # IN
        self.parse_json()
Exemple #20
0
def test_numpad():
    i = KLE2xy(numpad_code)
    # First row
    assert i[0][0]['name'] == 'Numlock'
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-9.525')

    assert i[0][1]['name'] == '/'
    assert i[0][1]['width'] == Decimal('1')
    assert i[0][1]['height'] == Decimal('1')
    assert i[0][1]['x'] == Decimal('28.575')
    assert i[0][1]['y'] == Decimal('-9.525')

    assert i[0][2]['name'] == '*'
    assert i[0][2]['width'] == Decimal('1')
    assert i[0][2]['height'] == Decimal('1')
    assert i[0][2]['x'] == Decimal('47.625')
    assert i[0][2]['y'] == Decimal('-9.525')

    assert i[0][3]['name'] == '-'
    assert i[0][3]['width'] == Decimal('1')
    assert i[0][3]['height'] == Decimal('1')
    assert i[0][3]['x'] == Decimal('66.675')
    assert i[0][3]['y'] == Decimal('-9.525')

    # Second row
    assert i[1][0]['name'] == '7\nHome'
    assert i[1][0]['width'] == Decimal('1')
    assert i[1][0]['height'] == Decimal('1')
    assert i[1][0]['x'] == Decimal('9.525')
    assert i[1][0]['y'] == Decimal('-28.575')

    assert i[1][1]['name'] == '8\nUp'
    assert i[1][1]['width'] == Decimal('1')
    assert i[1][1]['height'] == Decimal('1')
    assert i[1][1]['x'] == Decimal('28.575')
    assert i[1][1]['y'] == Decimal('-28.575')

    assert i[1][2]['name'] == '9\nPgUp'
    assert i[1][2]['width'] == Decimal('1')
    assert i[1][2]['height'] == Decimal('1')
    assert i[1][2]['x'] == Decimal('47.625')
    assert i[1][2]['y'] == Decimal('-28.575')

    assert i[1][3]['name'] == '+'
    assert i[1][3]['width'] == Decimal('1')
    assert i[1][3]['height'] == Decimal('2')
    assert i[1][3]['x'] == Decimal('66.675')
    assert i[1][3]['y'] == Decimal('-38.1')

    # Third row
    assert i[2][0]['name'] == '4\nLeft'
    assert i[2][0]['width'] == Decimal('1')
    assert i[2][0]['height'] == Decimal('1')
    assert i[2][0]['x'] == Decimal('9.525')
    assert i[2][0]['y'] == Decimal('-47.625')

    assert i[2][1]['name'] == '5'
    assert i[2][1]['width'] == Decimal('1')
    assert i[2][1]['height'] == Decimal('1')
    assert i[2][1]['x'] == Decimal('28.575')
    assert i[2][1]['y'] == Decimal('-47.625')

    assert i[2][2]['name'] == '6\nRight'
    assert i[2][2]['width'] == Decimal('1')
    assert i[2][2]['height'] == Decimal('1')
    assert i[2][2]['x'] == Decimal('47.625')
    assert i[2][2]['y'] == Decimal('-47.625')

    # Fourth row
    assert i[3][0]['name'] == '1\nEnd'
    assert i[3][0]['width'] == Decimal('1')
    assert i[3][0]['height'] == Decimal('1')
    assert i[3][0]['x'] == Decimal('9.525')
    assert i[3][0]['y'] == Decimal('-66.675')

    assert i[3][1]['name'] == '2\nDown'
    assert i[3][1]['width'] == Decimal('1')
    assert i[3][1]['height'] == Decimal('1')
    assert i[3][1]['x'] == Decimal('28.575')
    assert i[3][1]['y'] == Decimal('-66.675')

    assert i[3][2]['name'] == '3\nPgDn'
    assert i[3][2]['width'] == Decimal('1')
    assert i[3][2]['height'] == Decimal('1')
    assert i[3][2]['x'] == Decimal('47.625')
    assert i[3][2]['y'] == Decimal('-66.675')

    assert i[3][3]['name'] == 'Enter'
    assert i[3][3]['width'] == Decimal('1')
    assert i[3][3]['height'] == Decimal('2')
    assert i[3][3]['x'] == Decimal('66.675')
    assert i[3][3]['y'] == Decimal('-76.2')

    # Fifth row
    assert i[4][0]['name'] == '0\nIns'
    assert i[4][0]['width'] == Decimal('2')
    assert i[4][0]['height'] == Decimal('1')
    assert i[4][0]['x'] == Decimal('19.05')
    assert i[4][0]['y'] == Decimal('-85.725')

    assert i[4][1]['name'] == '.\nDel'
    assert i[4][1]['width'] == Decimal('1')
    assert i[4][1]['height'] == Decimal('1')
    assert i[4][1]['x'] == Decimal('47.625')
    assert i[4][1]['y'] == Decimal('-85.725')
Exemple #21
0
def test_1_25u():
    i = KLE2xy('[{h:1.25},""]')
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1.25')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-11.90625')
Exemple #22
0
def test_2_50u():
    i = KLE2xy('[{h:2.5},""]')
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('2.5')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-23.8125')
Exemple #23
0
def test_2_25u():
    i = KLE2xy('[{h:2.25},""]')
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('2.25')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-21.43125')
Exemple #24
0
def test_2_00u():
    i = KLE2xy('[{h:2},""]')
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('2')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-19.05')
Exemple #25
0
def test_1_75u():
    i = KLE2xy('[{h:1.75},""]')
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1.75')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-16.66875')
Exemple #26
0
def test_1_50u():
    i = KLE2xy('[{h:1.5},""]')
    assert i[0][0]['width'] == Decimal('1')
    assert i[0][0]['height'] == Decimal('1.5')
    assert i[0][0]['x'] == Decimal('9.525')
    assert i[0][0]['y'] == Decimal('-14.2875')