Skip to content
Permalink
Browse files

Add progress interfaces.

  • Loading branch information...
manateelazycat committed Jul 20, 2018
1 parent b31e3a5 commit 8be7725f108dff0dfd9a3d1d63dbc56036e5b162
Showing with 48 additions and 10 deletions.
  1. +0 −3 core/browser.py
  2. +5 −0 core/browser_buffer.py
  3. +32 −6 core/buffer.py
  4. +11 −0 docs/HACKING.md
  5. +0 −1 docs/TODOLIST.md
@@ -38,14 +38,11 @@ def __init__(self):
self.web_page = BrowserPage()
self.setPage(self.web_page)

self.event_widgets = []

def event(self, event):
if event.type() == QEvent.ChildAdded:
obj = event.child()
if isinstance(obj, QWidget):
obj.installEventFilter(self)
self.event_widgets.append(obj)

return QtWebEngineWidgets.QWebEngineView.event(self, event)

@@ -19,6 +19,7 @@
# 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 PyQt5 import QtCore
from core.browser import BrowserView, webview_scroll
from core.buffer import Buffer

@@ -29,6 +30,10 @@ def __init__(self, buffer_id, url, fit_to_view, background_color):

self.add_widget(BrowserView())

self.buffer_widget.loadStarted.connect(self.start_progress)
self.buffer_widget.loadProgress.connect(self.update_progress)
self.buffer_widget.loadFinished.connect(self.stop_progress)

def get_key_event_widgets(self):
# We need send key event to QWebEngineView's focusProxy widget, not QWebEngineView.
return [self.buffer_widget.focusProxy()]
@@ -20,7 +20,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from PyQt5 import QtCore
from PyQt5.QtGui import QBrush
from PyQt5.QtGui import QBrush, QColor
from PyQt5.QtWidgets import QGraphicsScene, QApplication
import abc
from core.utils import PostGui
@@ -44,17 +44,43 @@ def __init__(self, buffer_id, url, fit_to_view, background_color):

self.buffer_widget = None

self.draw_progressbar = False
self.progressbar_progress = 0
self.progressbar_color = QColor(233, 129, 35, 255)
self.progressbar_height = 2

def drawForeground(self, painter, rect):
if self.draw_progressbar:
painter.setBrush(self.progressbar_color)
painter.setPen(self.progressbar_color)
painter.drawRect(0, 0, rect.width() * self.progressbar_progress * 1.0 / 100, self.progressbar_height)

@QtCore.pyqtSlot()
def start_progress(self):
self.progressbar_progress = 0
self.draw_progressbar = True
self.update()

@QtCore.pyqtSlot()
def stop_progress(self):
self.draw_progressbar = False
self.update()

@QtCore.pyqtSlot(int)
def update_progress(self, progress):
self.progressbar_progress = progress
self.draw_progressbar = True
self.update()

if progress == 100:
QtCore.QTimer.singleShot(500, self.stop_progress)

def add_widget(self, widget):
self.buffer_widget = widget
self.addWidget(self.buffer_widget)

self.buffer_widget.installEventFilter(self)

def eventFitler(self, event):
print("8u3947923473924732 ", event.type())

return False

def handle_destroy(self):
self.before_destroy_hook.emit()

@@ -201,5 +201,16 @@ If you want handle keystroke send from Emacs, you just need implement interface

Argument "keystroke" is emacs key string.

### Update progress.

If your application will do some long-time operation, you can use below use below interfaces of buffer:

```Python
def start_progress(self):
def stop_progress(self):
def update_progress(self, progress):
```


## Todolist
[Some works you can hacking ;)](TODOLIST.md)
@@ -2,7 +2,6 @@
* Core: Remove border of QGraphicsView.
* Browser: add cookie support
* Browser: support pop window, such as emacs-china.org
* Browser: add progressbar
* Browser: add proxy support
* Browser: implement js plugin like vimium
* Browser: study more code from https://github.com/LavaPower/Browthon-Old/blob/c25d5721b40e95131a3c521566a18467f13ecbf0/files/Browthon_elements.py

0 comments on commit 8be7725

Please sign in to comment.
You can’t perform that action at this time.