Re: [PyQt] Trying to learn ...

2011-08-03 Thread Hans-Peter Jansen
Dear BigAl,

On Wednesday 03 August 2011, 01:27:55 Algis Kabaila wrote:

 Hi, Pete!

 Looking at testui.py it seems to me that it should/would work without
 the decorator @pyqtSlot().  This suggests two questions:

 1. What is the advantage, if any, to use the decorator in this case?

In short: none. I opted to mangle Magnus' file in a minimum invasive 
fashion, and @pyqtSlot was one weapon in his quest to get the thing 
behave... 

IMHO, after getting used to it, it's usefulness is two fold: it nicely 
documents the slots in your classes, and helps to disambiguate/fix 
those cases, were it is needed. E.g. there are some not so obvious 
cases in esoteric usage pattern of webkit with javascript/PyQt 
interaction:

http://www.riverbankcomputing.com/pipermail/pyqt/2010-November/028600.html

 2. Where could one look up the code for this decorator?

http://www.riverbankcomputing.com/static/Docs/PyQt4/html/new_style_signals_slots.html#the-pyqtslot-decorator

 Thanks for your forever careful care of simple questions - there is
 nothing simple when one does not know how to get it working!  Good
 work!

 OldAl.

I dimly remember my own PyQt quest ten years ago. ;-)

BTW, I talked to someone lately, who was involved in a web based ERP 
system in about the same time span. Finally, they've given up, since 
they failed to cope with the need to redesign/rewrite the whole thing 
for the third time (in order to deal with the 
html/java/javascript/browser evolution).. I cannot qualify their 
development process, but I imagine, that sustainability of PyQt code is 
a couple of magnitudes above that level, even if factoring in sip v2 to 
v4, (Py)Qt v3 to v4 and python v2 to v3 advancements from that time.

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


Re: [PyQt] Trying to learn ...

2011-08-02 Thread Hans-Peter Jansen
Magnus, please keep the conversation on the ML or CC at the very least. 
Others might want to participate.

My personal preference is to NOT receive personal copies. 

On Tuesday 02 August 2011, 11:20:15 Magnus Wirström wrote:
 2011/8/2 Hans-Peter Jansen h...@urpla.net:
  On Monday 01 August 2011, 22:20:32 Magnus Wirström wrote:
  Hi
 
  I am sorry if this have been asked before :)
 
  I am trying to learn using python and pyqt using ERIC 5.1.2. I
  have a problem with signals and slots. I tried this on 2 different
  computer with different OS and different version of python. My
  problem is this...
 
  I am creating a test project using Eric ... using one of the
  tuturials on Eric's webpage. I create a project and a form, then i
  add a push button. I save the form and i generate the form into
  code using Eric I also generate dialog code and adding a slot for
  my push button. So far i have not written a single line of code.
  In my slot i write a print(Hello), My only self written code.
  When i run this, i get a window with my button but when i click it
  nothing happens. When have i done wrong? How can i get my button
  to execute the slot?
 
  You should get the Hello printed in console on start up, don't
  you?
 
  See below.

 It prints nothing in the console when i start up...

Ah, of course not. 

See below.

  thanks for the help ... sorry if this is a stupid question ;)
 
  Here is the code:
 
 
  # Form implementation generated from reading ui file
  '/home/magnus/eric/test/testui.ui'
  #
  # Created: Mon Aug  1 22:16:17 2011
  #      by: PyQt4 UI code generator 4.8.4
  #
  # WARNING! All changes made in this file will be lost!
 
  from PyQt4 import QtCore, QtGui
 
  try:
      _fromUtf8 = QtCore.QString.fromUtf8
  except AttributeError:
      _fromUtf8 = lambda s: s
 
  class Ui_Dialog(object):
      def setupUi(self, Dialog):
          Dialog.setObjectName(_fromUtf8(Dialog))
          Dialog.resize(400, 300)
          self.pushButton = QtGui.QPushButton(Dialog)
          self.pushButton.setGeometry(QtCore.QRect(140, 130, 83,
  25)) self.pushButton.setObjectName(_fromUtf8(pushButton))
 
          self.retranslateUi(Dialog)
          QtCore.QMetaObject.connectSlotsByName(Dialog)
 
      def retranslateUi(self, Dialog):
         
  Dialog.setWindowTitle(QtGui.QApplication.translate(Dialog,
  Dialog, None, QtGui.QApplication.UnicodeUTF8))
 
  self.pushButton.setText(QtGui.QApplication.translate(Dialog,
  PushButton, None, QtGui.QApplication.UnicodeUTF8))
 
 
  if __name__ == __main__:
      import sys
      app = QtGui.QApplication(sys.argv)
      Dialog = QtGui.QDialog()
      ui = Ui_Dialog()
      ui.setupUi(Dialog)
      Dialog.show()
      sys.exit(app.exec_())
 
 
  --
 ---
  --
 
  --
 
 
 
  # -*- coding: utf-8 -*-
 
  
  Module implementing Dialog.
  
 
  from PyQt4.QtCore import *
  from PyQt4.QtGui import QDialog
 
  from .Ui_testui import Ui_Dialog
 
  class Dialog(QDialog, Ui_Dialog):
      
      Class documentation goes here.
      
      def __init__(self, parent = None):
          
          Constructor
 
          @param parent reference to the parent widget (QWidget)
          
          QDialog.__init__(self, parent)
          self.setupUi(self)
          QtCore.QObject.connect(self.pushButton,
  QtCore.SIGNAL(_fromUtf8(clicked())),
  self.on_pushButton_clicked())

 This was an attempt to get it to work. I added this and forgot to
 remove it. What i understand of the tutorial, the bindings to the
 slots would be done automatic by this line in  the script above
 QtCore.QMetaObject.connectSlotsByName(Dialog).

Yes. For that reason, if you try my fixed script, you get the Hello 
twice, once from the manual connection, and one from the automatic 
connection.

 I think my question 
 is why this is not working.

Your app is missing a major part: the usual if __name__ is __main__:
Check out the ui file. Not only it carries some such, it is also using 
sane import clauses. 

                                         
   self.pushButton.clicked.connect(self.on_pushButton_clicked)      
                    ^^ You're calling the signal handler here,
  resulting in connecting the signal to None. While at it, use the
  new style signals/slots:
 
         self.pushButton.clicked.connect(self.on_pushButton_clicked)
 
  Looking much nicer, doesn't it?

 Yes ... it looks much nicer... I tried to replace my line with yours
 but still no joy... still the same result... nothing happens. if i
 press the pushbutton a couple of times i get this message in the
 console:

 QDialog::exec: Recursive call detected

 When i start to get it ... it appears on every click.

This is confusing. You need to run the testui.py script, not the 
Ui_testui.py script for this to work. The latter is just the dialog 

Re: [PyQt] Trying to learn ...

2011-08-02 Thread Magnus Wirström
2011/8/2 Hans-Peter Jansen h...@urpla.net:
 Magnus, please keep the conversation on the ML or CC at the very least.
 Others might want to participate.

 My personal preference is to NOT receive personal copies.

Sorry ... first time using mailing list so i just used reply button,
my bad. Forgive me


 On Tuesday 02 August 2011, 11:20:15 Magnus Wirström wrote:
 2011/8/2 Hans-Peter Jansen h...@urpla.net:
  On Monday 01 August 2011, 22:20:32 Magnus Wirström wrote:
  Hi
 
  I am sorry if this have been asked before :)
 
  I am trying to learn using python and pyqt using ERIC 5.1.2. I
  have a problem with signals and slots. I tried this on 2 different
  computer with different OS and different version of python. My
  problem is this...
 
  I am creating a test project using Eric ... using one of the
  tuturials on Eric's webpage. I create a project and a form, then i
  add a push button. I save the form and i generate the form into
  code using Eric I also generate dialog code and adding a slot for
  my push button. So far i have not written a single line of code.
  In my slot i write a print(Hello), My only self written code.
  When i run this, i get a window with my button but when i click it
  nothing happens. When have i done wrong? How can i get my button
  to execute the slot?
 
  You should get the Hello printed in console on start up, don't
  you?
 
  See below.

 It prints nothing in the console when i start up...

 Ah, of course not.

 See below.

  thanks for the help ... sorry if this is a stupid question ;)
 
  Here is the code:
 
 
  # Form implementation generated from reading ui file
  '/home/magnus/eric/test/testui.ui'
  #
  # Created: Mon Aug  1 22:16:17 2011
  #      by: PyQt4 UI code generator 4.8.4
  #
  # WARNING! All changes made in this file will be lost!
 
  from PyQt4 import QtCore, QtGui
 
  try:
      _fromUtf8 = QtCore.QString.fromUtf8
  except AttributeError:
      _fromUtf8 = lambda s: s
 
  class Ui_Dialog(object):
      def setupUi(self, Dialog):
          Dialog.setObjectName(_fromUtf8(Dialog))
          Dialog.resize(400, 300)
          self.pushButton = QtGui.QPushButton(Dialog)
          self.pushButton.setGeometry(QtCore.QRect(140, 130, 83,
  25)) self.pushButton.setObjectName(_fromUtf8(pushButton))
 
          self.retranslateUi(Dialog)
          QtCore.QMetaObject.connectSlotsByName(Dialog)
 
      def retranslateUi(self, Dialog):
 
  Dialog.setWindowTitle(QtGui.QApplication.translate(Dialog,
  Dialog, None, QtGui.QApplication.UnicodeUTF8))
 
  self.pushButton.setText(QtGui.QApplication.translate(Dialog,
  PushButton, None, QtGui.QApplication.UnicodeUTF8))
 
 
  if __name__ == __main__:
      import sys
      app = QtGui.QApplication(sys.argv)
      Dialog = QtGui.QDialog()
      ui = Ui_Dialog()
      ui.setupUi(Dialog)
      Dialog.show()
      sys.exit(app.exec_())
 
 
  --
 ---
  --
 
  --
 
 
 
  # -*- coding: utf-8 -*-
 
  
  Module implementing Dialog.
  
 
  from PyQt4.QtCore import *
  from PyQt4.QtGui import QDialog
 
  from .Ui_testui import Ui_Dialog
 
  class Dialog(QDialog, Ui_Dialog):
      
      Class documentation goes here.
      
      def __init__(self, parent = None):
          
          Constructor
 
          @param parent reference to the parent widget (QWidget)
          
          QDialog.__init__(self, parent)
          self.setupUi(self)
          QtCore.QObject.connect(self.pushButton,
  QtCore.SIGNAL(_fromUtf8(clicked())),
  self.on_pushButton_clicked())

 This was an attempt to get it to work. I added this and forgot to
 remove it. What i understand of the tutorial, the bindings to the
 slots would be done automatic by this line in  the script above
 QtCore.QMetaObject.connectSlotsByName(Dialog).

 Yes. For that reason, if you try my fixed script, you get the Hello
 twice, once from the manual connection, and one from the automatic
 connection.

 I think my question
 is why this is not working.

 Your app is missing a major part: the usual if __name__ is __main__:
 Check out the ui file. Not only it carries some such, it is also using
 sane import clauses.


This seems to do the trick ... i have now an working app that responds
to signals
Thanks for the help :)

I will now try to learn pyqt :)
Magnus


 
   self.pushButton.clicked.connect(self.on_pushButton_clicked)
                    ^^ You're calling the signal handler here,
  resulting in connecting the signal to None. While at it, use the
  new style signals/slots:
 
         self.pushButton.clicked.connect(self.on_pushButton_clicked)
 
  Looking much nicer, doesn't it?

 Yes ... it looks much nicer... I tried to replace my line with yours
 but still no joy... still the same result... nothing happens. if i
 press the pushbutton a couple of times i get this message in the
 console:

 

Re: [PyQt] Trying to learn ...

2011-08-02 Thread Algis Kabaila
On Tue, 2 Aug 2011 08:38:21 PM Hans-Peter Jansen wrote:
 Magnus, please keep the conversation on the ML or CC at the very least.
 Others might want to participate.
 
 My personal preference is to NOT receive personal copies.
 
 On Tuesday 02 August 2011, 11:20:15 Magnus Wirström wrote:
  2011/8/2 Hans-Peter Jansen h...@urpla.net:
   On Monday 01 August 2011, 22:20:32 Magnus Wirström wrote:
   Hi
   
   I am sorry if this have been asked before :)
   
   I am trying to learn using python and pyqt using ERIC 5.1.2. I
   have a problem with signals and slots. I tried this on 2 different
   computer with different OS and different version of python. My
   problem is this...
   
   I am creating a test project using Eric ... using one of the
   tuturials on Eric's webpage. I create a project and a form, then i
   add a push button. I save the form and i generate the form into
   code using Eric I also generate dialog code and adding a slot for
   my push button. So far i have not written a single line of code.
   In my slot i write a print(Hello), My only self written code.
   When i run this, i get a window with my button but when i click it
   nothing happens. When have i done wrong? How can i get my button
   to execute the slot?
   
   You should get the Hello printed in console on start up, don't
   you?
   
   See below.
  
  It prints nothing in the console when i start up...
 
 Ah, of course not.
 
 See below.
 
   thanks for the help ... sorry if this is a stupid question ;)
   
   Here is the code:
   
   
   # Form implementation generated from reading ui file
   '/home/magnus/eric/test/testui.ui'
   #
   # Created: Mon Aug  1 22:16:17 2011
   #  by: PyQt4 UI code generator 4.8.4
   #
   # WARNING! All changes made in this file will be lost!
   
   from PyQt4 import QtCore, QtGui
   
   try:
   _fromUtf8 = QtCore.QString.fromUtf8
   except AttributeError:
   _fromUtf8 = lambda s: s
   
   class Ui_Dialog(object):
   def setupUi(self, Dialog):
   Dialog.setObjectName(_fromUtf8(Dialog))
   Dialog.resize(400, 300)
   self.pushButton = QtGui.QPushButton(Dialog)
   self.pushButton.setGeometry(QtCore.QRect(140, 130, 83,
   25)) self.pushButton.setObjectName(_fromUtf8(pushButton))
   
   self.retranslateUi(Dialog)
   QtCore.QMetaObject.connectSlotsByName(Dialog)
   
   def retranslateUi(self, Dialog):
  
   Dialog.setWindowTitle(QtGui.QApplication.translate(Dialog,
   Dialog, None, QtGui.QApplication.UnicodeUTF8))
   
   self.pushButton.setText(QtGui.QApplication.translate(Dialog,
   PushButton, None, QtGui.QApplication.UnicodeUTF8))
   
   
   if __name__ == __main__:
   import sys
   app = QtGui.QApplication(sys.argv)
   Dialog = QtGui.QDialog()
   ui = Ui_Dialog()
   ui.setupUi(Dialog)
   Dialog.show()
   sys.exit(app.exec_())
   
   
   --
  
  ---
  
   --
  
  
  
   --
  
  
  
   # -*- coding: utf-8 -*-
   
   
   Module implementing Dialog.
   
   
   from PyQt4.QtCore import *
   from PyQt4.QtGui import QDialog
   
   from .Ui_testui import Ui_Dialog
   
   class Dialog(QDialog, Ui_Dialog):
   
   Class documentation goes here.
   
   def __init__(self, parent = None):
   
   Constructor
   
   @param parent reference to the parent widget (QWidget)
   
   QDialog.__init__(self, parent)
   self.setupUi(self)
   QtCore.QObject.connect(self.pushButton,
   QtCore.SIGNAL(_fromUtf8(clicked())),
   self.on_pushButton_clicked())
  
  This was an attempt to get it to work. I added this and forgot to
  remove it. What i understand of the tutorial, the bindings to the
  slots would be done automatic by this line in  the script above
  QtCore.QMetaObject.connectSlotsByName(Dialog).
 
 Yes. For that reason, if you try my fixed script, you get the Hello
 twice, once from the manual connection, and one from the automatic
 connection.
 
  I think my question
  is why this is not working.
 
 Your app is missing a major part: the usual if __name__ is __main__:
 Check out the ui file. Not only it carries some such, it is also using
 sane import clauses.
 
  
self.pushButton.clicked.connect(self.on_pushButton_clicked)  
 ^^ You're calling the signal handler here,
   resulting in connecting the signal to None. While at it, use the
   new style signals/slots:
   
  self.pushButton.clicked.connect(self.on_pushButton_clicked)
   
   Looking much nicer, doesn't it?
  
  Yes ... it looks much nicer... I tried to replace my line with yours
  but still no joy... still the same result... nothing happens. if i
  press the pushbutton a couple of times i get this message in the
  

[PyQt] Trying to learn ...

2011-08-01 Thread Magnus Wirström
Hi

I am sorry if this have been asked before :)

I am trying to learn using python and pyqt using ERIC 5.1.2. I have a
problem with signals and slots. I tried this on 2 different computer
with different OS and different version of python. My problem is
this...

I am creating a test project using Eric ... using one of the
tuturials on Eric's webpage. I create a project and a form, then i add
a push button. I save the form and i generate the form into code using
Eric I also generate dialog code and adding a slot for my push button.
So far i have not written a single line of code. In my slot i write a
print(Hello), My only self written code. When i run this, i get a
window with my button but when i click it nothing happens. When have i
done wrong? How can i get my button to execute the slot?

thanks for the help ... sorry if this is a stupid question ;)

Here is the code:


# Form implementation generated from reading ui file
'/home/magnus/eric/test/testui.ui'
#
# Created: Mon Aug  1 22:16:17 2011
#  by: PyQt4 UI code generator 4.8.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s

class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8(Dialog))
Dialog.resize(400, 300)
self.pushButton = QtGui.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(140, 130, 83, 25))
self.pushButton.setObjectName(_fromUtf8(pushButton))

self.retranslateUi(Dialog)
QtCore.QObject.connect(self.pushButton,
QtCore.SIGNAL(_fromUtf8(clicked())), Dialog.exec)
QtCore.QMetaObject.connectSlotsByName(Dialog)

def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QtGui.QApplication.translate(Dialog,
Dialog, None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate(Dialog,
PushButton, None, QtGui.QApplication.UnicodeUTF8))


if __name__ == __main__:
import sys
app = QtGui.QApplication(sys.argv)
Dialog = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())


-


# -*- coding: utf-8 -*-


Module implementing Dialog.


from PyQt4.QtCore import *
from PyQt4.QtGui import QDialog

from .Ui_testui import Ui_Dialog

class Dialog(QDialog, Ui_Dialog):

Class documentation goes here.

def __init__(self, parent = None):

Constructor

@param parent reference to the parent widget (QWidget)

QDialog.__init__(self, parent)
self.setupUi(self)
QtCore.QObject.connect(self.pushButton,
QtCore.SIGNAL(_fromUtf8(clicked())), self.on_pushButton_clicked())

@pyqtSlot()
def on_pushButton_clicked(self):

Slot documentation goes here.

print(hello)
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Trying to learn ...

2011-08-01 Thread Hans-Peter Jansen
On Monday 01 August 2011, 22:20:32 Magnus Wirström wrote:
 Hi

 I am sorry if this have been asked before :)

 I am trying to learn using python and pyqt using ERIC 5.1.2. I have a
 problem with signals and slots. I tried this on 2 different computer
 with different OS and different version of python. My problem is
 this...

 I am creating a test project using Eric ... using one of the
 tuturials on Eric's webpage. I create a project and a form, then i
 add a push button. I save the form and i generate the form into code
 using Eric I also generate dialog code and adding a slot for my push
 button. So far i have not written a single line of code. In my slot i
 write a print(Hello), My only self written code. When i run this, i
 get a window with my button but when i click it nothing happens. When
 have i done wrong? How can i get my button to execute the slot?

You should get the Hello printed in console on start up, don't you?

See below.

 thanks for the help ... sorry if this is a stupid question ;)

 Here is the code:


 # Form implementation generated from reading ui file
 '/home/magnus/eric/test/testui.ui'
 #
 # Created: Mon Aug  1 22:16:17 2011
 #  by: PyQt4 UI code generator 4.8.4
 #
 # WARNING! All changes made in this file will be lost!

 from PyQt4 import QtCore, QtGui

 try:
 _fromUtf8 = QtCore.QString.fromUtf8
 except AttributeError:
 _fromUtf8 = lambda s: s

 class Ui_Dialog(object):
 def setupUi(self, Dialog):
 Dialog.setObjectName(_fromUtf8(Dialog))
 Dialog.resize(400, 300)
 self.pushButton = QtGui.QPushButton(Dialog)
 self.pushButton.setGeometry(QtCore.QRect(140, 130, 83, 25))
 self.pushButton.setObjectName(_fromUtf8(pushButton))

 self.retranslateUi(Dialog)
 QtCore.QObject.connect(self.pushButton,
 QtCore.SIGNAL(_fromUtf8(clicked())), Dialog.exec)
 QtCore.QMetaObject.connectSlotsByName(Dialog)

 def retranslateUi(self, Dialog):
 Dialog.setWindowTitle(QtGui.QApplication.translate(Dialog,
 Dialog, None, QtGui.QApplication.UnicodeUTF8))

 self.pushButton.setText(QtGui.QApplication.translate(Dialog,
 PushButton, None, QtGui.QApplication.UnicodeUTF8))


 if __name__ == __main__:
 import sys
 app = QtGui.QApplication(sys.argv)
 Dialog = QtGui.QDialog()
 ui = Ui_Dialog()
 ui.setupUi(Dialog)
 Dialog.show()
 sys.exit(app.exec_())


 -
--
--


 # -*- coding: utf-8 -*-

 
 Module implementing Dialog.
 

 from PyQt4.QtCore import *
 from PyQt4.QtGui import QDialog

 from .Ui_testui import Ui_Dialog

 class Dialog(QDialog, Ui_Dialog):
 
 Class documentation goes here.
 
 def __init__(self, parent = None):
 
 Constructor

 @param parent reference to the parent widget (QWidget)
 
 QDialog.__init__(self, parent)
 self.setupUi(self)
 QtCore.QObject.connect(self.pushButton,
 QtCore.SIGNAL(_fromUtf8(clicked())), self.on_pushButton_clicked())

   ^^
You're calling the signal handler here, resulting in connecting the 
signal to None. While at it, use the new style signals/slots:

self.pushButton.clicked.connect(self.on_pushButton_clicked)

Looking much nicer, doesn't it? 

(new, as in only a couple of years old…)

And it should do, what you want, does it?

 @pyqtSlot()
 def on_pushButton_clicked(self):
 
 Slot documentation goes here.
 
 print(hello)

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