Filechooser on mac: using path, crashes python
See original GitHub issueMacOS 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:
- Created 4 years ago
- Comments:8 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Found the issue! I’ll do a PR.
The thing was that
objc_arr
was expecting positional arguments. https://github.com/kivy/pyobjus/blob/3f6314152ea850bff8a218fb3dbc4df22431a4f2/pyobjus/pyobjus_types.pxi#L371And 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
. Andobjc_arr
is adding aNone
at the end of the positional arguments.So, instead of having
('jpg', 'JPG', None)
, it had(['jpg', 'JPG'], None)
. ThesetAllowedFileTypes()
method was expecting to work on strings and received a list. Crash.