pyqt4 - python pyqt interactive usuage -


i use edit functions defining slots while pyqt gui running can debug program without having restart it. example of have is, after importing py file generated pyuic

##-------------------------##  app=qapplication([]) window = qmainwindow() window.show() ui = ui_mainwindow() ui.setupui(window) ##-------------------------## def helloworld():      print "hi"  ui.pushbutton.clicked.connect(helloworld) 

now, after starting program can execute commands in console. after running program, redefine helloworld function using console

def helloworld():     print "goodbye" 

however, if this, both "hi" , "goodbye" both printed. "goodbye" printed.

i going use feature debug functions, while gui live. using spyder ide python 2.7.6 , pyqt4

edit:

after redefining function, reconnect slot. thereby, clicked action results in executing old function (printing "hi") , new function (printing "goodbye")

redefining function not disconnect original signal , not destroy original function. creates new function same name, preventing access original function not hold reference it. qt has reference, both functions called (i assume connect new function button?)

one way solve explicitly call ui.pushbutton.clicked.disconnect(helloworld) before redefining function.

alternatively, wrap function in another:

def wrap(*args, **kwargs):     return helloworld(*args, **kwargs)  ui.pushbutton.clicked.connect(wrap) 

then redefining helloworld have desired effect.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -