Re: [PyQt] clipboard not work on GNOME/Unity?

2012-09-20 Thread Hans-Peter Jansen
Am Thursday 20 September 2012 06:36:33 schrieb zw g:
> Can anyone help me on this?
> Still stuck.

This is rather OT, and you failed to RTFM.

http://doc.qt.digia.com/4.7-snapshot/qclipboard.html#notes-for-x11-users
 
Pete

> Thanks.
>
> On Tue, Sep 11, 2012 at 10:12 AM, zw g  wrote:
> > Anyone? Some suggestion would be fine.
> > Thanks.
> >
> > On Sat, Sep 8, 2012 at 8:17 PM, zw g  wrote:
> >> Dear list,
> >>
> >>
> >> How can i copy files between applications on GNOME/Unity
> >> desktop(with Nautilus file manager)?
> >>
> >> The below code works fine on KDE & Mac OS X(Finder), but not work
> >> on GNOME/Unity-based desktop.
> >> The section marked with *bold* were the part i used for copy &
> >> paster files. (Paste the files i copied from my PyQt app to
> >> somewhere on the filesystem, /home/myuser/, etc.)
> >>
> >>
> >> def buildContextMenu(self):
> >> self.contextMenu = QMenu(self)
> >> copyAction = QAction(self.trUtf8('Copy'), self)
> >> self.contextMenu.addAction(copyAction)
> >>
> >> self.connect(copyAction, SIGNAL('triggered()'),
> >> self.copy2clipboard)
> >>
> >> def copy2clipboard(self):
> >> selectedList = self.selectedIndexes()
> >> if selectedList:
> >> paths = []
> >> for i in selectedList:
> >> p = unicode(i.model().filePath(i))
> >> if p not in paths:
> >> paths.append(p)
> >> *
> >> urls = [QUrl.fromLocalFile(i) for i in paths]
> >>
> >> mime_data = QMimeData()
> >> mime_data.setUrls(urls)
> >>
> >> clipboard = QApplication.clipboard()
> >> clipboard.setMimeData(mime_data)*
> >>
> >>
> >> Any help would be appreciated.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Weird behavior in fromMimeData method (pyScintilla)

2012-09-20 Thread Salvatore Larosa
Hi Phil,

2012/9/20 Phil Thompson 

> On Thu, 20 Sep 2012 00:48:10 +0200, Salvatore Larosa 
> wrote:
> > Hi,
> >
> > 2012/9/19 Phil Thompson 
> >
> >> On Wed, 19 Sep 2012 14:54:57 +0200, Salvatore Larosa
> 
> >> wrote:
> >> > Hi Phil,
> >> >
> >> > 2012/9/19 Phil Thompson 
> >> >
> >> >> On Wed, 19 Sep 2012 08:05:42 +0200, Salvatore Larosa
> >> 
> >> >> wrote:
> >> >> > Hi,
> >> >> >
> >> >> > 2012/9/19 Phil Thompson 
> >> >> >
> >> >> >> On Tue, 18 Sep 2012 23:16:00 +0200, Salvatore Larosa
> >> >> 
> >> >> >> 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
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] QPoint not automatically cast to QPointF

2012-09-20 Thread Shriramana Sharma
Hi. Thanks for your reply. What you have to do in SIP, is it of the nature
of a workaround to Python's inability to do the conversion automatically?
Or Python is able to do the conversion automatically and SIP just needs to
present the classes in a proper manner as required by Python?

Sent from my Android phone
On Sep 20, 2012 2:19 PM, "Phil Thompson" 
wrote:

> On Thu, 20 Sep 2012 07:34:10 +0530, Shriramana Sharma 
> wrote:
> > In my recent work with Beziers I ran across this. A QPoint is *not*
> > automatically converted into a QPointF in Python/PyQt while it *is*
> > converted in C++:
> >
> > The following C++ code compiles fine:
> >
> > # include 
> > # include 
> > int main ( void ) {
> >   QPainterPath p ;
> >   QPoint p1 ( 100, 150 ), c1 ( 166, 250 ), c2 ( 234, 250 ), p2 (
> 300, 150
> )
> >   ;
> >   p . moveTo ( p1 ) ;
> >   p . cubicTo ( c1, c2, p2 ) ;
> > }
> >
> > whereas its Python/PyQt equivalent:
> >
> > #! /usr/bin/env python3
> > from PyQt4 . QtCore import QPoint
> > from PyQt4 . QtGui import QPainterPath
> > p = QPainterPath ()
> > p1 = QPoint ( 100, 150 )
> > c1 = QPoint ( 166, 250 )
> > c2 = QPoint ( 234, 250 )
> > p2 = QPoint ( 300, 150 )
> > p . moveTo ( p1 )
> > p . cubicTo ( c1, c2, p2 )
> >
> > produces the following:
> >
> > Traceback (most recent call last):
> >   File "./qpoint-test.py", line 11, in 
> > p . moveTo ( p1 )
> > TypeError: arguments did not match any overloaded call:
> >   QPainterPath.moveTo(QPointF): argument 1 has unexpected type 'QPoint'
> >   QPainterPath.moveTo(float, float): argument 1 has unexpected type
> >   'QPoint'
> >
> > But QPointF in PyQt *does* provide a constructor from QPoint, so is
> > this the limitation of Python that it does not automatically check
> > whether it can convert one type to another to satisfy a function's
> > call signature? (Or is there some other fault in my PyQt code?)
> >
> > I realize I could always convert it manually using QPointF(p1) etc but
> > the assumption seems natural that an integer-precision numeric object
> > should be accepted where a float-precision can...
>
> It requires a change to SIP to handle this automatically which is on the
> TODO list but I haven't got round to it yet.
>
> Phil
>
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] QPoint not automatically cast to QPointF

2012-09-20 Thread Phil Thompson
On Thu, 20 Sep 2012 07:34:10 +0530, Shriramana Sharma 
wrote:
> In my recent work with Beziers I ran across this. A QPoint is *not*
> automatically converted into a QPointF in Python/PyQt while it *is*
> converted in C++:
> 
> The following C++ code compiles fine:
> 
> # include 
> # include 
> int main ( void ) {
>   QPainterPath p ;
>   QPoint p1 ( 100, 150 ), c1 ( 166, 250 ), c2 ( 234, 250 ), p2 ( 300, 150
)
>   ;
>   p . moveTo ( p1 ) ;
>   p . cubicTo ( c1, c2, p2 ) ;
> }
> 
> whereas its Python/PyQt equivalent:
> 
> #! /usr/bin/env python3
> from PyQt4 . QtCore import QPoint
> from PyQt4 . QtGui import QPainterPath
> p = QPainterPath ()
> p1 = QPoint ( 100, 150 )
> c1 = QPoint ( 166, 250 )
> c2 = QPoint ( 234, 250 )
> p2 = QPoint ( 300, 150 )
> p . moveTo ( p1 )
> p . cubicTo ( c1, c2, p2 )
> 
> produces the following:
> 
> Traceback (most recent call last):
>   File "./qpoint-test.py", line 11, in 
> p . moveTo ( p1 )
> TypeError: arguments did not match any overloaded call:
>   QPainterPath.moveTo(QPointF): argument 1 has unexpected type 'QPoint'
>   QPainterPath.moveTo(float, float): argument 1 has unexpected type
>   'QPoint'
> 
> But QPointF in PyQt *does* provide a constructor from QPoint, so is
> this the limitation of Python that it does not automatically check
> whether it can convert one type to another to satisfy a function's
> call signature? (Or is there some other fault in my PyQt code?)
> 
> I realize I could always convert it manually using QPointF(p1) etc but
> the assumption seems natural that an integer-precision numeric object
> should be accepted where a float-precision can...

It requires a change to SIP to handle this automatically which is on the
TODO list but I haven't got round to it yet.

Phil
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Weird behavior in fromMimeData method (pyScintilla)

2012-09-20 Thread Phil Thompson
On Thu, 20 Sep 2012 00:48:10 +0200, Salvatore Larosa 
wrote:
> Hi,
> 
> 2012/9/19 Phil Thompson 
> 
>> On Wed, 19 Sep 2012 14:54:57 +0200, Salvatore Larosa

>> wrote:
>> > Hi Phil,
>> >
>> > 2012/9/19 Phil Thompson 
>> >
>> >> On Wed, 19 Sep 2012 08:05:42 +0200, Salvatore Larosa
>> 
>> >> wrote:
>> >> > Hi,
>> >> >
>> >> > 2012/9/19 Phil Thompson 
>> >> >
>> >> >> On Tue, 18 Sep 2012 23:16:00 +0200, Salvatore Larosa
>> >> 
>> >> >> 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().

Phil
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt