This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Wrong file association

Tags: None
(comma "," separated)
dumdidum
Registered Member
Posts
3
Karma
0

Wrong file association

Thu Nov 05, 2020 9:37 am
Hi,
I want to open simple .py files with a simple text editor like gedit. However, every time I try to open it, it launches Okular, because it thinks it is a PDF Document. As you can see in the screenshot, the filename pattern .py corresponds to python text files and and .pdf pattern is set for PDF-files. But in the file explorer it still says download.py is a PDF Document. Why does this happen? And how can I permanently fix that (so that I dont have to ask again in the future, if this happens more often)?
Code: Select all
~/.local/share/applications/mimeapps.list
is an empty file on my system.

Screenshot: https://ibb.co/12MxTnb
Best regards
User avatar
Mamarok
Manager
Posts
6071
Karma
16
OS

Re: Wrong file association

Thu Nov 05, 2020 11:58 am
In System Settings -> Personalization -> Applications -> File Associations, remove Okular from the Application Preference Order for the x-python and x-python3 file types, it shouldn't be in there anyway, there should only be text editors.

Also make sure the header of your script is formatted correctly, ideally all Python scripts should start with this:
Code: Select all
#!/usr/bin/env python


Running Kubuntu 22.10 with Plasma 5.26.3, Frameworks 5.100.0, Qt 5.15.6, kernel 5.19.0-23 on Ryzen 5 4600H, AMD Renoir, X11
FWIW: it's always useful to state the exact Plasma version (+ distribution) when asking questions, makes it easier to help ...
dumdidum
Registered Member
Posts
3
Karma
0

Re: Wrong file association

Fri Nov 06, 2020 12:07 pm
Hi Mamarok,
thanks for the answer.
The problem is, that Okular isn't even set as Application for python files. The only applications that are set are "Text Editor" and "VS Code" (as seen in the bottom left window of the screenshot; the file association for x-python3 is the same). That's why I am supprised as well :(
The header of the script is the following (set to my installation path of python):
Code: Select all
#!/usr/bin/python


BTW: I am using the newest Manjaro distribution with KDE and the Kernel 5.8.18-1-MANJARO and the DE Plasma 5.20.2 (if this is of interest).
User avatar
Mamarok
Manager
Posts
6071
Karma
16
OS

Re: Wrong file association

Sat Nov 07, 2020 2:38 pm
That is weird, I tried creating a test script, it is correctly shown as being a python script in the properties. Is this over all or is it just this one script?


Running Kubuntu 22.10 with Plasma 5.26.3, Frameworks 5.100.0, Qt 5.15.6, kernel 5.19.0-23 on Ryzen 5 4600H, AMD Renoir, X11
FWIW: it's always useful to state the exact Plasma version (+ distribution) when asking questions, makes it easier to help ...
dumdidum
Registered Member
Posts
3
Karma
0

Re: Wrong file association

Sat Nov 07, 2020 4:11 pm
So after some debugging I found out that in the script one line was
Code: Select all
pdf_hdr = b'%PDF-1.5'

After trying to isolate the error, I found out that if in any file the string %PDF-1.5 exists, it tries to open the file with Okular, no matter the file extension. If I remove this, it opens the file with the plain text editor, as expected. I suspect this to be a bug of some kind, isn't it? I understand, that if a file starts with this string, it probably is a pdf file, but 1. I would assume/hope, that KDE only uses the file extensions to figure out how to open it (that way it is way more intuitive) and 2. it doesn't even start with the string. The string is somewhere in the file.

Some more (maybe interesting) information:
If I call "file download.py", it says download.py: Python script, ASCII text executable, while when I do that for a test script, which is also opened with Okular, it says test.py: PDF document, version 1.5, ASCII text
(test script:
Code: Select all
#!/usr/bin/python3
a = b'%PDF-1.5'
)

Maybe you can try it on your machine as well, to see if it is reproducible on other systems.
User avatar
Mamarok
Manager
Posts
6071
Karma
16
OS

Re: Wrong file association

Sun Nov 08, 2020 12:52 am
I just tried and it is indeed reproducible here as well. You should report this as a bug against Dolphin


Running Kubuntu 22.10 with Plasma 5.26.3, Frameworks 5.100.0, Qt 5.15.6, kernel 5.19.0-23 on Ryzen 5 4600H, AMD Renoir, X11
FWIW: it's always useful to state the exact Plasma version (+ distribution) when asking questions, makes it easier to help ...


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], daret, Evergrowing, Google [Bot], lockheed, mesutakcan, sandyvee, Sogou [Bot]