[PyQt] Weird behavior in fromMimeData method (pyScintilla)
Salvatore Larosa
lrssvtml at gmail.com
Thu Sep 20 13:36:24 BST 2012
Hi Phil,
2012/9/20 Phil Thompson <phil at riverbankcomputing.com>
> On Thu, 20 Sep 2012 00:48:10 +0200, Salvatore Larosa <lrssvtml at gmail.com>
> wrote:
> > Hi,
> >
> > 2012/9/19 Phil Thompson <phil at riverbankcomputing.com>
> >
> >> On Wed, 19 Sep 2012 14:54:57 +0200, Salvatore Larosa
> <lrssvtml at gmail.com>
> >> wrote:
> >> > Hi Phil,
> >> >
> >> > 2012/9/19 Phil Thompson <phil at riverbankcomputing.com>
> >> >
> >> >> On Wed, 19 Sep 2012 08:05:42 +0200, Salvatore Larosa
> >> <lrssvtml at gmail.com>
> >> >> wrote:
> >> >> > Hi,
> >> >> >
> >> >> > 2012/9/19 Phil Thompson <phil at riverbankcomputing.com>
> >> >> >
> >> >> >> On Tue, 18 Sep 2012 23:16:00 +0200, Salvatore Larosa
> >> >> <lrssvtml at 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 mimedata are 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
> Phil
>
--
Salvatore Larosa
linkedIn: http://linkedin.com/in/larosasalvatore
twitter: @lrssvt
skype: s.larosa
IRC: lrssvt on freenode
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120920/bddc616e/attachment.html>
More information about the PyQt
mailing list