aboutsummaryrefslogtreecommitdiffstats
path: root/tagit/dialogues/file_picker.py
blob: 283adb6822d9593d8ef376f0ca5bf07f6866adbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Dialogue to pick a file.

Part of the tagit module.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2022
"""
# standard imports
import os

# kivy imports
from kivy.lang import Builder

# inner-module imports
from .path_picker import PathPicker
from .error import Error

# exports
__all__ = ('FilePicker', )


## code ##

# load kv
Builder.load_string('''
<FilePicker>:
    dirselect: False
    title: 'Please select a file'
''')

# classes
class FilePicker(PathPicker):
    """Dialogue with a file browser to select a file."""
    def ok(self):
        if not os.path.exists(self.path) or not os.path.isfile(self.path):
            Error(text='Please select a file').open()
        else:
            super(FilePicker, self).ok()

## EOF ##