def save_org_file(self):
     file_path = self.get_save_path("org")
     touch(file_path)
     eval_in_emacs(
         'eaf--export-org-json',
         [self.buffer_widget.execute_js("save_file();"), file_path])
     message_to_emacs("Save org file: " + file_path)
Esempio n. 2
0
    def run(self):
        while self.running_flag:
            ## In some cases, the markers may not be ready when fetch_marker_callback is first called,
            ## so we need to call fetch_marker_callback multiple times.
            if self.markers is None or len(self.markers) == 0:
                self.markers = self.fetch_marker_callback()
            minibuffer_input = get_emacs_func_result(
                "minibuffer-contents-no-properties", [])

            marker_input_quit = len(minibuffer_input) > 0 and minibuffer_input[
                -1] in self.marker_quit_keys
            marker_input_finish = minibuffer_input in self.markers

            if marker_input_quit:
                self.running_flag = False
                eval_in_emacs('exit-minibuffer', [])
                message_to_emacs("Quit marker selection.")
                self.match_marker.emit(self.callback_tag, minibuffer_input)
            elif marker_input_finish:
                self.running_flag = False
                eval_in_emacs('exit-minibuffer', [])
                message_to_emacs("Marker selected.")
                self.match_marker.emit(self.callback_tag, minibuffer_input)

            time.sleep(0.1)
 def export_text(self):
     self.buffer_widget.eval_js(self.readability_js)
     text = self.buffer_widget.execute_js(
         "new Readability(document).parse().textContent;")
     self.refresh_page()
     eval_in_emacs('eaf--browser-export-text',
                   ["EAF-BROWSER-TEXT-" + self.url, text])
    def play_next_or_prev(self, prev):
        if prev:
            play_function = "netease-cloud-music-play-previous-song"
        else:
            play_function = "netease-cloud-music-play-next-song"

        eval_in_emacs(play_function, [])
 def add_multiple_middle_nodes(self):
     node_id = self.buffer_widget.execute_js("_jm.get_selected_node();")
     if node_id == None:
         message_to_emacs("No selected node.")
     elif not self.buffer_widget.execute_js("_jm.get_selected_node().parent;"):
         message_to_emacs("No parent node for selected node.")
     else:
         eval_in_emacs('eaf--add-multiple-middle-nodes', [self.buffer_id])
Esempio n. 6
0
    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)

        # Activate emacs window when call focus widget, avoid first char is not
        eval_in_emacs('eaf-activate-emacs-window', [])
Esempio n. 7
0
    def open_devtools_tab(self, web_page):
        ''' Open devtools tab'''
        self.devtools_page = web_page
        eval_in_emacs('eaf-open-devtool-page', [])

        # We need adjust web window size after open developer tool.
        QTimer().singleShot(
            1000,
            lambda: eval_in_emacs('eaf-monitor-configuration-change', []))
    def showEvent(self, event):
        # NOTE: we must reparent after widget show, otherwise reparent operation maybe failed.
        self.reparent()

        if platform.system() in ["Windows", "Darwin"]:
            eval_in_emacs('eaf-activate-emacs-window', [])

        # Make graphics view at left-top corner after show.
        self.graphics_view.verticalScrollBar().setValue(0)
        self.graphics_view.horizontalScrollBar().setValue(0)
Esempio n. 9
0
    def __init__(self, args):
        global emacs_width, emacs_height, eaf_config_dir, proxy_string

        # Parse init arguments.
        (emacs_width, emacs_height, proxy_host, proxy_port, proxy_type,
         config_dir, emacs_server_port, var_dict_string) = args
        emacs_width = int(emacs_width)
        emacs_height = int(emacs_height)
        eaf_config_dir = os.path.join(os.path.expanduser(config_dir), '')

        # Init variables.
        self.buffer_dict = {}
        self.view_dict = {}
        self.emacs_var_dict = {}
        self.session_file = os.path.join(eaf_config_dir, "session.json")

        # Update Emacs var dictionary.
        self.update_emacs_var_dict(var_dict_string)

        # Init EPC client port.
        init_epc_client(int(emacs_server_port))

        # Build EPC server.
        self.server = ThreadingEPCServer(('localhost', 0), log_traceback=True)
        self.server.logger.setLevel(logging.DEBUG)
        self.server.allow_reuse_address = True

        if not os.path.exists(eaf_config_dir):
            os.makedirs(eaf_config_dir)

        ch = logging.FileHandler(filename=os.path.join(eaf_config_dir,
                                                       'epc_log.txt'),
                                 mode='w')
        ch.setLevel(logging.DEBUG)
        self.server.logger.addHandler(ch)

        self.server.register_instance(
            self)  # register instance functions let elisp side call

        # Start EPC server with sub-thread, avoid block Qt main loop.
        self.server_thread = threading.Thread(target=self.server.serve_forever)
        self.server_thread.start()

        # Pass epc port and webengine codec information to Emacs when first start EAF.
        eval_in_emacs('eaf--first-start', [
            self.server.server_address[1],
            self.webengine_include_private_codec()
        ])

        # Set Network proxy.
        self.proxy = (proxy_type, proxy_host, proxy_port)
        self.is_proxy = False

        if proxy_type != "" and proxy_host != "" and proxy_port != "":
            self.enable_proxy()
    def _caret_at_line(self, marker):
        '''Enable caret by marker'''
        self.load_marker_file()
        self.execute_js("Marker.gotoMarker('%s', (e) => window.getSelection().collapse(e, 0))" % str(marker))
        self.cleanup_links_dom()

        self.eval_js("CaretBrowsing.setInitialCursor(true);")
        self.buffer.caret_browsing_mode = True
        eval_in_emacs('eaf--toggle-caret-browsing', ["'t" if self.buffer.caret_browsing_mode else "'nil"])
        self.buffer.caret_toggle_mark()
        self.buffer.caret_next_word()
 def caret_toggle_browsing(self):
     ''' Init caret browsing.'''
     if self.caret_js_ready:
         if self.caret_browsing_mode:
             self.buffer_widget.eval_js("CaretBrowsing.shutdown();")
             message_to_emacs("Caret browsing deactivated.")
             self.caret_browsing_mode = False
         else:
             self.buffer_widget.eval_js("CaretBrowsing.setInitialCursor();")
             message_to_emacs("Caret browsing activated.")
             self.caret_browsing_mode = True
         eval_in_emacs('eaf--toggle-caret-browsing', ["'t" if self.caret_browsing_mode else "'nil"])
Esempio n. 12
0
    def create_new_browser_window(self):
        ''' Create new browser window.'''
        # Generate buffer id same as eaf.el does.
        buffer_id = self.get_new_browser_window_buffer_id()

        # Create buffer for create new browser window.
        app_buffer = self.create_buffer(buffer_id, "http://0.0.0.0",
                                        "app.browser.buffer", "")

        # Create emacs buffer with buffer id.
        eval_in_emacs('eaf--create-new-browser-buffer', [buffer_id])

        # Return new QWebEngineView for create new browser window.
        return app_buffer.buffer_widget
Esempio n. 13
0
 def render(self):
     params = {
         "input_file": self.url,
         "output_file": self.preview_file,
         "dark_mode": self.dark_mode
     }
     url = 'http://localhost:{}?{}'.format(self.server_port, urlencode(params))
     with urlopen(url) as f:
         resp = f.read().decode("utf-8")
         if resp == "ok":
             self.buffer_widget.load(QUrl.fromLocalFile(self.preview_file))
             if platform.system() == "Windows":
                 eval_in_emacs('eaf-activate-emacs-window', [])
         else:
             message_to_emacs("preview failed: {}".format(resp))
    def init_app(self):
        self.buffer_widget.execute_js('initColor(\"{}\", \"{}\")'.format(
            get_emacs_var("eaf-emacs-theme-background-color"),
            get_emacs_var("eaf-emacs-theme-foreground-color")
        ))
        self.update_user_info()
        self.refresh_user_playlist()
        self.update_playlist_style(True)
        self.set_repeat_mode()
        self.set_panel_song()
        self.update_play_status()

        # Init
        eval_in_emacs('''eaf--netease-cloud-music-init''', [])
        self.set_playlist()
        eval_in_emacs('''eaf--netease-cloud-music--update-song-style''', [])
    def checking_status(self):
        changed_directory = str(self.buffer_widget.execute_js("title"))
        changed_executing_command = str(self.buffer_widget.execute_js("executing_command"))
        if len(changed_executing_command) > 30:
            changed_executing_command = changed_executing_command[:30]

        if changed_executing_command != self.executing_command and changed_executing_command != "":
            self.change_title(changed_executing_command)
            self.executing_command = changed_executing_command
        elif changed_executing_command == "" and self.executing_command != "" or not changed_directory == self.current_directory:
            self.change_title(changed_directory)
            if not changed_directory == self.current_directory:
                eval_in_emacs('eaf--change-default-directory', [changed_directory])
                self.current_directory = changed_directory
            if self.executing_command != "":
                self.executing_command = ""

        if subprocess.Popen.poll(self.background_process) is not None:
            self.destroy_buffer()
    def eventFilter(self, obj, event):
        ''' Handle event.'''
        # Debug event.
        # if event.type() != 1:
        #     import time
        #     print(time.time(), event.type(), self.rect())

        # Focus emacs buffer when user click view.
        event_type = [
            QEvent.MouseButtonPress, QEvent.MouseButtonRelease,
            QEvent.MouseButtonDblClick
        ]
        if platform.system() != "Darwin":
            event_type += [QEvent.Wheel]

        if event.type() in event_type:
            focus_emacs_buffer(self.buffer_id)

        if event.type() == QEvent.MouseButtonPress:

            if platform.system() == "Darwin":
                eval_in_emacs('eaf-activate-emacs-window', [])

            if event.button() == MOUSE_FORWARD_BUTTON:
                self.forward()

                event.accept()
                return True
            elif event.button() == MOUSE_BACK_BUTTON:
                self.back()

                event.accept()
                return True

        if event.type() == QEvent.Wheel:
            modifiers = QApplication.keyboardModifiers()
            if modifiers == Qt.ControlModifier:
                if event.angleDelta().y() > 0:
                    self.zoom_in()
                else:
                    self.zoom_out()

        return super(QWebEngineView, self).eventFilter(obj, event)
    def eventFilter(self, obj, event):
        # import time
        # print(time.time(), event.type())

        if event.type() in [QEvent.ShortcutOverride]:
            eval_in_emacs('eaf-activate-emacs-window', [self.buffer_id])

        # Focus emacs buffer when user click view.
        event_type = [
            QEvent.MouseButtonPress, QEvent.MouseButtonRelease,
            QEvent.MouseButtonDblClick
        ]
        if platform.system() != "Darwin":
            event_type += [QEvent.Wheel]

        if event.type() in event_type:
            focus_emacs_buffer(self.buffer_id)
            # Stop mouse event.
            return True

        return False
Esempio n. 18
0
 def save_as_bookmark(self):
     ''' Save as bookmark.'''
     eval_in_emacs('bookmark-set', [])
 def play_song(self, song):
     eval_in_emacs("netease-cloud-music-play", song)
Esempio n. 20
0
 def change_title(self, new_title):
     ''' Change title.'''
     if new_title != "about:blank":
         self.title = new_title
         eval_in_emacs('eaf--update-buffer-details',
                       [self.buffer_id, new_title, self.url])
 def cancel_search(self):
     self.buffer_widget.execute_js('''changePlaylistMode(false)''')
     self.set_playlist()
     eval_in_emacs('''netease-cloud-music-adjust-song-index''', [])
 def search_playlist(self):
     self.buffer_widget.execute_js('''resetSongStyle()''')
     eval_in_emacs('''netease-cloud-music-search-playlist''', [])
 def switch_enter(self, index):
     eval_in_emacs('''eaf--netease-cloud-music-switch-enter''', index)
Esempio n. 24
0
 def close_buffer(self):
     ''' Close buffer.'''
     eval_in_emacs('eaf-request-kill-buffer', [self.buffer_id])
 def change_playlist(self, pid):
     eval_in_emacs('''eaf--netease-cloud-music-change-playlist''', pid)
 def play_or_pause(self):
     if get_emacs_var("eaf-netease-cloud-music-play-status") == "":
         message_to_emacs("You've never started to play a song.")
         return
     eval_in_emacs("netease-cloud-music-pause-or-continue", [])
 def change_repeat_mode(self):
     eval_in_emacs("netease-cloud-music-change-repeat-mode", [])
Esempio n. 28
0
 def select_left_tab(self):
     ''' Select left tab.'''
     eval_in_emacs('eaf-goto-left-tab', [])
Esempio n. 29
0
 def open_in_dired(self, path):
     eval_in_emacs('dired', [path])
Esempio n. 30
0
 def select_right_tab(self):
     ''' Select right tab.'''
     eval_in_emacs('eaf-goto-right-tab', [])