def button_clicked(ui, clicked_button, buttons) -> None: global selected_button selected_button = clicked_button for button in buttons: if button == clicked_button: continue button.setChecked(False) selected_button.setFocus() deck_id = _deck_id(ui) button_id = selected_button.index ui.text.setText(api.get_button_text(deck_id, _page(ui), button_id)) ui.text_Align.setCurrentText( api.get_text_align(deck_id, _page(ui), button_id)) ui.font_Size.setValue(api.get_font_size(deck_id, _page(ui), button_id)) ui.font_Color.setCurrentText( api.get_font_color(deck_id, _page(ui), button_id)) ui.command.setText(api.get_button_command(deck_id, _page(ui), button_id)) ui.keys.setText(api.get_button_keys(deck_id, _page(ui), button_id)) ui.write.setPlainText(api.get_button_write(deck_id, _page(ui), button_id)) ui.change_brightness.setValue( api.get_button_change_brightness(deck_id, _page(ui), button_id)) ui.switch_page.setValue( api.get_button_switch_page(deck_id, _page(ui), button_id)) ui.target_device.setCurrentText( api.get_target_device(deck_id, _page(ui), button_id)) ui.selected_font.setCurrentText( api.get_selected_font(deck_id, _page(ui), button_id)) dimmers[deck_id].reset()
def button_clicked(ui, clicked_button, buttons) -> None: global selected_button selected_button = clicked_button for button in buttons: if button == clicked_button: continue button.setChecked(False) deck_id = _deck_id(ui) button_id = selected_button.index text = api.get_button_text(deck_id, _page(ui), button_id) ui.text.setText(text) ui.command.setText(api.get_button_command(deck_id, _page(ui), button_id)) ui.keys.setText(api.get_button_keys(deck_id, _page(ui), button_id)) ui.write.setPlainText(api.get_button_write(deck_id, _page(ui), button_id)) ui.change_brightness.setValue( api.get_button_change_brightness(deck_id, _page(ui), button_id)) ui.switch_page.setValue( api.get_button_switch_page(deck_id, _page(ui), button_id)) info_index = api.get_button_information_index(deck_id, _page(ui), button_id) if info_index == 0: api.set_button_info(deck_id, _page(ui), button_id, "") ui.information.setCurrentIndex(info_index) redraw_buttons(ui)
def button_clicked(ui, clicked_button, buttons) -> None: global selected_button selected_button = clicked_button for button in buttons: if button == clicked_button: continue button.setChecked(False) deck_id = _deck_id(ui) button_id = selected_button.index ui.text.setText(api.get_button_text(deck_id, _page(ui), button_id)) ui.command.setText(api.get_button_command(deck_id, _page(ui), button_id)) ui.keys.setText(api.get_button_keys(deck_id, _page(ui), button_id)) ui.write.setPlainText(api.get_button_write(deck_id, _page(ui), button_id)) ui.change_brightness.setValue(api.get_button_change_brightness(deck_id, _page(ui), button_id)) ui.switch_page.setValue(api.get_button_switch_page(deck_id, _page(ui), button_id))
def handle_keypress(deck_id: str, key: int, state: bool) -> None: if state: if dimmers[deck_id].reset(): return keyboard = Controller() page = api.get_page(deck_id) command = api.get_button_command(deck_id, page, key) if command: try: Popen(shlex.split(command)) except Exception as error: print(f"The command '{command}' failed: {error}") keys = api.get_button_keys(deck_id, page, key) if keys: keys = keys.strip().replace(" ", "") for section in keys.split(","): # Since + and , are used to delimit our section and keys to press, # they need to be substituded with keywords. section_keys = [_replace_special_keys(key_name) for key_name in section.split("+")] # Translate string to enum, or just the string itself if not found section_keys = [getattr(Key, key_name.lower(), key_name) for key_name in section_keys] for key_name in section_keys: try: if key_name == "delay": time.sleep(0.5) else: keyboard.press(key_name) except Exception: print(f"Could not press key '{key_name}'") for key_name in section_keys: try: if key_name != "delay": keyboard.release(key_name) except Exception: print(f"Could not release key '{key_name}'") write = api.get_button_write(deck_id, page, key) if write: try: keyboard.type(write) except Exception as error: print(f"Could not complete the write command: {error}") brightness_change = api.get_button_change_brightness(deck_id, page, key) if brightness_change: try: api.change_brightness(deck_id, brightness_change) dimmers[deck_id].brightness = api.get_brightness(deck_id) dimmers[deck_id].reset() except Exception as error: print(f"Could not change brightness: {error}") switch_page = api.get_button_switch_page(deck_id, page, key) if switch_page: api.set_page(deck_id, switch_page - 1)
def handle_keypress(deck_id: str, key: int, state: bool) -> None: if state: if dimmers[deck_id].reset(): return keyboard = Controller() page = api.get_page(deck_id) command = api.get_button_command(deck_id, page, key) if command: try: Popen(shlex.split(command)) except Exception as error: print(f"The command '{command}' failed: {error}") keys = api.get_button_keys(deck_id, page, key) if keys: keys = keys.strip().replace(" ", "") for section in keys.split(","): # Since + and , are used to delimit our section and keys to press, # they need to be substituted with keywords. section_keys = [ _replace_special_keys(key_name) for key_name in section.split("+") ] # Translate string to enum, or just the string itself if not found section_keys = [ getattr(Key, key_name.lower(), key_name) for key_name in section_keys ] for key_name in section_keys: if isinstance(key_name, str) and key_name.startswith("delay"): sleep_time_arg = key_name.split("delay", 1)[1] if sleep_time_arg: try: sleep_time = float(sleep_time_arg) except Exception: print( f"Could not convert sleep time to float '{sleep_time_arg}'" ) sleep_time = 0 else: # default if not specified sleep_time = 0.5 if sleep_time: try: time.sleep(sleep_time) except Exception: print( f"Could not sleep with provided sleep time '{sleep_time}'" ) else: try: keyboard.press(key_name) except Exception: print(f"Could not press key '{key_name}'") for key_name in section_keys: if not (isinstance(key_name, str) and key_name.startswith("delay")): try: keyboard.release(key_name) except Exception: print(f"Could not release key '{key_name}'") write = api.get_button_write(deck_id, page, key) if write: try: keyboard.type(write) except Exception as error: print(f"Could not complete the write command: {error}") brightness_change = api.get_button_change_brightness( deck_id, page, key) if brightness_change: try: api.change_brightness(deck_id, brightness_change) dimmers[deck_id].brightness = api.get_brightness(deck_id) dimmers[deck_id].reset() except Exception as error: print(f"Could not change brightness: {error}") switch_page = api.get_button_switch_page(deck_id, page, key) target_device = api.get_target_device(deck_id, page, key) if switch_page: api.set_page(target_device, switch_page - 1)