Git Product home page Git Product logo

pyqt4topyqt5's Introduction

pyqt4topyqt5

pyqt4 -> pyqt5

Usage

// install the tool
pip install .

pyqt4topyqt5 [-h] [--nosubdir] [--followlinks] [-o O]
             [--diff [DIFF]] [--diffs] [--nolog] [--nopyqt5]
             path

Basic example: porting the content of pyqt4app to pyqt5 in the directory pyqt5app:

pyqt4topyqt5 pyqt4app -o pyqt5app

pyqt4topyqt5's People

Contributors

bill-auger avatar hnasar avatar igordejanovic avatar mclam009 avatar rferrazz avatar smidm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyqt4topyqt5's Issues

QModelIndex

The following code:

self.connect(self, QtCore.SIGNAL("clicked(const QModelIndex &)"), self.clicked)

gets converted to

self.clicked[QModelIndex].connect(self.clicked)

But that code is giving me an error:

Traceback (most recent call last):
  File "C:\Users\mthorade\Anaconda3\lib\site-packages\ifcopenshell\geom\app.py", line 592, in browse
    self.load(filename)
  File "C:\Users\mthorade\Anaconda3\lib\site-packages\ifcopenshell\geom\app.py", line 605, in load
    c.load_file(f, setting=self.settings)
  File "C:\Users\mthorade\Anaconda3\lib\site-packages\ifcopenshell\geom\app.py", line 215, in load_file
    self.clicked[QModelIndex].connect(self.clicked)
NameError: name 'QModelIndex' is not defined

Am I doing somethign wrong, or is it a bug?

setAcceptsHoverEvents() is not translated into setAcceptHoverEvents() appropriately

In over-riding class for QtGui.QGraphicsRectItem in PyQt, self.setAcceptsHoverEvents(True) could be called. By pyqt4topyqt5.py, QtGui.QGraphicsRectItem is converted into QtWidgets.QGraphicsRectItem and it's correct.

However, self.setAcceptsHoverEvents(True) should be converted into self.setAcceptHoverEvents(True) in the class but it does not.

split_function throws IndexError

Example

from PyQt4.QtCore import QSettings
foo().connect(bar)

i in incremented and function[i] is accessed without checking if the index is valid.

It appears that fun_re fails to produce the match expected by split_function. It would be helpful to have comments about the intention of the code.

feature request: convert old style signals to new style signals ONLY

pyQt4 supports old style signals and new style signals,
pyQt5 supports new stylesignals only,
according to
http://pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html

This script converts from old to new style, but it also does a lot of other things.
Would it be possible to do the conversion in two steps, first convert only the signals to the new style, resulting in code that still works in pyQt4 (but not yet in pyQt5)?
Then, the second step would change the imports, thus breaking pyQt4 support.

Embedded Null Character

Command Prompt:

C:\Users\user\Desktop_DEV\qt4toqt5>pyqt4topyqt5.py about.pyc -o 11.pyc
Traceback (most recent call last):
File "C:\Users\user\Desktop_DEV\qt4toqt5\pyqt4topyqt5.py", line 2732, in
main = Main(sys.argv)
File "C:\Users\user\Desktop_DEV\qt4toqt5\pyqt4topyqt5.py", line 2499, in init
self.prepare_changes(self.followlinks)
File "C:\Users\user\Desktop_DEV\qt4toqt5\pyqt4topyqt5.py", line 2548, in prepare_changes
self.copy_files(self.destdir, subdirs, files)
File "C:\Users\user\Desktop_DEV\qt4toqt5\pyqt4topyqt5.py", line 2631, in copy_files
if not os.path.isfile(f):
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\genericpath.py", line 30, in isfile
st = os.stat(path)
ValueError: stat: embedded null character

pyqtSignature calls are not converted

I am attempting to convert someone else's code from Python 2 to 3, which requires an upgrade from PyQt4 to PyQt5. I tried using this tool to do the pyqt conversion and found that old style calls to pyqtSignature such as:
@pyqtSignature("")
def on_btn_Right_released(self):
self.tcp.sendData(cmd.CMD_CAMERA_STOP)
do not get converted to the new style Signals and Slots. I am new to PyQt, so doing this manually is beyond my current skill level. As far as I can tell, support for pyqtSignature has been dropped from the latest PyQt5 because even if I change @pyqtSignature to @QtCore.pyqtSignature I get the error:
AttributeError: module 'PyQt5.QtCore' has no attribute 'pyqtSignature'
I attached the original code I'm trying to convert. Any assistance would be appreciated! Thanks.

main.txt

Converting old signals to new signals using snake_case

It would be great if you thought of adding snake case to transformed pyqtSignal rather than having to go through every variable and remove spaces in between the words. Otherwise, very time-saving initiative by the devs. A star is not enough to thank you.

Usage example needed

Hi @rferrazz,

Would it be possible to add an example of how this project is meant to be used somewhere? I'd like to include reference to it for Qt.py as an initial step for projects interested in porting old projects to Qt 5, and was hoping to provide a short tutorial of the whole process.

Best,
Marcus

SIGNAL in character class is wrong

The regex 'send_re' includes '[, SIGNAL]', which looks wrong. I'm sure that the intention was to match "SIGNAL" as one word, not just letters S, I, G, N, A and L.

fix_qfiledialog fails if call inside another function call

PyQt4 code:

from PyQt4 import QtCore, QtGui

class Test(QtGui.QDialog):

    def set_filepath(self):
        self.filePathEdit.setText(
            QtGui.QFileDialog.getOpenFileName(
                self,
                "Choose file",
                self.filePathEdit.text()))

results in

from PyQt5 import QtCore, QtGui, QtWidgets

class Test(QtWidgets.QDialog):

    def set_filepath(self):
        self.filePathEdit.setText(
            QtWidgets.QFileDialog.getOpenFileName(
                self,
                "Choose file",
                self.filePathEdit.text()))[0]

See, the [0] should be before the last parenthesis.

        self.filePathEdit.setText(
            QtWidgets.QFileDialog.getOpenFileName(
                self,
                "Choose file",
                self.filePathEdit.text())[0])  # <--- here

Looks like an issue in find_closing_parenthesis.

Not converting close->quit signal

Maybe my syntax is incorrect but I have code that connects an action to the close event (in PyQt4)

 exit = QtGui.QAction('qaction', self)
 exit.setShortcut('Ctrl+Q')
 exit.setStatusTip('Close application') 
 self.connect(exit, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()'))

pyqt4topyqt5 converts signal-slot to:
exit.triggered.connect(close)

Which errors out converted program.

Instead convert to:
exit.triggered.connect(quit)

QGraphicsItem subclasses init refactoring bug

It seems that all initializations of QGraphicsItem subclasses are refactored in this way:

class MyEllipse(QtGui.QGraphicsEllipseItem):
+class MyEllipse(QtWidgets.QGraphicsEllipseItem):
     def __init__(self, radius=5.0):
-        super(MyEllipse, self).__init__(-radius/2, -radius/2, radius, radius)
+        super(MyEllipse, self).__init__(-radius/2, -radius/2, radius)
+        if radius is not None: radius.addItem(self)

The last argument is assumed to be scene and the addition to the scene is moved to a separate line. This assumption is not always true, in the sample above, the arguments are x, y, width, height and the addition to the scene is done elsewhere.

Workaround

Review the automatic changes using git.

changes not commited yet:

git diff --no-color > diff.txt

already commited changes:

git log # find the commit with changes done by pyqt4topyqt5
git show <commit> --no-color > diff.txt

Find new lines with addItem text using regexp: ^\+.*addItem (e.g. with less diff.txt).

CR versus CR LF

When running the conversion on Windows 10 with Python 3.6, I get broken line endings in some places:
CR LF
becomes

CR LF 
CR 
CR LF

but for some reason not everywhere.
It happened most often in the import section at the top of the file.

First Argument is Self Path (unrecognized arguments error)

Note: This error might be a result of my lack of understanding of how Windows shell commands work.

When executing the script from the Windows shell as such:
C:\path\of\pyqt4topyqt5file\> python pyqt4topyqt5.py fileToConvert.py

The error pyqt4topyqt5.py: error: unrecognized arguments: fileToConvert.py appears, and the conversion doesn't occur.

However, I noticed that when providing no arguments
C:\path\of\pyqt4topyqt5file\> python pyqt4topyqt5.py
the pyqt4topyqt5.py file successfully converts itself, creating the pyqt4topyqt5_PyQt5.py and the log file in the process.

I wondered if the Windows shell might be providing the pyqt4topyqt5.py filename as the first system argument, and after some quick testing that seems to be the case.

This implies to me that the Windows shell starts the system arguments with the original file name, while the program operates with the first system argument being the first given argument (which would result in the self conversion behavior seen above).

I was able to fix this by simply adding an args.pop(0) to the beginning of the init method (line 2435), after which the script seems to work as intended, though I wanted to add this as an issue rather than a change request because I'm unsure if this is how other platforms/systems operate and if there is a proper way of executing this script on Windows.

Hope this helps anyone who was having trouble.

How to run this script?

i have problems understanding the syntax of the execution command....
I downloaded the repository added a folder named source and a folder destination.

But i have no idea to convert this information into a executable command:

sudo python pyqt4topyqt5 ...................????

Thanks for your help

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.