diff options
| -rw-r--r-- | clipboard.py | 9 | ||||
| -rw-r--r-- | inkscape.py | 35 | ||||
| -rw-r--r-- | normal.py | 37 | ||||
| -rw-r--r-- | vim.py | 4 |
4 files changed, 78 insertions, 7 deletions
diff --git a/clipboard.py b/clipboard.py index b511313..1eb1e59 100644 --- a/clipboard.py +++ b/clipboard.py @@ -1,5 +1,14 @@ import subprocess +def paste(target=None): + extra_args = [] + + return subprocess.run( + ['xclip', '-sel', 'clip', '-t', 'text/plain', '-o'] + extra_args, + universal_newlines=True, + stdout=subprocess.PIPE + ).stdout + def copy(string, target=None): extra_args = [] if target != None: diff --git a/inkscape.py b/inkscape.py new file mode 100644 index 0000000..834dcd0 --- /dev/null +++ b/inkscape.py @@ -0,0 +1,35 @@ +import xml.etree.ElementTree as et +import subprocess + + +def distribute(ids, mode): + print(ids) + with open("/home/mike/neuron.d/static/currently_editing", "r") as f: + currently_editing = f.readline() + + print(currently_editing) + + selected = "" + for id in ids: + selected = selected + "select-by-id:" + id + ";" + + subprocess.run([ + 'inkscape', '--actions', + f'{selected}object-distribute:{mode};export-filename:{currently_editing};export-overwrite;export-do;', + currently_editing + ]) + # inkscape --actions="select-by-id:rect878;select-by-id:rect1814;select-by-id:rect1812;object-distribute:hgap;export-filename:/home/mike/neuron.d/static/index/another-one.svg;export-overwrite;export-do;" /home/mike/neuron.d/static/index/another-one.svg + + +def ids_from_xml(xml_string): + ids = [] + root = et.fromstring(xml_string) + for child in root: + # TODO: match for actual tag somehow + if child.tag[-2:] == "}g": + copied_objects = child + break + print(copied_objects.get("id")) + for obj in copied_objects: + ids.append(obj.get("id")) + return ids @@ -1,8 +1,9 @@ from Xlib import X, XK -from clipboard import copy +from clipboard import copy, paste from constants import TARGET from vim import open_vim +from inkscape import distribute, ids_from_xml import text import styles @@ -63,13 +64,14 @@ def normal_mode(self, event, char): events.clear() pressed.clear() +# TODO: add key for distributing and grouping maybe def handle_single_key(self, ev): if ev == 't': # Vim mode - open_vim(self, compile_latex=False) + open_vim(self, compile_latex=True) elif ev == 'Shift+t': # Vim mode prerendered - open_vim(self, compile_latex=True) + open_vim(self, compile_latex=False) elif ev == 'a': # Add objects mode self.mode = styles.object_mode @@ -91,12 +93,37 @@ def handle_single_key(self, ev): elif ev == 'f': # Bezier self.press('b') + elif ev == 'b': + # Node + self.press('n') elif ev == 'z': # Undo self.press('z', X.ControlMask) elif ev == 'Shift+z': # Delete self.press('Delete') + elif ev == 'd': + # distribute horizontally + self.press('s', X.ControlMask) + self.press('c', X.ControlMask) + clipboard = paste() + distribute(ids_from_xml(clipboard), "hgap") + self.press('r', X.ControlMask) + elif ev == 'Shift+d': + # distribute vertically + self.press('s', X.ControlMask) + self.press('c', X.ControlMask) + clipboard = paste() + distribute(ids_from_xml(clipboard), "vgap") + self.press('r', X.ControlMask) + elif ev == 'v': + self.press('t', X.ControlMask | X.Mod1Mask) + elif ev == 'Shift+v': + self.press('h', X.ControlMask | X.Mod1Mask) + elif ev == 'g': + self.press('g', X.ControlMask) + elif ev == 'Shift+g': + self.press('g', X.ControlMask | X.ShiftMask) elif ev == '`': # Disabled mode self.press('t') @@ -123,7 +150,7 @@ def paste_style(self, combination): 'stroke-opacity': 1 } - if {'s', 'a', 'd', 'g', 'h', 'x', 'e'} & combination: + if {'s', 'a', 'd', 'g', 'r', 'x', 'e'} & combination: style['stroke'] = 'black' style['stroke-width'] = w style['marker-end'] = 'none' @@ -136,7 +163,7 @@ def paste_style(self, combination): w = thick_width style['stroke-width'] = w - if 'h' in combination: + if 'r' in combination: w = very_thick_width style['stroke-width'] = w @@ -9,8 +9,8 @@ from Xlib import X def open_vim(self, compile_latex): f = tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix='.tex') - f.write('$$') - f.close() + # f.write('$$') + # f.close() config['open_editor'](f.name) |
