Clean mark/jump links after user cancel input.

master
Andy Stewart 6 years ago
parent f94313598b
commit b8cb6cb0ff
  1. 13
      app/pdf-viewer/buffer.py
  2. 3
      core/buffer.py
  3. 21
      docs/HACKING.md
  4. 6
      eaf.el
  5. 6
      eaf.py

@ -45,6 +45,10 @@ class AppBuffer(Buffer):
elif result_type == "jump_link":
self.buffer_widget.jump_to_link(str(result_content))
def cancel_input_message(self, result_type):
if result_type == "jump_link":
self.buffer_widget.clean_links()
def scroll(self, scroll_direction, scroll_type):
if scroll_type == "page":
if scroll_direction == "up":
@ -500,7 +504,6 @@ class PdfViewerWidget(QWidget):
page.deleteAnnot(annot)
self.jump_link_key_cache_dict.clear()
self.jump_link_annot_cache_dict.clear()
self.update()
def jump_to_link(self, key):
key = str(key).upper()
@ -509,6 +512,14 @@ class PdfViewerWidget(QWidget):
self.remember_current_position()
self.jump_to_page(link["page"] + 1)
self.delete_all_mark_jump_link_tips()
self.update()
def clean_links(self):
self.is_mark_link = False
self.delete_all_mark_jump_link_tips()
self.page_cache_pixmap_dict.clear()
self.update()
def jump_to_page(self, page_num):

@ -239,6 +239,9 @@ class Buffer(QGraphicsScene):
def handle_input_message(self, result_type, result_content):
pass
def cancel_input_message(self, result_type):
pass
def scroll(self, scroll_direction, scroll_type):
pass

@ -127,6 +127,7 @@ self.eval_in_emacs.emit('''(message "hello")''')
### Read user's input
Below is code example from pdfviewer:
```Python
...
@ -144,22 +145,28 @@ class AppBuffer(Buffer):
if result_type == "jump_page":
self.buffer_widget.jump_to_page(int(result_content))
def cacel_input_message(self, result_type):
if result_type == "jump_page":
...
...
```
If you want read input from emacs minibuffer then call back to python.
You can emit buffer signal "send_input_message", first argument is prompt string to user, second argument is callback_type for interface "handle_input_message".
You can emit buffer signal ```send_input_message```, first argument is prompt string to user, second argument is callback_type for interface ```handle_input_message```.
After emacs read user input, framework will call interface ```handle_input_message```, result_type is callback_type you use in signal ```send_input_message```, result_content is input string from emacs.
After emacs read user input, framework will call interface "handle_input_message", result_type is callback_type you use in signal "send_input_message", result_content is input string from emacs.
Simple logic is send ```send_input_message``` signal to emacs, then handle user input with buffer interface ```handle_input_message```
Simple logic is send "send_input_message" signal to emacs, then handle user input with buffer interface "handle_input_message"
If user cancel input, such as press Ctrl + g, you can define your own ```cancel_input_message``` interface, write cancel callback for type.
### Scroll by other window
In emacs, we usually call command "scroll-other-window" to scroll other window's buffer.
In emacs, we usually call command ```scroll-other-window``` to scroll other window's buffer.
If you want eaf application buffer respond scroll event to command "scroll-other-window".
You need implement "scroll" interface in AppBuffer, such as like PDF Viewer does:
You need implement ```scroll``` interface in AppBuffer, such as like PDF Viewer does:
```Python
def scroll(self, scroll_direction, scroll_type):
@ -182,7 +189,7 @@ Argument "scroll_type" is string, "page" mean scroll buffer by page, "line" mean
### Save/Restore session
We always need save and restore session for an application, such as, save play position of the video player.
You need implement interfaces "save_session_data" and "restore_session_data", below is an example of Vide Player does:
You need implement interfaces ```save_session_data``` and ```restore_session_data```, below is an example of Vide Player does:
```Python
@ -201,7 +208,7 @@ All session data save at ~/.emacs.d/eaf/session.json file.
### Update buffer
If you need to update buffer sometimes, such as update org-file previewer after saving org-file.
You need to implement the interface "update_with_data". Below is an example of what Org Previewer does:
You need to implement the interface ```update_with_data```. Below is an example of what Org Previewer does:
```Python
def update_with_data(self, update_data):

@ -796,8 +796,10 @@ This is used to bind key to EAF Python applications."
(defun eaf-input-message (input-buffer-id interactive-string callback-type)
"Handles input message INTERACTIVE-STRING on the Python side given INPUT-BUFFER-ID and CALLBACK-TYPE."
(let* ((input-message (eaf-read-string interactive-string)))
(when input-message
(eaf-call "handle_input_message" input-buffer-id callback-type input-message))))
(if input-message
(eaf-call "handle_input_message" input-buffer-id callback-type input-message)
(eaf-call "cancel_input_message" input-buffer-id callback-type)
)))
(dbus-register-signal
:session "com.lazycat.eaf" "/com/lazycat/eaf"

@ -267,6 +267,12 @@ class EAF(dbus.service.Object):
if buffer.buffer_id == buffer_id:
buffer.handle_input_message(callback_type, callback_result)
@dbus.service.method(EAF_DBUS_NAME, in_signature="ss", out_signature="")
def cancel_input_message(self, buffer_id, callback_type):
for buffer in list(self.buffer_dict.values()):
if buffer.buffer_id == buffer_id:
buffer.cancel_input_message(callback_type)
@dbus.service.method(EAF_DBUS_NAME, in_signature="s", out_signature="")
def store_emacs_var(self, var_dict_string):
for var_pair in var_dict_string.split(":"):

Loading…
Cancel
Save