def _get_misc_data(self): if not self.raw: return if self.show_gui: # progress dialog with indefinite progress bar prog = ProgressDialog(title="Loading SQD data...", message="Loading stim channel data from SQD " "file ...") prog.open() prog.update(0) else: prog = None try: data, times = self.raw[self.misc_chs] except Exception as err: if self.show_gui: error(None, "Error reading SQD data file: %s (Check the " "terminal output for details)" % str(err), "Error Reading SQD File") raise finally: if self.show_gui: prog.close() return data
def _get_misc_data(self): if not self.raw: return if self.show_gui: # progress dialog with indefinite progress bar prog = ProgressDialog(title="Loading SQD data...", message="Loading stim channel data from SQD " "file ...") prog.open() prog.update(0) else: prog = None try: data, times = self.raw[self.misc_chs] except Exception as err: if self.show_gui: error( None, "Error reading SQD data file: %s (Check the " "terminal output for details)" % str(err), "Error Reading SQD File") raise finally: if self.show_gui: prog.close() return data
def do_reload(self, info): app = info.ui.context['object'] progress = ProgressDialog(title="Reload", message="Reloading data", max=len(app.tabs)+1, can_cancel=True, parent=app.context.uiparent) progress.open() with app.drawmgr.hold(): for i, tab in enumerate(app.tabs): tab.reload = True cont, skip = progress.update(i+1) if not cont or skip: break progress.update(progress.max) progress.close()
def _create_fsaverage_fired(self): # progress dialog with indefinite progress bar title = "Creating FsAverage ..." message = "Copying fsaverage files ..." prog = ProgressDialog(title=title, message=message) prog.open() prog.update(0) try: self.model.create_fsaverage() except Exception as err: error(None, str(err), "Error Creating FsAverage") raise finally: prog.close()
def _create_fsaverage_fired(self): # progress dialog with indefinite progress bar title = "Creating FsAverage ..." message = "Copying fsaverage files ..." prog = ProgressDialog(title=title, message=message) prog.open() prog.update(0) try: self.model.create_fsaverage() except Exception as err: error(None, str(err), "Error Creating FsAverage") raise finally: prog.close()
def open_project(self, path): with open(path, 'rb') as fp: if fp.read(15) != 'Spacetime\nJSON\n': raise ValueError('not a valid Spacetime project file') data = json.load(fp) progress = ProgressDialog(title="Open", message="Loading project", max=len(data)+1, can_cancel=False, parent=self.context.uiparent) progress.open() with self.context.canvas.hold_delayed(): self.tabs[0].from_serialized(data.pop(0)[1]) tabs = [self.tabs[0]] progress.update(1) # FIXME: check version number and emit warning for p, (id, props) in enumerate(data): try: tab = self.get_new_tab(self.moduleloader.get_class_by_id(id)) tab.from_serialized(props) tabs.append(tab) except KeyError: support.Message.show(title='Warning', message='Warning: incompatible project file', desc='Ignoring unknown graph id "{0}". Project might not be completely functional.'.format(id)) progress.update(2+p) self.tabs = tabs self.project_path = path wx.CallAfter(self.clear_project_modified) wx.CallAfter(lambda: (progress.update(progress.max), progress.close()))
def retime_files(self): if not self.gui_active: return chunksize = self.parent.probe_progress_chunksize chunkcount = int(math.ceil(float(len(self.files)) / chunksize)) if chunkcount > 1: progress = ProgressDialog(title="Images", message="Loading images", max=chunkcount, can_cancel=False, parent=self.context.uiparent) else: progress = gui.support.DummyProgressDialog() progress.open() with cache.Cache('image_metadata') as c: for i, f in enumerate(self.files): if i % chunksize == 0: progress.update(i / chunksize) f.timestamp, f.exposure = self.get_timestamp(c, i, f.path) self.files = self.sort_files(self.files) progress.update(progress.max) progress.close()
def get_files(self, reload=False): chunksize = self.parent.probe_progress_chunksize if reload or not self.files: filenames = glob.glob(os.path.join(self.directory, self.pattern)) chunkcount = int(math.ceil(float(len(filenames)) / chunksize)) if chunkcount > 1: progress = ProgressDialog(title="Images", message="Loading images", max=chunkcount, can_cancel=False, parent=self.parent.context.uiparent) else: progress = gui.support.DummyProgressDialog() files = [] with cache.Cache('image_metadata') as c: progress.open() for i in range(chunkcount): eiter = enumerate(filenames[chunksize*i:chunksize*(i+1)], chunksize*i) files.extend(ImageFile.probefile(files, c, i, fn, self.get_timestamp) for (i, fn) in eiter) progress.update(i) progress.update(progress.max) progress.close() self.files = self.sort_files(files)
def _render_animation_fired(self): self.stop = True n_frames_render = self.render_to_frame - self.render_from_frame # prepare the render window renwin = self._figure.scene.render_window aa_frames = renwin.aa_frames renwin.aa_frames = 8 renwin.alpha_bit_planes = 1 # turn on off screen rendering #renwin.off_screen_rendering = True # set size of window if self.fix_image_size: orig_size = renwin.size renwin.size = self.image_size # render the frames progress = ProgressDialog(title="Rendering", max=n_frames_render, show_time=True, can_cancel=True) progress.open() self.is_rendering_animation = True for frame in range(self.render_from_frame, self.render_to_frame + 1): # move animation to desired frame, this will also render the scene self.current_frame = frame # prepare window to image writer render = tvtk.WindowToImageFilter(input=renwin, magnification=1)#, input_buffer_type='rgba') if not self.fix_image_size: render.magnification = self.magnification exporter = tvtk.PNGWriter(file_name=path.join(self.render_directory, self.render_name_pattern % frame)) configure_input(exporter,render) exporter.write() do_continue, skip = progress.update(frame - self.render_from_frame) if not do_continue: break # reset the render window to old values renwin.aa_frames = aa_frames if self.fix_image_size: renwin.size = orig_size #renwin.off_screen_rendering = False self.is_rendering_animation = False progress.close()
def _get_misc_data(self): if not self.raw: return if self.show_gui: # progress dialog with indefinite progress bar prog = ProgressDialog(title="Loading SQD data...", message="Loading stim channel data from SQD " "file ...") prog.open() prog.update(0) else: prog = None try: data, times = self.raw[self.misc_chs] except Exception as err: if self.show_gui: error(None, str(err), "Error Creating FsAverage") raise finally: if self.show_gui: prog.close() return data
def _get_misc_data(self): if not self.raw: return if self.show_gui: # progress dialog with indefinite progress bar prog = ProgressDialog(title="Loading SQD data...", message="Loading stim channel data from SQD " "file ...") prog.open() prog.update(0) else: prog = None try: data, times = self.raw[self.misc_chs] except Exception as err: if self.show_gui: error(None, str(err), "Error Creating FsAverage") raise err finally: if self.show_gui: prog.close() return data
def do_export_movie(self, info): context = info.ui.context['object'].context moviedialog = context.app.export_movie_dialog try: if not moviedialog.run().result: return except RuntimeError as e: support.Message.show(parent=context.uiparent, message='Nothing to animate', desc=str(e)) return dlg = wx.FileDialog( info.ui.control, "Save movie", context.prefs.get_path('export_movie'), "movie." + moviedialog.format, "*.{0}|*.{0}|All files (*.*)|*.*".format(moviedialog.format), wx.SAVE|wx.OVERWRITE_PROMPT ) if dlg.ShowModal() != wx.ID_OK: return context.prefs.set_path('export_movie', dlg.GetDirectory()) # preparations, no harm is done if something goes wrong here movie = stdout_cb = stdout = None oldfig = context.plot.figure progress = ProgressDialog(title="Movie", message="Building movie", max=moviedialog.get_framecount()+2, can_cancel=True, show_time=True, parent=context.uiparent) newfig = matplotlib.figure.Figure((moviedialog.frame_width / moviedialog.dpi, moviedialog.frame_height / moviedialog.dpi), moviedialog.dpi) canvas = FigureCanvasAgg(newfig) drawmgr = context.canvas.relocate(redraw=newfig.canvas.draw) finalpath = dlg.GetPath() if '%' in finalpath: # to support stuff like -f image2 -c:v png file_%02.png temppath = False else: temppath = finalpath + '.temp' class UserCanceled(Exception): pass class FFmpegFailed(Exception): pass # now the real thing starts. we have to clean up properly try: progress.open() context.plot.relocate(newfig) movie = util.FFmpegEncode( temppath or finalpath, moviedialog.format, moviedialog.codec, moviedialog.frame_rate, (moviedialog.frame_width, moviedialog.frame_height), moviedialog.ffmpeg_options.split(), ) stdout_cb = movie.spawnstdoutthread() drawmgr.rebuild() progress.update(1) iters = tuple(i() for i in moviedialog.get_animate_functions()) frameiter = enumerate(itertools.izip_longest(*iters)) while True: with drawmgr.hold(): try: frameno, void = frameiter.next() except StopIteration: progress.update(progress.max-1) break movie.writeframe(newfig.canvas.tostring_rgb()) (cont, skip) = progress.update(frameno+2) if not cont or skip: raise UserCanceled() ret = movie.close() if ret != 0: raise FFmpegFailed('ffmpeg returned {0}'.format(ret)) stdout = stdout_cb() stdout_cb = None if temppath: shutil.move(temppath, finalpath) progress.update(progress.max) except UserCanceled: movie.abort() return except: if movie: movie.close() if stdout_cb: try: stdout = stdout_cb() except: pass stdout_cb = None support.Message.show( parent=context.uiparent, message='Movie export failed', title='Exception occured', desc='Something went wrong while exporting the movie. Detailed debugging information can be found below.', bt="FFMPEG output:\n{0}\n\nBACKTRACE:\n{1}".format(stdout, traceback.format_exc()) ) return finally: if stdout_cb: stdout = stdout_cb() progress.close() try: os.remove(temppath) except: pass context.plot.relocate(oldfig) context.canvas.rebuild() support.Message.show( parent=context.uiparent, title='Movie complete', message='Movie complete', desc='The movie successfully been generated.\nFor debugging purposes, the full FFmpeg output can be found below.', bt=stdout )