下面是Python程序的概要(使用PyQt4):class Polygon( QtGui.QGraphicsItem ):
def __init__(self):
super(Polygon, self).__init__()
def addpoint( self, point ):
if last_point:
# trying to add auto-save here
class MainWidget(QtGui.QWidget):
openFileName = ""
list_of_polygons = []
def __init__(self):
super(MainWidget, self).__init__()
def openFile( self ):
call dialog
self.openFileName = ...
def saveFile( self ):
# needs to access a couple something with self.variables, like self.openFileName
def main():
app = QtGui.QApplication(sys.argv)
ex = MainWidget()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
功能是一个图像查看器,我在其中创建多边形来标记对象。我想在创建多边形后调用自动保存。在
所以为了保存多边形,我需要从saveFile函数MainWidget类调用它。我的问题是保存功能是在MainWidget类中实现的,我不知道如何从Polygon类内部访问它们。在
最好的办法是什么?是否应将saveFile设为全局?如果是,那么我如何进入自我。MainWidget的变量?在