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.
Files changed (162) hide show
  1. batoolset/GUI/__init__.py +0 -0
  2. batoolset/GUI/list_gui.py +513 -0
  3. batoolset/GUI/multi_image_display.py +989 -0
  4. batoolset/GUI/open.py +325 -0
  5. batoolset/GUI/overlay_hints.py +45 -0
  6. batoolset/GUI/paint2.py +1345 -0
  7. batoolset/GUI/scrollablepaint.py +1152 -0
  8. batoolset/IJ_ROIs/__init__.py +0 -0
  9. batoolset/IJ_ROIs/tools.py +40 -0
  10. batoolset/PATH/__init__.py +0 -0
  11. batoolset/PATH/tools.py +79 -0
  12. batoolset/SQLite_tools/__init__.py +0 -0
  13. batoolset/SQLite_tools/tools.py +840 -0
  14. batoolset/__init__.py +0 -0
  15. batoolset/binary/__init__.py +0 -0
  16. batoolset/binary/tools.py +123 -0
  17. batoolset/binarytools/__init__.py +0 -0
  18. batoolset/binarytools/cell_center_detector.py +290 -0
  19. batoolset/clipboard_tools/__init__.py +0 -0
  20. batoolset/clipboard_tools/tools.py +7 -0
  21. batoolset/colors/__init__.py +0 -0
  22. batoolset/colors/colorgen.py +193 -0
  23. batoolset/colors/tools.py +22 -0
  24. batoolset/command_line/__init__.py +0 -0
  25. batoolset/command_line/tools.py +18 -0
  26. batoolset/dialogs/__init__.py +0 -0
  27. batoolset/dialogs/opensave.py +228 -0
  28. batoolset/dicts/__init__.py +0 -0
  29. batoolset/dicts/tools.py +299 -0
  30. batoolset/dims/__init__.py +0 -0
  31. batoolset/dims/tools.py +83 -0
  32. batoolset/draw/__init__.py +0 -0
  33. batoolset/draw/shapes/Position.py +183 -0
  34. batoolset/draw/shapes/__init__.py +0 -0
  35. batoolset/draw/shapes/automated_alignment_drawing_refactored.py +346 -0
  36. batoolset/draw/shapes/circle2d.py +99 -0
  37. batoolset/draw/shapes/compute_optimal_size_all_merged.py +317 -0
  38. batoolset/draw/shapes/ellipse2d.py +336 -0
  39. batoolset/draw/shapes/freehand2d.py +235 -0
  40. batoolset/draw/shapes/group.py +1830 -0
  41. batoolset/draw/shapes/image2d.py +2469 -0
  42. batoolset/draw/shapes/line2d.py +575 -0
  43. batoolset/draw/shapes/point2d.py +257 -0
  44. batoolset/draw/shapes/polygon2d.py +357 -0
  45. batoolset/draw/shapes/polyline2d.py +235 -0
  46. batoolset/draw/shapes/rect2d.py +388 -0
  47. batoolset/draw/shapes/rectangle2d.py +601 -0
  48. batoolset/draw/shapes/scalebar.py +304 -0
  49. batoolset/draw/shapes/serializablefont.py +126 -0
  50. batoolset/draw/shapes/serializableguiparams.py +10 -0
  51. batoolset/draw/shapes/square2d.py +103 -0
  52. batoolset/draw/shapes/textorientation.py +45 -0
  53. batoolset/draw/shapes/tools.py +467 -0
  54. batoolset/draw/shapes/transform2D.py +350 -0
  55. batoolset/draw/shapes/txt2d.py +550 -0
  56. batoolset/draw/widgets/__init__.py +0 -0
  57. batoolset/draw/widgets/col.py +343 -0
  58. batoolset/draw/widgets/image_group.py +248 -0
  59. batoolset/draw/widgets/image_organizer.py +96 -0
  60. batoolset/draw/widgets/paint.py +184 -0
  61. batoolset/draw/widgets/vectorial.py +257 -0
  62. batoolset/figure/__init__.py +0 -0
  63. batoolset/figure/alignment.py +814 -0
  64. batoolset/figure/column.py +1117 -0
  65. batoolset/figure/fig_tools.py +285 -0
  66. batoolset/figure/minimal_debugger_scale_etc.py +139 -0
  67. batoolset/figure/panel.py +697 -0
  68. batoolset/figure/row.py +852 -0
  69. batoolset/figure/user_selection.py +287 -0
  70. batoolset/files/__init__.py +0 -0
  71. batoolset/files/tools.py +1321 -0
  72. batoolset/images/__init__.py +0 -0
  73. batoolset/images/tools.py +81 -0
  74. batoolset/img.py +5216 -0
  75. batoolset/linux/__init__.py +0 -0
  76. batoolset/linux/tools.py +72 -0
  77. batoolset/lists/__init__.py +0 -0
  78. batoolset/lists/tools.py +436 -0
  79. batoolset/luts/__init__.py +0 -0
  80. batoolset/luts/lut_minimal_test.py +1207 -0
  81. batoolset/matplolib/__init__.py +0 -0
  82. batoolset/matplolib/tools.py +44 -0
  83. batoolset/np_tools/__init__.py +0 -0
  84. batoolset/np_tools/tools.py +252 -0
  85. batoolset/np_tools/trash.py +15 -0
  86. batoolset/pandas_tools/__init__.py +0 -0
  87. batoolset/pandas_tools/tools.py +880 -0
  88. batoolset/partials/__init__.py +0 -0
  89. batoolset/partials/tools.py +83 -0
  90. batoolset/plot_tools/__init__.py +0 -0
  91. batoolset/plot_tools/tools.py +70 -0
  92. batoolset/pyqt/__init__.py +0 -0
  93. batoolset/pyqt/tools.py +691 -0
  94. batoolset/re_tools/__init__.py +0 -0
  95. batoolset/re_tools/tools.py +35 -0
  96. batoolset/serialization/__init__.py +0 -0
  97. batoolset/serialization/tools.py +1192 -0
  98. batoolset/sets/__init__.py +0 -0
  99. batoolset/sets/tools.py +109 -0
  100. batoolset/settings/__init__.py +0 -0
  101. batoolset/settings/global_settings.py +134 -0
  102. batoolset/strings/__init__.py +0 -0
  103. batoolset/strings/tools.py +225 -0
  104. batoolset/ta/__init__.py +0 -0
  105. batoolset/ta/database/__init__.py +0 -0
  106. batoolset/ta/database/advanced_sql_plotter.py +1170 -0
  107. batoolset/ta/database/my_qt_table.py +79 -0
  108. batoolset/ta/database/preview_and_edit_sqlite_db.py +405 -0
  109. batoolset/ta/database/sql.py +2141 -0
  110. batoolset/ta/database/sql_column_name_dialog.py +122 -0
  111. batoolset/ta/measurements/TAmeasures.py +2226 -0
  112. batoolset/ta/measurements/__init__.py +0 -0
  113. batoolset/ta/measurements/measurements3D/__init__.py +0 -0
  114. batoolset/ta/measurements/measurements3D/get_point_on_surface_if_centroid_is_bad.py +175 -0
  115. batoolset/ta/measurements/measurements3D/height_map_to_projection.py +82 -0
  116. batoolset/ta/measurements/measurements3D/measures3D.py +208 -0
  117. batoolset/ta/measurements/measurements3D/triangulate.py +331 -0
  118. batoolset/ta/measurements/nematic.py +562 -0
  119. batoolset/ta/measurements/nematic_measurements.py +107 -0
  120. batoolset/ta/segmentation/__init__.py +0 -0
  121. batoolset/ta/segmentation/neo_wshed.py +314 -0
  122. batoolset/ta/selections/__init__.py +0 -0
  123. batoolset/ta/selections/selection.py +329 -0
  124. batoolset/ta/tracking/__init__.py +0 -0
  125. batoolset/ta/tracking/last_tracking_based_on_matching_or_on_translation_from_mermaid_warp.py +653 -0
  126. batoolset/ta/tracking/local_to_track_correspondance.py +138 -0
  127. batoolset/ta/tracking/rapid_detection_of_vertices.py +517 -0
  128. batoolset/ta/tracking/registration.py +108 -0
  129. batoolset/ta/tracking/swap_detector_and_fixer.py +296 -0
  130. batoolset/ta/tracking/track_correction.py +238 -0
  131. batoolset/ta/tracking/tracking_error_detector_and_fixer.py +3099 -0
  132. batoolset/ta/tracking/tracking_yet_another_approach_pyramidal_registration_n_neo_swapping_correction.py +725 -0
  133. batoolset/ta/utils/TA_tools.py +43 -0
  134. batoolset/ta/utils/__init__.py +0 -0
  135. batoolset/ta/utils/rps_tools.py +1783 -0
  136. batoolset/tests/__init__.py +0 -0
  137. batoolset/tests/rps_tools.py +51 -0
  138. batoolset/tests/tools.py +10 -0
  139. batoolset/tools/__init__.py +0 -0
  140. batoolset/tools/early_stopper_class.py +9 -0
  141. batoolset/tools/guided_data_recoverer.py +110 -0
  142. batoolset/tools/logger.py +100 -0
  143. batoolset/tools/mytimer.py +31 -0
  144. batoolset/tools/prompt_color.py +160 -0
  145. batoolset/tools/qthandler.py +118 -0
  146. batoolset/uitools/__init__.py +0 -0
  147. batoolset/uitools/blinker.py +56 -0
  148. batoolset/unsafe/__init__.py +0 -0
  149. batoolset/unsafe/tools.py +115 -0
  150. batoolset/utils/__init__.py +0 -0
  151. batoolset/utils/commontools.py +158 -0
  152. batoolset/utils/loadlist.py +728 -0
  153. batoolset/version.py +10 -0
  154. batoolset/xml/__init__.py +0 -0
  155. batoolset/xml/tools.py +65 -0
  156. batoolset/zip_tools/__init__.py +0 -0
  157. batoolset/zip_tools/tools.py +76 -0
  158. batoolset-0.1.0.dist-info/LICENSE +24 -0
  159. batoolset-0.1.0.dist-info/METADATA +45 -0
  160. batoolset-0.1.0.dist-info/RECORD +162 -0
  161. batoolset-0.1.0.dist-info/WHEEL +5 -0
  162. batoolset-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,343 @@
1
+ #https://docs.python.org/2/library/operator.html
2
+
3
+ import os
4
+ from batoolset.settings.global_settings import set_UI # set the UI to qtpy
5
+ set_UI()
6
+ from batoolset.draw.shapes.rect2d import Rect2D
7
+ from qtpy.QtCore import QPointF, QRectF
8
+ # logger
9
+ from batoolset.tools.logger import TA_logger
10
+ from batoolset.figure.row import Row # KEEP Really required to avoid circular imports
11
+ logger = TA_logger()
12
+
13
+
14
+ # TODO hack it that it can handle rows or images if needed
15
+
16
+ class col(Rect2D):
17
+
18
+ def __init__(self, *args, space=3, width=None):
19
+ self.images = []
20
+ self.widthInPixel = width
21
+ self.space = space
22
+ for arg in args:
23
+ # if isinstance(arg, Column):
24
+ # arg.packX(space=space)
25
+ # arg.setToWidth(self.widthInPixel)
26
+ self.images.append(arg)
27
+ # else:
28
+ # self.images.append(Column(arg, space=space, width=width))
29
+ super(Rect2D, self).__init__()
30
+ self.packY(space=space)
31
+
32
+ def __or__(self, other):
33
+ if isinstance(other, col):
34
+ pos = self.get_P1()
35
+ other_pos = other.get_P1()
36
+ self.set_P1(other_pos)
37
+ other.set_P1(pos)
38
+ else:
39
+ logger.error('swapping not implemented yet for ' + str(type(other)))
40
+
41
+ def __sub__(self, other):
42
+ if other in self.images:
43
+ self.images.remove(other)
44
+ return
45
+ for row in self.images:
46
+ row -= other
47
+ for row in reversed(self.images):
48
+ if row.isEmpty():
49
+ self.images.remove(row)
50
+
51
+ return self
52
+
53
+ def __add__(self, other):
54
+ from batoolset.figure.row import Row # KEEP Really required to avoid circular imports # TODO is that still true ?
55
+ if isinstance(other, Row):
56
+ other.packX(space=self.space)
57
+ other.setToWidth(self.widthInPixel)
58
+ self.images.append(other)
59
+ return self
60
+ self.images.append(Row(other, space=self.space, width=self.widthInPixel))
61
+ self.packY(space=self.space)
62
+ return self
63
+
64
+ def __len__(self):
65
+ if self.images is None:
66
+ return 0
67
+ return len(self.images)
68
+
69
+ def __iter__(self):
70
+ ''' Returns the Iterator object '''
71
+ self._index = -1
72
+ return self
73
+
74
+ def __next__(self):
75
+ ''' Returns the next row of the col '''
76
+ self._index += 1
77
+ if self._index < len(self.images):
78
+ return self.images[self._index]
79
+ # End of Iteration
80
+ raise StopIteration
81
+
82
+ def setWidthInPixel(self, widthInPixel):
83
+ self.widthInPixel = widthInPixel
84
+ self.packY()
85
+
86
+ # Forces the block to be of width (width_in_px)
87
+ def setToWidth(self, width_in_px):
88
+ for image in self:
89
+ image.setToHeight(width_in_px)
90
+ self.packY(space=self.space)
91
+
92
+ def setToHeight(self, height_in_px):
93
+ for image in self:
94
+ image.setToHeight(height_in_px)
95
+ self.packY(space=self.space)
96
+
97
+ def getIncompressibleWidth(self):
98
+ extra_space = 0;
99
+ return extra_space;
100
+
101
+ def packX(self, space=3):
102
+ # pack shapes in x
103
+
104
+ last_x = 0
105
+ last_y = 0
106
+
107
+ for i in range(len(self.images)):
108
+ row = self.images[i]
109
+ if i != 0:
110
+ last_x += space
111
+ row.set_P1(last_x, row.get_P1().y())
112
+ # get all the bounding boxes and pack them with desired space in between
113
+ # get first point and last point in x
114
+ x = row.boundingRect().x()
115
+ y = row.boundingRect().y()
116
+ last_x = row.boundingRect().x() + row.boundingRect().width()
117
+ last_y = row.boundingRect().y() + row.boundingRect().height()
118
+ self.updateBoudingRect()
119
+
120
+
121
+ def packY(self, space=3):
122
+
123
+ if space is None:
124
+ space = 0
125
+
126
+ last_x = 0
127
+ last_y = 0
128
+
129
+
130
+ for i in range(len(self.images)):
131
+ row = self.images[i]
132
+ if i != 0:
133
+ last_y += space
134
+ row.set_P1(row.get_P1().x(), last_y)
135
+
136
+ x = row.boundingRect().x()
137
+ y = row.boundingRect().y()
138
+ last_x = row.boundingRect().x() + row.boundingRect().width()
139
+ last_y = row.boundingRect().y() + row.boundingRect().height()
140
+ self.updateBoudingRect()
141
+
142
+ def updateBoudingRect(self):
143
+ '''updates the image bounding rect depending on content
144
+
145
+ '''
146
+ x = None
147
+ y = None
148
+ x2 = None
149
+ y2 = None
150
+ for row in self:
151
+ topLeft = row.get_P1()
152
+ if x is None:
153
+ x = topLeft.x()
154
+ if y is None:
155
+ y = topLeft.y()
156
+ x = min(topLeft.x(), x)
157
+ y = min(topLeft.y(), y)
158
+ if x2 is None:
159
+ x2 = topLeft.x() + row.boundingRect().width()
160
+ if y2 is None:
161
+ y2 = topLeft.y() + row.boundingRect().height()
162
+ x2 = max(topLeft.x() + row.boundingRect().width(), x2)
163
+ y2 = max(topLeft.y() + row.boundingRect().height(), y2)
164
+
165
+ if x is not None:
166
+ self.setX(x)
167
+ if y is not None:
168
+ self.setY(y)
169
+ if x2 is not None:
170
+ self.setWidth(x2 - x)
171
+ if y2 is not None:
172
+ self.setHeight(y2 - y)
173
+
174
+ def set_P1(self, *args):
175
+ curP1 = self.get_P1()
176
+ Rect2D.set_P1(self, *args)
177
+ newP1 = self.get_P1()
178
+ # need do a translation of all its content images
179
+ for row in self:
180
+ row.translate(newP1.x() - curP1.x(), newP1.y() - curP1.y())
181
+
182
+ def translate(self, *args):
183
+ if len(args)==1:
184
+ point = args[0]
185
+ QRectF.translate(self, point.x(), point.y())
186
+ for img in self:
187
+ img.translate(point.x(), point.y())
188
+ else:
189
+ QRectF.translate(self, args[0], args[1])
190
+ for img in self:
191
+ img.translate(QPointF(args[0], args[1]))
192
+
193
+
194
+ def draw(self, painter, draw=True):
195
+ if draw:
196
+ painter.save()
197
+ if draw:
198
+ counter = 0
199
+ for row in self:
200
+ print('drawing', counter, row.boundingRect())
201
+ counter+=1
202
+ row.draw(painter, draw=draw)
203
+ painter.restore()
204
+
205
+ def fill(self, painter, draw=True):
206
+ if self.fill_color is None:
207
+ return
208
+ if draw:
209
+ painter.save()
210
+ if draw:
211
+ for row in self:
212
+ row.fill(painter, draw=draw)
213
+ painter.restore()
214
+
215
+ # TODO pb will draw the shape twice.... ---> because painter drawpolygon is called twice
216
+
217
+ def drawAndFill(self, painter):
218
+ painter.save()
219
+ self.draw(painter, draw=True)
220
+ painter.restore()
221
+
222
+ if __name__ == '__main__':
223
+ from batoolset.draw.shapes.image2d import Image2D # KEEP Really required to avoid circular imports
224
+
225
+ img1 = Image2D('/E/Sample_images/counter/00.png')
226
+ img2 = Image2D('/E/Sample_images/counter/01.png')
227
+ img3 = Image2D('/E/Sample_images/counter/02.png')
228
+ img4 = Image2D('/E/Sample_images/counter/03.png')
229
+ img5 = Image2D('/E/Sample_images/counter/04.png')
230
+ img6 = Image2D('/E/Sample_images/counter/05.png')
231
+ img8 = Image2D('/E/Sample_images/counter/06.png')
232
+ img9 = Image2D('/E/Sample_images/counter/07.png')
233
+ img10 = Image2D('/E/Sample_images/counter/08.png')
234
+ img11 = Image2D('/E/Sample_images/counter/09.png')
235
+
236
+ result = img1 | img2 # fix so that this works ???
237
+
238
+
239
+ print(result)
240
+ print(len(result.images))
241
+
242
+ # result += img3
243
+ # result += img4
244
+
245
+ # print(result)
246
+ # print(len(result.images)) # ça ça marche
247
+
248
+ # if True:
249
+ # sys.exit(0)
250
+
251
+ # img3.pop()
252
+
253
+ row2 = img3 | img4 | img8
254
+ # row2 = row(img3, img4)
255
+
256
+ print(row2)
257
+ print(row2.images) # why 4 images here ....
258
+ print('row2', len(row2.images)) # pas bon trop d'images --> pkoi ????
259
+
260
+ print(Image2D)
261
+
262
+ fig = result + row2
263
+ print(fig)
264
+ print(len(fig.images))
265
+
266
+ count = 0
267
+ for img in fig.images:
268
+ print(count, img.filename)
269
+ count += 1
270
+
271
+ final_result = fig - img4
272
+ print(final_result)
273
+ print(final_result.images)
274
+ print(len(final_result.images))
275
+
276
+ # ça marche
277
+
278
+ final_result = img4 + fig # ça ne marche pas
279
+ print(final_result)
280
+ print(final_result.images)
281
+ print(len(final_result.images))
282
+
283
+ # si je divide une row alors ça ajoute une colonne à la figure --> return 2 rows in a figure
284
+
285
+
286
+
287
+ fig = img5 / img6
288
+
289
+ print(fig)
290
+ print(fig.rows)
291
+ print(len(fig.rows))
292
+
293
+ final_fig = fig - img5
294
+
295
+ print(final_fig)
296
+ print(final_fig.rows)
297
+ print(len(final_fig.rows))
298
+
299
+ final_fig += row2
300
+
301
+ print(final_fig)
302
+ print(final_fig.rows)
303
+ print(len(final_fig.rows))
304
+
305
+ fig = (img9) / (img10 + img11)
306
+ print(fig)
307
+ print(fig.rows)
308
+ print(len(fig.rows))
309
+ print('r1', len(fig.rows[0].images))
310
+ print('r2', len(fig.rows[1].images))
311
+
312
+ # try the pack and check it
313
+ # almost there now in fact...
314
+
315
+ for img in row2:
316
+ print(img.boundingRect())
317
+
318
+ print(row2)
319
+ row2.packX()
320
+ for img in row2:
321
+ print(img.boundingRect())
322
+
323
+ row2.packY()
324
+ for img in row2:
325
+ print(img.boundingRect())
326
+
327
+ # ça marche
328
+
329
+ # tester le draw sur une image --> balancer un qimage ???
330
+
331
+
332
+
333
+ # print('#'*20)
334
+ # from qtpy.QtCore import QRectF, QPointF
335
+ # test = QRectF(0,0,411,512)
336
+ # print(test)
337
+ # test.setX(414) # --> fucks width --> need reput it in correct position
338
+ # # test.setWidth(411)
339
+ # print(test)
340
+ # test = QRectF(0,0,411,512)
341
+ # print(test)
342
+ # test.setTopLeft(QPointF(414,0))
343
+ # print(test)
@@ -0,0 +1,248 @@
1
+ import os
2
+ from batoolset.settings.global_settings import set_UI # set the UI to qtpy
3
+ set_UI()
4
+ from batoolset.draw.shapes.rect2d import Rect2D
5
+ from qtpy.QtCore import QPointF, QRectF
6
+ from deprecated import deprecated
7
+ # logger
8
+ from batoolset.tools.logger import TA_logger
9
+
10
+ logger = TA_logger()
11
+
12
+
13
+ # en fait le pack vaudrait mieux le faire là ça serait bcp plus utile
14
+ # keep this in mind: https://stackoverflow.com/questions/34827132/changing-the-order-of-operation-for-add-mul-etc-methods-in-a-custom-c
15
+ @deprecated(reason="will be removed soon")
16
+ class group(Rect2D):
17
+
18
+ def __init__(self, *args, space=3):
19
+ self.images = []
20
+ for img in args:
21
+ # if isinstance(img, Column):
22
+ # self.images += img.images
23
+ # else:
24
+ self.images.append(img)
25
+ # init super empty
26
+ super(Rect2D, self).__init__()
27
+ # self.isSet = True # required to allow dragging
28
+ self.space = space
29
+
30
+ # self.sameHeight(space=space)
31
+ # self.widthInPixel = width
32
+ # self.setToWidth(width)
33
+ self.updateBoudingRect()
34
+
35
+ def updateBoudingRect(self):
36
+ '''updates the image bounding rect depending on content'''
37
+ x = None
38
+ y = None
39
+ x2 = None
40
+ y2 = None
41
+ for img in self:
42
+ topLeft = img.get_P1()
43
+ if x is None:
44
+ x = topLeft.x()
45
+ if y is None:
46
+ y = topLeft.y()
47
+ x = min(topLeft.x(), x)
48
+ y = min(topLeft.y(), y)
49
+
50
+ # print(img, img.boundingRect(), type(img))
51
+ # print(img, img.boundingRect(), type(img), img.boundingRect().height())
52
+
53
+ if x2 is None:
54
+ x2 = topLeft.x() + img.boundingRect().width()
55
+ if y2 is None:
56
+ y2 = topLeft.y() + img.boundingRect().height()
57
+ x2 = max(topLeft.x() + img.boundingRect().width(), x2)
58
+ y2 = max(topLeft.y() + img.boundingRect().height(), y2)
59
+
60
+ self.setX(x)
61
+ self.setY(y)
62
+ self.setWidth(x2 - x)
63
+ self.setHeight(y2 - y)
64
+
65
+ def setOrigin(self, *args):
66
+ self.set_P1(*args)
67
+
68
+ def set_P1(self, *args):
69
+ curP1 = self.get_P1()
70
+ Rect2D.set_P1(self, *args)
71
+ newP1 = self.get_P1()
72
+ for img in self:
73
+ img.translate(newP1.x() - curP1.x(), newP1.y() - curP1.y())
74
+
75
+ self.updateBoudingRect()
76
+
77
+ def translate(self, *args):
78
+ if len(args) == 1:
79
+ point = args[0]
80
+ QRectF.translate(self, point.x(), point.y())
81
+ for img in self:
82
+ img.translate(point.x(), point.y())
83
+ else:
84
+ QRectF.translate(self, args[0], args[1])
85
+ for img in self:
86
+ img.translate(QPointF(args[0], args[1]))
87
+
88
+ def __iter__(self):
89
+ ''' Returns the Iterator object '''
90
+ self._index = -1
91
+ return self
92
+
93
+ def __next__(self):
94
+ ''' Returns the next image or panel in the row '''
95
+ self._index += 1
96
+ if self._index < len(self.images):
97
+ return self.images[self._index]
98
+ # End of Iteration
99
+ raise StopIteration
100
+
101
+ # Forces the block to be of width (width_in_px)
102
+ def setToWidth(self, width_in_px):
103
+
104
+ # make all content same height then compute width and incompressible width of each object in fact
105
+
106
+ if width_in_px is None:
107
+ return
108
+ nb_cols = len(self)
109
+ pure_image_width = (self.boundingRect().width()) - (nb_cols - 1.) * self.space - self.getIncompressibleWidth()
110
+ # print(width_in_px, self.getIncompressibleWidth(), (nb_cols - 1.) * self.space)
111
+ width_in_px -= self.getIncompressibleWidth() + (nb_cols - 1.) * self.space
112
+ ratio = width_in_px / pure_image_width
113
+ for img in self:
114
+ img.setToHeight(img.boundingRect().width() * ratio)
115
+
116
+
117
+ self.packX(self.space)
118
+ self.updateBoudingRect()
119
+
120
+
121
+ # compute corresponding row height ???? so that it fits not so easy in fact
122
+
123
+ # pb here l'incompressible space est le courant plus la somme des incompressible spaces du contenu
124
+ # def setToWidth(self, width_in_px):
125
+ #
126
+ # # make all content same height then compute width and incompressible width of each object in fact
127
+ #
128
+ # if width_in_px is None:
129
+ # return
130
+ # nb_cols = len(self)
131
+ # # pure_image_height = self.boundingRect().height() - self.getIncompressibleHeight()
132
+ # # incompressible_width = self.getIncompressibleWidth()
133
+ #
134
+ # # for img in self:
135
+ # # incompressible_width+=img.getIncompressibleWidth()
136
+ #
137
+ # pure_image_width = (self.boundingRect().width()) -self.getIncompressibleWidth(), (nb_cols - 1.) * self.space
138
+ #
139
+ # # print(width_in_px, self.getIncompressibleWidth(), (nb_cols - 1.) * self.space)
140
+ # width_in_px -= self.getIncompressibleWidth(), (nb_cols - 1.) * self.space
141
+ # # height_in_px -= self.getIncompressibleHeight()
142
+ # ratio = width_in_px / pure_image_width
143
+ # for img in self:
144
+ # print('target width before', width_in_px, img.boundingRect(), ratio)
145
+ # img.setToWidth(img.boundingRect().width() * ratio)
146
+ # print('target width after', width_in_px, img.boundingRect())
147
+ #
148
+ #
149
+ # self.packX(self.space)
150
+ # self.updateBoudingRect()
151
+
152
+ # Forces the block to be of width (width_in_px)
153
+ # tjrs faire ça row by row
154
+ def setToHeight(self, height_in_px):
155
+ # celui la marche mais celui du dessus ne marche pas --> pkoi ???
156
+
157
+ if height_in_px is None:
158
+ return
159
+ nb_cols = len(self) #ce ne sera pas tjrs correct --> faudrait faire mieux que ça en fait
160
+ # pure_image_width = (self.boundingRect().width()) -self.getIncompressibleWidth(), (nb_cols - 1.) * self.space
161
+ # incompressible_width = self.getIncompressibleWidth()
162
+
163
+ # for img in self:
164
+ # incompressible_width += img.getIncompressibleWidth()
165
+ pure_image_width = (self.boundingRect().width()) - self.getIncompressibleWidth(), (nb_cols - 1.) * self.space
166
+
167
+ pure_image_height = self.boundingRect().height()- self.getIncompressibleHeight()
168
+ # print(height_in_px, self.getIncompressibleHeight(), (nb_cols - 1.) * self.space)
169
+ height_in_px -= self.getIncompressibleHeight()
170
+ ratio = height_in_px / pure_image_height
171
+ for img in self:
172
+ img.setToHeight(img.boundingRect().height() * ratio)
173
+
174
+ print('values resize', pure_image_width, pure_image_height, height_in_px, ratio)
175
+
176
+ self.packX(self.space)
177
+ self.updateBoudingRect()
178
+
179
+ def __len__(self):
180
+ if self.images is None:
181
+ return 0
182
+ return len(self.images)
183
+
184
+ # @return the block incompressible width
185
+ def getIncompressibleWidth(self):
186
+ return 0
187
+ # # in fact need get nb of cols a
188
+ # nb_cols = len(self)
189
+ # extra_space = (nb_cols - 1.) * self.space
190
+ # extra_space += self.getExtraIncompressibleWidth()
191
+ # return extra_space
192
+ #
193
+ # def getExtraIncompressibleWidth(self):
194
+ # extra_space = 0
195
+ # return extra_space
196
+ #
197
+ # # @return the block incompressible height
198
+ def getIncompressibleHeight(self):
199
+ return 0
200
+ # # in fact need get nb of cols a
201
+ # nb_rows= len(self)
202
+ # extra_space = (nb_rows - 1.) * self.space
203
+ # extra_space += self.getExtraIncompressibleHeight()
204
+ # return extra_space
205
+ #
206
+ # def getExtraIncompressibleHeight(self):
207
+ # extra_space = 0
208
+ # return extra_space
209
+
210
+ def packX(self, space=3):
211
+ last_x = 0
212
+ last_y = 0
213
+
214
+ for i in range(len(self.images)):
215
+ img = self.images[i]
216
+ if i != 0:
217
+ last_x += space
218
+ img.set_P1(last_x, img.get_P1().y())
219
+ last_x = img.boundingRect().x() + img.boundingRect().width()
220
+
221
+ self.updateBoudingRect()
222
+
223
+ def packY(self, space=3):
224
+ last_x = 0
225
+ last_y = 0
226
+
227
+ for i in range(len(self.images)):
228
+ img = self.images[i]
229
+ if i != 0:
230
+ last_y += space
231
+ img.set_P1(img.get_P1().x(), last_y)
232
+ # get all the bounding boxes and pack them with desired space in between
233
+ # get first point and last point in x
234
+ x = img.boundingRect().x()
235
+ y = img.boundingRect().y()
236
+ last_x = img.boundingRect().x() + img.boundingRect().width()
237
+ last_y = img.boundingRect().y() + img.boundingRect().height()
238
+ self.updateBoudingRect()
239
+
240
+ def alignTop(self, updateBounds=False):
241
+ first_left = None
242
+ for img in self:
243
+ cur_pos = img.get_P1()
244
+ if first_left is None:
245
+ first_left = cur_pos
246
+ img.set_P1(cur_pos.x(), first_left.y())
247
+ if updateBounds:
248
+ self.updateMasterRect()
@@ -0,0 +1,96 @@
1
+
2
+
3
+ # TODO recode all from scratch rather than waisting time fixing it
4
+ # do a row kind of element that aligns vertically
5
+
6
+
7
+ # ça marche aussi maintenant reste plus qu'à faire le set width stuff set to width
8
+ def sameHeight(things_to_align, space):
9
+
10
+ print('len(things_to_align)', len(things_to_align))
11
+ if space is None:
12
+ space = 0
13
+ max_height = None
14
+ # try:
15
+ # iter(things_to_align)
16
+ for img in things_to_align:
17
+
18
+ if max_height is None:
19
+ max_height = img.boundingRect().height()
20
+ max_height = max(img.boundingRect().height(), max_height)
21
+ print('TUTU', img, type(img))
22
+ print('TUTA', img, img.boundingRect(), img.boundingRect().height)
23
+ print('TOTO', img, img.boundingRect(), img.boundingRect().height())
24
+
25
+
26
+ # why not looping till the end --> only gets one
27
+ count = 0
28
+ for img in things_to_align:
29
+ print(len(things_to_align), count)
30
+ count+=1
31
+ print('setting to height', max_height)
32
+ print('before 2', type(img))
33
+ img.setToHeight(max_height)
34
+ print('after 2', type(img), img.boundingRect())
35
+
36
+ print('max_height', max_height)
37
+
38
+ packX(things_to_align,space)
39
+ alignTop(things_to_align,updateBounds=False)
40
+ # things_to_align.updateBoudingRect()
41
+
42
+ def packX(things_to_align, space=3):
43
+ last_x = 0
44
+ last_y = 0
45
+
46
+ for i in range(len(things_to_align)):
47
+ img = things_to_align[i]
48
+ if i != 0:
49
+ last_x += space
50
+ img.set_P1(last_x, img.get_P1().y())
51
+ last_x = img.boundingRect().x() + img.boundingRect().width()
52
+
53
+ # things_to_align.updateBoudingRect()
54
+
55
+ def packY(things_to_align, space=3):
56
+ last_x = 0
57
+ last_y = 0
58
+
59
+
60
+ print('1',things_to_align)
61
+
62
+
63
+ for i in range(len(things_to_align)):
64
+ img = things_to_align[i]
65
+ print('2',img)
66
+ if isinstance(img, list):
67
+ from batoolset.draw.widgets.image_group import group
68
+ img = group(*img)
69
+ # should I create a row of objects in fact I need a group and move everything with that --> TODO --> maybe
70
+ if i != 0:
71
+ last_y += space
72
+
73
+ print('img', type(img))
74
+
75
+ img.set_P1(img.get_P1().x(), last_y)
76
+ # get all the bounding boxes and pack them with desired space in between
77
+ # get first point and last point in x
78
+ x = img.boundingRect().x()
79
+ y = img.boundingRect().y()
80
+ last_x = img.boundingRect().x() + img.boundingRect().width()
81
+ last_y = img.boundingRect().y() + img.boundingRect().height()
82
+ # things_to_align.updateBoudingRect()
83
+
84
+
85
+
86
+ # Align vectorial objects to the top
87
+ # in fact should align in y
88
+ def alignTop(things_to_align, updateBounds=False):
89
+ first_left = None
90
+ for img in things_to_align:
91
+ cur_pos = img.get_P1()
92
+ if first_left is None:
93
+ first_left = cur_pos
94
+ img.set_P1(cur_pos.x(), first_left.y())
95
+ # if updateBounds:
96
+ # things_to_align.updateMasterRect()