예제 #1
0
def redraw_buttons(ui) -> None:
    deck_id = _deck_id(ui)
    current_tab = ui.pages.currentWidget()
    buttons = current_tab.findChildren(QtWidgets.QToolButton)
    for button in buttons:
        button.setText(api.get_button_text(deck_id, _page(ui), button.index))
        button.setIcon(QIcon(api.get_button_icon(deck_id, _page(ui), button.index)))
예제 #2
0
def _handle_set_buffer_image(data: dict) -> None:
    payload = data['payload']
    cache_path = _get_path_from_image_id(payload['id'])
    page = _to_page(data['context'])
    if cache_path != deck_api.get_button_icon(_deck_id, page, _to_button_index(data['context'], page)) and\
            Path(cache_path).exists():
        deck_api.set_button_icon(_deck_id, page,
                                 _to_button_index(data['context'], page),
                                 cache_path)
예제 #3
0
def remove_image(window) -> None:
    deck_id = _deck_id(window.ui)
    image = api.get_button_icon(deck_id, _page(window.ui), selected_button.index)
    if image:
        confirm = QMessageBox(window)
        confirm.setWindowTitle("Remove image")
        confirm.setText("Are you sure you want to remove the image for this button?")
        confirm.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
        confirm.setIcon(QMessageBox.Question)
        button = confirm.exec_()
        if button == QMessageBox.Yes:
            api.set_button_icon(deck_id, _page(window.ui), selected_button.index, "")
            redraw_buttons(window.ui)
예제 #4
0
def select_image(window) -> None:
    deck_id = _deck_id(window.ui)
    image = api.get_button_icon(deck_id, _page(window.ui), selected_button.index)
    if not image:
        image = os.path.expanduser("~")

    file_name = QFileDialog.getOpenFileName(
        window, "Open Image", image, "Image Files (*.png *.jpg *.bmp)"
    )[0]
    if file_name:
        deck_id = _deck_id(window.ui)
        api.set_button_icon(deck_id, _page(window.ui), selected_button.index, file_name)
        redraw_buttons(window.ui)
예제 #5
0
파일: gui.py 프로젝트: Sawy7/streamdeck-ui
def redraw_buttons(ui) -> None:
    deck_id = _deck_id(ui)
    current_tab = ui.pages.currentWidget()
    buttons = current_tab.findChildren(QtWidgets.QToolButton)
    for button in buttons:
        # Give "info" priority
        info = api.get_button_info(deck_id, _page(ui), button.index)
        if info:
            button.setText(info)
            continue

        button.setText(api.get_button_text(deck_id, _page(ui), button.index))
        button.setIcon(QIcon(api.get_button_icon(deck_id, _page(ui), button.index)))
예제 #6
0
def _handle_set_image(data: dict) -> None:
    payload = data['payload']
    image_id = payload['id']
    cache_path = _get_path_from_image_id(image_id)
    page = _to_page(data['context'])
    if cache_path != deck_api.get_button_icon(
            _deck_id, page, _to_button_index(data['context'], page)):
        if not Path(cache_path).exists():
            Path(Path(cache_path).parent).mkdir(parents=True, exist_ok=True)
        if not Path(cache_path).exists():
            with request.urlopen(payload['image']) as response:
                with open(cache_path, 'wb') as image_file:
                    image_file.write(response.read())
        deck_api.set_button_icon(_deck_id, page,
                                 _to_button_index(data['context'], page),
                                 cache_path)
예제 #7
0
def select_image(window) -> None:
    global last_image_dir
    deck_id = _deck_id(window.ui)
    image = api.get_button_icon(deck_id, _page(window.ui),
                                selected_button.index)
    if not image:
        if not last_image_dir:
            image_file = os.path.expanduser("~")
        else:
            image_file = last_image_dir
    file_name = QFileDialog.getOpenFileName(
        window, "Open Image", image_file,
        "Image Files (*.png *.jpg *.bmp *.svg)")[0]
    if file_name:
        last_image_dir = os.path.dirname(file_name)
        deck_id = _deck_id(window.ui)
        api.set_button_icon(deck_id, _page(window.ui), selected_button.index,
                            file_name)
        redraw_buttons(window.ui)
예제 #8
0
def select_image(window) -> None:
    deck_id = _deck_id(window.ui)
    image = api.get_button_icon(deck_id, _page(window.ui),
                                selected_button.index)
    if not image:
        image = os.path.expanduser("~")

    root = tk.Tk()
    root.withdraw()

    file_name = filedialog.askopenfilename(
        initialdir=os.path.dirname(api.get_last_known_folder(deck_id)))

    # file_name = QFileDialog.getOpenFileName(
    #     window, "Open Image", image, "Image Files (*.png *.jpg *.bmp *.gif)"
    # )[0]
    if file_name:
        deck_id = _deck_id(window.ui)
        api.set_button_icon(deck_id, _page(window.ui), selected_button.index,
                            file_name)
        redraw_buttons(window.ui)