def updateDocActions(self, doc): minfo = metainfo.info(doc) if minfo.highlighting: highlighter.highlighter(doc) ac = self.actionCollection ac.view_highlighting.setChecked(minfo.highlighting) ac.tools_indent_auto.setChecked(minfo.auto_indent)
def update(block): """Retokenize the given block, saving the tokens in the UserData. You only need to call this if you immediately need the new tokens again, e.g. for more manipulations in the same moment. The tokens will automatically be updated when Qt re-enters the event loop. """ highlighter.highlighter(block.document()).rehighlightBlock(block)
def tokens(block): """Returns the tokens for the given block as a (possibly empty) tuple.""" try: return block.userData().tokens except AttributeError: highlighter.highlighter(block.document()).rehighlight() try: return block.userData().tokens except AttributeError: return ()
def state(blockOrCursor): """Returns a thawn ly.lex.State() object at the beginning of the given QTextBlock. If the argument is a QTextCursor, uses the current block or the first block of its selection. """ if isinstance(blockOrCursor, QTextCursor): block = cursortools.block(blockOrCursor) else: block = blockOrCursor if block.userState() == -1: highlighter.highlighter(block.document()).rehighlight() return highlighter.highlighter(block.document()).state(block)
def highlighting(self): self.high = not self.high if self.high: hg = highlighter(self.pro_text) hg.highlight() word_list = self.pro_text.split() tags = ["tg" + str(k) for k in range(len(word_list))] self.text.config(state=NORMAL) self.text.delete(1.0, END) for ix, word in enumerate(word_list): if any(word[:len(keyword)] == keyword for keyword in hg.keywords): self.color_text(tags[ix], word, 'blue') else: self.color_text(tags[ix], word) self.text.config(state=DISABLED) print 'Highlighting Complete' else: self.update_text(self.pro_text) return
def grep(regex, highlight, textFile, addLines): """Function mimicking grep in linux. It searches for specific text within a string and returns the lines that matches the regex or search pattern comming from input arguments. Args: - regex (String or list of strings): A single regex string, or a list of several regex strings. - highlight (boolean): True will color the text matching the regex. - textFile (str): File location as string for the text file to search within. - addLines (boolean): True will display/print which line that matches the regex. Returns: - grepText (str): A string of the grep result. """ regxAndColorsList = [] grepText = "" text = "" regxAndColorsList = list(zip(regex, range(31, 31 + len(regex)))) for lines, lineTxt in enumerate(open(textFile).readlines(), 1): line = f"\x1b[36m{lines}:\x1b[0m " fullText, matchedText, matchedTextUncolored = \ highlighter(regxAndColorsList, lineTxt) if (addLines): fullText = f"{line}{fullText}" text += fullText if (matchedText != ""): matchedText = f"{line}{matchedText}" matchedTextUncolored = f"{line}{matchedTextUncolored}" grepText += matchedText if highlight \ else matchedTextUncolored else: grepText += matchedText if highlight else matchedTextUncolored text += fullText return grepText
def __init__(self, parent=None): super(Dialog, self).__init__(parent) self._document = None self.messageLabel().setWordWrap(True) self.document = d = QTextDocument() d.setDocumentLayout(QPlainTextDocumentLayout(d)) self.highlighter = highlighter.highlighter(d) self.view = View(d) self.matcher = Matcher(self.view) self.completer = Completer(self.view) self.setMainWidget(self.view) userguide.addButton(self.buttonBox(), "musicview_editinplace") # action for completion popup self._showPopupAction = QAction(None, triggered=self.slotCompletionPopup) self.addAction(self._showPopupAction) # make Ctrl+Return accept the dialog self.button("ok").setShortcut(QKeySequence("Ctrl+Return")) qutil.saveDialogSize(self, "editinplace/dialog/size") self.accepted.connect(self.save) app.translateUI(self) app.settingsChanged.connect(self.readSettings) self.readSettings()
def __init__(self, parent=None): super(Dialog, self).__init__(parent) self._document = None self.messageLabel().setWordWrap(True) self.document = d = QTextDocument() d.setDocumentLayout(QPlainTextDocumentLayout(d)) self.highlighter = highlighter.highlighter(d) self.view = View(d) self.matcher = Matcher(self.view) self.completer = Completer(self.view) self.setMainWidget(self.view) userguide.addButton(self.buttonBox(), "musicview_editinplace") # action for completion popup self._showPopupAction = QAction(None, triggered=self.slotCompletionPopup) self.addAction(self._showPopupAction) # make Ctrl+Return accept the dialog self.button("ok").setShortcut(QKeySequence("Ctrl+Return")) qutil.saveDialogSize(self, "musicview/editinplace/dialog/size") self.accepted.connect(self.save) app.translateUI(self) app.settingsChanged.connect(self.readSettings) self.readSettings()
lang = lang_detect(txt) #print lang.text print lang.detect_language()''' # highlighter from highlighter import highlighter txt = textract.process("Short Stories/english.txt") txt = 'John likes to play badminton' hg = highlighter(txt) #print hg.txt hg.highlight() # summariser '''from summariser import * txt = textract.process("Short Stories/english2.txt") summ = summariser(txt, len(txt)/50) output = summ.summarize() print '\n\n'
def toggleHighlighting(self): doc = self.currentDocument() minfo = metainfo.info(doc) minfo.highlighting = not minfo.highlighting highlighter.highlighter(doc).setHighlighting(minfo.highlighting) self.updateOtherDocActions()
def initial_state(self): """Return the state at the beginning of the document.""" return highlighter.highlighter(self._d).initialState()
def update(block): """Retokenizes the given block, saving the tokens in the UserData.""" highlighter.highlighter(block.document()).rehighlightBlock(block)
def state(block): """Return the ly.lex.State() object at the beginning of the given QTextBlock.""" hl = highlighter.highlighter(block.document()) if block.previous().userState() == -1 and block.blockNumber() > 0: hl.rehighlight() return hl.state(block.previous())
def state_end(block): """Return the ly.lex.State() object at the end of the given QTextBlock.""" hl = highlighter.highlighter(block.document()) if block.userState() == -1: hl.rehighlight() return hl.state(block)