Exemplo n.º 1
0
 def add_line(self, cord_1, cord_2, color):
     key = tuple(sorted([tuple(cord_1), tuple(cord_2)]))
     x = min(cord_1[0], cord_2[0])
     y = min(cord_1[1], cord_2[1])
     if key in self.lines:
         print("ERROR: Line between {} and {} already added.".format(
             cord_1, cord_2))
     else:
         line = QLabel(self)
         if color == "white":
             pixmap = QPixmap(get_asset_path("hor_line_white"))
         else:
             pixmap = QPixmap(get_asset_path("hor_line_black"))
         c1 = (30 + cord_1[0] * 30, 30 + cord_1[1] * 30)
         c2 = (30 + cord_2[0] * 30, 30 + cord_2[1] * 30)
         length = ((c1[0] - c2[0])**2 + (c1[1] - c2[1])**2)**(1 / 2)
         angle = math.degrees(
             math.atan2(key[1][1] - key[0][1], key[1][0] - key[0][0]))
         pixmap = pixmap.scaled(length, 5)
         pixmap = pixmap.transformed(QTransform().rotate(angle))
         line.setPixmap(pixmap)
         line.move(30 + x * 30, 30 + y * 30)
         line.show()
         line.lower()
         self.lines[key] = line