Exemplo n.º 1
0
 def getDeformated(self):
     raw_html = self.getHtml()
     deformated = richtext.deformat_html(raw_html,
             (richtext.KEEPIF['black-bold'], 
              richtext.KEEPIF['red-underlined-bold']))
     deformated_str = richtext.get_str_formated_true(deformated)
     return deformated_str
Exemplo n.º 2
0
    def deformat_html(self):
        raw_html = self.getHtml()
        deformated = richtext.deformat_html(
            raw_html, (richtext.KEEPIF["black-bold"], richtext.KEEPIF["red-underlined-bold"])
        )
        deformated_str = richtext.get_str_formated_true(deformated)

        selection = self.get_text_selection()
        assert len(selection) == 2

        getpos = richtext.get_position

        true_select = [
            richtext.get_position(deformated, visible_position=selection[i])[0] for i in xrange(len(selection))
        ]

        self.setText(deformated_str)
        self.set_text_selection(*true_select)
        return deformated
Exemplo n.º 3
0
    def update_formatting(self):
        self._disable_signals = True
        self.clear_error()

        rsearch_rtext = researched_richtext
        self._update = False
        # print 'Updating', time.time()
        qtpos = self.get_text_cursor_pos()  # visible pos
        # print 'Got pos', qtpos
        raw_html = self.getHtml()
        # we need to get the "True Position", i.e. the position without
        # our formats added in. I think this is the best way to do it
        deformated = richtext.deformat_html(
            raw_html, (richtext.KEEPIF["black-bold"], richtext.KEEPIF["red-underlined-bold"])
        )
        deformated_str = richtext.get_str_formated_true(deformated)

        #            assert(len(deformated_str) <= len(self.getText()))
        true_pos = richtext.get_position(deformated, visible_position=qtpos)[0]

        regexp = self.get_regexp()
        try:
            re.compile(regexp)
        except Exception as E:
            pass
        else:
            self.Replace_groups_model.set_groups(textools.get_regex_groups(regexp))

        #            import pprint
        #            pprint.pprint(self.Replace_groups_model.data)

        error = None
        # These slow it down alot and are not really useful. Just
        # display an error
        if regexp == ".":
            error = "'.' -- Matches everything, not displayed"
        elif regexp == "\w":
            error = "'\w' -- Matches all characters, not displayed"
        elif regexp == "":
            error = "'' -- Results not displayed, matches between every" " character."
        else:
            try:
                researched = textools.re_search(regexp, deformated_str)
                if len(researched) == 1 and type(researched[0]) == str:
                    error = "No Match Found"
            except re.sre_compile.error as E:
                error = str(E)
        if error:
            print error
            self.set_error(error)
            # believe it or not, setText will add formating!
            # have to explicitly set html
            self.setText(deformated_str)
            print "er setting pos", true_pos
            self.set_text_cursor_pos(true_pos, no_anchor=True)
            self._disable_signals = False
            return

        # Set the html to the correct values
        if self.Radio_match.isChecked():
            print "doing match"
            html_list = rsearch_rtext.re_search_format_html(researched)
        else:
            print "doing replace"
            rlist = self.get_replace()
            replaced = textools.re_search_replace(researched, rlist, preview=True)
            html_list = rsearch_rtext.re_search_format_html(replaced)

        raw_html = richtext.get_str_formated_html(html_list)
        self.setHtml(raw_html)

        visible_pos = richtext.get_position(html_list, true_position=true_pos)[1]
        print "new visible pos", visible_pos
        self.set_text_cursor_pos(visible_pos, no_anchor=True)

        self._researched = researched
        self._html_list = html_list
        self._disable_signals = False