You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
994 B
35 lines
994 B
from pathlib import Path |
|
import json |
|
import math |
|
|
|
class Keymap: |
|
|
|
def __init__(self): |
|
self.keys = dict() |
|
pass |
|
|
|
def load_from_file(self, path = ''): |
|
if path == '': |
|
path = Path.home() / '.config/openrazer_scripter/keymap.json' |
|
with open(path,'r') as keymap_file: |
|
self.keys = json.load(keymap_file) |
|
|
|
def set_keys(self, keys): |
|
self.keys = keys |
|
|
|
def get_row_column(self, index): |
|
row = math.floor(index / 22) |
|
column = index % 22 |
|
return (row, column) |
|
|
|
def get_location(self, key): |
|
if key in self.keys.keys(): |
|
value = self.keys[key] |
|
return self.get_row_column(value) |
|
|
|
def write_keymap_file(self): |
|
keymap_json = json.dumps(self.keys) |
|
path = Path.home() / '.config/openrazer_scripter/keymap.json' |
|
Path(path.parent).mkdir(parents=True, exist_ok=True) |
|
with open(path,'w') as keymap_file: |
|
keymap_file.write(keymap_json) |