<span id="result_box" class="long_text" lang="en"><span class="hps">Hi Phil,</span></span><br><br><div class="gmail_quote">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">lrssvtml@gmail.com</a>><br>

<div><div class="h5">wrote:<br>
> Hi,<br>
><br>
> 2012/9/19 Phil Thompson <<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>><br>
><br>
>> On Wed, 19 Sep 2012 14:54:57 +0200, Salvatore Larosa<br>
<<a href="mailto:lrssvtml@gmail.com">lrssvtml@gmail.com</a>><br>
>> wrote:<br>
>> > Hi Phil,<br>
>> ><br>
>> > 2012/9/19 Phil Thompson <<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>><br>
>> ><br>
>> >> On Wed, 19 Sep 2012 08:05:42 +0200, Salvatore Larosa<br>
>> <<a href="mailto:lrssvtml@gmail.com">lrssvtml@gmail.com</a>><br>
>> >> wrote:<br>
>> >> > Hi,<br>
>> >> ><br>
>> >> > 2012/9/19 Phil Thompson <<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>><br>
>> >> ><br>
>> >> >> On Tue, 18 Sep 2012 23:16:00 +0200, Salvatore Larosa<br>
>> >> <<a href="mailto:lrssvtml@gmail.com">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 class="HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br><span id="result_box" class="long_text" lang="en"><span class="hps">As you can see</span> <span class="hps">from</span> <span class="hps">the</span> <span class="hps">video</span> [1] <span class="hps">operations</span> <span class="hps">paste</span> <span class="hps">and</span> <span class="hps">drop</span> <span class="hps">works fine.</span><br>
 <span class="hps">However</span><span>,</span> <span class="hps">with this configuration [2]</span><span class="hps"></span> <span class="hps">I can not</span> <span class="hps">paste</span> <span class="hps">or drop a</span> <span class="hps">piece of text</span> <span class="hps">to a specific position</span> <span class="hps">of the cursor</span> <span class="hps">is</span> <span class="hps">the</span> <span class="hps">clipboard</span><span class="atn"> and </span><span class="">mimedata</span><span> are inserted</span> <span class="hps">at the end</span> <span class="hps">of the line!</span> <span class="hps">You can</span> <span class="hps">also see</span> <span class="hps">this</span> <span class="hps">problem</span> <span class="hps">in the video</span><span class="">!</span></span><br>

Thanks for your time!!<br><br>Anyway, <span id="result_box" class="" lang="en"><span class="hps">if</span> <span class="hps">you can not</span> <span class="hps">replicate it</span><span>, apparently</span> <span class="hps">it's just</span> <span class="hps">my problem</span><span>!</span><br>
 <span class="hps"></span><span class="hps">I can</span> <span class="hps">send you</span> <span class="hps">the source code</span> <span class="hps">(a simple</span> <span class="hps">widget)</span> <span class="hps">so</span> <span class="hps">that you can</span> <span class="hps">replicate it</span><span class="">!</span></span><br>
<br>
Regards,<br>
<br>
-SL<br><br>[1] - <a href="http://lrssvt.ns0.it/pasteDropMimeData.ogv">http://lrssvt.ns0.it/pasteDropMimeData.ogv</a><br>[2] - <a href="https://gist.github.com/3755609">https://gist.github.com/3755609</a><br><br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class="HOEnZb"><font color="#888888">
Phil<br>
</font></span></blockquote></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>