aboutsummaryrefslogtreecommitdiffstats
path: root/tagit/dialogues
diff options
context:
space:
mode:
authorMatthias Baumgartner <dev@igsor.net>2023-01-29 11:31:16 +0100
committerMatthias Baumgartner <dev@igsor.net>2023-01-29 11:31:16 +0100
commit4d0ce7fb62eaad3a1f705ec3c77744e3ebc96a9e (patch)
treedbaf156f663de415bbcb9298d45b45d021d23612 /tagit/dialogues
parentd531555fe3483fac7676aa634f3787e8eab9b67f (diff)
downloadtagit-4d0ce7fb62eaad3a1f705ec3c77744e3ebc96a9e.tar.gz
tagit-4d0ce7fb62eaad3a1f705ec3c77744e3ebc96a9e.tar.bz2
tagit-4d0ce7fb62eaad3a1f705ec3c77744e3ebc96a9e.zip
session actions port
Diffstat (limited to 'tagit/dialogues')
-rw-r--r--tagit/dialogues/__init__.py8
-rw-r--r--tagit/dialogues/file_picker.py39
-rw-r--r--tagit/dialogues/path_picker.kv27
-rw-r--r--tagit/dialogues/path_picker.py41
4 files changed, 111 insertions, 4 deletions
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('''
+<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 ##
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
+
+<PathPicker>:
+ 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 ##