Add favicon support for Windows native#5841
Add favicon support for Windows native#5841DearRude wants to merge 4 commits intozauberzeug:mainfrom
Conversation
723057f to
616141c
Compare
### Implementation - Updated the `activate` function to accept a `favicon` parameter. - Modified the `_open_window` function to set the native window icon on Windows if a valid favicon file is provided. - Updated documentation to reflect the new favicon usage for native window icons. This change improves the user experience by allowing custom icons for native windows on Windows platforms.
616141c to
3d42cdb
Compare
|
@DearRude Wow. I nominate this for "top 3 first-time PR". I'm grabbing my Windows laptop for this one. |
|
@DearRude Works for titlebar, not for taskbar though.
Still, pretty good. Is taskbar functionality intended? |
The previous favicon support for native mode only set the window icon (title bar and Alt+Tab). This extends it to also set the taskbar icon using Windows IPropertyStore COM interface, which is required for proper taskbar icon display on Windows 7+. The implementation: - Adds shell32 access and COM GUID/PROPERTYKEY structures - Sets AppUserModelID to give the window a unique identity - Sets RelaunchIconResource to specify the taskbar icon path - Uses SHGetPropertyStoreForWindow to access the window's property store Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@DearRude Can you fix the pipeline? mypy and pylint isn't very happy... |
|
@evnchn Done. Let me know if I should squash the commits. |
|
Thanks, @DearRude! |
3bb748a to
209beb1
Compare
|
@DearRude I am guessing you came from GitLab which encourages force pushes? Because we don't really do force pushes for GitHub because the GitHub UI naturally encourages against it. Please don't do it unless it's necessary. Thanks. Example: GitLab you rebase a branch for latest main; GitHub you merge. |
|
Nice. Thank you for specifying that. |
|
@falkoschindler @evnchn Anything I have to do for now or do you think it is ready to be merged? |
|
@DearRude since this is schedule for 3.10, it is likely that we will look at this after at least 2 weeks from now. I'd consider this PR done for now. Please be on the watch out when we come around to review it. Meanwhile you can consider to work on items on the NiceGUI wishlist if you feel like it. MCP integration is a big one but not on the list just now. |
|
@falkoschindler I think it's your turn. Just find me if you want to test on Windows hardware. |
|
Thanks for the contribution, @DearRude! This is a nice addition for Windows users. I'm not very familiar with the Windows side of things, so I used Claude to help review the code. Here are some points that came up — it would be great if you could have a look:
|
|
@DearRude @falkoschindler I got some fixes at https://github.com/evnchn/nicegui/tree/evnchn/windows-native-icon but I don't have the time to review them yet. |


Motivation
pywebview's
iconparameter works only on Linux (GTK/Qt). On Windows and macOS, the window icon must typically be set at packaging time (via PyInstaller, Nuitka, etc.), so native NiceGUI windows on Windows show the default Python/executable icon instead of the app icon.Related issues and discussions:
LoadImageW+WM_SETICONto set the icon from a file path.This PR adds support for using the existing
faviconparameter fromui.run()as the native window icon on Windows when running in native mode. Users can pass a file path (e.g.favicon='icon.ico') and it will be applied to the taskbar and title bar at runtime, without requiring packaging changes.Implementation
favicon: No new API. Whennative=Trueandfaviconis a file path, it is passed to the native process.ui_run.py: Resolvesfaviconto an absolute path when it's a file and passes it tonative_module.activate().native_mode.py:activate()and_open_window()accept afaviconargument. On Windows, awindow.events.showncallback finds the window by title and sets the icon.window_icon.py(new): Windows-only helpers using ctypes:find_window_by_title()– usesEnumWindowsto get the HWNDset_window_icon_windows()– usesLoadImageWandWM_SETICONto set the iconiconthere).Progress