Exemplo n.º 1
0
class StepProgressBar(object):
    def __init__(self, gui, description):
        self.progress_bar = ProgressBar('progress_empty',
                                        'progress_done',
                                        satt='progress_progress')
        self.id_text = Text('')
        self.eta_text = Text('', align='right')
        title = Text(' {} '.format(description), align='center')
        self.progress_widget = AttrMap(
            LineBox(
                Columns([
                    title, ('weight', 2, self.progress_bar), self.id_text,
                    self.eta_text
                ])), 'box')
        gui.progress.append(self.progress_widget)
        self.gui = gui
        gui.redraw()

    def set_state(self, progress, elem_id, eta):
        m, s = divmod(eta, 60)
        h, m = divmod(m, 60)

        self.progress_bar.set_completion(progress)
        self.id_text.set_text([' ', '{:8}'.format(elem_id)])
        self.eta_text.set_text([('eta', '{:2d}:{:02d}:{:02d}'.format(h, m, s)),
                                ('box', ' left... ')])
        self.gui.redraw()

    def remove(self):
        self.gui.progress.remove(self.progress_widget)
        self.gui.redraw()
Exemplo n.º 2
0
 def __init__(self, gui, description):
     self.progress_bar = ProgressBar('progress_empty',
                                     'progress_done',
                                     satt='progress_progress')
     self.id_text = Text('')
     self.eta_text = Text('', align='right')
     title = Text(' {} '.format(description), align='center')
     self.progress_widget = AttrMap(
         LineBox(
             Columns([
                 title, ('weight', 2, self.progress_bar), self.id_text,
                 self.eta_text
             ])), 'box')
     gui.progress.append(self.progress_widget)
     self.gui = gui
     gui.redraw()
Exemplo n.º 3
0
 def __init__(self, step_count, cancel_func):
     self.cancel_func = cancel_func
     button = cancel_btn(_("Cancel"), on_press=self.do_cancel)
     self.bar = ProgressBar(normal='progress_incomplete',
                            complete='progress_complete',
                            current=0,
                            done=step_count)
     box = LineBox(Pile([self.bar, button_pile([button])]),
                   title=_("Applying network config"))
     super().__init__(box)
Exemplo n.º 4
0
 def __init__(self, step_count, cancel_func):
     self.cancel_func = cancel_func
     button = cancel_btn(on_press=self.do_cancel)
     self.bar = ProgressBar(normal='progress_incomplete',
                     complete='progress_complete',
                     current=0, done=step_count)
     box = LineBox(Pile([self.bar,
                         Padding.fixed_10(button)]),
                   title="Applying network config")
     super().__init__(box)
Exemplo n.º 5
0
    def pb(self, upload):
        pb = ProgressBar(
            normal='progress_incomplete',
            complete='progress_complete',
            current=upload.bytes_sent,
            done=upload.bytes_to_send)

        def _progress():
            pb.done = upload.bytes_to_send
            pb.current = upload.bytes_sent
        connect_signal(upload, 'progress', _progress)

        return pb
Exemplo n.º 6
0
 def __init__(self, message="", completion=0):
     message_widget = Padding.center_79(Color.body(Text(message)))
     progress_bar = Padding.center_60(
         ProgressBar(normal='progress_incomplete',
                     complete='progress_complete',
                     current=completion, done=100))
     status = deque([
         Padding.line_break(""),
         message_widget
     ])
     if completion > 0:
         status.appendleft(progress_bar)
     super().__init__(Pile(status))
Exemplo n.º 7
0
    def __init__(self, executor, label=None, additional_widgets=()):
        self.executor = executor
        self.duration = self.executor.get_load().duration
        self.widgets = []
        self.additional_widgets = additional_widgets
        self.widgets.extend(self.additional_widgets)

        if label is not None:
            self.widgets.append(Text(label))

        if self.duration is not None and self.duration != 0:
            self.progress = ProgressBar('pb-en', 'pb-dis', done=self.duration)
        else:
            self.progress = Text("Running...")
        self.widgets.append(self.progress)

        self.elapsed = Text("Elapsed: N/A")
        self.eta = Text("ETA: N/A", align=RIGHT)
        self.widgets.append(Columns([self.elapsed, self.eta]))
        super(SidebarWidget, self).__init__(self.widgets)
Exemplo n.º 8
0
    def __init__(self, executor, label=None, additional_widgets=()):
        PrioritizedWidget.__init__(self, priority=10)
        self.executor = executor
        self.duration = self.executor.get_load().duration
        self.widgets = []
        self.additional_widgets = additional_widgets
        self.widgets.extend(self.additional_widgets)
        self.finished = False

        if label is not None:
            self.widgets.append(Text(label))
        else:
            self.widgets.append(Text("%s" % executor))

        if self.duration:
            self.progress = ProgressBar('pb-en', 'pb-dis', done=self.duration)
        else:
            self.progress = Text("")
        self.widgets.append(self.progress)

        self.elapsed = Text("Elapsed: N/A")
        self.eta = Text("ETA: N/A", align=RIGHT)
        self.widgets.append(Columns([self.elapsed, self.eta]))
        super(ExecutorWidget, self).__init__(self.widgets)
Exemplo n.º 9
0
def render_text(text, K):
    # XXX: make this code lazy-reader reader-proxy aware
    txts = [make_text(t, K.width) for t in text.split('\n')]
    K.txts = txts
    piles = []
    p = Pile([])
    for t in txts[:]:
        #if 'What emerges' in t.text: pu.db
        p.contents.append((t, p.options()))
        t_size = t.rows((K.width, ))
        #if piles and h(piles[-1]) > height: pu.db
        while h(p, K) > K.height:
            # Add a new pile, and send the trimmings in there
            piles.append(p)
            d = h(t, K) - (h(p, K) - K.height)

            #if d <= 0: pu.db

            # start the next column
            p_new = Pile([])
            t_extra = trim(t, d, K.width)
            # TODO: include diff status in here, and line numbers
            p_new.contents.append((t_extra, p.options()))
            p = p_new
            t = t_extra

        #if piles and h(piles[-1]) > height:
        #    # ACK!
        #    break
        if h(p, K) == K.height:
            piles.append(p)
            # start the next column
            p = Pile([])

    # all done, don't forget the last pile which we haven't added to the list yet
    piles.append(p)

    palette = [('black', 'light gray', 'black'),
               ('heading', 'black', 'light gray'),
               ('important', 'black', 'light cyan'),
               ('line', 'black', 'light gray'),
               ('options', 'dark gray', 'black'),
               ('focus heading', 'white', 'dark red'),
               ('focus line', 'black', 'dark red'),
               ('diff old', 'dark red', 'black'),
               ('diff new', 'dark green', 'black'),
               ('focus options', 'black', 'light gray'),
               ('pg normal', 'white', 'black', 'standout'),
               ('pg complete', 'white', 'dark magenta'),
               ('selected', 'white', 'dark blue')]

    #piles = urwid.ListBox(urwid.SimpleFocusListWalker(piles))
    #cols = piles
    #fill = cols
    dc = int(K.max_width / K.width)  # number of displayed columns
    while len(piles) < int(dc):
        piles.append(Pile([]))
    cols = urwid.Columns(piles[:dc], dividechars=1, min_width=K.width)
    K.cols = cols
    col_widths = cols.column_widths(K.screen.get_cols_rows())
    K.displayed_columns = len(col_widths)

    def tmp_generator():
        for x in piles:
            yield urwid.Columns([x], dividechars=1, min_width=K.width)

    K.reader = LazyReader(tmp_generator())

    # XXX: I need to subclass columns, and make it so the keypress function
    # "rolls" the piles under the hood, and re-renders all the widgets.
    #
    # self.contents.append(self.contents.pop(0))
    #
    #cols.box_columns.extend(cols.widget_list)

    #grid = urwid.GridFlow(txts, cell_width=20, h_sep=4, v_sep=0, align='left')
    fill = urwid.Filler(cols, 'top', top=K.top_margin)
    K.total_cols = len(piles)

    # XXX: this is not the full story, it ignores the borders between columns
    c_columns = [sum(col_widths[:i + 1]) for i in range(K.displayed_columns)]
    border = (K.max_width - c_columns[-1]) / K.displayed_columns

    def xpos_to_col(pos):
        for i, c in enumerate(c_columns):
            if pos < (c + i * border):
                return i

    K.xpos_to_col = xpos_to_col
    pbar = ProgressBar('pg normal', 'pg complete', K.displayed_columns,
                       K.total_cols)
    K.pbar = pbar

    p = urwid.ListBox(urwid.SimpleListWalker([pbar]))

    all = Pile([
        fill,
        (1, p),
    ])
    cmd_line_text = urwid.Edit(K.fname)
    K.cmd_line_text = cmd_line_text
    #cmd_line_prompt = urwid.Text('hi there')
    #cmd_line_combined = urwid.Filler([cmd_line_prompt, cmd_line_text])
    #all = urwid.Frame(body=all, footer=cmd_line_combined)
    K.all = urwid.Frame(body=all, footer=cmd_line_text)
    K.loop = urwid.MainLoop(K.all,
                            palette,
                            K.screen,
                            unhandled_input=show_or_exit)
    K.loop.exit = urwid.Text(" Help? ")

    #IPython.embed()
    if K.args.diff:
        set_cmd("set ft=diff".split(), K)
    elif have_pygments:
        set_cmd(("set ft=" + lexer.name.split()[0].lower()).split(), K)

    if K.args.quick:
        K.loop.set_alarm_in(1, lambda x, y: quit())

    pbh = progress_bar_handler(p)
    K.pbh = pbh
    next(pbh)

    try:
        K.loop.run()
    except KeyboardInterrupt:
        pass