From d505588720a6e5cde553d7540f62fbc374f5718a 2012-02-01 20:54:50 From: MinRK Date: 2012-02-01 20:54:50 Subject: [PATCH] protect Widget._style_sheet_changed from being called before _control exists also ensure _control attributes start out as None, rather than undefined --- diff --git a/IPython/frontend/qt/console/console_widget.py b/IPython/frontend/qt/console/console_widget.py index 3372daf..f4e7d3a 100644 --- a/IPython/frontend/qt/console/console_widget.py +++ b/IPython/frontend/qt/console/console_widget.py @@ -137,7 +137,12 @@ class ConsoleWidget(LoggingConfigurable, QtGui.QWidget): font_changed = QtCore.Signal(QtGui.QFont) #------ Protected class variables ------------------------------------------ - + + # control handles + _control = None + _page_control = None + _splitter = None + # When the control key is down, these keys are mapped. _ctrl_down_remap = { QtCore.Qt.Key_B : QtCore.Qt.Key_Left, QtCore.Qt.Key_F : QtCore.Qt.Key_Right, @@ -182,8 +187,6 @@ class ConsoleWidget(LoggingConfigurable, QtGui.QWidget): layout = QtGui.QStackedLayout(self) layout.setContentsMargins(0, 0, 0, 0) self._control = self._create_control() - self._page_control = None - self._splitter = None if self.paging in ('hsplit', 'vsplit'): self._splitter = QtGui.QSplitter() if self.paging == 'hsplit': diff --git a/IPython/frontend/qt/console/ipython_widget.py b/IPython/frontend/qt/console/ipython_widget.py index 9467c8c..969e44b 100644 --- a/IPython/frontend/qt/console/ipython_widget.py +++ b/IPython/frontend/qt/console/ipython_widget.py @@ -533,12 +533,14 @@ class IPythonWidget(FrontendWidget): """ Set the style sheets of the underlying widgets. """ self.setStyleSheet(self.style_sheet) - self._control.document().setDefaultStyleSheet(self.style_sheet) - if self._page_control: + if self._control is not None: + self._control.document().setDefaultStyleSheet(self.style_sheet) + bg_color = self._control.palette().window().color() + self._ansi_processor.set_background_color(bg_color) + + if self._page_control is not None: self._page_control.document().setDefaultStyleSheet(self.style_sheet) - bg_color = self._control.palette().window().color() - self._ansi_processor.set_background_color(bg_color) def _syntax_style_changed(self):