Add an :all-widgets command and useful __repr__s

This commit is contained in:
Florian Bruhin 2014-06-17 06:37:56 +02:00
parent 177e2945b6
commit 17cd86d564
11 changed files with 40 additions and 0 deletions

View File

@ -533,6 +533,15 @@ class Application(QApplication):
qutescheme.pyeval_output = out
self.mainwindow.tabs.cmd.openurl('qute:pyeval')
@cmdutils.register(instance='', debug=True)
def all_widgets(self):
"""Print a list of all widgets to debug log."""
widgets = self.allWidgets()
log.misc.debug("{} widgets".format(len(widgets)))
widgets.sort(key=lambda e: repr(e))
for w in widgets:
log.misc.debug(w)
@pyqtSlot()
def shutdown(self):
"""Try to shutdown everything cleanly.

View File

@ -112,6 +112,9 @@ class CompletionView(QTreeView):
self.hide()
# FIXME set elidemode
def __repr__(self):
return '<CompletionView>'
def _resize_columns(self):
"""Resize the completion columns based on COLUMN_WIDTHS."""
width = self.size().width()

View File

@ -60,6 +60,10 @@ class DownloadView(QListView):
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.show_context_menu)
def __repr__(self):
return '<DownloadView with {} downloads>'.format(
self.model().rowCount())
@pyqtSlot('QPoint')
def show_context_menu(self, point):
"""Show the context menu."""

View File

@ -88,6 +88,9 @@ class MainWindow(QWidget):
#self.tabWidget.setCurrentIndex(0)
#QtCore.QMetaObject.connectSlotsByName(MainWindow)
def __repr__(self):
return '<MainWindow>'
def _set_default_geometry(self):
"""Set some sensible default geometry."""
self.setGeometry(QRect(50, 50, 800, 600))

View File

@ -33,3 +33,6 @@ class MinimalLineEdit(QLineEdit):
background-color: transparent;
}
""")
def __repr__(self):
return '<{} "{}">'.format(self.__class__.__name__, self.text())

View File

@ -158,6 +158,9 @@ class StatusBar(QWidget):
self.prog = Progress(self)
self._hbox.addWidget(self.prog)
def __repr__(self):
return '<StatusBar>'
@pyqtProperty(bool)
def error(self):
"""Getter for self.error, so it can be used as Qt property."""

View File

@ -53,6 +53,9 @@ class Progress(QProgressBar):
self.setTextVisible(False)
self.hide()
def __repr__(self):
return '<Progress {}%>'.format(self.value())
@pyqtSlot()
def on_load_started(self):
"""Clear old error and show progress, used as slot to loadStarted."""

View File

@ -63,6 +63,9 @@ class Prompt(QWidget):
self._input = MinimalLineEdit()
self._hbox.addWidget(self._input)
def __repr__(self):
return '<Prompt>'
def on_mode_left(self, mode):
"""Clear and reset input when the mode was left."""
if mode in ('prompt', 'yesno'):

View File

@ -42,6 +42,9 @@ class TextBase(QLabel):
self._elidemode = elidemode
self._elided_text = ''
def __repr__(self):
return '<{} "{}">'.format(self.__class__.__name__, self.text())
def _update_elided_text(self, width):
"""Update the elided text when necessary.

View File

@ -107,6 +107,9 @@ class TabbedBrowser(TabWidget):
# FIXME adjust this to font size
self.setIconSize(QSize(12, 12))
def __repr__(self):
return '<TabbedBrowser with {} tabs>'.format(self.count())
@property
def widgets(self):
"""Get a list of open tab widgets.

View File

@ -123,6 +123,9 @@ class TabBar(QTabBar):
"""Custom tabbar to close tabs on right click."""
def __repr__(self):
return '<TabBar with {} tabs>'.format(self.count())
def mousePressEvent(self, e):
"""Override mousePressEvent to emit tabCloseRequested on rightclick."""
if e.button() != Qt.RightButton: