##// END OF EJS Templates
Backport PR #2294: inputhook_qt4: Use QEventLoop instead of starting up the QCoreApplication...
Backport PR #2294: inputhook_qt4: Use QEventLoop instead of starting up the QCoreApplication I referenced this branch in #2080 and was letting it sit for a little while, but I have decided to make it a full pull request to get some additional visibility. Essentially our Qt event loop mechanism repeatedly starts and quits a `QCoreApplication` object. Unfortunately the `QCoreApplication::quit` slot has a lot of unintended side effects (like emitting an `aboutToQuit` signal which closes all open file dialogs). For our input hook, we _might_ be able to get by with just using a `QEventLoop` whose quit slot is much simpler and less destructive. For a little bit of background on why one might want to just use `QEventLoop::exec`, let's examine what `QCoreApplication::exec` does: ```c++ int QCoreApplication::exec() { if (!QCoreApplicationPrivate::checkInstance("exec")) return -1; // ... [some assertions] threadData->quitNow = false; QEventLoop eventLoop; self->d_func()->in_exec = true; self->d_func()->aboutToQuitEmitted = false; int returnCode = eventLoop.exec(); threadData->quitNow = false; if (self) { self->d_func()->in_exec = false; if (!self->d_func()->aboutToQuitEmitted) emit self->aboutToQuit(); self->d_func()->aboutToQuitEmitted = true; sendPostedEvents(0, QEvent::DeferredDelete); } return returnCode; } ``` As far as I can tell, it's a small wrapper around `QEventLoop::exec` which also: * Sets some variables regarding the current status * Emits an `aboutToQuit` signal right before the function returns (which is the root cause of @denisri's problem in #2080). Historically, our Qt event loop is a python implementation of the (win 32) input hook supplied with the PyQt4 source (see qtcore_input_hook` in `python-qt4/sip/QtCore/qcoreapplication.sip`), which more or less dates to a [mailing list post](http://www.riverbankcomputing.com/pipermail/pyqt/2007-July/016512.html) from July 2007.

File last commit:

r7339:d980adfb
r9834:71196839
Show More
pager.js
130 lines | 4.4 KiB | application/javascript | JavascriptLexer
//----------------------------------------------------------------------------
// Copyright (C) 2008-2011 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
//============================================================================
// Pager
//============================================================================
var IPython = (function (IPython) {
var utils = IPython.utils;
var Pager = function (pager_selector, pager_splitter_selector) {
this.pager_element = $(pager_selector);
var that = this;
this.percentage_height = 0.40;
this.pager_splitter_element = $(pager_splitter_selector)
.draggable({
containment: 'window',
axis:'y',
helper: null ,
drag: function(event, ui) {
// recalculate the amount of space the pager should take
var pheight = ($(body).height()-event.clientY-4);
var downprct = pheight/IPython.layout_manager.app_height();
downprct = Math.min(0.9, downprct);
if (downprct < 0.1) {
that.percentage_height = 0.1;
that.collapse({'duration':0});
} else if (downprct > 0.2) {
that.percentage_height = downprct;
that.expand({'duration':0});
}
IPython.layout_manager.do_resize();
}
});
this.expanded = false;
this.style();
this.bind_events();
};
Pager.prototype.style = function () {
this.pager_splitter_element.addClass('border-box-sizing ui-widget ui-state-default');
this.pager_element.addClass('border-box-sizing ui-widget');
this.pager_splitter_element.attr('title', 'Click to Show/Hide pager area, drag to Resize');
};
Pager.prototype.bind_events = function () {
var that = this;
this.pager_element.bind('collapse_pager', function (event, extrap) {
time = (extrap != undefined) ? ((extrap.duration != undefined ) ? extrap.duration : 'fast') : 'fast';
that.pager_element.hide(time);
});
this.pager_element.bind('expand_pager', function (event, extrap) {
time = (extrap != undefined) ? ((extrap.duration != undefined ) ? extrap.duration : 'fast') : 'fast';
that.pager_element.show(time);
});
this.pager_splitter_element.hover(
function () {
that.pager_splitter_element.addClass('ui-state-hover');
},
function () {
that.pager_splitter_element.removeClass('ui-state-hover');
}
);
this.pager_splitter_element.click(function () {
that.toggle();
});
$([IPython.events]).on('open_with_text.Pager', function (event, data) {
if (data.text.trim() !== '') {
that.clear();
that.expand();
that.append_text(data.text);
};
});
};
Pager.prototype.collapse = function (extrap) {
if (this.expanded === true) {
this.expanded = false;
this.pager_element.add($('div#notebook')).trigger('collapse_pager', extrap);
};
};
Pager.prototype.expand = function (extrap) {
if (this.expanded !== true) {
this.expanded = true;
this.pager_element.add($('div#notebook')).trigger('expand_pager', extrap);
};
};
Pager.prototype.toggle = function () {
if (this.expanded === true) {
this.collapse();
} else {
this.expand();
};
};
Pager.prototype.clear = function (text) {
this.pager_element.empty();
};
Pager.prototype.append_text = function (text) {
var toinsert = $("<div/>").addClass("output_area output_stream");
toinsert.append($('<pre/>').html(utils.fixCarriageReturn(utils.fixConsole(text))));
this.pager_element.append(toinsert);
};
IPython.Pager = Pager;
return IPython;
}(IPython));