[PyQt] how to use the button to control the program

2013-07-30 Thread 吉文
Hi,all, I want to use a button to control when the program start in pyqt4,
in other words, when I press the start button, the program will work. I
wrote some code, but it doesn't work. please help me to correct it. Thanks
in advance.

Best regards
Harry

import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
import time

class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()

def initUI(self):

nowtime = '-00-00 00:00:00'
timeEdit = QtGui.QLabel(str(nowtime),self)
timeEdit.resize(timeEdit.sizeHint())
timeEdit.move(110,30)

QtCore.QTimer.singleShot(1000,lambda:self.newtime(timeEdit))

startbtn = QtGui.QPushButton('Start', self)
startbtn.setToolTip('Click it to start the program')
startbtn.clicked.connect(self.newtime(timeEdit))
startbtn.resize(startbtn.sizeHint())
startbtn.move(200, 340)

qbtn = QtGui.QPushButton('Quit', self)
qbtn.setToolTip('Click it and quit the program')
qbtn.clicked.connect(QtCore.QCoreApplication.instance().quit)
qbtn.resize(qbtn.sizeHint())
qbtn.move(400, 340)

self.setGeometry(300, 200, 600, 400)
self.setWindowTitle('Battery status')
self.show()

def newtime(self,timeEdit):
nowtime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
timeEdit.setText(str(nowtime))
QtCore.QTimer.singleShot(1000,lambda:self.newtime(timeEdit))

def main():

app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())

if __name__ == '__main__':
main()

*when executing the program, there is something wrong:*
**
*Traceback (most recent call last):
  File "C:\Python\calendar.py", line 62, in 
main()
  File "C:\Python\calendar.py", line 57, in main
ex = Example()
  File "C:\Python\calendar.py", line 15, in __init__
self.initUI()
  File "C:\Python\calendar.py", line 32, in initUI
startbtn.clicked.connect(self.newtime(timeEdit))
TypeError: connect() slot argument should be a callable or a signal, not
'NoneType'*
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] PyQt5.uic.loadUi sometimes fails when connecting signals

2013-07-30 Thread Roger Leigh
Hi all,

I'm getting this error when I use loadUi():

Traceback (most recent call last):
  File "./testui", line 26, in 
t = Test()
  File "./testui", line 13, in __init__
self.ui = uic.loadUi("test-broken.ui", self)
  File "/usr/lib/python3/dist-packages/PyQt5/uic/__init__.py", line 224, in 
loadUi
return DynamicUILoader(package).loadUi(uifile, baseinstance, 
resource_suffix)
  File "/usr/lib/python3/dist-packages/PyQt5/uic/Loader/loader.py", line 72, in 
loadUi
return self.parse(filename, resource_suffix, basedir)
  File "/usr/lib/python3/dist-packages/PyQt5/uic/uiparser.py", line 931, in 
parse
actor(elem)
  File "/usr/lib/python3/dist-packages/PyQt5/uic/uiparser.py", line 856, in 
createConnections
bound_signal.connect(slot)
SystemError: error return without exception set

I've narrowed this down to occuring when I've added custom slots in
the ui designer.  However, it doesn't always occur, and I can't see
any obvious reasons for failure.

I've attached the most minimal testcase I can make.  The testui
program just loads one of the two attached .ui files.  One works,
one fails.  The only difference is one line which changes which
slot gets used.  However, both slots are absolutely identical,
and I can't see any reason for the failure unless either of the
names is somehow "special".

The code from which the testcase was derived is here:
http://anonscm.debian.org/gitweb/?p=users/rleigh/ogcalc.git;a=tree;f=qt/python;h=0d60c1c99d0438096badb186a030f166202e1a98;hb=341b96685f3abe92e78fd7768fc5c5893ce5b5ee
(ogcalc-ui, ogcalc.ui, SpinBoxEntry.py).  In this example both
the reset and calculate callbacks cause the failure; removing the
signal connection for both makes the UI load.  But if I remove
widgets from the UI to get to the minimal example above, it
eventually will start working by the time I'm down to the
minimal example above.


Being relatively new to both Qt and PyQt, I'm unsure if this isn't
me doing something wrong, but I can't see anything obviously bad
here so I'm wondering if I'm tripping over some odd edge case in
how the signal autoconnection works.  Either way, I'd be very
keen to understand what's going wrong here.

I'm using Python 3.3/Qt 5.1/PyQt 5.0 on Debian (unstable, amd64).


Thanks all,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?   http://gutenprint.sourceforge.net/
   `-GPG Public Key: 0x25BFB848   Please GPG sign your mail.
#!/usr/bin/python3

from PyQt5 import uic
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtGui import (QFont, QIcon)
from PyQt5.QtWidgets import (QApplication, QMainWindow)

class Test(QMainWindow):
def __init__(self):
super(Test, self).__init__()

#self.ui = uic.loadUi("test-ok.ui", self)
self.ui = uic.loadUi("test-broken.ui", self)

@pyqtSlot()
def calculate(self):
print("Calc")

@pyqtSlot()
def reset(self):
print("Reset")

if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
t = Test()
t.show()
sys.exit(app.exec())


 ogcalc
 
  
   
0
0
407
123
   
  
  
   
0
0
   
  
  
   
16777215
16777215
   
  
  
   OG & ABV calculator
  
  
   
ogcalc.svgogcalc.svg
  
  
   

 0
 0

   
   

 
  
   Reset
  
 

   
  
 
 
 
 
  
   reset
   clicked()
   ogcalc
   calculate()
   

 203
 102


 203
 61

   
  
 
 
  calculate()
  reset()
 



 ogcalc
 
  
   
0
0
407
123
   
  
  
   
0
0
   
  
  
   
16777215
16777215
   
  
  
   OG & ABV calculator
  
  
   
ogcalc.svgogcalc.svg
  
  
   

 0
 0

   
   

 
  
   Reset
  
 

   
  
 
 
 
 
  
   reset
   clicked()
   ogcalc
   reset()
   

 203
 102


 203
 61

   
  
 
 
  calculate()
  reset()
 



signature.asc
Description: Digital signature
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] Using SIP wrappers for extension modules in python IDEs

2013-07-30 Thread Kenneth Miller
So, I found out that there are some .api files that the tool that I'm using 
loads and parses. I'm pretty sure that SIP more than likely generated these, 
but I'm not sure because I'm not the most familiar with SIP. I updated the 
stack overflow question, but I'm pretty sure that the answer is no, Emacs 
doesn't support loading external modules' interface file via the .api files... 
I just want to make sure...



 From: Kenneth Miller 
To: "pyqt@riverbankcomputing.com"  
Sent: Monday, July 29, 2013 7:56 PM
Subject: [PyQt] Using SIP wrappers for extension modules in python IDEs
 


I thought that it would be good for me to alert the good folks at pyqt, but 
better that I should post my question somewhere so that if it gets revised or 
something I can make sure that all see the changes. Please see my SIP related 
question:

http://stackoverflow.com/questions/17936075/how-to-make-functions-in-python-extension-module-visible-to-emacs

Thanks so much 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] Issue compiling latest PyQt5 snapshot on Linux

2013-07-30 Thread Detlev Offenbach
Hello,

compiling latest PyQt5 snapshot on Linux fails because 
file  qpyqmlsingletonobject.h contains an include 
statement for QQMlEngine. However, that should read 
QQmlEngine, i.e. lowercase M.

Detlev-- 
*Detlev Offenbach*
det...@die-offenbachs.de
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt