Better __repr__s
This commit is contained in:
parent
9aa65a2341
commit
908a69af18
@ -156,6 +156,9 @@ class Application(QApplication):
|
||||
if self._crashdlg is not None:
|
||||
self._crashdlg.raise_()
|
||||
|
||||
def __repr__(self):
|
||||
return '<{}>'.format(self.__class__.__name__)
|
||||
|
||||
def _init_config(self):
|
||||
"""Inizialize and read the config."""
|
||||
if self._args.confdir is None:
|
||||
|
@ -39,6 +39,6 @@ class DiskCache(QNetworkDiskCache):
|
||||
self.setMaximumCacheSize(config.get('storage', 'cache-size'))
|
||||
|
||||
def __repr__(self):
|
||||
return '<{} size={}, maxsize={}, path={}>'.format(
|
||||
return '<{} size={}, maxsize={}, path="{}">'.format(
|
||||
self.__class__.__name__, self.cacheSize(), self.maximumCacheSize(),
|
||||
self.cacheDirectory())
|
||||
|
@ -65,6 +65,9 @@ class CommandDispatcher:
|
||||
self._tabs = parent
|
||||
self._editor = None
|
||||
|
||||
def __repr__(self):
|
||||
return '<{}>'.format(self.__class__.__name__)
|
||||
|
||||
def _current_widget(self):
|
||||
"""Get the currently active widget from a command."""
|
||||
widget = self._tabs.currentWidget()
|
||||
|
@ -32,6 +32,7 @@ class ReadConfigParser(configparser.ConfigParser):
|
||||
|
||||
Attributes:
|
||||
_configdir: The directory to read the config from.
|
||||
_fname: The filename of the config.
|
||||
_configfile: The config file path.
|
||||
"""
|
||||
|
||||
@ -45,12 +46,17 @@ class ReadConfigParser(configparser.ConfigParser):
|
||||
super().__init__(interpolation=None, comment_prefixes='#')
|
||||
self.optionxform = lambda opt: opt # be case-insensitive
|
||||
self._configdir = configdir
|
||||
self._fname = fname
|
||||
self._configfile = os.path.join(self._configdir, fname)
|
||||
if not os.path.isfile(self._configfile):
|
||||
return
|
||||
log.init.debug("Reading config from {}".format(self._configfile))
|
||||
self.read(self._configfile, encoding='utf-8')
|
||||
|
||||
def __repr__(self):
|
||||
return '{}("{}", "{}")'.format(
|
||||
self.__class__.__name__, self._configdir, self._fname)
|
||||
|
||||
|
||||
class ReadWriteConfigParser(ReadConfigParser):
|
||||
|
||||
|
@ -65,6 +65,7 @@ class KeyConfigParser(QObject):
|
||||
"""
|
||||
super().__init__(parent)
|
||||
self._configdir = configdir
|
||||
self._fname = fname
|
||||
self._configfile = os.path.join(self._configdir, fname)
|
||||
self._cur_section = None
|
||||
self._cur_command = None
|
||||
@ -97,6 +98,10 @@ class KeyConfigParser(QObject):
|
||||
lines.append('')
|
||||
return '\n'.join(lines) + '\n'
|
||||
|
||||
def __repr__(self):
|
||||
return '{}("{}", "{}")'.format(
|
||||
self.__class__.__name__, self._configdir, self._fname)
|
||||
|
||||
def _str_section_desc(self, sectname):
|
||||
"""Get the section description string for sectname."""
|
||||
wrapper = textwrapper.TextWrapper()
|
||||
|
@ -35,6 +35,7 @@ class LineConfigParser:
|
||||
data: A list of lines.
|
||||
_configdir: The directory to read the config from.
|
||||
_configfile: The config file path.
|
||||
_fname: Filename of the config.
|
||||
_binary: Whether to open the file in binary mode.
|
||||
"""
|
||||
|
||||
@ -49,6 +50,7 @@ class LineConfigParser:
|
||||
"""
|
||||
self._configdir = configdir
|
||||
self._configfile = os.path.join(self._configdir, fname)
|
||||
self._fname = fname
|
||||
self._limit = limit
|
||||
self._binary = binary
|
||||
if not os.path.isfile(self._configfile):
|
||||
@ -57,6 +59,11 @@ class LineConfigParser:
|
||||
log.init.debug("Reading config from {}".format(self._configfile))
|
||||
self.read(self._configfile)
|
||||
|
||||
def __repr__(self):
|
||||
return '{}("{}", "{}", limit={}, binary={})'.format(
|
||||
self.__class__.__name__, self._configdir, self._fname, self._limit,
|
||||
self._binary)
|
||||
|
||||
def __iter__(self):
|
||||
"""Iterate over the set data."""
|
||||
return self.data.__iter__()
|
||||
|
@ -60,6 +60,9 @@ class Completer(QObject):
|
||||
self._init_static_completions()
|
||||
self._init_setting_completions()
|
||||
|
||||
def __repr__(self):
|
||||
return '<{}>'.format(self.__class__.__name__)
|
||||
|
||||
def _init_static_completions(self):
|
||||
"""Initialize the static completion models."""
|
||||
self._models[usertypes.Completion.command] = CFM(
|
||||
|
@ -36,6 +36,9 @@ class ReadlineBridge:
|
||||
def __init__(self):
|
||||
self.deleted = {}
|
||||
|
||||
def __repr__(self):
|
||||
return '<{}>'.format(self.__class__.__name__)
|
||||
|
||||
def _widget(self):
|
||||
"""Get the currently active QLineEdit."""
|
||||
w = QApplication.instance().focusWidget()
|
||||
|
@ -151,6 +151,9 @@ class ConsoleTextEdit(QTextEdit):
|
||||
self.setFont(config.get('fonts', 'debug-console'))
|
||||
self.setFocusPolicy(Qt.NoFocus)
|
||||
|
||||
def __repr__(self):
|
||||
return '<{}>'.format(self.__class__.__name__)
|
||||
|
||||
def on_config_changed(self, section, option):
|
||||
"""Update font when config changed."""
|
||||
if section == 'fonts' and option == 'debug-console':
|
||||
@ -173,6 +176,10 @@ class ConsoleWidget(QWidget):
|
||||
self.setLayout(self.vbox)
|
||||
self.lineedit.setFocus()
|
||||
|
||||
def __repr__(self):
|
||||
return '<{}, visible={}>'.format(
|
||||
self.__class__.__name__, self.isVisible())
|
||||
|
||||
@pyqtSlot(str, str)
|
||||
def on_config_changed(self, section, option):
|
||||
"""Update font when config changed."""
|
||||
|
Loading…
Reference in New Issue
Block a user