def handle_drag_release(self, index, drag_widget): if drag_widget.drag_cls in ('stage_spinner', 'stage'): if drag_widget.drag_cls == 'stage_spinner': stage = self.stage_factory.stage_names[ drag_widget.obj_dragged.text] else: # we dragged a stage so we need to copy it stage = drag_widget.obj_dragged.stage if isinstance(stage, CeedStageRef): stage = stage.stage stage = deepcopy(stage) self.stage_factory.add_stage(stage, allow_last_experiment=False) self.show_stage(stage) return # otherwise, create a new empty stage stage = CeedStage( stage_factory=self.stage_factory, function_factory=self.stage_factory.function_factory, shape_factory=self.stage_factory.shape_factory) self.stage_factory.add_stage(stage, allow_last_experiment=False) self.show_stage(stage) widget = stage.display # what did we drag, function, shape, or stage into stage? if drag_widget.drag_cls in ('func', 'func_spinner'): func_widget = StageFuncChildrenList.handle_func_drag_release( index, drag_widget, self, stage) widget.func_widget.add_widget(func_widget, index=index) elif drag_widget.drag_cls in ('shape', 'shape_group'): shape_factory = self.stage_factory.shape_factory if drag_widget.drag_cls == 'shape': item = drag_widget.obj_dragged.shape selection = shape_factory.selected_shapes elif drag_widget.drag_cls == 'shape_group': item = drag_widget.obj_dragged.group selection = shape_factory.selected_groups else: assert False shape = stage.add_shape(item) if shape is not None: self.show_shape_in_stage(stage, shape) if drag_widget.obj_dragged.selected: for shape in selection: shape = stage.add_shape(shape) if shape is not None: self.show_shape_in_stage(stage, shape) else: assert False
def assert_stages_same(stage1: CeedStage, stage2: CeedStage, compare_name=False): assert isinstance(stage1, stage2.__class__) keys = set(stage1.get_state().keys()) | set(stage2.get_state().keys()) assert 'name' in keys if not compare_name: keys.remove('name') for key in keys: if key in ('stages', 'functions', 'shapes', 'cls'): continue assert getattr(stage1, key) == getattr(stage2, key)
def add_empty_stage(self) -> CeedStage: """Creates and adds a new stage to the :attr:`stage_factory`. The stage is added as a child of any stage currently selected in the GUI, or globally if non is selected. :return: The newly created stage. """ stage = CeedStage(stage_factory=self.stage_factory, function_factory=self.stage_factory.function_factory, shape_factory=self.stage_factory.shape_factory) if self.selected_nodes: stage_widget = self.selected_nodes[-1] stage_widget.stage.add_stage(stage) self.show_sub_stage(stage, stage_widget.stage) else: self.stage_factory.add_stage(stage, allow_last_experiment=False) self.show_stage(stage) return stage
def create_stage(self): stage = self.stage = CeedStage( stage_factory=self.stage_factory, function_factory=self.stage_factory.function_factory, shape_factory=self.stage_factory.shape_factory, name=self.name, order=self.order, complete_on=self.complete_on, color_r=self.color_r, color_g=self.color_g, color_b=self.color_b, color_a=self.color_a) for shape in self.shapes: if isinstance(shape, Shape): stage.add_shape(shape.shape) else: stage.add_shape(shape) for func in self.functions: stage.add_func(func.func)
def make_stage(stage_factory: StageFactoryBase, **kwargs) -> CeedStage: return CeedStage(stage_factory=stage_factory, function_factory=stage_factory.function_factory, shape_factory=stage_factory.shape_factory, **kwargs)