Hi Phil,<br><br><div class="gmail_quote">2012/9/19 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 Wed, 19 Sep 2012 08:05:42 +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 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 command 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 QByteArray 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>
</div></div>I don't know what your code is supposed to do. If  your implementation of<br>
fromMimeData() is adding extra behaviour (rather than changing the default<br>
behaviour) then call the super-class implementation, ie. add the following<br>
at the end...<br>
<br>
        return super(MyClass, self).fromMimeData(source)<br>
<div><div><br></div></div></blockquote><div><br>That solve the problem about typeError, but now it paste twice the same word!<br>You can see the source code here [1] (MIME data stuff is at line 418).<br><br>Thanks for your help!<br>
<br>Regards,<br><br>[1] - <a href="https://gist.github.com/3749286">https://gist.github.com/3749286</a><br><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">
<div>
<div>
>> > Second question: If in my console I typed some text ( e.g def<br>
>> > blablabla(self): ) and then<br>
>> > I want edit it by replacing "self" with "source" by using paste<br>
>> > command,<br>
>> > the pasted text<br>
>> > is placed at the end of the current line and not between brace<br>
getting<br>
>> the<br>
>> > following result:<br>
>> ><br>
>> > def blablabla(self):source<br>
>> ><br>
>> > Any idea on how I can solve it?<br>
>><br>
>> I can't reproduce that. What does move_cursor_to_end() do in the above<br>
>> code?<br>
>><br>
><br>
> move_cursor_to_end() move the cursor at the end of the current line!.<br>
> the result doesnt change if I comment out it!<br>
> if in my code I don't use the fromMimeData method, paste and drag/frop<br>
> event does work  as expected!<br>
> But I need it to execute command when multi-line text is dropped or<br>
pasted!<br>
><br>
><br>
>> Phil<br>
>><br>
><br>
> Regards,<br>
><br>
> -SL<br>
<br>
</div></div><span><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>