def __init__(self, parent=None): super(TaskDesigner, self).__init__(parent) self.begin_selected = None self.end_selected = None self.setWindowTitle('Task Designer') self.main_layout = QtGui.QVBoxLayout() self.main_layout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.main_layout) self.toolbar = TaskToolBar() self.toolbar.buttonClicked.connect(self.on_toolbar_clicked) self.main_layout.addWidget(self.toolbar) # main area self.main_area = QtGui.QSplitter() self.main_area.setContentsMargins(10, 0, 10, 10) self.main_layout.addWidget(self.main_area) self.task_area = QtGui.QSplitter(QtCore.Qt.Vertical) self.main_area.addWidget(self.task_area) # 添加任务树 self.task_tree_model = tree_view.TaskTreeModel() self.task_tree_view = tree_view.TaskTreeView() self.task_tree_view.setModel(self.task_tree_model) self.task_area.addWidget(self.task_tree_view) self.workflow_editor = TaskWorkFlow() self.task_area.addWidget(self.workflow_editor) # 添加属性编辑器,时间线,流程图 self.task_editor = TaskEditor() self.task_editor.attrib_editor.save_task.connect(self.on_save_task) self.main_area.addWidget(self.task_editor) self.task_tree_view.clicked.connect(self.on_select_task) self.reset_layout()
class TaskDesigner(QtGui.QWidget): client = honey.client.HoneyClient() def __init__(self, parent=None): super(TaskDesigner, self).__init__(parent) self.begin_selected = None self.end_selected = None self.setWindowTitle('Task Designer') self.main_layout = QtGui.QVBoxLayout() self.main_layout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.main_layout) self.toolbar = TaskToolBar() self.toolbar.buttonClicked.connect(self.on_toolbar_clicked) self.main_layout.addWidget(self.toolbar) # main area self.main_area = QtGui.QSplitter() self.main_area.setContentsMargins(10, 0, 10, 10) self.main_layout.addWidget(self.main_area) self.task_area = QtGui.QSplitter(QtCore.Qt.Vertical) self.main_area.addWidget(self.task_area) # 添加任务树 self.task_tree_model = tree_view.TaskTreeModel() self.task_tree_view = tree_view.TaskTreeView() self.task_tree_view.setModel(self.task_tree_model) self.task_area.addWidget(self.task_tree_view) self.workflow_editor = TaskWorkFlow() self.task_area.addWidget(self.workflow_editor) # 添加属性编辑器,时间线,流程图 self.task_editor = TaskEditor() self.task_editor.attrib_editor.save_task.connect(self.on_save_task) self.main_area.addWidget(self.task_editor) self.task_tree_view.clicked.connect(self.on_select_task) self.reset_layout() def reset_layout(self): self.main_area.setSizes([self.width()*0.8, self.width()*0.2]) self.task_area.setSizes([self.height()*0.6, self.height()*0.4]) def on_toolbar_clicked(self, tool_name): if tool_name == "add": self.add_task() if tool_name == "delete_task": self.delete_task() if tool_name == "update": self.load() def get_selected_index(self): selects = self.task_tree_view.selectedIndexes() if selects: return selects[0] return None def load(self): self.client.load_project() self.task_tree_model.set_root(self.client.task_root) def add_task(self): dialog = attrib_editor.create_dialog(getattr(honey.task.Task, '__name__')) if not dialog: return False if dialog.exec_() == QtGui.QDialog.Accepted: data = dialog.get_api_data() parent_index = self.get_selected_index() parent_node = None if parent_index: parent_node = self.task_tree_model.get(parent_index) task = self.client.current_project.add_task(data, parent_node) if parent_index: self.task_tree_model.add(task, parent_index) self.task_tree_view.expand(parent_index) else: self.task_tree_model.add(task, QtCore.QModelIndex()) print "Add task %s successful." % str(task) return True return False def delete_task(self): sel_index = self.get_selected_index() if sel_index: task_node = self.task_tree_model.get(sel_index) conform_box = QtGui.QMessageBox.critical( None, u"删除确认", u"确认要删除任务 %s 么?" % str(task_node.obj), QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Cancel ) if conform_box == QtGui.QMessageBox.Ok: print "Remove task %s." % str(task_node.obj) self.task_tree_model.remove(sel_index) return True else: return False def clear_sel(self): self.task_tree_view.clearSelection() def on_select_task(self, index): selects = self.task_tree_view.selectedIndexes() if selects: self.begin_selected = selects[0] self.end_selected = selects[-1] self.client.current_task = self.task_tree_model.get_obj(index) self.task_editor.load() self.workflow_editor.add_test() def on_save_task(self): if self.begin_selected and self.end_selected: self.task_tree_model.changePersistentIndex(self.begin_selected, self.end_selected)