From 15a2e4d070e74caa7920de52d7e15a52daf553d4 Mon Sep 17 00:00:00 2001 From: devdesk Date: Sun, 11 Jun 2023 12:20:57 +0300 Subject: [PATCH] inkscape --- .gitignore | 1 + README.md | 56 ++++++++++++++++++++++++++++++++++++++++----- inkscape/print.sh | 2 ++ inkscape/thermo.inx | 13 +++++++++++ inkscape/thermo.py | 49 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 inkscape/print.sh create mode 100644 inkscape/thermo.inx create mode 100644 inkscape/thermo.py diff --git a/.gitignore b/.gitignore index 5d381cc..5d306a8 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,4 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +labels/ \ No newline at end of file diff --git a/README.md b/README.md index fe5e4bf..7a3461e 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,56 @@ fancy name, QL-570 text formater -using gpt i got a shell script and then a python one. the python tries to detect letter width and maximise it to fit the label printer constraints (62mm width) -TDLR -`sudo brother_ql -b pyusb --model QL-570 -p usb://0x04f9:0x2028/000M12345678 print -l 62 logo.png` - -TODO: +### TODO - use as printer - - fix missing font defentions fail to take into account letter width + - works, but cant detect the length of text, will output a set (page?) length + - fix missing font defentions + - fail to take into account letter width - telegram bot (!) + +## CLI +`sudo brother_ql -b pyusb --model QL-570 -p usb://0x04f9:0x2028/000M12345678 print -l 62 logo.png` +## python +python tries to detect letter width and maximise it to fit the label printer constraints (62mm width) +`python thermatext.py "label to print"` + +## inkscape +[gptgist](https://gist.github.com/5shekel/98cc4898a1a8c7a5a1b305acc01d4326) + +inskcape user extension path +`/home/${USER}/.config/inkscape/extensions` + +symbolic link the dir fro here to the inkscape extension +`ln -s /home/${USER}/yair/thermatext/inkscape /home/${USER}/.config/inkscape/extensions/thermatext` +then check +```bash +find ~/.config/inkscape/ -type l +``` + +takes from the [inkscape-silhouette](https://github.com/fablabnbg/inkscape-silhouette) extension, as in, how to install. + +```bash +$ git clone https://github.com/fablabnbg/inkscape-silhouette +Cloning into 'inkscape-silhouette'... +remote: Enumerating objects: 2764, done. +remote: Counting objects: 100% (795/795), done. +remote: Compressing objects: 100% (364/364), done. +remote: Total 2764 (delta 483), reused 657 (delta 416), pack-reused 1969 +Receiving objects: 100% (2764/2764), 8.53 MiB | 3.64 MiB/s, done. +Resolving deltas: 100% (1786/1786), done. + +$ cd inkscape-silhouette/ + +$ make install-local + +mkdir -p locale +mkdir -p /home/devdesk/.config/inkscape/extensions +cp -r silhouette /home/devdesk/.config/inkscape/extensions +install -m 755 *silhouette*.py /home/devdesk/.config/inkscape/extensions +install -m 644 *.inx /home/devdesk/.config/inkscape/extensions +cp -r locale /home/devdesk/.config/inkscape/extensions +mkdir -p /home/devdesk/.config/inkscape/templates +install -m 644 templates/*.svg /home/devdesk/.config/inkscape/templates + +``` \ No newline at end of file diff --git a/inkscape/print.sh b/inkscape/print.sh new file mode 100644 index 0000000..84030b1 --- /dev/null +++ b/inkscape/print.sh @@ -0,0 +1,2 @@ +#!/bin/bash +sudo brother_ql -b pyusb --model QL-570 -p usb://0x04f9:0x2028/000M6Z401370 print -l 62 ~/text285.png \ No newline at end of file diff --git a/inkscape/thermo.inx b/inkscape/thermo.inx new file mode 100644 index 0000000..d298350 --- /dev/null +++ b/inkscape/thermo.inx @@ -0,0 +1,13 @@ + + + <_name>therma + org.inkscape.effect.exportandrunscript + thermatext/thermo.py + + all + + + Fx + \ No newline at end of file diff --git a/inkscape/thermo.py b/inkscape/thermo.py new file mode 100644 index 0000000..eb29b72 --- /dev/null +++ b/inkscape/thermo.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +import inkex +import os +import subprocess + +class ExportAndRunScript(inkex.EffectExtension): + + def effect(self): + # Define the export file path + png_file_path = "~/yair/exported.png" + + # Get the current selection + selection = self.svg.selected + + # If there's no selection, show an error and exit + if not selection: + inkex.dialogs.errormsg("No selection to export.") + return + + # Export the selection to PNG + self.export_selection_to_png(selection, png_file_path) + + # Run the bash script on the exported PNG + self.run_script_on_png(png_file_path) + + def export_selection_to_png(self, selection, png_file_path): + # Create a command that calls Inkscape's command line interface to export the selection to a PNG + command = ["inkscape", "--export-area-drawing", "--export-dpi=96", "--export-background-opacity=0", "-o", "{}".format(png_file_path)] + + # Add the IDs of the selected items to the command + for id, item in selection.items(): + command.append("--export-id={}".format(id)) + + # Run the command + subprocess.check_call(command) + + def run_script_on_png(self, png_file_path): + # Define the path to your bash script + bash_script_path = "print.sh" + + # Create a command that calls the bash script with the PNG as an argument + command = ["bash", bash_script_path, png_file_path] + + # Run the command + subprocess.check_call(command) + +if __name__ == "__main__": + ExportAndRunScript().run()