def _get(self, pos): if not pos: return None, None if pos.parent and pos.field != pos.parent.field[pos.index]: hachoir_log.error("assertion failed at urwid_ui.Walker._get") if not (pos.flags is None and pos.hidden()) and pos.flags != self.flags: self.update(pos) return pos.getWidget(self.start), pos
def save_field(self, path, raw): try: fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_WRONLY) except OSError as err: hachoir_log.error(str(err)) else: field = self.focus.field if raw: stream = InputFieldStream(field) else: stream = field.getSubIStream() copyfileobj(stream.file(), os.fdopen(fd, 'wb'))
def fromField(self, root, path): try: field = self.focus.field[path] except MissingField as e: field = e.field hachoir_log.error(str(e)) path = [] while field.parent: path.append(field.index) field = field.parent for index in reversed(path): self.read(root, index + 2, True) root = root.childs[index] return root
def run(): msg = _resize = retry = 0 events = ("window resize", ) profile_display = args.profile_display while True: for e in events: try: if e == "window resize": size = ui.get_cols_rows() resize = log.height else: e = top.keypress(size, e) if e is None: pass elif e in ('f1', '?'): try: body.select(body.tabs.index(help)) except ValueError: body.append(help) resize = log.height elif e in ('esc', 'ctrl w'): body.close() if body.original_widget is None: return resize = log.height elif e == '+': if log.height: resize = log.height - 1 elif e == '-': resize = log.height + 1 elif e == 'q': return # except AssertionError: # hachoir_log.error(getBacktrace()) except NewTab_Stream as e: stream = e.field.getSubIStream() logger.objects[stream] = e = "%u/%s" % ( body.active, e.field.absolute_address) parser = guessParser(stream) if not parser: hachoir_log.error("No parser found for %s" % stream.source) else: logger.objects[parser] = e body.append((e, TreeBox(charset, Node(parser, None), preload_fields, None, options))) resize = log.height except NeedInput as e: input.do(*e.args) if profile_display: events = events[1:] break while True: if msgs[0]: for level, prefix, text in msgs[0]: log_count[level] += 1 txt = Text("[%u]%s %s" % (msg, prefix, text)) msg += 1 msgs[1].append(txt) _resize += txt.rows(size[:1]) if log.height < _resize and (resize is None or resize < _resize): resize = _resize try: log.set_focus(len(msgs[1]) - 1) except IndexError: pass sep.set_info(*tuple(log_count)) msgs[0] = [] if resize is not None: body.height = size[1] - sep.rows(size[:1]) - resize if body.height <= 0: resize += body.height - 1 body.height = 1 log.height = resize resize = None canvas = top.render(size, focus=True) if not msgs[0]: _resize = retry = 0 break assert not retry retry += 1 ui.draw_screen(size, canvas) msgs[2] = len(msgs[1]) if profile_display and events: continue while True: events = ui.get_input() if events: break