batoolset 0.1.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.
- batoolset/GUI/__init__.py +0 -0
- batoolset/GUI/list_gui.py +513 -0
- batoolset/GUI/multi_image_display.py +989 -0
- batoolset/GUI/open.py +325 -0
- batoolset/GUI/overlay_hints.py +45 -0
- batoolset/GUI/paint2.py +1345 -0
- batoolset/GUI/scrollablepaint.py +1152 -0
- batoolset/IJ_ROIs/__init__.py +0 -0
- batoolset/IJ_ROIs/tools.py +40 -0
- batoolset/PATH/__init__.py +0 -0
- batoolset/PATH/tools.py +79 -0
- batoolset/SQLite_tools/__init__.py +0 -0
- batoolset/SQLite_tools/tools.py +840 -0
- batoolset/__init__.py +0 -0
- batoolset/binary/__init__.py +0 -0
- batoolset/binary/tools.py +123 -0
- batoolset/binarytools/__init__.py +0 -0
- batoolset/binarytools/cell_center_detector.py +290 -0
- batoolset/clipboard_tools/__init__.py +0 -0
- batoolset/clipboard_tools/tools.py +7 -0
- batoolset/colors/__init__.py +0 -0
- batoolset/colors/colorgen.py +193 -0
- batoolset/colors/tools.py +22 -0
- batoolset/command_line/__init__.py +0 -0
- batoolset/command_line/tools.py +18 -0
- batoolset/dialogs/__init__.py +0 -0
- batoolset/dialogs/opensave.py +228 -0
- batoolset/dicts/__init__.py +0 -0
- batoolset/dicts/tools.py +299 -0
- batoolset/dims/__init__.py +0 -0
- batoolset/dims/tools.py +83 -0
- batoolset/draw/__init__.py +0 -0
- batoolset/draw/shapes/Position.py +183 -0
- batoolset/draw/shapes/__init__.py +0 -0
- batoolset/draw/shapes/automated_alignment_drawing_refactored.py +346 -0
- batoolset/draw/shapes/circle2d.py +99 -0
- batoolset/draw/shapes/compute_optimal_size_all_merged.py +317 -0
- batoolset/draw/shapes/ellipse2d.py +336 -0
- batoolset/draw/shapes/freehand2d.py +235 -0
- batoolset/draw/shapes/group.py +1830 -0
- batoolset/draw/shapes/image2d.py +2469 -0
- batoolset/draw/shapes/line2d.py +575 -0
- batoolset/draw/shapes/point2d.py +257 -0
- batoolset/draw/shapes/polygon2d.py +357 -0
- batoolset/draw/shapes/polyline2d.py +235 -0
- batoolset/draw/shapes/rect2d.py +388 -0
- batoolset/draw/shapes/rectangle2d.py +601 -0
- batoolset/draw/shapes/scalebar.py +304 -0
- batoolset/draw/shapes/serializablefont.py +126 -0
- batoolset/draw/shapes/serializableguiparams.py +10 -0
- batoolset/draw/shapes/square2d.py +103 -0
- batoolset/draw/shapes/textorientation.py +45 -0
- batoolset/draw/shapes/tools.py +467 -0
- batoolset/draw/shapes/transform2D.py +350 -0
- batoolset/draw/shapes/txt2d.py +550 -0
- batoolset/draw/widgets/__init__.py +0 -0
- batoolset/draw/widgets/col.py +343 -0
- batoolset/draw/widgets/image_group.py +248 -0
- batoolset/draw/widgets/image_organizer.py +96 -0
- batoolset/draw/widgets/paint.py +184 -0
- batoolset/draw/widgets/vectorial.py +257 -0
- batoolset/figure/__init__.py +0 -0
- batoolset/figure/alignment.py +814 -0
- batoolset/figure/column.py +1117 -0
- batoolset/figure/fig_tools.py +285 -0
- batoolset/figure/minimal_debugger_scale_etc.py +139 -0
- batoolset/figure/panel.py +697 -0
- batoolset/figure/row.py +852 -0
- batoolset/figure/user_selection.py +287 -0
- batoolset/files/__init__.py +0 -0
- batoolset/files/tools.py +1321 -0
- batoolset/images/__init__.py +0 -0
- batoolset/images/tools.py +81 -0
- batoolset/img.py +5216 -0
- batoolset/linux/__init__.py +0 -0
- batoolset/linux/tools.py +72 -0
- batoolset/lists/__init__.py +0 -0
- batoolset/lists/tools.py +436 -0
- batoolset/luts/__init__.py +0 -0
- batoolset/luts/lut_minimal_test.py +1207 -0
- batoolset/matplolib/__init__.py +0 -0
- batoolset/matplolib/tools.py +44 -0
- batoolset/np_tools/__init__.py +0 -0
- batoolset/np_tools/tools.py +252 -0
- batoolset/np_tools/trash.py +15 -0
- batoolset/pandas_tools/__init__.py +0 -0
- batoolset/pandas_tools/tools.py +880 -0
- batoolset/partials/__init__.py +0 -0
- batoolset/partials/tools.py +83 -0
- batoolset/plot_tools/__init__.py +0 -0
- batoolset/plot_tools/tools.py +70 -0
- batoolset/pyqt/__init__.py +0 -0
- batoolset/pyqt/tools.py +691 -0
- batoolset/re_tools/__init__.py +0 -0
- batoolset/re_tools/tools.py +35 -0
- batoolset/serialization/__init__.py +0 -0
- batoolset/serialization/tools.py +1192 -0
- batoolset/sets/__init__.py +0 -0
- batoolset/sets/tools.py +109 -0
- batoolset/settings/__init__.py +0 -0
- batoolset/settings/global_settings.py +134 -0
- batoolset/strings/__init__.py +0 -0
- batoolset/strings/tools.py +225 -0
- batoolset/ta/__init__.py +0 -0
- batoolset/ta/database/__init__.py +0 -0
- batoolset/ta/database/advanced_sql_plotter.py +1170 -0
- batoolset/ta/database/my_qt_table.py +79 -0
- batoolset/ta/database/preview_and_edit_sqlite_db.py +405 -0
- batoolset/ta/database/sql.py +2141 -0
- batoolset/ta/database/sql_column_name_dialog.py +122 -0
- batoolset/ta/measurements/TAmeasures.py +2226 -0
- batoolset/ta/measurements/__init__.py +0 -0
- batoolset/ta/measurements/measurements3D/__init__.py +0 -0
- batoolset/ta/measurements/measurements3D/get_point_on_surface_if_centroid_is_bad.py +175 -0
- batoolset/ta/measurements/measurements3D/height_map_to_projection.py +82 -0
- batoolset/ta/measurements/measurements3D/measures3D.py +208 -0
- batoolset/ta/measurements/measurements3D/triangulate.py +331 -0
- batoolset/ta/measurements/nematic.py +562 -0
- batoolset/ta/measurements/nematic_measurements.py +107 -0
- batoolset/ta/segmentation/__init__.py +0 -0
- batoolset/ta/segmentation/neo_wshed.py +314 -0
- batoolset/ta/selections/__init__.py +0 -0
- batoolset/ta/selections/selection.py +329 -0
- batoolset/ta/tracking/__init__.py +0 -0
- batoolset/ta/tracking/last_tracking_based_on_matching_or_on_translation_from_mermaid_warp.py +653 -0
- batoolset/ta/tracking/local_to_track_correspondance.py +138 -0
- batoolset/ta/tracking/rapid_detection_of_vertices.py +517 -0
- batoolset/ta/tracking/registration.py +108 -0
- batoolset/ta/tracking/swap_detector_and_fixer.py +296 -0
- batoolset/ta/tracking/track_correction.py +238 -0
- batoolset/ta/tracking/tracking_error_detector_and_fixer.py +3099 -0
- batoolset/ta/tracking/tracking_yet_another_approach_pyramidal_registration_n_neo_swapping_correction.py +725 -0
- batoolset/ta/utils/TA_tools.py +43 -0
- batoolset/ta/utils/__init__.py +0 -0
- batoolset/ta/utils/rps_tools.py +1783 -0
- batoolset/tests/__init__.py +0 -0
- batoolset/tests/rps_tools.py +51 -0
- batoolset/tests/tools.py +10 -0
- batoolset/tools/__init__.py +0 -0
- batoolset/tools/early_stopper_class.py +9 -0
- batoolset/tools/guided_data_recoverer.py +110 -0
- batoolset/tools/logger.py +100 -0
- batoolset/tools/mytimer.py +31 -0
- batoolset/tools/prompt_color.py +160 -0
- batoolset/tools/qthandler.py +118 -0
- batoolset/uitools/__init__.py +0 -0
- batoolset/uitools/blinker.py +56 -0
- batoolset/unsafe/__init__.py +0 -0
- batoolset/unsafe/tools.py +115 -0
- batoolset/utils/__init__.py +0 -0
- batoolset/utils/commontools.py +158 -0
- batoolset/utils/loadlist.py +728 -0
- batoolset/version.py +10 -0
- batoolset/xml/__init__.py +0 -0
- batoolset/xml/tools.py +65 -0
- batoolset/zip_tools/__init__.py +0 -0
- batoolset/zip_tools/tools.py +76 -0
- batoolset-0.1.0.dist-info/LICENSE +24 -0
- batoolset-0.1.0.dist-info/METADATA +45 -0
- batoolset-0.1.0.dist-info/RECORD +162 -0
- batoolset-0.1.0.dist-info/WHEEL +5 -0
- batoolset-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,814 @@
|
|
|
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.draw.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.draw.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
|
+
mode = mode.get_packing_orientation()
|
|
256
|
+
|
|
257
|
+
if mode is None:
|
|
258
|
+
# logger.warning("Unknown orientation --> ignoring")
|
|
259
|
+
# this is not a known orientation --> skip it
|
|
260
|
+
return
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
# print('updated position', mode)
|
|
264
|
+
|
|
265
|
+
# factor = 1
|
|
266
|
+
# if '-' in mode:
|
|
267
|
+
# factor=-1
|
|
268
|
+
# # last = -last
|
|
269
|
+
|
|
270
|
+
orientation = mode.replace('-','')
|
|
271
|
+
|
|
272
|
+
if orientation == packing_modes[1]:
|
|
273
|
+
last = reference.y()+reference.height(all=True) if not '-' in mode else 0 # NB I COULD REPLACE topLeft with .topleft
|
|
274
|
+
if extra_border_mode and isinstance(reference, Image2D):
|
|
275
|
+
extra = reference.get_extra_border_size()
|
|
276
|
+
if '-' in mode:
|
|
277
|
+
last-=extra
|
|
278
|
+
else:
|
|
279
|
+
last += extra
|
|
280
|
+
else:
|
|
281
|
+
# try:
|
|
282
|
+
last = reference.x() + reference.width(all=True) if not '-' in mode else 0
|
|
283
|
+
# except:
|
|
284
|
+
# pass
|
|
285
|
+
if extra_border_mode and isinstance(reference, Image2D):
|
|
286
|
+
extra = reference.get_extra_border_size()
|
|
287
|
+
if '-' in mode:
|
|
288
|
+
last-=extra
|
|
289
|
+
else:
|
|
290
|
+
last += extra
|
|
291
|
+
|
|
292
|
+
# print('last',last, space, reference.y(), reference.height(), reference.height(all=True))
|
|
293
|
+
|
|
294
|
+
previous_coords = reference.topLeft()
|
|
295
|
+
for img in objects_to_pack[1:]:
|
|
296
|
+
# img = objects_to_pack[i]
|
|
297
|
+
|
|
298
|
+
# print('cur obj', img, type(img))
|
|
299
|
+
# if i != 0:
|
|
300
|
+
last += space
|
|
301
|
+
if orientation == packing_modes[1]:
|
|
302
|
+
if not '-' in mode:
|
|
303
|
+
if extra_border_mode and isinstance(img, Image2D):
|
|
304
|
+
last+=img.get_extra_border_size()
|
|
305
|
+
img.setTopLeft(img.x(), last) # here again it could be replaced by setTopLeft
|
|
306
|
+
last = img.y() + img.height(all=True)
|
|
307
|
+
if extra_border_mode and isinstance(img, Image2D):
|
|
308
|
+
last+=img.get_extra_border_size()
|
|
309
|
+
else:
|
|
310
|
+
last = previous_coords.y() - img.height(all=True)
|
|
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
|
+
if extra_border_mode and isinstance(img, Image2D):
|
|
315
|
+
last-=img.get_extra_border_size()
|
|
316
|
+
|
|
317
|
+
else:
|
|
318
|
+
if not '-' in mode:
|
|
319
|
+
if extra_border_mode and isinstance(img, Image2D):
|
|
320
|
+
last-=img.get_extra_border_size()
|
|
321
|
+
img.setTopLeft(last, img.y()) # here again it could be replaced by setTopLeft
|
|
322
|
+
last = img.x() + img.width(all=True)
|
|
323
|
+
if extra_border_mode and isinstance(img, Image2D):
|
|
324
|
+
last+=img.get_extra_border_size()
|
|
325
|
+
else:
|
|
326
|
+
if extra_border_mode and isinstance(img, Image2D):
|
|
327
|
+
last-=img.get_extra_border_size()
|
|
328
|
+
last = previous_coords.x() - img.width(all=True)
|
|
329
|
+
if extra_border_mode and isinstance(img, Image2D):
|
|
330
|
+
last-=img.get_extra_border_size()
|
|
331
|
+
img.setTopLeft(last, img.y()) # here again it could be replaced by setTopLeft
|
|
332
|
+
|
|
333
|
+
previous_coords = img.topLeft()
|
|
334
|
+
|
|
335
|
+
# new version (cleaner or the packing code!!!)
|
|
336
|
+
@deprecated(reason="will switch to pack2 soon")
|
|
337
|
+
def pack(space=3, mode=packing_modes[0], *objects_to_pack): # a cleaned and better version of packX
|
|
338
|
+
if objects_to_pack is None or len(objects_to_pack) <= 1:
|
|
339
|
+
# logger.warning("Nothing to align...")
|
|
340
|
+
return
|
|
341
|
+
|
|
342
|
+
reference = objects_to_pack[0]
|
|
343
|
+
|
|
344
|
+
if mode == packing_modes[1]:
|
|
345
|
+
last = reference.y()+reference.height() # NB I COULD REPLACE topLeft with .topleft
|
|
346
|
+
else:
|
|
347
|
+
last = reference.x() + reference.width()
|
|
348
|
+
|
|
349
|
+
for img in objects_to_pack[1:]:
|
|
350
|
+
# img = objects_to_pack[i]
|
|
351
|
+
# if i != 0:
|
|
352
|
+
last += space
|
|
353
|
+
if mode == packing_modes[1]:
|
|
354
|
+
img.setTopLeft(img.x(), last) # here again it could be replaced by setTopLeft
|
|
355
|
+
last = img.y() + img.height()
|
|
356
|
+
else:
|
|
357
|
+
img.setTopLeft(last, img.y()) # here again it could be replaced by setTopLeft
|
|
358
|
+
last = img.x() + img.width()
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
@deprecated(reason="This method is deprecated and will be removed in the future. Please use 'pack' instead.")
|
|
362
|
+
def packX(space=3, reference=None, *objects_to_align_with_respect_to_ref):
|
|
363
|
+
skip_first = False
|
|
364
|
+
if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
|
|
365
|
+
# logger.warning("Nothing to align...")
|
|
366
|
+
return
|
|
367
|
+
if reference is None:
|
|
368
|
+
if len(objects_to_align_with_respect_to_ref) < 2:
|
|
369
|
+
logger.warning("Reference is None, can't align anything...")
|
|
370
|
+
return
|
|
371
|
+
else:
|
|
372
|
+
reference = objects_to_align_with_respect_to_ref[0]
|
|
373
|
+
skip_first = True
|
|
374
|
+
# del objects_to_align_with_respect_to_ref[0]
|
|
375
|
+
|
|
376
|
+
last_x = reference.topLeft().x()+reference.width() # NB I COULD REPLACE topLeft with .topleft
|
|
377
|
+
# last_y = reference.topLeft().y()
|
|
378
|
+
|
|
379
|
+
for i in range(len(objects_to_align_with_respect_to_ref)):
|
|
380
|
+
if i == 0 and skip_first:
|
|
381
|
+
continue
|
|
382
|
+
img = objects_to_align_with_respect_to_ref[i]
|
|
383
|
+
# print('begin', last_x)
|
|
384
|
+
if i != 0:
|
|
385
|
+
last_x += space
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
# print('before', last_x, img.boundingRect(), space)
|
|
389
|
+
img.setTopLeft(last_x, img.topLeft().y()) # here again it could be replaced by setTopLeft
|
|
390
|
+
# print(img.boundingRect(), last_x, img.topLeft().x())
|
|
391
|
+
last_x = img.boundingRect().x() + img.boundingRect().width()
|
|
392
|
+
# print('end', last_x)
|
|
393
|
+
# self.updateBoudingRect()
|
|
394
|
+
|
|
395
|
+
# align everything with respect to ref
|
|
396
|
+
# get first point and align so that the all have the same x
|
|
397
|
+
|
|
398
|
+
ORIENTATION_TOP_TO_BOTTOM = 0
|
|
399
|
+
ORIENTATION_BOTTOM_TO_TOP = 1
|
|
400
|
+
|
|
401
|
+
# need do a code for two orientations --> from top to bottom and reverse --> can be useful to do...
|
|
402
|
+
|
|
403
|
+
@deprecated(reason="This method is deprecated and will be removed in the future. Please use 'pack' instead.")
|
|
404
|
+
def packYreverse(space=3, reference=None, *objects_to_align_with_respect_to_ref):
|
|
405
|
+
skip_first = False
|
|
406
|
+
if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
|
|
407
|
+
# logger.warning("Nothing to align...")
|
|
408
|
+
return
|
|
409
|
+
if reference is None:
|
|
410
|
+
if len(objects_to_align_with_respect_to_ref) < 2:
|
|
411
|
+
logger.warning("Reference is None, can't align anything...")
|
|
412
|
+
return
|
|
413
|
+
else:
|
|
414
|
+
reference = objects_to_align_with_respect_to_ref[0]
|
|
415
|
+
skip_first = True
|
|
416
|
+
# del objects_to_align_with_respect_to_ref[0]
|
|
417
|
+
|
|
418
|
+
# last_x = reference.topLeft().x()
|
|
419
|
+
last_y = reference.topLeft().y()
|
|
420
|
+
|
|
421
|
+
for i in range(len(objects_to_align_with_respect_to_ref)):
|
|
422
|
+
if i==0 and skip_first:
|
|
423
|
+
continue
|
|
424
|
+
img = objects_to_align_with_respect_to_ref[i]
|
|
425
|
+
if i != 0:
|
|
426
|
+
last_y -= space
|
|
427
|
+
# last_y -= img.boundingRect().height()
|
|
428
|
+
# print(last_y, img.topLeft())
|
|
429
|
+
img.setTopLeft(img.topLeft().x(), last_y-img.boundingRect().height())
|
|
430
|
+
# get all the bounding boxes and pack them with desired space in between
|
|
431
|
+
# get first point and last point in x
|
|
432
|
+
x = img.boundingRect().x()
|
|
433
|
+
y = img.boundingRect().y()
|
|
434
|
+
# last_x = img.boundingRect().x() + img.boundingRect().width()
|
|
435
|
+
last_y = img.boundingRect().y()
|
|
436
|
+
# self.updateBoudingRect()
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
@deprecated(reason="This method is deprecated and will be removed in the future. Please use 'pack' instead.")
|
|
440
|
+
def packY(space=3, reference=None, *objects_to_align_with_respect_to_ref):
|
|
441
|
+
skip_first = False
|
|
442
|
+
if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
|
|
443
|
+
# logger.warning("Nothing to align...")
|
|
444
|
+
return
|
|
445
|
+
if reference is None:
|
|
446
|
+
if len(objects_to_align_with_respect_to_ref) < 2:
|
|
447
|
+
logger.warning("Reference is None, can't align anything...")
|
|
448
|
+
return
|
|
449
|
+
else:
|
|
450
|
+
reference = objects_to_align_with_respect_to_ref[0]
|
|
451
|
+
skip_first = True
|
|
452
|
+
# del objects_to_align_with_respect_to_ref[0]
|
|
453
|
+
|
|
454
|
+
# last_x = reference.topLeft().x()
|
|
455
|
+
last_y = reference.topLeft().y() + reference.height()
|
|
456
|
+
|
|
457
|
+
for i in range(len(objects_to_align_with_respect_to_ref)):
|
|
458
|
+
if i==0 and skip_first:
|
|
459
|
+
continue
|
|
460
|
+
img = objects_to_align_with_respect_to_ref[i]
|
|
461
|
+
if i != 0:
|
|
462
|
+
last_y += space
|
|
463
|
+
# print(last_y, img.topLeft())
|
|
464
|
+
img.setTopLeft(img.topLeft().x(), last_y)
|
|
465
|
+
# get all the bounding boxes and pack them with desired space in between
|
|
466
|
+
# get first point and last point in x
|
|
467
|
+
x = img.boundingRect().x()
|
|
468
|
+
y = img.boundingRect().y()
|
|
469
|
+
# last_x = img.boundingRect().x() + img.boundingRect().width()
|
|
470
|
+
last_y = img.boundingRect().y() + img.boundingRect().height()
|
|
471
|
+
# self.updateBoudingRect()
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
# align everything with respect to ref
|
|
475
|
+
# get first point and align so that the all have the same x
|
|
476
|
+
|
|
477
|
+
# align everything with respect to ref
|
|
478
|
+
# get first point and align so that the all have the same x
|
|
479
|
+
|
|
480
|
+
align_positions = ['Top', 'Bottom','Left', 'Right', 'CenterV', 'CenterH']
|
|
481
|
+
|
|
482
|
+
# I had to add scale to it to make it much better!!!
|
|
483
|
+
def align2(position=None,*objects_to_align_with_respect_to_ref):
|
|
484
|
+
if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) <=1:
|
|
485
|
+
# logger.warning("Nothing to align...")
|
|
486
|
+
return
|
|
487
|
+
|
|
488
|
+
reference = objects_to_align_with_respect_to_ref[0]
|
|
489
|
+
# TOD REPLACE BY A SWITCH --> somehow switch does not work with external variable --> maybe try still
|
|
490
|
+
|
|
491
|
+
if position == align_positions[0] or position is None:
|
|
492
|
+
last_y = reference.y()
|
|
493
|
+
elif position == align_positions[1]:
|
|
494
|
+
last_y = reference.y() + reference.height(all=True)
|
|
495
|
+
elif position == align_positions[2]:
|
|
496
|
+
last_x = reference.x()
|
|
497
|
+
elif position == align_positions[3]:
|
|
498
|
+
last_x = reference.x()+reference.width(all=True)
|
|
499
|
+
elif position == align_positions[4]:
|
|
500
|
+
last_y = reference.y() + reference.height(all=True) / 2. # should be the end point of every stuff
|
|
501
|
+
elif position == align_positions[5]:
|
|
502
|
+
last_x = reference.x() + reference.width(all=True) / 2.
|
|
503
|
+
else:
|
|
504
|
+
pass
|
|
505
|
+
for img in objects_to_align_with_respect_to_ref[1:]:
|
|
506
|
+
if position == align_positions[0] or position is None:
|
|
507
|
+
img.setTopLeft(img.x(), last_y)
|
|
508
|
+
elif position == align_positions[1]:
|
|
509
|
+
pos_y = img.y() + img.height(all=True)
|
|
510
|
+
difference_y = last_y - pos_y
|
|
511
|
+
img.setTopLeft(img.x(), img.y() + difference_y)
|
|
512
|
+
elif position == align_positions[2]:
|
|
513
|
+
img.setTopLeft(last_x, img.y())
|
|
514
|
+
elif position == align_positions[3]:
|
|
515
|
+
pos_x = img.x() + img.width(all=True)
|
|
516
|
+
difference_x = last_x - pos_x
|
|
517
|
+
img.setTopLeft(img.x() + difference_x, img.y())
|
|
518
|
+
elif position == align_positions[4]:
|
|
519
|
+
pos_y = img.y() + img.height(all=True) / 2.
|
|
520
|
+
difference_y = last_y - pos_y
|
|
521
|
+
img.setTopLeft(img.x(), img.y() + difference_y)
|
|
522
|
+
elif position == align_positions[5]:
|
|
523
|
+
pos_x = img.x() + img.width(all=True) / 2.
|
|
524
|
+
difference_x = last_x - pos_x
|
|
525
|
+
img.setTopLeft(img.x() + difference_x, img.y())
|
|
526
|
+
else:
|
|
527
|
+
print('error trying to align there')
|
|
528
|
+
pass
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
# this is the new version of the align code that is not duplicated and so much better
|
|
532
|
+
@deprecated(reason='will soon switch to align2')
|
|
533
|
+
def align(position=None,*objects_to_align_with_respect_to_ref):
|
|
534
|
+
if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) <=1:
|
|
535
|
+
# logger.warning("Nothing to align...")
|
|
536
|
+
return
|
|
537
|
+
|
|
538
|
+
reference = objects_to_align_with_respect_to_ref[0]
|
|
539
|
+
# TOD REPLACE BY A SWITCH --> somehow switch does not work with external variable --> maybe try still
|
|
540
|
+
|
|
541
|
+
if position == align_positions[0] or position is None:
|
|
542
|
+
last_y = reference.y()
|
|
543
|
+
elif position == align_positions[1]:
|
|
544
|
+
last_y = reference.y() + reference.height()
|
|
545
|
+
elif position == align_positions[2]:
|
|
546
|
+
last_x = reference.x()
|
|
547
|
+
elif position == align_positions[3]:
|
|
548
|
+
last_x = reference.x()+reference.width()
|
|
549
|
+
elif position == align_positions[4]:
|
|
550
|
+
last_y = reference.y() + reference.height() / 2. # should be the end point of every stuff
|
|
551
|
+
elif position == align_positions[5]:
|
|
552
|
+
last_x = reference.x() + reference.width() / 2.
|
|
553
|
+
else:
|
|
554
|
+
pass
|
|
555
|
+
for img in objects_to_align_with_respect_to_ref[1:]:
|
|
556
|
+
if position == align_positions[0] or position is None:
|
|
557
|
+
img.setTopLeft(img.x(), last_y)
|
|
558
|
+
elif position == align_positions[1]:
|
|
559
|
+
pos_y = img.y() + img.height()
|
|
560
|
+
difference_y = last_y - pos_y
|
|
561
|
+
img.setTopLeft(img.x(), img.y() + difference_y)
|
|
562
|
+
elif position == align_positions[2]:
|
|
563
|
+
img.setTopLeft(last_x, img.y())
|
|
564
|
+
elif position == align_positions[3]:
|
|
565
|
+
pos_x = img.x() + img.width()
|
|
566
|
+
difference_x = last_x - pos_x
|
|
567
|
+
img.setTopLeft(img.x() + difference_x, img.y())
|
|
568
|
+
elif position == align_positions[4]:
|
|
569
|
+
pos_y = img.y() + img.height() / 2.
|
|
570
|
+
difference_y = last_y - pos_y
|
|
571
|
+
img.setTopLeft(img.x(), img.y() + difference_y)
|
|
572
|
+
elif position == align_positions[5]:
|
|
573
|
+
pos_x = img.x() + img.width() / 2.
|
|
574
|
+
difference_x = last_x - pos_x
|
|
575
|
+
img.setTopLeft(img.x() + difference_x, img.y())
|
|
576
|
+
else:
|
|
577
|
+
pass
|
|
578
|
+
|
|
579
|
+
# match position:
|
|
580
|
+
# case align_positions[0]:
|
|
581
|
+
# pass
|
|
582
|
+
# case align_positions[1]:
|
|
583
|
+
# pass
|
|
584
|
+
# case pattern-3:
|
|
585
|
+
# pass
|
|
586
|
+
# case _:
|
|
587
|
+
# pass
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
@deprecated(reason="This method is deprecated and will be removed in the future. Please use 'align' instead.")
|
|
593
|
+
def alignLeft(reference=None, *objects_to_align_with_respect_to_ref):
|
|
594
|
+
skip_first = False
|
|
595
|
+
if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
|
|
596
|
+
# logger.warning("Nothing to align...")
|
|
597
|
+
return
|
|
598
|
+
if reference is None:
|
|
599
|
+
if len(objects_to_align_with_respect_to_ref) < 2:
|
|
600
|
+
logger.warning("Reference is None, can't align anything...")
|
|
601
|
+
return
|
|
602
|
+
else:
|
|
603
|
+
reference = objects_to_align_with_respect_to_ref[0]
|
|
604
|
+
skip_first = True
|
|
605
|
+
# del objects_to_align_with_respect_to_ref[0]
|
|
606
|
+
|
|
607
|
+
last_x = reference.topLeft().x()
|
|
608
|
+
# last_y = reference.topLeft().y()
|
|
609
|
+
|
|
610
|
+
for i in range(len(objects_to_align_with_respect_to_ref)):
|
|
611
|
+
if i==0 and skip_first:
|
|
612
|
+
continue
|
|
613
|
+
img = objects_to_align_with_respect_to_ref[i]
|
|
614
|
+
|
|
615
|
+
img.setTopLeft(last_x, img.topLeft().y())
|
|
616
|
+
# get all the bounding boxes and pack them with desired space in between
|
|
617
|
+
# get first point and last point in x
|
|
618
|
+
# x = img.boundingRect().x()
|
|
619
|
+
# y = img.boundingRect().y()
|
|
620
|
+
# last_x = img.boundingRect().x() + img.boundingRect().width()
|
|
621
|
+
# last_y = img.boundingRect().y() + img.boundingRect().height()
|
|
622
|
+
# self.updateBoudingRect()
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
@deprecated(reason="This method is deprecated and will be removed in the future. Please use 'align' instead.")
|
|
626
|
+
def alignTop(reference=None, *objects_to_align_with_respect_to_ref):
|
|
627
|
+
skip_first = False
|
|
628
|
+
if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
|
|
629
|
+
# logger.warning("Nothing to align...")
|
|
630
|
+
return
|
|
631
|
+
if reference is None:
|
|
632
|
+
if len(objects_to_align_with_respect_to_ref) < 2:
|
|
633
|
+
logger.warning("Reference is None, can't align anything...")
|
|
634
|
+
return
|
|
635
|
+
else:
|
|
636
|
+
reference = objects_to_align_with_respect_to_ref[0]
|
|
637
|
+
skip_first = True
|
|
638
|
+
# del objects_to_align_with_respect_to_ref[0]
|
|
639
|
+
|
|
640
|
+
# last_x = reference.topLeft().x()
|
|
641
|
+
last_y = reference.topLeft().y()
|
|
642
|
+
|
|
643
|
+
for i in range(len(objects_to_align_with_respect_to_ref)):
|
|
644
|
+
if i==0 and skip_first:
|
|
645
|
+
continue
|
|
646
|
+
img = objects_to_align_with_respect_to_ref[i]
|
|
647
|
+
|
|
648
|
+
img.setTopLeft(img.topLeft().x(), last_y)
|
|
649
|
+
# get all the bounding boxes and pack them with desired space in between
|
|
650
|
+
# get first point and last point in x
|
|
651
|
+
# x = img.boundingRect().x()
|
|
652
|
+
# y = img.boundingRect().y()
|
|
653
|
+
# last_x = img.boundingRect().x() + img.boundingRect().width()
|
|
654
|
+
# last_y = img.boundingRect().y() + img.boundingRect().height()
|
|
655
|
+
# self.updateBoudingRect()
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
# align everything with respect to ref
|
|
659
|
+
# get first point and align so that the all have the same x
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
@deprecated(reason="This method is deprecated and will be removed in the future. Please use 'align' instead.")
|
|
663
|
+
def alignBottom(reference=None, *objects_to_align_with_respect_to_ref):
|
|
664
|
+
skip_first = False
|
|
665
|
+
if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
|
|
666
|
+
# logger.warning("Nothing to align...")
|
|
667
|
+
return
|
|
668
|
+
if reference is None:
|
|
669
|
+
if len(objects_to_align_with_respect_to_ref) < 2:
|
|
670
|
+
logger.warning("Reference is None, can't align anything...")
|
|
671
|
+
return
|
|
672
|
+
else:
|
|
673
|
+
reference = objects_to_align_with_respect_to_ref[0]
|
|
674
|
+
skip_first = True
|
|
675
|
+
# del objects_to_align_with_respect_to_ref[0]
|
|
676
|
+
|
|
677
|
+
# last_x = reference.topLeft().x()
|
|
678
|
+
last_y = reference.topLeft().y()+reference.height() # should be the end point of every stuff
|
|
679
|
+
|
|
680
|
+
for i in range(len(objects_to_align_with_respect_to_ref)):
|
|
681
|
+
if i==0 and skip_first:
|
|
682
|
+
continue
|
|
683
|
+
img = objects_to_align_with_respect_to_ref[i]
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
pos_y = img.topLeft().y()+img.height()
|
|
687
|
+
difference_y = last_y-pos_y
|
|
688
|
+
img.setTopLeft(img.topLeft().x(), img.topLeft().y()+difference_y)
|
|
689
|
+
# get all the bounding boxes and pack them with desired space in between
|
|
690
|
+
# get first point and last point in x
|
|
691
|
+
# x = img.boundingRect().x()
|
|
692
|
+
# y = img.boundingRect().y()
|
|
693
|
+
# last_x = img.boundingRect().x() + img.boundingRect().width()
|
|
694
|
+
# last_y = img.boundingRect().y() + img.boundingRect().height()
|
|
695
|
+
# self.updateBoudingRect()
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
# align everything with respect to ref
|
|
699
|
+
# get first point and align so that the all have the same x
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
@deprecated(reason="This method is deprecated and will be removed in the future. Please use 'align' instead.")
|
|
703
|
+
# bug here now with the images
|
|
704
|
+
def alignRight(reference=None, *objects_to_align_with_respect_to_ref):
|
|
705
|
+
skip_first = False
|
|
706
|
+
if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
|
|
707
|
+
# logger.warning("Nothing to align...")
|
|
708
|
+
return
|
|
709
|
+
if reference is None:
|
|
710
|
+
if len(objects_to_align_with_respect_to_ref) < 2:
|
|
711
|
+
logger.warning("Reference is None, can't align anything...")
|
|
712
|
+
return
|
|
713
|
+
else:
|
|
714
|
+
reference = objects_to_align_with_respect_to_ref[0]
|
|
715
|
+
skip_first = True
|
|
716
|
+
# del objects_to_align_with_respect_to_ref[0]
|
|
717
|
+
|
|
718
|
+
last_x = reference.topLeft().x()+reference.width() # should be the end point of every stuff
|
|
719
|
+
# last_y = reference.topLeft().y()+reference.height() # should be the end point of every stuff
|
|
720
|
+
|
|
721
|
+
for i in range(len(objects_to_align_with_respect_to_ref)):
|
|
722
|
+
if i==0 and skip_first:
|
|
723
|
+
continue
|
|
724
|
+
img = objects_to_align_with_respect_to_ref[i]
|
|
725
|
+
|
|
726
|
+
pos_x = img.topLeft().x()+img.width()
|
|
727
|
+
difference_x = last_x-pos_x
|
|
728
|
+
img.setTopLeft(img.topLeft().x()+difference_x, img.topLeft().y())
|
|
729
|
+
# get all the bounding boxes and pack them with desired space in between
|
|
730
|
+
# get first point and last point in x
|
|
731
|
+
# x = img.boundingRect().x()
|
|
732
|
+
# y = img.boundingRect().y()
|
|
733
|
+
# last_x = img.boundingRect().x() + img.boundingRect().width()
|
|
734
|
+
# last_y = img.boundingRect().y() + img.boundingRect().height()
|
|
735
|
+
# self.updateBoudingRect()
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
# align everything with respect to ref
|
|
739
|
+
# get first point and align so that the all have the same x
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
@deprecated(reason="This method is deprecated and will be removed in the future. Please use 'align' instead.")
|
|
743
|
+
def alignCenterH(reference=None, *objects_to_align_with_respect_to_ref):
|
|
744
|
+
skip_first = False
|
|
745
|
+
if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
|
|
746
|
+
# logger.warning("Nothing to align...")
|
|
747
|
+
return
|
|
748
|
+
if reference is None:
|
|
749
|
+
if len(objects_to_align_with_respect_to_ref) < 2:
|
|
750
|
+
logger.warning("Reference is None, can't align anything...")
|
|
751
|
+
return
|
|
752
|
+
else:
|
|
753
|
+
reference = objects_to_align_with_respect_to_ref[0]
|
|
754
|
+
skip_first = True
|
|
755
|
+
# del objects_to_align_with_respect_to_ref[0]
|
|
756
|
+
|
|
757
|
+
# last_x = reference.topLeft().x()+reference.width()/2. # should be the end point of every stuff
|
|
758
|
+
last_x = reference.topLeft().x()+reference.width()/2. # should be the end point of every stuff
|
|
759
|
+
# last_y = reference.topLeft().y()+reference.height() # should be the end point of every stuff
|
|
760
|
+
|
|
761
|
+
for i in range(len(objects_to_align_with_respect_to_ref)):
|
|
762
|
+
if i==0 and skip_first:
|
|
763
|
+
continue
|
|
764
|
+
img = objects_to_align_with_respect_to_ref[i]
|
|
765
|
+
|
|
766
|
+
pos_x = img.topLeft().x()+img.width()/2.
|
|
767
|
+
difference_x = last_x-pos_x
|
|
768
|
+
img.setTopLeft(img.topLeft().x()+difference_x, img.topLeft().y())
|
|
769
|
+
# get all the bounding boxes and pack them with desired space in between
|
|
770
|
+
# get first point and last point in x
|
|
771
|
+
# x = img.boundingRect().x()
|
|
772
|
+
# y = img.boundingRect().y()
|
|
773
|
+
# last_x = img.boundingRect().x() + img.boundingRect().width()
|
|
774
|
+
# last_y = img.boundingRect().y() + img.boundingRect().height()
|
|
775
|
+
# self.updateBoudingRect()
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
# align everything with respect to ref
|
|
779
|
+
# get first point and align so that the all have the same x
|
|
780
|
+
|
|
781
|
+
@deprecated(reason="This method is deprecated and will be removed in the future. Please use 'align' instead.")
|
|
782
|
+
def alignCenterV(reference=None, *objects_to_align_with_respect_to_ref):
|
|
783
|
+
skip_first = False
|
|
784
|
+
if objects_to_align_with_respect_to_ref is None or len(objects_to_align_with_respect_to_ref) == 0:
|
|
785
|
+
# logger.warning("Nothing to align...")
|
|
786
|
+
return
|
|
787
|
+
if reference is None:
|
|
788
|
+
if len(objects_to_align_with_respect_to_ref) < 2:
|
|
789
|
+
logger.warning("Reference is None, can't align anything...")
|
|
790
|
+
return
|
|
791
|
+
else:
|
|
792
|
+
reference = objects_to_align_with_respect_to_ref[0]
|
|
793
|
+
skip_first = True
|
|
794
|
+
# del objects_to_align_with_respect_to_ref[0]
|
|
795
|
+
|
|
796
|
+
# last_x = reference.topLeft().x()
|
|
797
|
+
last_y = reference.topLeft().y()+reference.height()/2. # should be the end point of every stuff
|
|
798
|
+
|
|
799
|
+
for i in range(len(objects_to_align_with_respect_to_ref)):
|
|
800
|
+
if i==0 and skip_first:
|
|
801
|
+
continue
|
|
802
|
+
img = objects_to_align_with_respect_to_ref[i]
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
pos_y = img.topLeft().y()+img.height()/2.
|
|
806
|
+
difference_y = last_y-pos_y
|
|
807
|
+
img.setTopLeft(img.topLeft().x(), img.topLeft().y()+difference_y)
|
|
808
|
+
# get all the bounding boxes and pack them with desired space in between
|
|
809
|
+
# get first point and last point in x
|
|
810
|
+
# x = img.boundingRect().x()
|
|
811
|
+
# y = img.boundingRect().y()
|
|
812
|
+
# last_x = img.boundingRect().x() + img.boundingRect().width()
|
|
813
|
+
# last_y = img.boundingRect().y() + img.boundingRect().height()
|
|
814
|
+
# self.updateBoudingRect()
|