diff options
author | Matthias Baumgartner <dev@igsor.net> | 2023-01-06 22:55:36 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2023-01-06 22:55:36 +0100 |
commit | 1a8d8f8a37e78f48da88dd69e785234d822425ed (patch) | |
tree | 8c1003075aec91026908c191cba0fe366539740b /tagit | |
parent | ceaaef069d8ffda23fce320ce66c86e0226f1046 (diff) | |
download | tagit-1a8d8f8a37e78f48da88dd69e785234d822425ed.tar.gz tagit-1a8d8f8a37e78f48da88dd69e785234d822425ed.tar.bz2 tagit-1a8d8f8a37e78f48da88dd69e785234d822425ed.zip |
load from config, switch to browsing
Diffstat (limited to 'tagit')
-rw-r--r-- | tagit/actions/__init__.py | 16 | ||||
-rw-r--r-- | tagit/actions/misc.kv | 35 | ||||
-rw-r--r-- | tagit/actions/misc.py | 167 | ||||
-rw-r--r-- | tagit/actions/planes.kv | 15 | ||||
-rw-r--r-- | tagit/actions/planes.py | 57 | ||||
-rw-r--r-- | tagit/config/loader.py | 4 | ||||
-rw-r--r-- | tagit/config/port-config.yaml | 114 | ||||
-rw-r--r-- | tagit/config/settings.py | 12 | ||||
-rw-r--r-- | tagit/config/user-defaults.yaml | 112 |
9 files changed, 519 insertions, 13 deletions
diff --git a/tagit/actions/__init__.py b/tagit/actions/__init__.py index 444bd73..9fd6342 100644 --- a/tagit/actions/__init__.py +++ b/tagit/actions/__init__.py @@ -15,9 +15,9 @@ from tagit.utils.builder import BuilderBase from . import filter from . import grouping #from . import library -#from . import misc +from . import misc #from . import objects -#from . import planes +from . import planes from . import search #from . import session #from . import tabs @@ -88,9 +88,9 @@ class ActionBuilder(BuilderBase): #'ShellDrop': misc.ShellDrop, #'OpenExternal': misc.OpenExternal, #'Menu': misc.Menu, - #'ShowConsole': misc.ShowConsole, - #'ShowHelp': misc.ShowHelp, - #'ShowSettings': misc.ShowSettings, + 'ShowConsole': misc.ShowConsole, + 'ShowHelp': misc.ShowHelp, + 'ShowSettings': misc.ShowSettings, #'ClipboardCopy': misc.ClipboardCopy, #'ClipboardPaste': misc.ClipboardPaste, ## objects @@ -105,9 +105,9 @@ class ActionBuilder(BuilderBase): #'SetRank4': objects.SetRank4, #'SetRank5': objects.SetRank5, ## planes - #'ShowDashboard': planes.ShowDashboard, - #'ShowBrowsing': planes.ShowBrowsing, - #'ShowCodash': planes.ShowCodash, + 'ShowDashboard': planes.ShowDashboard, + 'ShowBrowsing': planes.ShowBrowsing, + 'ShowCodash': planes.ShowCodash, ## search #'Search': search.Search, #'ShowSelected': search.ShowSelected, diff --git a/tagit/actions/misc.kv b/tagit/actions/misc.kv new file mode 100644 index 0000000..f9d5157 --- /dev/null +++ b/tagit/actions/misc.kv @@ -0,0 +1,35 @@ +#:import resource_find kivy.resources.resource_find + +<Menu>: + source: resource_find('atlas://misc/menu') + tooltip: 'Open the menu' + +<ShellDrop>: + source: resource_find('atlas://misc/shell') + tooltip: 'Open a terminal shell' + +<OpenExternal>: + source: resource_find('atlas://misc/open_external') + tooltip: 'Open selected items in an external application' + +<ShowConsole>: + source: resource_find('atlas://misc/console') + tooltip: 'Open the log console' + +<ShowHelp>: + source: resource_find('atlas://misc/help') + tooltip: 'Open the help' + +<ShowSettings>: + source: resource_find('atlas://misc/settings') + tooltip: 'Open the settings menu' + +<ClipboardCopy>: + source: resource_find('atlas://misc/clip_copy') + tooltip: 'Copy selected items to the clipboard' + +<ClipboardPaste>: + source: resource_find('atlas://misc/clip_paste') + tooltip: 'Import files from the clipboard' + +## EOF ## diff --git a/tagit/actions/misc.py b/tagit/actions/misc.py new file mode 100644 index 0000000..dc939ca --- /dev/null +++ b/tagit/actions/misc.py @@ -0,0 +1,167 @@ +""" + +Part of the tagit module. +A copy of the license is provided with the project. +Author: Matthias Baumgartner, 2022 +""" +# standard imports +import logging +import os + +# kivy imports +from kivy.core.clipboard import Clipboard +from kivy.lang import Builder +import kivy.properties as kp +import webbrowser + +# tagit imports +from tagit import config +#from tagit.io_.sync import export # FIXME: mb/port +#from tagit.utils import fileopen # FIXME: mb/port +from tagit.widgets import Binding + +# inner-module imports +from .action import Action + +# constants +HELP_URL = 'https://www.igsor.net/projects/tagit/' + +# exports +__all__ = [] + + +## code ## + +logger = logging.getLogger(__name__) + +# load kv +Builder.load_file(os.path.join(os.path.dirname(__file__), 'misc.kv')) + +# classes +class Menu(Action): + """Open the menu.""" + text = kp.StringProperty('Menu') + + def ktrigger(self, evt): + return Binding.check(evt, self.cfg('bindings', 'misc', 'menu')) + + def apply(self): + x = self.pos[0] + self.width + y = self.pos[1] + self.height + self.root.context.show(x, y) + + +class ShellDrop(Action): + """Open a terminal shell.""" + text = kp.StringProperty('Shell') + + def apply(self): + from tagit import debug + debug(locals(), globals()) + + +class OpenExternal(Action): + """Open the selected items in an external application.""" + text = kp.StringProperty('Open') + + def ktrigger(self, evt): + # FIXME: Triggered on Shift + Click (Interferes with selection!) + # Triggered on <Enter> when tags are edited. + return Binding.check(evt, self.cfg('bindings', 'misc', 'open')) + + def apply(self): + with self.root.browser as browser: + if browser.cursor is None: + logger.error('No file selected') + elif os.path.exists(browser.cursor.path): + fileopen(browser.cursor.path) + else: + logger.error('File unavailable') + + +class ShowConsole(Action): + """Open the log console.""" + text = kp.StringProperty('Console') + + def apply(self): + self.root.status.console() + + +class ShowHelp(Action): + """Show some help.""" + text = kp.StringProperty('Help') + + def ktrigger(self, evt): + return Binding.check(evt, self.cfg('bindings', 'misc', 'help')) + + def apply(self): + webbrowser.open(HELP_URL) + + +class ShowSettings(Action): + """Open the settings menu.""" + text = kp.StringProperty('Settings') + + def ktrigger(self, evt): + return Binding.check(evt, self.cfg('bindings', 'misc', 'settings')) + + def apply(self): + from kivy.app import App + App.get_running_app().open_settings() + + +class ClipboardCopy(Action): + """Copy selected items into the clipboard.""" + text = kp.StringProperty('Copy to clipboard') + + def ktrigger(self, evt): + return Binding.check(evt, self.cfg('bindings', 'clipboard', 'copy')) + + def apply(self): + browser = self.root.browser + paths = [obj.path for obj in browser.selection] + Clipboard.copy('\n'.join(paths)) + + +class ClipboardPaste(Action): + """Import items from the clipboard.""" + text = kp.StringProperty('Paste from clipboard') + + def ktrigger(self, evt): + return Binding.check(evt, self.cfg('bindings', 'clipboard', 'paste')) + + def apply(self): + paths = Clipboard.paste() + paths = paths.split('\n') + self.root.trigger('ImportObjects', paths) + + +## config ## + +# keybindings + +config.declare(('bindings', 'misc', 'menu'), + config.Keybind(), Binding.simple(Binding.CMD, None, Binding.mALL), + __name__, Menu.text.defaultvalue, Menu.__doc__) + +config.declare(('bindings', 'misc', 'open'), + config.Keybind(), Binding.simple(Binding.ENTER, None, Binding.mALL), + __name__, OpenExternal.text.defaultvalue, OpenExternal.__doc__) + +config.declare(('bindings', 'misc', 'help'), + config.Keybind(), Binding.simple('/', Binding.mSHIFT), + __name__, ShowHelp.text.defaultvalue, ShowHelp.__doc__) + +config.declare(('bindings', 'misc', 'settings'), + config.Keybind(), Binding.simple(Binding.F1), # also the kivy default + __name__, ShowSettings.text.defaultvalue, ShowSettings.__doc__) + +config.declare(('bindings', 'clipboard', 'copy'), + config.Keybind(), Binding.simple('c', Binding.mCTRL), + __name__, ClipboardCopy.text.defaultvalue, ClipboardCopy.__doc__) + +config.declare(('bindings', 'clipboard', 'paste'), + config.Keybind(), Binding.simple('v', Binding.mCTRL), + __name__, ClipboardPaste.text.defaultvalue, ClipboardPaste.__doc__) + +## EOF ## diff --git a/tagit/actions/planes.kv b/tagit/actions/planes.kv new file mode 100644 index 0000000..184f949 --- /dev/null +++ b/tagit/actions/planes.kv @@ -0,0 +1,15 @@ +#:import resource_find kivy.resources.resource_find + +<ShowDashboard>: + source: resource_find('atlas://planes/dashboard') + tooltip: 'Switch to the Dashboard' + +<ShowBrowsing>: + source: resource_find('atlas://planes/browsing') + tooltip: 'Switch to the browsing plane' + +<ShowCodash>: + source: resource_find('atlas://planes/codash') + tooltip: 'Switch to the contextual dashboard' + +## EOF ## diff --git a/tagit/actions/planes.py b/tagit/actions/planes.py new file mode 100644 index 0000000..89f93bb --- /dev/null +++ b/tagit/actions/planes.py @@ -0,0 +1,57 @@ +""" + +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 .action import Action + +# exports +__all__ = [] + + +## code ## + +# load kv +Builder.load_file(os.path.join(os.path.dirname(__file__), 'planes.kv')) + +# classes + +class ShowDashboard(Action): + """Switch to the dashboard.""" + text = kp.StringProperty('Dashboard') + + def apply(self): + planes = self.root.planes + if planes.current_slide != planes.dashboard: + planes.load_slide(planes.dashboard) + + +class ShowBrowsing(Action): + """Switch to the browsing plane.""" + text = kp.StringProperty('Browsing') + + def apply(self): + planes = self.root.planes + if planes.current_slide != planes.browsing: + planes.load_slide(planes.browsing) + + +class ShowCodash(Action): + """Switch to the contextual dashboard.""" + text = kp.StringProperty('Context') + + def apply(self): + planes = self.root.planes + if planes.current_slide != planes.codash: + planes.load_slide(planes.codash) + +## EOF ## diff --git a/tagit/config/loader.py b/tagit/config/loader.py index 489b063..87ac328 100644 --- a/tagit/config/loader.py +++ b/tagit/config/loader.py @@ -17,7 +17,7 @@ from .settings import Settings TAGITRC = '.tagitrc' -DEFAULT_USER_CONFIG = os.path.join(os.path.dirname(__file__), 'user-defaults.json') +DEFAULT_USER_CONFIG = os.path.join(os.path.dirname(__file__), 'user-defaults.yaml') SETTINGS_PATH = [ # user home @@ -26,7 +26,7 @@ SETTINGS_PATH = [ '/usr/share/tagit/settings', '/usr/share/tagit/keybindings', # module defaults - os.path.join(os.path.dirname(__file__), 'settings.json'), + os.path.join(os.path.dirname(__file__), 'settings.yaml'), ] # exports diff --git a/tagit/config/port-config.yaml b/tagit/config/port-config.yaml new file mode 100644 index 0000000..038dc07 --- /dev/null +++ b/tagit/config/port-config.yaml @@ -0,0 +1,114 @@ +session: + first_start: false + paths: + searchlog: ~/.tagit.log +storage: + index: + preview_size: + - 50 + - 200 + - 400 +ui: + standalone: + plane: browsing + browser: + maxcols: 8 + maxrows: 8 + buttondocks: + sidebar_left: [] + #- Menu + #- ShowDashboard + #- AddTag + #- EditTag + #- CreateGroup + #- DissolveGroup + #- SelectAll + #- SelectNone + #- SelectInvert + #- SelectAdditive + #- SelectSubtractive + #- SelectSingle + #- SelectMulti + #- SelectRange + context: + app: + - ShowSettings + - ShowHelp + - ShowConsole + - ShowBrowsing + # browser: + # - ZoomIn + # - ZoomOut + # clipboard: + # - ClipboardCopy + # - ClipboardPaste + # grouping: + # - CreateGroup + # - DissolveGroup + # - AddToGroup + # - RepresentGroup + # - RemoveFromGroup + # root: + # - CloseSessionAndExit + # search: + # - ShowSelected + # - RemoveSelected + # select: + # - SelectAll + # - SelectNone + # - SelectInvert + # - SelectSingle + # - SelectMulti + # - SelectRange + # - SelectAdditive + # - SelectSubtractive + # session: + # - SaveSession + # - SaveSessionAs + # - ItemExport + # - ImportObjects + # tagging: + # - AddTag + # - EditTag + # - SetRank1 + # - SetRank3 + # - SetRank5 + search: + sort_blacklist: + - entity + - flash + - latitude + - longitude + - mime + - author + - camera + - attributes + tabs: + max: 2 + tiledocks: + dashboard: {} + #Buttons: + # buttons: + # - ShowBrowsing + # - CreateSession + # - CreateTempSession + # - LoadSession + # - ReloadSession + # - ImportObjects + # - SaveSession + # - SaveSessionAs + # - ItemExport + # - UpdateSelectedObjects + # - SyncSelectedObjects + # - ShowHelp + # - ShowSettings + #Hints: {} + #LibSummary: {} + #Searchtree: {} + #TagHistogram: {} + #Tagcloud: {} + sidebar_right: {} + #CursorTags: {} + #Info: {} + #Venn: {} + window_size: 1024x768 diff --git a/tagit/config/settings.py b/tagit/config/settings.py index 21ab594..190268c 100644 --- a/tagit/config/settings.py +++ b/tagit/config/settings.py @@ -12,6 +12,9 @@ import json import os import typing +# external imports +import yaml # FIXME: mb/port/convenicence + # tagit imports from tagit.utils import errors, fst, is_list @@ -60,11 +63,14 @@ class Settings(abc.MutableMapping, abc.Hashable, abc.Callable): if os.path.exists(source): config_path = os.path.realpath(source) with open(source, 'r') as ifile: - config = json.load(ifile) + #config = json.load(ifile) + config = yaml.safe_load(ifile) # FIXME: mb/port/convenicence else: - config = json.loads(source) + #config = json.loads(source) + config = yaml.safe_load(source) # FIXME: mb/port/convenicence elif isinstance(source, io.TextIOBase): # opened file - config = json.load(source) + #config = json.load(source) + config = yaml.safe_load(source) # FIXME: mb/port/convenicence else: raise TypeError('expected dict, path, or file-like') diff --git a/tagit/config/user-defaults.yaml b/tagit/config/user-defaults.yaml new file mode 100644 index 0000000..b7a70c4 --- /dev/null +++ b/tagit/config/user-defaults.yaml @@ -0,0 +1,112 @@ +session: + first_start: false + paths: + searchlog: ~/.tagit.log +storage: + index: + preview_size: + - 50 + - 200 + - 400 +ui: + standalone: + browser: + maxcols: 8 + maxrows: 8 + buttondocks: + sidebar_left: + - Menu + - ShowDashboard + - AddTag + - EditTag + - CreateGroup + - DissolveGroup + - SelectAll + - SelectNone + - SelectInvert + - SelectAdditive + - SelectSubtractive + - SelectSingle + - SelectMulti + - SelectRange + context: + app: + - ShowSettings + - ShowHelp + - ShowConsole + browser: + - ZoomIn + - ZoomOut + clipboard: + - ClipboardCopy + - ClipboardPaste + grouping: + - CreateGroup + - DissolveGroup + - AddToGroup + - RepresentGroup + - RemoveFromGroup + root: + - CloseSessionAndExit + search: + - ShowSelected + - RemoveSelected + select: + - SelectAll + - SelectNone + - SelectInvert + - SelectSingle + - SelectMulti + - SelectRange + - SelectAdditive + - SelectSubtractive + session: + - SaveSession + - SaveSessionAs + - ItemExport + - ImportObjects + tagging: + - AddTag + - EditTag + - SetRank1 + - SetRank3 + - SetRank5 + search: + sort_blacklist: + - entity + - flash + - latitude + - longitude + - mime + - author + - camera + - attributes + tabs: + max: 2 + tiledocks: + dashboard: + Buttons: + buttons: + - ShowBrowsing + - CreateSession + - CreateTempSession + - LoadSession + - ReloadSession + - ImportObjects + - SaveSession + - SaveSessionAs + - ItemExport + - UpdateSelectedObjects + - SyncSelectedObjects + - ShowHelp + - ShowSettings + Hints: {} + LibSummary: {} + Searchtree: {} + TagHistogram: {} + Tagcloud: {} + sidebar_right: + CursorTags: {} + Info: {} + Venn: {} + window_size: 1024x768 |