|
6 | 6 |
|
7 | 7 | USE_SPHINX_GALLERY = False
|
8 | 8 |
|
| 9 | +# Check if in IDLE, disable if so |
| 10 | +import sys |
| 11 | + |
| 12 | +class non_idle_tqdm: |
| 13 | + def __init__(self, iterable, *args, **kwargs): |
| 14 | + self.iterable = iterable |
| 15 | + if 'idlelib.run' not in sys.modules: |
| 16 | + self.tqdm = tqdm |
| 17 | + else: |
| 18 | + self.tqdm = None |
| 19 | + |
| 20 | + def __iter__(self): |
| 21 | + if self.tqdm is not None: |
| 22 | + return iter(self.tqdm(self.iterable)) |
| 23 | + else: |
| 24 | + return iter(self.iterable) |
| 25 | + |
| 26 | +class no_tqdm: |
| 27 | + def __init__(self, iterable, *args, **kwargs): |
| 28 | + self.iterable = iterable |
| 29 | + |
| 30 | + def __iter__(self): |
| 31 | + return iter(self.iterable) |
| 32 | + |
| 33 | + def __call__(self, *args, **kwargs): |
| 34 | + return iter(self.iterable) |
9 | 35 |
|
10 | 36 | def get_dimensions(stitches):
|
11 | 37 | if len(stitches) == 0: return 0, 0
|
@@ -216,11 +242,15 @@ def visualise_pattern(pattern, turtle=None, width=800, height=800, scale=1, spee
|
216 | 242 | raise_error = False
|
217 | 243 | threads = list(pattern.threadlist)
|
218 | 244 | thread_idx = 0
|
| 245 | + progressbar = non_idle_tqdm |
219 | 246 | if skip:
|
220 | 247 | print("Rendering... (show animation with skip=False)")
|
| 248 | + progressbar = no_tqdm |
221 | 249 | else:
|
222 | 250 | print("Visualising... (skip with skip=True)")
|
223 |
| - for x, y, command in tqdm(pattern.stitches): |
| 251 | + if len(pattern.stitches) < 50: |
| 252 | + progressbar = no_tqdm |
| 253 | + for x, y, command in progressbar(pattern.stitches): |
224 | 254 | x = scale * x
|
225 | 255 | y = scale * y
|
226 | 256 | if command == JUMP:
|
@@ -304,7 +334,10 @@ def density(stitches):
|
304 | 334 | def density_from_points(pts, dist=0.5, num=20):
|
305 | 335 | print("Checking density of stitches... (skip with check_density=False)")
|
306 | 336 | adjmat = [ [ -1 for j in range(len(pts))] for i in range(len(pts))]
|
307 |
| - for i in tqdm(range(len(pts))): |
| 337 | + progressbar = non_idle_tqdm |
| 338 | + if len(pts) < 5000: |
| 339 | + progressbar = no_tqdm |
| 340 | + for i in progressbar(range(len(pts))): |
308 | 341 | adjmat[i][i] = 1 # close enough
|
309 | 342 | for j in range(i+1, len(pts)):
|
310 | 343 | dx = pts[i][0] - pts[j][0]
|
|
0 commit comments