def select_image(window) -> None: file_name = QFileDialog.getOpenFileName( window, "Open Image", os.path.expanduser("~"), "Image Files (*.png *.jpg *.bmp)" )[0] deck_id = _deck_id(window.ui) api.set_button_icon(deck_id, _page(window.ui), selected_button.index, file_name) redraw_buttons(window.ui)
def dropEvent(self, e): # noqa: N802 - Part of QT signature. global selected_button self.setStyleSheet(BUTTON_STYLE) if e.source(): # Ignore drag and drop on yourself if e.source().index == self.index: return api.swap_buttons(_deck_id(self.ui), _page(self.ui), e.source().index, self.index) # In the case that we've dragged the currently selected button, we have to # check the target button instead so it appears that it followed the drag/drop if e.source().isChecked(): e.source().setChecked(False) self.setChecked(True) selected_button = self else: # Handle drag and drop from outside the application if e.mimeData().hasUrls: file_name = e.mimeData().urls()[0].toLocalFile() api.set_button_icon(_deck_id(self.ui), _page(self.ui), self.index, file_name) redraw_buttons(self.ui)
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)
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)
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)
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)
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)
def _reset_button(button_index: int, image_path: str, page: int) -> None: deck_api.set_button_text(_deck_id, page, button_index, '') deck_api.set_button_command(_deck_id, page, button_index, '') deck_api.set_button_icon(_deck_id, page, button_index, image_path)