def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path, call_emacs): BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path, call_emacs, 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.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(self.translate_text) self.buffer_widget.open_url_in_new_tab.connect(self.open_url_in_new_tab) self.buffer_widget.open_url_in_background_tab.connect(self.open_url_in_background_tab) # Reset to default zoom when page init or url changed. self.reset_default_zoom() self.buffer_widget.urlChanged.connect(self.update_url)
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.load_image(url)
def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path, call_emacs): BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path, call_emacs, False, QColor(255, 255, 255, 255)) # Get free port to render markdown. self.port = get_free_port() self.url = url argument_list = arguments.split("ᛡ") self.command = argument_list[0] self.start_directory = argument_list[1] self.server_js = (os.path.join(os.path.dirname(__file__), "server.js")) # Start server process. self.background_process = subprocess.Popen( "node {0} {1} {2} {3}".format( self.server_js, self.port, "'{}'".format(self.start_directory), "'{}'".format(self.command), stdout=subprocess.PIPE ), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) self.load_server() self.reset_default_zoom()
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 = "file://" + (os.path.join(os.path.dirname(__file__), "index.html")) self.buffer_widget.setUrl(QUrl(index_file)) self.cut_node_id = None for method_name in ["add_sub_node", "add_brother_node", "remove_node", "remove_middle_node", "add_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", "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", "save_screenshot"]: self.build_insert_or_do(method_name) self.build_all_methods(self) QTimer.singleShot(500, self.init_file)
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 = "file://" + (os.path.join(os.path.dirname(__file__), "index.html")) self.buffer_widget.setUrl(QUrl(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", "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", "save_screenshot"]: self.build_insert_or_do(method_name) self.build_all_methods(self) # Reset to default zoom when page init or url changed. self.reset_default_zoom() QTimer.singleShot(500, self.init_file)
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.url = url arguments_dict = json.loads(arguments) self.command = arguments_dict["command"] self.start_directory = arguments_dict["directory"] self.index_file = os.path.join(os.path.dirname(__file__), "index.html") self.server_js = os.path.join(os.path.dirname(__file__), "server.js") # Start server process. self.background_process = subprocess.Popen( "node {0} {1} '{2}' '{3}'".format(self.server_js, self.port, self.start_directory, self.command), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) self.open_terminal_page() self.reset_default_zoom() QTimer.singleShot(250, self.focus_terminal)
def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path, call_emacs): BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path, call_emacs, False, QColor(255, 255, 255, 255)) self.load_image(url)
def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict): BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, False, QColor(255, 255, 255, 255)) self.url = url index_file = "file://" + (os.path.join(os.path.dirname(__file__), "index.html")) self.buffer_widget.setUrl(QUrl(index_file)) self.cut_node_id = None for method_name in ["add_sub_node", "add_brother_node", "remove_node"]: 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", "save_screenshot"]: self.build_js_method(method_name) for method_name in ["zoom_in", "zoom_out", "zoom_reset", "remove_node", "update_node_topic", "copy_node_topic", "paste_node_topic", "refresh_page", "select_up_node", "select_down_node", "select_left_node", "select_right_node", "toggle_node", "save_screenshot", "save_file", "save_org_file", "change_node_background", "cut_node_tree", "paste_node_tree"]: self.build_insert_or_do(method_name) QTimer.singleShot(500, self.init_file)
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())
def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict): BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, False, QColor(255, 255, 255, 255)) self.url = url self.load_org_html_file()
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()
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.render() self.update_content.connect(self.render) threading.Timer(1, self.monitor_file_change).start()
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://"))
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)
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 with open(self.index_file, "r") as f: html = f.read().replace("%1", os.path.join( os.path.dirname(__file__))).replace( "%2", self.url) self.buffer_widget.setHtml(html, QUrl("file://"))
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. self.background_process = subprocess.Popen( "node {0} {1} '{2}' '{3}'".format(self.server_js, self.port, self.start_directory, self.command), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) self.open_terminal_page() self.reset_default_zoom() QTimer.singleShot(250, self.focus_terminal) self.build_all_methods(self) self.timer = QTimer() self.timer.start(250) self.timer.timeout.connect(self.checking_status)
def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict): BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, False, QColor(255, 255, 255, 255)) 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_log_file_path = os.path.join(self.config_dir, "browser", "history", "log.txt") self.history_url_pattern = re.compile("(.*?)\s([^\s]+)$") self.buffer_widget.titleChanged.connect(self.record_history) self.buffer_widget.titleChanged.connect(self.change_title) self.buffer_widget.translate_selected_text.connect(self.translate_text) self.buffer_widget.open_url_in_new_tab.connect( self.open_url_in_new_tab) self.buffer_widget.open_url_in_background_tab.connect( self.open_url_in_background_tab) # Reset to default zoom when page init or url changed. self.reset_default_zoom() self.buffer_widget.urlChanged.connect( lambda url: self.reset_default_zoom()) settings = QWebEngineSettings.globalSettings() try: settings.setAttribute( QWebEngineSettings.PluginsEnabled, self.emacs_var_dict["eaf-browser-enable-plugin"] == "true") settings.setAttribute( QWebEngineSettings.JavascriptEnabled, self.emacs_var_dict["eaf-browser-enable-javascript"] == "true") except Exception: pass
def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict): BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, False, QColor(255, 255, 255, 255)) # Get free port to render markdown. self.port = get_free_port() self.url = url # Start wetty process. self.background_process = subprocess.Popen( "wetty -p {0} --base / --sshuser {1} --sshauth publickey -c bash".format(self.port, getpass.getuser()), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) # Add timer make load markdown preview link after grip process start finish. threading.Timer(1, self.load_wetty_server).start() self.reset_default_zoom()
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.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 emacs_var_dict["eaf-markdown-dark-mode"] == "true" or \ (emacs_var_dict["eaf-markdown-dark-mode"] == "follow" and emacs_var_dict["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)
def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict): BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, False, QColor(255, 255, 255, 255)) # Get free port to render markdown. self.port = self.get_free_port() self.url = url # Start markdown render process. if arguments == "": subprocess.Popen("grip {0} {1}".format(url, self.port), shell=True) else: subprocess.Popen("grip --pass {0} {1} {2}".format( arguments, url, self.port), shell=True) # Add timer make load markdown preview link after grip process start finish. timer = threading.Timer(2, self.load_markdown_server) timer.start()
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://"))
def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path, call_emacs): BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module_path, call_emacs, False, QColor(233, 129, 35, 255)) # Get free port. self.port = get_free_port() self.url = url argument_list = arguments.split("ᛡ") self.command = argument_list[0] self.start_directory = argument_list[1] self.index_file = os.path.join(os.path.dirname(__file__), "index.html") self.server_js = os.path.join(os.path.dirname(__file__), "server.js") # Start server process. self.background_process = subprocess.Popen( "node {0} {1} '{2}' '{3}'".format(self.server_js, self.port, self.start_directory, self.command), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) self.open_terminal_page() self.reset_default_zoom()
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.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(self.translate_text) self.buffer_widget.open_url_in_new_tab.connect( self.open_url_in_new_tab) self.buffer_widget.duplicate_page_in_new_tab.connect( self.duplicate_page_in_new_tab) self.buffer_widget.open_url_in_background_tab.connect( self.open_url_in_background_tab) 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)
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) # Draw progressbar. self.progressbar_progress = 0 self.buffer_widget.loadStarted.connect(self.start_progress) self.buffer_widget.loadProgress.connect(self.update_progress) # 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())
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.load_image(url)