[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] [PYQT] Increse the regex in QtCore.QRegExp
From:       Maziar Parsijani <maziar.parsijani () gmail ! com>
Date:       2018-09-16 7:59:30
Message-ID: CAPD04aPaZX+97q0km0F0syOGo_cVJag-822XU8yBbVmrjEhEqw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Michael,
I attached an example file on this post,But I summarized the part that I
want to work on it.I retrieve data from sqlite and set it into textedit and
here I have just added 2 strings in it.for addition I have to say my data
is Arabic text.before this I have found a way to compile the exact thing to
highlight but now the problem is the low speed with more data.
Thanks for your advice about profiling codes.

On Sun, Sep 16, 2018 at 8:00 AM michael h <michaelkenth@gmail.com> wrote:

> doc.setDefaultStyleSheet(<span class="highlight">found</span>)
>>
>> This is where the css rules go, not the html
>
>> doc.setHtml()
>>
>> this would be where you set the html
>
>
> Aside from that:
>
> - Profile the code because the issue may not be where you expect it
> - You might look into using QSyntaxHighlighter, which would allow you to
> highlight without inserting HTML markup.
> - If you could post a self contained runnable example I'd take a closer
> look
>

[Attachment #5 (text/html)]

<div dir="ltr"><div dir="ltr"><div>Hi Michael,<br></div><div>I attached an example \
file on this post,But I summarized the part that I want to work on it.I retrieve data \
from sqlite and set it into textedit and here I have just added 2 strings in it.for \
addition I have to say my data is Arabic text.before this I have found a way to \
compile the exact thing to highlight but now the problem is the low speed with more \
data. <br></div><div>Thanks for your advice about profiling \
codes.<br></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Sep \
16, 2018 at 8:00 AM michael h &lt;<a \
href="mailto:michaelkenth@gmail.com">michaelkenth@gmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div \
class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div \
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div \
dir="ltr"><div dir="ltr"><pre \
style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:&quot;DejaVu \
Sans Mono&quot;;font-size:9.1pt">doc.setDefaultStyleSheet(<font face="monospace, \
monospace">&lt;span class=&quot;highlight&quot;&gt;found&lt;/span&gt;</font>)<br><code><span \
class="m_-7225432585895105533m_2058158689121283743gmail-pln"></span></code></pre></div></div></div></div></div></div></div></div></div></blockquote><div>This \
is where the css rules go, not the html</div><blockquote class="gmail_quote" \
style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div \
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div \
dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><pre \
style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:&quot;DejaVu \
Sans Mono&quot;;font-size:9.1pt"><code><span \
class="m_-7225432585895105533m_2058158689121283743gmail-pln">doc</span><span \
class="m_-7225432585895105533m_2058158689121283743gmail-pun">.</span><span \
class="m_-7225432585895105533m_2058158689121283743gmail-pln">setHtml()<br></span></cod \
e><br></pre></div></div></div></div></div></div></div></div></div></blockquote><div>this \
would be where you set the html</div><div><br></div><div><br></div><div>Aside from \
that:</div><div><br></div><div>- Profile the code because the issue may not be where \
you expect it</div><div>- You might look into using QSyntaxHighlighter, which would \
allow you to highlight without inserting HTML markup.</div><div>- If you could post a \
self contained runnable example I&#39;d take a closer look<br></div></div></div> \
</blockquote></div>


["example.py" (text/x-python)]

import sys
from PyQt5.QtWidgets import QDialog, QApplication
from PyQt5 import QtCore, QtGui, QtWidgets
class AppWindow(QDialog):
    def __init__(self):
        super().__init__()
        self.setObjectName("Dialog")
        self.resize(800, 600)
        self.lineEdit = QtWidgets.QLineEdit(self)
        self.lineEdit.setGeometry(QtCore.QRect(70, 70, 211, 21))
        self.lineEdit.setObjectName("lineEdit")
        self.pushButton = QtWidgets.QPushButton(self)
        self.pushButton.setGeometry(QtCore.QRect(130, 110, 83, 28))
        self.pushButton.setObjectName("pushButton")
        self.SearchResults = QtWidgets.QTextEdit(self)
        self.SearchResults.setGeometry(QtCore.QRect(50, 140, 700, 400))
        font = QtGui.QFont()
        font.setFamily("Amiri")
        font.setPointSize(12)
        self.SearchResults.setFont(font)
        self.SearchResults.setToolTipDuration(0)
        self.SearchResults.setReadOnly(True)
        self.SearchResults.setAutoFormatting(QtWidgets.QTextEdit.AutoAll)
        self.SearchResults.setObjectName("SearchResults")

        doc = QtGui.QTextDocument()
        doc.setHtml("")
        doc.setDefaultStyleSheet("")
        self.SearchResults.setDocument(doc)

        self.retranslateUi(self)
        QtCore.QMetaObject.connectSlotsByName(self)


        self.SearchResults.append("وَسِعْتُ كِتابَ اللَّهِ \
                لفظـــاً وَحِكمَــــةً")
        self.SearchResults.append("وَتَنسيـــقُ أسمــاءٍ \
لِمُخْتَرَعــــاتِ")

    def find1(self):
        cursor = self.SearchResults.textCursor()
        format = QtGui.QTextCharFormat()
        format.setBackground(QtGui.QBrush(QtGui.QColor("red")))
#        pp = self.m
        pattern1 = r'\b(?:{})\b'.format(self.lineEdit.text())
        regex = QtCore.QRegExp(pattern1)
        pos = 0
        index = regex.indexIn(self.SearchResults.toPlainText(), pos)
        tedad = 0
        while (index != -1):
            cursor.beginEditBlock()
            cursor.setPosition(index)
            cursor.movePosition(QtGui.QTextCursor.NextWord, \
QtGui.QTextCursor.KeepAnchor, 1)  cursor.endEditBlock()
            cursor.mergeCharFormat(format)
            pos = index + regex.matchedLength()
            index = regex.indexIn(self.SearchResults.toPlainText(), pos)


    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        self.setWindowTitle(_translate("Dialog", "Dialog"))
        self.pushButton.setText(_translate("Dialog", "PushButton"))

        self.pushButton.clicked.connect(self.find1)
app = QApplication(sys.argv)
w = AppWindow()
w.show()
sys.exit(app.exec_())


[Attachment #7 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic