class Human(Entity): BRAVE = "brave" COWARD = "coward" CARELESS = "careless" CAUTIOUS = "cautious" RATIONAL = "rational" STUPID = "stupid" WEAPON_LONG = "long" WEAPON_SHORT = "short" NO_WEAPON = "noweapon" def __init__(self, personality, weapon, cord_x=0, cord_y=0, parent=None): super().__init__("human_{}_{}.png".format(personality, weapon), parent=parent) self.personality = personality self.weapon = weapon self.cord_x = cord_x self.cord_y = cord_y self.setFixedSize(73 * _SCALE, 73 * _SCALE) def change_weapon(self, weapon): self.weapon = weapon self._base_image = "human_{}_{}.png".format(self.personality, self.weapon) self.updatePixmap() def updatePixmap(self): path = _PATH + os.sep + "assets" + os.sep + self._base_image self.__pixmap = QPixmap(path) self.__pixmap = self.__pixmap.scaled(self.__pixmap.width() * _SCALE, self.__pixmap.height() * _SCALE) self.__pixmap = self.__pixmap.transformed(QTransform().rotate(self.angle)) self._base_label.setPixmap(self.__pixmap)
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
def __init__(self, parent, i, mainSize, deskSize): QLabel.__init__(self, '', parent) self.index = i picture = QPixmap('img/philosopher.png') if i < 3: transform = QTransform().scale(-1, 1) picture = picture.transformed(transform, Qt.SmoothTransformation) self.setPixmap(picture) center = mainSize / 2 - self.SIZE / 2 dx = numpy.cos(numpy.radians(90 - i * 72)) * (deskSize / 2 + self.SIZE / 2) dy = numpy.sin(numpy.radians(90 - i * 72)) * (deskSize / 2 + self.SIZE / 2) self.move(center + dx, center - dy)
def __init__(self, list_of_files): QWidget.__init__(self) l1 = QHBoxLayout(self) k = 0 n = 0 for fileName in list_of_files: if k < 10 and n == 0: label = QLabel() l1.addWidget(label) pixmap = QPixmap(fileName) pixmap = pixmap.scaled(150, 150, Qt.KeepAspectRatio) pixmap = pixmap.transformed(QTransform().rotate(180)) label.setPixmap(pixmap) n = n + 1 if n == len(list_of_files) / 10: k = k + 1 n = 0
def _renderPixmaps(self): self._pixmaps=[] for i in range(self._steps+1): angle = int(i * 360.0 / self._steps) pixmap = QPixmap(self._resource) # if problem with loading png if pixmap.size().width()==0: self._pixmaps=None return rotate_matrix = QMatrix() rotate_matrix.rotate(angle) pixmap_rotated = pixmap.transformed(rotate_matrix) pixmap_moved = QPixmap(pixmap.size()) pixmap_moved.fill(Qt.transparent) painter = QPainter() painter.begin(pixmap_moved) painter.drawPixmap((pixmap_moved.width() - pixmap_rotated.width()) / 2.0, (pixmap_moved.height() - pixmap_rotated.height()) / 2.0, pixmap_rotated) painter.end() self._pixmaps+=[pixmap_moved.scaled(self._width, self._height)]
def load_image(self, path): if not path: return self._empty_image if not Loader.is_image(path): return self._empty_image if path in self._cache: node = self._cache[path] self._pull(node) return node.image image = QPixmap(path) exif = Exif(path) if exif.orientation != 0: image = image.transformed(QTransform().rotate(360 - exif.orientation)) node = _Node(path, image) self._cache[path] = node cast_off = self._push(node) if cast_off: del self._cache[cast_off.path] return image
def setHistogram(self, values=None, bins=None, use_kde=False, histogram=None): """ Set background histogram (or density estimation, violin plot) The histogram of bins is calculated from values, optionally as a Gaussian KDE. If histogram is provided, its values are used directly and other parameters are ignored. """ if (values is None or not len(values)) and histogram is None: self.setPixmap(None) return if histogram is not None: self._histogram = hist = histogram else: if bins is None: bins = min(100, max(10, len(values) // 20)) if use_kde: hist = gaussian_kde(values, None if isinstance(use_kde, bool) else use_kde)( np.linspace(np.min(values), np.max(values), bins)) else: hist = np.histogram(values, bins)[0] self._histogram = hist = hist / hist.max() HEIGHT = self.rect().height() / 2 OFFSET = HEIGHT * .3 pixmap = QPixmap(QSize(len(hist), 2 * (HEIGHT + OFFSET))) # +1 avoids right/bottom frame border shadow pixmap.fill(Qt.transparent) painter = QPainter(pixmap) painter.setPen(QPen(Qt.darkGray)) for x, value in enumerate(hist): painter.drawLine(x, HEIGHT * (1 - value) + OFFSET, x, HEIGHT * (1 + value) + OFFSET) if self.orientation() != Qt.Horizontal: pixmap = pixmap.transformed(QTransform().rotate(-90)) self.setPixmap(pixmap)
class Human(Entity): BRAVE = "brave" COWARD = "coward" CARELESS = "careless" CAUTIOUS = "cautious" RATIONAL = "rational" STUPID = "stupid" WEAPON_LONG = "long" WEAPON_SHORT = "short" NO_WEAPON = "noweapon" def __init__(self, personality, weapon, cord_x=0, cord_y=0, parent=None): super().__init__("human_{}_{}.png".format(personality, weapon), parent=parent) self.personality = personality self.weapon = weapon self.cord_x = cord_x self.cord_y = cord_y self.setFixedSize(73 * _SCALE, 73 * _SCALE) def change_weapon(self, weapon): self.weapon = weapon self._base_image = "human_{}_{}.png".format(self.personality, self.weapon) self.updatePixmap() def updatePixmap(self): path = _PATH + os.sep + "assets" + os.sep + self._base_image self.__pixmap = QPixmap(path) self.__pixmap = self.__pixmap.scaled(self.__pixmap.width() * _SCALE, self.__pixmap.height() * _SCALE) self.__pixmap = self.__pixmap.transformed(QTransform().rotate( self.angle)) self._base_label.setPixmap(self.__pixmap)
class Entity(QWidget): def __init__(self, base_image, size, hp=100, pos=(0, 0), parent=None): super().__init__(parent) self._base_label = QLabel(self) self._base_image = base_image self._size = size self._decor_label = None self._decor_pixmap = None self._hp_max = hp self.__pixmap = None """:type: PyQt4.QtGui.QPixmap""" self.__cord_x = pos[0] self.__cord_y = pos[1] self.__angle = 0 self.__hp_bar = QProgressBar(self) self.__hp_bar.setMaximum(self._hp_max) self.__hp_bar.setValue(self._hp_max) self.__hp_bar.setTextVisible(False) self.__hp_bar.setMaximumSize(size[0], 5) self.setAlignment(Qt.AlignCenter) self.updatePixmap() if _debugging: self.setStyleSheet("border: 1px solid black") @property def health(self): return self.__hp_bar.value() @health.setter def health(self, hp): if hp > self._hp_max: hp = self._hp_max elif hp < 0: hp = 0 self.__hp_bar.setValue(hp) @property def angle(self): return self.__angle @angle.setter def angle(self, angle): self.__angle = angle self.updatePixmap() @property def cord_x(self): return self.__cord_x @cord_x.setter def cord_x(self, cord): self.__cord_x = cord self.move(self.cord_x, self.cord_y) @property def cord_y(self): return self.__cord_y @cord_y.setter def cord_y(self, cord): self.__cord_y = cord self.move(self.cord_x, self.cord_y) def hide_hp_bar(self, bool=False): if bool: self.__hp_bar.hide() else: self.__hp_bar.show() def add_decoration(self, path): if path is None: self._decor_label.deleteLater() self._decor_label = None else: self._decor_label = QLabel(self) self._decor_pixmap = QPixmap(path) # self._decor_pixmap = self._decor_pixmap.scaled(self._size[0], self._size[1]) self._decor_pixmap = self._decor_pixmap.transformed( QTransform().rotate(self.angle)) self._decor_label.setPixmap(self._decor_pixmap) self._decor_label.setAlignment(Qt.AlignCenter) self._decor_label.show() def updatePixmap(self): path = get_asset_path(self._base_image) self.__pixmap = QPixmap(path) self.__pixmap = self.__pixmap.scaled(self._size[0], self._size[1]) self.__pixmap = self.__pixmap.transformed(QTransform().rotate( self.angle)) self._base_label.setPixmap(self.__pixmap) self._base_label.show() # self.setFixedSize(self.__pixmap.width(), self.__pixmap.height()) def setFixedSize(self, x, y): super().setFixedSize(x, y) self._base_label.setFixedSize(x, y) def setAlignment(self, alignment): self._base_label.setAlignment(alignment)
class Entity(QWidget): def __init__(self, base_image, parent=None): super().__init__(parent) self._base_label = QLabel(self) self._base_image = base_image self._decor_label = QLabel(self) self._decor_pixmap = None self.__pixmap = None """:type: PyQt4.QtGui.QPixmap""" self.__cord_x = 0 self.__cord_y = 0 self.__angle = 0 self.setAlignment(Qt.AlignCenter) self.updatePixmap() if _debugging: self.setStyleSheet("border: 1px solid black") @property def angle(self): return self.__angle @angle.setter def angle(self, angle): self.__angle = angle self.updatePixmap() @property def cord_x(self): return self.__cord_x @cord_x.setter def cord_x(self, cord): self.__cord_x = cord self.move(self.cord_x, self.cord_y) @property def cord_y(self): return self.__cord_y @cord_y.setter def cord_y(self, cord): self.__cord_y = cord self.move(self.cord_x, self.cord_y) def add_decoration(self, path): if path is None: self._decor_label.hide() else: self._decor_label = QLabel(self) self._decor_pixmap = QPixmap(path) self._decor_pixmap = self._decor_pixmap.scaled(self._decor_pixmap.width() * _SCALE, self._decor_pixmap.height() * _SCALE) self._decor_pixmap = self._decor_pixmap.transformed(QTransform().rotate(self.angle)) self._decor_label.setPixmap(self._decor_pixmap) def updatePixmap(self): path = _PATH + os.sep + "assets" + os.sep + self._base_image self.__pixmap = QPixmap(path) self.__pixmap = self.__pixmap.scaled(self.__pixmap.width()*_SCALE, self.__pixmap.height()*_SCALE) self.__pixmap = self.__pixmap.transformed(QTransform().rotate(self.angle)) self._base_label.setPixmap(self.__pixmap) self.setFixedSize(self.__pixmap.width(), self.__pixmap.height()) def setFixedSize(self, x, y): super().setFixedSize(x, y) self._base_label.setFixedSize(x, y) def setAlignment(self, alignment): self._base_label.setAlignment(alignment) self._decor_label.setAlignment(alignment)
class Entity(QWidget): def __init__(self, base_image, parent=None): super().__init__(parent) self._base_label = QLabel(self) self._base_image = base_image self._decor_label = QLabel(self) self._decor_pixmap = None self.__pixmap = None """:type: PyQt4.QtGui.QPixmap""" self.__cord_x = 0 self.__cord_y = 0 self.__angle = 0 self.setAlignment(Qt.AlignCenter) self.updatePixmap() if _debugging: self.setStyleSheet("border: 1px solid black") @property def angle(self): return self.__angle @angle.setter def angle(self, angle): self.__angle = angle self.updatePixmap() @property def cord_x(self): return self.__cord_x @cord_x.setter def cord_x(self, cord): self.__cord_x = cord self.move(self.cord_x, self.cord_y) @property def cord_y(self): return self.__cord_y @cord_y.setter def cord_y(self, cord): self.__cord_y = cord self.move(self.cord_x, self.cord_y) def add_decoration(self, path): if path is None: self._decor_label.hide() else: self._decor_label = QLabel(self) self._decor_pixmap = QPixmap(path) self._decor_pixmap = self._decor_pixmap.scaled( self._decor_pixmap.width() * _SCALE, self._decor_pixmap.height() * _SCALE) self._decor_pixmap = self._decor_pixmap.transformed( QTransform().rotate(self.angle)) self._decor_label.setPixmap(self._decor_pixmap) def updatePixmap(self): path = _PATH + os.sep + "assets" + os.sep + self._base_image self.__pixmap = QPixmap(path) self.__pixmap = self.__pixmap.scaled(self.__pixmap.width() * _SCALE, self.__pixmap.height() * _SCALE) self.__pixmap = self.__pixmap.transformed(QTransform().rotate( self.angle)) self._base_label.setPixmap(self.__pixmap) self.setFixedSize(self.__pixmap.width(), self.__pixmap.height()) def setFixedSize(self, x, y): super().setFixedSize(x, y) self._base_label.setFixedSize(x, y) def setAlignment(self, alignment): self._base_label.setAlignment(alignment) self._decor_label.setAlignment(alignment)
class Entity(QWidget): def __init__(self, base_image, size, hp=100, pos=(0, 0), parent=None): super().__init__(parent) self._base_label = QLabel(self) self._base_image = base_image self._size = size self._decor_label = None self._decor_pixmap = None self._hp_max = hp self.__pixmap = None """:type: PyQt4.QtGui.QPixmap""" self.__cord_x = pos[0] self.__cord_y = pos[1] self.__angle = 0 self.__hp_bar = QProgressBar(self) self.__hp_bar.setMaximum(self._hp_max) self.__hp_bar.setValue(self._hp_max) self.__hp_bar.setTextVisible(False) self.__hp_bar.setMaximumSize(size[0], 5) self.setAlignment(Qt.AlignCenter) self.updatePixmap() if _debugging: self.setStyleSheet("border: 1px solid black") @property def health(self): return self.__hp_bar.value() @health.setter def health(self, hp): if hp > self._hp_max: hp = self._hp_max elif hp < 0: hp = 0 self.__hp_bar.setValue(hp) @property def angle(self): return self.__angle @angle.setter def angle(self, angle): self.__angle = angle self.updatePixmap() @property def cord_x(self): return self.__cord_x @cord_x.setter def cord_x(self, cord): self.__cord_x = cord self.move(self.cord_x, self.cord_y) @property def cord_y(self): return self.__cord_y @cord_y.setter def cord_y(self, cord): self.__cord_y = cord self.move(self.cord_x, self.cord_y) def hide_hp_bar(self, bool=False): if bool: self.__hp_bar.hide() else: self.__hp_bar.show() def add_decoration(self, path): if path is None: self._decor_label.deleteLater() self._decor_label = None else: self._decor_label = QLabel(self) self._decor_pixmap = QPixmap(path) # self._decor_pixmap = self._decor_pixmap.scaled(self._size[0], self._size[1]) self._decor_pixmap = self._decor_pixmap.transformed(QTransform().rotate(self.angle)) self._decor_label.setPixmap(self._decor_pixmap) self._decor_label.setAlignment(Qt.AlignCenter) self._decor_label.show() def updatePixmap(self): path = get_asset_path(self._base_image) self.__pixmap = QPixmap(path) self.__pixmap = self.__pixmap.scaled(self._size[0], self._size[1]) self.__pixmap = self.__pixmap.transformed(QTransform().rotate(self.angle)) self._base_label.setPixmap(self.__pixmap) self._base_label.show() # self.setFixedSize(self.__pixmap.width(), self.__pixmap.height()) def setFixedSize(self, x, y): super().setFixedSize(x, y) self._base_label.setFixedSize(x, y) def setAlignment(self, alignment): self._base_label.setAlignment(alignment)