示例#1
0
def create_paragraph(file_lines):
    #Create a "Paragraph" object to hold all text from the file
    paragraph = Paragraph()
    #Text in the paragraph will have a font size of 16
    paragraph.FontSize = 16.0

    #Go through every line in the file passed in from the command
    #line...
    for x in file_lines:
        #...looking for Python/Ruby/PowerShell style comments
        if "#" in x:

            #Split the line whenever a comment is found
            first, second = x.split("#", 1)

            #Add the first part of the line to the paragraph
            paragraph.Inlines.Add(Run(first + "#"))

            #Split the second part of the line based on whitespace
            for y in second.split():
                #If the word is misspelled...
                if not check_word(y):
                    #Add a drop down menu to offer alternative
                    #spelling suggestions
                    c = ComboBox()
                    c.Background = Red
                    c.HorizontalAlignment = HorizontalAlignment.Left
                    #Add the misspelled word to the drop down menu
                    #and make is the first item
                    c.AddText(y)
                    c.SelectedItem = y
                    #Offer alternative spellings in the drop down menu
                    for suggest in suggestions(y):
                        c.AddText(suggest)
                    #Add the combo box to the drop down menu
                    paragraph.Inlines.Add(c)
                else:
                    paragraph.Inlines.Add(Run(y))
                paragraph.Inlines.Add(" ")
            paragraph.Inlines.Add(Run("\n"))
        else:
            #If there's no comment in the line, just directly
            #add it to the paragraph
            paragraph.Inlines.Add(Run(x))
    return paragraph
示例#2
0
def create_paragraph(file_lines):
    #Create a "Paragraph" object to hold all text from the file
    paragraph = Paragraph()
    #Text in the paragraph will have a font size of 16
    paragraph.FontSize = 16.0

    #Go through every line in the file passed in from the command
    #line...
    for x in file_lines:
        #...looking for Python/Ruby/PowerShell style comments
        if "#" in x:

            #Split the line whenever a comment is found
            first, second = x.split("#", 1)

            #Add the first part of the line to the paragraph
            paragraph.Inlines.Add(Run(first + "#"))
            
            #Split the second part of the line based on whitespace
            for y in second.split():
                #If the word is misspelled...
                if not check_word(y):
                    #Add a drop down menu to offer alternative
                    #spelling suggestions
                    c = ComboBox()
                    c.Background = Red
                    c.HorizontalAlignment = HorizontalAlignment.Left
                    #Add the misspelled word to the drop down menu
                    #and make is the first item
                    c.AddText(y)
                    c.SelectedItem = y
                    #Offer alternative spellings in the drop down menu
                    for suggest in suggestions(y):
                        c.AddText(suggest)
                    #Add the combo box to the drop down menu
                    paragraph.Inlines.Add(c)
                else:
                    paragraph.Inlines.Add(Run(y))
                paragraph.Inlines.Add(" ")
            paragraph.Inlines.Add(Run("\n"))
        else:
            #If there's no comment in the line, just directly
            #add it to the paragraph
            paragraph.Inlines.Add(Run(x))
    return paragraph