Repository: spyder-ide/spyder

Issue:
Spyder won't start after upgrade to 3.1.0 due to an error with QRegularExpression
## Description of your problem

**What steps will reproduce the problem?**

1. Start spyder from terminal

**What is the expected output? What do you see instead?**
I expect spyder to start, instead I get an error:

> spyder
QML debugging is enabled. Only use this in a safe environment.
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/spyder/app/mainwindow.py", line 2979, in main
    mainwindow = run_spyder(app, options, args)
  File "/usr/lib/python2.7/site-packages/spyder/app/mainwindow.py", line 2883, in run_spyder
    main.setup()
  File "/usr/lib/python2.7/site-packages/spyder/app/mainwindow.py", line 780, in setup
    message=_("Spyder Internal Console\n\n"
  File "/usr/lib/python2.7/site-packages/spyder/plugins/console.py", line 79, in __init__
    self.find_widget.set_editor(self.shell)
  File "/usr/lib/python2.7/site-packages/spyder/widgets/findreplace.py", line 280, in set_editor
    self.refresh()
  File "/usr/lib/python2.7/site-packages/spyder/widgets/findreplace.py", line 259, in refresh
    self.find()
  File "/usr/lib/python2.7/site-packages/spyder/widgets/findreplace.py", line 326, in find
    self.editor.find_text('')
  File "/usr/lib/python2.7/site-packages/spyder/widgets/mixins.py", line 513, in find_text
    found_cursor = self.document().find(pattern, cursor, findflag)
TypeError: arguments did not match any overloaded call:
  QTextDocument.find(str, int position=0, QTextDocument.FindFlags options=0): argument 1 has unexpected type 'QRegularExpression'
  QTextDocument.find(QRegExp, int position=0, QTextDocument.FindFlags options=0): argument 1 has unexpected type 'QRegularExpression'
  QTextDocument.find(str, QTextCursor, QTextDocument.FindFlags options=0): argument 1 has unexpected type 'QRegularExpression'
  QTextDocument.find(QRegExp, QTextCursor, QTextDocument.FindFlags options=0): argument 1 has unexpected type 'QRegularExpression'

**Please provide any additional information below**


## Versions and main components

* Spyder Version: 3.1.0
* Python Version: 2.7.12
* Operating system: OpenSuse 13.2


## Dependencies

Please go to the menu entry `Help > Optional Dependencies` (or
`Help > Dependencies`), press the button `Copy to clipboard`
and paste the contents below:
I can't get spyder to start, so ...



Discussion:
@rlaverde
What are your qt and pyqt versions?
PyQt5: 5.3.1
PyQt4: 4.11.1
How do I get the Qt-version?
Yast is showing me a bunch of libs (for instance "libqt5-qtbase-devel"), from there:
Qt5: 5.4.2
Qt4: 4.8.6
I think this is a bug of Qt5, you should upgrade to PyQt>=5.5

QRegularExpression was [introduced](http://doc.qt.io/qt-5/qregularexpression.html) in Qt 5.0 but QTextDocument.find supporting QRegularExpression was [introduced](http://doc.qt.io/qt-5/qtextdocument.html#find-4) in Qt 5.5

@ccordoba12 Since we are supporting PyQt5 5.2+,  Should we implement a workaround for this?
@rlaverde, yes. Please add a check for qt 5.5+ where you introduced this feature.

This is a priority for 3.1.1, so I want a PR as soon as possible :-)
> you should upgrade to PyQt>=5.5

I can't. Pip can't and opensuse does not offer an update.

Pip:
> pip2 install PyQt5
Downloading/unpacking PyQt5
  Could not find any downloads that satisfy the requirement PyQt5
Cleaning up...
No distributions at all found for PyQt5
Storing debug log for failure in /root/.pip/pip.log
> you should upgrade to PyQt>=5.5

I can't. Pip can't and opensuse does not offer an update.

Pip:
> pip2 install PyQt5
Downloading/unpacking PyQt5
  Could not find any downloads that satisfy the requirement PyQt5
Cleaning up...
No distributions at all found for PyQt5
Storing debug log for failure in /root/.pip/pip.log

Resolving patch:
diff --git a/spyder/widgets/mixins.py b/spyder/widgets/mixins.py
--- a/spyder/widgets/mixins.py
+++ b/spyder/widgets/mixins.py
@@ -22,22 +22,23 @@
 from qtpy.QtCore import QPoint, Qt
 from qtpy.QtGui import QCursor, QTextCursor, QTextDocument
 from qtpy.QtWidgets import QApplication, QToolTip
-from qtpy import PYQT5
-
-if PYQT5:
-    from qtpy.QtCore import QRegularExpression
-else:
-    from qtpy.QtCore import QRegExp
+from qtpy import QT_VERSION
 
 # Local imports
 from spyder.config.base import _
 from spyder.py3compat import is_text_string, to_text_string, u
-from spyder.utils import encoding, sourcecode
+from spyder.utils import encoding, sourcecode, programs
 from spyder.utils.dochelpers import (getargspecfromtext, getobj,
                                      getsignaturefromtext)
 from spyder.utils.misc import get_error_match
 from spyder.widgets.arraybuilder import NumpyArrayDialog
 
+QT55_VERSION = programs.check_version(QT_VERSION, "5.5", ">=")
+
+if QT55_VERSION:
+    from qtpy.QtCore import QRegularExpression
+else:
+    from qtpy.QtCore import QRegExp
 
 HISTORY_FILENAMES = []
 
@@ -490,7 +491,7 @@ def find_text(self, text, changed=True, forward=True, case=False,
             moves += [QTextCursor.End]
         if not regexp:
             text = re.escape(to_text_string(text))
-        if PYQT5:
+        if QT55_VERSION:
             pattern = QRegularExpression(r"\b{}\b".format(text) if words else
                                          text)
             if case:


Test patch: