Score:0

Wrong MIME type and icon for a file in Nautilus

ni flag

I am writing a GUI application in Python using PyQt5, with the main application named main_app.py. Despite being simply a Python script, and file -i main_app.py returning the correct MIME type text/x-script.python, the icon shown in the Nautilus is not that of a Python script and the MIME type reported by the "Properties" tab is text/x-qml. Screenshot 1

What is more puzzling is that, checking the /etc/mime.types file, there is no entry for text/x-qml! Screenshot 2


After playing around with the file a bit, I found out that this behavior depends really on the contents of the file. My first non-comment lines are

from custom_parser import Parser
import html
import json
from PyQt5 import Qt, QtCore
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import sys

If I remove all imports of PyQt5 libraries, Nautilus reports the correct icon and MIME type.

One last important (maybe) thing: I had Qt Designer installed earlier on my PC (via sudo apt install qttools5-dev qttools5-dev-tools), but then removed it with apt in the same way. I'm running Ubuntu 22.04.2 and Python 3.10.


Therefore, my question is: how can I prevent Nautilus from changing MIME type in this fashion? I don't need support for this extra text/x-qml MIME type, so it would be fine if I could just delete it from some configuration file.

hr flag
Does `xdg-mime query default text/x-qml` return anything?
Arducode avatar
ni flag
No. On top of things, `xdg-mime query filetype main_app.py` returns `text/x-qml` when the PyQt5 libraries are imported in the file, `text/x-python3` when not
Score:0
ni flag

Thanks to @steeldriver 's comment and this other answer I was able to find a solution. Evidently Qt Designer had not uninstalled itself correctly and left specifications for its text/x-qml MIME type in the file /usr/share/mime/packages/freedesktop.org.xml:

<mime-type type="text/x-qml">
  <comment>Qt Markup Language file</comment>
  ...
  <magic priority="80">
    <match type="string" value="/bin/env qml" offset="2:16"/>
    <match type="string" value="import Qt" offset="0:3000">
      <match type="string" value="{" offset="9:3009"/>
    </match>
    <match type="string" value="import Qml" offset="0:3000">
      <match type="string" value="{" offset="9:3009"/>
    </match>
  </magic>
  <glob pattern="*.qml"/>
  <glob pattern="*.qmltypes"/>
  <glob pattern="*.qmlproject"/>
</mime-type>

(notice the <match type="string" value="import Qt" offset="0:3000"> line, which was probably the one identifying my script as text/x-qml since it matched with line 4 of my import statements). I simply deleted that entry from the file, recompiled the MIME database using sudo update-mime-database -V /usr/share/ and everything went back to normality.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.