Skip to content
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

Buttons should show icons or text (icon theme not properly set) #53

Closed
chaoticbear opened this issue Aug 8, 2020 · 32 comments
Closed

Comments

@chaoticbear
Copy link

Hi there, I'm Josh, I'm really interested in the project as there aren't many other similar applications available for Debian/Gnome with an easy to use UI.

Describe the bug
Main buttons and buttons on detail screens / tabs have no icons or text to indicate what they do. The buttons do work though.

To Reproduce
Steps to reproduce the behavior:

  1. Open application
  2. Main buttons and buttons on detail tabs / screens have no icons or text.

Expected behavior
Button icons or text should show to indicate what the button does.

Screenshots
image

OS

  • OS: Debian
  • Window Manager: Gnome 3
  • Kernel version: Linux 5.7.0-2-amd64 Master #1 SMP Debian 5.7.10-1 (2020-07-26) x86_64 GNU/Linux
  • Version Bullseye (Testing)

Additional context
N/A

@gustavo-iniguez-goya
Copy link
Owner

ouch, that's really weird and awful. I tested it on LinuxMint and Ubuntu 20 with gnome-shell 3.3x and it worked fine.

The preferences icon name is preferences-desktop, which is a standard name of the icon naming specification, and included in the package gnome-icon-theme.

So my first question is, do you have that package installed? I guess so, but just in case..

And the second question, can you fire a search of the file preferences-desktop.png? find /usr/share/icons/ -name 'preferences-desktop.png'
There should be several files like /usr/share/icons/gnome/32x32/categories/preferences-desktop.png

thank you for reporting it Josh!

@ryanolton
Copy link

I performed a fresh install this weekend and noticed this exact same thing happening with the icons. I have gnome-icon-theme installed and the find command noted returns the exact file shown (including other sizes).

I'm using Pop!_OS 20.04 (Ubuntu-based) and on another machine with this exact OS it works. The only different is the other machine originally had a RC of opensnitch (v1.0.0rc11) so perhaps something was working then and simply carried forward that the current (v1.0.1) version does not?

I'm certain I just don't have something installed the same as the other machine, but I don't know what to look for. If I use the Gnome Tweaks app and change the "Icons" setting under appearance to "Gnome" it works correct, but not with my distro default icons selected.

I'm happy to try anything you might think it is, thanks!

@chaoticbear
Copy link
Author

So my first question is, do you have that package installed? I guess so, but just in case..

gnome-icon-theme is already the newest version (3.12.0-3)

And the second question, can you fire a search of the file preferences-desktop.png? find /usr/share/icons/ -name 'preferences-desktop.png'
There should be several files like /usr/share/icons/gnome/32x32/categories/preferences-desktop.png

$ find /usr/share/icons/ -name 'preferences-desktop.png'
/usr/share/icons/Adwaita/22x22/legacy/preferences-desktop.png
/usr/share/icons/Adwaita/24x24/legacy/preferences-desktop.png
/usr/share/icons/Adwaita/48x48/legacy/preferences-desktop.png
/usr/share/icons/Adwaita/32x32/legacy/preferences-desktop.png
/usr/share/icons/Adwaita/16x16/legacy/preferences-desktop.png
/usr/share/icons/gnome/22x22/categories/preferences-desktop.png
/usr/share/icons/gnome/24x24/categories/preferences-desktop.png
/usr/share/icons/gnome/48x48/categories/preferences-desktop.png
/usr/share/icons/gnome/32x32/categories/preferences-desktop.png
/usr/share/icons/gnome/16x16/categories/preferences-desktop.png

Per @ryanolton 's comment I tried changing the icon theme with gnome tweaks and indeed my icons were initially not set to a theme, once I set them to either Adwaita or Gnome the icons appeared.

I then noticed that once I've set the icon set, if I use my Dark theme toggle gnome extension https://extensions.gnome.org/extension/2326/dark-theme-toggle/ the icons are unset again. So this may have been a bug with how that extension works, rather than your application. Though it might be nice if there was some kind of fallback in cases where maybe someone is using an oddball icon theme?

image

After using the dark theme toggle extension:
image

@gustavo-iniguez-goya
Copy link
Owner

Interesting finding! I really don't know if I can add a fallback for these cases. But at least I know now how to reproduce it, and maybe find a workaround.

@gustavo-iniguez-goya gustavo-iniguez-goya changed the title Buttons should show icons or text Buttons should show icons or text (icon theme not properly set) Aug 12, 2020
@gustavo-iniguez-goya
Copy link
Owner

As far as I can tell, I can change programmatically the icon theme, but I don't see a way to check if it has been applied correctly.

One option could be to check if there's no icon theme configured, and in such case display a warning dialog to the user. what do you think? At least the user will know that it's not an error in opensnitch so s/he can fix it.

@gustavo-iniguez-goya
Copy link
Owner

Ok, I've reproduced the issue on Pop!_OS 20.04. The default theme is under /usr/share/icons/Pop and effectively, the GUI icons are not set. The thing is that this theme in particular doesn't have the standard icons that we use on our GUI: document-new and document-save as per defined by freedesktop

So yes, I can fallback to the default Gnome theme Adwaita, and if it doesn't work either fallback to the old "gnome" theme.

you can try it by adding this lines to the end of __init__ in /usr/lib/python3/dist-packages/opensnitch/service.py:

        if QtGui.QIcon.hasThemeIcon("document-new") == False:
            self._show_theme_empty_dialog()
            QtGui.QIcon.setThemeName("Adwaita")
            if QtGui.QIcon.hasThemeIcon("document-new") == False:
                QtGui.QIcon.setThemeName("gnome")
        print("Icon Theme: ", QtGui.QIcon.themeName(), QtGui.QIcon.hasThemeIcon("document-new"))

@LaurentFough
Copy link

  • On Arch
  • Python: 3.8.6
  • OpenSnitch-UI: 1.0.1(.r3.544ce11) from this AUR Package: opensnitch-ui-git:

self._show_theme_empty_dialog(); generates an error:

Traceback (most recent call last):
 File "/usr/bin/opensnitch-ui", line 50, in <module>
   service = UIService(app, on_exit)
 File "/usr/lib/python3.8/site-packages/opensnitch/service.py", line 77, in __init__
   self._show_theme_empty_dialog()
AttributeError: 'UIService' object has no attribute '_show_theme_empty_dialog'

Setting the Theme programmatically via: QtGui.QIcon.setThemeName("DESIRED_ICON_THEME_NAME"), works, but I've found that the less intrusive working method is to simply create a symbolic link to the required icon theme in your local theme folder.

So:

$ cd ~/.local/share/icons
$ ln <DESIRED_ICON_THEME_NAME> gnome
  • Depending on how your icon themes are installed; doing this in /usr/share/icons would work as well, but making it global may cause issues later.

@gustavo-iniguez-goya
Copy link
Owner

gustavo-iniguez-goya commented Oct 14, 2020

Hi @LaurentFough , yes, my bad, this should be it:

# add the end of service.oy:__init__() method:

        if QtGui.QIcon.hasThemeIcon("document-new") == False:
            hasFallback = "fallbackThemeName" in dir(QtGui.QIcon)
            if hasFallback:
                fTheme = QtGui.QIcon.fallbackThemeName()
                if fTheme != "":
                    QtGui.QIcon.setThemeName(fTheme)
                else:
                    self._set_alternative_theme()
            else:
                self._set_alternative_theme()

    def _set_alternative_theme(self):
        themes = os.listdir("/usr/share/icons")
        try:
            themes.remove("HighContrast")
            themes.remove("hicolor")
            themes.remove("locolor")
        except Exception:
            pass

        for theme in themes:
            QtGui.QIcon.setThemeName(theme)
            if QtGui.QIcon.hasThemeIcon("document-new"):
                return

        if QtGui.QIcon.themeName() == "" or QtGui.QIcon.hasThemeIcon("document-new") == False:
            self._show_theme_empty_dialog()

    def _show_theme_empty_dialog(self):
        self._msg.setIcon(QtWidgets.QMessageBox.Warning)
        self._msg.setWindowTitle("OpenSnitch")
        self._msg.setText("Your Desktop Environment doesn't have an icon theme configured," + \
                "or it lacks of some icons (document-new, document-save)." + \
                "\n\nPlease, use gnome-tweaks or other tool to set an icon theme."
                )
        self._msg.setStandardButtons(QtWidgets.QMessageBox.Ok)
        self._msg.show()

@licaon-kter
Copy link

Seeing the same (better said not seeing any icons) on Debian Sid, amd64, built from git HEAD (1d49e81).

I have gnome-icon-theme and I did not get any warnings on start.

➜ find /usr/share/icons/ -name 'preferences-desktop.png'
/usr/share/icons/Faenza/categories/96/preferences-desktop.png
...
/usr/share/icons/gnome/24x24/categories/preferences-desktop.png
...
/usr/share/icons/Adwaita/24x24/legacy/preferences-desktop.png
...
/usr/share/icons/Tango/24x24/categories/preferences-desktop.png
...

@gustavo-iniguez-goya
Copy link
Owner

Hi @licaon-kter , do you see a warning dialog stating that your Desktop Environment doesn't have an icon theme configured?
What Window Manager are you using? Did you installed a theme not shipped with Debian?

Can you launch gnome-tweaks and post what icon theme appear configured under Appearance?

@licaon-kter
Copy link

As said above already, no warning.
It's a mix of XFCE and i3wm, I do have icons in GTK apps at least.

Did you installed a theme not shipped with Debian?

Dunno

I don't have Gnome or gnome-tweaks, is Gnome a dependency?

@gustavo-iniguez-goya
Copy link
Owner

yes, or any other tool that tell you the default icon theme configured, xfce4-settings-editor for example.

I'll install xfce and see if I can reproduce it. Thank you reporting this problem.

@licaon-kter
Copy link

licaon-kter commented Oct 30, 2020

xfce4-settings-editor I have, which property? xsettings - Net - IconThemeName? Says Faenza.

xfce4-appearance-settings says the same, switched to Adwaita or Gnome, still no icons, no warning.

/LE: Do I need to logout/login to get it applied? I don't see any changes.

@gustavo-iniguez-goya
Copy link
Owner

ok @licaon-kter , thank you, I'll try to reproduce it with xfce + i3wm.

@LaurentFough
Copy link

@gustavo-iniguez-goya this is still happening.
As previously mentioned I'm on Arch, running i3wm.

The only solution that's been working is still: QtGui.QIcon.setThemeName("DESIRED_ICON_THEME_NAME")

And I think there's been a regression in the code, unless you didn't commit the snippet above

# add the end of service.oy:__init__() method:

        if QtGui.QIcon.hasThemeIcon("document-new") == False:
            hasFallback = "fallbackThemeName" in dir(QtGui.QIcon)
            if hasFallback:
                fTheme = QtGui.QIcon.fallbackThemeName()
                if fTheme != "":
                    QtGui.QIcon.setThemeName(fTheme)
                else:
                    self._set_alternative_theme()
            else:
                self._set_alternative_theme()

    def _set_alternative_theme(self):
        themes = os.listdir("/usr/share/icons")
        try:
            themes.remove("HighContrast")
            themes.remove("hicolor")
            themes.remove("locolor")
        except Exception:
            pass

        for theme in themes:
            QtGui.QIcon.setThemeName(theme)
            if QtGui.QIcon.hasThemeIcon("document-new"):
                return

        if QtGui.QIcon.themeName() == "" or QtGui.QIcon.hasThemeIcon("document-new") == False:
            self._show_theme_empty_dialog()

    def _show_theme_empty_dialog(self):
        self._msg.setIcon(QtWidgets.QMessageBox.Warning)
        self._msg.setWindowTitle("OpenSnitch")
        self._msg.setText("Your Desktop Environment doesn't have an icon theme configured," + \
                "or it lacks of some icons (document-new, document-save)." + \
                "\n\nPlease, use gnome-tweaks or other tool to set an icon theme."
                )
        self._msg.setStandardButtons(QtWidgets.QMessageBox.Ok)
        self._msg.show()
  • I've been looking into it and it seems it's (near impossible) troublesome at best for a QT5 app to reliably (across multiple platforms+DE) determine the current theme.

That being said; we should be able to come up with a workable solution.

What are you're thoughts on including a simple UI to allow the user to select a theme?
Or including resources for the missing button images?

@gustavo-iniguez-goya
Copy link
Owner

gustavo-iniguez-goya commented Nov 17, 2020

ok @LaurentFough , I've just tested it with Gnome/Xfce + i3wm and the icons show up.

And I think there's been a regression in the code, unless you didn't commit the snippet above

That snippet is commited, what's the regression you are seeing?

What are you're thoughts on including a simple UI to allow the user to select a theme?

I think this is not a problem of opensnitch itself.

Or including resources for the missing button images?

This probably would be the solution. But you have to provide icons for multiple resolutions, etc.

Please, follow these instructions and see if any of them make the icons show up:

https://wiki.archlinux.org/index.php/Uniform_look_for_Qt_and_GTK_applications#Tips_and_tricks
https://wiki.archlinux.org/index.php/Uniform_look_for_Qt_and_GTK_applications#Troubleshooting

@LaurentFough
Copy link

Hi @gustavo-iniguez-goya

Neither of those links, had solutions that applied to me, or resolved the issue.
Most of the suggestions either don't apply to me, or my settings were already in line them.

As for the regression - not an issue - I can see you did, I was looking for a specific function order.

@LaurentFough
Copy link

More testing.

I see where the error is, just need to track down why it's happening.

Even though my theme is set to: "Arc"
In-App code is reporting that "hicolor" is the current theme.

currentTheme = QtGui.QIcon.themeName()
print(currentTheme)

hicolor

...

And then testing to see why no icons are being set.

        if QtGui.QIcon.hasThemeIcon("document-new") == False:
            print(currentTheme+"has no document-new icon")

hicolor
hicolor has no document-new icon

@gustavo-iniguez-goya
Copy link
Owner

great @LaurentFough ! thank you for analyze it.

Have you checked if you have the document-* icons? find /usr/share/icons -name 'document-*'

Maybe the theme Arc doesn't have these icons, as it happens with the theme Pop.

I removed HighContrast and lo/hicolor from themes list to test, because a system should have a theme configured. But hicolor is the fallback icon theme by default.

    def _set_alternative_theme(self):
        themes = os.listdir("/usr/share/icons")
        try:
            themes.remove("HighContrast")
            themes.remove("hicolor")
            themes.remove("locolor")

...there should always exist a theme called "hicolor...

By default, apps should look in $HOME/.icons (for backwards compatibility), in $XDG_DATA_DIRS/icons and in /usr/share/pixmaps (in that order)

https://developer.gnome.org/icon-theme-spec/

In my system:

$ env | grep XDG_DATA
XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share:/usr/share

@gustavo-iniguez-goya
Copy link
Owner

gustavo-iniguez-goya commented Nov 18, 2020

@LaurentFough can you try the following code snippet?

add this to stats.py , at the end of the constructor, after line 387

if QtGui.QIcon.hasThemeIcon("document-new") == False:                   
    self.newRuleButton.setIcon(self.style().standardIcon(getattr(QtWidgets.QStyle, "SP_FileIcon")))
    self.saveButton.setIcon(self.style().standardIcon(getattr(QtWidgets.QStyle, "SP_DialogSaveButton")))

@LaurentFough
Copy link

hi @gustavo-iniguez-goya,

My theme is in: ~/.local/share/icons, but yes, I've checked and it dœs have the correct Icons.

/home/$USER/.local/share/icons/Arc/actions/24/document-new.png
/home/$USER/.local/share/icons/Arc/actions/24@2x/document-new.png
/home/$USER/.local/share/icons/Arc/actions/22/document-new.png
/home/$USER/.local/share/icons/Arc/actions/22@2x/document-new.png
/home/$USER/.local/share/icons/Arc/actions/16/document-new.png
/home/$USER/.local/share/icons/Arc/actions/16@2x/document-new.png

@LaurentFough
Copy link

@LaurentFough can you try the following code snippet?

add this to stats.py , at the end of the constructor, after line 387

if QtGui.QIcon.hasThemeIcon("document-new") == False:                   
    self.newRuleButton.setIcon(self.style().standardIcon(getattr(QtWidgets.QStyle, "SP_FileIcon")))
    self.saveButton.setIcon(self.style().standardIcon(getattr(QtWidgets.QStyle, "SP_DialogSaveButton")))

Trying.
Will confirm, shortly.

@LaurentFough
Copy link

@gustavo-iniguez-goya,

That works.
You're setting the buttons to some standard defaults?

@gustavo-iniguez-goya
Copy link
Owner

Yes, Qt has some builtin icons, so we can use them in this case:
https://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum

But I'd really like to know why even having the standard icons, fromTheme() doesn't find them. Can you post the output of this:

$ python3
>>> from PyQt5 import QtWidgets
>>> app = QtWidgets.Appliaction([])
>>> for path in QtGui.QIcon.themeSearchPaths():
...        print ("%s/%s" % (path, QtGui.QIcon.themeName())

in my system after setting the hicolor theme:

/home/gus/.icons/hicolor
/usr/share/icons/hicolor
:/icons/hicolor

@LaurentFough
Copy link

/home/$USER/.icons/hicolor
/home/$USER/.local/share/icons/hicolor
/usr/share/icons/hicolor
:/icons/hicolor

@gustavo-iniguez-goya
Copy link
Owner

That seems to be the problem. We need to know why your theme is set to hicolor instead of Arc:

>>> from PyQt5 import QtGui
>>> QtGui.QIcon.themeName()

@gustavo-iniguez-goya
Copy link
Owner

On cinnamon or Gnome you can change the icon theme as follow:

gsettings set org.gnome.desktop.interface icon-theme "Arc"
gsettings set org.cinnamon.desktop.interface icon-theme "Arc"

No idea on i3. Many suggest to install lxappearance or dconf to change it. I think you should ask on i3 or Arch forums to get more help.

Anyway, I'll commit the changes to fallback to the Qt built-in icons in case the document-* icons are missing.

@LaurentFough
Copy link

LaurentFough commented Nov 18, 2020

That seems to be the problem. We need to know why your theme is set to hicolor instead of Arc:

>>> from PyQt5 import QtGui
>>> QtGui.QIcon.themeName()

Yes. I've run this snippet previously, while debugging.
And it also returns hicolor, unless I've explicitly set Arc in the python code.

I do have lxappearance installed.
Settings are fine there as well.

Let me do some more digging.

  • $ gsettings get org.gnome.desktop.interface icon-theme returns: Arc

gustavo-iniguez-goya added a commit that referenced this issue Nov 19, 2020
There're several situations where the icons of the app don't show up:
 - icon theme not configured.
 - icon theme configured but lacks standard icons defined by the
   standard (freedesktop).
 - icon theme configured but Qt doesn't load it.

If we fall into any of these cases, use the Qt built-in icons .

More information on this issue: #53

* removed non-used imports.
@gustavo-iniguez-goya
Copy link
Owner

hey @LaurentFough , did you have the chance to dig more on this issue?

Otherwise I'll close it.

@LaurentFough
Copy link

@gustavo-iniguez-goya

I did.

But nothing certain stood out.

I'm still just editing the source and setting my theme manually; as previously described.

@LaurentFough
Copy link

LaurentFough commented Dec 3, 2020

@gustavo-iniguez-goya;

I think the last commit in 1.3_0rc2 works.
The default icons work without any need for me to manually set a theme.

It's still not respecting my currently set theme, but all app buttons have icons.

Thanks.

@gustavo-iniguez-goya
Copy link
Owner

Great! thank you very much for your feedback Laurent :)

I'll close this issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants