Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4c6b05a
Build and install instructions
probonopd May 5, 2018
2f533fa
Add usage
probonopd May 5, 2018
12d796b
Update README.md
probonopd May 5, 2018
9e139b5
Example to print some text using a 12mm TZe tape
probonopd May 5, 2018
20c6a6e
Add files via upload
probonopd Nov 3, 2018
6cc9437
Create ptouch-770.py
probonopd Nov 3, 2018
8022cb2
Update ptouch-770.py
probonopd Nov 3, 2018
880934d
Update README.md
probonopd Nov 3, 2018
1f8160e
Update README.md
probonopd Nov 3, 2018
8d65e79
Add files via upload
probonopd Nov 3, 2018
d546d62
Rename label.py to ptouch-770-gui
probonopd Nov 3, 2018
20035a2
Update README.md
probonopd Nov 3, 2018
33f3838
Update README.md
probonopd Nov 3, 2018
84cfde1
Create LICENSE
probonopd Nov 3, 2018
f5c4b19
Merge pull request #6 from probonopd/add-license-1
probonopd Nov 3, 2018
6e2e898
Create ptouch-770.desktop
probonopd Dec 22, 2018
c9af566
Add USB ID 2064, hopefully this closes #7
probonopd Jun 1, 2019
a02ada0
Create ptouch-770.yml
probonopd Jun 2, 2019
8a73b07
Create .travis.yml
probonopd Jun 2, 2019
66524d6
Update .travis.yml
probonopd Jun 2, 2019
ac45a42
desktop-file-utils
probonopd Jun 2, 2019
940f197
Update ptouch-770.yml
probonopd Jun 2, 2019
3e6be46
Update ptouch-770.yml
probonopd Jun 2, 2019
8a3237d
Update ptouch-770.yml
probonopd Jun 2, 2019
46f94e4
Update .travis.yml
probonopd Jun 2, 2019
2b9de7b
Update ptouch-770.yml
probonopd Jun 2, 2019
8aef5e0
Update ptouch-770.yml
probonopd Jun 2, 2019
ad7fa7a
Update ptouch-770.yml
probonopd Jun 2, 2019
e74d6b1
Update ptouch-770.yml
probonopd Jun 2, 2019
4381e81
#!/usr/bin/env python3
probonopd Jun 2, 2019
551b250
#!/usr/bin/env python3
probonopd Jun 2, 2019
4d8922d
python3-gi
probonopd Jun 2, 2019
f8624b6
gir1.2-gtk-3.0
probonopd Jun 2, 2019
eaf8a71
Add invert button, closes #2
probonopd Jun 2, 2019
50ce75f
Make font selection functional, closes #4
probonopd Jun 2, 2019
1550b14
Update ptouch-770.yml
probonopd Jun 9, 2019
dd4be5c
Add files via upload
probonopd Jun 9, 2019
523d79f
Update ptouch-770.desktop
probonopd Jun 9, 2019
c180016
Update ptouch-770.yml
probonopd Jun 9, 2019
0d27f5f
Delete ptouch-770-gui.jpg
probonopd Jun 9, 2019
eef7119
Add files via upload
probonopd Jun 9, 2019
e2f1e1a
Update README.md
probonopd Jun 9, 2019
2c239b2
Update README.md
probonopd Jun 11, 2019
a4ce3da
Create .gitkeep
probonopd Dec 28, 2020
0aa70b7
Pure Python variant, tested on FreeBSD with PT-700
probonopd Dec 28, 2020
43fe0f4
Delete .gitkeep
probonopd Dec 28, 2020
f9e1371
Automatically select the first found device
probonopd Jan 2, 2021
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
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: cpp
compiler: gcc
sudo: require
dist: trusty

install:
- sudo apt-get -y install libudev-dev python3-pil desktop-file-utils

script:
- make -j$(nproc)
- wget -c "https://raw.githubusercontent.com/AppImage/pkg2appimage/master/pkg2appimage"
- bash -ex pkg2appimage ptouch-770.yml

after_success:
- wget -c https://github.com/probonopd/uploadtool/raw/master/upload.sh
- bash upload.sh out/P-touch_P700_Labels*.AppImage*

branches:
except:
- # Do not build tags that we create when we upload to GitHub Releases
- /^(?i:continuous)/
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
Brother PT-H500/P700/E500 printer control utility.
# Brother P-touch P700 label printer for Linux

## Building

On Debian/Ubuntu-like systems, compile and install with

```
sudo apt install git make gcc libudev-dev python3-pil python-usb libusb-1.0-0 python3-gi gir1.2-gtk-3.0
git clone https://github.com/abelits/ptouch-770
cd ptouch-770/
make
strip ptouch-770-write
sudo cp ptouch-770-write ptouch-770-gui /usr/local/bin/
```
## Usage (Python GTK3 GUI)

![screenshot](https://user-images.githubusercontent.com/2480569/47957306-38ca8c00-dfab-11e8-8d83-3d81aa30278f.png)

## Usage (Python script)

The Python script can be used to print multi-line text like this:

```
./ptouch-770.py --text "test\nfoo"
```

## Usage (raw tool)

Print a test image with

```
sudo ptouch-770-write tux-128px-bw.pbm
```

On the P700, this will result in the printer spitting out approximately 20mm of unprinted label, then cutting the label, then printing the Tux graphic on another approx. 20mm of label and cutting the label again.

To print some text using a 12mm TZe tape:

```
#!/bin/bash

# The following works for 12mm TZe tapes
convert -size x100 -gravity south -pointsize 72 caption:"Test" write.pbm
ptouch-770-write write.pbm
```
Binary file added calibrate_12mm_tape.pbm
Binary file not shown.
141 changes: 141 additions & 0 deletions ptouch-770-gui
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/env python3

from PIL import Image, ImageFont, ImageDraw
import os, sys, subprocess, argparse
import gi

gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class MyWindow(Gtk.ApplicationWindow):
def __init__(self, app):
Gtk.Window.__init__(self, title="Label", application=app)
self.lines = 0
self.entries = []
self.text = []
self.unprintable = 20
self.height = 84 # 12mm tape (tested)
self.rim = 5
self.font = "FreeSansBold.ttf"
self.set_border_width(10)
self.max_height = self.height + self.unprintable
self.outfile = "/tmp/out.pbm"
self.out = os.path.abspath(self.outfile)
self.invert = False

vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
for i in range(6):
entry = Gtk.Entry()
entry.connect("changed", self.on_text_changed)
vbox.pack_start(entry, False, False, 0)
self.entries.append(entry)

fonts = ["FreeSans.ttf", "FreeSansBold.ttf"]
fonts_combo = Gtk.ComboBoxText()
fonts_combo.set_entry_text_column(0)
for currency in fonts:
fonts_combo.append_text(currency)
vbox.pack_start(fonts_combo, False, False, 0)
fonts_combo.connect("changed", self.on_fonts_combo_changed)

self.inverted = Gtk.CheckButton("Invert")
self.inverted.show()
vbox.pack_start(self.inverted, False, False, 0)
self.inverted.connect("toggled", self.on_button_toggled, "2")

self.image = Gtk.Image()
self.image.set_from_file(self.outfile)
vbox.pack_start(self.image, False, False, 0)

self.button = Gtk.Button.new_with_label("Print")
self.button.connect("clicked", self.on_click_me_clicked)
vbox.pack_start(self.button, False, False, 0)

self.add(vbox)

def on_fonts_combo_changed(self, combo):
tree_iter = combo.get_active_iter()
if tree_iter is not None:
model = combo.get_model()
row_id, name = model[tree_iter][:2]
print("Selected: ID=%s" % (row_id))
self.font = row_id
else:
entry = combo.get_child()
print("Entered: %s" % entry.get_text())
self.on_text_changed(None)


def on_button_toggled(self, button, name):
if button.get_active():
self.invert = True
else:
self.invert = False
print("Button", name, "was toggled")
self.on_text_changed(None)

def on_text_changed(self, entry):
self.lines = 0
self.text = []
# Count the number of lines
for entry in self.entries:
if (entry.get_text() != ""):
self.text.append(entry.get_text())
self.lines = self.lines + 1

fontsize = int(round(self.height / self.lines, 0))

font = ImageFont.truetype(self.font, fontsize)

# Determine the height in pixels based on letter "A"
# rather than the actual text so as to not have varying
# text heights just because some lines contain letters
# such as "A, g" that have a different height
text_unused_width, text_height = font.getsize("A")

# Determine the longest line
max_width = 0
for line in self.text:
text_width, text_unused_height = font.getsize(line)
width = text_width + self.rim * 2
if (width > max_width):
max_width = width

if(self.invert == True):
foreground = 255
background = 0
else:
foreground = 0
background = 255

image = Image.new("1", (max_width, self.max_height), background)
draw = ImageDraw.Draw(image)

text_x = self.rim
text_y = self.unprintable - text_height
for line in self.text:
text_y = text_y + text_height * 0.9
draw.text((text_x, text_y), line, fill=foreground, font=font)
image.save(self.out)
self.image.set_from_file(self.outfile)

def on_click_me_clicked(self, button):
tool = os.path.abspath(os.path.join(os.path.dirname(__file__), "ptouch-770-write"))
subprocess.run(["sudo", tool, self.out], check=True)

class MyApplication(Gtk.Application):

def __init__(self):
Gtk.Application.__init__(self)

def do_activate(self):
win = MyWindow(self)
win.show_all()

def do_startup(self):
Gtk.Application.do_startup(self)


app = MyApplication()
exit_status = app.run(sys.argv)
sys.exit(exit_status)
Binary file added ptouch-770-gui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion ptouch-770-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ int main(int argc, char **argv)
&& !strcasecmp(vendor,"04f9") /* Brother */
&& (!strcasecmp(product,"205e") /* PT-H500 */
|| !strcasecmp(product,"205f") /* PT-E500 */
|| !strcasecmp(product,"2061") /* PT-P700 */))
|| !strcasecmp(product,"2061") /* PT-P700 */
|| !strcasecmp(product,"2064") /* PT-P700 */))
{
devpath_found = udev_device_get_devnode(udev_dev);
if(devpath_found)
Expand Down
7 changes: 7 additions & 0 deletions ptouch-770.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Desktop Entry]
Type=Application
Name=P-touch P700 Labels
Comment=Print labels on the Brother P-touch P700
Icon=ptouch-770-gui
Exec=ptouch-770-gui
Categories=2DGraphics;
52 changes: 52 additions & 0 deletions ptouch-770.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3

# Based on https://github.com/SquirrelCZE/ptouch-770
# On 12mm tape, the topmost 20px are not printed, the following 84 px are printed
# (as determined by experimentation using calibrate_12mm_tape.pbm made with GIMP)
# TODO: Check other tape sizes

from PIL import Image, ImageFont, ImageDraw
import os, subprocess, argparse

unprintable = 20

parser = argparse.ArgumentParser(description="Utility for printing on ptouch 700")
parser.add_argument('--text', type=str, help="string to be printed", default="Two\\nlines")
parser.add_argument('--height', type=int, help="height in pixels of loaded tape", default=84)
parser.add_argument('--rim', type=int, help="rim around the text in pixels", default=5)
parser.add_argument('--font', type=str, help="name of truetype font", default="FreeSansBold.ttf")

args = parser.parse_args()
max_height = args.height + unprintable

text = args.text.split("\\n")
print(text)

lines = len(text)

fontsize = int(round(args.height/lines,0))

font = ImageFont.truetype(args.font, fontsize)

# Determine the longest line
max_width = 0
for line in text:
text_width, text_height = font.getsize(line)
width = text_width + args.rim * 2
if(width > max_width):
max_width = width

image = Image.new("1", ( max_width, max_height ), 0)
draw = ImageDraw.Draw( image )

text_x = args.rim
text_y = unprintable-text_height
for line in text:
text_y = text_y + text_height*0.9
draw.text((text_x,text_y), line, fill=255, font=font)

out = os.path.abspath("out.pbm")
image.save(out)
tool = os.path.abspath(os.path.join(os.path.dirname(__file__), "ptouch-770-write"))

subprocess.run(["sudo", tool, out], check=True)
29 changes: 29 additions & 0 deletions ptouch-770.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
app: ptouch-770

ingredients:
packages:
- python3
- python3-pil
- python-usb
- libusb-1.0-0
- python3-gi
- gir1.2-gtk-3.0
- python3-click
- python3-gi-cairo
- python3-cairo

dist: trusty
sources:
- deb http://us.archive.ubuntu.com/ubuntu/ trusty main universe
script:
- git rev-parse --short HEAD > VERSION

script:
- mkdir -p usr/bin
- cp ../../ptouch-770-gui usr/bin
- cp ../../ptouch-770-write usr/bin
- chmod +x usr/bin/*
- mkdir -p usr/share/applications && cp ../../ptouch-770.desktop usr/share/applications/
- mkdir -p usr/share/icons/hicolor/256x256/apps && cp ../../ptouch-770-gui.png usr/share/icons/hicolor/256x256/apps/
- cp ./usr/share/applications/ptouch-770.desktop . # Why do I need to do this manually?
- cp usr/share/icons/hicolor/256x256/apps/printmgr.png . # Dito
Loading