Skip to content

Commit 815d5fe

Browse files
authored
Black & isort
1 parent 65d411c commit 815d5fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1754
-1292
lines changed

pyembroidery/ArtReader.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
# contents = compoundfiles.CompoundFileReader(f).open('Contents')
2424
# contents.seek(4) # file size
2525
# art = BytesIO(zlib.decompress(bytes([swizzle(b) for b in contents.read()])))
26-
# while True:
27-
# b = read_int_8(art)
28-
# if b is None or b == -1:
29-
# break
30-
# print('%02X' % b)
26+
# with open('file.bin', 'bw') as f:
27+
# while True:
28+
# b = read_int_8(art)
29+
# if b is None or b == -1:
30+
# break
31+
# f.write(bytearray(chr(b), 'utf-8'))
32+
# print('%02X' % b)

pyembroidery/BroReader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from .ReadHelper import read_int_16le, read_int_8, signed8, signed16
2-
1+
from .ReadHelper import read_int_8, read_int_16le, signed8, signed16
32

43
# Do you even embroider .bro?
54

5+
66
def read_bro_stitches(f, out):
77
count = 0
88
while True:

pyembroidery/ColReader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
def read(f, out, settings=None):
77
count = int(f.readline())
8-
for i in range(0,count):
8+
for i in range(0, count):
99
line = f.readline()
10-
splits = line.split(',')
10+
splits = line.split(",")
1111
thread = EmbThread()
1212
thread.catalog_number = splits[0]
1313
thread.set_color(int(splits[1]), int(splits[2]), int(splits[3]))

pyembroidery/ColWriter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ def write(pattern, f, settings=None):
77
write_string_utf8(f, "%d\r\n" % len(pattern.threadlist))
88
index = 0
99
for thread in pattern.threadlist:
10-
write_string_utf8(f, "%d,%d,%d,%d\r\n" % (
11-
index,
12-
thread.get_red(),
13-
thread.get_green(),
14-
thread.get_blue()))
10+
write_string_utf8(
11+
f,
12+
"%d,%d,%d,%d\r\n"
13+
% (index, thread.get_red(), thread.get_green(), thread.get_blue()),
14+
)
1515
index += 1

pyembroidery/CsvReader.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
def read(f, out, settings=None):
77
import csv
8-
csv_reader = csv.reader(f, delimiter=',')
8+
9+
csv_reader = csv.reader(f, delimiter=",")
910
command_dict = get_command_dictionary()
1011
for row in csv_reader:
1112
if len(row) == 0:
1213
continue
1314
if "*" in row[0]:
14-
split = row[2].split(' ')
15+
split = row[2].split(" ")
1516
command = command_dict[split[0]]
1617
for sp in split[1:]:
1718
if sp[0] == "n":
@@ -35,7 +36,12 @@ def read(f, out, settings=None):
3536
out.metadata(row[1], row[2])
3637
elif "$" in row[0]:
3738
thread_add = {}
38-
if len(row) == 7 and len(row[2]) <= 3 and len(row[3]) <= 3 and len(row[4]) <= 3:
39+
if (
40+
len(row) == 7
41+
and len(row[2]) <= 3
42+
and len(row[3]) <= 3
43+
and len(row[4]) <= 3
44+
):
3945
# This is an embroidermodder csv file, I changed the colors and added more details.
4046
# [THREAD_NUMBER], [RED], [GREEN], [BLUE], [DESCRIPTION], [CATALOG_NUMBER]\"\n");
4147
thread_add["rgb"] = (int(row[2]), int(row[3]), int(row[4]))

pyembroidery/CsvWriter.py

Lines changed: 82 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def csv(f, values):
1313
string = ""
1414
for v in values:
1515
if len(string) > 0:
16-
string += ','
17-
string += ('\"%s\"' % v)
16+
string += ","
17+
string += '"%s"' % v
1818
write_string_utf8(f, string + "\n")
1919

2020

@@ -38,19 +38,19 @@ def write_data(pattern, f):
3838
width = extends[2] - extends[0]
3939
height = extends[3] - extends[1]
4040

41-
csv(f, ('#', '[VAR_NAME]', '[VAR_VALUE]'))
41+
csv(f, ("#", "[VAR_NAME]", "[VAR_VALUE]"))
4242
count_stitches = pattern.count_stitches()
43-
csv(f, ('>', 'STITCH_COUNT:', str(count_stitches)))
43+
csv(f, (">", "STITCH_COUNT:", str(count_stitches)))
4444
count_threads = pattern.count_color_changes()
45-
csv(f, ('>', 'THREAD_COUNT:', str(count_threads)))
45+
csv(f, (">", "THREAD_COUNT:", str(count_threads)))
4646
count_set_needles = pattern.count_needle_sets()
47-
csv(f, ('>', 'NEEDLE_COUNT:', str(count_set_needles)))
48-
csv(f, ('>', 'EXTENTS_LEFT:', str(extends[0])))
49-
csv(f, ('>', 'EXTENTS_TOP:', str(extends[1])))
50-
csv(f, ('>', 'EXTENTS_RIGHT:', str(extends[2])))
51-
csv(f, ('>', 'EXTENTS_BOTTOM:', str(extends[3])))
52-
csv(f, ('>', 'EXTENTS_WIDTH:', str(width)))
53-
csv(f, ('>', 'EXTENTS_HEIGHT:', str(height)))
47+
csv(f, (">", "NEEDLE_COUNT:", str(count_set_needles)))
48+
csv(f, (">", "EXTENTS_LEFT:", str(extends[0])))
49+
csv(f, (">", "EXTENTS_TOP:", str(extends[1])))
50+
csv(f, (">", "EXTENTS_RIGHT:", str(extends[2])))
51+
csv(f, (">", "EXTENTS_BOTTOM:", str(extends[3])))
52+
csv(f, (">", "EXTENTS_WIDTH:", str(width)))
53+
csv(f, (">", "EXTENTS_HEIGHT:", str(height)))
5454

5555
stitch_counts = {}
5656
for s in pattern.stitches:
@@ -67,56 +67,50 @@ def write_data(pattern, f):
6767
name = "COMMAND_" + names[the_key]
6868
except (IndexError, KeyError):
6969
name = "COMMAND_UNKNOWN_" + str(the_key)
70-
csv(f, (
71-
'>',
72-
name,
73-
str(the_value)
74-
))
70+
csv(f, (">", name, str(the_value)))
7571

7672
write_string_utf8(f, "\n")
7773

7874

7975
def write_metadata(pattern, f):
8076
if len(pattern.extras) > 0:
81-
csv(f, (
82-
'#',
83-
'[METADATA_NAME]',
84-
'[METADATA]'
85-
))
77+
csv(f, ("#", "[METADATA_NAME]", "[METADATA]"))
8678
for the_key, the_value in pattern.extras.items():
8779
if isinstance(the_value, tuple):
8880
the_value = "\n" + get_graphic_as_string(the_value)
89-
csv(f, (
90-
'@',
91-
str(the_key),
92-
str(the_value)
93-
))
81+
csv(f, ("@", str(the_key), str(the_value)))
9482
write_string_utf8(f, "\n")
9583

9684

9785
def write_threads(pattern, f):
9886
if len(pattern.threadlist) > 0:
99-
csv(f, (
100-
'#',
101-
'[THREAD_NUMBER]',
102-
'[HEX_COLOR]',
103-
'[DESCRIPTION]',
104-
'[BRAND]',
105-
'[CATALOG_NUMBER]',
106-
'[DETAILS]',
107-
'[WEIGHT]'
108-
))
87+
csv(
88+
f,
89+
(
90+
"#",
91+
"[THREAD_NUMBER]",
92+
"[HEX_COLOR]",
93+
"[DESCRIPTION]",
94+
"[BRAND]",
95+
"[CATALOG_NUMBER]",
96+
"[DETAILS]",
97+
"[WEIGHT]",
98+
),
99+
)
109100
for i, thread in enumerate(pattern.threadlist):
110-
csv(f, (
111-
'$',
112-
str(i),
113-
thread.hex_color(),
114-
thread.description,
115-
thread.brand,
116-
thread.catalog_number,
117-
thread.details,
118-
thread.weight,
119-
))
101+
csv(
102+
f,
103+
(
104+
"$",
105+
str(i),
106+
thread.hex_color(),
107+
thread.description,
108+
thread.brand,
109+
thread.catalog_number,
110+
thread.details,
111+
thread.weight,
112+
),
113+
)
120114
write_string_utf8(f, "\n")
121115

122116

@@ -137,87 +131,74 @@ def decoded_name(names, data):
137131

138132
def write_stitches_displacement(pattern, f):
139133
names = get_common_name_dictionary()
140-
csv(f, (
141-
'#',
142-
'[STITCH_INDEX]',
143-
'[STITCH_TYPE]',
144-
'[X]',
145-
'[Y]',
146-
'[DX]',
147-
'[DY]',
148-
'[R]',
149-
'[ANGLE]'
150-
))
134+
csv(
135+
f,
136+
(
137+
"#",
138+
"[STITCH_INDEX]",
139+
"[STITCH_TYPE]",
140+
"[X]",
141+
"[Y]",
142+
"[DX]",
143+
"[DY]",
144+
"[R]",
145+
"[ANGLE]",
146+
),
147+
)
151148

152149
current_x = 0
153150
current_y = 0
154151
for i, stitch in enumerate(pattern.stitches):
155152
name = decoded_name(names, stitch[2])
156153
dx = stitch[0] - current_x
157154
dy = stitch[1] - current_y
158-
csv(f, (
159-
'*',
160-
str(i),
161-
name,
162-
str(stitch[0]),
163-
str(stitch[1]),
164-
str(dx),
165-
str(dy),
166-
str(distance(dx, dy)),
167-
str(angle(dx, dy))
168-
))
155+
csv(
156+
f,
157+
(
158+
"*",
159+
str(i),
160+
name,
161+
str(stitch[0]),
162+
str(stitch[1]),
163+
str(dx),
164+
str(dy),
165+
str(distance(dx, dy)),
166+
str(angle(dx, dy)),
167+
),
168+
)
169169
current_x = stitch[0]
170170
current_y = stitch[1]
171171

172172

173173
def write_stitches_deltas(pattern, f):
174174
names = get_common_name_dictionary()
175-
csv(f, (
176-
'#',
177-
'[STITCH_INDEX]',
178-
'[STITCH_TYPE]',
179-
'[X]',
180-
'[Y]',
181-
'[DX]',
182-
'[DY]'
183-
))
175+
csv(f, ("#", "[STITCH_INDEX]", "[STITCH_TYPE]", "[X]", "[Y]", "[DX]", "[DY]"))
184176
current_x = 0
185177
current_y = 0
186178
for i, stitch in enumerate(pattern.stitches):
187179
name = decoded_name(names, stitch[2])
188180
dx = stitch[0] - current_x
189181
dy = stitch[1] - current_y
190-
csv(f, (
191-
'*',
192-
str(i),
193-
name,
194-
str(stitch[0]),
195-
str(stitch[1]),
196-
str(dx),
197-
str(dy)
198-
))
182+
csv(f, ("*", str(i), name, str(stitch[0]), str(stitch[1]), str(dx), str(dy)))
199183
current_x = stitch[0]
200184
current_y = stitch[1]
201185

202186

203187
def write_stitches(pattern, f):
204188
names = get_common_name_dictionary()
205-
csv(f, (
206-
'#',
207-
'[STITCH_INDEX]',
208-
'[STITCH_TYPE]',
209-
'[X]',
210-
'[Y]'
211-
))
189+
csv(f, ("#", "[STITCH_INDEX]", "[STITCH_TYPE]", "[X]", "[Y]"))
212190
for i, stitch in enumerate(pattern.stitches):
213191
name = decoded_name(names, stitch[2])
214-
csv(f, (
215-
'*',
216-
str(i),
217-
name,
218-
str(stitch[0]),
219-
str(stitch[1]),
220-
))
192+
csv(
193+
f,
194+
(
195+
"*",
196+
str(i),
197+
name,
198+
str(stitch[0]),
199+
str(stitch[1]),
200+
),
201+
)
221202

222203

223204
def write(pattern, f, settings=None):

pyembroidery/DatReader.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def read_barudan_dat(f, out):
6363
if dx != 0 or dy != 0:
6464
out.move(dx, dy)
6565
continue
66-
if command == 0x08: # ww, stop file had proper A8 rather than E8 and displacement
66+
if (
67+
command == 0x08
68+
): # ww, stop file had proper A8 rather than E8 and displacement
6769
# C00 Stop
6870
out.stop()
6971
if dx != 0 or dy != 0:

pyembroidery/DstReader.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,8 @@ def process_header_info(out, prefix, value):
4040
elif prefix == "CP":
4141
out.metadata("copyright", value)
4242
elif prefix == "TC":
43-
values = [x.strip() for x in value.split(',')]
44-
out.add_thread({
45-
"hex": values[0],
46-
"description": value[1],
47-
"catalog": value[2]
48-
})
43+
values = [x.strip() for x in value.split(",")]
44+
out.add_thread({"hex": values[0], "description": value[1], "catalog": value[2]})
4945
else:
5046
out.metadata(prefix, value)
5147

@@ -54,12 +50,14 @@ def dst_read_header(f, out):
5450
header = f.read(512)
5551
start = 0
5652
for i, element in enumerate(header):
57-
if element == 13 or element == 10 or element == '\n' or element == '\r': # 13 =='\r', 10 = '\n'
53+
if (
54+
element == 13 or element == 10 or element == "\n" or element == "\r"
55+
): # 13 =='\r', 10 = '\n'
5856
end = i
5957
data = header[start:end]
6058
start = end
6159
try:
62-
line = data.decode('utf8').strip()
60+
line = data.decode("utf8").strip()
6361
if len(line) > 3:
6462
process_header_info(out, line[0:2].strip(), line[3:].strip())
6563
except UnicodeDecodeError: # Non-utf8 information. See #83
@@ -94,9 +92,9 @@ def dst_read_stitches(f, out, settings=None):
9492
clipping = True
9593
trim_distance = None
9694
if settings is not None:
97-
count_max = settings.get('trim_at', count_max)
95+
count_max = settings.get("trim_at", count_max)
9896
trim_distance = settings.get("trim_distance", trim_distance)
99-
clipping = settings.get('clipping', clipping)
97+
clipping = settings.get("clipping", clipping)
10098
if trim_distance is not None:
10199
trim_distance *= 10 # Pixels per mm. Native units are 1/10 mm.
102100
out.interpolate_trims(count_max, trim_distance, clipping)

0 commit comments

Comments
 (0)