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

missing buttons in top bar #3

Closed
hannesdelbeke opened this issue Apr 17, 2023 · 16 comments · Fixed by #4
Closed

missing buttons in top bar #3

hannesdelbeke opened this issue Apr 17, 2023 · 16 comments · Fixed by #4

Comments

@hannesdelbeke
Copy link
Collaborator

image

The buttons are there, but appear as if they are not. because they don't show the images.
This is likely an issue with the stylesheet hookup, or a icon-resource not found issue.

MODULE_PATH = os.path.dirname(os.path.abspath(__file__))
MODULE_NAME = os.path.basename(MODULE_PATH)
UI_PATH = os.path.join(MODULE_PATH, 'ui', 'script_editor.ui')
CONFIG_PATH = os.path.join(MODULE_PATH, 'config.txt')

I printed MODULE_PATH, which appears correct.
so that means this should be correct too:
QtCore.QResource.registerResource(os.path.join(MODULE_PATH, "icons", "icons.rcc"))

@leixingyu
Copy link
Owner

Thanks for flagging, I'll check it out

@leixingyu
Copy link
Owner

I just did a fresh install and the icons appeared fine on my end, but I guess it's safer (and less hassle) to not compile those into resources since there are only a few.

@leixingyu
Copy link
Owner

alrighty, fix is up.

@hannesdelbeke
Copy link
Collaborator Author

hannesdelbeke commented Jun 5, 2023

I'm afraid the buttons are still invisible with the latest update.
I tested this with PySide2

@hannesdelbeke
Copy link
Collaborator Author

hannesdelbeke commented Jun 5, 2023

  • if i set the path to an absolute path in script_editor.ui it works
  • if i change the relative path from ../icons/clearAll.png to ../unrealscripteditor-plugin/pythonscripteditor/content/python/unrealscripteditor/icons/clearAll.png it also works

it seems the relativeness is not from the ui file, but from something else. not sure what exactly
image

This makes me think that either it's related to how the environment is setup for the project.

Or there's a bug in the Qt module.
The UI loads correctly except for the icons. but the relativeness of the paths might be decided on something else, and the fault then doesn't ly with Qt.py

from Qt import _loadUi
_loadUi(UI_PATH, self)

@hannesdelbeke
Copy link
Collaborator Author

if i copy the icons folder to a higher folder, i can get it to work.
(1 folder above my project folder)
image
image

@hannesdelbeke
Copy link
Collaborator Author

hannesdelbeke commented Jun 5, 2023

if in pycharm i change the working directory to the icons, codeeditor or ui folder, the relative paths start to work, and the icons show up.
so it appears the relativeness in the path is from the working directory, not the .ui file

that also explains why it doesn't work in Unreal. the working directory is neither of those folders in the unreal projects.

@leixingyu
Copy link
Owner

weird, the startup.py should already be adding the root of the tool to sys.path which is basically what you described as adding the tool as working directory right?
did you add the startup.py as the startup file for unreal at all, if so, can you print out the sys.path and paste it here?

@hannesdelbeke
Copy link
Collaborator Author

hannesdelbeke commented Jun 6, 2023

paths in the original code

 'C:\\Users\\user\\repos\\unrealScriptEditor-plugin',
 'C:\\Users\\user\\repos\\unrealScriptEditor-plugin\\venv',
 'C:\\Users\\user\\repos\\unrealScriptEditor-plugin\\venv\\lib\\site-packages',
 'C:\\Users\\user\\repos\\unrealScriptEditor-plugin\\PythonScriptEditor\\Content\\Python',
 'C:\\Users\\user\\repos\\unrealScriptEditor-plugin\\PythonScriptEditor\\Content\\Python\\unrealScriptEditor\\..',

my working dir was set to the icons folder, so tried adding that to path but it doesn't fix the issue

'C:\\Users\\user\\repos\\unrealScriptEditor-plugin\\PythonScriptEditor\\Content\\Python\\unrealScriptEditor\\icons',
'C:\\Users\\user\\repos\\unrealScriptEditor-plugin\\PythonScriptEditor\\Content\\Python\\unrealScriptEditor']

i think working dir might be similar to active dir when you run commands.
e.g. when you cd to a folder in the terminal.

@hannesdelbeke
Copy link
Collaborator Author

hannesdelbeke commented Jun 6, 2023

adding to the path didn't fix it
but when i add the following line, to change the working dir it works

import os
os.chdir("C:\\Users\\user\\repos\\unrealScriptEditor-plugin\\PythonScriptEditor\\Content\\Python\\unrealScriptEditor\\icons")

image

Not sure if this is a recommended thing to do in unreal though
maybe we can change working dir, and change it back to the original afterwards?

@hannesdelbeke
Copy link
Collaborator Author

hannesdelbeke commented Jun 6, 2023

what also worked, and is perhaps a cleaner solution

in the .ui file, change ../icons/executeAll.png to ICONS:/executeAll.png
then run this in the startup.py file, before loading the UI

from PySide2.QtCore import QDir

MODULE_PATH = os.path.dirname(os.path.abspath(__file__))
ICONS_PATH = os.path.join(MODULE_PATH, 'icons')
QDir.addSearchPath("ICONS", ICONS_PATH)

@hannesdelbeke
Copy link
Collaborator Author

made a PR #4

@hannesdelbeke
Copy link
Collaborator Author

hannesdelbeke commented Jun 27, 2023

found another solution for this, even cleaner.

# change 
QtCore.QResource.registerResource("icons.rcc")
# to 
QtCore.QResource.registerResource(str(MODULE_PATH / "icons.rcc") )

now the rcc loads correctly, and no changes are needed to any other file. one line fix.
will create a PR for this in the original stylesheet repo

@leixingyu
Copy link
Owner

can you help me understand what this part is doing? str(MODULE_PATH / "icons.rcc")

@hannesdelbeke
Copy link
Collaborator Author

hannesdelbeke commented Jun 28, 2023

explanation

old code

QtCore.QResource.registerResource("icons.rcc") 
# this assumes this script runs from the same folder as icons.rcc
# or that icons.rcc is in the path.
# if however you import the stylesheet as a module, or anywhere not in the main path
# the icons can't be found in the search path. 

new code

QtCore.QResource.registerResource(str(MODULE_PATH / "icons.rcc") )
# the new code sets the Resource path to an explicit path, using pathlib
str(MODULE_PATH / "icons.rcc") # is actually the same as 
"C:\Users\hanne\OneDrive\Documents\repos\unrealStylesheet\unreal_qt_stylesheet\icons.rcc"

reference: see pyside searchpath docs

This approach means only a single line of code change is needed to fix the path
So we don't need these changes:

  • the merged in approach changed several files to fix it.
  • you also changed icon paths to fix the issue, which didnt fix it but was still merged in
  • another attempt to fix, by adding to sys path, ideally packages should avoid doing this since it changes import behaviour for other scripts.

@hannesdelbeke
Copy link
Collaborator Author

hannesdelbeke commented Jun 28, 2023

by the way, i don't think this needs changing in this repo, since we will fix this in the stylesheet repo,
and this issue is already fixed in this repo.

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

Successfully merging a pull request may close this issue.

2 participants