简体   繁体   中英

How to remove or replace the PyVista window icon?

How can I remove or change the PyVista render window's icon? I have tried to search the issue also from the docs but didn't find any answers.

This is not currently supported directly in PyVista, but this is a great idea and I'll open a pull request to implement this once a major refactor of render windows is done .

In the meantime you can use raw VTK , the SetIcon() method on render windows. According to the docs this only works on Windows and Linux though.

As of PyVista 0.36.1 you have direct access to plotter.ren_win which is a VTK render window object. According to the docs the icon should be a vtkImageData ; in practical PyVista terms this means UniformGrid s with dimensions (n, m, 1) .

Some experimentation suggests that the icon has to have uint8 active scalars of shape (n_points, 3) or (n_points, 4) , but I could only get the icon to actually show up on my linux machine with the latter setup. It seems that non-square shaped icons get tiled to square shape, so you have to crop your image to square shape first. Finally, you need to call ren_win.Render() before setting the icon, otherwise problems arise (on my linux machine: a segmentation fault).

Here's a small example:

import numpy as np
import pyvista as pv
from pyvista import examples

# example icon: cropped puppy mesh turned from RGB to RGBA
icon = examples.download_puppy().extract_subset([0, 1199, 0, 1199, 0, 0])
data = np.empty((icon.n_points, 4), dtype=np.uint8)
data[:, :-1] = icon.point_data['JPEGImage']
data[:, -1] = 255  # pad with full opacity
icon.point_data['JPEGImage'] = data

# create a plotter with a dummy mesh and set its icon
plotter = pv.Plotter()
plotter.add_mesh(pv.Dodecahedron())
ren_win = plotter.ren_win  # render window
ren_win.Render()  # important against segfault
ren_win.SetIcon(icon)
plotter.show()

With this my bottom panel looks like this:

带有看起来像小狗图像的图标的面板项目

It also works for my window switcher:

三个并排的大图标,用于 gimp、“vtk”和 firefox;中间的有小狗形象

(Interestingly, the window title in the title bar is "PyVista" which is the default title in pyvista.Plotter.__init__() , but in the window switcher I see "Vtk". I don't know why this is but I'll also try to see if we can fix this.)

Opacity handling seems to work too:

# add opacity in a nontrivial pattern
i, j = np.indices(icon.dimensions[:-1])
alpha = ((np.sin(2*i/icon.dimensions[0]*2*np.pi) * np.cos(j/icon.dimensions[1]*2*np.pi)) * 255).round().astype(np.uint8)
icon.point_data['JPEGImage'][:, -1] = alpha.ravel()

with this icon the window switcher looks like this:

带有三个图标的窗口切换器; “vtk”有一个时髦的黑色半透明覆盖层

It looks funky but that's just because the opacity pattern itself is funky. Transparency shows up as the switcher's semitransparent background colour on my system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM