Store more Qt properties as class attributes.
This commit is contained in:
parent
b90d402587
commit
01096b995c
@ -64,10 +64,9 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
self._pattern = val
|
self._pattern = val
|
||||||
self.invalidateFilter()
|
self.invalidateFilter()
|
||||||
sortcol = 0
|
sortcol = 0
|
||||||
srcmodel = self.sourceModel()
|
if self.srcmodel is not None:
|
||||||
if srcmodel is not None:
|
|
||||||
try:
|
try:
|
||||||
srcmodel.sort(sortcol)
|
self.srcmodel.sort(sortcol)
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
self.sort(sortcol)
|
self.sort(sortcol)
|
||||||
self.invalidate()
|
self.invalidate()
|
||||||
|
@ -244,7 +244,7 @@ class TabbedBrowser(TabWidget):
|
|||||||
"""
|
"""
|
||||||
dx = int(count) * float(dx)
|
dx = int(count) * float(dx)
|
||||||
dy = int(count) * float(dy)
|
dy = int(count) * float(dy)
|
||||||
self.currentWidget().page().mainFrame().scroll(dx, dy)
|
self.currentWidget().page_.mainFrame().scroll(dx, dy)
|
||||||
|
|
||||||
def cur_scroll_percent_x(self, perc=None, count=None):
|
def cur_scroll_percent_x(self, perc=None, count=None):
|
||||||
"""Scroll the current tab to a specific percent of the page.
|
"""Scroll the current tab to a specific percent of the page.
|
||||||
@ -274,7 +274,7 @@ class TabbedBrowser(TabWidget):
|
|||||||
perc = int(count)
|
perc = int(count)
|
||||||
else:
|
else:
|
||||||
perc = float(perc)
|
perc = float(perc)
|
||||||
frame = self.currentWidget().page().mainFrame()
|
frame = self.currentWidget().page_.mainFrame()
|
||||||
m = frame.scrollBarMaximum(orientation)
|
m = frame.scrollBarMaximum(orientation)
|
||||||
if m == 0:
|
if m == 0:
|
||||||
return
|
return
|
||||||
@ -283,10 +283,10 @@ class TabbedBrowser(TabWidget):
|
|||||||
def cur_scroll_page(self, mx, my, count=1):
|
def cur_scroll_page(self, mx, my, count=1):
|
||||||
"""Scroll the frame mx pages to the right and my pages down."""
|
"""Scroll the frame mx pages to the right and my pages down."""
|
||||||
# FIXME this might not work with HTML frames
|
# FIXME this might not work with HTML frames
|
||||||
page = self.currentWidget().page()
|
size = self.page_.viewportSize()
|
||||||
size = page.viewportSize()
|
self.currentWidget().page_.mainFrame().scroll(
|
||||||
page.mainFrame().scroll(int(count) * float(mx) * size.width(),
|
int(count) * float(mx) * size.width(),
|
||||||
int(count) * float(my) * size.height())
|
int(count) * float(my) * size.height())
|
||||||
|
|
||||||
def switch_prev(self, count=1):
|
def switch_prev(self, count=1):
|
||||||
"""Switch to the ([count]th) previous tab.
|
"""Switch to the ([count]th) previous tab.
|
||||||
@ -467,17 +467,19 @@ class BrowserTab(QWebView):
|
|||||||
_shutdown_callback = None # callback to be called after shutdown
|
_shutdown_callback = None # callback to be called after shutdown
|
||||||
_open_new_tab = False # open new tab for the next action
|
_open_new_tab = False # open new tab for the next action
|
||||||
_destroyed = None # Dict of all items to be destroyed.
|
_destroyed = None # Dict of all items to be destroyed.
|
||||||
|
page_ = None # QWebPage
|
||||||
# dict of tab specific signals, and the values we last got from them.
|
# dict of tab specific signals, and the values we last got from them.
|
||||||
signal_cache = None
|
signal_cache = None
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._destroyed = {}
|
self._destroyed = {}
|
||||||
self.setPage(BrowserPage())
|
self.page_ = BrowserPage(self)
|
||||||
|
self.setPage(self.page_)
|
||||||
self.signal_cache = SignalCache(uncached=['linkHovered'])
|
self.signal_cache = SignalCache(uncached=['linkHovered'])
|
||||||
self.loadProgress.connect(self.on_load_progress)
|
self.loadProgress.connect(self.on_load_progress)
|
||||||
self.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
|
self.page_.setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
|
||||||
self.page().linkHovered.connect(self.linkHovered)
|
self.page_.linkHovered.connect(self.linkHovered)
|
||||||
self.installEventFilter(self)
|
self.installEventFilter(self)
|
||||||
self.linkClicked.connect(self.on_link_clicked)
|
self.linkClicked.connect(self.on_link_clicked)
|
||||||
# FIXME find some way to hide scrollbars without setScrollBarPolicy
|
# FIXME find some way to hide scrollbars without setScrollBarPolicy
|
||||||
@ -537,8 +539,6 @@ class BrowserTab(QWebView):
|
|||||||
[1] https://github.com/integricho/path-of-a-pyqter/tree/master/qttut08
|
[1] https://github.com/integricho/path-of-a-pyqter/tree/master/qttut08
|
||||||
|
|
||||||
"""
|
"""
|
||||||
page = self.page()
|
|
||||||
netman = page.networkAccessManager()
|
|
||||||
self._shutdown_callback = callback
|
self._shutdown_callback = callback
|
||||||
try:
|
try:
|
||||||
# Avoid loading finished signal when stopping
|
# Avoid loading finished signal when stopping
|
||||||
@ -549,14 +549,16 @@ class BrowserTab(QWebView):
|
|||||||
self.close()
|
self.close()
|
||||||
self.settings().setAttribute(QWebSettings.JavascriptEnabled, False)
|
self.settings().setAttribute(QWebSettings.JavascriptEnabled, False)
|
||||||
|
|
||||||
self._destroyed[page] = False
|
self._destroyed[self.page_] = False
|
||||||
page.destroyed.connect(functools.partial(self.on_destroyed, page))
|
self.page_.destroyed.connect(functools.partial(self.on_destroyed,
|
||||||
page.deleteLater()
|
self.page_))
|
||||||
|
self.page_.deleteLater()
|
||||||
|
|
||||||
self._destroyed[self] = False
|
self._destroyed[self] = False
|
||||||
self.destroyed.connect(functools.partial(self.on_destroyed, self))
|
self.destroyed.connect(functools.partial(self.on_destroyed, self))
|
||||||
self.deleteLater()
|
self.deleteLater()
|
||||||
|
|
||||||
|
netman = self.page_.network_access_manager
|
||||||
self._destroyed[netman] = False
|
self._destroyed[netman] = False
|
||||||
netman.abort_requests()
|
netman.abort_requests()
|
||||||
netman.destroyed.connect(functools.partial(self.on_destroyed, netman))
|
netman.destroyed.connect(functools.partial(self.on_destroyed, netman))
|
||||||
@ -581,13 +583,13 @@ class BrowserTab(QWebView):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
if watched == self and e.type() == QEvent.Paint:
|
if watched == self and e.type() == QEvent.Paint:
|
||||||
frame = self.page().mainFrame()
|
frame = self.page_.mainFrame()
|
||||||
new_pos = (frame.scrollBarValue(Qt.Horizontal),
|
new_pos = (frame.scrollBarValue(Qt.Horizontal),
|
||||||
frame.scrollBarValue(Qt.Vertical))
|
frame.scrollBarValue(Qt.Vertical))
|
||||||
if self._scroll_pos != new_pos:
|
if self._scroll_pos != new_pos:
|
||||||
self._scroll_pos = new_pos
|
self._scroll_pos = new_pos
|
||||||
logging.debug("Updating scroll position")
|
logging.debug("Updating scroll position")
|
||||||
frame = self.page().mainFrame()
|
frame = self.page_.mainFrame()
|
||||||
m = (frame.scrollBarMaximum(Qt.Horizontal),
|
m = (frame.scrollBarMaximum(Qt.Horizontal),
|
||||||
frame.scrollBarMaximum(Qt.Vertical))
|
frame.scrollBarMaximum(Qt.Vertical))
|
||||||
perc = (round(100 * new_pos[0] / m[0]) if m[0] != 0 else 0,
|
perc = (round(100 * new_pos[0] / m[0]) if m[0] != 0 else 0,
|
||||||
@ -619,15 +621,15 @@ class BrowserPage(QWebPage):
|
|||||||
"""Our own QWebPage with advanced features."""
|
"""Our own QWebPage with advanced features."""
|
||||||
|
|
||||||
_extension_handlers = None
|
_extension_handlers = None
|
||||||
_network_access_manager = None
|
network_access_manager = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, parent=None):
|
||||||
super().__init__()
|
super().__init__(parent)
|
||||||
self._extension_handlers = {
|
self._extension_handlers = {
|
||||||
QWebPage.ErrorPageExtension: self._handle_errorpage,
|
QWebPage.ErrorPageExtension: self._handle_errorpage,
|
||||||
}
|
}
|
||||||
self._network_access_manager = NetworkManager()
|
self.network_access_manager = NetworkManager(self)
|
||||||
self.setNetworkAccessManager(self._network_access_manager)
|
self.setNetworkAccessManager(self.network_access_manager)
|
||||||
|
|
||||||
def supportsExtension(self, ext):
|
def supportsExtension(self, ext):
|
||||||
"""Override QWebPage::supportsExtension to provide error pages."""
|
"""Override QWebPage::supportsExtension to provide error pages."""
|
||||||
|
@ -83,6 +83,7 @@ class CompletionView(QTreeView):
|
|||||||
enabled = True
|
enabled = True
|
||||||
completing = False
|
completing = False
|
||||||
height = QPoint(0, 200)
|
height = QPoint(0, 200)
|
||||||
|
_delegate = None
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
@ -92,7 +93,8 @@ class CompletionView(QTreeView):
|
|||||||
self.model = CompletionFilterModel()
|
self.model = CompletionFilterModel()
|
||||||
self.setModel(self.model)
|
self.setModel(self.model)
|
||||||
self.setmodel('command')
|
self.setmodel('command')
|
||||||
self.setItemDelegate(CompletionItemDelegate())
|
self._delegate = CompletionItemDelegate(self)
|
||||||
|
self.setItemDelegate(self._delegate)
|
||||||
self.setStyleSheet(config.get_stylesheet(self._stylesheet))
|
self.setStyleSheet(config.get_stylesheet(self._stylesheet))
|
||||||
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Minimum)
|
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Minimum)
|
||||||
self.setHeaderHidden(True)
|
self.setHeaderHidden(True)
|
||||||
|
@ -164,6 +164,7 @@ class Command(QLineEdit):
|
|||||||
_shortcuts = []
|
_shortcuts = []
|
||||||
_tmphist = []
|
_tmphist = []
|
||||||
_histpos = None
|
_histpos = None
|
||||||
|
_validator = None # CommandValidator
|
||||||
|
|
||||||
# FIXME won't the tab key switch to the next widget?
|
# FIXME won't the tab key switch to the next widget?
|
||||||
# See [0] for a possible fix.
|
# See [0] for a possible fix.
|
||||||
@ -180,7 +181,8 @@ class Command(QLineEdit):
|
|||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
""")
|
""")
|
||||||
self.setValidator(CommandValidator())
|
self._validator = CommandValidator(self)
|
||||||
|
self.setValidator(self._validator)
|
||||||
self.returnPressed.connect(self.on_return_pressed)
|
self.returnPressed.connect(self.on_return_pressed)
|
||||||
self.textEdited.connect(self._histbrowse_stop)
|
self.textEdited.connect(self._histbrowse_stop)
|
||||||
self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Ignored)
|
self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Ignored)
|
||||||
|
Loading…
Reference in New Issue
Block a user