Beispiel #1
0
def setToHeight(space, height_in_px, *objects):
    if height_in_px is None:
        return
    bounds = updateBoudingRect(*objects)
    left = Point2D(bounds.topLeft())
    for img in objects:
        img.setToHeight(height_in_px)
    packX(space, left, *objects)
Beispiel #2
0
def setToWidth2(space, width_in_px, *objects):
    if width_in_px is None:
        return
    bounds = updateBoudingRect(*objects)
    left = Point2D(bounds.topLeft())
    for img in objects:
        img.setToWidth(width_in_px)
    packY(space, left, *objects)
Beispiel #3
0
 def setToHeight(self, height_in_px):
     if height_in_px is None:
         return
     # # nb_cols = len(self)
     # pure_image_height = (self.boundingRect().height()) - self.getIncompressibleHeight()
     # # print(width_in_px, self.getIncompressibleWidth(), (nb_cols - 1.) * self.space )
     # height_in_px -= self.getIncompressibleHeight()
     # ratio = height_in_px / pure_image_height
     # for img in self:
     #     img.setToHeight(img.boundingRect().height() * ratio)
     # self.packX(self.space)
     # self.updateBoudingRect()
     topleft = Point2D(self.boundingRect().topLeft())
     alignTop(topleft, *self.images)
     setToHeight(self.space, height_in_px, *self.images)
     self.updateBoudingRect()
Beispiel #4
0
def setToHeight2(space, height_in_px, *objects):
    if height_in_px is None:
        return
    bounds = updateBoudingRect(*objects)
    left = Point2D(bounds.topLeft())
    incompressible_height = 0
    for img in objects:
        incompressible_height += img.getIncompressibleHeight()
    # si row doit maintenir same height until reached desired width is reached --> change its width --> doit aussi connaitre la incompressible height des objects
    pure_image_height = (bounds.height()) - incompressible_height
    # print(width_in_px, self.getIncompressibleWidth(), (nb_cols - 1.) * self.space )
    height_in_px -= incompressible_height
    ratio = height_in_px / pure_image_height
    for img in objects:
        img.setToHeight(img.boundingRect().height() * ratio)
    packY(space, left, *objects)
Beispiel #5
0
    def setToWidth(self, width_in_px):
        if width_in_px is None:
            return
        # nb_cols = len(self)

        # probably need do more complex stuff here and take or not scaled size --> TODO
        # in fact c'est l'original size que je veux ???
        # pure_image_width = (self.boundingRect().width()) - self.getIncompressibleWidth()
        # # print(width_in_px, self.getIncompressibleWidth(), (nb_cols - 1.) * self.space )
        # width_in_px -= self.getIncompressibleWidth()
        # ratio = width_in_px / pure_image_width
        # for img in self:
        #     img.setToWidth(img.boundingRect().width() * ratio)
        # self.packY(self.space)
        # self.updateBoudingRect()
        topleft = Point2D(self.boundingRect().topLeft())
        alignLeft(topleft, *self.images)
        setToWidth2(self.space, width_in_px, *self.images)
Beispiel #6
0
    def __init__(self, parent=None, demo=False):
        QtWidgets.QWidget.__init__(self, parent)
        self.shapes_to_draw = []
        self.lastPoint = None
        if demo:
            self.shapes_to_draw.append(
                Polygon2D(0, 0, 10, 0, 10, 20, 0, 20, 0, 0, color=0x00FF00))
            self.shapes_to_draw.append(
                Polygon2D(100,
                          100,
                          110,
                          100,
                          110,
                          120,
                          10,
                          120,
                          100,
                          100,
                          color=0x0000FF,
                          fill_color=0x00FFFF,
                          stroke=2))
            self.shapes_to_draw.append(
                Line2D(0, 0, 110, 100, color=0xFF0000, stroke=3))
            self.shapes_to_draw.append(Rect2D(200, 150, 250, 100, stroke=10))
            self.shapes_to_draw.append(Ellipse2D(0, 50, 600, 200, stroke=3))
            self.shapes_to_draw.append(Circle2D(150, 300, 30, color=0xFF0000))
            self.shapes_to_draw.append(
                PolyLine2D(10,
                           10,
                           20,
                           10,
                           20,
                           30,
                           40,
                           30,
                           color=0xFF0000,
                           stroke=2))
            self.shapes_to_draw.append(
                PolyLine2D(10,
                           10,
                           20,
                           10,
                           20,
                           30,
                           40,
                           30,
                           color=0xFF0000,
                           stroke=2))
            self.shapes_to_draw.append(
                Point2D(128, 128, color=0xFF0000, stroke=6))
            self.shapes_to_draw.append(
                Point2D(128, 128, color=0x00FF00, stroke=1))
            self.shapes_to_draw.append(
                Point2D(10, 10, color=0x000000, stroke=6))

            self.shapes_to_draw.append(
                Rect2D(0, 0, 512, 512, color=0xFF00FF, stroke=6))
            img0 = Image2D(
                '/media/D/Sample_images/sample_images_PA/trash_test_mem/counter/00.png'
            )
            # img0 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # size is not always respected and that is gonna be a pb but probably size would be ok for journals as they would not want more than 14 pt size ????

            # ci dessous la font size marche mais je comprend rien ... pkoi ça marche et l'autre marche pas les " et ' ou \' ont l'air clef...
            # in fact does not work font is super small
            # img0.setLetter(TAText2D(text='<font face="Comic Sans Ms" size=\'12\' color=yellow ><font size=`\'12\'>this is a <br>test</font></font>'))
            # img0.setLetter(TAText2D(text='<font face="Comic Sans Ms" color=yellow ><font size=12 >this is a <br>test</font></font>'))
            # img0.setLetter(TAText2D("<p style='font-size: large; font-color: yellow;'><b>Serial Number:</b></p> "))
            # a l'air de marcher mais à tester
            # img0.setLetter(TAText2D('<html><body><p><font face="verdana" color="yellow" size="2000">font_face = "verdana"font_color = "green"font_size = 3</font></html>'))

            # try that https://www.learnpyqt.com/examples/megasolid-idiom-rich-text-editor/
            # img0.setLetter(TAText2D(text='<html><font face="times" size=3 color=yellow>test</font></html>'))
            # img0.setLetter(TAText2D(text="<p style='font-size: 12pt; font-style: italic; font-weight: bold; color: yellow; text-align: center;'> <u>Don't miss it</u></p><p style='font-size: 12pt; font-style: italic; font-weight: bold; color: yellow; text-align: center;'> <u>Don't miss it</u></p>"))

            # this is really a one liner but a bit complex to do I find
            # chaque format different doit etre dans un span different --> facile
            # ça marche mais voir comment faire ça
            img0.setLetter(
                TAText2D(
                    text=
                    '<p style="text-align:left;color: yellow">This text is left aligned <span style="float:right;font-style: italic;font-size: 8pt;"> This text is right aligned </span><span style="float:right;font-size: 4pt;color:red"> This text is another text </span></p>'
                ))

            img1 = Image2D(
                '/media/D/Sample_images/sample_images_PA/trash_test_mem/counter/01.png'
            )
            # img1 = Image2D('D:/dataset1/unseen/focused_Series012.png')
            # img1.setLetter(TAText2D(text="<font face='Comic Sans Ms' size=16 color='blue' >this is a <br>test</font>"))
            # ça ça marche vraiment en fait --> use css to write my text instead of that

            # ça ça a l'air de marcher --> pas trop mal en fait du coup
            # ça a l'air de marcher maintenant --> could use that and do a converter for ezfig ???
            # img1.setLetter(TAText2D(text="<span style='font-size: 12pt; font-style: italic; font-weight: bold; color: yellow; paddind: 20px; text-align: center;'> <u>Don't miss it</u></span><span style='font-size: 4pt; font-style: italic; font-weight: bold; color: #00FF00; paddind: 3px; text-align: right;'> <u>test2</u></span>"))

            # TODO need remove <meta name="qrichtext" content="1" /> from the stuff otherwise alignment is not ok... TODO --> should I offer a change to that ??? maybe not
            test_text = '''
            </style></head><body style=" font-family:'Comic Sans MS'; font-size:22pt; font-weight:400; font-style:normal;">
            <p style="color:#00ff00;"><span style=" color:#ff0000;">toto</span><br />tu<span style=" vertical-align:super;">tu</span></p>
            '''
            img1.setLetter(TAText2D(text=test_text))
            # background-color: orange;
            # span div et p donnent la meme chose par contre c'est sur deux lignes
            # display:inline; float:left # to display as the same line .... --> does that work html to svg
            # https://stackoverflow.com/questions/10451445/two-div-blocks-on-same-line --> same line for two divs

            img2 = Image2D(
                '/media/D/Sample_images/sample_images_PA/trash_test_mem/counter/02.png'
            )
            img3 = Image2D(
                '/media/D/Sample_images/sample_images_PA/trash_test_mem/counter/03.png'
            )
            img4 = Image2D(
                '/media/D/Sample_images/sample_images_PA/trash_test_mem/counter/04.png'
            )
            img5 = Image2D(
                '/media/D/Sample_images/sample_images_PA/trash_test_mem/counter/05.png'
            )
            img6 = Image2D(
                '/media/D/Sample_images/sample_images_PA/trash_test_mem/counter/06.png'
            )
            img7 = Image2D(
                '/media/D/Sample_images/sample_images_PA/trash_test_mem/counter/07.png'
            )
            img8 = Image2D(
                '/media/D/Sample_images/sample_images_PA/trash_test_mem/counter/08.png'
            )
            img9 = Image2D(
                '/media/D/Sample_images/sample_images_PA/trash_test_mem/counter/09.png'
            )
            img10 = Image2D(
                '/media/D/Sample_images/sample_images_PA/trash_test_mem/counter/10.png'
            )

            # img10 = Image2D('/media/D/Sample_images/sample_images_PA/trash_test_mem/counter/10.png')
            # img2 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # img3 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # img4 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # img5 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # img6 = Image2D('D:/dataset1/unseen/focused_Series012.png')
            # img7 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # img8 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # img9 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # img10 = Image2D('D:/dataset1/unseen/focused_Series012.png')

            # is row really different from a panel ??? probably not that different
            # row = img1 + img2

            # self.shapes_to_draw.append(row)
            # self.shapes_to_draw.append(row)

            # pkoi ça creerait pas plutot un panel
            # au lieu de creer une row faut creer des trucs
            # row2 = img4 + img5
            # fig = row / row2
            # fig = col(row, row2, width=512)# ça c'est ok
            # self.shapes_to_draw.append(fig)

            # TODO add image swapping and other changes and also implement sticky pos --> just need store initial pos

            # print(len(row))
            # for img in row:
            #     print(img.boundingRect())

            # fig.setToWidth(512) # bug is really here I do miss something but what and why

            # print('rows', len(fig))
            # for r in fig:
            #     print('bounding rect', r.boundingRect())
            #     print('cols in row', len(r))

            # self.shapes_to_draw.append(fig)

            # peut etre si rien n'est mis juste faire une row avec un panel
            row1 = Row(img0, img1, img2)  # , img6, #, nCols=3, nRows=2

            # marche pas en fait car un truc ne prend pas en charge les figs

            # ça marche donc en fait tt peut etre un panel en fait

            col1 = Column(img4, img5, img6)  # , img6, img6, nCols=3, nRows=2,

            col2 = Column(img3, img7)

            # col1+=col2
            col1 /= col2
            # col1+=img3

            # print('mega begin', panel2.nCols, panel2.nRows, panel2.orientation, len(panel2.images), type(panel2), panel2.boundingRect())
            print('mega begin', len(col1.images), type(col1),
                  col1.boundingRect())

            row2 = Row(img8, img9)

            # row1+=row2
            row1 /= row2
            # row1+= img7

            # all seems fine now

            # panel = Panel(img0)# , img1, img2, img3)  # , img6, #, nCols=3, nRows=2

            # # marche pas en fait car un truc ne prend pas en charge les figs
            #
            # # ça marche donc en fait tt peut etre un panel en fait
            #
            # panel2 = Panel(img4, img5)  # ,

            # panel2.setToWidth(256)
            # panel3.setToWidth(256)
            # panel.setToWidth(256)

            print(type(col1))

            # tt marche
            # should I put align top left or right...

            col1.setToHeight(512)
            # panel3.setToWidth(512)
            row1.setToWidth(512)

            # can I add self to any of the stuff --> check --> if plus --> adds if divide --> stack it --> good idea and quite simple

            # fig = col(panel,panel2,panel3)

            # panel2+=panel
            # print(type(panel2))

            # panel2.setToHeight(512)
            # panel2.setToWidth(512)

            # all seems fine now --> see how I can fix things

            # panel2+=panel3 # bug here cause does not resize the panel properly
            # print('mega final', panel2.nCols, panel2.nRows, panel2.orientation, len(panel2.images), type(panel2), panel2.boundingRect(), panel.boundingRect())
            print('mega final', len(col1.images), type(col1),
                  col1.boundingRect(), row1.boundingRect())

            # on dirait que tt marche

            # maintenant ça marche mais reessayer qd meme
            # panel2.setToWidth(256) # seems still a very modest bug somewhere incompressible height and therefore ratio is complex to calculate for width with current stuff --> see how I can do --> should I ignore incompressible within stuff --> most likely yes... and should set its width and height irrespective of that
            # panel2.setToWidth(512) # seems still a very modest bug somewhere incompressible height and therefore ratio is complex to calculate for width with current stuff --> see how I can do --> should I ignore incompressible within stuff --> most likely yes... and should set its width and height irrespective of that

            # panel2.setToHeight(1024) #marche pas --> à fixer
            # panel2.setToHeight(128) # marche pas --> faut craiment le coder en fait --> voir comment je peux faire ça

            # marche pas non plus en fait --> bug qq part
            # panel2.setToHeight(82.65128578548527) # marche pas --> faut craiment le coder en fait --> voir comment je peux faire ça

            # panel += img7
            # panel -= img0
            # panel -= img1
            # panel -= img10
            # self.shapes_to_draw.append(panel)
            # panel2.set_P1(256, 300)

            # panel2.set_P1(512,0)
            # panel3.set_P1(1024, 0)
            # self.shapes_to_draw.append(panel2)

            self.shapes_to_draw.append(col1)
            self.shapes_to_draw.append(row1)
            # self.shapes_to_draw.append(fig)

        # panel2 | panel
        # panel2 | panel # for swapping panels
        # panel | panel2

        # panel << img3

        # ça ne marche pas pkoi

        # img3 >> panel # does not work --> need implement it in my image2D

        # panel >> img3

        # cannot be dragged --> is it because self.is_set
        # row.packX()
        # row.packY() # ça marche mais finaliser le truc pr que ça soit encore plus simple à gerer
        # img.setP1(10,10) #translate it --> cool
        # self.shapes_to_draw.append(img1)
        # self.shapes_to_draw.append(img2)
        # self.shapes_to_draw.append(img3)

        self.shapes_to_draw.append(Square2D(300, 260, 250, stroke=3))

        self.selected_shape = None
Beispiel #7
0
    def __init__(self,
                 active=False,
                 demo=False,
                 scale=1.0,
                 drawing_mode=False):
        self.shapes = []
        self.currently_drawn_shape = None
        self.shape_to_draw = None
        self.selected_shape = []
        self.active = active
        self.scale = scale
        self.drawing_mode = drawing_mode
        if demo:
            self.shapes.append(
                Polygon2D(0, 0, 10, 0, 10, 20, 0, 20, 0, 0, color=0x00FF00))
            self.shapes.append(
                Polygon2D(100,
                          100,
                          110,
                          100,
                          110,
                          120,
                          10,
                          120,
                          100,
                          100,
                          color=0x0000FF,
                          fill_color=0x00FFFF,
                          stroke=2))
            self.shapes.append(Line2D(0, 0, 110, 100, color=0xFF0000,
                                      stroke=3))
            self.shapes.append(Rect2D(200, 150, 250, 100, stroke=10))
            self.shapes.append(Square2D(300, 260, 250, stroke=3))
            self.shapes.append(Ellipse2D(0, 50, 600, 200, stroke=3))
            self.shapes.append(Circle2D(150, 300, 30, color=0xFF0000))
            self.shapes.append(
                PolyLine2D(10,
                           10,
                           20,
                           10,
                           20,
                           30,
                           40,
                           30,
                           color=0xFF0000,
                           stroke=2))
            self.shapes.append(
                PolyLine2D(10,
                           10,
                           20,
                           10,
                           20,
                           30,
                           40,
                           30,
                           color=0xFF0000,
                           stroke=2))
            self.shapes.append(Point2D(128, 128, color=0xFF0000, stroke=6))
            self.shapes.append(Point2D(128, 128, color=0x00FF00, stroke=1))
            self.shapes.append(Point2D(10, 10, color=0x000000, stroke=6))
            img0 = Image2D('./../data/counter/00.png')
            img1 = Image2D('./../data/counter/01.png')
            img2 = Image2D('./../data/counter/02.png')
            img3 = Image2D('./../data/counter/03.png')
            img4 = Image2D('./../data/counter/04.png')
            img5 = Image2D('./../data/counter/05.png')
            img6 = Image2D('./../data/counter/06.png')
            img7 = Image2D('./../data/counter/07.png')
            img8 = Image2D('./../data/counter/08.png')
            img9 = Image2D('./../data/counter/09.png')
            img10 = Image2D('./../data/counter/10.png')

            row = img1 + img2 + img10

            self.shapes.append(row)

            row2 = img4 + img5
            fig = row / row2
            # fig = Column(row, row2)
            #self.shapes.append(fig)
            self.drawing_mode = True
            # self.shape_to_draw = Line2D
            # self.shape_to_draw = Rect2D
            # self.shape_to_draw = Square2D
            # self.shape_to_draw = Ellipse2D
            # self.shape_to_draw = Circle2D
            # self.shape_to_draw = Point2D  # ok maybe small centering issue
            # self.shape_to_draw = Freehand2D
            # self.shape_to_draw = PolyLine2D
            # self.shape_to_draw = Polygon2D
            import random
            drawing_methods = [
                Line2D, Rect2D, Square2D, Ellipse2D, Circle2D, Point2D,
                Freehand2D, PolyLine2D, Polygon2D
            ]
            self.shape_to_draw = random.choice(drawing_methods)
Beispiel #8
0
    def setToWidth(self, width_in_px):
        # from timeit import default_timer as timer
        # start = timer()
        if width_in_px is None:
            return
        # print('setToWidth row 1', timer() - start)
        topleft = Point2D(self.boundingRect().topLeft())
        # print('setToWidth row 2', timer() - start)
        alignTop(topleft, *self.images)
        # print('setToWidth row 3', timer() - start)
        packX(self.space, topleft, *self.images)
        # print('setToWidth row 4', timer() - start)
        # print('bounds before', updateBoudingRect(*self.images))
        setToWidth(self.space, width_in_px, *self.images)
        # print('setToWidth row 5', timer() - start)
        bounds = updateBoudingRect(*self.images)
        # print('bounds after', updateBoudingRect(*self.images))
        # print('setToWidth row 6', timer() - start)

        max_height = -1

        cur_height = bounds.height()
        cur_width = bounds.width()
        all_heights_are_the_same = True
        # print('setToWidth row 7', timer() - start)
        for img in self.images:
            max_height = max(max_height, img.boundingRect().height())
            # print('cur height', img.boundingRect().height(), img.boundingRect().width())
            if cur_height != max_height:
                all_heights_are_the_same = False

        if not all_heights_are_the_same:
            setToHeight(self.space, max_height, *self.images)
            bounds = updateBoudingRect(*self.images)
            all_heights_are_the_same = True
        else:
            bounds = updateBoudingRect(*self.images)

        sign = 1
        if bounds.width() >= width_in_px:
            sign = -1

        # print(bounds.width(), 'vs desired', width_in_px, 'sign', sign)
        #
        # print(all_heights_are_the_same)
        # print(bounds.width() != width_in_px)
        # print(abs(bounds.width()-width_in_px)>0.3)

        # print('setToWidth row 8', timer() - start)
        # dirty height/width fix for complex panels figure out the math for it and replace this code
        # TODO also speed this up so that the action is only faked and not really done (just done once at the end to gain time)
        if not all_heights_are_the_same or (
                bounds.width() != width_in_px
                and abs(bounds.width() - width_in_px) > 0.3):
            # print('setToWidth row 9', timer() - start)
            while True:
                setToHeight(self.space, max_height, *self.images)
                bounds = updateBoudingRect(*self.images)
                if sign < 0:
                    if bounds.width() <= width_in_px:
                        break
                else:
                    if bounds.width() >= width_in_px:
                        break
                max_height += 1 * sign
            # print('setToWidth row 10', timer() - start)

            if bounds.width() != width_in_px:
                if bounds.width() >= width_in_px:
                    sign = -1
                else:
                    sign = 1
                # what if i remove refine step
                #
                # print('setToWidth row 10', timer() - start)
                # max_height -= 1
                # print('max_height', max_height, updateBoudingRect(*self.images))
                while True:
                    setToHeight(self.space, max_height, *self.images)
                    bounds = updateBoudingRect(*self.images)
                    if sign < 0:
                        if bounds.width() <= width_in_px:
                            break
                    else:
                        if bounds.width() >= width_in_px:
                            break
                    max_height += 0.25 * sign  # critical step with this value --> timing is ok --> maybe ok for now
                # # print('setToWidth row 11', timer() - start)

        # print('setToWidth row 11', timer() - start)
        # print('setToWidth row 12', timer() - start)
        self.updateBoudingRect()
Beispiel #9
0
    def setToHeight(self, height_in_px):
        # from timeit import default_timer as timer
        # start = timer()
        if height_in_px is None:
            return
        # pure_image_height = (self.boundingRect().height()) - self.getIncompressibleHeight()
        # # print(width_in_px, self.getIncompressibleWidth(), (nb_cols - 1.) * self.space )
        # height_in_px -= self.getIncompressibleHeight()
        # ratio = height_in_px / pure_image_height
        # for img in self:
        #     img.setToHeight(img.boundingRect().height() * ratio)
        # self.packY(self.space)
        # self.updateBoudingRect()
        # print('desired ',height_in_px)
        topleft = Point2D(self.boundingRect().topLeft())
        alignLeft(topleft, *self.images)
        packY(self.space, topleft, *self.images)
        setToHeight2(self.space, height_in_px, *self.images)
        bounds = updateBoudingRect(*self.images)

        max_width = -1
        cur_height = bounds.height()
        cur_width = bounds.width()
        all_widths_are_the_same = True
        for img in self.images:
            max_width = max(max_width, img.boundingRect().width())
            if max_width != cur_width:
                all_widths_are_the_same = False

        if not all_widths_are_the_same:
            setToWidth2(self.space, max_width, *self.images)
            bounds = updateBoudingRect(*self.images)
            all_widths_are_the_same = True
        else:
            bounds = updateBoudingRect(*self.images)

        sign = 1
        if bounds.height() >= height_in_px:
            sign = -1

        # bug cause also cyclic inside --> need pass whether increase or decrease once for good initially
        # print(bounds.height(), 'vs heigth desired', height_in_px, 'sign', sign)
        # print('heigth', all_widths_are_the_same)
        # dirty height/width fix for complex panels figure out the math for it and replace this code
        # TODO also speed this up so that the action is only faked and not really done (just done once at the end to gain time)
        if not all_widths_are_the_same or (
                bounds.height() != height_in_px
                and abs(bounds.height() - height_in_px) > 0.3):
            # print('setToHeight col 9', timer() - start)
            while True:
                # print(max_width)
                setToWidth2(self.space, max_width, *self.images)
                bounds = updateBoudingRect(*self.images)
                if sign < 0:
                    if bounds.height() <= height_in_px:
                        break
                else:
                    if bounds.height() >= height_in_px:
                        break
                max_width += 1 * sign

            cur_height = bounds.height()
            if bounds.height() != height_in_px:
                if bounds.height() >= height_in_px:
                    sign = -1
                else:
                    sign = 1
                # print('setToHeight col 10', timer() - start)
                # max_width -= 1
                while True:
                    setToWidth2(self.space, max_width, *self.images)
                    bounds = updateBoudingRect(*self.images)
                    if sign < 0:
                        if bounds.height() <= height_in_px:
                            break
                    else:
                        if bounds.height() >= height_in_px:
                            break
                    max_width += 0.25 * sign  # critical time consuming step --> seems ok with this value

        self.updateBoudingRect()
Beispiel #10
0
    def __init__(self, parent=None, demo=False):
        QtWidgets.QWidget.__init__(self, parent)
        self.shapes_to_draw = []
        self.lastPoint = None
        if demo:

            self.shapes_to_draw.append(Polygon2D(0, 0, 10, 0, 10, 20, 0, 20, 0, 0, color=0x00FF00))
            self.shapes_to_draw.append(
                Polygon2D(100, 100, 110, 100, 110, 120, 10, 120, 100, 100, color=0x0000FF, fill_color=0x00FFFF,
                          stroke=2))
            self.shapes_to_draw.append(Line2D(0, 0, 110, 100, color=0xFF0000, stroke=3))
            self.shapes_to_draw.append(Rect2D(200, 150, 250, 100, stroke=10, fill_color=0xFF0000))
            self.shapes_to_draw.append(Ellipse2D(0, 50, 600, 200, stroke=3))
            self.shapes_to_draw.append(Circle2D(150, 300, 30, color=0xFF0000, fill_color=0x00FFFF))
            self.shapes_to_draw.append(PolyLine2D(10, 10, 20, 10, 20, 30, 40, 30, color=0xFF0000, stroke=2))
            self.shapes_to_draw.append(PolyLine2D(10, 10, 20, 10, 20, 30, 40, 30, color=0xFF0000, stroke=2))
            self.shapes_to_draw.append(Point2D(128, 128, color=0xFF0000, fill_color=0x00FFFF, stroke=0.65))
            self.shapes_to_draw.append(Point2D(128, 128, color=0x00FF00, stroke=0.65))
            self.shapes_to_draw.append(Point2D(10, 10, color=0x000000, fill_color=0x00FFFF, stroke=3))

            self.shapes_to_draw.append(Rect2D(0, 0, 512, 512, color=0xFF00FF, stroke=6))
            img0 = Image2D('/D/Sample_images/sample_images_PA/trash_test_mem/counter/00.png')

            inset = Image2D('/D/Sample_images/sample_images_PA/trash_test_mem/counter/01.png')
            inset2 = Image2D('/D/Sample_images/sample_images_PA/trash_test_mem/counter/01.png')
            inset3 = Image2D('/D/Sample_images/sample_images_PA/trash_test_mem/counter/01.png')
            # inset.setToHeight(32)
            # check inset

            scale_bar = ScaleBar(30, '<font color="#FF00FF">10µm</font>')
            scale_bar.set_P1(0,0)
            # scale_bar.set_scale(self.get_scale())
            # # scale_bar.set_P1(self.get_P1().x()+extra_space, self.get_P1().y()+extra_space)
            img0.add_object(scale_bar, Image2D.TOP_LEFT)
            # scale_bar0 = ScaleBar(30, '<font color="#FF00FF">10µm</font>')
            # scale_bar0.set_P1(0, 0)
            # img0.add_object(scale_bar0, Image2D.TOP_LEFT)
            img0.add_object(inset3, Image2D.TOP_LEFT)

            # all seems fine and could even add insets to it --> not so hard I guess
            # check

            # see how to handle insets --> in a way they can be classical images and one should just determine what proportion of the parent image width they should occupy -->
            # need a boolean or need set fraction of orig --> jut one variable
            # maybe also need draw a square around it of a given size --> see how to do that ???

            # img0.add_object(TAText2D(text='<font color="#FF0000">top right</font>'), Image2D.TOP_RIGHT)
            # img0.add_object(TAText2D(text='<font color="#FF0000">top right2</font>'), Image2D.TOP_RIGHT)
            # img0.add_object(TAText2D(text='<font color="#FF0000">top right3</font>'), Image2D.TOP_RIGHT)

            img0.add_object(inset, Image2D.BOTTOM_RIGHT)  # ça marche meme avec des insets mais faudrait controler la taille des trucs... --> TODO
            # img0.add_object(inset2, Image2D.BOTTOM_RIGHT)  # ça marche meme avec des insets mais faudrait controler la taille des trucs... --> TODO
            # img0.add_object(TAText2D(text='<font color="#FF0000">bottom right</font>'), Image2D.BOTTOM_RIGHT)
            # img0.add_object(TAText2D(text='<font color="#FF0000">bottom right2</font>'), Image2D.BOTTOM_RIGHT)
            img0.add_object(TAText2D(text='<font color="#FF0000">bottom right3</font>'), Image2D.BOTTOM_RIGHT)

            # ask whether a border should be drawn for the inset or not ??? and ask for its width...

            # ça a l'air de marcher mais voir comment faire pour gérer

            # img0.add_object(TAText2D(text='<font color="#FF0000">bottom left1</font>'), Image2D.BOTTOM_LEFT)
            # img0.add_object(TAText2D(text='<font color="#FF0000">bottom left2</font>'), Image2D.BOTTOM_LEFT)
            # img0.add_object(TAText2D(text='<font color="#FF0000">bottom left3</font>'), Image2D.BOTTOM_LEFT)

            # seems to work --> just finalize things up...

            # img0 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # size is not always respected and that is gonna be a pb but probably size would be ok for journals as they would not want more than 14 pt size ????

            # ci dessous la font size marche mais je comprend rien ... pkoi ça marche et l'autre marche pas les " et ' ou \' ont l'air clef...
            # in fact does not work font is super small
            # img0.setLetter(TAText2D(text='<font face="Comic Sans Ms" size=\'12\' color=yellow ><font size=`\'12\'>this is a <br>test</font></font>'))
            # img0.setLetter(TAText2D(text='<font face="Comic Sans Ms" color=yellow ><font size=12 >this is a <br>test</font></font>'))
            # img0.setLetter(TAText2D("<p style='font-size: large; font-color: yellow;'><b>Serial Number:</b></p> "))
            # a l'air de marcher mais à tester
            # img0.setLetter(TAText2D('<html><body><p><font face="verdana" color="yellow" size="2000">font_face = "verdana"font_color = "green"font_size = 3</font></html>'))

            # try that https://www.learnpyqt.com/examples/megasolid-idiom-rich-text-editor/
            # img0.setLetter(TAText2D(text='<html><font face="times" size=3 color=yellow>test</font></html>'))
            # img0.setLetter(TAText2D(text="<p style='font-size: 12pt; font-style: italic; font-weight: bold; color: yellow; text-align: center;'> <u>Don't miss it</u></p><p style='font-size: 12pt; font-style: italic; font-weight: bold; color: yellow; text-align: center;'> <u>Don't miss it</u></p>"))

            # this is really a one liner but a bit complex to do I find
            # chaque format different doit etre dans un span different --> facile
            # ça marche mais voir comment faire ça
            # img0.setLettering(TAText2D(
            #     text='<p style="text-align:left;color: yellow">This text is left aligned <span style="float:right;font-style: italic;font-size: 8pt;"> This text is right aligned </span><span style="float:right;font-size: 4pt;color:red"> This text is another text </span></p>'))
            img0.setLettering('<font color="red">A</font>')
            # letter
            img0.annotation.append(Rect2D(88, 88, 200, 200, stroke=3, color=0xFF00FF))
            img0.annotation.append(Ellipse2D(88, 88, 200, 200, stroke=3, color=0x00FF00))
            img0.annotation.append(Circle2D(33,33, 200, stroke=3, color=0x0000FF))
            img0.annotation.append(Line2D(33,33, 88,88, stroke=3, color=0x0000FF))
            img0.annotation.append(Freehand2D(10, 10, 20, 10, 20, 30, 288, 30, color=0xFFFF00, stroke=3))
            # img0.annotation.append(PolyLine2D(10, 10, 20, 10, 20, 30, 288, 30, color=0xFFFF00, stroke=3))
            img0.annotation.append(Point2D(128, 128, color=0xFFFF00, stroke=6))
            # everything seems to work but do check

            img1 = Image2D('/D/Sample_images/sample_images_PA/trash_test_mem/counter/01.png')
            # img1 = Image2D('D:/dataset1/unseen/focused_Series012.png')
            # img1.setLetter(TAText2D(text="<font face='Comic Sans Ms' size=16 color='blue' >this is a <br>test</font>"))
            # ça ça marche vraiment en fait --> use css to write my text instead of that

            # ça ça a l'air de marcher --> pas trop mal en fait du coup
            # ça a l'air de marcher maintenant --> could use that and do a converter for ezfig ???
            # img1.setLetter(TAText2D(text="<span style='font-size: 12pt; font-style: italic; font-weight: bold; color: yellow; paddind: 20px; text-align: center;'> <u>Don't miss it</u></span><span style='font-size: 4pt; font-style: italic; font-weight: bold; color: #00FF00; paddind: 3px; text-align: right;'> <u>test2</u></span>"))

            # TODO need remove <meta name="qrichtext" content="1" /> from the stuff otherwise alignment is not ok... TODO --> should I offer a change to that ??? maybe not
            test_text = '''
            </style></head><body style=" font-family:'Comic Sans MS'; font-size:22pt; font-weight:400; font-style:normal;">
            <p style="color:#00ff00;"><span style=" color:#ff0000;">toto</span><br />tu<span style=" vertical-align:super;">tu</span></p>
            '''
            img1.setLettering(TAText2D(text=test_text))

            # background-color: orange;
            # span div et p donnent la meme chose par contre c'est sur deux lignes
            # display:inline; float:left # to display as the same line .... --> does that work html to svg
            # https://stackoverflow.com/questions/10451445/two-div-blocks-on-same-line --> same line for two divs

            img2 = Image2D('/D/Sample_images/sample_images_PA/trash_test_mem/counter/02.png')

            # crop is functional again but again a packing error
            img2.crop(left=60)
            img2.crop(right=30)
            img2.crop(bottom=90)
            img2.crop(top=60)
            # img2.crop(all=0) # reset crop
            # img2.crop(top=0) # reset crop --> seems ok
            # now seems ok --> see how to do that with figures/vector graphics ...
            # img2.crop(right=60)
            # img2.crop(bottom=60)
            img3 = Image2D('/D/Sample_images/sample_images_PA/trash_test_mem/counter/03.png')
            img4 = Image2D('/D/Sample_images/sample_images_PA/trash_test_mem/counter/04.png')
            img5 = Image2D('/D/Sample_images/sample_images_PA/trash_test_mem/counter/05.png')
            img6 = Image2D('/D/Sample_images/sample_images_PA/trash_test_mem/counter/06.png')
            img7 = Image2D('/D/Sample_images/sample_images_PA/trash_test_mem/counter/07.png')
            img8 = Image2D('/D/Sample_images/sample_images_PA/trash_test_mem/counter/08.png')

            # reference point is the original image and stroke should be constant irrespective of zoom --> most likely need the scaling factor too there
            # reference size is also the underlying original image --> TODO
            # img8.annotation.append(Line2D(0, 0, 110, 100, color=0xFF0000, stroke=3))
            img8.annotation.append(Rect2D(60, 60, 100, 100, stroke=20, color=0xFF00FF))
            # need make the scale rese
            # img8.annotation.append(Ellipse2D(0, 50, 600, 200, stroke=3))

            img9 = Image2D('/D/Sample_images/sample_images_PA/trash_test_mem/counter/09.png')
            img10 = Image2D('/D/Sample_images/sample_images_PA/trash_test_mem/counter/10.png')
            # Data for plotting
            import numpy as np
            import matplotlib.pyplot as plt

            t = np.arange(0.0, 2.0, 0.01)
            s = 1 + np.sin(2 * np.pi * t)

            fig, ax = plt.subplots()
            ax.plot(t, s)

            ax.set(xlabel='time (s)', ylabel='voltage (mV)',
                   title='About as simple as it gets, folks')
            ax.grid()

            # plt.show()
            # fig.savefig("test.png")
            # plt.show()
            # ça marche --> voici deux examples de shapes

            # first graph test --> TODO improve that
            graph2d = VectorGraphics2D(fig)
            graph2d.crop(all=20) # not great neither

            vectorGraphics = VectorGraphics2D('/D/Sample_images/sample_images_svg/cartman.svg')

            # nb cropping marche en raster mais pas en svg output --> besoin de faire un masque d'ecretage --> pourrait aussi dessiner un rectangle de la meme taille de facon à le faire

            # TODO KEEP unfortunately cropping does not work when saved as svg but works when saved as raster...
            vectorGraphics.crop(left=10, right=30, top=10, bottom=10)
            animatedVectorGraphics = VectorGraphics2D('/D/Sample_images/sample_images_svg/animated.svg')

            # bug cause shears the stuff --> would need crop the other dimension too to maintain AR
            animatedVectorGraphics.crop(left=30)#, top=20, bottom=20

            # self.shapes_to_draw.append(graph2d)

            # img10 = Image2D('/D/Sample_images/sample_images_PA/trash_test_mem/counter/10.png')
            # img2 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # img3 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # img4 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # img5 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # img6 = Image2D('D:/dataset1/unseen/focused_Series012.png')
            # img7 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # img8 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # img9 = Image2D('D:/dataset1/unseen/100708_png06.png')
            # img10 = Image2D('D:/dataset1/unseen/focused_Series012.png')

            # is row really different from a panel ??? probably not that different
            # row = img1 + img2

            # self.shapes_to_draw.append(row)
            # self.shapes_to_draw.append(row)

            # pkoi ça creerait pas plutot un panel
            # au lieu de creer une row faut creer des trucs
            # row2 = img4 + img5
            # fig = row / row2
            # fig = col(row, row2, width=512)# ça c'est ok
            # self.shapes_to_draw.append(fig)

            # TODO add image swapping and other changes and also implement sticky pos --> just need store initial pos

            # print(len(row))
            # for img in row:
            #     print(img.boundingRect())

            # fig.setToWidth(512) # bug is really here I do miss something but what and why

            # print('rows', len(fig))
            # for r in fig:
            #     print('bounding rect', r.boundingRect())
            #     print('cols in row', len(r))

            # self.shapes_to_draw.append(fig)

            # peut etre si rien n'est mis juste faire une row avec un panel
            row1 = Row(img0, img1, img2, graph2d, animatedVectorGraphics) #, graph2d, animatedVectorGraphics  # , img6, #, nCols=3, nRows=2 #le animated marche mais faut dragger le bord de l'image mais pas mal qd meme
            # see how I should handle size of graphs but I'm almost there

            # marche pas en fait car un truc ne prend pas en charge les figs
            # ça marche donc en fait tt peut etre un panel en fait

            col1 = Column(img4, img5, img6, vectorGraphics)  # , vectorGraphics# , img6, img6, nCols=3, nRows=2,
            col2 = Column(img3, img7, img10)
            #
            # col1.setLettering('<font color="#FFFFFF">A</font>')

            # col1+=col2
            col1 /= col2
            # col1+=img3




            # print('mega begin', panel2.nCols, panel2.nRows, panel2.orientation, len(panel2.images), type(panel2), panel2.boundingRect())
            # print('mega begin', len(col1.images), type(col1), col1.boundingRect())


            # ok need increment and need see how to change the font of the stuff and bg color and fg color --> TODO but ok for now
            row2 = Row(img8, img9)
            row2.setLettering('<font color="#FFFFFF">a</font>')

            # row1+=row2
            row1 /= row2
            # row1+= img7

            # all seems fine now

            # panel = Panel(img0)# , img1, img2, img3)  # , img6, #, nCols=3, nRows=2

            # # marche pas en fait car un truc ne prend pas en charge les figs
            #
            # # ça marche donc en fait tt peut etre un panel en fait
            #
            # panel2 = Panel(img4, img5)  # ,

            # panel2.setToWidth(256)
            # panel3.setToWidth(256)
            # panel.setToWidth(256)

            # print(type(col1))

            # tt marche
            # should I put align top left or right...
            # should I put align top left or right...

            col1.setToHeight(512) # creates big bugs now
            # panel3.setToWidth(512)
            row1.setToWidth(512)
            # row1.setLettering('<font color="#FF00FF">B</font>')
            # row1.setLettering(' ') # remove letters
            # row1.setToWidth(1024)
            # ça a l'air de marcher...

            # it now seems ok
            # from epyseg.figure.alignment import alignRight, alignLeft, alignTop, alignBottom, alignCenterH, alignCenterV

            # alignLeft(row1, col1)
            # alignRight(row1, col1)
            # alignTop(row1, col1)
            # alignBottom(row1, col1)
            # alignCenterH(row1, col1)
            # alignCenterV(row1, col1)

            # can I add self to any of the stuff --> check --> if plus --> adds if divide --> stack it --> good idea and quite simple

            # fig = col(panel,panel2,panel3)

            # panel2+=panel
            # print(type(panel2))

            # panel2.setToHeight(512)
            # panel2.setToWidth(512)

            # all seems fine now --> see how I can fix things

            # panel2+=panel3 # bug here cause does not resize the panel properly
            # print('mega final', panel2.nCols, panel2.nRows, panel2.orientation, len(panel2.images), type(panel2), panel2.boundingRect(), panel.boundingRect())
            # print('mega final', len(col1.images), type(col1), col1.boundingRect(), row1.boundingRect())

            # on dirait que tt marche

            # maintenant ça marche mais reessayer qd meme
            # panel2.setToWidth(256) # seems still a very modest bug somewhere incompressible height and therefore ratio is complex to calculate for width with current stuff --> see how I can do --> should I ignore incompressible within stuff --> most likely yes... and should set its width and height irrespective of that
            # panel2.setToWidth(512) # seems still a very modest bug somewhere incompressible height and therefore ratio is complex to calculate for width with current stuff --> see how I can do --> should I ignore incompressible within stuff --> most likely yes... and should set its width and height irrespective of that

            # panel2.setToHeight(1024) #marche pas --> à fixer
            # panel2.setToHeight(128) # marche pas --> faut craiment le coder en fait --> voir comment je peux faire ça

            # marche pas non plus en fait --> bug qq part
            # panel2.setToHeight(82.65128578548527) # marche pas --> faut craiment le coder en fait --> voir comment je peux faire ça

            # panel += img7
            # panel -= img0
            # panel -= img1
            # panel -= img10
            # self.shapes_to_draw.append(panel)
            # panel2.set_P1(256, 300)

            # panel2.set_P1(512,0)
            # panel3.set_P1(1024, 0)
            # self.shapes_to_draw.append(panel2)

            self.shapes_to_draw.append(col1)
            self.shapes_to_draw.append(row1)

            # big bug marche pas
            # packX(3, None, *[img0, img1, img2])  # ça marche presque de nouveau

            # print(img0.boundingRect(), img1.boundingRect(), img2.boundingRect())
            #
            # self.shapes_to_draw.append(img0)
            # self.shapes_to_draw.append(img1)
            # self.shapes_to_draw.append(img2)

            img4.setLettering('<font color="#0000FF">Z</font>') # ça marche mais voir comment faire en fait
            # self.shapes_to_draw.append(fig)

        # panel2 | panel
        # panel2 | panel # for swapping panels
        # panel | panel2

        # panel << img3

        # ça ne marche pas pkoi

        # img3 >> panel # does not work --> need implement it in my image2D

        # panel >> img3

        # cannot be dragged --> is it because self.is_set
        # row.packX()
        # row.packY() # ça marche mais finaliser le truc pr que ça soit encore plus simple à gerer
        # img.setP1(10,10) #translate it --> cool
        # self.shapes_to_draw.append(img1)
        # self.shapes_to_draw.append(img2)
        # self.shapes_to_draw.append(img3)

        self.shapes_to_draw.append(Square2D(300, 260, 250, stroke=3))
        self.selected_shape = None
Beispiel #11
0
    def draw(self, painter, draw=True):
        if draw:
            painter.save()
            painter.setOpacity(self.opacity)
            # painter.setClipRect(self)  # only draw in self --> very useful for inset borders # pb clip rect does not work for svg --> remove for now users can add it manually if desired or I can add it if people really want it and then I should draw relevant lines or shifted rects --> do that later
            # prevents drawing outside from the image
            rect_to_plot = self.boundingRect(
                scaled=True
            )  #scaled=True #self.adjusted(self.__crop_left, self.__crop_top, self.__crop_right, self.__crop_bottom) # need remove the crops with that
            # self.scale = 1
            # if self.scale is not None and self.scale != 1:
            # #     # TODO KEEP THE ORDER THIS MUST BE DONE THIS WAY OR IT WILL GENERATE PLENTY OF BUGS...
            #     new_width = rect_to_plot.width() * self.scale
            #     new_height = rect_to_plot.height() * self.scale
            # #     # print(rect_to_plot.width(), rect_to_plot.height())  # here ok
            # #     # setX changes width --> why is that
            # #
            # #     # TODO BE EXTREMELY CAREFUL AS SETX AND SETY CAN CHANGE WIDTH AND HEIGHT --> ALWAYS TAKE SIZE BEFORE OTHERWISE THERE WILL BE A PB AND ALWAYS RESET THE SIZE WHEN SETX IS CALLED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            # #     # Sets the left edge of the rectangle to the given x coordinate. May change the width, but will never change the right edge of the rectangle. --> NO CLUE WHY SHOULD CHANGE WIDTH THOUGH BUT BE CAREFUL!!!
            # #     rect_to_plot.setX(rect_to_plot.x() * self.scale)
            # #     rect_to_plot.setY(rect_to_plot.y() * self.scale)
            # #     # maybe to avoid bugs I should use translate instead rather that set x but ok anyways
            # #     # print(rect_to_plot.width(), rect_to_plot.height())# bug here --> too big
            # #
            # #     # print(new_height, new_height, self.width(), self.scale, self.scale* self.width())
            #     rect_to_plot.setWidth(new_width)
            #     rect_to_plot.setHeight(new_height)

            if self.img is not None:
                x = 0
                y = 0
                w = self.img.get_width()
                h = self.img.get_height()
                if self.__crop_top is not None:
                    y = self.__crop_top
                    h -= self.__crop_top
                if self.__crop_left is not None:
                    x = self.__crop_left
                    w -= self.__crop_left
                if self.__crop_right is not None:
                    w -= self.__crop_right
                if self.__crop_bottom is not None:
                    h -= self.__crop_bottom
                # pb here --> see how to really crop
                qsource = QRectF(x, y, w, h)
                painter.drawImage(rect_to_plot, self.qimage,
                                  qsource)  # , flags=QtCore.Qt.AutoColor
            else:
                painter.drawRect(rect_to_plot)

            # letter is good
            extra_space = 3

            # draw annotations first
            if self.annotation is not None and self.annotation:
                # need clone the object then set its P1 with respect to position or need a trick to keep original ref and have an updated one just for display but then need renew it all the time --> see how I can do that...
                # maybe clone is not smart as it duplicates resources without a need for it
                # but then need clone the original rect and draw with respect to that
                # and I indeed need scale the shape --> TODO too
                # indeed thanks to cloning I always preserve original info --> not bad

                # annot position is good
                # TODO see how to do that cause not so easy --> think carefully and take inspiration from EZF and improve it
                for annot in self.annotation:
                    # always empty --> why is that
                    # print('init',annot.get_P1())
                    # always assume everything is done at 0,0 then do translation
                    # annot.set_P1(self.get_P1().x() + annot.get_P1().x(),                    self.get_P1().y() + annot.get_P1().y())  # always relative to the parent image
                    # annot.set_P1(self.get_P1())  # always relative to the parent image
                    # print(annot.get_P1())

                    # print('init', self.get_P1(), 'scale', self.get_scale())
                    annot.set_to_translation(rect_to_plot.topLeft())

                    annot.set_to_scale(
                        self.scale)  # will f**k the stuff but ok for a test
                    # print('scaled',annot.get_P1())
                    annot.draw(painter=painter)
                    # print('tranbs', annot.translation)

            # and indeed I need also to take crop into account in order not to misposition things...

            if self.letter is not None:
                self.letter.set_P1(rect_to_plot.topLeft().x() + extra_space,
                                   rect_to_plot.topLeft().y() + extra_space)

            # then draw text and insets --> on top of annotations
            # TODO need align insets differently than others and need align its bounding box also differently --> TODO but almost there
            if len(self.top_right_objects) != 0 or len(
                    self.top_left_objects) != 0 or len(
                        self.bottom_left_objects) != 0 or len(
                            self.bottom_right_objects) != 0 or len(
                                self.centered_objects) != 0:
                # align a scale bar to various positions
                # maybe if there is a letter first point should be place below stuff
                # top_left = Point2D(self.get_P1())
                top_left_shifted = Point2D(rect_to_plot.topLeft())
                # top_left_shifted.setX(top_left_shifted.x() )# + extra_space
                # top_left_shifted.setY(top_left_shifted.y() )#+ extra_space

                # print('before', top_left)
                # if self.letter is not None:
                #     packY(extra_space, self.letter, top_left_shifted)
                # print('after', top_left)

                # insets should be aligned to unshifted values
                # whereas texts should be aligned to shifted ones
                # what if I try all unshifted
                # cause in a way it's simpler

                # top_right = Point2D(self.get_P1())
                top_right_shifted = Point2D(rect_to_plot.topLeft())
                top_right_shifted.setX(top_right_shifted.x() +
                                       rect_to_plot.width())  #- extra_space
                top_right_shifted.setY(top_right_shifted.y())  #+ extra_space

                # bottom_left = Point2D(self.get_P1())
                bottom_left_shifted = Point2D(rect_to_plot.topLeft())
                bottom_left_shifted.setX(
                    bottom_left_shifted.x())  #+ extra_space
                bottom_left_shifted.setY(
                    bottom_left_shifted.y() + rect_to_plot.height()
                )  #- extra_space  # should align right then pack on top of that --> may need a direction in packing--> TODO

                bottom_right = Point2D(rect_to_plot.topLeft())
                bottom_right_shifted = Point2D(rect_to_plot.topLeft())
                bottom_right_shifted.setX(
                    bottom_right_shifted.x() +
                    rect_to_plot.width())  # - extra_space
                bottom_right_shifted.setY(
                    bottom_right_shifted.y() +
                    rect_to_plot.height())  #- extra_space

                center = Point2D(rect_to_plot.topLeft())
                center.setX(center.x() + rect_to_plot.width() / 2)
                center.setY(center.y() + rect_to_plot.height() / 2)

                if len(self.top_left_objects) != 0:
                    # change inset size first
                    for obj in self.top_left_objects:
                        if isinstance(obj, Image2D):
                            obj.setToWidth(
                                rect_to_plot.width() * obj.
                                fraction_of_parent_image_width_if_image_is_inset
                            )

                    # if letter exists align with respect to it

                    alignTop(top_left_shifted, *self.top_left_objects)
                    alignLeft(top_left_shifted, *self.top_left_objects)

                    if self.letter is not None:
                        # packY(extra_space, self.letter, top_left_shifted)
                        top_left_shifted = self.letter

                    # in fact images really need be aligned left of the image but the others need be aligned with the letter that has an extra space --> TODO --> change some day

                    packY(extra_space, top_left_shifted,
                          *self.top_left_objects)

                    # all images need be shifted back??? to be aligned left

                    for obj in self.top_left_objects:
                        # for drawing of inset borders
                        # if isinstance(obj, Image2D):
                        #     # make it draw a border and align it
                        #     # painter.save()
                        #     img_bounds = Rect2D(obj)
                        #     img_bounds.stroke = 3
                        #     # img_bounds.translate(-img_bounds.stroke / 2, -img_bounds.stroke / 2)
                        #     img_bounds.color = 0xFFFF00
                        #     img_bounds.fill_color = 0xFFFF00
                        #     img_bounds.draw(painter=painter)
                        #     # print(img_bounds)
                        #     # painter.restore()
                        obj.draw(painter=painter)

                if len(self.top_right_objects) != 0:
                    # change inset size first
                    for obj in self.top_right_objects:
                        if isinstance(obj, Image2D):
                            obj.setToWidth(
                                rect_to_plot.width() * obj.
                                fraction_of_parent_image_width_if_image_is_inset
                            )
                    alignRight(top_right_shifted, *self.top_right_objects)
                    alignTop(top_right_shifted, *self.top_right_objects)
                    packY(extra_space, top_right_shifted,
                          *self.top_right_objects)
                    for obj in self.top_right_objects:
                        # # for drawing of inset borders
                        # if isinstance(obj, Image2D):
                        #     # make it draw a border and align it
                        #     # painter.save()
                        #     img_bounds = Rect2D(obj)
                        #     img_bounds.stroke = 3
                        #     # img_bounds.translate(img_bounds.stroke / 2, -img_bounds.stroke / 2)
                        #     img_bounds.color = 0xFFFF00
                        #     img_bounds.fill_color = 0xFFFF00
                        #     img_bounds.draw(painter=painter)
                        #     # print(img_bounds)
                        #     # painter.restore()
                        obj.draw(painter=painter)

                if len(self.bottom_right_objects) != 0:
                    # change inset size first
                    for obj in self.bottom_right_objects:
                        if isinstance(obj, Image2D):
                            obj.setToWidth(
                                rect_to_plot.width() * obj.
                                fraction_of_parent_image_width_if_image_is_inset
                            )
                    alignRight(bottom_right_shifted,
                               *self.bottom_right_objects)
                    alignBottom(bottom_right_shifted,
                                *self.bottom_right_objects)
                    packYreverse(extra_space, bottom_right_shifted,
                                 *self.bottom_right_objects)
                    # packY(3, top_right, *self.top_right_objects) # I do need to invert packing order
                    for obj in self.bottom_right_objects:
                        # # for drawing of inset borders
                        # if isinstance(obj, Image2D):
                        #     # make it draw a border and align it
                        #     # painter.save()
                        #     img_bounds = Rect2D(obj)
                        #     img_bounds.stroke = 3
                        #     # img_bounds.translate(-img_bounds.stroke / 2, img_bounds.stroke / 2)
                        #     # should I clip it to the image size --> maybe it's the best
                        #     img_bounds.color = 0xFFFF00
                        #     img_bounds.fill_color = 0xFFFF00
                        #     img_bounds.draw(painter=painter)
                        #     # print(img_bounds)
                        #     # painter.restore()
                        obj.draw(painter=painter)

                if len(self.bottom_left_objects) != 0:
                    # change inset size first
                    for obj in self.bottom_left_objects:
                        if isinstance(obj, Image2D):
                            obj.setToWidth(
                                rect_to_plot.width() * obj.
                                fraction_of_parent_image_width_if_image_is_inset
                            )
                    alignLeft(bottom_left_shifted, *self.bottom_left_objects)
                    alignBottom(bottom_left_shifted, *self.bottom_left_objects)
                    packYreverse(extra_space, bottom_left_shifted,
                                 *self.bottom_left_objects)
                    for obj in self.bottom_left_objects:
                        # # for drawing of inset borders
                        # if isinstance(obj, Image2D):
                        #     # make it draw a border and align it
                        #     # painter.save()
                        #     img_bounds = Rect2D(obj)
                        #     img_bounds.stroke = 3
                        #     # img_bounds.translate(-img_bounds.stroke/2, img_bounds.stroke/2)
                        #     img_bounds.color = 0xFFFF00
                        #     img_bounds.fill_color = 0xFFFF00
                        #     img_bounds.draw(painter=painter)
                        #     # print(img_bounds)
                        #     # painter.restore()
                        obj.draw(painter=painter)

                if len(self.centered_objects) != 0:
                    # change inset size first
                    for obj in self.centered_objects:
                        if isinstance(obj, Image2D):
                            obj.setToWidth(
                                rect_to_plot.width() * obj.
                                fraction_of_parent_image_width_if_image_is_inset
                            )
                    alignCenterH(center, *self.centered_objects)
                    alignCenterV(center, *self.centered_objects)
                    for obj in self.centered_objects:
                        # # for drawing of inset borders
                        # if isinstance(obj, Image2D):
                        #     # make it draw a border and align it
                        #     # painter.save()
                        #     img_bounds = Rect2D(obj)
                        #     img_bounds.stroke = 3
                        #     img_bounds.color = 0xFFFF00
                        #     img_bounds.fill_color = 0xFFFF00
                        #     img_bounds.draw(painter=painter)
                        #     # print(img_bounds)
                        #     # painter.restore()
                        obj.draw(painter=painter)

            # then need to draw the letter at last so that it is always on top
            if self.letter is not None:
                self.letter.draw(painter)

            painter.restore()