I have written a command line widget in my pyside program. The structure is like this:
class CommandWidget(QWidget):
def __init__(self, parent = None):
super(CommandWidget, self).__init__(parent)
self.buffer=PyInterp(self)
self.buffer.initInterpreter(locals())
self........
class PyInterp(QTextEdit):
class InteractiveInterpreter(code.InteractiveInterpreter):
def __init__(self, locals):
code.InteractiveInterpreter.__init__(self, locals)
def runIt(self, command):
code.InteractiveInterpreter.runsource(self, command)
def __init__(self, parent = None):
super(PyInterp, self).__init__(parent)
I also have a mainwindow program running together with some other widgets. My question is how can i import some functions in other widget class in this interpreter, run the function and output the result to the global space. Or in other words, I want to share some variables between the local space of the interpreter and the global mainwindow space. How can I achieve that ?
EDIT: This is the data type I want to put into a signal.
class PosType(QObject):
def __init__(self, nx, ny, nz, start_pos, type):
self.nx = nx
self.ny = ny
self.nz = nz
self.start_pos = start_pos
self.type = type
This is the signal.
class PosSig(QObject):
sig = Signal(PosType)
def emit_sig(self, pos_data):
self.sig.emit(pos_data)
This is the function I want to put into the interpreter, so that when it is called it will emit a signal.
def graphene(nx, ny, start_pos):
pos_info = PosType(nx = nx, ny = ny, nz = None, start_pos = start_pos, type = 1)
tmp_sig = PosSig()
tmp_sig.emit_sig(pos_info)
return
The above classes are in a file called ExposeFunc.py, and I plan to import this .py file in the interpreter, then call the graphene function to emit the signal.
In the mainwindow class, I have a slot.
def __init__(self):
#Interpreter Signals :
possig = PosSig()
possig.sig.connect(self.createObject)
@Slot(PosType)
def createObject(self, pos_info):
type = pos_info.type
if type == 1:
SharedItems.QS._FillData(pos_info.nx, pos_info.ny, start_pos)
return