Example #1
0
        def __init__(self, text='', comment_prefix='#', parent=None, **kwargs):
            """
            Initialize.
            :param text: initial text.
            :param parent: parent widget.
            :param kwargs: arguments for LoggingConfigurable
            :return:
            """
            edit_class.__init__(self, text, parent)
            DocumentConfig.__init__(self, **kwargs)

            self.setFrameStyle(QtGui.QFrame.NoFrame)

            self.viewport_filter = ViewportFilter(self)
            self.viewport().installEventFilter(self.viewport_filter)
            self.entry_filter = ChatAreaFilter(self)
            self.installEventFilter(self.entry_filter)
            self.text_area_filter = TextAreaFilter(self)
            self.installEventFilter(self.text_area_filter)

            self.setAcceptDrops(True)

            # self.entry_filter = ChatAreaFilter(self)
            # self.installEventFilter(self.entry_filter)

            # Text interaction
            self.setTextInteractionFlags(QtCore.Qt.TextEditable | QtCore.Qt.TextEditorInteraction)
            self.setUndoRedoEnabled(True)
            self._comment_prefix = comment_prefix
Example #2
0
        def __init__(self, is_complete=None, text='', use_ansi=True, comment_prefix='#',
                     parent=None, **kwargs):
            """
            Initialize.
            :param is_complete: function str->(bool, str) that checks whether the input is complete code
            :param code: True if object should initially expect code to be executed; otherwise arbitrary text.
            :param text: initial text.
            :param parent: parent widget.
            :param kwargs: arguments for LoggingConfigurable
            :return:
            """
            edit_class.__init__(self, text, parent)
            DocumentConfig.__init__(self, **kwargs)

            self.use_ansi = use_ansi
            self.highlighter.enable()

            # Call tips
            # forcefully disable calltips if PySide is < 1.0.7, because they crash
            if QT_API == QT_API_PYSIDE:
                import PySide
                if PySide.__version_info__ < (1,0,7):
                    self.log.warn("PySide %s < 1.0.7 detected, disabling calltips" % PySide.__version__)
                    self.enable_call_tips = False
            self.call_tip_widget = CallTipWidget(self)
            self.call_tip_widget.setFont(self.font)
            self.font_changed.connect(self.call_tip_widget.setFont)

            self._bracket_matcher = BracketMatcher(self)
            self.document().contentsChange.connect(self._document_contents_change)

            self.setFrameStyle(QtGui.QFrame.NoFrame)

            self.setAcceptDrops(True)

            self._control = self  # required for completer
            self._clear_temporary_buffer = lambda: None
            self.completer = CompletionWidget(self)
            self.completer.setFont(self.font)
            self.is_complete = is_complete

            self.viewport_filter = ViewportFilter(self)
            self.viewport().installEventFilter(self.viewport_filter)
            self.entry_filter = CodeAreaFilter(self)
            self.installEventFilter(self.entry_filter)
            self.text_area_filter = TextAreaFilter(self)
            self.installEventFilter(self.text_area_filter)

            # Text interaction
            self.setTextInteractionFlags(QtCore.Qt.TextEditable | QtCore.Qt.TextEditorInteraction)
            self.setUndoRedoEnabled(True)
            self.kill_ring = QtKillRing(self)
            self.history = History(self)
            self._comment_prefix = comment_prefix
Example #3
0
        def __init__(self, text='', use_ansi=True, show_users=False, parent=None, **kwargs):
            """
            Initialize.
            :param text: initial text.
            :param use_ansi: whether to use ansi codes in output.
            :param show_users: whether to show user names in command listings.
            :param parent: parent widget.
            :return:
            """
            edit_class.__init__(self, text, parent)
            DocumentConfig.__init__(self, **kwargs)

            self.use_ansi = use_ansi
            self.text_register = TextRegister(self, visible=show_users)

            # Setting a positive maximum block count will automatically
            # disable the undo/redo history
            self.document().setMaximumBlockCount(self.max_blocks)
            self.output_q = Queue()
            self.timing_guard = QtCore.QSemaphore()
            self._out_buffer = OutBuffer(self, self)
            self._out_buffer.item_ready.connect(self.on_item_ready)
            self._out_buffer.start()

            self.show_banner = QtCore.QSemaphore(1)

            self.setAcceptDrops(True)

            self.viewport_filter = ViewportFilter(self)
            self.viewport().installEventFilter(self.viewport_filter)
            self.receiver_filter = ReceiverFilter(self)
            self.installEventFilter(self.receiver_filter)
            self.text_area_filter = TextAreaFilter(self)
            self.installEventFilter(self.text_area_filter)

            # Text interaction
            self.setReadOnly(True)
            self.setTextInteractionFlags(
                QtCore.Qt.TextSelectableByMouse |
                QtCore.Qt.TextSelectableByKeyboard |
                QtCore.Qt.LinksAccessibleByMouse |
                QtCore.Qt.LinksAccessibleByKeyboard)
Example #4
0
        def __init__(self, locations, initial_location, text='', use_ansi=True, parent=None, **kwargs):
            """
            Initialize pager.
            :param locations: Possible pager locations,
                                list of pairs (location, {'target': QSplitter or QStackedLayout, 'index': Integer}),
                                where location is Enum('top', 'inside', 'right') indicating the loation of the pager,
                                target is the container where the pager is placed and index is its index in the
                                container.
            :param text: To initialize the pager with.
            :param parent: Parent widget.
            :param kwargs: Passed to LoggingConfigurable.
            :return:
            """
            QtGui.QTextEdit.__init__(self, text, parent)
            DocumentConfig.__init__(self, use_ansi, **kwargs)

            self._locations = dict(locations)
            self.location = initial_location
            self.document().setMaximumBlockCount(0)

            # While scrolling the pager on Mac OS X, it tears badly.  The
            # NativeGesture is platform and perhaps build-specific hence
            # we take adequate precautions here.
            self.pager_scroll_events = [QtCore.QEvent.Wheel]
            if hasattr(QtCore.QEvent, 'NativeGesture'):
                self.pager_scroll_events.append(QtCore.QEvent.NativeGesture)

            self.viewport_filter = ViewportFilter(self)
            self.viewport().installEventFilter(self.viewport_filter)
            self.pager_filter = PagerFilter(self)
            self.installEventFilter(self.pager_filter)
            self.text_area_filter = TextAreaFilter(self)
            self.installEventFilter(self.text_area_filter)

            # Text interaction
            self.setReadOnly(True)
            self.setTextInteractionFlags(
                QtCore.Qt.TextSelectableByMouse |
                QtCore.Qt.TextSelectableByKeyboard |
                QtCore.Qt.LinksAccessibleByMouse |
                QtCore.Qt.LinksAccessibleByKeyboard)
Example #5
0
 def _set_font(self, font):
     DocumentConfig.set_font(self, font)
     if hasattr(self, 'completer') and self.completer:
         self.completer.setFont(font)
     self.font_changed.emit(font)