<commit_before>import sys
import webbrowser

from PyQt5 import QtCore, QtWidgets, QtWebKitWidgets, QtGui


def init_gui(application, port=5000, width=300, height=400,
             window_title="PyFladesk", icon="appicon.png"):

    ROOT_URL = 'http://localhost:{}'.format(port)

    # open links in browser from http://stackoverflow.com/a/3188942/1103397 :D
    def link_clicked(url):
        ready_url = url.toEncoded().data().decode()
        if ROOT_URL not in ready_url:
            webbrowser.open(ready_url)
        else:
            window.webView.load(QtCore.QUrl(ready_url))

    def run_app():
        application.run(port=port, threaded=True)

    qtapp = QtWidgets.QApplication(sys.argv)

    webapp = QtCore.QThread()
    webapp.__del__ = webapp.wait
    webapp.run = run_app
    webapp.start()

    qtapp.aboutToQuit.connect(webapp.terminate)

    window = QtWidgets.QMainWindow()
    window.resize(width, height)
    window.setWindowTitle(window_title)
    window.webView = QtWebKitWidgets.QWebView(window)
    window.setCentralWidget(window.webView)
    window.setWindowIcon(QtGui.QIcon(icon))

    window.webView.page().setLinkDelegationPolicy(
        QtWebKitWidgets.QWebPage.DelegateAllLinks)
    window.webView.page().linkClicked.connect(link_clicked)

    window.webView.load(QtCore.QUrl(ROOT_URL))
    window.show()

    return qtapp.exec_()<commit_msg>Migrate deprecated PyQt 5.5 to new PyQt 5.10<commit_after>import sys
from PyQt5 import QtCore, QtWidgets, QtGui, QtWebEngineWidgets


def init_gui(application, port=5000, width=300, height=400,
             window_title="PyFladesk", icon="appicon.png"):

    ROOT_URL = 'http://localhost:{}'.format(port)

    # open links in browser from http://stackoverflow.com/a/3188942/1103397 :D
    # thanks to https://github.com/marczellm/qhangups/blob/cfed73ee4383caed1568c0183a9906180f01cb00/qhangups/WebEnginePage.py
    def link_clicked(url, typ, ismainframe):
        ready_url = url.toEncoded().data().decode()
        is_clicked = typ == QtWebEngineWidgets.QWebEnginePage.NavigationTypeLinkClicked
        is_not_internal = ROOT_URL not in ready_url
        if is_clicked and is_not_internal:
            QtGui.QDesktopServices.openUrl(url)
            return False
        return True

    def run_app():
        application.run(port=port, threaded=True)

    # Application Level
    qtapp = QtWidgets.QApplication(sys.argv)
    webapp = QtCore.QThread()
    webapp.__del__ = webapp.wait
    webapp.run = run_app
    webapp.start()
    qtapp.aboutToQuit.connect(webapp.terminate)

    # Main Window Level
    window = QtWidgets.QMainWindow()
    window.resize(width, height)
    window.setWindowTitle(window_title)
    window.setWindowIcon(QtGui.QIcon(icon))

    # WebView Level
    window.webView = QtWebEngineWidgets.QWebEngineView(window)
    window.setCentralWidget(window.webView)

    # WebPage Level
    page = QtWebEngineWidgets.QWebEnginePage()
    page.acceptNavigationRequest = link_clicked
    page.load(QtCore.QUrl(ROOT_URL))
    window.webView.setPage(page)

    window.show()

    return qtapp.exec_()
{'fraction_non_alphanumeric': 0.10510996119016817, 'fraction_numerical': 0.0258732212160414, 'mean_word_length': 3.541850220264317, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '5018775', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1026, 'n_words': 167}