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,550 @@
|
|
|
1
|
+
# TODO allow text for be written at an angle and determine it size then
|
|
2
|
+
from batoolset.settings.global_settings import set_UI # set the UI to qtpy
|
|
3
|
+
set_UI()
|
|
4
|
+
from batoolset.pyqt.tools import get_painter_transform_and_rotation
|
|
5
|
+
from batoolset.draw.shapes.textorientation import get_angle
|
|
6
|
+
from batoolset.draw.shapes.Position import Position
|
|
7
|
+
from qtpy import QtCore
|
|
8
|
+
from qtpy.QtCore import QRect
|
|
9
|
+
from qtpy.QtGui import QTextDocument, QTextOption
|
|
10
|
+
from qtpy.QtGui import QPainter, QImage, QColor, QFont, QBrush, QTransform
|
|
11
|
+
from qtpy.QtCore import QRectF, QPointF
|
|
12
|
+
import sys
|
|
13
|
+
from qtpy import QtGui
|
|
14
|
+
from qtpy.QtCore import Qt
|
|
15
|
+
from qtpy.QtWidgets import QApplication
|
|
16
|
+
from batoolset.draw.shapes.rectangle2d import Rectangle2D
|
|
17
|
+
# log errors
|
|
18
|
+
from batoolset.tools.logger import TA_logger
|
|
19
|
+
logger = TA_logger()
|
|
20
|
+
|
|
21
|
+
class TAText2D(Rectangle2D):
|
|
22
|
+
|
|
23
|
+
# TODO add bg to it so that it can be drawn
|
|
24
|
+
def __init__(self, text=None, doc=None, opacity=1.,x=None, y=None, fill_color=None, color=None, text_orientation='X',placement=Position(),range=None, is_letter=False,__version=1.0,*args, **kwargs):
|
|
25
|
+
if doc is not None and isinstance(doc, QTextDocument):
|
|
26
|
+
self.doc = doc
|
|
27
|
+
self.doc.setDocumentMargin(0) # important so that the square is properly placed
|
|
28
|
+
# self.text = self.doc.toHtml()
|
|
29
|
+
else:
|
|
30
|
+
self.doc = QTextDocument()
|
|
31
|
+
self.doc.setDocumentMargin(0) # important so that the square is properly placed
|
|
32
|
+
|
|
33
|
+
textOption = self.doc.defaultTextOption()
|
|
34
|
+
textOption.setWrapMode(QTextOption.NoWrap)
|
|
35
|
+
self.doc.setDefaultTextOption(textOption)
|
|
36
|
+
|
|
37
|
+
if text is not None:
|
|
38
|
+
self.doc.setHtml(text)
|
|
39
|
+
# self.setText(text)
|
|
40
|
+
# else:
|
|
41
|
+
# self.setText('')
|
|
42
|
+
# self.text = text
|
|
43
|
+
# self.isSet = True
|
|
44
|
+
self.doc.adjustSize()
|
|
45
|
+
size = self.getSize()
|
|
46
|
+
|
|
47
|
+
super(TAText2D, self).__init__(x if x is not None else 0, y if y is not None else 0, size.width(), size.height())
|
|
48
|
+
self.opacity = opacity
|
|
49
|
+
self.immutable=True
|
|
50
|
+
self.line_style = None # useless just for compat with other shapes
|
|
51
|
+
if placement is not None:
|
|
52
|
+
if not isinstance(placement, Position):
|
|
53
|
+
placement = Position(placement)
|
|
54
|
+
self.placement = placement
|
|
55
|
+
self.fill_color = fill_color
|
|
56
|
+
self.color = color
|
|
57
|
+
self.text_orientation = text_orientation
|
|
58
|
+
self.range = range # this will contain the spanning of text over several elements only used and useful for text rows
|
|
59
|
+
self.__version = __version
|
|
60
|
+
self.is_letter = is_letter
|
|
61
|
+
# if x is not None:
|
|
62
|
+
# self.setX(x)
|
|
63
|
+
# if y is not None:
|
|
64
|
+
# self.setY(y)
|
|
65
|
+
|
|
66
|
+
def set_range(self, range):
|
|
67
|
+
# this is the range of labels in text rows
|
|
68
|
+
self.range = range
|
|
69
|
+
|
|
70
|
+
def set_opacity(self, opacity):
|
|
71
|
+
self.opacity = opacity
|
|
72
|
+
|
|
73
|
+
def setText(self, html):
|
|
74
|
+
self.doc.setHtml(html)
|
|
75
|
+
# self.doc.adjustSize()
|
|
76
|
+
# size = self.getSize()
|
|
77
|
+
# self.setWidth(size.width())
|
|
78
|
+
# self.setHeight(size.height())
|
|
79
|
+
self.setDoc(self.doc)
|
|
80
|
+
# self.text = html
|
|
81
|
+
|
|
82
|
+
def setDoc(self, doc):
|
|
83
|
+
self.doc = doc
|
|
84
|
+
self.doc.setDocumentMargin(0)
|
|
85
|
+
self.doc.adjustSize()
|
|
86
|
+
size = self.getSize()
|
|
87
|
+
self.setWidth(size.width())
|
|
88
|
+
self.setHeight( size.height())
|
|
89
|
+
# self.text = self.getHtmlText()
|
|
90
|
+
|
|
91
|
+
def draw(self, painter, draw=True, parent=None):
|
|
92
|
+
if draw:
|
|
93
|
+
self.scale=1 # TODO FIX THIS BETTER TATEXT SHOULD NEVER BE RESCALED just a hack so that the scale is always preserved (importantly the square is properly positioned but the text is not (probably needs be cntered on the rect center) no big deal I guess
|
|
94
|
+
painter.save()
|
|
95
|
+
|
|
96
|
+
# transform = QTransform()
|
|
97
|
+
# transform.rotate(0) # Rotate 45 degrees clockwise
|
|
98
|
+
# painter.setWorldTransform(transform)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# Get the rotation angle of the transform
|
|
102
|
+
# Get the current transformation and rotation
|
|
103
|
+
|
|
104
|
+
# transform, rotation_angle = get_painter_transform_and_rotation(painter) # this is ok --> this is 0
|
|
105
|
+
# print(f"Current transformation matrix: {transform}")
|
|
106
|
+
# print(f"Current rotation angle: {rotation_angle:.2f} degrees")
|
|
107
|
+
|
|
108
|
+
painter.setPen(Qt.NoPen)
|
|
109
|
+
painter.setBrush(Qt.NoBrush)
|
|
110
|
+
|
|
111
|
+
# Get the current clip rect of the painter
|
|
112
|
+
# current_clip_rect = painter.clipBoundingRect()
|
|
113
|
+
# print('current_clip_rect',current_clip_rect)
|
|
114
|
+
|
|
115
|
+
# print('self.placement, self.placement.isEmpty()',self.placement, self.placement.isEmpty())
|
|
116
|
+
|
|
117
|
+
rect_to_plot = self.getRect(scale=True)
|
|
118
|
+
if self.placement is None or self.placement.isEmpty():
|
|
119
|
+
# if True:
|
|
120
|
+
# painter.setClipRect(self.getRect(scale=True)) # in fact this is needed to get text to work!!! # DO NOT DO THIS OTHERWISE THE TEXT IS NOT CLIPPED WHICH IS NOT WHAT I WANT!!!!
|
|
121
|
+
# if text --> need center v or h --> TODO
|
|
122
|
+
# else:
|
|
123
|
+
rect_to_plot = self.getRect(scale=True)
|
|
124
|
+
|
|
125
|
+
if parent is not None and parent.scale is not None and parent.scale != 1:
|
|
126
|
+
rect_to_plot = QRectF(rect_to_plot.x() / parent.scale, rect_to_plot.y() / parent.scale, rect_to_plot.width() / parent.scale,rect_to_plot.height() / parent.scale)
|
|
127
|
+
# neo
|
|
128
|
+
# rect_to_plot = self.getRect(scale=True)
|
|
129
|
+
# rect_to_plot.setX(rect_to_plot.x()/parent.scale)
|
|
130
|
+
# rect_to_plot.setY(rect_to_plot.y()/parent.scale) # now this shit is huge
|
|
131
|
+
# somehow this is required for text but why ????
|
|
132
|
+
|
|
133
|
+
# print('rect_to_plot', rect_to_plot)
|
|
134
|
+
if parent is not None:
|
|
135
|
+
rect_to_plot = rect_to_plot.translated(parent.topLeft())
|
|
136
|
+
# print('rect_to_plot2',rect_to_plot)
|
|
137
|
+
|
|
138
|
+
#DEBUG
|
|
139
|
+
if False:
|
|
140
|
+
painter.setPen(QtCore.Qt.red)
|
|
141
|
+
painter.drawRect(rect_to_plot)
|
|
142
|
+
|
|
143
|
+
# do not move this, this is where the fill color should be applied
|
|
144
|
+
if self.fill_color:
|
|
145
|
+
# if isinstance(self.fill_color, QColor):
|
|
146
|
+
# self.fill_color = self.fill_color.rgb() & 0xFFFFFF
|
|
147
|
+
|
|
148
|
+
# print(self, self.fill_color, 'inside drawing')
|
|
149
|
+
|
|
150
|
+
# somehow the rect pos is completely wrong
|
|
151
|
+
|
|
152
|
+
# painter.setPen(QtCore.Qt.red)
|
|
153
|
+
painter.setBrush(QBrush(QColor(self.fill_color)))
|
|
154
|
+
painter.save()
|
|
155
|
+
|
|
156
|
+
# all seems to be fixed now but allI do here is totally crazy -−> DO A CLEAN FIX OF THE STUFF SOME DAY
|
|
157
|
+
rect2 =QRectF(rect_to_plot.x(), rect_to_plot.y(), rect_to_plot.width(), rect_to_plot.height())
|
|
158
|
+
text_width = self.doc.documentLayout().documentSize().width()
|
|
159
|
+
text_height = self.doc.documentLayout().documentSize().height()
|
|
160
|
+
# very dirty fix I have to fix all more poperly some day this is totally abnormal that I have to do all of this !!! --< now that fixes the size but not the position --> somehow I am missing something still
|
|
161
|
+
rect2.setWidth(text_width)
|
|
162
|
+
rect2.setHeight(text_height)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
# this is not totally ok
|
|
169
|
+
if self.text_orientation is not None and not 'X' in self.text_orientation:
|
|
170
|
+
# painter.translate(rect_to_plot.center())
|
|
171
|
+
# painter.rotate(90)
|
|
172
|
+
# painter.translate(-(rect_to_plot.center()))
|
|
173
|
+
# painter.translate(-)
|
|
174
|
+
painter.translate(rect_to_plot.topLeft())
|
|
175
|
+
painter.translate(rect_to_plot.height(), 0)
|
|
176
|
+
painter.rotate(get_angle(self.text_orientation))
|
|
177
|
+
painter.translate(-rect_to_plot.topLeft()) # presque -−> doit etre aligne au coin gaughe
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
# else:
|
|
181
|
+
painter.translate(rect_to_plot.center() - rect2.center())
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
painter.drawRect(rect2)
|
|
185
|
+
painter.restore()
|
|
186
|
+
# self.doc.drawContents(painter)
|
|
187
|
+
|
|
188
|
+
# this is positioned properly so why isn't text positioned there too!!! ???
|
|
189
|
+
|
|
190
|
+
# self.doc.drawContents(painter)
|
|
191
|
+
|
|
192
|
+
# if self.theta is not None and self.theta != 0:
|
|
193
|
+
if self.theta is not None and self.theta != 0:
|
|
194
|
+
# I have added support for rotation to that maybe I will need something smarter if rotation 90 degrees or flips and images no same width and height
|
|
195
|
+
painter.translate(rect_to_plot.center())
|
|
196
|
+
painter.rotate(self.theta)
|
|
197
|
+
painter.translate(-rect_to_plot.center())
|
|
198
|
+
|
|
199
|
+
if self.text_orientation is not None and not 'X' in self.text_orientation: # self.text_orientation is not None: # and not 'X' in self.text_orientation
|
|
200
|
+
# very good -> that does the job --> the only thing is that of course it selection is not correct --> need fix it
|
|
201
|
+
painter.translate(rect_to_plot.topLeft())
|
|
202
|
+
painter.translate(rect_to_plot.height(), 0)
|
|
203
|
+
painter.rotate(get_angle(self.text_orientation))
|
|
204
|
+
painter.translate(-rect_to_plot.topLeft()) # presque -−> doit etre aligne au coin gaughe
|
|
205
|
+
# painter.translate(rect_to_plot.height(),0) # presque -−> doit etre aligne au coin gaughe
|
|
206
|
+
|
|
207
|
+
# self.doc.drawContents(painter)
|
|
208
|
+
# if True: #TODO remove that debug only
|
|
209
|
+
# painter.drawRect(rect_to_plot)
|
|
210
|
+
|
|
211
|
+
# if self.opacity is not None:
|
|
212
|
+
# painter.setOpacity(self.opacity)
|
|
213
|
+
|
|
214
|
+
# if False:
|
|
215
|
+
painter.translate(rect_to_plot.x(), rect_to_plot.y())
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
if False:
|
|
220
|
+
text_width = self.doc.documentLayout().documentSize().width()
|
|
221
|
+
text_height = self.doc.documentLayout().documentSize().height()
|
|
222
|
+
# rect_of_doc = self.doc.documentRect()
|
|
223
|
+
painter.setClipRect(QRectF(rect_to_plot.x(), rect_to_plot.y(),min(text_width, rect_to_plot.width()),min(text_height, rect_to_plot.height())))
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
if True:
|
|
228
|
+
text_width = self.doc.documentLayout().documentSize().width()
|
|
229
|
+
text_height = self.doc.documentLayout().documentSize().height()
|
|
230
|
+
# print('text_width, text_height',text_width, text_height, rect_to_plot, 'BINGO BINGO2')
|
|
231
|
+
painter.translate((rect_to_plot.width()-text_width)/2, (rect_to_plot.height()-text_height)/2) # le bug est bien ici --> somehow the rect is still not correct and wrongly scaled --> what is the bug ?
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
# with that the rect size is ok but the position is completely crap
|
|
235
|
+
# if self.fill_color:
|
|
236
|
+
# text_width = self.doc.documentLayout().documentSize().width()
|
|
237
|
+
# text_height = self.doc.documentLayout().documentSize().height()
|
|
238
|
+
# # very dirty fix I have to fix all more poperly some day this is totally abnormal that I have to do all of this !!! --< now that fixes the size but not the position --> somehow I am missing something still
|
|
239
|
+
# rect_to_plot.setWidth(text_width)
|
|
240
|
+
# rect_to_plot.setHeight(text_height)
|
|
241
|
+
# painter.setBrush(QBrush(QColor(self.fill_color)))
|
|
242
|
+
# painter.drawRect(rect_to_plot)
|
|
243
|
+
|
|
244
|
+
# painter.translate(self.x()+self.width()/2., self.y()+self.height()/2.) # if I do that the square and the
|
|
245
|
+
|
|
246
|
+
# here I need a cliprect of just the size of the stuff and not even that but the intersection with the parent
|
|
247
|
+
# painter.translate(-rect_to_plot.center())
|
|
248
|
+
|
|
249
|
+
# shall I get the rect of the doc and see if it fits the other otherwise probably I need to center it at least I can check that
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
# not 'X' in self.text_orientation
|
|
253
|
+
if self.text_orientation and '-' in self.text_orientation:# self.text_orientation and '-' in self.text_orientation:
|
|
254
|
+
painter.rotate(180) # ok but the pb is then I need to shift it back again
|
|
255
|
+
painter.translate(-rect_to_plot.width(), -rect_to_plot.height())
|
|
256
|
+
|
|
257
|
+
# painter.setWorldTransform(QTransform())
|
|
258
|
+
#
|
|
259
|
+
# transform, rotation_angle = get_painter_transform_and_rotation(painter) # this is ok --> this is 0
|
|
260
|
+
# print(f"DEBUG Current transformation matrix: {transform}")
|
|
261
|
+
# print(f"Current rotation angle: {rotation_angle:.2f} degrees")
|
|
262
|
+
# print(self.text_orientation, '-->',get_angle(self.text_orientation)) # NO BUG IS THERE YET RANDOM ....
|
|
263
|
+
# painter.resetTransform()
|
|
264
|
+
self.doc.drawContents(painter)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
painter.restore()
|
|
274
|
+
# maybe activate this upon debug
|
|
275
|
+
# painter.save()
|
|
276
|
+
# painter.setPen(QtCore.Qt.red)
|
|
277
|
+
# painter.drawRect(self)
|
|
278
|
+
# painter.restore()
|
|
279
|
+
|
|
280
|
+
# def set_to_scale(self, factor): # this object should not be rescalable
|
|
281
|
+
# raise Exception('this should not be called --> this creates a bug because the size fo this object is immutable')
|
|
282
|
+
# self.scale = 1
|
|
283
|
+
|
|
284
|
+
def boundingRect(self): # is that ok also
|
|
285
|
+
return self
|
|
286
|
+
|
|
287
|
+
def getSize(self): # is that ok ???
|
|
288
|
+
return self.doc.size()
|
|
289
|
+
|
|
290
|
+
def getWidth(self):
|
|
291
|
+
return self.boundingRect().width()
|
|
292
|
+
|
|
293
|
+
def getHeight(self):
|
|
294
|
+
return self.boundingRect().height()
|
|
295
|
+
|
|
296
|
+
def setText(self, text):
|
|
297
|
+
self.doc.setHtml(text)
|
|
298
|
+
# size = self.size()
|
|
299
|
+
# self.setWidth(size.width(), size.height())
|
|
300
|
+
self.setDoc(self.doc)
|
|
301
|
+
|
|
302
|
+
# def sync_text(self): # TODO always make sure to call this whenever a change to the text is made -−> will ease the serialization
|
|
303
|
+
# self.text = self.getHtmlText()
|
|
304
|
+
|
|
305
|
+
def getRect(self,*args, **kwargs):
|
|
306
|
+
# print('self.scale of the text', self.scale)
|
|
307
|
+
|
|
308
|
+
text_width = self.doc.documentLayout().documentSize().width()
|
|
309
|
+
text_height = self.doc.documentLayout().documentSize().height()
|
|
310
|
+
# if args:
|
|
311
|
+
if args or kwargs:
|
|
312
|
+
rect = QRectF(self.x()*self.scale, self.y()*self.scale, text_width, text_height)
|
|
313
|
+
if self.text_orientation is not None and not 'X' in self.text_orientation and 'all' in kwargs:
|
|
314
|
+
t = QTransform().translate(rect.x(), rect.y()).translate(rect.height(),0).rotate(90).translate(-rect.x(), -rect.y())
|
|
315
|
+
rotatedPolygon = t.mapToPolygon(rect.toRect()) # Map the rectangle to a rotated polygon
|
|
316
|
+
|
|
317
|
+
# Create a QRectF from the bounding rectangle of the rotated polygon
|
|
318
|
+
rotatedRect = rotatedPolygon.boundingRect()
|
|
319
|
+
rotatedRect = QRectF(rotatedRect.x(), rotatedRect.y(), rotatedRect.width(), rotatedRect.height())
|
|
320
|
+
rect = rotatedRect
|
|
321
|
+
return rect
|
|
322
|
+
else:
|
|
323
|
+
# if args or kwargs:
|
|
324
|
+
return QRectF(self.x(), self.y(), text_width, text_height)
|
|
325
|
+
|
|
326
|
+
def width(self, *args, **kwargs):
|
|
327
|
+
return self.getRect(*args, **kwargs).width()
|
|
328
|
+
|
|
329
|
+
def height(self, *args, **kwargs):
|
|
330
|
+
return self.getRect(*args, **kwargs).height()
|
|
331
|
+
|
|
332
|
+
# def getRect(self,*args, **kwargs):
|
|
333
|
+
# if args or kwargs:
|
|
334
|
+
# if 'all' in kwargs:
|
|
335
|
+
# # print('in there!')
|
|
336
|
+
# # rect_to_plot = QRectF(*super().getRect())#QRectF(self.x(), self.y(), self.width() / self.scale, self.height() / self.scale)
|
|
337
|
+
# rect_to_plot = QRectF(self.x(), self.y(), self.width() / self.scale, self.height() / self.scale)
|
|
338
|
+
# center = rect_to_plot.center()
|
|
339
|
+
# if self.theta:
|
|
340
|
+
# # t = QTransform().translate(center.x(), center.y()).rotate(self.theta).translate(-center.x(),-center.y())
|
|
341
|
+
# # rotatedRect = t.mapToPolygon(rect_to_plot.toRect()) # // mapRect() returns the bounding rect
|
|
342
|
+
# t = QTransform().translate(center.x(), center.y()).rotate(self.theta).translate(-center.x(),
|
|
343
|
+
# -center.y())
|
|
344
|
+
# rotatedPolygon = t.mapToPolygon(rect_to_plot.toRect()) # Map the rectangle to a rotated polygon
|
|
345
|
+
#
|
|
346
|
+
# # Create a QRectF from the bounding rectangle of the rotated polygon
|
|
347
|
+
# rotatedRect = QRectF(rotatedPolygon.boundingRect())
|
|
348
|
+
# else:
|
|
349
|
+
# return rect_to_plot
|
|
350
|
+
# try:
|
|
351
|
+
# return QRectF(rotatedRect.boundingRect())
|
|
352
|
+
# except:
|
|
353
|
+
# return rotatedRect
|
|
354
|
+
# # return QRectF(self.x(), self.y(), self.width() / self.scale, self.height() / self.scale)
|
|
355
|
+
# else:
|
|
356
|
+
# # default to scaled object
|
|
357
|
+
# return QRectF(self.x(), self.y(), self.width()/self.scale, self.height()/self.scale)
|
|
358
|
+
|
|
359
|
+
# def __getstate__(self):
|
|
360
|
+
# # Return a dictionary containing the state of the object
|
|
361
|
+
# return {'text': self.getHtmlText()}
|
|
362
|
+
#
|
|
363
|
+
# def __setstate__(self, state):
|
|
364
|
+
# # Set the state of the object from the dictionary
|
|
365
|
+
# self.setText(state['text'])
|
|
366
|
+
|
|
367
|
+
# shall I rather compute its size including the roitation so that it never gets truncated --> that does make sense -−> need compute the bounds of the rotated stuff
|
|
368
|
+
# and the incompressible size should also depend on that
|
|
369
|
+
|
|
370
|
+
# def getIncompressibleWidth(self):
|
|
371
|
+
# # TODO in fact take the rotated size --> much smarter here --> see how I can do
|
|
372
|
+
# return self.width()
|
|
373
|
+
#
|
|
374
|
+
# def getIncompressibleHeight(self):
|
|
375
|
+
# return self.height()
|
|
376
|
+
#
|
|
377
|
+
# def get_incompressible_size(self, axis=None):
|
|
378
|
+
# # if True:
|
|
379
|
+
# # return self.width()
|
|
380
|
+
# # if self.theta is not None:
|
|
381
|
+
# # get width and or height
|
|
382
|
+
# if axis:
|
|
383
|
+
# if axis == 'X':
|
|
384
|
+
# return self.getIncompressibleWidth()
|
|
385
|
+
# else:
|
|
386
|
+
# return self.getIncompressibleHeight()
|
|
387
|
+
|
|
388
|
+
def setTopLeft(self, *args):
|
|
389
|
+
if args:
|
|
390
|
+
# cur_top_left = self.topLeft()
|
|
391
|
+
# print('cur_top_left', cur_top_left, args)
|
|
392
|
+
if len(args)==1:
|
|
393
|
+
# # assume a QpointF
|
|
394
|
+
self.moveTo(args[0].x(), args[0].y())
|
|
395
|
+
elif len(args) == 2:
|
|
396
|
+
self.moveTo(QPointF(args[0], args[1]))
|
|
397
|
+
# self.update_bounds()
|
|
398
|
+
# elif len(args)==2:
|
|
399
|
+
# for img in self.content:
|
|
400
|
+
# img.moveTopLeft(QPointF(args[0], args[1]))
|
|
401
|
+
# else:
|
|
402
|
+
# # logger.error('invalid args for top left')
|
|
403
|
+
# print('invalid args for top left')
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
# def set_P1(self, *args):
|
|
407
|
+
# if not args:
|
|
408
|
+
# logger.error("no coordinate set...")
|
|
409
|
+
# return
|
|
410
|
+
# if len(args) == 1:
|
|
411
|
+
# self.moveTo(args[0].x(), args[0].y())
|
|
412
|
+
# else:
|
|
413
|
+
# self.moveTo(QPointF(args[0], args[1]))
|
|
414
|
+
#
|
|
415
|
+
# def get_P1(self):
|
|
416
|
+
# return QPointF(self.x(), self.y())
|
|
417
|
+
|
|
418
|
+
def getPlainText(self):
|
|
419
|
+
return self.doc.toPlainText()
|
|
420
|
+
|
|
421
|
+
def getHtmlText(self):
|
|
422
|
+
return self.doc.toHtml()
|
|
423
|
+
|
|
424
|
+
def __repr__(self):
|
|
425
|
+
class_name = type(self).__name__
|
|
426
|
+
memory_address = hex(id(self))
|
|
427
|
+
return f"{class_name}-{memory_address}"
|
|
428
|
+
|
|
429
|
+
def to_dict(self):
|
|
430
|
+
x = self.x()
|
|
431
|
+
y = self.y()
|
|
432
|
+
# width = self.width()
|
|
433
|
+
# height = self.height()
|
|
434
|
+
|
|
435
|
+
# Create a dictionary representation of the values of the super object
|
|
436
|
+
output_dict = {
|
|
437
|
+
'x': x,
|
|
438
|
+
'y': y,
|
|
439
|
+
'text': self.getHtmlText(),
|
|
440
|
+
|
|
441
|
+
# 'width': width,
|
|
442
|
+
# 'height': height,
|
|
443
|
+
# 'args':self.filename,
|
|
444
|
+
# 'filename':self.filename,
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
# print(output_dict)
|
|
448
|
+
# Update the dictionary with the __dict__ of Rectangle2D
|
|
449
|
+
output_dict.update(self.__dict__) # not smart because overrides the outputdict
|
|
450
|
+
|
|
451
|
+
output_dict['range']=self.range if self.range is None else str(self.range) # force convert it to text]
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
return output_dict
|
|
455
|
+
|
|
456
|
+
if __name__ == '__main__':
|
|
457
|
+
# this could be a pb ...
|
|
458
|
+
app = QApplication(sys.argv)# IMPORTANT KEEP !!!!!!!!!!!
|
|
459
|
+
|
|
460
|
+
# window = MyWidget()
|
|
461
|
+
# window.show()
|
|
462
|
+
|
|
463
|
+
# ça marche car ça override la couleur par defaut du truc
|
|
464
|
+
# c'est parfait et 2000X plus facile que ds java --> cool
|
|
465
|
+
|
|
466
|
+
html = '''
|
|
467
|
+
<!DOCTYPE html>
|
|
468
|
+
<html>
|
|
469
|
+
<head>
|
|
470
|
+
<title>Font Face</title>
|
|
471
|
+
</head>
|
|
472
|
+
<body>
|
|
473
|
+
<font color="red">
|
|
474
|
+
<font face="Symbol" size="5">Symbol</font><br />
|
|
475
|
+
<font face="Times New Roman" size="5">Times New Roman</font><br />
|
|
476
|
+
<font face="Verdana" size="5">Verdana</font><br />
|
|
477
|
+
<font face="Comic Sans MS" size="5">Comic Sans MS</font><br />
|
|
478
|
+
<font face="WildWest" size="5">WildWest</font><br />
|
|
479
|
+
<font face="Bedrock" size="5">Bedrock</font><br />
|
|
480
|
+
</font>
|
|
481
|
+
</body>
|
|
482
|
+
</html>
|
|
483
|
+
'''
|
|
484
|
+
|
|
485
|
+
# html = "<font color=blue size=24>this is a test<sup>2</sup><br></font><font color=green size=12>continued<sub>1</sub><br></font><font color=white size=12>test greek <font face='Symbol' size=32>a</font> another α<font face='Arial' color='Orange'>I am a sentence!</font>"
|
|
486
|
+
text = TAText2D(html)
|
|
487
|
+
|
|
488
|
+
# hexagon.append(QPointF(10, 20))
|
|
489
|
+
print(text)
|
|
490
|
+
|
|
491
|
+
# print(hexagon.translate(10, 20)) # why none ???
|
|
492
|
+
# translate and so on can all be saved...
|
|
493
|
+
|
|
494
|
+
image = QImage('/E/Sample_images/sample_images_PA/mini/focused_Series012/handCorrection.png')
|
|
495
|
+
# image = QImage(QSize(400, 300), QImage.Format_RGB32)
|
|
496
|
+
painter = QPainter()
|
|
497
|
+
painter.begin(image)
|
|
498
|
+
# painter.setOpacity(0.3);
|
|
499
|
+
painter.drawImage(0, 0, image)
|
|
500
|
+
painter.setPen(QtCore.Qt.blue)
|
|
501
|
+
text.opacity = 0.7
|
|
502
|
+
painter.translate(10, 20)
|
|
503
|
+
painter.setPen(QColor(168, 34, 3))
|
|
504
|
+
|
|
505
|
+
text.draw(painter) # ça marche pourrait overloader ça avec du svg
|
|
506
|
+
|
|
507
|
+
painter.drawRect(text)# try to draw the bounds
|
|
508
|
+
|
|
509
|
+
# painter.setPen(QtCore.Qt.green)
|
|
510
|
+
# painter.setFont(QFont('SansSerif', 50))
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
painter.setFont(QFont('Decorative', 10))
|
|
514
|
+
painter.drawText(256, 256, "this is a test")
|
|
515
|
+
|
|
516
|
+
# nothing works it just doesn't draw for unknown reason ????
|
|
517
|
+
# painter.drawText(QRect(60,60,256,256), Qt.AlignCenter, "this is a test")
|
|
518
|
+
|
|
519
|
+
painter.setPen(QtGui.QColor(0, 255, 255)) # colors are weird !!!
|
|
520
|
+
# painter.drawText(20, 20, "MetaGenerator") # fait planter le soft --> pkoi exit(139) ...
|
|
521
|
+
painter.drawText(QRect(60,60,256,256), Qt.AlignCenter, "Text centerd in the drawing area")
|
|
522
|
+
|
|
523
|
+
# painter.drawText(QRect(100, 100, 200, 100), "Text you want to draw...");
|
|
524
|
+
print('here')
|
|
525
|
+
painter.end()
|
|
526
|
+
|
|
527
|
+
# image = QImage(QSize(400, 300), QImage::Format_RGB32);
|
|
528
|
+
# QPainter
|
|
529
|
+
# painter( & image);
|
|
530
|
+
# painter.setBrush(QBrush(Qt::green));
|
|
531
|
+
# painter.fillRect(QRectF(0, 0, 400, 300), Qt::green);
|
|
532
|
+
# painter.fillRect(QRectF(100, 100, 200, 100), Qt::white);
|
|
533
|
+
# painter.setPen(QPen(Qt::black));
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
# painter.save()
|
|
537
|
+
# painter.setCompositionMode(QtGui.QPainter.CompositionMode_Clear)
|
|
538
|
+
# painter.eraseRect(r)
|
|
539
|
+
# painter.restore()
|
|
540
|
+
print('saving', '/E/trash//test_pyQT_draw_text.png')
|
|
541
|
+
image.save('/E/trash/test_pyQT_draw_text.png', "PNG")
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
# split text and find bounding rect of the stuff --> so that it is well positioned
|
|
545
|
+
# or do everything in svg and just show what's needed ???
|
|
546
|
+
|
|
547
|
+
#pas mal TODO faire une classe drawsmthg qui dessine n'importe quelle forme que l'on lui passe avec des parametres de couleur, transparence, ...
|
|
548
|
+
|
|
549
|
+
# tt marche aps mal ça va très vite
|
|
550
|
+
sys.exit(0)
|
|
File without changes
|