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>