def init_view(self): self.btree_scene = QGraphicsScene() self.btree_view = NodeEditorView(self.btree_scene) self.btree_view.setAttribute(Qt.WA_DeleteOnClose) self.btree_scene.setSceneRect(AREA) self.vm = NodeEditorVM(self.model, self.btree_view, self.btree_scene, self)
class BTreeInstanceVM(object): def __init__(self, model, parent, file_name): self.file_name = file_name self.file_path = os.path.abspath(file_name) self.modified = False self.model = model self.parent = parent self.current_graphics_node = None self.init_view() self.sub_window = parent.mdi.addSubWindow(self.btree_view) self.sub_window.instance = self self.sub_window.setAttribute(Qt.WA_DeleteOnClose) self.update_title() self.btree_view.closeEvent = self.close_handler parent.add_instance(self) self.sub_window.show() self.vm.refresh() def init_view(self): self.btree_scene = QGraphicsScene() self.btree_view = NodeEditorView(self.btree_scene) self.btree_view.setAttribute(Qt.WA_DeleteOnClose) self.btree_scene.setSceneRect(AREA) self.vm = NodeEditorVM(self.model, self.btree_view, self.btree_scene, self) def set_dirty(self): self.set_modified(True) def set_modified(self, b): self.modified = b self.sub_window.setWindowModified(b) def update_title(self): self.sub_window.setWindowTitle(self.file_path + "[*]") def close_handler(self, ev): if self.modified: ret = QMessageBox().question( self.btree_view, "Confirm", "close without saving?", QMessageBox.Yes | QMessageBox.No) if ret == QMessageBox.No: ev.ignore() return self.parent.remove_instance(self) def activation_handler(self): #print("%s about to be activated" % self) pass def deactivation_handler(self): #print("%s about to be deactivated" % self) self.vm.cancel_selection() def focus_on(self, node_id): self.parent.mdi.setActiveSubWindow(self.sub_window) node = self.model.get_node(node_id) if node is None: return False self.vm.selected_node = node self.vm.refresh() return True
class BTreeInstanceVM(object): def __init__(self, model, parent, file_name): self.file_name = file_name self.file_path = os.path.abspath(file_name) self.modified = False self.model = model self.parent = parent self.current_graphics_node = None self.init_view() self.sub_window = parent.mdi.addSubWindow(self.btree_view) self.sub_window.instance = self self.sub_window.setAttribute(Qt.WA_DeleteOnClose) self.update_title() self.btree_view.closeEvent = self.close_handler parent.add_instance(self) self.sub_window.show() self.vm.refresh() def init_view(self): self.btree_scene = QGraphicsScene() self.btree_view = NodeEditorView(self.btree_scene) self.btree_view.setAttribute(Qt.WA_DeleteOnClose) self.btree_scene.setSceneRect(AREA) self.vm = NodeEditorVM(self.model, self.btree_view, self.btree_scene, self) def set_dirty(self): self.set_modified(True) def set_modified(self, b): self.modified = b self.sub_window.setWindowModified(b) def update_title(self): self.sub_window.setWindowTitle(self.file_path + "[*]") def close_handler(self, ev): if self.modified: ret = QMessageBox().question(self.btree_view, "Confirm", "close without saving?", QMessageBox.Yes | QMessageBox.No) if ret == QMessageBox.No: ev.ignore() return self.parent.remove_instance(self) def activation_handler(self): #print("%s about to be activated" % self) pass def deactivation_handler(self): #print("%s about to be deactivated" % self) self.vm.cancel_selection() def focus_on(self, node_id): self.parent.mdi.setActiveSubWindow(self.sub_window) node = self.model.get_node(node_id) if node is None: return False self.vm.selected_node = node self.vm.refresh() return True