batoolset-gui 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. batoolset/GUI/__init__.py +0 -0
  2. batoolset/GUI/customdialog.py +136 -0
  3. batoolset/GUI/exception_handler.py +74 -0
  4. batoolset/GUI/list_gui.py +514 -0
  5. batoolset/GUI/multi_image_display.py +1038 -0
  6. batoolset/GUI/open.py +325 -0
  7. batoolset/GUI/overlay_hints.py +45 -0
  8. batoolset/GUI/paint2.py +1369 -0
  9. batoolset/GUI/scrollablepaint.py +1165 -0
  10. batoolset/dialogs/__init__.py +0 -0
  11. batoolset/dialogs/opensave.py +228 -0
  12. batoolset/drawings/__init__.py +0 -0
  13. batoolset/drawings/math_text.py +294 -0
  14. batoolset/drawings/pdf_svg_renderer.py +376 -0
  15. batoolset/drawings/shapes/Position.py +183 -0
  16. batoolset/drawings/shapes/__init__.py +0 -0
  17. batoolset/drawings/shapes/automated_alignment_drawing_refactored.py +346 -0
  18. batoolset/drawings/shapes/circle2d.py +99 -0
  19. batoolset/drawings/shapes/compute_optimal_size_all_merged.py +328 -0
  20. batoolset/drawings/shapes/ellipse2d.py +336 -0
  21. batoolset/drawings/shapes/freehand2d.py +235 -0
  22. batoolset/drawings/shapes/group.py +1985 -0
  23. batoolset/drawings/shapes/image2d.py +3157 -0
  24. batoolset/drawings/shapes/line2d.py +579 -0
  25. batoolset/drawings/shapes/point2d.py +257 -0
  26. batoolset/drawings/shapes/polygon2d.py +357 -0
  27. batoolset/drawings/shapes/polyline2d.py +235 -0
  28. batoolset/drawings/shapes/rect2d.py +388 -0
  29. batoolset/drawings/shapes/rectangle2d.py +601 -0
  30. batoolset/drawings/shapes/scalebar.py +310 -0
  31. batoolset/drawings/shapes/serializablefont.py +133 -0
  32. batoolset/drawings/shapes/serializableguiparams.py +14 -0
  33. batoolset/drawings/shapes/square2d.py +102 -0
  34. batoolset/drawings/shapes/test_publication_style.py +220 -0
  35. batoolset/drawings/shapes/textorientation.py +45 -0
  36. batoolset/drawings/shapes/tools.py +467 -0
  37. batoolset/drawings/shapes/transform2D.py +350 -0
  38. batoolset/drawings/shapes/txt2d.py +615 -0
  39. batoolset/drawings/svg_clip_renderer.py +247 -0
  40. batoolset/drawings/svg_embed.py +165 -0
  41. batoolset/drawings/svg_text_renderer.py +183 -0
  42. batoolset/drawings/widgets/__init__.py +0 -0
  43. batoolset/drawings/widgets/col.py +343 -0
  44. batoolset/drawings/widgets/image_group.py +248 -0
  45. batoolset/drawings/widgets/image_organizer.py +96 -0
  46. batoolset/drawings/widgets/paint.py +184 -0
  47. batoolset/drawings/widgets/vectorial.py +256 -0
  48. batoolset/figure/__init__.py +0 -0
  49. batoolset/figure/alignment.py +822 -0
  50. batoolset/figure/column.py +1117 -0
  51. batoolset/figure/fig_tools.py +285 -0
  52. batoolset/figure/minimal_debugger_scale_etc.py +139 -0
  53. batoolset/figure/panel.py +697 -0
  54. batoolset/figure/row.py +852 -0
  55. batoolset/figure/user_selection.py +287 -0
  56. batoolset/icons/__init__.py +0 -0
  57. batoolset/icons/tools.py +248 -0
  58. batoolset/luts/__init__.py +0 -0
  59. batoolset/luts/lut_minimal_test.py +1308 -0
  60. batoolset/luts/lutcreatorfromformula.py +209 -0
  61. batoolset/luts/luteditor.py +243 -0
  62. batoolset/pyqts/__init__.py +0 -0
  63. batoolset/pyqts/pleasewaitdialog.py +14 -0
  64. batoolset/pyqts/tools.py +760 -0
  65. batoolset/serializations/__init__.py +0 -0
  66. batoolset/serializations/tools.py +1338 -0
  67. batoolset/theme.py +647 -0
  68. batoolset/uis/__init__.py +0 -0
  69. batoolset/uis/blinker.py +56 -0
  70. batoolset_gui-0.2.0.dist-info/METADATA +54 -0
  71. batoolset_gui-0.2.0.dist-info/RECORD +74 -0
  72. batoolset_gui-0.2.0.dist-info/WHEEL +5 -0
  73. batoolset_gui-0.2.0.dist-info/licenses/LICENSE +24 -0
  74. batoolset_gui-0.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,822 @@
1
+ # align objects left right top or bottom
2
+ # maybe just need methods and not even a class
3
+ # logger
4
+ import os
5
+
6
+
7
+ from batoolset.settings.global_settings import set_UI # set the UI to qtpy
8
+ set_UI()
9
+ from deprecated import deprecated
10
+ from qtpy.QtCore import QRectF
11
+
12
+ from batoolset.drawings.shapes.point2d import Point2D
13
+ from batoolset.tools.logger import TA_logger
14
+ import numpy as np
15
+
16
+ logger = TA_logger()
17
+
18
+ # TODO replace all functions by that to avoid duplicated code
19
+
20
+ # def setToWidth(space, width_in_px, *objects):
21
+ # if width_in_px is None:
22
+ # return
23
+ # bounds = updateBoudingRect(*objects)
24
+ # left = Point2D(bounds.topLeft())
25
+ # incompressible_width = 0
26
+ # for img in objects:
27
+ # incompressible_width+=img.getIncompressibleWidth()
28
+ # # si row doit maintenir same height until reached desired width is reached --> change its width --> doit aussi connaitre la incompressible height des objects
29
+ # pure_image_width = (bounds.width()) - incompressible_width
30
+ # # print(width_in_px, self.getIncompressibleWidth(), (nb_cols - 1.) * self.space )
31
+ # width_in_px -= incompressible_width
32
+ # ratio = width_in_px / pure_image_width
33
+ # for img in objects:
34
+ # img.setToWidth(img.boundingRect().width() * ratio)
35
+ # packX(space, left, *objects)
36
+ # # self.updateBoudingRect()
37
+
38
+ # def setToHeight2(space, height_in_px, *objects):
39
+ # if height_in_px is None:
40
+ # return
41
+ # bounds = updateBoudingRect(*objects)
42
+ # left = Point2D(bounds.topLeft())
43
+ # incompressible_height = 0
44
+ # for img in objects:
45
+ # incompressible_height+=img.getIncompressibleHeight()
46
+ # # si row doit maintenir same height until reached desired width is reached --> change its width --> doit aussi connaitre la incompressible height des objects
47
+ # pure_image_height = (bounds.height()) - incompressible_height
48
+ # # print(width_in_px, self.getIncompressibleWidth(), (nb_cols - 1.) * self.space )
49
+ # height_in_px -= incompressible_height
50
+ # ratio = height_in_px / pure_image_height
51
+ # for img in objects:
52
+ # img.setToHeight(img.boundingRect().height() * ratio)
53
+ # packY(space, left, *objects)
54
+ # # self.updateBoudingRect()
55
+
56
+
57
+
58
+ #from timeit import default_timer as timer see why so slow --> see what part of computation is slow and remove it
59
+ def setToHeight(space, height_in_px, *objects):
60
+ if height_in_px is None:
61
+ return
62
+ bounds = updateBoudingRect(*objects)
63
+ left = Point2D(bounds.topLeft())
64
+ for img in objects:
65
+ img.setToHeight(height_in_px)
66
+ packX(space, left, *objects)
67
+ # self.updateBoudingRect()
68
+
69
+ def _brute_force_find_width(col1, min_h, max_h, increment, desired_height):
70
+ # to be faster --> find sign inversion and stop there and take closest
71
+ # stop on sign change in fact
72
+ closest = None
73
+ mn = 100000000
74
+ old_sign = None
75
+ break_soon = False
76
+
77
+
78
+ for width in np.arange(min_h, max_h, increment):
79
+ col1.setToWidth(width)
80
+ # print('bob', height, col1.width(), col1.height())
81
+ # in fact before that it becomes <0
82
+
83
+ if old_sign is not None:
84
+ if old_sign > 0 and col1.height() - desired_height < 0:
85
+ # print('changing sign --> stopping')
86
+ break_soon = True
87
+ elif old_sign < 0 and col1.height() - desired_height > 0:
88
+ # print('changing sign --> stopping')
89
+ break_soon = True
90
+
91
+ if old_sign is None:
92
+ if col1.height() - desired_height < 0:
93
+ old_sign = -1
94
+ else:
95
+ old_sign = 1
96
+ if (col1.height() - desired_height) <= mn and col1.height() - desired_height >= 0:
97
+ closest = (col1.width(), col1.height(), width)
98
+ mn = col1.height() - desired_height
99
+ if break_soon:
100
+ # print('stopping at ',height) # stopping at 41.14420004379321 min_h, max_h 40.14420004379321 43.19553376948639 # --> a vraiment stoppé vite en fait
101
+ break
102
+
103
+ # print('break_soon, closest, min_h, max_h, increment',break_soon, closest, min_h, max_h, increment)
104
+ return closest
105
+
106
+
107
+ def _brute_force_find_height(col1, min_h, max_h, increment, desired_width):
108
+ # to be faster --> find sign inversion and stop there and take closest
109
+ # stop on sign change in fact
110
+ closest = None
111
+ mn = 100000000
112
+ old_sign = None
113
+ break_soon = False
114
+ for height in np.arange(min_h, max_h, increment):
115
+ col1.setToHeight(height)
116
+ # print('bob', height, col1.width(), col1.height())
117
+ # in fact before that it becomes <0
118
+
119
+ if old_sign is not None:
120
+ if old_sign > 0 and col1.width() - desired_width < 0:
121
+ # print('changing sign --> stopping')
122
+ break_soon = True
123
+ elif old_sign < 0 and col1.width() - desired_width > 0:
124
+ # print('changing sign --> stopping')
125
+ break_soon = True
126
+
127
+ if old_sign is None:
128
+ if col1.width() - desired_width < 0:
129
+ old_sign = -1
130
+ else:
131
+ old_sign = 1
132
+ if (col1.width() - desired_width) <= mn and col1.width() - desired_width >= 0:
133
+ closest = (col1.width(), col1.height(), height)
134
+ mn = col1.width() - desired_width
135
+ if break_soon:
136
+ # print('stopping at ',height) # stopping at 41.14420004379321 min_h, max_h 40.14420004379321 43.19553376948639 # --> a vraiment stoppé vite en fait
137
+ break
138
+ return closest
139
+
140
+ def setToWidth2(space, width_in_px, *objects):
141
+ if width_in_px is None:
142
+ return
143
+ bounds = updateBoudingRect(*objects)
144
+ left = Point2D(bounds.topLeft())
145
+ for img in objects:
146
+ img.setToWidth(width_in_px)
147
+ packY(space, left, *objects)
148
+
149
+
150
+
151
+ def updateBoudingRect(*objects):
152
+
153
+ # print('objects',objects)
154
+
155
+ if not objects:
156
+ return
157
+ '''updates the image bounding rect depending on content'''
158
+ bounding_rect = QRectF()
159
+ x = None
160
+ y = None
161
+ x2 = None
162
+ y2 = None
163
+ for img in objects:
164
+ topLeft = img.topLeft()
165
+ if x is None:
166
+ x = topLeft.x()
167
+ if y is None:
168
+ y = topLeft.y()
169
+ x = min(topLeft.x(), x)
170
+ y = min(topLeft.y(), y)
171
+
172
+ # print(img, img.boundingRect(), type(img))
173
+ # print(img, img.boundingRect(), type(img), img.boundingRect().height())
174
+
175
+
176
+ if x2 is None:
177
+ try:
178
+ x2 = topLeft.x() + img.get_raw_size()[1]
179
+ except:
180
+ x2 = topLeft.x() + img.boundingRect().width()
181
+ if y2 is None:
182
+ try:
183
+ y2 = topLeft.y() + img.get_raw_size()[0]
184
+ except:
185
+ y2 = topLeft.y() + img.boundingRect().height()
186
+ x2 = max(topLeft.x() + img.boundingRect().width(), x2)
187
+ y2 = max(topLeft.y() + img.boundingRect().height(), y2)
188
+
189
+ # print('x, x2, y, y2',x, x2, y, y2)
190
+
191
+ bounding_rect.setX(x)
192
+ bounding_rect.setY(y)
193
+ bounding_rect.setWidth(x2 - x)
194
+ bounding_rect.setHeight(y2 - y)
195
+ return bounding_rect
196
+
197
+
198
+
199
+ packing_modes = ['X','Y', '-X', '-Y']
200
+
201
+ # def pack2(space=3, mode=packing_modes[0], *objects_to_pack): # a cleaned and better version of packX
202
+ # if objects_to_pack is None or len(objects_to_pack) <= 1:
203
+ # logger.warning("Nothing to align...")
204
+ # return
205
+ #
206
+ # reference = objects_to_pack[0]
207
+ #
208
+ # # factor = 1
209
+ # # if '-' in mode:
210
+ # # factor=-1
211
+ # # last = -last
212
+ #
213
+ # if mode == packing_modes[1]:
214
+ # last = reference.y()+reference.height(all=True) # NB I COULD REPLACE topLeft with .topleft
215
+ # else:
216
+ # last = reference.x() + reference.width(all=True)
217
+ #
218
+ # # print('last',last, space, reference.y(), reference.height(), reference.height(all=True))
219
+ #
220
+ # for img in objects_to_pack[1:]:
221
+ # # img = objects_to_pack[i]
222
+ #
223
+ # # print('cur obj', img, type(img))
224
+ # # if i != 0:
225
+ # last += space
226
+ # if mode == packing_modes[1]:
227
+ # img.setTopLeft(img.x(), last) # here again it could be replaced by setTopLeft
228
+ # last = img.y() + img.height(all=True)
229
+ # else:
230
+ # img.setTopLeft(last, img.y()) # here again it could be replaced by setTopLeft
231
+ # last = img.x() + img.width(all=True)
232
+
233
+ def pack2(space=3, mode=packing_modes[0], extra_border_mode=False, *objects_to_pack): # a cleaned and better version of packX
234
+ from batoolset.drawings.shapes.image2d import Image2D
235
+
236
+ # check position
237
+
238
+
239
+
240
+ # TODO --> allow positioning from
241
+
242
+ if objects_to_pack is None or len(objects_to_pack) <= 1:
243
+ # logger.warning("Nothing to align...")
244
+ return
245
+
246
+ if mode is None:
247
+ logger.warning("Unknown alignment mode")
248
+ return
249
+
250
+ reference = objects_to_pack[0]
251
+
252
+ # print('mode', mode)
253
+
254
+ if mode not in packing_modes:
255
+ if isinstance(mode, str):
256
+ # tolerate legacy quoted strings ('"X"') from old .pyf files
257
+ mode = mode.strip().strip('\'"')
258
+ if mode not in packing_modes:
259
+ try:
260
+ mode = mode.get_packing_orientation()
261
+ except AttributeError:
262
+ logger.warning('Unknown packing mode ' + repr(mode) + ' --> ignoring')
263
+ return
264
+
265
+ if mode is None:
266
+ # logger.warning("Unknown orientation --> ignoring")
267
+ # this is not a known orientation --> skip it
268
+ return
269
+
270
+
271
+ # print('updated position', mode)
272
+
273
+ # factor = 1
274
+ # if '-' in mode:
275
+ # factor=-1
276
+ # # last = -last
277
+
278
+ orientation = mode.replace('-','')
279
+
280
+ if orientation == packing_modes[1]:
281
+ last = reference.y()+reference.height(all=True) if not '-' in mode else 0 # NB I COULD REPLACE topLeft with .topleft
282
+ if extra_border_mode and isinstance(reference, Image2D):
283
+ extra = reference.get_extra_border_size()
284
+ if '-' in mode:
285
+ last-=extra
286
+ else:
287
+ last += extra
288
+ else:
289
+ # try:
290
+ last = reference.x() + reference.width(all=True) if not '-' in mode else 0
291
+ # except:
292
+ # pass
293
+ if extra_border_mode and isinstance(reference, Image2D):
294
+ extra = reference.get_extra_border_size()
295
+ if '-' in mode:
296
+ last-=extra
297
+ else:
298
+ last += extra
299
+
300
+ # print('last',last, space, reference.y(), reference.height(), reference.height(all=True))
301
+
302
+ previous_coords = reference.topLeft()
303
+ for img in objects_to_pack[1:]:
304
+ # img = objects_to_pack[i]
305
+
306
+ # print('cur obj', img, type(img))
307
+ # if i != 0:
308
+ last += space
309
+ if orientation == packing_modes[1]:
310
+ if not '-' in mode:
311
+ if extra_border_mode and isinstance(img, Image2D):
312
+ last+=img.get_extra_border_size()
313
+ img.setTopLeft(img.x(), last) # here again it could be replaced by setTopLeft
314
+ last = img.y() + img.height(all=True)
315
+ if extra_border_mode and isinstance(img, Image2D):
316
+ last+=img.get_extra_border_size()
317
+ else:
318
+ last = previous_coords.y() - img.height(all=True)
319
+ if extra_border_mode and isinstance(img, Image2D):
320
+ last-=img.get_extra_border_size()
321
+ img.setTopLeft(img.x(), last) # here again it could be replaced by setTopLeft
322
+ if extra_border_mode and isinstance(img, Image2D):
323
+ last-=img.get_extra_border_size()
324
+
325
+ else:
326
+ if not '-' in mode:
327
+ if extra_border_mode and isinstance(img, Image2D):
328
+ last-=img.get_extra_border_size()
329
+ img.setTopLeft(last, img.y()) # here again it could be replaced by setTopLeft
330
+ last = img.x() + img.width(all=True)
331
+ if extra_border_mode and isinstance(img, Image2D):
332
+ last+=img.get_extra_border_size()
333
+ else:
334
+ if extra_border_mode and isinstance(img, Image2D):
335
+ last-=img.get_extra_border_size()
336
+ last = previous_coords.x() - img.width(all=True)
337
+ if extra_border_mode and isinstance(img, Image2D):
338
+ last-=img.get_extra_border_size()
339
+ img.setTopLeft(last, img.y()) # here again it could be replaced by setTopLeft
340
+
341
+ previous_coords = img.topLeft()
342
+
343
+ # new version (cleaner or the packing code!!!)
344
+ @deprecated(reason="will switch to pack2 soon")
345
+ def pack(space=3, mode=packing_modes[0], *objects_to_pack): # a cleaned and better version of packX
346
+ if objects_to_pack is None or len(objects_to_pack) <= 1:
347
+ # logger.warning("Nothing to align...")
348
+ return
349
+
350
+ reference = objects_to_pack[0]
351
+
352
+ if mode == packing_modes[1]:
353
+ last = reference.y()+reference.height() # NB I COULD REPLACE topLeft with .topleft
354
+ else:
355
+ last = reference.x() + reference.width()
356
+
357
+ for img in objects_to_pack[1:]:
358
+ # img = objects_to_pack[i]
359
+ # if i != 0:
360
+ last += space
361
+ if mode == packing_modes[1]:
362
+ img.setTopLeft(img.x(), last) # here again it could be replaced by setTopLeft
363
+ last = img.y() + img.height()
364
+ else:
365
+ img.setTopLeft(last, img.y()) # here again it could be replaced by setTopLeft
366
+ last = img.x() + img.width()
367
+
368
+
369
+ @deprecated(reason="This method is deprecated and will be removed in the future. Please use 'pack' instead.")
370
+ def packX(space=3, reference=None, *objects_to_align_with_respect_to_ref):
371
+ skip_first = False
372
+ if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
373
+ # logger.warning("Nothing to align...")
374
+ return
375
+ if reference is None:
376
+ if len(objects_to_align_with_respect_to_ref) < 2:
377
+ logger.warning("Reference is None, can't align anything...")
378
+ return
379
+ else:
380
+ reference = objects_to_align_with_respect_to_ref[0]
381
+ skip_first = True
382
+ # del objects_to_align_with_respect_to_ref[0]
383
+
384
+ last_x = reference.topLeft().x()+reference.width() # NB I COULD REPLACE topLeft with .topleft
385
+ # last_y = reference.topLeft().y()
386
+
387
+ for i in range(len(objects_to_align_with_respect_to_ref)):
388
+ if i == 0 and skip_first:
389
+ continue
390
+ img = objects_to_align_with_respect_to_ref[i]
391
+ # print('begin', last_x)
392
+ if i != 0:
393
+ last_x += space
394
+
395
+
396
+ # print('before', last_x, img.boundingRect(), space)
397
+ img.setTopLeft(last_x, img.topLeft().y()) # here again it could be replaced by setTopLeft
398
+ # print(img.boundingRect(), last_x, img.topLeft().x())
399
+ last_x = img.boundingRect().x() + img.boundingRect().width()
400
+ # print('end', last_x)
401
+ # self.updateBoudingRect()
402
+
403
+ # align everything with respect to ref
404
+ # get first point and align so that the all have the same x
405
+
406
+ ORIENTATION_TOP_TO_BOTTOM = 0
407
+ ORIENTATION_BOTTOM_TO_TOP = 1
408
+
409
+ # need do a code for two orientations --> from top to bottom and reverse --> can be useful to do...
410
+
411
+ @deprecated(reason="This method is deprecated and will be removed in the future. Please use 'pack' instead.")
412
+ def packYreverse(space=3, reference=None, *objects_to_align_with_respect_to_ref):
413
+ skip_first = False
414
+ if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
415
+ # logger.warning("Nothing to align...")
416
+ return
417
+ if reference is None:
418
+ if len(objects_to_align_with_respect_to_ref) < 2:
419
+ logger.warning("Reference is None, can't align anything...")
420
+ return
421
+ else:
422
+ reference = objects_to_align_with_respect_to_ref[0]
423
+ skip_first = True
424
+ # del objects_to_align_with_respect_to_ref[0]
425
+
426
+ # last_x = reference.topLeft().x()
427
+ last_y = reference.topLeft().y()
428
+
429
+ for i in range(len(objects_to_align_with_respect_to_ref)):
430
+ if i==0 and skip_first:
431
+ continue
432
+ img = objects_to_align_with_respect_to_ref[i]
433
+ if i != 0:
434
+ last_y -= space
435
+ # last_y -= img.boundingRect().height()
436
+ # print(last_y, img.topLeft())
437
+ img.setTopLeft(img.topLeft().x(), last_y-img.boundingRect().height())
438
+ # get all the bounding boxes and pack them with desired space in between
439
+ # get first point and last point in x
440
+ x = img.boundingRect().x()
441
+ y = img.boundingRect().y()
442
+ # last_x = img.boundingRect().x() + img.boundingRect().width()
443
+ last_y = img.boundingRect().y()
444
+ # self.updateBoudingRect()
445
+
446
+
447
+ @deprecated(reason="This method is deprecated and will be removed in the future. Please use 'pack' instead.")
448
+ def packY(space=3, reference=None, *objects_to_align_with_respect_to_ref):
449
+ skip_first = False
450
+ if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
451
+ # logger.warning("Nothing to align...")
452
+ return
453
+ if reference is None:
454
+ if len(objects_to_align_with_respect_to_ref) < 2:
455
+ logger.warning("Reference is None, can't align anything...")
456
+ return
457
+ else:
458
+ reference = objects_to_align_with_respect_to_ref[0]
459
+ skip_first = True
460
+ # del objects_to_align_with_respect_to_ref[0]
461
+
462
+ # last_x = reference.topLeft().x()
463
+ last_y = reference.topLeft().y() + reference.height()
464
+
465
+ for i in range(len(objects_to_align_with_respect_to_ref)):
466
+ if i==0 and skip_first:
467
+ continue
468
+ img = objects_to_align_with_respect_to_ref[i]
469
+ if i != 0:
470
+ last_y += space
471
+ # print(last_y, img.topLeft())
472
+ img.setTopLeft(img.topLeft().x(), last_y)
473
+ # get all the bounding boxes and pack them with desired space in between
474
+ # get first point and last point in x
475
+ x = img.boundingRect().x()
476
+ y = img.boundingRect().y()
477
+ # last_x = img.boundingRect().x() + img.boundingRect().width()
478
+ last_y = img.boundingRect().y() + img.boundingRect().height()
479
+ # self.updateBoudingRect()
480
+
481
+
482
+ # align everything with respect to ref
483
+ # get first point and align so that the all have the same x
484
+
485
+ # align everything with respect to ref
486
+ # get first point and align so that the all have the same x
487
+
488
+ align_positions = ['Top', 'Bottom','Left', 'Right', 'CenterV', 'CenterH']
489
+
490
+ # I had to add scale to it to make it much better!!!
491
+ def align2(position=None,*objects_to_align_with_respect_to_ref):
492
+ if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) <=1:
493
+ # logger.warning("Nothing to align...")
494
+ return
495
+
496
+ reference = objects_to_align_with_respect_to_ref[0]
497
+ # TOD REPLACE BY A SWITCH --> somehow switch does not work with external variable --> maybe try still
498
+
499
+ if position == align_positions[0] or position is None:
500
+ last_y = reference.y()
501
+ elif position == align_positions[1]:
502
+ last_y = reference.y() + reference.height(all=True)
503
+ elif position == align_positions[2]:
504
+ last_x = reference.x()
505
+ elif position == align_positions[3]:
506
+ last_x = reference.x()+reference.width(all=True)
507
+ elif position == align_positions[4]:
508
+ last_y = reference.y() + reference.height(all=True) / 2. # should be the end point of every stuff
509
+ elif position == align_positions[5]:
510
+ last_x = reference.x() + reference.width(all=True) / 2.
511
+ else:
512
+ pass
513
+ for img in objects_to_align_with_respect_to_ref[1:]:
514
+ if position == align_positions[0] or position is None:
515
+ img.setTopLeft(img.x(), last_y)
516
+ elif position == align_positions[1]:
517
+ pos_y = img.y() + img.height(all=True)
518
+ difference_y = last_y - pos_y
519
+ img.setTopLeft(img.x(), img.y() + difference_y)
520
+ elif position == align_positions[2]:
521
+ img.setTopLeft(last_x, img.y())
522
+ elif position == align_positions[3]:
523
+ pos_x = img.x() + img.width(all=True)
524
+ difference_x = last_x - pos_x
525
+ img.setTopLeft(img.x() + difference_x, img.y())
526
+ elif position == align_positions[4]:
527
+ pos_y = img.y() + img.height(all=True) / 2.
528
+ difference_y = last_y - pos_y
529
+ img.setTopLeft(img.x(), img.y() + difference_y)
530
+ elif position == align_positions[5]:
531
+ pos_x = img.x() + img.width(all=True) / 2.
532
+ difference_x = last_x - pos_x
533
+ img.setTopLeft(img.x() + difference_x, img.y())
534
+ else:
535
+ print('error trying to align there')
536
+ pass
537
+
538
+
539
+ # this is the new version of the align code that is not duplicated and so much better
540
+ @deprecated(reason='will soon switch to align2')
541
+ def align(position=None,*objects_to_align_with_respect_to_ref):
542
+ if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) <=1:
543
+ # logger.warning("Nothing to align...")
544
+ return
545
+
546
+ reference = objects_to_align_with_respect_to_ref[0]
547
+ # TOD REPLACE BY A SWITCH --> somehow switch does not work with external variable --> maybe try still
548
+
549
+ if position == align_positions[0] or position is None:
550
+ last_y = reference.y()
551
+ elif position == align_positions[1]:
552
+ last_y = reference.y() + reference.height()
553
+ elif position == align_positions[2]:
554
+ last_x = reference.x()
555
+ elif position == align_positions[3]:
556
+ last_x = reference.x()+reference.width()
557
+ elif position == align_positions[4]:
558
+ last_y = reference.y() + reference.height() / 2. # should be the end point of every stuff
559
+ elif position == align_positions[5]:
560
+ last_x = reference.x() + reference.width() / 2.
561
+ else:
562
+ pass
563
+ for img in objects_to_align_with_respect_to_ref[1:]:
564
+ if position == align_positions[0] or position is None:
565
+ img.setTopLeft(img.x(), last_y)
566
+ elif position == align_positions[1]:
567
+ pos_y = img.y() + img.height()
568
+ difference_y = last_y - pos_y
569
+ img.setTopLeft(img.x(), img.y() + difference_y)
570
+ elif position == align_positions[2]:
571
+ img.setTopLeft(last_x, img.y())
572
+ elif position == align_positions[3]:
573
+ pos_x = img.x() + img.width()
574
+ difference_x = last_x - pos_x
575
+ img.setTopLeft(img.x() + difference_x, img.y())
576
+ elif position == align_positions[4]:
577
+ pos_y = img.y() + img.height() / 2.
578
+ difference_y = last_y - pos_y
579
+ img.setTopLeft(img.x(), img.y() + difference_y)
580
+ elif position == align_positions[5]:
581
+ pos_x = img.x() + img.width() / 2.
582
+ difference_x = last_x - pos_x
583
+ img.setTopLeft(img.x() + difference_x, img.y())
584
+ else:
585
+ pass
586
+
587
+ # match position:
588
+ # case align_positions[0]:
589
+ # pass
590
+ # case align_positions[1]:
591
+ # pass
592
+ # case pattern-3:
593
+ # pass
594
+ # case _:
595
+ # pass
596
+
597
+
598
+
599
+
600
+ @deprecated(reason="This method is deprecated and will be removed in the future. Please use 'align' instead.")
601
+ def alignLeft(reference=None, *objects_to_align_with_respect_to_ref):
602
+ skip_first = False
603
+ if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
604
+ # logger.warning("Nothing to align...")
605
+ return
606
+ if reference is None:
607
+ if len(objects_to_align_with_respect_to_ref) < 2:
608
+ logger.warning("Reference is None, can't align anything...")
609
+ return
610
+ else:
611
+ reference = objects_to_align_with_respect_to_ref[0]
612
+ skip_first = True
613
+ # del objects_to_align_with_respect_to_ref[0]
614
+
615
+ last_x = reference.topLeft().x()
616
+ # last_y = reference.topLeft().y()
617
+
618
+ for i in range(len(objects_to_align_with_respect_to_ref)):
619
+ if i==0 and skip_first:
620
+ continue
621
+ img = objects_to_align_with_respect_to_ref[i]
622
+
623
+ img.setTopLeft(last_x, img.topLeft().y())
624
+ # get all the bounding boxes and pack them with desired space in between
625
+ # get first point and last point in x
626
+ # x = img.boundingRect().x()
627
+ # y = img.boundingRect().y()
628
+ # last_x = img.boundingRect().x() + img.boundingRect().width()
629
+ # last_y = img.boundingRect().y() + img.boundingRect().height()
630
+ # self.updateBoudingRect()
631
+
632
+
633
+ @deprecated(reason="This method is deprecated and will be removed in the future. Please use 'align' instead.")
634
+ def alignTop(reference=None, *objects_to_align_with_respect_to_ref):
635
+ skip_first = False
636
+ if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
637
+ # logger.warning("Nothing to align...")
638
+ return
639
+ if reference is None:
640
+ if len(objects_to_align_with_respect_to_ref) < 2:
641
+ logger.warning("Reference is None, can't align anything...")
642
+ return
643
+ else:
644
+ reference = objects_to_align_with_respect_to_ref[0]
645
+ skip_first = True
646
+ # del objects_to_align_with_respect_to_ref[0]
647
+
648
+ # last_x = reference.topLeft().x()
649
+ last_y = reference.topLeft().y()
650
+
651
+ for i in range(len(objects_to_align_with_respect_to_ref)):
652
+ if i==0 and skip_first:
653
+ continue
654
+ img = objects_to_align_with_respect_to_ref[i]
655
+
656
+ img.setTopLeft(img.topLeft().x(), last_y)
657
+ # get all the bounding boxes and pack them with desired space in between
658
+ # get first point and last point in x
659
+ # x = img.boundingRect().x()
660
+ # y = img.boundingRect().y()
661
+ # last_x = img.boundingRect().x() + img.boundingRect().width()
662
+ # last_y = img.boundingRect().y() + img.boundingRect().height()
663
+ # self.updateBoudingRect()
664
+
665
+
666
+ # align everything with respect to ref
667
+ # get first point and align so that the all have the same x
668
+
669
+
670
+ @deprecated(reason="This method is deprecated and will be removed in the future. Please use 'align' instead.")
671
+ def alignBottom(reference=None, *objects_to_align_with_respect_to_ref):
672
+ skip_first = False
673
+ if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
674
+ # logger.warning("Nothing to align...")
675
+ return
676
+ if reference is None:
677
+ if len(objects_to_align_with_respect_to_ref) < 2:
678
+ logger.warning("Reference is None, can't align anything...")
679
+ return
680
+ else:
681
+ reference = objects_to_align_with_respect_to_ref[0]
682
+ skip_first = True
683
+ # del objects_to_align_with_respect_to_ref[0]
684
+
685
+ # last_x = reference.topLeft().x()
686
+ last_y = reference.topLeft().y()+reference.height() # should be the end point of every stuff
687
+
688
+ for i in range(len(objects_to_align_with_respect_to_ref)):
689
+ if i==0 and skip_first:
690
+ continue
691
+ img = objects_to_align_with_respect_to_ref[i]
692
+
693
+
694
+ pos_y = img.topLeft().y()+img.height()
695
+ difference_y = last_y-pos_y
696
+ img.setTopLeft(img.topLeft().x(), img.topLeft().y()+difference_y)
697
+ # get all the bounding boxes and pack them with desired space in between
698
+ # get first point and last point in x
699
+ # x = img.boundingRect().x()
700
+ # y = img.boundingRect().y()
701
+ # last_x = img.boundingRect().x() + img.boundingRect().width()
702
+ # last_y = img.boundingRect().y() + img.boundingRect().height()
703
+ # self.updateBoudingRect()
704
+
705
+
706
+ # align everything with respect to ref
707
+ # get first point and align so that the all have the same x
708
+
709
+
710
+ @deprecated(reason="This method is deprecated and will be removed in the future. Please use 'align' instead.")
711
+ # bug here now with the images
712
+ def alignRight(reference=None, *objects_to_align_with_respect_to_ref):
713
+ skip_first = False
714
+ if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
715
+ # logger.warning("Nothing to align...")
716
+ return
717
+ if reference is None:
718
+ if len(objects_to_align_with_respect_to_ref) < 2:
719
+ logger.warning("Reference is None, can't align anything...")
720
+ return
721
+ else:
722
+ reference = objects_to_align_with_respect_to_ref[0]
723
+ skip_first = True
724
+ # del objects_to_align_with_respect_to_ref[0]
725
+
726
+ last_x = reference.topLeft().x()+reference.width() # should be the end point of every stuff
727
+ # last_y = reference.topLeft().y()+reference.height() # should be the end point of every stuff
728
+
729
+ for i in range(len(objects_to_align_with_respect_to_ref)):
730
+ if i==0 and skip_first:
731
+ continue
732
+ img = objects_to_align_with_respect_to_ref[i]
733
+
734
+ pos_x = img.topLeft().x()+img.width()
735
+ difference_x = last_x-pos_x
736
+ img.setTopLeft(img.topLeft().x()+difference_x, img.topLeft().y())
737
+ # get all the bounding boxes and pack them with desired space in between
738
+ # get first point and last point in x
739
+ # x = img.boundingRect().x()
740
+ # y = img.boundingRect().y()
741
+ # last_x = img.boundingRect().x() + img.boundingRect().width()
742
+ # last_y = img.boundingRect().y() + img.boundingRect().height()
743
+ # self.updateBoudingRect()
744
+
745
+
746
+ # align everything with respect to ref
747
+ # get first point and align so that the all have the same x
748
+
749
+
750
+ @deprecated(reason="This method is deprecated and will be removed in the future. Please use 'align' instead.")
751
+ def alignCenterH(reference=None, *objects_to_align_with_respect_to_ref):
752
+ skip_first = False
753
+ if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
754
+ # logger.warning("Nothing to align...")
755
+ return
756
+ if reference is None:
757
+ if len(objects_to_align_with_respect_to_ref) < 2:
758
+ logger.warning("Reference is None, can't align anything...")
759
+ return
760
+ else:
761
+ reference = objects_to_align_with_respect_to_ref[0]
762
+ skip_first = True
763
+ # del objects_to_align_with_respect_to_ref[0]
764
+
765
+ # last_x = reference.topLeft().x()+reference.width()/2. # should be the end point of every stuff
766
+ last_x = reference.topLeft().x()+reference.width()/2. # should be the end point of every stuff
767
+ # last_y = reference.topLeft().y()+reference.height() # should be the end point of every stuff
768
+
769
+ for i in range(len(objects_to_align_with_respect_to_ref)):
770
+ if i==0 and skip_first:
771
+ continue
772
+ img = objects_to_align_with_respect_to_ref[i]
773
+
774
+ pos_x = img.topLeft().x()+img.width()/2.
775
+ difference_x = last_x-pos_x
776
+ img.setTopLeft(img.topLeft().x()+difference_x, img.topLeft().y())
777
+ # get all the bounding boxes and pack them with desired space in between
778
+ # get first point and last point in x
779
+ # x = img.boundingRect().x()
780
+ # y = img.boundingRect().y()
781
+ # last_x = img.boundingRect().x() + img.boundingRect().width()
782
+ # last_y = img.boundingRect().y() + img.boundingRect().height()
783
+ # self.updateBoudingRect()
784
+
785
+
786
+ # align everything with respect to ref
787
+ # get first point and align so that the all have the same x
788
+
789
+ @deprecated(reason="This method is deprecated and will be removed in the future. Please use 'align' instead.")
790
+ def alignCenterV(reference=None, *objects_to_align_with_respect_to_ref):
791
+ skip_first = False
792
+ if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
793
+ # logger.warning("Nothing to align...")
794
+ return
795
+ if reference is None:
796
+ if len(objects_to_align_with_respect_to_ref) < 2:
797
+ logger.warning("Reference is None, can't align anything...")
798
+ return
799
+ else:
800
+ reference = objects_to_align_with_respect_to_ref[0]
801
+ skip_first = True
802
+ # del objects_to_align_with_respect_to_ref[0]
803
+
804
+ # last_x = reference.topLeft().x()
805
+ last_y = reference.topLeft().y()+reference.height()/2. # should be the end point of every stuff
806
+
807
+ for i in range(len(objects_to_align_with_respect_to_ref)):
808
+ if i==0 and skip_first:
809
+ continue
810
+ img = objects_to_align_with_respect_to_ref[i]
811
+
812
+
813
+ pos_y = img.topLeft().y()+img.height()/2.
814
+ difference_y = last_y-pos_y
815
+ img.setTopLeft(img.topLeft().x(), img.topLeft().y()+difference_y)
816
+ # get all the bounding boxes and pack them with desired space in between
817
+ # get first point and last point in x
818
+ # x = img.boundingRect().x()
819
+ # y = img.boundingRect().y()
820
+ # last_x = img.boundingRect().x() + img.boundingRect().width()
821
+ # last_y = img.boundingRect().y() + img.boundingRect().height()
822
+ # self.updateBoudingRect()