2014-01-17 12:24:38 +01:00
|
|
|
from PyQt5.QtCore import QObject, pyqtSlot, QUrl, pyqtSignal
|
2013-12-15 21:40:15 +01:00
|
|
|
from PyQt5.QtWebKitWidgets import QWebView
|
|
|
|
from qutebrowser.widgets.tabbar import TabWidget
|
2014-01-17 20:29:20 +01:00
|
|
|
import logging
|
2013-12-15 21:40:15 +01:00
|
|
|
|
|
|
|
class TabbedBrowser(TabWidget):
|
|
|
|
tabs = []
|
2014-01-17 12:24:38 +01:00
|
|
|
cur_progress = pyqtSignal(int)
|
2013-12-15 21:40:15 +01:00
|
|
|
|
|
|
|
def __init__(self, parent):
|
|
|
|
super().__init__(parent)
|
2014-01-17 13:16:13 +01:00
|
|
|
self.currentChanged.connect(self.index_changed)
|
2013-12-15 21:40:15 +01:00
|
|
|
self.tabopen("http://ddg.gg/")
|
|
|
|
|
|
|
|
@pyqtSlot(str)
|
|
|
|
def tabopen(self, url):
|
|
|
|
tab = BrowserTab(self)
|
|
|
|
tab.openurl(url)
|
|
|
|
self.tabs.append(tab)
|
|
|
|
self.addTab(tab, url)
|
2013-12-16 22:07:11 +01:00
|
|
|
self.setCurrentWidget(tab)
|
2014-01-17 20:29:07 +01:00
|
|
|
self.progress_changed(tab.progress)
|
2014-01-17 13:08:44 +01:00
|
|
|
tab.loadProgress.connect(self.progress_changed)
|
2013-12-15 21:40:15 +01:00
|
|
|
|
2013-12-16 22:01:06 +01:00
|
|
|
@pyqtSlot(str)
|
|
|
|
def openurl(self, url):
|
|
|
|
tab = self.tabs[self.currentIndex()]
|
|
|
|
tab.openurl(url)
|
|
|
|
|
2014-01-17 08:03:42 +01:00
|
|
|
@pyqtSlot()
|
|
|
|
def close_act(self):
|
2014-01-17 08:28:04 +01:00
|
|
|
if len(self.tabs) > 1:
|
|
|
|
idx = self.currentIndex()
|
|
|
|
self.tabs.pop(idx)
|
|
|
|
self.removeTab(idx)
|
|
|
|
else:
|
|
|
|
# FIXME
|
|
|
|
pass
|
2014-01-17 08:03:42 +01:00
|
|
|
|
2014-01-17 08:39:14 +01:00
|
|
|
@pyqtSlot()
|
|
|
|
def switch_prev(self):
|
|
|
|
idx = self.currentIndex()
|
|
|
|
if idx > 0:
|
|
|
|
self.setCurrentIndex(idx - 1)
|
|
|
|
else:
|
|
|
|
# FIXME
|
|
|
|
pass
|
|
|
|
|
|
|
|
@pyqtSlot()
|
|
|
|
def switch_next(self):
|
|
|
|
idx = self.currentIndex()
|
|
|
|
if idx < self.count() - 1:
|
|
|
|
self.setCurrentIndex(idx + 1)
|
|
|
|
else:
|
|
|
|
# FIXME
|
|
|
|
pass
|
|
|
|
|
2014-01-17 13:08:44 +01:00
|
|
|
@pyqtSlot(int)
|
|
|
|
def progress_changed(self, prog):
|
|
|
|
if self.currentWidget() == self.sender():
|
2014-01-17 20:29:20 +01:00
|
|
|
logging.debug("progress = {}, current".format(prog))
|
2014-01-17 13:08:44 +01:00
|
|
|
self.cur_progress.emit(prog)
|
2014-01-17 20:29:20 +01:00
|
|
|
else:
|
|
|
|
logging.debug("progress = {}, non-current".format(prog))
|
2014-01-17 08:39:14 +01:00
|
|
|
|
2014-01-17 13:16:13 +01:00
|
|
|
@pyqtSlot(int)
|
|
|
|
def index_changed(self, idx):
|
|
|
|
tab = self.widget(idx)
|
|
|
|
self.cur_progress.emit(tab.progress)
|
|
|
|
|
2013-12-15 21:40:15 +01:00
|
|
|
class BrowserTab(QWebView):
|
2014-01-17 12:24:38 +01:00
|
|
|
parent = None
|
2014-01-17 13:16:13 +01:00
|
|
|
progress = 0
|
2014-01-17 12:24:38 +01:00
|
|
|
|
2013-12-15 21:40:15 +01:00
|
|
|
def __init__(self, parent):
|
|
|
|
super().__init__(parent)
|
2014-01-17 13:16:13 +01:00
|
|
|
self.loadProgress.connect(self.set_progress)
|
2013-12-15 21:40:15 +01:00
|
|
|
self.show()
|
|
|
|
|
|
|
|
def openurl(self, url):
|
|
|
|
if not url.startswith('http://'):
|
|
|
|
url = 'http://' + url
|
|
|
|
super().load(QUrl(url))
|
2014-01-17 13:16:13 +01:00
|
|
|
|
|
|
|
def set_progress(self, prog):
|
|
|
|
self.progress = prog
|