<commit_before>#
# QtHelp.py -- customized Qt widgets and convenience functions
#
# This is open-source software licensed under a BSD license.
# Please see the file LICENSE.txt for details.
#
import glob
import os
import math

import ginga.toolkit
from ginga.util import iohelper
from ginga.misc import Callback, Bunch
from ginga.fonts import font_asst

configured = False

toolkit = ginga.toolkit.toolkit

# if user wants to force a toolkit
if toolkit == 'qt5':
    os.environ['QT_API'] = 'pyqt5'

elif toolkit == 'qt4':
    os.environ['QT_API'] = 'pyqt'

elif toolkit == 'pyside2':
    os.environ['QT_API'] = 'pyside2'

elif toolkit == 'pyside':
    os.environ['QT_API'] = 'pyside'

have_pyqt4 = False
have_pyqt5 = False
have_pyside = False
have_pyside2 = False
qtpy_import_error = ""

try:
    from qtpy import QtCore
    from qtpy import QtWidgets as QtGui
    from qtpy.QtGui import QImage, QColor, QFont, QPixmap, QIcon, QCursor, QPainter, QPen, QPolygonF, QPolygon, QTextCursor, QDrag, QPainterPath, QBrush, QFontDatabase  # noqa
    from qtpy.QtCore import QItemSelectionModel  # noqa
    from qtpy.QtWidgets import QApplication  # noqa
    try:
        from qtpy.QtWebEngineWidgets import QWebEngineView as QWebView  # noqa
    except ImportError as e:
        pass

    # Let's see what qtpy configured for us...
    from qtpy import PYQT4, PYQT5, PYSIDE, PYSIDE2
    have_pyqt4 = PYQT4
    have_pyqt5 = PYQT5
    have_pyside = PYSIDE
    have_pyside2 = PYSIDE2

    configured = True
except ImportError as e:
    qtpy_import_error = "Error importing 'qtpy': {}".format(e)
    # for debugging purposes, uncomment this to get full traceback
    #raise e

if have_pyqt5:
    ginga.toolkit.use('qt5')
    os.environ['QT_API'] = 'pyqt5'
elif have_pyqt4:
    ginga.toolkit.use('qt4')
    os.environ['QT_API'] = 'pyqt'
elif have_pyside2:
    ginga.toolkit.use('pyside2')
    os.environ['QT_API'] = 'pyside2'
elif have_pyside:
    ginga.toolkit.use('pyside')
    os.environ['QT_API'] = 'pyside'
else:
    raise ImportError("Failed to configure qt4, qt5, pyside or pyside2. "
                      "Is the 'qtpy' package installed? (%s)" % (
        qtpy_import_error))


tabwidget_style = """
QTabWidget::pane { margin: 0px,0px,0px,0px; padding: 0px; }
QMdiSubWindow { margin: 0px; padding: 2px; }
"""


class TopLevel(QtGui.QWidget):

    app = None
    ## def __init__(self, *args, **kwdargs):
    ##     return super(TopLevel, self).__init__(self, *args, **kwdargs)

    def closeEvent(self, event):
        if not (self.app is None):<commit_msg>flake8 fix<commit_after>#
# QtHelp.py -- customized Qt widgets and convenience functions
#
# This is open-source software licensed under a BSD license.
# Please see the file LICENSE.txt for details.
#
import glob
import os
import math

import ginga.toolkit
from ginga.util import iohelper
from ginga.misc import Callback, Bunch
from ginga.fonts import font_asst

configured = False

toolkit = ginga.toolkit.toolkit

# if user wants to force a toolkit
if toolkit == 'qt5':
    os.environ['QT_API'] = 'pyqt5'

elif toolkit == 'qt4':
    os.environ['QT_API'] = 'pyqt'

elif toolkit == 'pyside2':
    os.environ['QT_API'] = 'pyside2'

elif toolkit == 'pyside':
    os.environ['QT_API'] = 'pyside'

have_pyqt4 = False
have_pyqt5 = False
have_pyside = False
have_pyside2 = False
qtpy_import_error = ""

try:
    from qtpy import QtCore
    from qtpy import QtWidgets as QtGui
    from qtpy.QtGui import QImage, QColor, QFont, QPixmap, QIcon, QCursor, QPainter, QPen, QPolygonF, QPolygon, QTextCursor, QDrag, QPainterPath, QBrush, QFontDatabase  # noqa
    from qtpy.QtCore import QItemSelectionModel  # noqa
    from qtpy.QtWidgets import QApplication  # noqa
    try:
        from qtpy.QtWebEngineWidgets import QWebEngineView as QWebView  # noqa
    except ImportError as e:
        pass

    # Let's see what qtpy configured for us...
    from qtpy import PYQT4, PYQT5, PYSIDE, PYSIDE2
    have_pyqt4 = PYQT4
    have_pyqt5 = PYQT5
    have_pyside = PYSIDE
    have_pyside2 = PYSIDE2

    configured = True
except ImportError as e:
    qtpy_import_error = "Error importing 'qtpy': {}".format(e)
    # for debugging purposes, uncomment this to get full traceback
    #raise e

if have_pyqt5:
    ginga.toolkit.use('qt5')
    os.environ['QT_API'] = 'pyqt5'
elif have_pyqt4:
    ginga.toolkit.use('qt4')
    os.environ['QT_API'] = 'pyqt'
elif have_pyside2:
    ginga.toolkit.use('pyside2')
    os.environ['QT_API'] = 'pyside2'
elif have_pyside:
    ginga.toolkit.use('pyside')
    os.environ['QT_API'] = 'pyside'
else:
    raise ImportError("Failed to configure qt4, qt5, pyside or pyside2. "
                      "Is the 'qtpy' package installed? (%s)" % (
                          qtpy_import_error))


tabwidget_style = """
QTabWidget::pane { margin: 0px,0px,0px,0px; padding: 0px; }
QMdiSubWindow { margin: 0px; padding: 2px; }
"""


class TopLevel(QtGui.QWidget):

    app = None
    ## def __init__(self, *args, **kwdargs):
    ##     return super(TopLevel, self).__init__(self, *args, **kwdargs)

    def closeEvent(self, event):
        if not (self.app is None):
{'fraction_non_alphanumeric': 0.10822426255127955, 'fraction_numerical': 0.013869896464153155, 'mean_word_length': 3.499121265377856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2441933', 'n_tokens_mistral': 1921, 'n_tokens_neox': 1892, 'n_words': 502}