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

List:       pykde
Subject:    Re: [PyQt] Weird behavior in fromMimeData method (pyScintilla)
From:       Salvatore Larosa <lrssvtml () gmail ! com>
Date:       2012-09-22 10:54:05
Message-ID: CANxjxar6+edW4ws6ENW3Oa+AxC-j4qaf2H076RRtznNS-LhqAA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Phil and all,

2012/9/20 Salvatore Larosa <lrssvtml@gmail.com>

> Hi Phil,
>
> 2012/9/20 Phil Thompson <phil@riverbankcomputing.com>
>
>> On Thu, 20 Sep 2012 00:48:10 +0200, Salvatore Larosa <lrssvtml@gmail.com>
>> wrote:
>> > Hi,
>> >
>> > 2012/9/19 Phil Thompson <phil@riverbankcomputing.com>
>> >
>> >> On Wed, 19 Sep 2012 14:54:57 +0200, Salvatore Larosa
>> <lrssvtml@gmail.com>
>> >> wrote:
>> >> > Hi Phil,
>> >> >
>> >> > 2012/9/19 Phil Thompson <phil@riverbankcomputing.com>
>> >> >
>> >> >> On Wed, 19 Sep 2012 08:05:42 +0200, Salvatore Larosa
>> >> <lrssvtml@gmail.com>
>> >> >> wrote:
>> >> >> > Hi,
>> >> >> >
>> >> >> > 2012/9/19 Phil Thompson <phil@riverbankcomputing.com>
>> >> >> >
>> >> >> >> On Tue, 18 Sep 2012 23:16:00 +0200, Salvatore Larosa
>> >> >> <lrssvtml@gmail.com>
>> >> >> >> wrote:
>> >> >> >> > Hi all,
>> >> >> >> > I am not sure if this is the rigth place to ask!
>> >> >> >> >
>> >> >> >> > I created a small console to execute python command by using
>> >> >> Qscintilla
>> >> >> >> > python bindings but something doesnt work with MIME data.
>> >> >> >> >
>> >> >> >> > My code is:
>> >> >> >> >
>> >> >> >> > def fromMimeData(self, source):
>> >> >> >> >         if source.hasText():
>> >> >> >> >             pasteList = QStringList()
>> >> >> >> >             pasteList = source.text().split("\n")
>> >> >> >> >             if (len(pasteList) > 1):
>> >> >> >> >               self.move_cursor_to_end()
>> >> >> >> >             for line in pasteList[:-1]:
>> >> >> >> >                 self.append(line)
>> >> >> >> >                 self.move_cursor_to_end()
>> >> >> >> >                 self.runCommand(unicode(self.currentCommand()))
>> >> >> >> >             self.append(unicode(pasteList[-1]))
>> >> >> >> >             self.move_cursor_to_end()
>> >> >> >> >
>> >> >> >> > First question: when I paste some text in console and run
>> command
>> >> I
>> >> >> >> > get:
>> >> >> >> >
>> >> >> >> > TypeError: invalid result type from PythonEdit.fromMimeData()
>> >> >> >> >
>> >> >> >> > How I can avoid it?
>> >> >> >>
>> >> >> >> fromMimeData() should return a 2-tuple of the text as a
>> QByteArray
>> >> and
>> >> >> a
>> >> >> >> bool set if the selection is rectangular.
>> >> >> >>
>> >> >> >
>> >> >> > Thanks for your reply.
>> >> >> >
>> >> >> > oddly the paste command works well although returns that error!
>> >> >> > how should I manage the contents of tuple?
>> >> >>
>> >> >> I don't know what your code is supposed to do. If  your
>> implementation
>> >> of
>> >> >> fromMimeData() is adding extra behaviour (rather than changing the
>> >> >> default
>> >> >> behaviour) then call the super-class implementation, ie. add the
>> >> >> following
>> >> >> at the end...
>> >> >>
>> >> >>         return super(MyClass, self).fromMimeData(source)
>> >> >>
>> >> >>
>> >> > That solve the problem about typeError, but now it paste twice the
>> same
>> >> > word!
>> >> > You can see the source code here [1] (MIME data stuff is at line
>> 418).
>> >>
>> >> The purpose of fromMimeData() is to allow you to specify how MIME data
>> is
>> >> converted to text. It looks like you are trying to use it for another
>> >> purpose. You should probably look at reimplementing dropEvent()
>> instead.
>> >>
>> >>
>> > I thought it would work like insertFromMimeData [1].
>> > I tested it with QTextEdit widget and works fine!
>> >
>> > I need that to execute multi-line command in my shell i.e.:
>> >>>> if True:
>> > . . .    print "Hello"
>> > . . . if False:
>> > . . .    print "Bye Bye"
>> >
>> > so the last command line only paste the text doesnt run it!
>> >
>> > Also, I implemented dropEvent() and has worked only for drag and drop
>> event
>> > and not to paste :-(
>>
>> So reimplement paste().
>>
>>
> As you can see from the video [1] operations paste and drop works fine.
> However, with this configuration [2] I can not paste or drop a piece of
> text to a specific position of the cursor is the clipboard and mimedataare inserted at
> the end of the line! You can also see this problem in the video!
> Thanks for your time!!
>
> Anyway, if you can not replicate it, apparently it's just my problem!
> I can send you the source code (a simple widget) so that you can replicate
> it!
>
> Regards,
>
> -SL
>
> [1] - http://lrssvt.ns0.it/pasteDropMimeData.ogv
> [2] - https://gist.github.com/3755609
>


I soved simply changing self.append() to self.insert() in
insertFromDropPaste() method!
The "append()" method inserts the text to the end of the text edit [1]

Cheers!

[1] - http://goo.gl/yGWkE



-- 
Salvatore Larosa
linkedIn: http://linkedin.com/in/larosasalvatore
twitter: @lrssvt
skype: s.larosa
IRC: lrssvt on freenode

[Attachment #5 (text/html)]

Hi Phil and all,<br><br><div class="gmail_quote">2012/9/20 Salvatore Larosa <span \
dir="ltr">&lt;<a href="mailto:lrssvtml@gmail.com" \
target="_blank">lrssvtml@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" \
style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <span \
lang="en"><span>Hi Phil,</span></span><br><br><div class="gmail_quote"><div><div \
class="h5">2012/9/20 Phil Thompson <span dir="ltr">&lt;<a \
href="mailto:phil@riverbankcomputing.com" \
target="_blank">phil@riverbankcomputing.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">On Thu, 20 Sep 2012 00:48:10 +0200, Salvatore Larosa &lt;<a \
href="mailto:lrssvtml@gmail.com" target="_blank">lrssvtml@gmail.com</a>&gt;<br>


<div><div>wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; 2012/9/19 Phil Thompson &lt;<a href="mailto:phil@riverbankcomputing.com" \
target="_blank">phil@riverbankcomputing.com</a>&gt;<br> &gt;<br>
&gt;&gt; On Wed, 19 Sep 2012 14:54:57 +0200, Salvatore Larosa<br>
&lt;<a href="mailto:lrssvtml@gmail.com" \
target="_blank">lrssvtml@gmail.com</a>&gt;<br> &gt;&gt; wrote:<br>
&gt;&gt; &gt; Hi Phil,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 2012/9/19 Phil Thompson &lt;<a \
href="mailto:phil@riverbankcomputing.com" \
target="_blank">phil@riverbankcomputing.com</a>&gt;<br> &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; On Wed, 19 Sep 2012 08:05:42 +0200, Salvatore Larosa<br>
&gt;&gt; &lt;<a href="mailto:lrssvtml@gmail.com" \
target="_blank">lrssvtml@gmail.com</a>&gt;<br> &gt;&gt; &gt;&gt; wrote:<br>
&gt;&gt; &gt;&gt; &gt; Hi,<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; 2012/9/19 Phil Thompson &lt;<a \
href="mailto:phil@riverbankcomputing.com" \
target="_blank">phil@riverbankcomputing.com</a>&gt;<br> &gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; On Tue, 18 Sep 2012 23:16:00 +0200, Salvatore Larosa<br>
&gt;&gt; &gt;&gt; &lt;<a href="mailto:lrssvtml@gmail.com" \
target="_blank">lrssvtml@gmail.com</a>&gt;<br> &gt;&gt; &gt;&gt; &gt;&gt; wrote:<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt; Hi all,<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt; I am not sure if this is the rigth place to ask!<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt; I created a small console to execute python command \
by using<br> &gt;&gt; &gt;&gt; Qscintilla<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt; python bindings but something doesnt work with MIME \
data.<br> &gt;&gt; &gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt; My code is:<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt; def fromMimeData(self, source):<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt;         if source.hasText():<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt;             pasteList = QStringList()<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt;             pasteList = \
source.text().split(&quot;\n&quot;)<br> &gt;&gt; &gt;&gt; &gt;&gt; &gt;             \
if (len(pasteList) &gt; 1):<br> &gt;&gt; &gt;&gt; &gt;&gt; &gt;               \
self.move_cursor_to_end()<br> &gt;&gt; &gt;&gt; &gt;&gt; &gt;             for line in \
pasteList[:-1]:<br> &gt;&gt; &gt;&gt; &gt;&gt; &gt;                 \
self.append(line)<br> &gt;&gt; &gt;&gt; &gt;&gt; &gt;                 \
self.move_cursor_to_end()<br> &gt;&gt; &gt;&gt; &gt;&gt; &gt;                 \
self.runCommand(unicode(self.currentCommand()))<br> &gt;&gt; &gt;&gt; &gt;&gt; &gt;   \
self.append(unicode(pasteList[-1]))<br> &gt;&gt; &gt;&gt; &gt;&gt; &gt;             \
self.move_cursor_to_end()<br> &gt;&gt; &gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt; First question: when I paste some text in console and \
run<br> command<br>
&gt;&gt; I<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt; get:<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt; TypeError: invalid result type from \
PythonEdit.fromMimeData()<br> &gt;&gt; &gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; &gt; How I can avoid it?<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;&gt; fromMimeData() should return a 2-tuple of the text as \
a<br> QByteArray<br>
&gt;&gt; and<br>
&gt;&gt; &gt;&gt; a<br>
&gt;&gt; &gt;&gt; &gt;&gt; bool set if the selection is rectangular.<br>
&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Thanks for your reply.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; oddly the paste command works well although returns that \
error!<br> &gt;&gt; &gt;&gt; &gt; how should I manage the contents of tuple?<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; I don&#39;t know what your code is supposed to do. If  your<br>
implementation<br>
&gt;&gt; of<br>
&gt;&gt; &gt;&gt; fromMimeData() is adding extra behaviour (rather than changing \
the<br> &gt;&gt; &gt;&gt; default<br>
&gt;&gt; &gt;&gt; behaviour) then call the super-class implementation, ie. add \
the<br> &gt;&gt; &gt;&gt; following<br>
&gt;&gt; &gt;&gt; at the end...<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;         return super(MyClass, self).fromMimeData(source)<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt; That solve the problem about typeError, but now it paste twice the<br>
same<br>
&gt;&gt; &gt; word!<br>
&gt;&gt; &gt; You can see the source code here [1] (MIME data stuff is at line<br>
418).<br>
&gt;&gt;<br>
&gt;&gt; The purpose of fromMimeData() is to allow you to specify how MIME data<br>
is<br>
&gt;&gt; converted to text. It looks like you are trying to use it for another<br>
&gt;&gt; purpose. You should probably look at reimplementing dropEvent()<br>
instead.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt; I thought it would work like insertFromMimeData [1].<br>
&gt; I tested it with QTextEdit widget and works fine!<br>
&gt;<br>
&gt; I need that to execute multi-line command in my shell i.e.:<br>
&gt;&gt;&gt;&gt; if True:<br>
&gt; . . .    print &quot;Hello&quot;<br>
&gt; . . . if False:<br>
&gt; . . .    print &quot;Bye Bye&quot;<br>
&gt;<br>
&gt; so the last command line only paste the text doesnt run it!<br>
&gt;<br>
&gt; Also, I implemented dropEvent() and has worked only for drag and drop<br>
event<br>
&gt; and not to paste :-(<br>
<br>
</div></div>So reimplement paste().<br>
<span><font color="#888888"><br></font></span></blockquote></div></div><div><br><span \
lang="en"><span>As you can see</span> <span>from</span> <span>the</span> \
<span>video</span> [1] <span>operations</span> <span>paste</span> <span>and</span> \
<span>drop</span> <span>works fine.</span><br>

 <span>However</span><span>,</span> <span>with this configuration \
[2]</span><span></span> <span>I can not</span> <span>paste</span> <span>or drop \
a</span> <span>piece of text</span> <span>to a specific position</span> <span>of the \
cursor</span> <span>is</span> <span>the</span> <span>clipboard</span><span> and \
</span><span>mimedata</span><span> are inserted</span> <span>at the end</span> \
<span>of the line!</span> <span>You can</span> <span>also see</span> \
<span>this</span> <span>problem</span> <span>in the \
video</span><span>!</span></span><br>


Thanks for your time!!<br><br>Anyway, <span lang="en"><span>if</span> <span>you can \
not</span> <span>replicate it</span><span>, apparently</span> <span>it&#39;s \
just</span> <span>my problem</span><span>!</span><br>  <span></span><span>I \
can</span> <span>send you</span> <span>the source code</span> <span>(a simple</span> \
<span>widget)</span> <span>so</span> <span>that you can</span> <span>replicate \
it</span><span>!</span></span><br>

<br>
Regards,<br>
<br>
-SL<br><br>[1] - <a href="http://lrssvt.ns0.it/pasteDropMimeData.ogv" \
target="_blank">http://lrssvt.ns0.it/pasteDropMimeData.ogv</a><br>[2] - <a \
href="https://gist.github.com/3755609" \
target="_blank">https://gist.github.com/3755609</a><br> </div></div></blockquote><div \
class="h5"><br><br>I soved simply changing self.append() to self.insert() in \
insertFromDropPaste() method!<br>The &quot;append()&quot; method inserts the text to \
the end of the text edit [1]<br> <br>Cheers!<br><br>[1] - <a \
href="http://goo.gl/yGWkE">http://goo.gl/yGWkE</a><br> </div></div><br><br \
clear="all"><br>-- <br>Salvatore Larosa<br>linkedIn: <a \
href="http://linkedin.com/in/larosasalvatore" \
target="_blank">http://linkedin.com/in/larosasalvatore</a><br>twitter: \
                @lrssvt<br>skype: s.larosa<br>
IRC: lrssvt on freenode<br><br>



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://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