Commit 331253fa authored by Andy Stewart's avatar Andy Stewart
Browse files

Include browser_buffer module to remove duplicate interface code.

parent 14b91abf
Loading
Loading
Loading
Loading
+3 −13
Original line number Diff line number Diff line
@@ -21,22 +21,12 @@

from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QColor
from core.browser import BrowserView, webview_scroll
from core.buffer import Buffer
from core.browser_buffer import BrowserBuffer

class AppBuffer(Buffer):
class AppBuffer(BrowserBuffer):
    def __init__(self, buffer_id, url):
        Buffer.__init__(self, buffer_id, url, False, QColor(255, 255, 255, 255))
        BrowserBuffer.__init__(self, buffer_id, url, False, QColor(255, 255, 255, 255))

        self.add_widget(BrowserView())
        self.buffer_widget.setUrl(QUrl(url))
        self.buffer_widget.titleChanged.connect(self.change_title)
        self.buffer_widget.open_url_in_new_tab.connect(self.open_url)

    def send_key_event(self, event):
        # We need send key event to QWebEngineView's child, not QWebEngineView.
        for child in self.buffer_widget.children():
            QApplication.sendEvent(child, event)

    def scroll(self, scroll_direction, scroll_type):
        webview_scroll(self, scroll_direction, scroll_type)
+3 −9
Original line number Diff line number Diff line
@@ -21,17 +21,16 @@

from PyQt5.QtCore import QUrl, Qt
from PyQt5.QtGui import QColor
from core.browser import BrowserView, webview_scroll
from core.buffer import Buffer
from core.browser_buffer import BrowserBuffer
from core.utils import PostGui
import socket
import subprocess
import threading
import os

class AppBuffer(Buffer):
class AppBuffer(BrowserBuffer):
    def __init__(self, buffer_id, url):
        Buffer.__init__(self, buffer_id, url, False, QColor(255, 255, 255, 255))
        BrowserBuffer.__init__(self, buffer_id, url, False, QColor(255, 255, 255, 255))

        # Get free port to render markdown.
        self.port = self.get_free_port()
@@ -40,9 +39,6 @@ class AppBuffer(Buffer):
        # Start markdown render process.
        subprocess.Popen("grip {0} {1}".format(url, self.port), shell=True)

        # Init widget.
        self.add_widget(BrowserView())

        # Add timer make load markdown preview link after grip process start finish.
        timer = threading.Timer(2, self.load_markdown_server)
        timer.start()
@@ -67,5 +63,3 @@ class AppBuffer(Buffer):
        if len(paths) > 0:
            self.change_title(paths[-1])
    def scroll(self, scroll_direction, scroll_type):
        webview_scroll(self, scroll_direction, scroll_type)
+3 −8
Original line number Diff line number Diff line
@@ -21,16 +21,14 @@

from PyQt5.QtCore import QUrl, Qt
from PyQt5.QtGui import QColor
from core.browser import BrowserView, webview_scroll
from core.buffer import Buffer
from core.browser_buffer import BrowserBuffer
import os

class AppBuffer(Buffer):
class AppBuffer(BrowserBuffer):
    def __init__(self, buffer_id, url):
        Buffer.__init__(self, buffer_id, url, False, QColor(255, 255, 255, 255))
        BrowserBuffer.__init__(self, buffer_id, url, False, QColor(255, 255, 255, 255))

        self.url = url
        self.add_widget(BrowserView())

        self.load_org_html_file()

@@ -40,6 +38,3 @@ class AppBuffer(Buffer):
    def update_with_data(self, update_data):
        self.load_org_html_file()
        self.buffer_widget.reload()

    def scroll(self, scroll_direction, scroll_type):
        webview_scroll(self, scroll_direction, scroll_type)

core/browser_buffer.py

0 → 100644
+38 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright (C) 2018 Andy Stewart
#
# Author:     Andy Stewart <lazycat.manatee@gmail.com>
# Maintainer: Andy Stewart <lazycat.manatee@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from core.browser import BrowserView, webview_scroll
from core.buffer import Buffer

class BrowserBuffer(Buffer):

    def __init__(self, buffer_id, url, fit_to_view, background_color):
        Buffer.__init__(self, buffer_id, url, fit_to_view, background_color)

        self.add_widget(BrowserView())

    def send_key_event(self, event):
        # We need send key event to QWebEngineView's child, not QWebEngineView.
        for child in self.buffer_widget.children():
            QApplication.sendEvent(child, event)

    def scroll(self, scroll_direction, scroll_type):
        webview_scroll(self, scroll_direction, scroll_type)