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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
"""
Part of the tagit module.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2022
"""
# standard imports
import code
import logging
import os
import sys
# external imports
import webbrowser
# kivy imports
from kivy.core.clipboard import Clipboard
from kivy.lang import Builder
import kivy.properties as kp
# tagit imports
from tagit import config
from tagit.utils import fileopen
from tagit.widgets import Binding
# inner-module imports
from .action import Action
# constants
HELP_URL = 'https://www.bsfs.io/'
# 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 pprint import pprint as pp
loc = globals()
loc.update(locals())
code.interact(banner='tagit shell', local=loc)
if loc.get('abort', False):
sys.exit(1)
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):
return # FIXME: mb/port
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):
return # FIXME: mb/port
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):
return # FIXME: mb/port
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 ##
|