-
-
Notifications
You must be signed in to change notification settings - Fork 606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
favicon arg for ui.run does not work when native is true, even with default nicegui favicon. #620
Comments
Can you, please, give a minimal reproducible example and explain, what exactly does not work. What do you expect? What is happening instead? |
Of course from nicegui import ui
ui.button('Button', on_click=lambda: ui.notify('Click'))
ui.run(native=True, title="example", favicon= r"favicon.ico", reload=True) The |
A native window does not have a favicon at all. Or could you share a screenshot where the icon should appear? |
Its the small icon to the left of the "example" window title text. from nicegui import ui, app
import ctypes
icon_path = r"favicon.ico"
def set_icon(icon_path):
print("setting icon")
# Load the necessary Windows API functions using ctypes
user32 = ctypes.windll.user32
kernel32 = ctypes.windll.kernel32
# Get the handle of the current process and the current window
# Ideally replace this to directly reference the created webview window
hWnd = user32.GetForegroundWindow()
# Constants for Win32 API calls
ICON_SMALL = 0
ICON_BIG = 1
WM_SETICON = 0x0080
# Load the icon file
hIcon = user32.LoadImageW(None, icon_path, 1, 0, 0, 0x00000010)
# Set the window icon using WM_SETICON message
ctypes.windll.user32.SendMessageW(hWnd, WM_SETICON, ICON_SMALL, hIcon)
ctypes.windll.user32.SendMessageW(hWnd, WM_SETICON, ICON_BIG, hIcon)
# Button to manually change the icon
ui.button('Change Icon', on_click=lambda: set_icon(icon_path))
# Change icon on connection instead. Not ideal, as if created window does not have focus
# the icon will be set incorrectly elsewhere.
app.on_connect(lambda: set_icon("favicon.ico"))
ui.run(native=True, title="example", reload=True) |
@Skjolbir thank you for the example code and in-depth research. What do you mean with
You are already retrieving them in your code, or not? Are you looking for a better way? Is there a more elegant way with pywebview? If you have an example code for that, we could figure out a way on how to bring similar configuration options to NiceGUI. |
GetForegroundWindow function (winuser.h) GetModuleHandleW function (libloaderapi.h) LoadImageW function (winuser.h) Upon reading that GetModuleHandleW is optional, I have edited/removed it from the code example above. I will dig through pywebviews documentation a bit more, to see if there is anywhere I can pull the created window handle from, and if thats the case then it should be a guarantee that the webview window will have its icon set. I also notice that the icon is changed a little delayed when called from |
I've made a pull request with added icon support. edit: yeah, I think I messed up, its showing changes on 4 files, but it should just be changing 2; native_mode.py and run.py |
I'll close this stale issue in favor of a new feature request #1745. |
No description provided.
The text was updated successfully, but these errors were encountered: