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.
73 lines
2.4 KiB
73 lines
2.4 KiB
import warnings |
|
from collections.abc import Iterable |
|
|
|
import openrazer.client |
|
|
|
from .color import Color |
|
from .keymap import Keymap |
|
|
|
|
|
class Keyboard: |
|
|
|
"""Provides tooling to call openrazer.client.device""" |
|
|
|
def __init__(self, no_keymap = False): |
|
self.kbd = None |
|
self.find_keyboard(no_keymap) |
|
if self.kbd is None: |
|
warnings.warn('Compatible keyboard was not detected', RuntimeWarning) |
|
|
|
def find_keyboard(self, no_keymap): |
|
if self.kbd is not None: |
|
print('keyboard was already initiated') |
|
return True |
|
|
|
devman = openrazer.client.DeviceManager() |
|
|
|
for device in devman.devices: |
|
if (device.name == "Razer BlackWidow Chroma V2"): |
|
self.kbd = device |
|
if not no_keymap: |
|
self.keymap = Keymap() |
|
self.keymap.load_from_file(self.kbd.name) |
|
return True |
|
return False |
|
|
|
def found_keyboard(self): |
|
return self.kbd is not None |
|
|
|
def keyboard_name(self): |
|
return self.kbd.name |
|
|
|
def set_keys(self, color, *keys): |
|
if not isinstance(color, Color): |
|
print(f"Color {color} for key(s) '{keys}' is no instance of Color, skipping.") |
|
return False |
|
for key in keys: |
|
if isinstance(key, Iterable) and not isinstance(key, str): # Allow for iterables (lists etc) of keys to be parsed |
|
for single_key in key: |
|
self.set_keys(color, single_key) |
|
else: |
|
location = self.keymap.get_location(key) |
|
self.kbd.fx.advanced.matrix[location] = [color.red, color.green, color.blue] |
|
return True |
|
|
|
def set_key(self, row, column, color): |
|
if not isinstance(color, Color): |
|
print(f"Color '{color}' for key {row},{column} is no instance of Color, skipping.") |
|
return False |
|
self.kbd.fx.advanced.matrix[row, column] = [color.red, color.green, color.blue] |
|
|
|
def set_static(self, color): |
|
if not isinstance(color, Color): |
|
print(f"Color for set_static() is no instance of Color, skipping.") |
|
return False |
|
for row in range(0,6): |
|
for column in range(0, 22): |
|
self.kbd.fx.advanced.matrix[row,column] = [color.red, color.green, color.blue] |
|
|
|
def clear(self): |
|
self.set_static(Color(0, 0, 0)) |
|
|
|
def draw(self): |
|
self.kbd.fx.advanced.draw()
|
|
|