Open sf-migrator-bot opened 10 years ago
I like the idea! I prefer something like the first option. The weak point is if somebody does this kind of program:
import PyQt4.QtDesigner
import taurus.qt.QtGui
# ...
I propose here what I believe is a safer implementation:
I think we could have in taurus.qt.QtGui an API to check/set if in QtDesigner:
# taurus/qt/QtGui/__init__.py
__designerMode = False
def isDesignerMode():
global __designerMode
return __designerMode
def setDesignerMode(yesno):
global __designerMode
__designerMode = yesno
When QtDesigner starts, it imports taurus.qt.qtdesigner.tauruspluginplugin. The taurus.qt.qtdesigner.tauruspluginplugin could set the designer mode to True:
# taurus/qt/qtdesigner/tauruspluginplugin.py
from taurus.qt.QtGui import setDesignerMode
def main()
setDesignerMode(True)
# ...
The widgets could check if they are in QtDesigner if needed by doing:
# mywidget.py
from taurus.qt.QtGui import isDesignerMode
class MyWidget(...):
def __init__(self, parent=None):
# ...
designerMode = isDesignerMode()
if designerMode:
# ...
else:
# ...
# ...
Original comment by: tiagocoutinho (http://sourceforge.net/u/tiagocoutinho)
I like that!
Original comment by: cpascual (http://sourceforge.net/u/cpascual)
Original comment by: cpascual (http://sourceforge.net/u/cpascual)
Using designMode as constructor parameter is not very nice. If you create a widget by composition and use it with QtDesigner (*) , the children of the widget will not be in designerMode and it will create a mess.
(*) for example by importing a .ui file. But in pure python code, providing designerMode everywhere it is needed is also a mess.
One way to fix that, the one i use with the help of Tiago is to check the modules:
It does not support all the cases, but it can be improved
Another way is to inject the context to the class when we create the QtDesignerPlugin
And using something like that on the class:
Reported by: vallsv ( http://sf.net/u/valentinvalls )