From 4d0ce7fb62eaad3a1f705ec3c77744e3ebc96a9e Mon Sep 17 00:00:00 2001 From: Matthias Baumgartner Date: Sun, 29 Jan 2023 11:31:16 +0100 Subject: session actions port --- tagit/dialogues/__init__.py | 8 ++++---- tagit/dialogues/file_picker.py | 39 +++++++++++++++++++++++++++++++++++++++ tagit/dialogues/path_picker.kv | 27 +++++++++++++++++++++++++++ tagit/dialogues/path_picker.py | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 tagit/dialogues/file_picker.py create mode 100644 tagit/dialogues/path_picker.kv create mode 100644 tagit/dialogues/path_picker.py (limited to 'tagit/dialogues') diff --git a/tagit/dialogues/__init__.py b/tagit/dialogues/__init__.py index a467699..3647bf0 100644 --- a/tagit/dialogues/__init__.py +++ b/tagit/dialogues/__init__.py @@ -23,11 +23,11 @@ from .console import Console #from .dir_picker import DirPicker from .error import Error #from .file_creator import FileCreator -#from .file_picker import FilePicker +from .file_picker import FilePicker from .message import Message from .numeric_input import NumericInput #from .path_creator import PathCreator -#from .path_picker import PathPicker +from .path_picker import PathPicker #from .project import Project from .simple_input import SimpleInput from .stoken import TokenEdit @@ -40,11 +40,11 @@ __all__: typing.Sequence[str] = ( #'DirPicker', 'Error', #'FileCreator', - #'FilePicker', + 'FilePicker', 'Message', 'NumericInput', #'PathCreator', - #'PathPicker', + 'PathPicker', #'Project', 'SimpleInput', 'TokenEdit', diff --git a/tagit/dialogues/file_picker.py b/tagit/dialogues/file_picker.py new file mode 100644 index 0000000..283adb6 --- /dev/null +++ b/tagit/dialogues/file_picker.py @@ -0,0 +1,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(''' +: + 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 ## diff --git a/tagit/dialogues/path_picker.kv b/tagit/dialogues/path_picker.kv new file mode 100644 index 0000000..1837b80 --- /dev/null +++ b/tagit/dialogues/path_picker.kv @@ -0,0 +1,27 @@ +#:import join os.path.join +#:import pwd os.path.curdir + +: + path: '' + title: 'Please select a file or directory' + filters: [] + dirselect: True + + DialogueContentTitle: + title: root.title + size_hint_y: 0.8 + + FileChooserListView: + text_size: self.width - dp(16), None + halign: 'center' + dirselect: root.dirselect + path: pwd + filters: root.filters + + on_selection: root.path = join(self.path, self.selection[0]); buttons.ok_enabled = True + + DialogueButtons_Two: + id: buttons + ok_enabled: False + +## EOF ## diff --git a/tagit/dialogues/path_picker.py b/tagit/dialogues/path_picker.py new file mode 100644 index 0000000..25bbf32 --- /dev/null +++ b/tagit/dialogues/path_picker.py @@ -0,0 +1,41 @@ +"""Dialogue to pick a file or directory. + +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 +import kivy.properties as kp + +# inner-module imports +from .dialogue import Dialogue +from .error import Error + +# exports +__all__ = ('PathPicker', ) + + +## code ## + +# load kv +Builder.load_file(os.path.join(os.path.dirname(__file__), 'path_picker.kv')) + +# classes +class PathPicker(Dialogue): + """Dialogue with a file browser to select a file or directory.""" + + title = kp.StringProperty('') + path = kp.StringProperty('') + filters = kp.ListProperty() + + def ok(self): + if not os.path.exists(self.path): + Error(text='Please select a file or directory').open() + else: + super(PathPicker, self).ok() + +## EOF ## -- cgit v1.2.3