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