question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filechooser on mac: using path, crashes python

See original GitHub issue

MacOS 10.14.6

using the path parameter causes python to crash (not just the app). Using the use_extensions with path causes an uncaught exception.

Test case:

from pathlib import Path

from kivy.app import App
from kivy.lang.builder import Builder
from plyer import filechooser

kv = '''
BoxLayout:
    orientation: 'vertical'
    Button:
        text: 'Test: Open, filters=["*.pdf"]; this will crash python'
        on_release: app.ft.open(filters=['*.pdf'])
    Button:
        text: 'Test: Open, filters=["*.pdf"] use_extensions=True; throws exception '
        on_release: app.ft.open(filters=['*.pdf'], use_extensions=True)
    Button:
        text: 'Test: Open, filters=[] this will work as expected'
        on_release: app.ft.open()
    Label:
        text: 'plyer.filechooser.open_file() with a filter will crash on mac'
'''


class FileTest:
    def __init__(self):
        self.file_name = ''

    def open(self, **kwargs):
        filechooser.open_file(title='Open Patch File',
                              on_selection=self._open_selection, **kwargs)

    def _open_selection(self, selection):
        try:
            self.file_name = Path(selection[0]).name
        except (ValueError, IndexError):  # The user did not select a file
            print('open canceled')
        else:
            print(f'open file: {self.file_name}')


class PlyerFilechooserTestApp(App):
    ft = FileTest()

    def build(self):
        return Builder.load_string(kv)


if __name__ == '__main__':
    PlyerFilechooserTestApp().run()



Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Mulugruntzcommented, Jun 30, 2020

Found the issue! I’ll do a PR.

0reactions
Mulugruntzcommented, Jun 30, 2020

The thing was that objc_arr was expecting positional arguments. https://github.com/kivy/pyobjus/blob/3f6314152ea850bff8a218fb3dbc4df22431a4f2/pyobjus/pyobjus_types.pxi#L371

And the list was given as an argument. In Objective-C, there’s this thing where when you initialize with a list, the last element must have nil. And objc_arr is adding a None at the end of the positional arguments.

So, instead of having ('jpg', 'JPG', None), it had (['jpg', 'JPG'], None). The setAllowedFileTypes() method was expecting to work on strings and received a list. Crash.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Choosing a file in Python with simple Dialog - Stack Overflow
Currently I can only ask for full path as an input in the console. Is there a way to trigger a simple user...
Read more >
Consistent crashes from basic file… | Apple Developer Forums
I have been working on an app as a project for a forensics class for the past few weeks. The main idea, developmentally...
Read more >
IDEA UI freezes when browsing in the File Chooser dialog
When I use open project, file choose the netty source folder. The idea freeze . I had to kill the idea process. OS:...
Read more >
Python KivyMD - Access file system of any OS - YouTube
In order to access the file system of a OS, you will have to make use of the FileChooser package within Kivy UIX....
Read more >
Changelog — Kivy 2.1.0 documentation
[#6624]: Filechooser: Use full path. [#6650]: DropDown/ModalView: Make modal and dropdown consistent. [#6666]: TextInput: Fix for crashes caused by text ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found