translate / virtaal

Easy-to-use and powerful offline translation tool
https://virtaal.translatehouse.org
GNU General Public License v2.0
300 stars 58 forks source link

`kdialog` does not work with KDE 5 (plasma) #3266

Closed demurgos closed 7 years ago

demurgos commented 7 years ago

Hi, I am using Arch Linux with KDE 5 (Plasma). I am unable to use the "open" button (both in the welcome screen and toolbar) to open a file to translate. I receive the following error related to kdialog:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.7/site-packages/virtaal/support/thread.py", line 31, in func
    q.put(target(*kwargs))
  File "/usr/lib/python2.7/site-packages/virtaal/support/native_widgets.py", line 134, in kdialog_open_dialog
    (returncode, filename) = _show_kdialog(window, title, args)
  File "/usr/lib/python2.7/site-packages/virtaal/support/native_widgets.py", line 110, in _show_kdialog
    process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "/usr/lib/python2.7/subprocess.py", line 390, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1024, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

I logged the command:

['kdialog', '--caption', u'Virtaal', '--icon', 'virtaal', '--title', u'Choose a Translation File', '--attach', '90177539', '--getopenfilename', '.', u'*.mo *.gmo *.po *.pot *.catkeys *.utf8 *.tab *.ts *.qph *.qm *.tbx *.tmx *.utx *.xlf *.xliff *.sdlxliff|All Supported Files\n*.mo *.gmo|Gettext MO file\n*.po *.pot|Gettext PO file\n*.catkeys|Haiku catkeys file\n*.utf8 *.tab|OmegaT Glossary\n*.ts|Qt Linguist Translation File\n*.qph|Qt Phrase Book\n*.qm|Qt .qm file\n*.tbx|TBX Glossary\n*.tmx|TMX Translation Memory\n*.utx|UTX Dictionary\n*.xlf *.xliff *.sdlxliff|XLIFF Translation File']

I then installed the KDialog package. The error message disappeared, but the file picker still does not open.

As a temporary workaround, I hardcoded dialog_to_use to None in native_widget.py. It fixed my problem but for the moment it's just a hack.

demurgos commented 7 years ago

While playing with kdialog, I noticed the following:

kdialog --getopenfilename . works but kdialog --caption Virtaal --getopenfilename . yields Unknown option 'caption'. instead of opening the dialog. It could be the source of this issue.

friedelwolff commented 7 years ago

Thank you for the report. Are you able to provide a proper fix with a pull request? Thanks again!

friedelwolff commented 7 years ago

It seems that we should additionally test for the presence of kdialog before assuming it is the right path to follow under KDE. The code currently assumes that kdialog is available if running under KDE.

demurgos commented 7 years ago

I'll take a look at it this week-end but please notice that this issue really reports two bugs:

demurgos commented 7 years ago

Due to the lack of manual, here is the "official" source code the argument parser of kdialog: https://cgit.kde.org/kdialog.git/tree/src/kdialog.cpp?h=fd50a04df49bac3ce3e95f3eef5e5aa38b4021e0#n286

After testing and checking the source code above, I found the reason of the error: the caption option is invalid.

demurgos commented 7 years ago

As you can see above, I submitted two pull requests to address this issue. The first one removes the invalid kdialog option, the second one adds a better test for the existence of kdialog.

@friedelwolff Could you take a look at these PRs?

ghost commented 6 years ago

Try it instead of kdialog:

https://github.com/blackPantherOS/playground/tree/master/pydialog

It is a Python3-Qt5 alternative of the kdialog

demurgos commented 6 years ago

Since PyDialog is in Python, it may be better to directly integrate it with Virtaal.

I also just wrote a cross-platform equivalent to the "open-file" feature of kdialog. For the moment there's just a programmatic Rust API, but I'll add a a CLI once it's more stable. Not sure about the other widget though. Native dialog "Open File".