Skip to content

Commit 3aa14c7

Browse files
committed
Initial commit, need cleanup
1 parent 5762976 commit 3aa14c7

32 files changed

+1471
-0
lines changed

Documentation.odt

20.8 KB
Binary file not shown.

Labitrack.py

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
#!/usr/bin/env python
2+
# coding: utf-8
3+
4+
#####################################################
5+
# #
6+
# Labitrack v 0.1 - (Beerware) - 2010 panton, halfd #
7+
# #
8+
#####################################################
9+
10+
11+
import Tkinter as T
12+
import barcode.barcode as B
13+
import opencv
14+
#import opencv.adaptors
15+
import ImageTk
16+
from opencv import highgui
17+
18+
import os, sqlite3, random, time
19+
20+
# Application class
21+
os.chdir('/home/panton/Documents/labitrack/')
22+
23+
class Labitrack:
24+
def __init__(self, master):
25+
self.conn = sqlite3.connect('objects.db')
26+
self.cur = self.conn.cursor()
27+
28+
# Get the next id man
29+
self.cur.execute('select oid+1 from objects order by oid desc limit 1;')
30+
self.id_val = self.cur.fetchone()[0]
31+
32+
self.camera = highgui.cvCreateCameraCapture(0)
33+
self.image = None
34+
35+
# Create a label instance
36+
self.label = B.Label()
37+
38+
# The master frame
39+
self.frame = T.Frame(master)
40+
41+
# Frame for camera input
42+
camera_frame = T.Frame(self.frame, relief="sunken", borderwidth=1, pady=20)
43+
44+
self.imagecanvas = T.Canvas(camera_frame, width=320, height=240)
45+
46+
# take picture button
47+
picture_button = T.Button(camera_frame, text="Take picture", anchor=T.W, command=self.takepicture)
48+
49+
# Frame for input
50+
input_frame = T.Frame(self.frame, relief="sunken", borderwidth=1, pady=20)
51+
52+
# Object name label and input field
53+
object_name_label = T.Label(
54+
input_frame,
55+
text="Name of item",
56+
font=("Helvetica", 17),
57+
anchor=T.W,
58+
justify=T.LEFT,
59+
width=50,
60+
padx=20,
61+
pady=5
62+
)
63+
64+
self.object_name = T.Entry(
65+
input_frame,
66+
width=64,
67+
font=("Helvetica", 14),
68+
border=0,
69+
highlightcolor="#34fe32"
70+
)
71+
72+
# Object tagline label and input field
73+
object_tagline_label = T.Label(
74+
input_frame,
75+
text="Tagline",
76+
font=("Helvetica", 17),
77+
anchor=T.W,
78+
justify=T.LEFT,
79+
width=50,
80+
padx=20,
81+
pady=5
82+
)
83+
84+
self.object_tagline = T.Entry(
85+
input_frame,
86+
width=64,
87+
font=("Helvetica", 14),
88+
border=0,
89+
highlightcolor="#34fe32"
90+
)
91+
92+
# Frame for options
93+
option_frame = T.Frame(self.frame, relief="sunken", border=1, pady=20, padx=20)
94+
95+
self.personal = T.IntVar()
96+
self.choice_personal = T.Checkbutton(option_frame, text="Personal", variable=self.personal)
97+
98+
self.manual = T.IntVar()
99+
self.choice_manual = T.Checkbutton(option_frame, text="Manual", variable=self.manual)
100+
101+
self.dnh = T.IntVar()
102+
self.choice_dnh = T.Checkbutton(option_frame, text="Do not hack", variable=self.dnh)
103+
104+
# Frame for buttons
105+
button_frame = T.Frame(self.frame, relief="sunken", border=1, pady=20, padx=20)
106+
107+
# Preview button
108+
preview_button = T.Button(button_frame, text="Preview", anchor=T.W, command=self.create_preview)
109+
110+
# Print button
111+
print_button = T.Button(button_frame, text="Print", anchor=T.E, command=self.create_print)
112+
113+
# Pack camera input
114+
camera_frame.pack(side="left")
115+
self.imagecanvas.pack(side="top")
116+
picture_button.pack(side="top")
117+
118+
# Pack input frame and widgets
119+
input_frame.pack(side="top",expand="true")
120+
121+
object_name_label.pack(side="top")
122+
self.object_name.pack(side="top", expand="true")
123+
124+
object_tagline_label.pack(side="top")
125+
self.object_tagline.pack(side="top")
126+
127+
# Pack choice frame and widgets
128+
option_frame.pack(side="left",expand="true")
129+
130+
self.choice_personal.pack(side="left")
131+
self.choice_manual.pack(side="left")
132+
self.choice_dnh.pack(side="left")
133+
134+
# Pack button frame and widgets
135+
button_frame.pack(side="left")
136+
137+
preview_button.pack(side="left")
138+
print_button.pack(side="left")
139+
140+
# Set window-title and pack the master frame
141+
self.frame.master.title('Labitrack')
142+
self.frame.pack()
143+
#self.display_picture()
144+
145+
def create_preview(self):
146+
self.name_val = self.object_name.get()
147+
self.tagline_val = self.object_tagline.get()
148+
self.personal_val = self.personal.get()
149+
self.manual_val = self.manual.get()
150+
self.dnh_val = self.dnh.get()
151+
152+
self.cur.execute('select oid+1 from objects order by oid desc limit 1;')
153+
self.id_val = self.cur.fetchone()[0]
154+
155+
self.label.create(
156+
self.name_val,
157+
self.tagline_val,
158+
self.id_val,
159+
labelpersonal=self.personal_val,
160+
labelmanual=self.manual_val,
161+
labeldnh=self.dnh_val
162+
)
163+
164+
def create_print(self):
165+
self.cur.execute('insert into objects (name, tagline) values (?, ?);', (self.name_val, self.tagline_val))
166+
self.label.printlabel()
167+
self.conn.commit()
168+
169+
def display_picture(self):
170+
imagecapture = highgui.cvQueryFrame(self.camera)
171+
self.pilimage = opencv.adaptors.Ipl2PIL(imagecapture)
172+
miniimage = self.pilimage.resize((320,240))
173+
self.image = ImageTk.PhotoImage(miniimage, master=self.frame)
174+
self.imagecanvas.create_image(0,0,image=self.image,anchor="nw")
175+
self.imagecanvas.update()
176+
time.sleep(0.1)
177+
self.display_picture()
178+
179+
def takepicture(self):
180+
self.pilimage.save('images/%d.png' % (self.id_val, ))
181+
182+
# Create application and run mainloop
183+
top = T.Tk()
184+
labitrack = Labitrack(top)
185+
top.mainloop()
File renamed without changes.

barcode/__init__.pyc

137 Bytes
Binary file not shown.

barcode/barcode.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python
2+
3+
# coding: utf-8
4+
5+
import sys, pyx, os
6+
import qrcode
7+
8+
from urllib2 import urlopen
9+
from PIL import Image
10+
from random import randint
11+
12+
class Label:
13+
def __init__(self):
14+
pyx.text.set(mode="latex")
15+
pyx.text.preamble(r"\parindent=0pt")
16+
self.e = qrcode.Encoder()
17+
18+
def create(self, labelname, labelinfo, labelid, labelpersonal=False, labelmanual=False, labeldnh=True):
19+
labelid = int(labelid)
20+
self.printedid = labelid
21+
22+
width = 5.5
23+
image = self.e.encode('http://o.labitat.dk/%d' % labelid, version=2, eclevel=self.e.eclevel.L)
24+
25+
c = pyx.canvas.canvas()
26+
c.insert(pyx.bitmap.bitmap(0, 0.4, image, height=2.5))
27+
c.text(2.7, 2.9, r"{\textbf{\Large\sffamily %s}}" % labelname , [pyx.text.halign.boxleft, pyx.text.valign.top])
28+
c.text(2.7, 2.35, r"{\sffamily ID: %d}" % labelid , [pyx.text.halign.boxleft, pyx.text.valign.top])
29+
30+
c.text(2.7, 1.96, r"{\textit{\sffamily %s}}" % labelinfo , [pyx.text.parbox(width), pyx.text.halign.boxleft, pyx.text.valign.top])
31+
32+
if labelpersonal:
33+
im = Image.open("/home/halfd/labitrack/barcode/person.jpg")
34+
c.insert(pyx.bitmap.bitmap(2.7,0.1+0.4,im,height=0.7))
35+
36+
if labelmanual:
37+
im = Image.open("/home/halfd/labitrack/barcode/manual.jpg")
38+
c.insert(pyx.bitmap.bitmap(3.6,0.1+0.4,im,height=0.7))
39+
40+
if labeldnh:
41+
tbox = pyx.text.text(2.5+width, 0.31+0.4, r"{\textbf{\Large\sffamily DNH}}", [pyx.text.halign.boxright, pyx.text.valign.bottom])
42+
tpath = tbox.bbox().enlarged(3*pyx.unit.x_pt).path()
43+
c.draw(tpath, [pyx.deco.stroked()])
44+
c.stroke(tpath, [pyx.style.linewidth.Thick])
45+
c.insert(tbox)
46+
47+
sc = pyx.canvas.canvas()
48+
sc.insert(c, [pyx.trafo.rotate(90)])
49+
50+
sc.writePDFfile("print")
51+
os.system("pdftops print.pdf")
52+
os.system("evince print.ps")
53+
54+
def printlabel(self):
55+
os.system("lpr -PQL-570 print.ps")
56+
os.system("mv print.ps printed/%s.ps" % (self.printedid, ) )
57+
os.system("rm print.pdf")

barcode/barcode.pyc

2.97 KB
Binary file not shown.

barcode/barcode.py~

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python
2+
3+
# coding: utf-8
4+
5+
import sys, pyx, os
6+
import qrcode
7+
8+
from urllib2 import urlopen
9+
from PIL import Image
10+
from random import randint
11+
12+
class Label:
13+
def __init__(self):
14+
pyx.text.set(mode="latex")
15+
pyx.text.preamble(r"\parindent=0pt")
16+
self.e = qrcode.Encoder()
17+
18+
def create(self, labelname, labelinfo, labelid, labelpersonal=False, labelmanual=False, labeldnh=True):
19+
labelid = int(labelid)
20+
self.printedid = labelid
21+
22+
width = 5.5
23+
image = self.e.encode('http://o.labitat.dk/%d' % labelid, version=2, eclevel=self.e.eclevel.L)
24+
25+
c = pyx.canvas.canvas()
26+
c.insert(pyx.bitmap.bitmap(0, 0.4, image, height=2.5))
27+
c.text(2.7, 2.9, r"{\textbf{\Large\sffamily %s}}" % labelname , [pyx.text.halign.boxleft, pyx.text.valign.top])
28+
c.text(2.7, 2.35, r"{\sffamily ID: %d}" % labelid , [pyx.text.halign.boxleft, pyx.text.valign.top])
29+
30+
c.text(2.7, 1.96, r"{\textit{\sffamily %s}}" % labelinfo , [pyx.text.parbox(width), pyx.text.halign.boxleft, pyx.text.valign.top])
31+
32+
if labelpersonal:
33+
im = Image.open("/home/halfd/labitrack/barcode/person.jpg")
34+
c.insert(pyx.bitmap.bitmap(2.7,0.1+0.4,im,height=0.7))
35+
36+
if labelmanual:
37+
im = Image.open("/home/halfd/labitrack/barcode/manual.jpg")
38+
c.insert(pyx.bitmap.bitmap(3.6,0.1+0.4,im,height=0.7))
39+
40+
if labeldnh:
41+
tbox = pyx.text.text(2.5+width, 0.31+0.4, r"{\textbf{\Large\sffamily DNH}}", [pyx.text.halign.boxright, pyx.text.valign.bottom])
42+
tpath = tbox.bbox().enlarged(3*pyx.unit.x_pt).path()
43+
c.draw(tpath, [pyx.deco.stroked()])
44+
c.stroke(tpath, [pyx.style.linewidth.Thick])
45+
c.insert(tbox)
46+
47+
sc = pyx.canvas.canvas()
48+
sc.insert(c, [pyx.trafo.rotate(90)])
49+
50+
sc.writePDFfile("print")
51+
os.system("pdftops print.pdf")
52+
os.system("evince print.ps")
53+
54+
def printlabel(self):
55+
os.system("lpr -PQL-570 print.ps")
56+
os.system("mv print.ps printed/%s.ps" % (self.printedid, ) )

barcode/manual.jpg

9.24 KB
Loading

barcode/opryd/manual.png

1.63 KB
Loading

barcode/opryd/manual.svg

Lines changed: 4 additions & 0 deletions
Loading

barcode/opryd/person.png

1.51 KB
Loading

barcode/opryd/person.svg

Lines changed: 21 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)