Issue
I have a package with the following structure:
package
├── LICENSE
├── README.md
├── MANIFEST.in
├── my_pkg
│ └── __init__.py
│ └── main.py
│ └── style.qss
├── setup.py
When I install it from github using pip
, the stylesheet file style.qss
is cloned, but when I launch the script typing foopkg
it is not loaded. This is my setup.py
file:
setup.py
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="my_pkg",
version="0.0.1",
author="foo",
author_email="[email protected]",
description="A small gui",
long_description=long_description,
long_description_content_type="text/markdown",
# url="https://github.com/foo/pkg",
include_package_data=True,
packages=setuptools.find_packages(),
install_requires=[
'PyQt5',
],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.7',
entry_points={
"gui_scripts": [
"foopkg = my_pkg.main:main",
]
}
)
And this is my MANIFEST.in
file:
MANIFEST.in
recursive-include my_pkg *.qss
The main.py is
main.py
import sys
...
def main():
app = QApplication(sys.argv)
style_path = sys.path[0] + '/style.qss'
file = QFile(style_path)
file.open(QFile.ReadOnly)
stream = QTextStream(file.readAll())
app.setStyleSheet(stream.readAll())
gui = GuiWindow()
gui.show()
app.exec_()
if __name__ == '__main__':
main()
What am I missing? What should I modify to be able to call my script using stylesheet?
Solution
When you build routes you must take into account what information each part contains, for example sys.path[0]
contains the information from where the application is launched, for example when launching the entrypoint in Linux in my case it is /usr/bin. Instead you should use the __file__
attribute:
import os
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
def main():
app = QApplication(sys.argv)
style_path = os.path.join(CURRENT_DIR, 'style.qss')
file = QFile(style_path)
# ...
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.