예제 #1
0
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path):
        BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path, False)

        self.url = url
        index_file = os.path.join(os.path.dirname(__file__), "index.html")
        self.buffer_widget.setUrl(QUrl.fromLocalFile(index_file))

        self.cut_node_id = None

        edit_mode = "true" if self.emacs_var_dict["eaf-mindmap-edit-mode"] == "true" else "false"
        for method_name in ["add_sub_node", "add_brother_node", "add_middle_node"]:
            self.build_js_method(method_name, True, js_kwargs={"inline": edit_mode})

        for method_name in ["remove_node", "remove_middle_node", "update_node_topic_inline"]:
            self.build_js_method(method_name, True)

        for method_name in ["zoom_in", "zoom_out", "zoom_reset",
                            "select_up_node", "select_down_node", "select_left_node", "select_right_node",
                            "toggle_node", "toggle_node_selection", "save_screenshot"]:
            self.build_js_method(method_name)

        for method_name in ["zoom_in", "zoom_out", "zoom_reset", "remove_node",
                            "remove_middle_node", "add_middle_node", "refresh_page",
                            "select_up_node", "select_down_node", "select_left_node", "select_right_node",
                            "toggle_node", "toggle_node_selection", "save_screenshot"]:
            self.build_insert_or_do(method_name)

        self.build_all_methods(self)

        self.buffer_widget.loadFinished.connect(lambda _: self.initialize())
예제 #2
0
    def __init__(self, buffer_id, url, arguments):
        BrowserBuffer.__init__(self, buffer_id, url, arguments, False)

        self.index_file_dir = os.path.join(os.path.dirname(__file__), "dist")
        self.index_file = os.path.join(self.index_file_dir, "index.html")
        self.url = url
        self.first_file = arguments

        self.panel_background_color = QColor(
            get_emacs_var("eaf-emacs-theme-background-color")).darker(
                110).name()

        self.buffer_widget.loadFinished.connect(self.load_first_file)

        with open(self.index_file, "r") as f:
            html = self.convert_index_html(f.read(), self.index_file_dir)
            self.buffer_widget.setHtml(html, QUrl("file://"))

        for (python_method_name,
             js_method_name) in [("scroll_up", "scrollUp"),
                                 ("scroll_down", "scrollDown"),
                                 ("scroll_up_page", "scrollUpPage"),
                                 ("scroll_down_page", "scrollDownPage"),
                                 ("scroll_to_begin", "scrollToBegin"),
                                 ("scroll_to_bottom", "scrollToBottom")]:
            self.build_js_bridge_method(python_method_name, js_method_name)
예제 #3
0
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict,
                 module_path):
        BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments,
                               emacs_var_dict, module_path, False)

        self.index_file_dir = os.path.join(os.path.dirname(__file__), "dist")
        self.index_file = os.path.join(self.index_file_dir, "index.html")
        self.url = url
        self.first_file = arguments

        self.panel_background_color = QColor(
            self.emacs_var_dict["eaf-emacs-theme-background-color"]).darker(
                110).name()

        self.buffer_widget.loadFinished.connect(self.load_first_file)

        with open(self.index_file, "r") as f:
            html = f.read().replace(
                '''href="''', '''href="''' + self.index_file_dir).replace(
                    '''<script src="''',
                    '''<script src="''' + self.index_file_dir).replace(
                        '''<body>''',
                        '''<body style="background: {}">'''.format(
                            self.emacs_var_dict[
                                "eaf-emacs-theme-background-color"]))
            self.buffer_widget.setHtml(html, QUrl("file://"))

        for (python_method_name,
             js_method_name) in [("scroll_up", "scrollUp"),
                                 ("scroll_down", "scrollDown"),
                                 ("scroll_up_page", "scrollUpPage"),
                                 ("scroll_down_page", "scrollDownPage"),
                                 ("scroll_to_begin", "scrollToBegin"),
                                 ("scroll_to_bottom", "scrollToBottom")]:
            self.build_js_bridge_method(python_method_name, js_method_name)
예제 #4
0
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict,
                 module_path):
        BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments,
                               emacs_var_dict, module_path, False)

        self.url = url

        self.load_org_html_file()
예제 #5
0
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path):
        BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path, False)

        self.index_file_dir = os.path.join(os.path.dirname(__file__), "dist")
        self.index_file = os.path.join(self.index_file_dir, "index.html")
        self.url = url

        with open(self.index_file, "r") as f:
            html = f.read().replace('''href="''', '''href="''' + self.index_file_dir).replace('''<script src="''', '''<script src="''' + self.index_file_dir)
            self.buffer_widget.setHtml(html, QUrl("file://"))
예제 #6
0
    def __init__(self, buffer_id, url, arguments):
        BrowserBuffer.__init__(self, buffer_id, url, arguments, False)

        self.index_file_dir = os.path.join(os.path.dirname(__file__), "dist")
        self.index_file = os.path.join(self.index_file_dir, "index.html")
        self.url = url

        with open(self.index_file, "r") as f:
            html = self.convert_index_html(f.read(), self.index_file_dir)
            self.buffer_widget.setHtml(html, QUrl("file://"))
예제 #7
0
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path):
        BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path, False)

        self.url = url
        index_file = os.path.join(os.path.dirname(__file__), "index.html")
        self.buffer_widget.setUrl(QUrl.fromLocalFile(index_file))

        for method_name in ["toggle_play", "forward", "backward", "restart", "increase_volume", "decrease_volume"]:
            self.build_js_method(method_name)

        QTimer.singleShot(500, self.play_video)
예제 #8
0
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict,
                 module_path):
        BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments,
                               emacs_var_dict, module_path, False)

        # Get free port.
        self.port = get_free_port()
        self.http_url = "http://127.0.0.1:{0}".format(get_free_port())
        self.url = url

        arguments_dict = json.loads(arguments)
        self.command = arguments_dict["command"]
        self.start_directory = arguments_dict["directory"]
        self.current_directory = self.start_directory
        self.executing_command = ""
        self.index_file = "{0}/index.html".format(self.http_url)
        self.server_js = os.path.join(os.path.dirname(__file__), "server.js")

        self.buffer_widget.titleChanged.connect(self.change_title)

        http_thread = threading.Thread(target=self.run_http_server, args=())
        http_thread.start()

        self.search_term = ""

        # Start server process.
        args = [
            "node", self.server_js,
            str(self.port), self.start_directory, self.command
        ]
        self.background_process = subprocess.Popen(args,
                                                   stdout=subprocess.PIPE,
                                                   stderr=subprocess.STDOUT,
                                                   shell=False)

        # The background process (server.js) might take time to start.
        # If we open the terminal page before it's up and running, we'll get a
        # "connection refused" error when connecting to the websocket port.
        # User will have to reload the page to get a terminal.
        # Adding this extra step seems to solve this timing problem.
        try:
            outs, errs = self.background_process.communicate(timeout=1)
        except Exception:
            print("Terminal: timed out when communicating with server.js.")

        self.open_terminal_page()

        QTimer.singleShot(250, self.focus_widget)

        self.build_all_methods(self)

        self.timer = QTimer()
        self.timer.start(250)
        self.timer.timeout.connect(self.checking_status)
예제 #9
0
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path):
        BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path, False)

        self.index_file = os.path.join(os.path.dirname(__file__), "index.html")
        self.url = url
        self.parent_dir = os.path.abspath(os.path.join(url, os.pardir))
        self.image_name = os.path.basename(url)

        # Set background color.
        self.background_color_str = "#7F7F7F"
        self.buffer_widget.web_page.setBackgroundColor(QColor(self.background_color_str))

        with open(self.index_file, "r") as f:
            html = f.read().replace("%1", os.path.join(os.path.dirname(__file__))).replace("%2", os.path.join("file://", url)).replace("%3", self.background_color_str)
            self.buffer_widget.setHtml(html, QUrl("file://"))
예제 #10
0
    def __init__(self, buffer_id, url, arguments):
        BrowserBuffer.__init__(self, buffer_id, url, arguments, False)

        self.index_file_dir = os.path.join(os.path.dirname(__file__), "dist")
        self.index_file = os.path.join(self.index_file_dir, "index.html")
        self.url = url
        self.arguments = json.loads(arguments)

        with open(self.index_file, "r") as f:
            html = self.convert_index_html(f.read(), self.index_file_dir)
            self.buffer_widget.setHtml(html, QUrl("file://"))

        self.buffer_widget.loadFinished.connect(self.init_path)

        for (python_method_name, js_method_name) in [
            ("select_next_file", "selectNextFile"),
            ("select_prev_file", "selectPrevFile"),
        ]:
            self.build_js_bridge_method(python_method_name, js_method_name)
예제 #11
0
 def handle_input_response(self, callback_tag, result_content):
     ''' Handle input message.'''
     if not BrowserBuffer.handle_input_response(self, callback_tag,
                                                result_content):
         if callback_tag == "clear_history":
             self._clear_history()
         elif callback_tag == "import_chrome_history":
             self._import_chrome_history()
         elif callback_tag == "clear_cookies":
             self._clear_cookies()
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path):
        BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path, False)

        # Get free port.
        self.port = get_free_port()
        self.http_url = "http://127.0.0.1:{0}".format(get_free_port())
        self.url = url

        arguments_dict = json.loads(arguments)
        self.command = arguments_dict["command"]
        self.start_directory = arguments_dict["directory"]
        self.current_directory = self.start_directory
        self.executing_command = ""
        self.index_file = "{0}/index.html".format(self.http_url)
        self.server_js = os.path.join(os.path.dirname(__file__), "server.js")

        self.buffer_widget.titleChanged.connect(self.change_title)

        http_thread = threading.Thread(target=self.run_http_server, args=())
        http_thread.start()

        self.search_term = ""

        # Start server process.
        args = ["node", self.server_js, str(self.port), self.start_directory, self.command]
        self.background_process = subprocess.Popen(
            args,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            shell=False)

        self.open_terminal_page()

        QTimer.singleShot(250, self.focus_widget)

        self.build_all_methods(self)

        self.timer=QTimer()
        self.timer.start(250)
        self.timer.timeout.connect(self.checking_status)
예제 #13
0
    def __init__(self, buffer_id, url, arguments):
        BrowserBuffer.__init__(self, buffer_id, url, arguments, False)

        self.url = url
        self.preview_file = tempfile.mkstemp(prefix='eaf-',
                                             suffix='.html',
                                             text=True)[1]
        self.render_js = os.path.join(os.path.dirname(__file__), "render.js")
        self.server_port = get_free_port()
        self.dark_mode = "false"
        if (get_emacs_var("eaf-markdown-dark-mode") == "force" or \
            get_emacs_var("eaf-markdown-dark-mode") == True or \
            (get_emacs_var("eaf-markdown-dark-mode") == "follow" and get_emacs_var("eaf-emacs-theme-mode") == "dark")):
            self.dark_mode = "true"

        self.draw_progressbar = True

        self.run_render_server()
        self.render()

        self.file_watcher = QFileSystemWatcher()
        self.file_watcher.fileChanged.connect(self.on_file_changed)
        self.file_watcher.addPath(url)
예제 #14
0
    def __init__(self, buffer_id, url, arguments):
        BrowserBuffer.__init__(self, buffer_id, url, arguments, False)

        self.url = url

        self.load_org_html_file()
예제 #15
0
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict,
                 module_path):
        BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments,
                               emacs_var_dict, module_path, False)

        self.config_dir = config_dir

        # When arguments is "temp_html_file", browser will load content of html file, then delete temp file.
        # Usually use for render html mail.
        if arguments == "temp_html_file":
            with open(url, "r") as html_file:
                self.buffer_widget.setHtml(html_file.read())
                if os.path.exists(url):
                    os.remove(url)
        else:
            self.buffer_widget.setUrl(QUrl(url))

        self.history_list = []
        if self.emacs_var_dict["eaf-browser-remember-history"] == "true":
            self.history_log_file_path = os.path.join(self.config_dir,
                                                      "browser", "history",
                                                      "log.txt")

            self.history_pattern = re.compile("^(.+)ᛝ(.+)ᛡ(.+)$")
            self.noprefix_url_pattern = re.compile("^(https?|file)://(.+)")
            self.nopostfix_url_pattern = re.compile("^[^#\?]*")
            self.history_close_file_path = os.path.join(
                self.config_dir, "browser", "history", "close.txt")
            touch(self.history_log_file_path)
            with open(self.history_log_file_path, "r", encoding="utf-8") as f:
                raw_list = f.readlines()
                for raw_his in raw_list:
                    his_line = re.match(self.history_pattern, raw_his)
                    if his_line is None:  # Obsolete Old history format
                        old_his = re.match("(.*)\s((https?|file):[^\s]+)$",
                                           raw_his)
                        if old_his is not None:
                            self.history_list.append(
                                HistoryPage(old_his.group(1), old_his.group(2),
                                            1))
                    else:
                        self.history_list.append(
                            HistoryPage(his_line.group(1), his_line.group(2),
                                        his_line.group(3)))

        self.autofill = PasswordDb(
            os.path.join(os.path.dirname(config_dir), "browser",
                         "password.db"))
        self.pw_autofill_id = 0
        self.pw_autofill_raw = self.buffer_widget.read_js_content(
            "pw_autofill.js")

        self.readability_js = open(os.path.join(
            os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
            "node_modules", "@mozilla", "readability", "Readability.js"),
                                   encoding="utf-8").read()

        self.close_page.connect(self.record_close_page)

        self.buffer_widget.titleChanged.connect(self.record_history)
        self.buffer_widget.titleChanged.connect(self.change_title)

        self.buffer_widget.translate_selected_text.connect(translate_text)

        self.buffer_widget.urlChanged.connect(self.set_adblocker)
        self.buffer_widget.urlChanged.connect(self.caret_exit)

        # Record url when url changed.
        self.buffer_widget.urlChanged.connect(self.update_url)

        self.buffer_widget.urlChanged.connect(self.skip_youtube_ads)

        # Draw progressbar.
        self.progressbar_progress = 0
        self.progressbar_color = QColor(
            self.emacs_var_dict["eaf-emacs-theme-foreground-color"])
        self.progressbar_height = 2
        self.buffer_widget.loadStarted.connect(self.start_progress)
        self.buffer_widget.loadProgress.connect(self.update_progress)
        self.is_loading = False

        # Reverse background and foreground color, to help cursor recognition.
        self.caret_foreground_color = QColor(
            self.emacs_var_dict["eaf-emacs-theme-background-color"])
        self.caret_background_color = QColor(
            self.emacs_var_dict["eaf-emacs-theme-foreground-color"])

        # Reset zoom after page loading finish.
        # Otherwise page won't zoom if we call setUrl api in current page.
        self.buffer_widget.loadFinished.connect(
            lambda: self.buffer_widget.zoom_reset())