def get_md_action(button_index: int) -> str: """ Returns the md_action for the specified button. """ button_state = deck_api._button_state( # pylint: disable=protected-access _deck_id, deck_api.get_page(_deck_id), button_index) return button_state.get('material_deck', {}).get('init_data', {}).get('action', '') # type: ignore
def md_action_changed(button_index: int, action: str) -> None: """ Handles changing the type of action Material Deck listens for. """ global _ui # pylint: disable=global-statement,invalid-name button_state = deck_api._button_state( # pylint: disable=protected-access _deck_id, deck_api.get_page(_deck_id), button_index) page = deck_api.get_page(_deck_id) if action: deck_info: dict = button_state.setdefault('material_deck', {}) init_data = deck_info.setdefault( 'init_data', { 'event': 'willAppear', 'payload': { 'settings': { 'displayName': True, 'displayIcon': True, 'displaySceneIcon': True, 'displaySceneName': True, }, }, }) init_data['action'] = action command = _create_command_payload(action, 'keyDown', button_index, page) deck_api.set_button_command( _deck_id, page, button_index, f"{CONFIG_PATH}/pipe_writer.sh '{_bridge_file}' '{json.dumps(command)}'" ) _write_message( json.dumps( _create_will_display_payload(deck_info, button_index, page))) elif 'material_deck' in button_state: previous_action = button_state['material_deck'].get('init_data', {}).get( 'action', '') del button_state['material_deck'] _reset_button(button_index, '', page) _write_message( json.dumps({ 'event': 'willDisappear', 'action': previous_action, 'payload': { 'coordinates': { 'column': button_index % DECK_COLUMNS, 'row': math.floor(button_index / DECK_COLUMNS), }, }, 'context': _to_context(button_index, page), 'device': _deck_id, })) deck_api.export_config(DECK_CONFIG_FILE) deck_gui.redraw_buttons(_ui)
def get_md_data(button_index: int) -> str: """ Returns the md_data for the specified button """ button_state = deck_api._button_state( # pylint: disable=protected-access _deck_id, deck_api.get_page(_deck_id), button_index) deck_info = button_state.get('material_deck') if deck_info: return json.dumps(deck_info.setdefault('action_settings', {})) return ''
def key_up_callback(deck_id: str, key: int, state: bool) -> None: """ Handles key up events by sending the necessary information to the output queue. """ if state: log.warning('Released callback called while the state boolean is true') button_state = deck_api._button_state(deck_id, deck_api.get_page(_deck_id), key) # pylint: disable=protected-access md_info = button_state.get('material_deck') if md_info: _write_message( json.dumps( _create_command_payload(md_info['init_data']['action'], 'keyUp', key, deck_api.get_page(_deck_id))))
def _get_settings_for_action(action: str, button_index: int, page: int) -> dict: button_state = deck_api._button_state(_deck_id, page, button_index) # pylint: disable=protected-access action_settings: dict = button_state.setdefault('material_deck', {}).setdefault( 'action_settings', {}) if not action_settings: if action == 'soundboard': action_settings['soundNr'] = _to_context(button_index + 1, page) elif action == 'macro': action_settings['macroMode'] = 'macroBoard' action_settings['macroNumber'] = _to_context( button_index + 1, page) elif action == 'scene': action_settings['sceneFunction'] = 'any' action_settings['sceneName'] = '' return action_settings
def md_data_changed(button_index: int, text: str) -> None: """ Handles when data is changed within the md data box. """ try: json.loads(text) except Exception: # pylint: disable=broad-except return page = deck_api.get_page(_deck_id) button_state = deck_api._button_state(_deck_id, page, button_index) # pylint: disable=protected-access deck_info = button_state.get('material_deck', {}) if deck_info: deck_info['action_settings'] = json.loads(text) _write_message( json.dumps( _create_will_display_payload(deck_info, button_index, page)))