Re: [PyQt] Can't get keyboard shortcuts to work

2012-01-22 Thread David Townshend
Thanks for the reply.  I just realised that the example I sent does
actually work (once I sort out the focus).  After about an hour of testing
I discovered that in my actual scenario I never called widget.addAction().
 I've got quite a bit of abstraction around the QActions and I somehow
missed it!

On Sun, Jan 22, 2012 at 2:16 PM, Hans-Peter Jansen  wrote:

> On Thursday 19 January 2012, 10:53:31 David Townshend wrote:
> > I can't get keyboard shortcuts to work with Qt.WidgetShortcut
> > or Qt.WidgetWithChildrenShortcut context.  It seems that nothing I do
> > will trigger the action. Below is a sample class which is giving the
> > problem. Can anyone point out where I am going wrong?
> >
> > class Widget(QtGui.QWidget):
> > def __init__(self):
> > super().__init__()
> > self.act = QtGui.QAction('test', self)
> >
> > self.act.setShortcut(QtGui.QKeySequence(QtGui.QKeySequence.Copy))
> > self.act.setShortcutContext(Qt.WidgetWithChildrenShortcut)
> > self.addAction(self.act)
> > self.act.triggered.connect(self.slot)
> >
> > def slot(self):
> > print('triggered')
>
> Check out FocusPolicy in the fine manual..
>
> Pete
>
>
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] Simple C++ example has undefined symbol

2012-01-22 Thread Jens Thoms Toerring
Hi Gary,

On Sun, Jan 22, 2012 at 11:57:44AM -0500, Gary Fisher wrote:
> >>> What does "return (static char *)Null" mean?
> 
> My mistake...I meant "return (const char *)Null" ... not staticand yes
> I do believe NULL is used in C++.  At least the compiler didn't witch at me
> for it.

There's still no reason for the cast. And while you use 'NULL'
in C quite often it's frowned upon in C++. All you really need
is

 return 0;

Since the compiler knows that the function returns a 'const char *'
it will automatically do the conversion. By casting (and then
even using a C-style cast, which is strongly discouraged in C++)
you tell the compiler "I know better than you" and you shouldn't
do that unless there's something the compiler can't figure out
on his own since a) you keep the compiler from explaining about
stuff that shouldn't/can't be done (don't see compiler complaints
as a nuisance but as a valuable help you to write correct pro-
grams) and b) you make the next person reading your code wonder
what this is all about.

> When I use "nm -C libword.so" on my little wrapped library I see nothing in
> the output to suggest a "word" class or a "reverse" method.

And that's at the very heart of your problem: the symbols needed
by the wrapper script don't exist in 'libword.so'. Rhe reason is
that there's not the slightest bit of necessity for the compiler/
linker to put them in there: you have a class declared with in-
lined methods that is never used anywhere. So there's no reason
to use the class for anything and it simply gets thrown out.

Every program using your library would include a header file for
the library that defines the interface. And while doing so it
would see the declaration of the class and would construct it's
own version of the class when it's needed.

I'm a bit at a loss at understanding how you got your SIP wrapper
to work without a header file, but that's another topic;-)

The quick fix is to simply splitting the word.cpp file up into
two parts, the necessary header file with the class declaration
and a cpp file with the function definitions. I.e. something
like this:

--- word.hpp -
#ifndef WORD_HPP_
#define WORD_HPP_

class Word {
  public:

Word( const char * w );

const char * reverse( );

  private:

const char * the_word;
};

#endif
--- word.cpp -
#include "word.hpp"

Word::Word( const char * w ) :
the_word( w )
{ }

const char *
Word::reverse( )
{
   return 0;
}
--

BTW: don't forget the 'public:' in the class!

If you now compile this into a shared library it will con-
tain both the symbols for the constructor and the reverse()
method. And within the SIP wrapper you include the 'word.hpp'
header file.

  However, when
> I run "nm -C word.so" against the library generated by make I get things
> like:
> 
> 21b4 d methods_Word
>  U Word::Word(char const*)
>  U Word::reverse() const
> 
> among other things.

Yes, the 'word.so' library needs those symbols and expects
them in one of the libraries it was linked with, but they
aren't anywhere. That will be only noticed when Python tries
to load the 'word.so' library and thus it fails.

BTW, the code in your program looks a bit broken. 

> class Word {
>   const char *the_word;
>   //  const char *the_reverse;
>   char buffer[20], *pb;
> 
>   int i, len;
> 
>   Word( const char *w) {
>   the_word = w;
>   }

Do you realize that 'the_word' is now set to some memory
that doesn't belong to this class? It looks as if you 
would like to store a word using this class, but that's
not what you do - all you keep is a pointer to some
string somewhere else in memory (and not owned by the
class instance). And if this memory is used for something
else then the 'the_word' pointer will point to memory that
doesn't contain a string anymore. I guess you're coming from
languages where memory allocation is done for you in the
background (like in Python), but if you write in C++ (or C)
you will have to be very careful to do the right thing with
memory, e.g. just holding a pointer to some memory doesn't
make it "yours" - you have to ensure that nothing else will
fiddle with the memory pointed to.

>   const char *reverse () {
> 
>   return (const char *) NULL;
> 
>   /
>   len = strlen(the_word);
>   strcpy (buffer, the_word);

What happens if what 'the_word' points to is longer than 19
chars? You write past the end of buffer with unforseeable
effects. In the worst case it even might seem to work at
firt until some strange and hard to trace erros show up
much later...

>   pb = (char *)the_word;

That's exactly one of the places were a cast shouldn't be
used. 'the_word' points to memory you are not allowed to
change. And to get around this you need the cast. So you're
now operating directly on the memory where your word is
stored which could reside in read-o

Re: [PyQt] Simple C++ example has undefined symbol

2012-01-22 Thread Gary Fisher
Hi Jens,

Thank you for getting back to me, much appreciated.
My source code "word.cpp" is attached.

OK, just to make sure we're all on the same page here, this is the
page
containing
the recipe I'm following.  :-)




>>> What does "return (static char *)Null" mean?

My mistake...I meant "return (const char *)Null" ... not staticand yes
I do believe NULL is used in C++.  At least the compiler didn't witch at me
for it.


>>> If you compile C++ code you should use g++ instead of gcc.

I re-ran through the entire example again using g++ instead and I still the
get undefined symbol.  The difference between the two is now
understood...thanks for that.


>>> Do you have anything in configure.py 
>>> for example a line with
>>> makefile.extra_libs = [ 'word' ]

I do, and exactly as you typed it.


>>> That will result in the resulting Makefile having '-lword'
>>> as linker option.

2 little snippets from the resulting makefile follow.  They also show that,
in the making of the library word.so, the linker was indeed aware of the
need to include my little wrapped library libword.so.

LIBS = -lword

$(TARGET): $(OFILES)
@echo '{ global: initword; local: *; };' > word.exp
$(LINK) $(LFLAGS) -o $(TARGET) $(OFILES) $(LIBS)


>>> I would try ldd word.so

I did and the result show that there is indeed a dependency on the library
libword.so...the one I copied into /usr/lib before doing the make.  ldd
output follows:

linux-gate.so.1 =>  (0x00ffb000)
libword.so => /usr/lib/libword.so (0x00c24000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x0011)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0x00c6e000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00206000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00225000)
/lib/ld-linux.so.2 (0x00cf1000)


>>> I would use 'nm' for such checks
>>>  Check the letter before the name of the function - if
>>> it's a 'T' everything is fine (i.e. the symbol is defined in
>>> that library) but if it's a 'U' the symbol is undefined

When I use "nm -C libword.so" on my little wrapped library I see nothing in
the output to suggest a "word" class or a "reverse" method.  However, when
I run "nm -C word.so" against the library generated by make I get things
like:

21b4 d methods_Word
 U Word::Word(char const*)
 U Word::reverse() const

among other things.  I can provide complete outputs from both libraries if
needed.

So I'm still stumped and will be researching  why I'm seeing (and not
seeing) these things in the 2 libraries.  Until then, are there any
other ideas out there ?

thanks,
 Gary ---













On Sat, Jan 21, 2012 at 3:51 PM, Jens Thoms Toerring  wrote:

> Hi Gary,
>
> On Sat, Jan 21, 2012 at 08:47:21AM -0500, Gary Fisher wrote:
> > So, I wrote a little C++ class called word and provided a method
> > called reverse which does nothing but "return (static char *)Null".
>
> What does "return (static char *)Null" mean? There's no 'Null'
> in C++ and casting to 'static char pointer also looks rather
> strange (and shouldn't compile since you can't cast to some-
> thing that's 'static'). Do you simply want to return a char
> (NULL) pointer? Then
>
>  return 0;
>
> will be all you need (assuming that the function is defined
> to return a char pointer.
>
> > I then ran "gcc -o libword.so -shared word.cpp" to make my little
> > fictional library (as referred to in the text).
>
> If you compile C++ code you should use g++ instead of gcc.
>
> > I then made the word.sip and configure.py files and ran configure.py.
> > Prior to running make I copied libword.so into /usr/lib so the linker
> would
> > find it.  Running make and 'make install' ran flawless, as did everything
> > until now.
>
> Do you have anything in configure.py that would tell the make
> process that the resulting 'word.so' library will need the
> 'libword.so' library, for example a line with
>
> makefile.extra_libs = [ 'word' ]
>
> That will result in the resulting Makefile having '-lword'
> as linker option.
>
> > At this point, if I understand the theory here, I figured I'd start up a
> > Python command line session and issue the command "import word" and
> > then try "word.reverse()".  To my surprise I got the following error:
> >
> > >>> import word
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > ImportError: ./word.so: undefined symbol: _ZNK4Word7reverseEv
>
> So 'word.so' is the wrapper library for your original library
> written in C++ (which seems to be 'libword.so'), right? Looks
> to me as if when was 'word.so' created the linker wasn't aware
> that 'libword.so' would be needed when 'word.so' is used.
> 'word.so' is also a library, so the linker will not complain
> when symbols aren't found while 'word.so' is created since
> they're then expected to be found somewhere when the library is
> loaded.
>
> I would tr

Re: [PyQt] Building PyQT windows 7 64 bit QT 4.8.0

2012-01-22 Thread Teodor Calin Hanchevici
Hi,
as I suspected, the QT distribution was incomplete. After rebuilding and
reinstalling QT, Py-QT built fine.
I wonder if would be possible to get more verbose/clearer error messages
from sip?
Thank you all
Teodor

On Thu, Jan 19, 2012 at 1:05 PM,  wrote:

> Nico,
> In my case it seems that the QT distribution was corrupted. I am
> rebuilding QT now and see what happens. After installing the headers and
> the binaries for QT VS2010 32 bit, I was able to generate everything. Still
> got into linking errors when I used the 64 bit QT.
>
> Teodor
>
>
> On , Nico Dufort  wrote:
> > Teodor,
> >
> >
> > I ran into a similar error but on QtDeclarative while trying to build
> against an older version of Python under Linux.  Never could get the build
> to work even though I was using the freshly installed sip, not the system
> one.  Gave up as I was getting nowhere after a few days of trying and I
> needed to move on.  Did the same install, with older versions of the
> packages on another machine without a problem.
> >
> >
> >
> >
> > On Thu, Jan 19, 2012 at 3:36 PM, Phil Thompson
> p...@riverbankcomputing.com> wrote:
> >
> >
> >
> > On Thu, 19 Jan 2012 09:16:19 -0500, Teodor Calin Hanchevici
> >
> > calin.hanchev...@gmail.com> wrote:
> >
> > > Hi Phil,
> >
> > >
> >
> > > I doubt that this is the problem. I ran the following:
> >
> >
> >
> >
> > Sorry, I mis-read your previous email.
> >
> >
> >
> > > C:\home\3rdparty\sources\PyQt-win-gpl-4.9>"C:\Python27\sip" -w -o -x
> >
> > > VendorID -t WS_WIN -x PyQt_OpenSSL -x PyQt_NoPrintRangeBug -t Qt_4_8_0
> >
> > -x
> >
> > > Py_v3 -g -a QtNetwork.api -c
> >
> > > C:\home\3rdparty\sources\PyQt-win-gpl-4.9\QtNetwork -b
> >
> > > QtNetwork\QtNetwork.sbf -I
> C:\home\3rdparty\sources\PyQt-win-gpl-4.9\sip
> >
> > >
> C:\home\3rdparty\sources\PyQt-win-gpl-4.9/sip/QtNetwork/QtNetworkmod.sip
> >
> > > sip: __or__() unsupported function return type - provide %MethodCode
> and
> >
> > a
> >
> > > C++ signature
> >
> > >
> >
> > > C:\home\3rdparty\sources\PyQt-win-gpl-4.9>sip -w -o -x VendorID -t
> >
> > WS_WIN
> >
> > > -x PyQt_OpenSSL -x PyQt_NoPrintRangeBug -t Qt_4_8_0 -x Py_v3 -g -a
> >
> > > QtNetwork.api -c C:\home\3rdparty\sources\PyQt-win-gpl-4.9\QtNetwork -b
> >
> > > QtNetwork\QtNetwork.sbf -I
> >
> > > C:\home\3rdparty\sources\PyQt-win-gpl-4.9\sip
> >
> > >
> C:\home\3rdparty\sources\PyQt-win-gpl-4.9/sip/QtNetwork/QtNetworkmod.sip
> >
> > > sip: __or__() unsupported function return type - provide %MethodCode
> and
> >
> > a
> >
> > > C++ signature
> >
> > >
> >
> > > C:\home\3rdparty\sources\PyQt-win-gpl-4.9>sip.exe -w -o -x VendorID -t
> >
> > > WS_WIN -x PyQt_OpenSSL -x PyQt_NoPrintRangeBug -t Qt_4_8_0 -x Py_v3 -g
> >
> > -a
> >
> > > QtNetwork.api -c C:\home\3rdparty\sources\PyQt-win-gpl-4.9\QtNetwork -b
> >
> > > QtNetwork\QtNetwork.sbf -I
> >
> > > C:\home\3rdparty\sources\PyQt-win-gpl-4.9\sip
> >
> > >
> C:\home\3rdparty\sources\PyQt-win-gpl-4.9/sip/QtNetwork/QtNetworkmod.sip
> >
> > > sip: __or__() unsupported function return type - provide %MethodCode
> and
> >
> > a
> >
> > > C++ signature
> >
> > >
> >
> > > C:\home\3rdparty\sources\PyQt-win-gpl-4.9>"C:\Python27\sip.exe" -w -o
> -x
> >
> > > VendorID -t WS_WIN -x PyQt_OpenSSL -x PyQt_NoPrintRangeBug -t Qt_4_8_0
> >
> > -x
> >
> > > Py_v3 -g -a QtNetwork.api -c
> >
> > > C:\home\3rdparty\sources\PyQt-win-gpl-4.9\QtNetwork -b
> >
> > > QtNetwork\QtNetwork.sbf -I
> C:\home\3rdparty\sources\PyQt-win-gpl-4.9\sip
> >
> > >
> C:\home\3rdparty\sources\PyQt-win-gpl-4.9/sip/QtNetwork/QtNetworkmod.sip
> >
> > > sip: __or__() unsupported function return type - provide %MethodCode
> and
> >
> > a
> >
> > > C++ signature
> >
> > >
> >
> > >
> >
> > > I am able to configure the package as follows:
> >
> > > C:\home\3rdparty\sources\PyQt-win-gpl-4.9>python configure.py --verbose
> >
> > -e
> >
> > > QtCore -e QtHelp -e QtScriptTools  -e QtXml -e QtDBus -eQtMultimedia
>  -e
> >
> > > QtSql -e QtDeclarative  -e QtSvg -e QAxContainer -e QtDesigner -e
> >
> > QtOpenGL
> >
> > > -e QtTest -e QtAssistant -e QtGui -e QtScript -e QtWebKit
> >
> > >
> >
> > > QtNetwork and QtXmlPatterns give the same errors.
> >
> >
> >
> >
> >
> > I don't know. The message implies a mis-match between the version of sip
> >
> > and the version of PyQt (ie. its .sip files). Obviously it works for me,
> >
> > and I haven't seen anybody else report a similar problem. I would still
> >
> > suspect the QCIS installation.
> >
> >
> >
> > Phil
> >
> > ___
> >
> > PyQt mailing listPyQt@riverbankcomputing.com
> >
> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> >
> >
> >
> >
> >
> >
> >
> > --
> > "Attention, attention. Here and now, boys," the mynah repeated. "Here
> and now, boys."
> >
> >
>
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] Sending a Signal from a QTableWidget header

2012-01-22 Thread Hans-Peter Jansen
On Sunday 22 January 2012, 16:38:21 Hans-Peter Jansen wrote:
> On Saturday 21 January 2012, 23:21:18 starglider.dev wrote:
> > Hi,
> > I need to open a dialog if the user click in the QTableWidget
> > header.
>
> There's no such class in PyQt (nor in Qt). If you mean QTable, then
> QHeader.clicked() is proably, wat you're looking for.

Scratch that, I looked up the wrong docs. 

Since QTableWidget inherits from QTableView, the 
{horizontal,vertical}Header() methods return a QHeaderView instance, 
which emits e.g. sectionPressed(int). 

Sorry for the confusion.

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


Re: [PyQt] Sending a Signal from a QTableWidget header

2012-01-22 Thread Hans-Peter Jansen
On Saturday 21 January 2012, 23:21:18 starglider.dev wrote:
> Hi,
> I need to open a dialog if the user click in the QTableWidget header.

There's no such class in PyQt (nor in Qt). If you mean QTable, then 
QHeader.clicked() is proably, wat you're looking for.

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


Re: [PyQt] Function to open window and return user input

2012-01-22 Thread Hans-Peter Jansen
On Friday 20 January 2012, 20:38:33 Christopher Evans wrote:
> QInput is designed to get a single input from a user.
>
> In my case, we are making a complex remapping dialog that takes two
> ordered lists as input, allows the users to change the order, then on
> dialog close, it should return the two re-ordered lists.

That's called a modal dialog. Create it, exec_ it (look up 
QDialog::exec()), process data after close, and be done.

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


Re: [PyQt] Can't get keyboard shortcuts to work

2012-01-22 Thread Hans-Peter Jansen
On Thursday 19 January 2012, 10:53:31 David Townshend wrote:
> I can't get keyboard shortcuts to work with Qt.WidgetShortcut
> or Qt.WidgetWithChildrenShortcut context.  It seems that nothing I do
> will trigger the action. Below is a sample class which is giving the
> problem. Can anyone point out where I am going wrong?
>
> class Widget(QtGui.QWidget):
> def __init__(self):
> super().__init__()
> self.act = QtGui.QAction('test', self)
>
> self.act.setShortcut(QtGui.QKeySequence(QtGui.QKeySequence.Copy))
> self.act.setShortcutContext(Qt.WidgetWithChildrenShortcut)
> self.addAction(self.act)
> self.act.triggered.connect(self.slot)
>
> def slot(self):
> print('triggered')

Check out FocusPolicy in the fine manual..

Pete


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


Re: [PyQt] GraphicsView and Opengl

2012-01-22 Thread Tayfun Kayhan
In case it helps, the example works properly on my system, Kubuntu 11.10, 
64bit. You could also try running OpenGL examples that python-qt4-doc package 
provides. 


 From: Peter Würtz 
To: pyqt@riverbankcomputing.com 
Sent: Sunday, January 22, 2012 1:23 PM
Subject: [PyQt] GraphicsView and Opengl
 
Hi,

I'm having trouble using QGraphicsView on a QGLWidget. I'm getting a
white window and errors like this these:
QGLShader: could not create shader
Vertex shader for simpleShaderProg (MainVertexShader &
PositionOnlyVertexShader) failed to compile

This is an example application triggering the problem:
http://pastebin.com/R0aa8ejs

The 'same' program works flawlessly when using C++/Qt. I'm seeing the
exact behavior when using PySide instead of PyQt4 by the way. Is there
some special treatment required when using python + opengl?

My system is Ubuntu 11.10, opengl is provided by the nvidia driver.

Thanks in advance.
___
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] GraphicsView and Opengl

2012-01-22 Thread Peter Würtz
Hi,

I'm having trouble using QGraphicsView on a QGLWidget. I'm getting a
white window and errors like this these:
QGLShader: could not create shader
Vertex shader for simpleShaderProg (MainVertexShader &
PositionOnlyVertexShader) failed to compile

This is an example application triggering the problem:
http://pastebin.com/R0aa8ejs

The 'same' program works flawlessly when using C++/Qt. I'm seeing the
exact behavior when using PySide instead of PyQt4 by the way. Is there
some special treatment required when using python + opengl?

My system is Ubuntu 11.10, opengl is provided by the nvidia driver.

Thanks in advance.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt