def __init__(self, task): warnings.warn( "IPython2ProgressBar is deprecated. Please upgrade to IPython " "version 5 or later.", DeprecationWarning) super(IPython2ProgressBar, self).__init__(task) self._escaped_task = escape(task) self._widget = IPythonProgressWidget() self._initialized = False
def update_client(self, client): if self.progress is not None: client.write_text( json.dumps({ 'name_during': escape(getattr(self.progress, 'name_during', 'Building')), 'name_after': escape(getattr(self.progress, 'name_after', 'Build')), 'progress': self.progress.progress, 'max_steps': self.progress.max_steps, 'elapsed_time': str(timestamp2timedelta(self.progress.elapsed_seconds())), 'eta': str(timestamp2timedelta(self.progress.eta())), 'finished': self.progress.finished, 'success': self.progress.success })) if self.progress.finished: self.progress = None
def _reload_update_item(self, uid, old_item, new_item, new_name_finder): # noqa: C901 """Tell the client about changes to the item due to reload.""" changed = False if isinstance(old_item, (nengo.Node, nengo.Ensemble, nengo.Network)): old_label = self.page.get_label(old_item) new_label = self.page.get_label( new_item, default_labels=new_name_finder.known_name) if old_label != new_label: self.to_be_sent.append( dict(type='rename', uid=uid, name=escape(new_label))) changed = True if isinstance(old_item, nengo.Network): if self.page.config[old_item].expanded: self.to_be_expanded.append(new_item) changed = True elif isinstance(old_item, nengo.Connection): old_pre = NetGraph.connection_pre_obj(old_item) old_post = NetGraph.connection_post_obj(old_item) new_pre = NetGraph.connection_pre_obj(new_item) new_post = NetGraph.connection_post_obj(new_item) old_pre = self.page.get_uid(old_pre) old_post = self.page.get_uid(old_post) new_pre = self.page.get_uid( new_pre, default_labels=new_name_finder.known_name) new_post = self.page.get_uid( new_post, default_labels=new_name_finder.known_name) if new_pre != old_pre or new_post != old_post: # if the connection has changed, tell javascript pres, posts = self.get_connection_hierarchy( new_item, default_labels=new_name_finder.known_name) self.to_be_sent.append( dict(type='reconnect', uid=uid, pres=pres, posts=posts)) changed = True return changed
def create_object(self, client, obj, obj_type, parent): """Send the JSON of the newly created objects to client-side""" uid = self.page.get_uid(obj) # if the uid already exists, then it's already been inserted in # the netgraph, so don't send anything if uid in self.uids: return self.uids[uid] = obj pos = self.page.config[obj].pos if pos is None: import random pos = random.uniform(0, 1), random.uniform(0, 1) self.page.config[obj].pos = pos size = self.page.config[obj].size if size is None: size = (0.1, 0.1) self.page.config[obj].size = size label = self.page.get_label(obj) info = dict(uid=uid, label=escape(label), pos=pos, type=obj_type, size=size, parent=parent) info.update(self.get_extra_info(obj)) if type == 'net': info['expanded'] = self.page.config[obj].expanded client.write_text(json.dumps(info))