Python PyQt5.QtCore.Qt() Examples

The following are 30 code examples of PyQt5.QtCore.Qt(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PyQt5.QtCore , or try the search function .
Example #1
Source File: items.py    From Miyamoto with GNU General Public License v3.0 6 votes vote down vote up
def paint(self, painter, option, widget):
        """
        Paints the path
        """
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setClipRect(option.exposedRect)

        if self.isSelected():
            painter.setBrush(QtGui.QBrush(globals.theme.color('nabbit_path_fill_s')))
            painter.setPen(QtGui.QPen(globals.theme.color('nabbit_path_lines_s'), 1 / 24 * globals.TileWidth))
        else:
            painter.setBrush(QtGui.QBrush(globals.theme.color('nabbit_path_fill')))
            painter.setPen(QtGui.QPen(globals.theme.color('nabbit_path_lines'), 1 / 24 * globals.TileWidth))
        painter.drawRoundedRect(self.RoundedRect, 4, 4)

        painter.setFont(self.font)
        painter.drawText(self.RoundedRect, Qt.AlignCenter, str(self.nodeid)) 
Example #2
Source File: puzzle.py    From Miyamoto with GNU General Public License v3.0 6 votes vote down vote up
def addObj(self):
        global Tileset

        Tileset.addObject(new=True)

        pix = QtGui.QPixmap(24, 24)
        pix.fill(Qt.transparent)

        painter = QtGui.QPainter(pix)
        painter.drawPixmap(0, 0, Tileset.tiles[0].image.scaledToWidth(24, Qt.SmoothTransformation))
        painter.end()
        del painter

        count = len(Tileset.objects)
        item = QtGui.QStandardItem(QtGui.QIcon(pix), 'Object {0}'.format(count-1))
        item.setFlags(item.flags() & ~Qt.ItemIsEditable)
        window.objmodel.appendRow(item)
        index = window.objectList.currentIndex()
        window.objectList.setCurrentIndex(index)
        self.setObject(index)

        window.objectList.update()
        self.update() 
Example #3
Source File: puzzle.py    From Miyamoto with GNU General Public License v3.0 6 votes vote down vote up
def updateList(self):
        # Update the list >.>
        object = window.objmodel.itemFromIndex(window.objectList.currentIndex())
        if not object: return


        tex = QtGui.QPixmap(self.size[0] * 24, self.size[1] * 24)
        tex.fill(Qt.transparent)
        painter = QtGui.QPainter(tex)

        Xoffset = 0
        Yoffset = 0

        for y, row in enumerate(self.tiles):
            for x, tile in enumerate(row):
                painter.drawPixmap(x*24, y*24, tile)

        painter.end()

        object.setIcon(QtGui.QIcon(tex))

        window.objectList.update() 
Example #4
Source File: spritelib.py    From Miyamoto with GNU General Public License v3.0 6 votes vote down vote up
def setSize(self, width):
        self.prepareGeometryChange()
        self.BoundingRect = QtCore.QRectF(0, 0, width * (TileWidth/16), width * (TileWidth/16))

        centerOffset = (8 - (width / 2)) * (TileWidth/16)
        fullOffset = -(width * (TileWidth/16)) + TileWidth

        xval = 0
        if self.alignMode & Qt.AlignHCenter:
            xval = centerOffset
        elif self.alignMode & Qt.AlignRight:
            xval = fullOffset

        yval = 0
        if self.alignMode & Qt.AlignVCenter:
            yval = centerOffset
        elif self.alignMode & Qt.AlignBottom:
            yval = fullOffset

        self.setPos(xval, yval)
        self.width = width 
Example #5
Source File: puzzle.py    From Miyamoto with GNU General Public License v3.0 6 votes vote down vote up
def saveImage(self, nml=False):

        fn = QtWidgets.QFileDialog.getSaveFileName(self, 'Choose a new filename', '', '.png (*.png)')[0]
        if fn == '': return

        tex = QtGui.QPixmap(960, 960)
        tex.fill(Qt.transparent)
        painter = QtGui.QPainter(tex)

        Xoffset = 0
        Yoffset = 0

        for tile in Tileset.tiles:
            tileimg = tile.image
            if nml:
                tileimg = tile.normalmap
            painter.drawPixmap(Xoffset, Yoffset, tileimg)
            Xoffset += 60
            if Xoffset >= 960:
                Xoffset = 0
                Yoffset += 60

        painter.end()

        tex.save(fn) 
Example #6
Source File: tileset.py    From Miyamoto with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, main=None, nml=None):
        """
        Initializes the TilesetTile
        """
        if not main:
            main = QtGui.QPixmap(60, 60)
            main.fill(Qt.transparent)
            self.exists = False

        self.main = main

        if not nml:
            nml = QtGui.QPixmap(60, 60)
            nml.fill(QtGui.QColor(128, 128, 255))

        self.nml = nml
        self.isAnimated = False
        self.animFrame = 0
        self.animTiles = []
        self.setCollisions(0)
        self.collOverlay = None 
Example #7
Source File: items.py    From Miyamoto with GNU General Public License v3.0 6 votes vote down vote up
def paint(self, painter, option, widget):
        """
        Paints the path
        """
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setClipRect(option.exposedRect)

        if self.isSelected():
            painter.setBrush(QtGui.QBrush(globals.theme.color('path_fill_s')))
            painter.setPen(QtGui.QPen(globals.theme.color('path_lines_s'), 1 / 24 * globals.TileWidth))
        else:
            painter.setBrush(QtGui.QBrush(globals.theme.color('path_fill')))
            painter.setPen(QtGui.QPen(globals.theme.color('path_lines'), 1 / 24 * globals.TileWidth))
        painter.drawRoundedRect(self.RoundedRect, 4, 4)

        painter.setFont(self.font)
        margin = globals.TileWidth / 10
        painter.drawText(QtCore.QRectF(margin, margin, globals.TileWidth / 2 - margin, globals.TileWidth / 2 - margin), Qt.AlignCenter,
                         str(self.pathid))
        painter.drawText(QtCore.QRectF(margin, globals.TileWidth / 2, globals.TileWidth / 2 - margin, globals.TileWidth / 2 - margin),
                         Qt.AlignCenter, str(self.nodeid)) 
Example #8
Source File: stamp.py    From Miyamoto with GNU General Public License v3.0 6 votes vote down vote up
def data(self, index, role=Qt.DisplayRole):
        """
        Get what we have for a specific row
        """
        if not index.isValid(): return None
        n = index.row()
        if n < 0: return None
        if n >= len(self.items): return None

        if role == Qt.DecorationRole:
            return self.items[n].Icon

        elif role == Qt.BackgroundRole:
            return QtWidgets.qApp.palette().base()

        elif role == Qt.UserRole:
            return self.items[n].Name

        elif role == Qt.StatusTipRole:
            return self.items[n].Name

        else:
            return None 
Example #9
Source File: ui.py    From Miyamoto with GNU General Public License v3.0 6 votes vote down vote up
def ParseCategory(self, items):
        """
        Parses a XML category
        """
        nodes = []
        for item in items:
            node = QtWidgets.QTreeWidgetItem()
            node.setText(0, item[0])
            # see if it's a category or a level
            if isinstance(item[1], str):
                # it's a level
                node.setData(0, Qt.UserRole, item[1])
                node.setToolTip(0, item[1])
            else:
                # it's a category
                children = self.ParseCategory(item[1])
                for cnode in children:
                    node.addChild(cnode)
                node.setToolTip(0, item[0])
            nodes.append(node)
        return tuple(nodes) 
Example #10
Source File: part-1.py    From Writer-Tutorial with MIT License 6 votes vote down vote up
def save(self):

        # Only open dialog if there is no filename yet
        #PYQT5 Returns a tuple in PyQt5, we only need the filename
        if not self.filename:
          self.filename = QtWidgets.QFileDialog.getSaveFileName(self, 'Save File')[0]

        if self.filename:

            # Append extension if not there yet
            if not self.filename.endswith(".writer"):
              self.filename += ".writer"

            # We just store the contents of the text file along with the
            # format in html, which Qt does in a very nice way for us
            with open(self.filename,"wt") as file:
                file.write(self.text.toHtml())

            self.changesSaved = True 
Example #11
Source File: items.py    From Miyamoto with GNU General Public License v3.0 6 votes vote down vote up
def UpdateListItem(self, updateTooltipPreview=False):
        """
        Updates the list item
        """
        if not hasattr(self, 'listitem'): return
        if self.listitem is None: return

        if updateTooltipPreview:
            # It's just like Qt to make this overly complicated. XP
            img = self.renderInLevelIcon()
            byteArray = QtCore.QByteArray()
            buf = QtCore.QBuffer(byteArray)
            img.save(buf, 'PNG')
            byteObj = bytes(byteArray)
            b64 = base64.b64encode(byteObj).decode('utf-8')

            self.listitem.setToolTip('<img src="data:image/png;base64,' + b64 + '" />')

        self.listitem.setText(self.ListString()) 
Example #12
Source File: items.py    From Miyamoto with GNU General Public License v3.0 6 votes vote down vote up
def paint(self, painter, option, widget):
        """
        Paints the object
        """
        if self.isSelected():
            painter.setPen(QtGui.QPen(globals.theme.color('object_lines_s'), 1, Qt.DotLine))
            painter.drawRect(self.SelectionRect)
            painter.fillRect(self.SelectionRect, globals.theme.color('object_fill_s'))

            painter.fillRect(self.DrawGrabberRectTL, globals.theme.color('object_lines_s'))
            painter.fillRect(self.DrawGrabberRectTR, globals.theme.color('object_lines_s'))
            painter.fillRect(self.DrawGrabberRectBL, globals.theme.color('object_lines_s'))
            painter.fillRect(self.DrawGrabberRectBR, globals.theme.color('object_lines_s'))
            painter.fillRect(self.DrawGrabberRectMT, globals.theme.color('object_lines_s'))
            painter.fillRect(self.DrawGrabberRectML, globals.theme.color('object_lines_s'))
            painter.fillRect(self.DrawGrabberRectMB, globals.theme.color('object_lines_s'))
            painter.fillRect(self.DrawGrabberRectMR, globals.theme.color('object_lines_s')) 
Example #13
Source File: puzzle.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def newTileset(self):
        '''Creates a new, blank tileset'''

        global Tileset
        Tileset.clear()
        Tileset = TilesetClass()

        EmptyPix = QtGui.QPixmap(60, 60)
        EmptyPix.fill(Qt.black)

        normalmap = QtGui.QPixmap(60, 60)
        normalmap.fill(QtGui.QColor(0x80, 0x80, 0xff))

        for i in range(256):
            Tileset.addTile(EmptyPix, normalmap)

        Tileset.slot = self.slot
        self.tileWidget.tilesetType.setText('Pa{0}'.format(Tileset.slot))

        self.setuptile()

        cobj = 0
        crow = 0
        ctile = 0
        for object in Tileset.objects:
            for row in object.tiles:
                for tile in row:
                    if tile[2] & 3 or not Tileset.slot:
                        Tileset.objects[cobj].tiles[crow][ctile] = (tile[0], tile[1], (tile[2] & 0xFC) | Tileset.slot)
                    ctile += 1
                crow += 1
                ctile = 0
            cobj += 1
            crow = 0
            ctile = 0 
Example #14
Source File: puzzle.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def setObject(self, object):
        self.clear()

        global Tileset

        self.size = [object.width, object.height]
        self.setMinimumSize(self.size[0]*24 + 12, self.size[1]*24 + 12)

        if not object.upperslope[1] == 0:
            if object.upperslope[0] & 2:
                self.slope = -object.upperslope[1]
            else:
                self.slope = object.upperslope[1]

        x = 0
        y = 0
        for row in object.tiles:
            self.tiles.append([])
            for tile in row:
                if (Tileset.slot == 0) or ((tile[2] & 3) != 0):
                    self.tiles[-1].append(Tileset.tiles[tile[1]].image.scaledToWidth(24, Qt.SmoothTransformation))
                else:
                    pix = QtGui.QPixmap(24,24)
                    pix.fill(QtGui.QColor(0,0,0,0))
                    self.tiles[-1].append(pix)
                x += 1
            y += 1
            x = 0


        self.object = window.objectList.currentIndex().row()
        self.update()
        self.updateList()

        window.tileWidget.repeatX.update()
        window.tileWidget.repeatY.update()
        window.tileWidget.slopeLine.update() 
Example #15
Source File: puzzle.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def supportedDragActions(self):
        super().supportedDragActions()
        return Qt.CopyAction | Qt.MoveAction | Qt.LinkAction 
Example #16
Source File: puzzle.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def data(self, index, role=Qt.DisplayRole):
        if not index.isValid():
            return None

        if role == Qt.DecorationRole:
            return QtGui.QIcon(self.pixmaps[index.row()])

        if role == Qt.UserRole:
            return self.pixmaps[index.row()]

        return None 
Example #17
Source File: puzzle.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def mimeData(self, indexes):
        mimeData = QtCore.QMimeData()
        encodedData = QtCore.QByteArray()

        stream = QtCore.QDataStream(encodedData, QtCore.QIODevice.WriteOnly)

        for index in indexes:
            if index.isValid():
                pixmap = QtGui.QPixmap(self.data(index, Qt.UserRole))
                stream << pixmap

        mimeData.setData('image/x-tile-piece', encodedData)
        return mimeData 
Example #18
Source File: puzzle.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def supportedDragActions(self):
        return Qt.CopyAction | Qt.MoveAction



#############################################################################################
############ Main Window Class. Takes care of menu functions and widget creation ############ 
Example #19
Source File: model_bind.py    From corrscope with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def set_model(self, value: CheckState):
        """Qt.PartiallyChecked probably should not happen."""
        Qt = qc.Qt
        assert value in [Qt.Unchecked, Qt.PartiallyChecked, Qt.Checked]
        self.set_bool(value != Qt.Unchecked) 
Example #20
Source File: puzzle.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def setuptile(self):
        self.tileWidget.tiles.clear()
        self.model.clear()

        if self.normalmap:
            for tile in Tileset.tiles:
                self.model.addPieces(tile.normalmap.scaledToWidth(24, Qt.SmoothTransformation))
        else:
            for tile in Tileset.tiles:
                self.model.addPieces(tile.image.scaledToWidth(24, Qt.SmoothTransformation)) 
Example #21
Source File: model_bind.py    From corrscope with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def calc_error_palette(self) -> QPalette:
        """ Palette with red background, used for widgets with invalid input. """
        error_palette = QPalette(self.palette())

        bg = error_palette.color(QPalette.Base)
        red = QColor(qc.Qt.red)

        red_bg = blend_colors(bg, red, 0.5)
        error_palette.setColor(QPalette.Base, red_bg)
        return error_palette

    # My class/method naming scheme is inconsistent and unintuitive.
    # PresentationModel+set_model vs. cfg2gui+set_gui vs. widget
    # Feel free to improve the naming. 
Example #22
Source File: tileset.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def _compressBC3_libtxc_dxtn(tex, tile_path):
    """
    RGBA8 QPixmap -> BC3 DDS
    Uses our port of `libtxc_dxtn` (or Wexos's Compressor if Cython is not available)
    """
    data = tex.bits()
    data.setsize(tex.byteCount())
    data = data.asstring()

    dataList = []
    dataList.append(bc3.compress(data, 2048, 512))

    for i in range(1, 12):
        mipTex = QtGui.QImage(tex).scaledToWidth(max(1, 2048 >> i), Qt.SmoothTransformation)
        mipTex = mipTex.convertToFormat(QtGui.QImage.Format_RGBA8888)

        mipData = mipTex.bits()
        mipData.setsize(mipTex.byteCount())
        mipData = mipData.asstring()

        dataList.append(
            bc3.compress(mipData, max(1, 2048 >> i), max(1, 512 >> i)))

    with open(tile_path + '/tmp.dds', 'wb+') as out:
        out.write(dds.generateHeader(2048, 512, 0x33, 12))
        for data in dataList:
            out.write(data) 
Example #23
Source File: model_bind.py    From corrscope with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def on_check(self, value: CheckState):
        """Qt.PartiallyChecked probably should not happen."""
        Qt = qc.Qt
        assert value in [Qt.Unchecked, Qt.PartiallyChecked, Qt.Checked]
        if value != Qt.Unchecked:
            self.color_text.setText("#ffffff")
        else:
            self.color_text.setText("")


# Unused 
Example #24
Source File: stamp.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def setData(self, index, value, role=Qt.DisplayRole):
        """
        Set data for a specific row
        """
        if not index.isValid(): return None
        n = index.row()
        if n < 0: return None
        if n >= len(self.items): return None

        if role == Qt.UserRole:
            self.items[n].Name = value 
Example #25
Source File: dialogs.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, widget=None, initialWidth=-1, initialHeight=-1):
            super().__init__()

            self.setWidgetResizable(True)
            self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

            deltaWidth = globals.app.style().pixelMetric(QtWidgets.QStyle.PM_ScrollBarExtent)

            if widget:
                self.setWidget(widget)

                if initialWidth == -1:
                    initialWidth = widget.sizeHint().width()

                if initialHeight == -1:
                    initialHeight = widget.sizeHint().height()

            if initialWidth == -1:
                initialWidth = super().sizeHint().width()

            else:
                initialWidth += deltaWidth

            if initialHeight == -1:
                initialHeight = super().sizeHint().height()

            else:
                initialHeight += deltaWidth

            self.initialWidth = initialWidth
            self.initialHeight = initialHeight 
Example #26
Source File: stamp.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def render(self):
        """
        Renders the stamp icon, preview AND text
        """

        # Get the preview icon
        prevIcon = self.renderPreview()

        # Calculate the total size of the icon
        textSize = self.calculateTextSize(self.Name)
        totalWidth = max(prevIcon.width(), textSize.width())
        totalHeight = prevIcon.height() + 2 + textSize.height()

        # Make a pixmap and painter
        pix = QtGui.QPixmap(totalWidth, totalHeight)
        pix.fill(Qt.transparent)
        painter = QtGui.QPainter(pix)

        # Draw the preview
        iconXOffset = (totalWidth - prevIcon.width()) / 2
        painter.drawPixmap(iconXOffset, 0, prevIcon)

        # Draw the text
        textRect = QtCore.QRectF(0, prevIcon.height() + 2, totalWidth, textSize.height())
        painter.setFont(QtGui.QFont())
        painter.drawText(textRect, Qt.AlignTop | Qt.TextWordWrap, self.Name)

        # Return the pixmap
        return pix 
Example #27
Source File: stamp.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def calculateTextSize(text):
        """
        Calculates the size of text. Crops to 96 pixels wide.
        """
        fontMetrics = QtGui.QFontMetrics(QtGui.QFont())
        fontRect = fontMetrics.boundingRect(QtCore.QRect(0, 0, 96, 48), Qt.TextWordWrap, text)
        w, h = fontRect.width(), fontRect.height()
        return QtCore.QSizeF(min(w, 96), h) 
Example #28
Source File: items.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def paint(self, painter, option, widget):
        """
        Paints the path lines
        """
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setClipRect(option.exposedRect)

        color = globals.theme.color('nabbit_path_connector')
        painter.setBrush(QtGui.QBrush(color))
        painter.setPen(QtGui.QPen(color, 3 * globals.TileWidth / 24, join=Qt.RoundJoin, cap=Qt.RoundCap))

        lines = []

        snl = self.nodelist
        mult = globals.TileWidth / 16
        for j, node in enumerate(snl):
            if ((j + 1) < len(snl)):
                a = QtCore.QPointF(float(snl[j]['x'] * mult) - self.x(), float(snl[j]['y'] * mult) - self.y())
                b = QtCore.QPointF(float(snl[j + 1]['x'] * mult) - self.x(), float(snl[j + 1]['y'] * mult) - self.y())
                lines.append(QtCore.QLineF(a, b))
            elif self.loops and (j + 1) == len(snl):
                a = QtCore.QPointF(float(snl[j]['x'] * mult) - self.x(), float(snl[j]['y'] * mult) - self.y())
                b = QtCore.QPointF(float(snl[0]['x'] * mult) - self.x(), float(snl[0]['y'] * mult) - self.y())
                lines.append(QtCore.QLineF(a, b))

        painter.drawLines(lines) 
Example #29
Source File: ui.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def HandleItemChange(self, current, previous):
        """
        Catch the selected level and enable/disable OK button as needed
        """
        self.currentlevel = current.data(0, Qt.UserRole)
        if self.currentlevel is None:
            self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(False)
        else:
            self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(True)
            self.currentlevel = str(self.currentlevel) 
Example #30
Source File: ui.py    From Miyamoto with GNU General Public License v3.0 5 votes vote down vote up
def HandleItemActivated(self, item, column):
        """
        Handle a doubleclick on a level
        """
        self.currentlevel = item.data(0, Qt.UserRole)
        if self.currentlevel is not None:
            self.currentlevel = str(self.currentlevel)
            self.accept()