def open_file(self, path): f = open(path, 'r') unpickler = pickle.Unpickler(f) new_model = unpickler.load() # update the link back to the controller (ie, self) for wi in new_model.workflow: wi.task = self # and set up the view handlers for view in wi.views: view.handler = view.handler_factory(model=view, wi=wi) # replace the current workflow with the one we just loaded if False: from event_tracer import record_events with record_events() as container: self.model.workflow[:] = new_model.workflow self.model.selected = new_model.selected container.save_to_directory(os.getcwd()) else: self.model.workflow[:] = new_model.workflow self.model.selected = new_model.selected wi = self.model.workflow[0] while True: wi.status = "invalid" with self.worker_lock: self.to_update.put_nowait((self.model.workflow.index(wi), wi)) if wi.next: wi = wi.next else: break # check to see if we have a worker thread around if not self.worker or not self.worker.is_alive(): self.worker = threading.Thread(target=update_model, args=(self.worker_flag, self.worker_lock, self.to_update)) self.worker.daemon = True self.worker.start() # start the worker thread processing with self.worker_lock: if not self.to_update.empty(): self.worker_flag.set()
def open_file(self, path): f = open(path, 'r') unpickler = pickle.Unpickler(f) new_model = unpickler.load() # update the link back to the controller (ie, self) for wi in new_model.workflow: wi.task = self # and set up the view handlers for view in wi.views: view.handler = view.handler_factory(model = view, wi = wi) # replace the current workflow with the one we just loaded if False: from event_tracer import record_events with record_events() as container: self.model.workflow[:] = new_model.workflow self.model.selected = new_model.selected container.save_to_directory(os.getcwd()) else: self.model.workflow[:] = new_model.workflow self.model.selected = new_model.selected wi = self.model.workflow[0] while True: wi.valid = "invalid" with self.worker_lock: self.to_update.put_nowait((self.model.workflow.index(wi), wi)) if wi.next: wi = wi.next else: break # check to see if we have a worker thread around if not self.worker or not self.worker.is_alive(): self.worker = threading.Thread(target = update_model, args = (self.worker_flag, self.worker_lock, self.to_update)) self.worker.daemon = True self.worker.start() # start the worker thread processing with self.worker_lock: if not self.to_update.empty(): self.worker_flag.set()
def open_file(self, path): f = open(path, 'r') unpickler = pickle.Unpickler(f) new_workflow = unpickler.load() # replace the current workflow with the one we just loaded if False: from event_tracer import record_events with record_events() as container: self.model.workflow = new_workflow container.save_to_directory(os.getcwd()) else: self.model.workflow = new_workflow
def open_file(self, path): f = open(path, 'r') unpickler = pickle.Unpickler(f) try: version = unpickler.load() except TraitError: error(parent=None, message="This doesn't look like a Cytoflow file. Or maybe " "you tried to load a workflow older than version " "0.5?") return if version != self.model.version: ret = confirm( parent=None, message="This is Cytoflow {}, but you're trying " "to load a workflow from version {}. This may or " "may not work! Are you sure you want to proceed?".format( self.model.version, version), title="Load workflow?") if ret != YES: return try: new_workflow = unpickler.load() except TraitError: error(parent=None, message="Error trying to load the workflow.") return # replace the current workflow with the one we just loaded if False: # for debugging the loading of things from event_tracer import record_events with record_events() as container: self.model.workflow = new_workflow container.save_to_directory(os.getcwd()) else: self.model.workflow = new_workflow self.model.modified = False self.model.workflow[0].operation.changed = "api"
trait3 = Bool traits_view = View(Group(Item(name='trait1'), Item(name='trait2'), Item(name='trait3'))) class TestList(HasTraits): el = List(TestPageClass) view = View( Group( Item(name='el', id='table', #editor = ListEditor() editor=VerticalNotebookEditor(page_name='.trait1', view='traits_view', delete = True) )), resizable = True) from event_tracer import record_events import os with record_events() as container: test = TestList() test.el.append(TestPageClass(trait1="one", trait2=True)) test.el.append(TestPageClass(trait1="three", trait2=False)) test.configure_traits() container.save_to_directory(os.getcwd())
def open_file(self, path): f = open(path, 'r') unpickler = pickle.Unpickler(f) try: version = unpickler.load() except TraitError: error(parent=None, message="This doesn't look like a Cytoflow file. Or maybe " "you tried to load a workflow older than version " "0.5?") return if version != self.model.version: ret = confirm( parent=None, message="This is Cytoflow {}, but you're trying " "to load a workflow from version {}. This may or " "may not work! Are you sure you want to proceed?".format( self.model.version, version), title="Load workflow?") if ret != YES: return try: new_workflow = unpickler.load() except TraitError: error(parent=None, message="Error trying to load the workflow.") return # a few things to take care of when reloading for wi_idx, wi in enumerate(new_workflow): # clear the wi status wi.status = "invalid" # re-link the linked list. i thought this would get taken care # of in deserialization, but i guess not... if wi_idx > 0: wi.previous = new_workflow[wi_idx - 1] # reload the subset lists. i don't know why this is necessary. for view in wi.views: subset_list = view.subset_list view.subset_list = [] for s in subset_list: view.subset_list.append(s) subset_list = wi.operation.subset_list wi.operation.subset_list = [] for s in subset_list: wi.operation.subset_list.append(s) # replace the current workflow with the one we just loaded if False: # for debugging the loading of things from event_tracer import record_events with record_events() as container: self.model.workflow = new_workflow container.save_to_directory(os.getcwd()) else: self.model.workflow = new_workflow self.model.modified = False