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

List:       pykde
Subject:    Re: [PyQt] Here are some images... what widgets should I base the app around?
From:       "Jones, Bryan" <bjones () ece ! msstate ! edu>
Date:       2015-12-16 3:00:37
Message-ID: CAHhYbD9-hWy2psrX3wwvLWeUDS4Nqbe_=PKxr1i7JF+A6wC6=g () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


As an example of what can be done by extending a QTextEdit, see the
qutepart widget [1]. This is the core of the Enki editor [2], a good way to
see qutepart in action.

Bryan

[1] https://github.com/hlamer/qutepart
[2] http://enki-editor.org

On Tue, Dec 15, 2015 at 8:15 PM, David Cortesi <davecortesi@gmail.com>
wrote:

>
>
> Date: Tue, 15 Dec 2015 11:49:01 -0800
>> From: Brian Merchant <bhmerchant@gmail.com>
>> To: pyqt@riverbankcomputing.com
>> Subject: [PyQt]
>>
>
>
>> I have made some images to demo a text-editor like app I'd like to make;
>> http://imgur.com/a/2OKph
>>
>> Some features are very familiar: type text to enter it, auto-complete
>> boxes, etc
>
>
> Things like this -- dynamic behavior based on the user's keystrokes in the
> context of the text near the insertion point -- is done using a
> QSyntaxHighlighter [1].
>
> The main use of this is to highlight the different classes of tokens as
> the user types them. For a simple example, to put a wavy red line
> underneath a word that fails spellcheck. Or to make a keyword one color and
> a variable a different color. Obviously this requires close linkage between
> the user's keystrokes and the highlighter. The user types "fro" and that's
> a spelling error, underline it; then the next keystroke is "g" and now it
> is not a spelling error, clear the underline.
>
> The relationship between a QSyntaxHighlighter and an editor is not well
> explained in the doc. The Qt design is to make a syntax highlighter a
> separate object from the editor, I suppose so that you could design it
> separately, and apply one highlighter to multiple different text edit
> widgets. Anyway you subclass QSyntaxHighlighter and specify its behaviors
> by implementing .highlightBlock().
>
> You apply a highlighter, making the highlights appear, by calling its
> .setDocument() method, passing a QTextDocument. At this moment, the
> highlightBlock() method is called for every existing line (or maybe only
> the visible lines?). From then on, highlightBlock() is called for the line
> with the insertion point whenever a character changes. To remove
> highlighting, call its .setDocument() passing None.
>
> I think using this you could implement your auto suggestion dropdown.
> Although I couldn't say how to figure out the x/y coordinates of the
> insertion point to locate the menu.
>
>
>> Some features are not so familiar: you can drag and drop some elements of
>> the text to "flip" their position, some keywords are automatically
>> converted into symbols when typed, and so on
>
>
> Qt's edit widgets (PlainTextEdit and TextEdit) support drag/drop of
> selected text, complete with a nice transparent overlay of the dragged text
> and moving insertion point to show where it will drop. You want to
> implement this but make it behave based on lexical units, not merely based
> on character-by-character moves. Read carefully through the QTextEdit doc
> [2] about drag/drop of mime types. You might be able to,
>
> 1. Select the current lexical unit
> 2. Cut it
> 3. Make it a mime package
> 4. Start a drag/drop
> 5. Let Qt do its thing
> 6. Override the QTextEdit dragMoveEvent() to highlight lexical units under
> the cursor showing where the dragged mime unit can legally go
> 6. Override the QTextEdit dropEvent() to refuse to drop in an illegal
> place, and to animate moving lexical units around when it's legal.
>
> However I have done some experiments with QDrag [3] and friends and found
> it a very difficult API to work with.
>
>
>> My plan is to use PyQt4.
>>
>
> Why?!? We are a couple of years into the Qt5 release after all.
>
> Cheers,
> Dave Cortesi
>
> [1] http://doc.qt.io/qt-5/qsyntaxhighlighter.html
>
> [2] http://doc.qt.io/qt-5/qtextedit.html#details
>
> [3] http://doc.qt.io/qt-5/qdrag.html
>



-- 
Bryan A. Jones, Ph.D.
Associate Professor
Department of Electrical and Computer Engineering
231 Simrall / PO Box 9571
Mississippi State University
Mississippi state, MS 39762
http://www.ece.msstate.edu/~bjones
bjones AT ece DOT msstate DOT edu
voice 662-325-3149
fax 662-325-2298

Our Master, Jesus Christ, is on his way. He'll show up right on
time, his arrival guaranteed by the Blessed and Undisputed Ruler,
High King, High God.
- 1 Tim. 6:14b-15 (The Message)

[Attachment #5 (text/html)]

<div dir="ltr">As an example of what can be done by extending a QTextEdit, see the \
qutepart widget [1]. This is the core of the Enki editor [2], a good way to see \
qutepart in action.<div><br></div><div>Bryan</div><div><br></div><div>[1]  <a \
href="https://github.com/hlamer/qutepart">https://github.com/hlamer/qutepart</a></div><div>[2] \
<a href="http://enki-editor.org">http://enki-editor.org</a><br><div \
class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 15, 2015 at 8:15 PM, \
David Cortesi <span dir="ltr">&lt;<a href="mailto:davecortesi@gmail.com" \
target="_blank">davecortesi@gmail.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">




<div>
<div dir="ltr"><br>
<div class="gmail_extra"><br>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
                
Date: Tue, 15 Dec 2015 11:49:01 -0800<br>
From: Brian Merchant &lt;<a href="mailto:bhmerchant@gmail.com" \
                target="_blank">bhmerchant@gmail.com</a>&gt;<br>
To: <a href="mailto:pyqt@riverbankcomputing.com" \
                target="_blank">pyqt@riverbankcomputing.com</a><br>
Subject: [PyQt] <br>
</blockquote>
<div>  </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
 I have made some images to demo a text-editor like app I&#39;d like to make;<br>
<a href="http://imgur.com/a/2OKph" rel="noreferrer" \
target="_blank">http://imgur.com/a/2OKph</a><br> <br>
Some features are very familiar: type text to enter it, auto-complete<br>
boxes, etc</blockquote>
<div><br>
</div>
<div>Things like this -- dynamic behavior based on the user&#39;s keystrokes in the \
context of the text near the insertion point -- is done using a QSyntaxHighlighter \
[1].<br> <br>
</div>
<div>The main use of this is to highlight the different classes of tokens as the user \
types them. For a simple example, to put a wavy red line underneath a word that fails \
spellcheck. Or to make a keyword one color and a variable a different color. \
Obviously  this requires close linkage between the user&#39;s keystrokes and the \
highlighter. The user types &quot;fro&quot; and that&#39;s a spelling error, \
underline it; then the next keystroke is &quot;g&quot; and now it is not a spelling \
error, clear the underline.<br> </div>
<div><br>
</div>
<div>The relationship between a QSyntaxHighlighter and an editor is not well \
explained in the doc. The Qt design is to make a syntax highlighter a separate object \
from the editor, I suppose so that you could design it separately, and apply one \
highlighter to  multiple different text edit widgets. Anyway you subclass \
QSyntaxHighlighter and specify its behaviors by implementing .highlightBlock().<br> \
<br> </div>
<div>You apply a highlighter, making the highlights appear, by calling its \
.setDocument() method, passing a QTextDocument. At this moment, the highlightBlock() \
method is called for every existing line (or maybe only the visible lines?). From \
then on, highlightBlock()  is called for the line with the insertion point whenever a \
character changes. To remove highlighting, call its .setDocument() passing None.<br> \
<br> </div>
<div>I think using this you could implement your auto suggestion dropdown. Although I \
couldn&#39;t say how to figure out the x/y coordinates of the insertion point to \
locate the menu.<br> </div>
<div>  <br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
 Some features are not so familiar: you can drag and drop some elements of<br>
the text to &quot;flip&quot; their position, some keywords are automatically<br>
converted into symbols when typed, and so on</blockquote>
<div><br>
</div>
<div>Qt&#39;s edit widgets (PlainTextEdit and TextEdit) support drag/drop of selected \
text, complete with a nice transparent overlay of the dragged text and moving \
insertion point to show where it will drop. You want to implement this but make it \
behave based on  lexical units, not merely based on character-by-character moves. \
Read carefully through the QTextEdit doc [2] about drag/drop of mime types. You might \
be able to,<br> <br>
</div>
<div>1. Select the current lexical unit<br>
</div>
<div>2. Cut it<br>
</div>
<div>3. Make it a mime package<br>
</div>
<div>4. Start a drag/drop<br>
</div>
<div>5. Let Qt do its thing<br>
</div>
<div>6. Override the QTextEdit dragMoveEvent() to highlight lexical units under the \
cursor showing where the dragged mime unit can legally go<br> </div>
<div>6. Override the QTextEdit dropEvent() to refuse to drop in an illegal place, and \
to animate moving lexical units around when it&#39;s legal.<br> <br>
</div>
<div>However I have done some experiments with QDrag [3] and friends and found it a \
very difficult API to work with.<br> </div>
<div>  <br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
 My plan is to use PyQt4.<br>
</blockquote>
<div><br>
</div>
<div>Why?!? We are a couple of years into the Qt5 release after all.<br>
<br>
</div>
<div>Cheers,<br>
</div>
<div>Dave Cortesi<br>
</div>
<div>  <br>
</div>
</div>
[1] <a href="http://doc.qt.io/qt-5/qsyntaxhighlighter.html" \
target="_blank">http://doc.qt.io/qt-5/qsyntaxhighlighter.html</a><br> <br>
[2] <a href="http://doc.qt.io/qt-5/qtextedit.html#details" \
target="_blank">http://doc.qt.io/qt-5/qtextedit.html#details</a><br> <br>
[3] <a href="http://doc.qt.io/qt-5/qdrag.html" \
target="_blank">http://doc.qt.io/qt-5/qdrag.html</a><br> </div>
</div>
</div>

</blockquote></div><br><br clear="all"><div><br></div>-- <br><div \
class="gmail_signature">Bryan A. Jones, Ph.D.<br>Associate Professor<br>Department of \
Electrical and Computer Engineering<br>231 Simrall / PO Box 9571<br>Mississippi State \
University<br>Mississippi state, MS 39762<br><a \
href="http://www.ece.msstate.edu/~bjones" \
target="_blank">http://www.ece.msstate.edu/~bjones</a><br>bjones AT ece DOT msstate \
DOT edu<br>voice 662-325-3149<br>fax 662-325-2298<br><br>Our Master, Jesus Christ, is \
on his way. He&#39;ll show up right on<br>time, his arrival guaranteed by the Blessed \
and Undisputed Ruler,<br>High King, High God.<br>- 1 Tim. 6:14b-15 (The \
Message)<br></div> </div></div></div>


[Attachment #6 (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