Ejemplo n.º 1
0
 def test_dfs_before(self):
     g = self.make_linear(10)
     inc = []
     dec = []
     def before(id): inc.append(id)
     def after(id): dec.append(id)
     g.dfs(enter_vertex=before,
           leave_vertex=after)
     assert inc == [0,1,2,3,4,5,6,7,8,9]
     assert inc == list(reversed(dec))
     assert all(a < b for a, b in izip(inc[:-1], inc[1:]))
     assert all(a > b for a, b in izip(dec[:-1], dec[1:]))
Ejemplo n.º 2
0
    def test_dfs_before(self):
        g = self.make_linear(10)
        inc = []
        dec = []

        def before(id):
            inc.append(id)

        def after(id):
            dec.append(id)

        g.dfs(enter_vertex=before, leave_vertex=after)
        assert inc == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
        assert inc == list(reversed(dec))
        assert all(a < b for a, b in izip(inc[:-1], inc[1:]))
        assert all(a > b for a, b in izip(dec[:-1], dec[1:]))
Ejemplo n.º 3
0
 def trim_first_paragraph(self):
     doc = self.document()
     count = doc.blockCount()
     cursor = QtGui.QTextCursor(doc)
     cursor.select(QtGui.QTextCursor.LineUnderCursor)
     sel = cursor.selection().toPlainText()
     if all(c == ' ' for c in sel):
         cursor.removeSelectedText()
         cursor = QtGui.QTextCursor(doc)
         cursor.deleteChar()
Ejemplo n.º 4
0
 def trim_first_paragraph(self):
     doc = self.document()
     count = doc.blockCount()
     cursor = QtGui.QTextCursor(doc)
     cursor.select(QtGui.QTextCursor.LineUnderCursor)
     sel = cursor.selection().toPlainText()
     if all(c == ' ' for c in sel):
         cursor.removeSelectedText()
         cursor = QtGui.QTextCursor(doc)
         cursor.deleteChar()
Ejemplo n.º 5
0
            def evaluate(i):
                try:
                    v = d['value'](i)
                    if v == None:
                        return module.default_value
                    return v
                except Exception, e:
                    debug.unexpected_exception(e)
                    return debug.format_exception(e)

            return [evaluate(i) for i in xrange(self.size)]

        result = get()

        if not all(module.validate(x) for x in result):
            show_warning(
                'Failed Validation', 'One of the <i>%s</i>\'s user defined '
                'functions has failed validation, '
                'which usually means it generated a '
                'value of a type different '
                'than that specified by the '
                'parameter. Parameter Exploration '
                'aborted.' % param_info.spec.descriptor.name)
            return None
        return result

    def getValuesString(self):
        """ getValuesString() -> str
        Return a string representation of the parameter list
        
Ejemplo n.º 6
0
                exec(self.function) in {}, d
            except Exception, e:
                return [module.default_value] * count
            def evaluate(i):
                try:
                    v = d['value'](i)
                    if v is None:
                        return module.default_value
                    return v
                except Exception, e:
                    debug.unexpected_exception(e)
                    return debug.format_exception(e)
            return [evaluate(i) for i in xrange(self.size)]
        result = get()
        
        if not all(module.validate(x) for x in result):
            show_warning('Failed Validation',
                         'One of the <i>%s</i>\'s user defined '
                         'functions has failed validation, '
                         'which usually means it generated a '
                         'value of a type different '
                         'than that specified by the '
                         'parameter. Parameter Exploration '
                         'aborted.' % param_info.spec.descriptor.name)
            return None
        return result
        

    def getValuesString(self):
        """ getValuesString() -> str
        Return a string representation of the parameter list
Ejemplo n.º 7
0
    def keyPressEvent(self, e):
        """keyPressEvent(e) -> None
        Handle user input a key at a time.

        Notice that text might come more than one keypress at a time
        if user is a fast enough typist!
        
        """
        text  = e.text()
        key   = e.key()

        # NB: Sometimes len(str(text)) > 1!
        if len(text) and all(ord(x) >= 32 and
                             ord(x) < 127
                             for x in str(text)):
        # exit select mode and jump to end of text
            cursor = self.textCursor()
            if self.selectMode or cursor.hasSelection():
                self.selectMode = False
                cursor.movePosition(QtGui.QTextCursor.End)
                cursor.clearSelection()
                self.setTextCursor(cursor)
            self.__insertText(text)
            return
 
        if e.modifiers() & QtCore.Qt.MetaModifier and key == self.eofKey:
            self.parent().closeSession()
        
        if e.modifiers() & QtCore.Qt.ControlModifier:
            if key == QtCore.Qt.Key_C or key == QtCore.Qt.Key_Insert:
                self.copy()
            elif key == QtCore.Qt.Key_V:
                cursor = self.textCursor()
                cursor.movePosition(QtGui.QTextCursor.End)
                cursor.clearSelection()
                self.setTextCursor(cursor)
                self.paste()
            elif key == QtCore.Qt.Key_A:
                self.selectAll()
                self.selectMode = True
            else:
                e.ignore()
            return

        if e.modifiers() & QtCore.Qt.ShiftModifier:
            if key == QtCore.Qt.Key_Insert:
                cursor = self.textCursor()
                cursor.movePosition(QtGui.QTextCursor.End)
                cursor.clearSelection()
                self.setTextCursor(cursor)
                self.paste()
            else:
                e.ignore()
            return

        # exit select mode and jump to end of text
        cursor = self.textCursor()
        if self.selectMode or cursor.hasSelection():
            self.selectMode = False
            cursor.movePosition(QtGui.QTextCursor.End)
            cursor.clearSelection()
            self.setTextCursor(cursor)

        if key == QtCore.Qt.Key_Backspace:
            if self.point:
                QtGui.QTextEdit.keyPressEvent(self, e)
                self.point -= 1
                self.line = self.line[:self.point] + self.line[self.point+1:]
        elif key == QtCore.Qt.Key_Delete:
            QtGui.QTextEdit.keyPressEvent(self, e)
            self.line = self.line[:self.point] + self.line[self.point+1:]
        elif key == QtCore.Qt.Key_Return or key == QtCore.Qt.Key_Enter:
            if self.reading:
                self.reading = 0
            else:
                self.__run()
        elif key == QtCore.Qt.Key_Tab:
            self.__insertText(text)
        elif key == QtCore.Qt.Key_Left:
            if self.point:
                QtGui.QTextEdit.keyPressEvent(self, e)
                self.point -= 1
        elif key == QtCore.Qt.Key_Right:
            if self.point < len(self.line):
                QtGui.QTextEdit.keyPressEvent(self, e)
                self.point += 1
        elif key == QtCore.Qt.Key_Home:
            cursor = self.textCursor()
            cursor.movePosition(QtGui.QTextCursor.StartOfLine)
            cursor.setPosition(cursor.position() + 4)
            self.setTextCursor(cursor)
            self.point = 0
        elif key == QtCore.Qt.Key_End:
            QtGui.QTextEdit.keyPressEvent(self, e)
            self.point = len(self.line)
        elif key == QtCore.Qt.Key_Up:
            if len(self.history):
                if self.pointer == 0:
                    self.pointer = len(self.history)
                self.pointer -= 1
                self.__recall()
        elif key == QtCore.Qt.Key_Down:
            if len(self.history):
                self.pointer += 1
                if self.pointer == len(self.history):
                    self.pointer = 0
                self.__recall()
        else:
            e.ignore()