def __init__(self, png, tank_item: TankItem, direction: Direction): QGraphicsPixmapItem.__init__(self, png) self.tank_item = tank_item self.tank = tank_item.tank self.direction = direction self.available = True if self.direction == Direction.UP: self.setX(self.tank_item.x() + cube_size / 2 - 3) self.setY(self.tank_item.y()) elif self.direction == Direction.DOWN: self.setX(self.tank_item.x() + cube_size / 2 + 3) self.setY(self.tank_item.y() + cube_size) self.setRotation(180) elif self.direction == Direction.LEFT: self.setX(self.tank_item.x()) self.setY(self.tank_item.y() + cube_size / 2 + 3) self.setRotation(270) elif self.direction == Direction.RIGHT: self.setX(self.tank_item.x() + cube_size) self.setY(self.tank_item.y() + cube_size / 2 - 3) self.setRotation(90) self.timer = QTimer() self.timer.setInterval(interval) self.timer.timeout.connect(self.move) self.timer.start()
def __init__(self, _parent, _imgfile: str, _functionname: str, _translations: dict, _vars: list, _connections: dict, _type: BlockType, _typeIMG: BlockImgType, _nameControl: str = "", img=None): self._parent = _parent self._translations = _translations self._vars = _vars self.initConections(_connections) self._language = Language() self.__functionname = _functionname self._type = _type self._typeImg = _typeIMG self._nameControl = _nameControl self.c, self.cS = None, None # self.timer = QTimer() # self.timer.timeout.connect(self.updateSize) # self.timer.start(100) QObject.__init__(self) QGraphicsPixmapItem.__init__(self) if img is None: img = PILImagetoCV2Image(Image.open(_imgfile)) _varstext = self.listValuesVars() Block.__init__(self, _img=img, _text1="", _text2=self._nameControl, _vars=_varstext, _type=self._type, _typeIMG=self._typeImg) self.setFlag(QGraphicsItem.ItemIsMovable, True) self.setFlag(QGraphicsItem.ItemIsSelectable, True) self.setAcceptHoverEvents(True) self.setZValue(1) self.initPopUpMenu() self._language.changed.connect(self.changeLanguage) self.imgchanged.connect(self.repaintImg) self.changeLanguage() super(QGraphicsBlockItem, self).setPos(QPointF(0, 0))
def __init__(self, tank, direction: Direction): png = QPixmap() png.load('../images/%s' % tank.pic) png = png.scaled(cube_size, cube_size) QGraphicsPixmapItem.__init__(self, png) self.directions = [] self.direction = direction self.tank = Tank(tank) self.setTransformOriginPoint(cube_size / 2, cube_size / 2) self.move_timer = QTimer() self.move_timer.setInterval(interval) self.move_timer.timeout.connect(self.move) self.move_timer.start()