2023-06-11 12:20:57 +03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import inkex
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
class ExportAndRunScript(inkex.EffectExtension):
|
|
|
|
|
|
|
|
def effect(self):
|
|
|
|
# Define the export file path
|
2023-06-11 13:41:02 +03:00
|
|
|
png_file_path = "/home/devdesk/yair/thermatext/labels/exported.png"
|
2023-06-11 17:06:47 +03:00
|
|
|
|
2023-06-11 12:20:57 +03:00
|
|
|
# Get the current selection
|
|
|
|
selection = self.svg.selected
|
|
|
|
|
|
|
|
# If there's no selection, show an error and exit
|
|
|
|
if not selection:
|
2023-06-11 13:41:02 +03:00
|
|
|
inkex.errormsg("No selection to export.")
|
2023-06-11 12:20:57 +03:00
|
|
|
return
|
2023-06-11 16:23:54 +03:00
|
|
|
|
|
|
|
# Get the IDs of the selected elements
|
|
|
|
selected_ids = ",".join(element.get('id') for element in selection.values())
|
|
|
|
|
2023-06-11 17:06:47 +03:00
|
|
|
# Convert objects to paths
|
|
|
|
self.convert_to_path(selected_ids)
|
|
|
|
|
2023-06-11 16:23:54 +03:00
|
|
|
# Run the Inkscape CLI command to export the selection to a PNG
|
|
|
|
self.run_export_command(selected_ids, png_file_path)
|
|
|
|
|
2023-06-11 12:20:57 +03:00
|
|
|
# Run the bash script on the exported PNG
|
|
|
|
self.run_script_on_png(png_file_path)
|
2023-06-11 17:06:47 +03:00
|
|
|
|
|
|
|
def convert_to_path(self, selected_ids):
|
|
|
|
# Create a command that calls Inkscape's command line interface to convert objects to paths
|
|
|
|
command = [
|
|
|
|
"inkscape",
|
|
|
|
"--select={}".format(selected_ids),
|
|
|
|
"--verb=ObjectToPath",
|
|
|
|
self.options.input_file
|
|
|
|
]
|
|
|
|
|
|
|
|
# Run the command
|
|
|
|
subprocess.check_call(command)
|
|
|
|
|
2023-06-11 16:23:54 +03:00
|
|
|
def run_export_command(self, selected_ids, png_file_path):
|
2023-06-11 12:20:57 +03:00
|
|
|
# Create a command that calls Inkscape's command line interface to export the selection to a PNG
|
2023-06-11 16:23:54 +03:00
|
|
|
command = [
|
|
|
|
"inkscape",
|
|
|
|
"--export-type=png",
|
|
|
|
"--export-id={}".format(selected_ids),
|
|
|
|
"--export-filename={}".format(png_file_path),
|
|
|
|
self.options.input_file
|
|
|
|
]
|
2023-06-11 17:06:47 +03:00
|
|
|
|
2023-06-11 12:20:57 +03:00
|
|
|
# Run the command
|
|
|
|
subprocess.check_call(command)
|
|
|
|
|
|
|
|
def run_script_on_png(self, png_file_path):
|
|
|
|
# Define the path to your bash script
|
2023-06-11 16:23:54 +03:00
|
|
|
# bash_script_path = "print.sh"
|
2023-06-11 17:06:47 +03:00
|
|
|
|
2023-06-11 12:20:57 +03:00
|
|
|
# Create a command that calls the bash script with the PNG as an argument
|
2023-06-11 13:41:02 +03:00
|
|
|
command = ["sudo", "brother_ql", "-b", "pyusb", "--model", "QL-570", "-p", "usb://0x04f9:0x2028/000M6Z401370", "print", "-l", "62", png_file_path]
|
2023-06-11 17:06:47 +03:00
|
|
|
|
2023-06-11 12:20:57 +03:00
|
|
|
# Run the command
|
|
|
|
subprocess.check_call(command)
|
2023-06-11 17:06:47 +03:00
|
|
|
|
2023-06-11 12:20:57 +03:00
|
|
|
if __name__ == "__main__":
|
|
|
|
ExportAndRunScript().run()
|