Fix parent/child relationships

This commit is contained in:
Florian Bruhin 2014-06-17 07:17:21 +02:00
parent 17cd86d564
commit af9e4ae072
14 changed files with 66 additions and 53 deletions

View File

@ -130,13 +130,13 @@ class Application(QApplication):
websettings.init()
quickmarks.init()
proxy.init()
self.cookiejar = CookieJar()
self.cookiejar = CookieJar(self)
self.networkmanager = NetworkManager(self.cookiejar)
self.commandmanager = CommandManager()
self.searchmanager = SearchManager()
self.downloadmanager = DownloadManager()
self.searchmanager = SearchManager(self)
self.downloadmanager = DownloadManager(self)
self.downloadmodel = DownloadModel(self.downloadmanager)
self.mainwindow = MainWindow()
self.mainwindow = MainWindow(self)
self.modeman.mainwindow = self.mainwindow
self.installEventFilter(self.modeman)
@ -162,7 +162,7 @@ class Application(QApplication):
else:
confdir = self.args.confdir
try:
self.config = ConfigManager(confdir, 'qutebrowser.conf')
self.config = ConfigManager(confdir, 'qutebrowser.conf', self)
except (config.ValidationError,
config.NoOptionError,
configparser.InterpolationError,
@ -194,7 +194,7 @@ class Application(QApplication):
'prompt': PassthroughKeyParser('keybind.prompt', self, warn=False),
'yesno': PromptKeyParser(self),
}
self.modeman = ModeManager()
self.modeman = ModeManager(self)
self.modeman.register('normal', self._keyparsers['normal'].handle)
self.modeman.register('hint', self._keyparsers['hint'].handle)
self.modeman.register('insert', self._keyparsers['insert'].handle,
@ -221,7 +221,7 @@ class Application(QApplication):
self.setOrganizationName("qutebrowser")
self.setApplicationName("qutebrowser")
self.setApplicationVersion(qutebrowser.__version__)
self.messagebridge = MessageBridge()
self.messagebridge = MessageBridge(self)
self.rl_bridge = ReadlineBridge()
def _handle_segfault(self):
@ -307,7 +307,7 @@ class Application(QApplication):
Python interpreter once all 500ms.
"""
signal(SIGINT, lambda *args: self.exit(128 + SIGINT))
timer = QTimer()
timer = QTimer(self)
timer.start(500)
timer.timeout.connect(lambda: None)
self._timers.append(timer)

View File

@ -601,7 +601,7 @@ class CommandDispatcher:
def run_userscript(self, cmd, *args):
"""Run an userscript given as argument."""
url = urlutils.urlstring(self._tabs.currentWidget().url())
runner = UserscriptRunner()
runner = UserscriptRunner(self._tabs)
runner.got_cmd.connect(self._tabs.got_cmd)
runner.run(cmd, *args, env={'QUTE_URL': url})
self._userscript_runners.append(runner)
@ -664,7 +664,7 @@ class CommandDispatcher:
if elem.isNull():
raise CommandError("No editable element focused!")
text = elem.evaluateJavaScript('this.value')
self._editor = ExternalEditor()
self._editor = ExternalEditor(self._tabs)
self._editor.editing_finished.connect(
partial(self.on_editing_finished, elem))
self._editor.edit(text)

View File

@ -29,8 +29,8 @@ class CookieJar(QNetworkCookieJar):
"""Our own cookie jar to save cookies to disk if desired."""
def __init__(self):
super().__init__()
def __init__(self, parent=None):
super().__init__(parent)
datadir = get_standard_dir(QStandardPaths.DataLocation)
self._linecp = LineConfigParser(datadir, 'cookies')
cookies = []

View File

@ -99,7 +99,7 @@ class DownloadItem(QObject):
reply.finished.connect(self.on_reply_finished)
reply.error.connect(self.on_reply_error)
reply.readyRead.connect(self.on_ready_read)
self.timer = QTimer()
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_speed)
self.timer.setInterval(self.SPEED_REFRESH_INTERVAL)
self.timer.start()
@ -347,7 +347,7 @@ class DownloadManager(QObject):
suggested_filepath = os.path.join(download_location,
suggested_filename)
logger.debug("fetch: {} -> {}".format(reply.url(), suggested_filepath))
download = DownloadItem(reply)
download = DownloadItem(reply, self)
download.finished.connect(partial(self.on_finished, download))
download.data_changed.connect(partial(self.on_data_changed, download))
download.error.connect(self.on_error)
@ -356,7 +356,7 @@ class DownloadManager(QObject):
self.downloads.append(download)
self.download_added.emit()
q = Question()
q = Question(self)
q.text = "Save file to:"
q.mode = PromptMode.text
q.default = suggested_filepath

View File

@ -53,7 +53,6 @@ class Command:
handler, completion, modes, not_modes, needs_js, debug):
# I really don't know how to solve this in a better way, I tried.
# pylint: disable=too-many-arguments
super().__init__()
self.name = name
self.split = split
self.hide = hide

View File

@ -54,8 +54,8 @@ class _BlockingFIFOReader(QObject):
got_line = pyqtSignal(str)
finished = pyqtSignal()
def __init__(self, filepath):
super().__init__()
def __init__(self, filepath, parent=None):
super().__init__(parent)
self.filepath = filepath
self.fifo = None
@ -110,8 +110,8 @@ class _BaseUserscriptRunner(QObject):
QProcess.UnknownError: "An unknown error occurred.",
}
def __init__(self):
super().__init__()
def __init__(self, parent=None):
super().__init__(parent)
self.filepath = None
self.proc = None
@ -123,7 +123,7 @@ class _BaseUserscriptRunner(QObject):
*args: The arguments to hand to the command
env: A dictionary of environment variables to add.
"""
self.proc = QProcess()
self.proc = QProcess(self)
procenv = QProcessEnvironment.systemEnvironment()
procenv.insert('QUTE_FIFO', self.filepath)
if env is not None:
@ -184,8 +184,8 @@ class _POSIXUserscriptRunner(_BaseUserscriptRunner):
thread: The QThread where reader runs.
"""
def __init__(self):
super().__init__()
def __init__(self, parent=None):
super().__init__(parent)
self.reader = None
self.thread = None
@ -200,7 +200,7 @@ class _POSIXUserscriptRunner(_BaseUserscriptRunner):
os.mkfifo(self.filepath) # pylint: disable=no-member
self.reader = _BlockingFIFOReader(self.filepath)
self.thread = QThread()
self.thread = QThread(self)
self.reader.moveToThread(self.thread)
self.reader.got_line.connect(self.got_cmd)
self.thread.started.connect(self.reader.read)
@ -247,8 +247,8 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner):
(overwrite) to write to the file!
"""
def __init__(self):
super().__init__()
def __init__(self, parent=None):
super().__init__(parent)
self.oshandle = None
def _cleanup(self):

View File

@ -163,6 +163,7 @@ class String(BaseType):
typestr = 'string'
def __init__(self, minlen=None, maxlen=None, forbidden=None, none=False):
super().__init__()
self.minlen = minlen
self.maxlen = maxlen
self.forbidden = forbidden
@ -237,6 +238,7 @@ class Int(BaseType):
typestr = 'int'
def __init__(self, minval=None, maxval=None, none=False):
super().__init__()
self.minval = minval
self.maxval = maxval
self.none = none
@ -290,6 +292,7 @@ class Float(BaseType):
typestr = 'float'
def __init__(self, minval=None, maxval=None):
super().__init__()
self.minval = minval
self.maxval = maxval
@ -321,6 +324,7 @@ class Perc(BaseType):
typestr = 'percentage'
def __init__(self, minval=None, maxval=None):
super().__init__()
self.minval = minval
self.maxval = maxval
@ -354,6 +358,7 @@ class PercList(List):
typestr = 'perc-list'
def __init__(self, minval=None, maxval=None):
super().__init__()
self.minval = minval
self.maxval = maxval
@ -385,6 +390,7 @@ class PercOrInt(BaseType):
typestr = 'percentage-or-int'
def __init__(self, minperc=None, maxperc=None, minint=None, maxint=None):
super().__init__()
self.minperc = minperc
self.maxperc = maxperc
self.minint = minint
@ -523,6 +529,7 @@ class Regex(BaseType):
typestr = 'regex'
def __init__(self, flags=0):
super().__init__()
self.flags = flags
def validate(self, value):
@ -542,6 +549,7 @@ class RegexList(List):
typestr = 'regex-list'
def __init__(self, flags=0):
super().__init__()
self.flags = flags
def transform(self, value):
@ -578,6 +586,7 @@ class Directory(BaseType):
typestr = 'directory'
def __init__(self, none=False):
super().__init__()
self.none = none
def validate(self, value):
@ -617,6 +626,7 @@ class WebKitBytes(BaseType):
typestr = 'bytes'
def __init__(self, maxsize=None):
super().__init__()
self.maxsize = maxsize
def validate(self, value):
@ -658,6 +668,7 @@ class WebKitBytesList(List):
typestr = 'bytes-list'
def __init__(self, maxsize=None, length=None):
super().__init__()
self.length = length
self.bytestype = WebKitBytes(maxsize)

View File

@ -63,21 +63,22 @@ class Completer(QObject):
def _init_command_completion(self):
"""Initialize the command completion model."""
self._models['command'] = CFM(CommandCompletionModel(self))
self._models['command'] = CFM(CommandCompletionModel(self), self)
def _init_setting_completions(self):
"""Initialize setting completion models."""
self._models['section'] = CFM(SettingSectionCompletionModel(self))
self._models['section'] = CFM(SettingSectionCompletionModel(self),
self)
self._models['option'] = {}
self._models['value'] = {}
for sectname in configdata.DATA:
model = SettingOptionCompletionModel(sectname, self)
self._models['option'][sectname] = CFM(model)
self._models['option'][sectname] = CFM(model, self)
config.instance().changed.connect(model.on_config_changed)
self._models['value'][sectname] = {}
for opt in configdata.DATA[sectname].keys():
model = SettingValueCompletionModel(sectname, opt, self)
self._models['value'][sectname][opt] = CFM(model)
self._models['value'][sectname][opt] = CFM(model, self)
config.instance().changed.connect(model.on_config_changed)
def _get_new_completion(self, parts, cursor_part):

View File

@ -77,6 +77,7 @@ def modular_question(message, mode, default=None):
q.mode = mode
q.default = default
instance().question.emit(q, True)
q.deleteLater()
return q.answer
@ -86,6 +87,7 @@ def alert(message):
q.text = message
q.mode = PromptMode.alert
instance().question.emit(q, True)
q.deleteLater()
def question(message, mode, handler, cancelled_handler=None, default=None):
@ -99,7 +101,7 @@ def question(message, mode, handler, cancelled_handler=None, default=None):
cancelled by the user, or None.
default: The default value to display.
"""
q = Question()
q = Question(instance())
q.text = message
q.mode = mode
q.default = default
@ -118,7 +120,7 @@ def confirm_action(message, yes_action, no_action=None, default=None):
no_action: Callable to be called when the user answered no.
default: True/False to set a default value, or None.
"""
q = Question()
q = Question(instance())
q.text = message
q.mode = PromptMode.yesno
q.default = default

View File

@ -46,9 +46,9 @@ class _CrashDialog(QDialog):
_crash_info: A list of tuples with title and crash information.
"""
def __init__(self):
def __init__(self, parent=None):
"""Constructor for CrashDialog."""
super().__init__()
super().__init__(parent)
self._crash_info = None
self._hbox = None
self._lbl = None
@ -79,7 +79,7 @@ class _CrashDialog(QDialog):
Should be extended by superclass to provide the actual buttons.
"""
self._hbox = QHBoxLayout()
self._hbox = QHBoxLayout(self)
self._hbox.addStretch()
self._vbox.addLayout(self._hbox)
@ -156,14 +156,14 @@ class ExceptionCrashDialog(_CrashDialog):
_exc: An exception tuple (type, value, traceback)
"""
def __init__(self, pages, cmdhist, exc):
def __init__(self, pages, cmdhist, exc, parent=None):
self._pages = pages
self._cmdhist = cmdhist
self._exc = exc
self._btn_quit = None
self._btn_restore = None
self._btn_pastebin = None
super().__init__()
super().__init__(parent)
self.setModal(True)
def _init_text(self):
@ -213,11 +213,11 @@ class FatalCrashDialog(_CrashDialog):
_btn_pastebin: The pastebin button.
"""
def __init__(self, log):
def __init__(self, log, parent=None):
self._log = log
self._btn_ok = None
self._btn_pastebin = None
super().__init__()
super().__init__(parent)
def _init_text(self):
super()._init_text()

View File

@ -52,7 +52,7 @@ class DownloadView(QListView):
self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
self.setFlow(QListView.LeftToRight)
self._menu = None
self._model = DownloadModel()
self._model = DownloadModel(self)
self._model.rowsInserted.connect(self.updateGeometry)
self._model.rowsRemoved.connect(self.updateGeometry)
self.setModel(self._model)
@ -71,7 +71,7 @@ class DownloadView(QListView):
if not index.isValid():
return
item = self.model().data(index, Role.item)
self._menu = QMenu()
self._menu = QMenu(self)
cancel = self._menu.addAction("Cancel")
cancel.triggered.connect(item.cancel)
self._menu.popup(self.viewport().mapToGlobal(point))

View File

@ -48,8 +48,8 @@ class MainWindow(QWidget):
_vbox: The main QVBoxLayout.
"""
def __init__(self):
super().__init__()
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle('qutebrowser')
try:

View File

@ -120,21 +120,21 @@ class StatusBar(QWidget):
self._hbox.setContentsMargins(0, 0, 0, 0)
self._hbox.setSpacing(5)
self._stack = QStackedLayout()
self._stack = QStackedLayout(self)
self._stack.setContentsMargins(0, 0, 0, 0)
self.cmd = Command(self)
self.cmd = Command()
self._stack.addWidget(self.cmd)
self.txt = Text(self)
self.txt = Text()
self._stack.addWidget(self.txt)
self._timer_was_active = False
self._text_queue = deque()
self._text_pop_timer = QTimer()
self._text_pop_timer = QTimer(self)
self._text_pop_timer.setInterval(config.get('ui', 'message-timeout'))
self._text_pop_timer.timeout.connect(self._pop_text)
self.prompt = Prompt(self)
self.prompt = Prompt()
self._stack.addWidget(self.prompt)
self.cmd.show_cmd.connect(self._show_cmd_widget)
@ -146,16 +146,16 @@ class StatusBar(QWidget):
self._hbox.addLayout(self._stack)
self.keystring = KeyString(self)
self.keystring = KeyString()
self._hbox.addWidget(self.keystring)
self.url = Url(self)
self.url = Url()
self._hbox.addWidget(self.url)
self.percentage = Percentage(self)
self.percentage = Percentage()
self._hbox.addWidget(self.percentage)
self.prog = Progress(self)
self.prog = Progress()
self._hbox.addWidget(self.prog)
def __repr__(self):

View File

@ -197,7 +197,7 @@ class Prompt(QWidget):
Return:
The answer to the question. No, it's not always 42.
"""
loop = EventLoop()
loop = EventLoop(self)
self.loops.append(loop)
loop.destroyed.connect(lambda: self.loops.remove(loop))
self.question.answered.connect(loop.quit)