update eaf package

This commit is contained in:
2021-01-30 14:52:51 +01:00
parent 84eb4929ee
commit 5207af83cb
4981 changed files with 11795 additions and 761570 deletions

View File

@@ -21,11 +21,12 @@
from PyQt5 import QtCore
from PyQt5.QtGui import QBrush, QColor
from PyQt5.QtGui import QFocusEvent
from PyQt5.QtWidgets import QGraphicsScene
from PyQt5.QtCore import Qt, QEvent
from PyQt5.QtGui import QKeyEvent
from PyQt5.QtWidgets import QApplication
from core.utils import interactive
from core.utils import interactive, abstract, get_clipboard_text, set_clipboard_text
import abc
import string
@@ -101,13 +102,14 @@ class Buffer(QGraphicsScene):
update_buffer_details = QtCore.pyqtSignal(str, str, str)
open_url_in_new_tab = QtCore.pyqtSignal(str)
duplicate_page_in_new_tab = QtCore.pyqtSignal(str)
open_url_in_background_tab = QtCore.pyqtSignal(str)
translate_text = QtCore.pyqtSignal(str)
input_message = QtCore.pyqtSignal(str, str, str, str, str)
request_close_buffer = QtCore.pyqtSignal(str)
message_to_emacs = QtCore.pyqtSignal(str)
set_emacs_var = QtCore.pyqtSignal(str, str)
eval_in_emacs = QtCore.pyqtSignal(str)
set_emacs_var = QtCore.pyqtSignal(str, str, str)
eval_in_emacs = QtCore.pyqtSignal(str, list)
goto_left_tab = QtCore.pyqtSignal()
goto_right_tab = QtCore.pyqtSignal()
aspect_ratio_change = QtCore.pyqtSignal()
@@ -123,11 +125,7 @@ class Buffer(QGraphicsScene):
self.emacs_var_dict = emacs_var_dict
self.module_path = module_path
self.fit_to_view = fit_to_view
if emacs_var_dict["eaf-emacs-theme-mode"] == "dark":
self.background_color = QColor(233, 129, 35, 255)
else:
self.background_color = QColor(255, 255, 255, 255)
self.setBackgroundBrush(QBrush(self.background_color))
self.title = ""
self.buffer_widget = None
@@ -153,7 +151,8 @@ class Buffer(QGraphicsScene):
def build_interactive_method(self, origin_class, class_method_name, new_method_name=None, msg_emacs=None, insert_or_do=False):
''' Build interactive methods.'''
new_name = class_method_name if new_method_name is None else new_method_name
self.__dict__.update({new_name: getattr(origin_class, class_method_name)})
if (not hasattr(self, class_method_name)) or hasattr(getattr(self, class_method_name), "abstract"):
self.__dict__.update({new_name: getattr(origin_class, class_method_name)})
if msg_emacs is not None:
self.message_to_emacs.emit(msg_emacs)
if insert_or_do:
@@ -213,12 +212,15 @@ class Buffer(QGraphicsScene):
''' Close buffer.'''
self.request_close_buffer.emit(self.buffer_id)
@abstract
def all_views_hide(self):
pass
@abstract
def some_view_show(self):
pass
@abstract
def resize_view(self):
pass
@@ -227,42 +229,58 @@ class Buffer(QGraphicsScene):
return [self.buffer_widget]
def send_input_message(self, message, callback_tag, input_type="string", initial_content=""):
''' Send input message.'''
''' Send an input message to Emacs side for the user to respond.
MESSAGE is a message string that would be sent to the user.
CALLBACK_TAG is the reference tag when handle_input_message is invoked.
INPUT_TYPE must be one of "string", "file", or "yes-or-no".
INITIAL_CONTENT is the intial content of the user response, it is only useful when INPUT_TYPE is "string".
'''
self.input_message.emit(self.buffer_id, message, callback_tag, input_type, initial_content)
def handle_input_message(self, result_type, result_content):
@abstract
def handle_input_response(self, callback_tag, result_content):
pass
@abstract
def action_quit(self):
pass
def cancel_input_message(self, result_type):
@abstract
def cancel_input_response(self, callback_tag):
pass
@abstract
def scroll_other_buffer(self, scroll_direction, scroll_type):
pass
def save_session_data(self):
return ""
@abstract
def restore_session_data(self, session_data):
pass
@abstract
def update_with_data(self, update_data):
pass
def execute_function(self, function_name):
''' Execute function.'''
''' Execute function.'''
getattr(self, function_name)()
def call_function(self, function_name):
''' Call function.'''
return getattr(self, function_name)()
def call_function_with_args(self, function_name, args_string):
def call_function_with_args(self, function_name, *args, **kwargs):
''' Call function with arguments.'''
return getattr(self, function_name)(args_string)
return getattr(self, function_name)(*args, **kwargs)
@abstract
def fake_key_event_filter(self, event_string):
pass
@@ -325,10 +343,18 @@ class Buffer(QGraphicsScene):
''' Get url.'''
return self.url
def get_clipboard_text(self):
''' Get text from system clipboard.'''
return get_clipboard_text()
def set_clipboard_text(self, text):
''' Set text to system clipboard.'''
set_clipboard_text(text)
@interactive(insert_or_do=True)
def save_as_bookmark(self):
''' Save as bookmark.'''
self.eval_in_emacs.emit('''(bookmark-set)''')
self.eval_in_emacs.emit('bookmark-set', [])
@interactive(insert_or_do=True)
def select_left_tab(self):
@@ -339,3 +365,9 @@ class Buffer(QGraphicsScene):
def select_right_tab(self):
''' Select right tab.'''
self.goto_right_tab.emit()
def focus_widget(self, event=None):
'''Focus buffer widget.'''
if event is None:
event = QFocusEvent(QEvent.FocusIn, Qt.MouseFocusReason)
QApplication.sendEvent(self.buffer_widget.focusProxy(), event)