Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $ pip install -r requirements.txt
```bash
$ ./print.py --help
usage: print.py [-h] [-l {debug,info,warn,error}] [-b {mean-threshold,floyd-steinberg,atkinson,halftone,none}] [-s] [-d DEVICE] [-e ENERGY]
filename
[-S SPEED] filename

prints an image on your cat thermal printer

Expand All @@ -40,8 +40,64 @@ options:
services.
-e ENERGY, --energy ENERGY
Thermal energy. Between 0x0000 (light) and 0xffff (darker, default).
-S SPEED, --speed SPEED
Print speed. Higher values print slower and darker. The official app uses 10 for the SC03h.
```

# Desktop app (AppImage)

There is also a GTK 4 desktop app (in Spanish) in `catprinter_gui/`. It
stays connected to the printer, shows its battery level and prints images,
PDFs, office documents (through LibreOffice) and text files with a preview
of the exact dots that will be printed.

It runs on the system's Python and GTK, so on Debian/Ubuntu you need:

```bash
$ sudo apt install python3-gi python3-gi-cairo gir1.2-gtk-4.0 gir1.2-adw-1 poppler-utils
```

Build the AppImage (about 1 MB) and run it:

```bash
$ ./appimage/build.sh
$ ./dist/CatPrinter-*-x86_64.AppImage
```

From the app menu, "Integrar con Archivos y el menú de apps" (or
`--instalar` on the command line) copies the AppImage to `~/.local/bin` and
adds it to the application menu, to "Open With" and to the context menu of
Files. For a top-level entry in that context menu, also install
`python3-nautilus` and restart Files with `nautilus -q`.

# Web app

`docs/` contains a web app (in Spanish) that prints from the browser through
Web Bluetooth, with the same processing and print settings as the desktop
app. It is a PWA: it can be installed, works offline once loaded, appears in
the Android share sheet and, when installed on the desktop, in "Open With".

Publish it with GitHub Pages (Settings → Pages → Deploy from a branch →
`main`, `/docs`). Web Bluetooth needs Chrome, Edge or Opera on Windows,
macOS, Android or ChromeOS; on other browsers the page explains the
alternatives. To try it locally, serve `docs/` over `http://localhost`.

# Dual-mode printers (SC03h)

Some printers, like the SC03h, also offer classic Bluetooth. BlueZ may then
try to connect over classic Bluetooth and fail with
`br-connection-profile-unavailable`. To fix it:

- Don't pair the printer in the system's Bluetooth settings. If you did,
remove it there: these printers don't need pairing.
- With BlueZ 5.80 or newer, set `Experimental = true` in the `[General]`
section of `/etc/bluetooth/main.conf` and run
`sudo systemctl restart bluetooth`. This lets catprinter ask BlueZ to use
Bluetooth Low Energy for the printer.

If prints come out blank, charge the printer: with a low battery it feeds
the paper but doesn't heat the print head.

# Example
```bash
% ./print.py --show-preview test.png
Expand Down
22 changes: 22 additions & 0 deletions appimage/AppRun
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# Runs the app with the system's Python and GTK; the AppImage only bundles
# pure Python code.
HERE="$(dirname "$(readlink -f "$0")")"

fail() {
if command -v zenity >/dev/null 2>&1; then
zenity --error --title="Impresora térmica" --text="$1" 2>/dev/null
elif command -v notify-send >/dev/null 2>&1; then
notify-send "Impresora térmica" "$1"
fi
echo "$1" >&2
exit 1
}

command -v python3 >/dev/null 2>&1 || fail "Falta Python 3. Instálalo con: sudo apt install python3"
python3 -c 'import gi, cairo; gi.require_version("Gtk", "4.0"); gi.require_version("Adw", "1")' 2>/dev/null ||
fail "Faltan bibliotecas de GTK. Instálalas con:
sudo apt install python3-gi python3-gi-cairo gir1.2-gtk-4.0 gir1.2-adw-1"

export PYTHONPATH="$HERE/usr/share/catprinter:$HERE/usr/share/catprinter/vendor"
exec python3 -s -m catprinter_gui "$@"
58 changes: 58 additions & 0 deletions appimage/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/sh
# Builds dist/CatPrinter-<version>-x86_64.AppImage.
set -eu

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
BUILD="$ROOT/build/appimage"
APPDIR="$BUILD/AppDir"
APP_ID=io.github.catprinter.Gui
APPIMAGETOOL_VERSION=1.9.1
TOOL="$BUILD/tools/appimagetool-$APPIMAGETOOL_VERSION-x86_64.AppImage"
TOOL_URL="https://github.com/AppImage/appimagetool/releases/download/$APPIMAGETOOL_VERSION/appimagetool-x86_64.AppImage"
VERSION="$(cd "$ROOT" && python3 -c 'import catprinter_gui; print(catprinter_gui.VERSION)')"
OUTPUT="$ROOT/dist/CatPrinter-$VERSION-x86_64.AppImage"

rm -rf "$APPDIR"
mkdir -p "$APPDIR/usr/share/catprinter" "$BUILD/tools" "$ROOT/dist"

# App code. img.py needs OpenCV and is only used by the command line tool.
for pkg in catprinter catprinter_gui; do
cp -r "$ROOT/$pkg" "$APPDIR/usr/share/catprinter/"
done
find "$APPDIR" -name __pycache__ -prune -exec rm -rf {} +
rm -f "$APPDIR/usr/share/catprinter/catprinter/img.py"

python3 -m pip install --quiet --no-compile \
--target "$APPDIR/usr/share/catprinter/vendor" -r "$ROOT/appimage/requirements.txt"
rm -rf "$APPDIR/usr/share/catprinter/vendor/bin"
if find "$APPDIR/usr/share/catprinter/vendor" -name '*.so' | grep -q .; then
echo "Error: bundled dependencies must be pure Python" >&2
exit 1
fi

cp "$ROOT/appimage/AppRun" "$APPDIR/AppRun"
cp "$ROOT/catprinter_gui/data/$APP_ID.svg" "$APPDIR/$APP_ID.svg"
ln -sf "$APP_ID.svg" "$APPDIR/.DirIcon"
mkdir -p "$APPDIR/usr/share/icons/hicolor/scalable/apps" "$APPDIR/usr/share/applications"
cp "$ROOT/catprinter_gui/data/$APP_ID.svg" "$APPDIR/usr/share/icons/hicolor/scalable/apps/"
cat > "$APPDIR/$APP_ID.desktop" <<DESKTOP
[Desktop Entry]
Type=Application
Name=Impresora térmica
Comment=Imprime imágenes, PDF, documentos y texto en tu impresora térmica
Exec=catprinter %F
Icon=$APP_ID
Terminal=false
Categories=Graphics;Utility;
DESKTOP
cp "$APPDIR/$APP_ID.desktop" "$APPDIR/usr/share/applications/"

if [ ! -x "$TOOL" ]; then
echo "Downloading appimagetool $APPIMAGETOOL_VERSION..."
curl -fL -o "$TOOL" "$TOOL_URL"
chmod +x "$TOOL"
fi
# Build next to the output and rename, so a running copy is not overwritten.
ARCH=x86_64 "$TOOL" --appimage-extract-and-run --no-appstream "$APPDIR" "$OUTPUT.tmp"
mv -f "$OUTPUT.tmp" "$OUTPUT"
echo "Built $OUTPUT"
4 changes: 4 additions & 0 deletions appimage/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Bundled in the AppImage. Only pure Python packages, so the AppImage works
# with whatever Python 3 version the system has.
bleak==0.14.3
dbus-next==0.2.3
Loading