예제 #1
0
class AHPTreeEditor(QtCore.QObject):
	def __init__(self, ahpFile, parent = None):
		QtCore.QObject.__init__(self)
		
		#构造组件
		self.ahpFile_ = ahpFile
		self.tree_ = AHPTree()
		self.tree_.LoadXml(ahpFile)
		self.widget_ = QtGui.QDialog(parent)
		self.ui_ = Ui_AHPEditor()
		self.ui_.setupUi(self.widget_)
		
		#挂接模型与菜单
		self.treeModel_ = AHPTreeModel(self.tree_)
		self.contextMenu_ = AHPTreeContextMenu(self.ui_.aphTreeView)

		self.ui_.aphTreeView.setModel(self.treeModel_)
	
		#挂接signal/slot
		self._SetupSlots()
		
	def _SetupSlots(self):
		self.connect(self.ui_.aphTreeView, QtCore.SIGNAL("doubleClicked (const QModelIndex&)"), self._OnEditMatrix)
		self.connect(self.ui_.applyBtn, QtCore.SIGNAL("clicked(bool)"), self._OnSaveToFile)
		self.connect(self.ui_.acceptBtn, QtCore.SIGNAL("clicked(bool)"), self._OnAccept)
		self.connect(self.ui_.btnRandGen, QtCore.SIGNAL("clicked(bool)"), self._OnRandomGen)
		
	def _OnEditMatrix(self, index):
		if not index.isValid(): return
		
		if index.column() != 0:
			curTreeItem = index.internalPointer()
			curNode = curTreeItem.ahpNode_
			if not curNode: return
			matEditor = AHPCmpTblEditor(curNode.ahpMat_)
			matEditor.dlg_.setWindowTitle("Comparison Table Editor")
			matEditor.ShowWidgetModal()
			curTreeItem.UpdateTree()
	
	def _OnRandomGen(self):
		randGen = AHPTreeRandGenEditor(self.tree_)
		randGen.ShowWidgetModal()
		self.treeModel_.reset()
			
	def _OnSaveToFile(self, b):
		self.tree_.SaveXml(self.ahpFile_)
		self.tree_.SaveCriteriaToXmlFile(os.path.join(os.path.dirname(self.ahpFile_), "Criteria.xml"))
		
	def _OnAccept(self, b):
		self._OnSaveToFile(b)
		self.widget_.accept()
		
	def ShowWidget(self):
		self.widget_.show()
	
	def ShowWidgetModel(self):
		result = self.widget_.exec_()
		if result == QtGui.QDialog.Accepted:
			self._OnSaveToFile(True)
예제 #2
0
	def __init__(self, ahpFile, parent = None):
		QtCore.QObject.__init__(self)
		
		#构造组件
		self.ahpFile_ = ahpFile
		self.tree_ = AHPTree()
		self.tree_.LoadXml(ahpFile)
		self.widget_ = QtGui.QDialog(parent)
		self.ui_ = Ui_AHPEditor()
		self.ui_.setupUi(self.widget_)
		
		#挂接模型与菜单
		self.treeModel_ = AHPTreeModel(self.tree_)
		self.contextMenu_ = AHPTreeContextMenu(self.ui_.aphTreeView)

		self.ui_.aphTreeView.setModel(self.treeModel_)
	
		#挂接signal/slot
		self._SetupSlots()