# Path: vise/communicate.py
# def python_to_js(page_or_tab, name, *args):
#     page = page_or_tab.page() if isinstance(page_or_tab, QWebEngineView) else page_or_tab
#     page.runJavaScript('window.send_message_to_javascript(%s, %s)' % (json.dumps(name), json.dumps(args)), QWebEngineScript.ScriptWorldId.ApplicationWorld)


from functools import partial
from gettext import gettext as _
from PyQt6.QtCore import QEvent, Qt, QUrl
from PyQt6.QtGui import QKeyEvent, QClipboard
from PyQt6.QtWidgets import QApplication
from PyQt6.QtWebEngineCore import QWebEnginePage
from .communicate import python_to_js
    from .downloads import DOWNLOADS_URL


def paste_and_go_newtab(window, *args, **kwargs):
    _paste_and_go(window, in_current_tab=False)
    return True


def scroll_line(key, window, focus_widget, key_filter, *args, **kwargs):
    if focus_widget is not None:
        with key_filter.disable_filtering:
            QApplication.sendEvent(focus_widget,
                                   QKeyEvent(QEvent.Type.KeyPress, key,
                                             Qt.KeyboardModifier(0)))
    return True


def scroll_page(up, window, focus_widget, key_filter, *args, **kwargs):
    if focus_widget is not None:
        with key_filter.disable_filtering:
            key = Qt.Key.Key_PageUp if up else Qt.Key.Key_PageDown
            QApplication.sendEvent(focus_widget,
                                   QKeyEvent(QEvent.Type.KeyPress, key,
                                             Qt.KeyboardModifier(0)))
    return True


def scroll_to_boundary(top, window, focus_widget, key_filter, *args, **kwargs):
    if focus_widget is not None:
        with key_filter.disable_filtering:
            key = Qt.Key.Key_Home if top else Qt.Key.Key_End

# Path: vise/communicate.py
# def python_to_js(page_or_tab, name, *args):
#     page = page_or_tab.page() if isinstance(page_or_tab, QWebEngineView) else page_or_tab
#     page.runJavaScript('window.send_message_to_javascript(%s, %s)' % (json.dumps(name), json.dumps(args)), QWebEngineScript.ScriptWorldId.ApplicationWorld)


# Path: vise/actions.py
from functools import partial
from gettext import gettext as _
from PyQt6.QtCore import QEvent, Qt, QUrl
from PyQt6.QtGui import QKeyEvent, QClipboard
from PyQt6.QtWidgets import QApplication
from PyQt6.QtWebEngineCore import QWebEnginePage
from .communicate import python_to_js
    from .downloads import DOWNLOADS_URL



def paste_and_go_newtab(window, *args, **kwargs):
    _paste_and_go(window, in_current_tab=False)
    return True


def scroll_line(key, window, focus_widget, key_filter, *args, **kwargs):
    if focus_widget is not None:
        with key_filter.disable_filtering:
            QApplication.sendEvent(focus_widget,
                                   QKeyEvent(QEvent.Type.KeyPress, key,
                                             Qt.KeyboardModifier(0)))
    return True


def scroll_page(up, window, focus_widget, key_filter, *args, **kwargs):
    if focus_widget is not None:
        with key_filter.disable_filtering:
            key = Qt.Key.Key_PageUp if up else Qt.Key.Key_PageDown
            QApplication.sendEvent(focus_widget,
                                   QKeyEvent(QEvent.Type.KeyPress, key,
                                             Qt.KeyboardModifier(0)))
    return True


def scroll_to_boundary(top, window, focus_widget, key_filter, *args, **kwargs):
    if focus_widget is not None:
        with key_filter.disable_filtering:
            key = Qt.Key.Key_Home if top else Qt.Key.Key_End

            QApplication.sendEvent(focus_widget,