hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en/latest/
MIT License
13.22k stars 688 forks source link

viewport icon doesn't work #1024

Open yonis65 opened 3 years ago

yonis65 commented 3 years ago

I have this code:

` setup_viewport()

    set_viewport_title(title='AddMeFast Bot')

    set_viewport_large_icon("sticker_2103-512x512.ico")

    set_viewport_small_icon("sticker_2103-512x512.ico")

    set_viewport_width(500)

    set_viewport_height(200)

    start_dearpygui()`

but it doesn't set the icon. Am I doing something wrong?

hoffstadt commented 3 years ago

Can you try an absolute path to the ico file?

yonis65 commented 3 years ago

It doesn't work

hoffstadt commented 3 years ago

Actually, you have to call these commands prior to "showing" the viewport. We will document this better later today. Below is a working example (expanded the setup_viewport command):

import dearpygui.dearpygui as dpg

vp = dpg.create_viewport()
dpg.setup_dearpygui(viewport=vp)

dpg.set_viewport_small_icon("C:/dev/DearPyGui/Resources/dpg_icon_small.ico")
dpg.set_viewport_large_icon("C:/dev/DearPyGui/Resources/dpg_icon_large.ico")

dpg.show_viewport(vp)

with dpg.window(label="", width=600, height=500) as ne_id:
    pass

dpg.start_dearpygui()
Tremeschin commented 3 years ago

Are those icon targets supposed to work on Linux?

I get parsing errors if the small_icon and large_icon args are given on create_viewport directly (perhaps they are not wired properly?)

Tho after creating the viewport and calling both set_viewport_small_icon and set_viewport_large_icon with DearPyGui's icons on Resources dir while it runs ok no icon image is shown on the docks (Windows only, too much low res, wrong data type?)

GLFW might be able to accept a full fat PNG file no problem for the icon, in fact I remember giving it a big PNG and working ok, I see we do call glfwSetWindowIcon on this current line but doesn't seem to do much.

Jah-On commented 3 years ago

Icons flat out don't work on Linux. I tried using ICO, PNG, and SVG. Some of which were ones that come with the OS. Here is the min code. I am running Manjaro Cinnamon, kernel 5.13, with Python 3.9, using the latest stable DPG install.

import dearpygui.dearpygui as dpg
import os

win = dpg.add_window()
dpg.set_primary_window(win, True)

dpg.setup_viewport()
dpg.set_viewport_large_icon("/usr/share/icons/Papirus-Dark/64x64/apps/acestream.svg")
dpg.set_viewport_small_icon("/usr/share/icons/Papirus-Dark/64x64/apps/acestream.svg")
dpg.start_dearpygui()
hoffstadt commented 3 years ago

Will check.

hoffstadt commented 3 years ago

Seems to be working on mine.

SriniMaiya commented 2 years ago

Hey, devs!! I just started to learn DPG using the documentation of DearPyGUI. I have landed on the same problem @Jah-On is/ was facing.

DearPyGUI version: 1.5.1 Python version: 3.9.7 (on venv)

OS: Ubuntu 20.04, Kernel Version: 5.13.0-39-generic

Screenshot from 2022-04-17 22-31-11

By the way, thanks a lot for the clean responsive GUI and clear documentation. <3

hoffstadt commented 2 years ago

Hi @SriniMaiya, we will reverify this!

AnnaSasDev commented 2 years ago

Uhm ... I might have the solution to this one (on windows)

def fix_icon_for_taskbar(app_model_id:str):
    # Define application ICON,
    #   make sure that dpg.viewport(large_icon=..., small_icon=...) kwargs are both set before this function is ran
    if (sys_platform := sys.platform) == "win32":
        # WINDOWS NEEDS THIS to make this possible
        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(app_model_id)
    else:
        # TODO fix this! (aka, find out how to do this)
        raise NotImplementedError(f"the 'fix_icon_for_taskbar' function does not currently work for the os: {sys_platform}")

(it's just a plug from my own lib) as I only work on windows and don't know what the actual equivalent to any of the other OS's might be. Btw, the app_model_id can just be any random string, as long as it isn't used by any other app on the pc, aka your application name should do the job

The thing is, for windows, the large_icon and small_icon have to be defined as .ico files

(couple of edits to make my code clearer)

I have a working link on my git repo: https://github.com/DirectiveAthena/AthenaDPGLib/tree/core/examples/ico Reason for repo link and not a plain code block: You need an ico file to test out, so I placed one with the example in the same folder

python 3.10 DearPyGui 1.6.2

sedenka commented 2 years ago

Thank you, successfully tested on Windows 10, Python 3.10.4.

AnnaSasDev commented 2 years ago

After going over my 1am solution I posted above, I scrolled up to see the following example by Hoffstadt

Actually, you have to call these commands prior to "showing" the viewport. We will document this better later today. Below is a working example (expanded the setup_viewport command):

import dearpygui.dearpygui as dpg

vp = dpg.create_viewport()
dpg.setup_dearpygui(viewport=vp)

dpg.set_viewport_small_icon("C:/dev/DearPyGui/Resources/dpg_icon_small.ico")
dpg.set_viewport_large_icon("C:/dev/DearPyGui/Resources/dpg_icon_large.ico")

dpg.show_viewport(vp)

with dpg.window(label="", width=600, height=500) as ne_id:
    pass

dpg.start_dearpygui()

And indeed, in the second file I created in my examples, it works the way Hoffstadt describes: https://github.com/DirectiveAthena/AthenaDPGLib/blob/core/examples/ico/ico_old_example_hoffstadt.py Which means there seems to be something wrong with the dpg.create_viewport(large_icon=..., small_icon=...) kwargs?

I've tried going over the source code (c++) but I can't seem to find where the "issue" occurs, this is probably because my understanding of c++ is very lacking

NaymDev commented 10 months ago

It’s not working for me(windows 11) but I don’t get any errors.. even if the file does not exist the code run normally except there is no icon… ): I tried everything mention here comment by comment nothing