1

I created a file mymime.xml

<?xml version='1.0' encoding='utf-8'?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
    <mime-type type="text/myapp">
        <comment>my format</comment>
        <glob pattern="*.myformat"/>
    </mime-type>
</mime-info>

and a file myapp.desktop

[Desktop Entry]
Name=MyApp
GenericName=My Generic Name 
Comment=a comment
Exec=myapp
Icon=myicon
Terminal=false
Type=Application
Categories=Development;
MimeType=text/myapp;
Name[en_US]=MyApp

Now when I right click on a file that has myformat ending, it suggests opening with MyApp, which is the behavior I was looking! But on the python3 code (I am using PyQt5), how do I take the loading argument when there is a file loaded like this? (right click open or double click on a file.myformat)

closed as off-topic by muru, andrew.46, Pilot6, qbi, David Foerster Jun 16 '16 at 8:49

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – muru, andrew.46, Pilot6, qbi, David Foerster
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Wtf is happening with this site? Second question I asked placed on hold with little effort from a great number of people who are not interested in the least to help or offer some explanation. I have no idea how things work in any other distro or operating system, I have no idea how to set file types or whatever, this is made from observation of Ubuntu from having used it a long time. If you have a smart-ass comment, please do and help me to understand to which extent informing mime-type works. I just feel it won't work the same on Windows. – eri0o Jun 16 '16 at 9:18
  • We closed this because it wasn't about Ubuntu enough - it was a programming language. – Tim Jun 17 '16 at 22:54
  • @Tim you know you kind of have the power to move questions instead of closing. I don't have this power. – eri0o Jun 17 '16 at 23:03
  • No I don't. Only moderators can migrate to other sites on the network. – Tim Jun 17 '16 at 23:04
  • @Tim I also can't delete my question. – eri0o Jun 17 '16 at 23:23
1

Ok, I solved this with the following code:

class MainWindow(QMainWindow):
    def __init__(self, filelist, **kwargs):

        openFileAtStart(filelist)

    def openFileAtStart(self, filelist):
        matching = [s for s in filelist if ".myformat" in s]
        if len(matching) > 0:
            self.openFileByName(matching)

if __name__ == "__main__":
    from sys import argv, exit
    from PyQt5.QtWidgets import QApplication
    a = QApplication(argv)
    MainWindow(argv)

Basically, at opening, QApplication needs to read the argv arguments, and removes anything related to Qt. Than I pass the remaining arguments to my application ("MainWindow"), which will handle the list checking for items that match my format and will throw this list to my function that handles opening files.

Not the answer you're looking for? Browse other questions tagged or ask your own question.