Giter Club home page Giter Club logo

Comments (8)

PierreRaybaut avatar PierreRaybaut commented on September 17, 2024

I have tested this part of the code with the following script with Python 2.7 and Python 3.4 and it works:
(what version of Python 3 are you using?)

import struct
from qwt.qt.QtGui import (QApplication, QColor, QFont, QPixmap, QFontMetrics,
                          QPainter)
from qwt.qt.QtCore import Qt

def findAscent(font):
    dummy = "E"
    white = QColor(Qt.white)
    fm = QFontMetrics(font)
    pm = QPixmap(fm.width(dummy), fm.height())
    pm.fill(white)
    p = QPainter(pm)
    p.setFont(font)
    p.drawText(0, 0, pm.width(), pm.height(), 0, dummy)
    p.end()
    img = pm.toImage()
    w = pm.width()
    linebytes = w*4
    for row in range(img.height()):
        line = img.scanLine(row).asstring(linebytes)
        for col in range(w):
            color = struct.unpack('I', line[col*4:(col+1)*4])[0]
            if color != white.rgb():
                return fm.ascent()-row+1
    return fm.ascent()

if __name__ == '__main__':
    app = QApplication([])
    font = QFont('Arial')
    print(findAscent(font))

from pythonqwt.

PierreRaybaut avatar PierreRaybaut commented on September 17, 2024

Tested on Python 3.3 on Windows 10. It works too.

from pythonqwt.

picca avatar picca commented on September 17, 2024

com-sixs@sixs7:~/picca/bugs$ python3.4 test.py
Traceback (most recent call last):
File "test.py", line 30, in
print(findAscent(font))
File "test.py", line 20, in findAscent
line = img.scanLine(row).asstring(linebytes)
SystemError: Bad call flags in PyCFunction_Call. METH_OLDARGS is no longer supported!

from pythonqwt.

picca avatar picca commented on September 17, 2024

I split the line and it failes with the asstring method

Traceback (most recent call last):
File "test.py", line 32, in
print(findAscent(font))
File "test.py", line 22, in findAscent
line = sline.asstring(linebytes)
SystemError: Bad call flags in PyCFunction_Call. METH_OLDARGS is no longer supported!

from pythonqwt.

picca avatar picca commented on September 17, 2024

https://bugs.python.org/issue15657

I think that there is a bad interaction with sip

from pythonqwt.

picca avatar picca commented on September 17, 2024

https://riverbankcomputing.com/pipermail/pyqt/2014-December/035201.html

from pythonqwt.

PierreRaybaut avatar PierreRaybaut commented on September 17, 2024

Ok, I think you found the source of the problem.

Given the fact that Phil Thompson wrote here that the bug was fixed in latest sip snapshot on december 2014, it should be fixed with PyQt4 >= 4.11.4 and PyQt5 >= 5.4.

So the question is: what version of PyQt are you using? and would it be possible for you to upgrade your PyQt installation?

from pythonqwt.

picca avatar picca commented on September 17, 2024

ii python-sip 4.16.4+dfsg-1 amd64 Python/C++ bindings generator runtime library
ii python3-sip 4.16.4+dfsg-1 amd64 Python 3/C++ bindings generator runtime library
picca@sixs7:~/Debian/guiqwt$ dpkg -l | grep python-qt4
ii python-qt4 4.11.2+dfsg-1 amd64 Python bindings for Qt4
ii python-qt4-gl 4.11.2+dfsg-1 amd64 Python bindings for Qt4's OpenGL module

The current Debian jessie is affected by this bug :((. It means that for now it is not possible to backport the python3 version of python-qwt. Not a big deal, but it is nice to have the info somewhere :)

thanks

from pythonqwt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.