Add profile.py
This commit is contained in:
parent
4925d25c36
commit
a9a4b2ac92
27
profile.py
Normal file
27
profile.py
Normal file
@ -0,0 +1,27 @@
|
||||
"""Profile qutebrowser."""
|
||||
|
||||
import sys
|
||||
import cProfile
|
||||
import os.path
|
||||
from os import getcwd
|
||||
from tempfile import mkdtemp
|
||||
from subprocess import call
|
||||
from shutil import rmtree
|
||||
|
||||
from qutebrowser.app import QuteBrowser
|
||||
|
||||
tempdir = mkdtemp()
|
||||
|
||||
if '--keep' in sys.argv:
|
||||
sys.argv.remove('--keep')
|
||||
profilefile = os.path.join(getcwd(), 'profile')
|
||||
else:
|
||||
profilefile = os.path.join(tempdir, 'profile')
|
||||
callgraphfile = os.path.join(tempdir, 'callgraph')
|
||||
|
||||
profiler = cProfile.Profile()
|
||||
profiler.run('app = QuteBrowser(); app.exec_()')
|
||||
profiler.dump_stats(profilefile)
|
||||
|
||||
call(['pyprof2calltree', '-k', '-i', profilefile, '-o', callgraphfile])
|
||||
rmtree(tempdir)
|
@ -96,13 +96,6 @@ class CompletionView(QTreeView):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
height = config.config.get('general', 'completion_height')
|
||||
if height.endswith('%'):
|
||||
self._height = QPoint(0, 200) # just a temporary sane value
|
||||
self._height_perc = int(height.rstrip('%'))
|
||||
else:
|
||||
self._height = QPoint(0, int(height))
|
||||
self._height_perc = None
|
||||
self._enabled = config.config.getboolean('general', 'show_completion')
|
||||
self._completion_models = {}
|
||||
self._completion_models[''] = None
|
||||
@ -169,55 +162,6 @@ class CompletionView(QTreeView):
|
||||
self.expandAll()
|
||||
self.resizeColumnToContents(0)
|
||||
|
||||
@pyqtSlot('QRect')
|
||||
def resize_to_bar(self, geom):
|
||||
"""Resize the completion area to the statusbar geometry.
|
||||
|
||||
Slot for the resized signal of the statusbar.
|
||||
|
||||
Args:
|
||||
geom: A QRect containing the statusbar geometry.
|
||||
|
||||
Raises:
|
||||
AssertionError if new geometry is invalid.
|
||||
|
||||
"""
|
||||
bottomleft = geom.topLeft()
|
||||
bottomright = geom.topRight()
|
||||
topleft = bottomleft - self._height
|
||||
assert topleft.x() < bottomright.x()
|
||||
assert topleft.y() < bottomright.y()
|
||||
self.setGeometry(QRect(topleft, bottomright))
|
||||
|
||||
@pyqtSlot('QRect')
|
||||
def on_browser_resized(self, geom):
|
||||
"""Slot for the resized signal of the browser window.
|
||||
|
||||
Adjust the height of the completion if it was configured as a
|
||||
percentage.
|
||||
|
||||
Args:
|
||||
geom: A QRect containing the browser geometry.
|
||||
|
||||
"""
|
||||
if self._height_perc is None:
|
||||
return
|
||||
else:
|
||||
height = int(geom.height() * self._height_perc / 100)
|
||||
self._height = QPoint(0, height)
|
||||
|
||||
@pyqtSlot('QPoint')
|
||||
def move_to_bar(self, pos):
|
||||
"""Move the completion area to the statusbar geometry.
|
||||
|
||||
Slot for the moved signal of the statusbar.
|
||||
|
||||
Args:
|
||||
pos: A QPoint containing the statusbar position.
|
||||
|
||||
"""
|
||||
self.move(pos - self._height)
|
||||
|
||||
@pyqtSlot(str)
|
||||
def on_cmd_text_changed(self, text):
|
||||
"""Check if completions are available and activate them.
|
||||
|
@ -20,7 +20,7 @@
|
||||
import binascii
|
||||
from base64 import b64decode
|
||||
|
||||
from PyQt5.QtCore import QRect
|
||||
from PyQt5.QtCore import QRect, QPoint
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout
|
||||
|
||||
from qutebrowser.widgets.statusbar import StatusBar
|
||||
@ -72,9 +72,9 @@ class MainWindow(QWidget):
|
||||
self.status = StatusBar()
|
||||
self._vbox.addWidget(self.status)
|
||||
|
||||
self.status.resized.connect(self.completion.resize_to_bar)
|
||||
self.status.moved.connect(self.completion.move_to_bar)
|
||||
self.tabs.resized.connect(self.completion.on_browser_resized)
|
||||
#self.status.resized.connect(self.completion.resize_to_bar)
|
||||
#self.status.moved.connect(self.completion.move_to_bar)
|
||||
#self.tabs.resized.connect(self.completion.on_browser_resized)
|
||||
self.tabs.cur_progress.connect(self.status.prog.setValue)
|
||||
self.tabs.cur_load_finished.connect(self.status.prog.hide)
|
||||
self.tabs.cur_load_finished.connect(
|
||||
@ -101,3 +101,23 @@ class MainWindow(QWidget):
|
||||
def _set_default_geometry(self):
|
||||
"""Set some sensible default geometry."""
|
||||
self.setGeometry(QRect(50, 50, 800, 600))
|
||||
|
||||
def resizeEvent(self, e):
|
||||
"""Extend resizewindow's resizeEvent to adjust completion.
|
||||
|
||||
Args:
|
||||
e: The QResizeEvent
|
||||
|
||||
"""
|
||||
super().resizeEvent(e)
|
||||
confheight = config.config.get('general', 'completion_height')
|
||||
if confheight.endswith('%'):
|
||||
perc = int(confheight.rstrip('%'))
|
||||
height = self.height() * perc / 100
|
||||
else:
|
||||
height = int(confheight)
|
||||
# hpoint now would be the bottom-left edge of the widget if it was on
|
||||
# the top of the main window.
|
||||
topleft = QPoint(0, self.height() - self.status.height() - height)
|
||||
bottomright = self.status.geometry().topRight()
|
||||
self.completion.setGeometry(QRect(topleft, bottomright))
|
||||
|
Loading…
Reference in New Issue
Block a user