Exemplo n.º 1
0
    def __init__(self):
        self.screen = Screen()
        self.screen.set_input_timeouts(max_wait=0)
        self.steps = GridFlow([], 20, 2, 1, 'left')
        self.progress = SimpleFocusListWalker([])
        self.log = SimpleFocusListWalker([])

        self.widget = AttrMap(
            LineBox(Pile([
                ('fixed', 6, AttrMap(Filler(self.steps), 'default')),
                ('fixed', 1, Filler(Divider('\u2500'))),
                ('fixed', 3, ListBox(self.progress)),
                AttrMap(LineBox(ListBox(self.log), title='Message log'),
                        'default')
            ]),
                    title='Indico 1.2 -> 2.0 migration'), 'global_frame')

        self.screen.register_palette(
            [('green', 'light green', ''), ('white', 'white', ''),
             ('red', 'dark red', ''), ('yellow', 'yellow', ''),
             ('progress_empty', 'black',
              'light gray'), ('progress_progress', 'light cyan', 'light gray'),
             ('progress_done', 'black', 'light cyan'),
             ('box', 'white', 'dark gray'), ('step_done', 'light green', ''),
             ('step_working', 'dark gray',
              ''), ('global_frame', 'light cyan',
                    ''), ('fill', 'light cyan', 'dark cyan'),
             ('done', 'white', 'dark green'), ('eta', 'yellow', 'dark gray')] +
            generate_urwid_palette(PALETTE))
Exemplo n.º 2
0
class TrackWidget(WidgetWrap):
    number = None
    track = None
    ui = None

    def __init__(self, ui=None, track=None, number=None):
        self.ui = ui or self.ui
        self.track = track or self.track
        self.number = number or self.number

        self.header = TrackHeader(self.track.name, number)
        self.clips = SimpleFocusListWalker(
            [ClipButton(self.ui, c)
             for c in self.track.clips] + [AddClipButton(self.on_add_button)])

        Clip.ON_ADD.append(self.on_clip_added)

        WidgetWrap.__init__(self, Frame(ListBox(self.clips),
                                        header=self.header))

    def on_add_button(self, _):
        self.ui.editor.show(track=self.track)

    def on_clip_added(self, track, clip):
        if track == self.track:
            self.clips.insert(-1, ClipButton(self.ui, clip))
Exemplo n.º 3
0
class TrackWidget(WidgetWrap):
    number = None
    track  = None
    ui     = None

    def __init__(self, ui=None, track=None, number=None):
        self.ui     = ui     or self.ui
        self.track  = track  or self.track
        self.number = number or self.number
 
        self.header = TrackHeader(self.track.name, number)
        self.clips = SimpleFocusListWalker(
            [ClipButton(self.ui, c) for c in self.track.clips] +
            [AddClipButton(self.on_add_button)])

        Clip.ON_ADD.append(self.on_clip_added)

        WidgetWrap.__init__(self, Frame(ListBox(self.clips),
                                        header=self.header))

    def on_add_button(self, _):
        self.ui.editor.show(track=self.track)

    def on_clip_added(self, track, clip):
        if track == self.track:
            self.clips.insert(-1, ClipButton(self.ui, clip))
Exemplo n.º 4
0
class WebcamWindow(Window):
    def __init__(self, tui):
        super().__init__(tui)
        self.body.contents.append((Text("Available Webcams"), ('pack', None)))
        self.body.contents.append((Divider(), ('pack', None)))

        self.walker = SimpleFocusListWalker([])
        listbox = ListBox(self.walker)
        self.body.contents.append((listbox, ('weight', 1)))
        self.body.focus_position = 2
        self.add_hotkey('U', self.update, "update")
        self.update()

    def update(self):
        def camlist_cb(json_msg):
            self.walker.clear()

            def button_cb(locator, url, button):
                webbrowser.open_new(url)
                self.tui.pop_window()

            self.display_errors(json_msg)
            webcams = json_msg.get('webcams', None)
            if not webcams: return
            for locator, webcam in webcams.items():
                name = webcam["name"]
                url = webcam["url"]
                button = Button(name)
                urwid.connect_signal(button,
                                     'click',
                                     button_cb,
                                     user_args=[locator, url])
                self.walker.append(AttrMap(button, None, focus_map='selected'))

        self.tui.controller.get_camlist(camlist_cb)
Exemplo n.º 5
0
    def __init__(self, tui, locator, device):
        super().__init__(tui)
        self.body.contents.append(
            (Text("Selected device \"{}\"".format(device)), ('pack', None)))
        fn = self.tui.controller.get_filename(locator)
        self.filename_txt = Text("Selected file \"{}\"".format(fn))
        self.body.contents.append((self.filename_txt, ('pack', None)))
        self.body.contents.append((Divider(), ('pack', None)))

        self.statuswidget = Pile([])
        self.body.contents.append((self.statuswidget, ('pack', None)))
        self.body.contents.append((Divider(), ('pack', None)))

        self.locator = locator
        self.device = device

        self.walker = SimpleFocusListWalker([])
        listbox = ListBox(self.walker)
        self.body.contents.append((listbox, ('weight', 1)))
        self.body.focus_position = 5
        self.add_hotkey('U', self.update, "update")
        self.add_hotkey('w', self.webcams, "webcams")
        self.add_hotkey('a', self.actions, "actions")
        self.status = defaultdict(str)
        self.update()
Exemplo n.º 6
0
    def __init__(self, tui, locator, device):
        super().__init__(tui)
        self.body.contents.append(
            (Text("Select file to load on \"{}\"".format(device)), ('pack',
                                                                    None)))
        self.body.contents.append((Divider(), ('pack', None)))
        self.device = device

        self.locator = locator
        self.device = device
        self.all_files = []

        def limit(regexp):
            self.regexp = regexp
            self.populate_list()

        def enter(edit_text):
            if len(self.walker) < 1:
                self.tui.pop_window()
                return
            button = self.walker[0]
            button.keypress(1, 'enter')

        editbox = CB_Edit("Limit (regexp): ", "", limit, enter)
        self.body.contents.append((editbox, ('pack', 1)))
        self.body.contents.append((Divider(), ('pack', 1)))

        self.walker = SimpleFocusListWalker([])
        listbox = ListBox(self.walker)
        self.body.contents.append((listbox, ('weight', 1)))
        self.body.focus_position = 2
        self.update()
        self.regexp = ".*"
Exemplo n.º 7
0
    def __init__(self, controller):
        self.controller = controller
        self.spinner = Spinner(controller.loop)

        self.event_listwalker = SimpleFocusListWalker([])
        self.event_listbox = ListBox(self.event_listwalker)
        self.event_linebox = MyLineBox(self.event_listbox)
        self.event_buttons = button_pile([other_btn("View full log", on_press=self.view_log)])
        event_body = [
            ('pack', Text("")),
            ('weight', 1, Padding.center_79(self.event_linebox)),
            ('pack', Text("")),
            ('pack', self.event_buttons),
            ('pack', Text("")),
        ]
        self.event_pile = Pile(event_body)

        self.log_listwalker = SimpleFocusListWalker([])
        self.log_listbox = ListBox(self.log_listwalker)
        log_linebox = MyLineBox(self.log_listbox, _("Full installer output"))
        log_body = [
            ('weight', 1, log_linebox),
            ('pack', button_pile([other_btn(_("Close"), on_press=self.close_log)])),
            ]
        self.log_pile = Pile(log_body)

        super().__init__(self.event_pile)
Exemplo n.º 8
0
 def __init__(self, tui):
     super().__init__(tui)
     description = Text(
         "NOTICE. The log displayed here is a copy of the "
         "daemon log. Keeping the the loglevel at debug impacts "
         "performance. When done, run ':loglevel warning'")
     self.body.contents.append((description, ('pack', None)))
     self.walker = SimpleFocusListWalker([])
     self.listbox = ScrollingListBox(self.walker)
     self.body.contents.append((self.listbox, ('weight', 1)))
Exemplo n.º 9
0
class ChatMessages(ListBox):
    """ Show the last couple of chat messages as a scrolling list """

    def __init__(self, chat):
        self.chat = chat
        self.walker = SimpleFocusListWalker([])
        super(ChatMessages, self).__init__(self.walker)

    def add(self, message):
        self.walker.append(Text(message))
        self.set_focus(len(self.walker) - 1)
Exemplo n.º 10
0
class ChatMessages(ListBox):
    """ Show the last couple of chat messages as a scrolling list """

    def __init__(self, chat):
        self.chat = chat
        self.walker = SimpleFocusListWalker([])
        super(ChatMessages, self).__init__(self.walker)

    def add(self, message):
        self.walker.append(Text(message))
        self.set_focus(len(self.walker)-1)
Exemplo n.º 11
0
    def __init__(self, tui):
        super().__init__(tui)
        self.body.contents.append((Text("Available Webcams"), ('pack', None)))
        self.body.contents.append((Divider(), ('pack', None)))

        self.walker = SimpleFocusListWalker([])
        listbox = ListBox(self.walker)
        self.body.contents.append((listbox, ('weight', 1)))
        self.body.focus_position = 2
        self.add_hotkey('U', self.update, "update")
        self.update()
Exemplo n.º 12
0
 def __init__(self, rolling_packet_buffer=None):
     """
     
     Args:
         rolling_packet_buffer (int, optional): Max packets to
             keep in the rolling buffer at a time. Defaults to unlimited.
     """
     self.walker = SimpleFocusListWalker([])
     self.packets = scapy.plist.PacketList()
     self.rolling_packet_buffer = rolling_packet_buffer
     super(ScrollingListBox, self).__init__(self.walker)
Exemplo n.º 13
0
 def __init__(self, controller):
     self.controller = controller
     self.listwalker = SimpleFocusListWalker([])
     self.listbox = ListBox(self.listwalker)
     self.linebox = MyLineBox(self.listbox)
     body = [
         ('pack', Text("")),
         ('weight', 1, Padding.center_79(self.linebox)),
         ('pack', Text("")),
     ]
     self.pile = Pile(body)
     super().__init__(self.pile)
Exemplo n.º 14
0
class ProgressView(BaseView):
    def __init__(self, controller):
        self.controller = controller
        self.listwalker = SimpleFocusListWalker([])
        self.listbox = ListBox(self.listwalker)
        self.linebox = MyLineBox(self.listbox)
        body = [
            ('pack', Text("")),
            ('weight', 1, Padding.center_79(self.linebox)),
            ('pack', Text("")),
        ]
        self.pile = Pile(body)
        super().__init__(self.pile)

    def add_log_tail(self, text):
        at_end = len(
            self.listwalker) == 0 or self.listbox.focus_position == len(
                self.listwalker) - 1
        for line in text.splitlines():
            self.listwalker.append(Text(line))
        if at_end:
            self.listbox.set_focus(len(self.listwalker) - 1)
            self.listbox.set_focus_valign('bottom')

    def clear_log_tail(self):
        self.listwalker[:] = []

    def set_status(self, text):
        self.linebox.set_title(text)

    def show_complete(self, include_exit=False):
        buttons = [
            ok_btn(_("Reboot Now"), on_press=self.reboot),
        ]
        if include_exit:
            buttons.append(cancel_btn(_("Exit To Shell"), on_press=self.quit))
        buttons = button_pile(buttons)

        new_pile = Pile([
            ('pack', Text("")),
            buttons,
            ('pack', Text("")),
        ])
        self.pile.contents[-1] = (new_pile, self.pile.options('pack'))
        self.pile.focus_position = len(self.pile.contents) - 1

    def reboot(self, btn):
        self.controller.reboot()

    def quit(self, btn):
        self.controller.quit()
Exemplo n.º 15
0
    def __init__(self, ui=None, track=None, number=None):
        self.ui = ui or self.ui
        self.track = track or self.track
        self.number = number or self.number

        self.header = TrackHeader(self.track.name, number)
        self.clips = SimpleFocusListWalker(
            [ClipButton(self.ui, c)
             for c in self.track.clips] + [AddClipButton(self.on_add_button)])

        Clip.ON_ADD.append(self.on_clip_added)

        WidgetWrap.__init__(self, Frame(ListBox(self.clips),
                                        header=self.header))
Exemplo n.º 16
0
    def __init__(self, tui, locator, device):
        super().__init__(tui)
        self.locator = locator
        self.device = device

        self.add_hotkey('U', self.update, "update")
        self.add_hotkey('w', self.webcams, "webcams")
        self.add_hotkey('a', self.actions, "actions")

        self.body.contents.append(
            (Text("Selected device \"{}\"".format(device)), ('pack', None)))
        self.body.contents.append((Divider(), ('pack', None)))

        self.walker = SimpleFocusListWalker([])
        listbox = ListBox(self.walker)
        self.body.contents.append((listbox, ('weight', 1)))
        self.body.focus_position = 2
        self.update()
Exemplo n.º 17
0
class LogWindow(Window):
    def __init__(self, tui):
        super().__init__(tui)
        description = Text(
            "NOTICE. The log displayed here is a copy of the "
            "daemon log. Keeping the the loglevel at debug impacts "
            "performance. When done, run ':loglevel warning'")
        self.body.contents.append((description, ('pack', None)))
        self.walker = SimpleFocusListWalker([])
        self.listbox = ScrollingListBox(self.walker)
        self.body.contents.append((self.listbox, ('weight', 1)))
        #self.add_hotkey('-', self.update, "increase")
        #self.add_hotkey('+', self.update, "decrease")
        #c e w i d

    def wrap(self, line):
        if line.startswith('CRITICAL'):
            focusmap = 'critical'
        elif line.startswith('ERROR'):
            focusmap = 'error'
        elif line.startswith('WARNING'):
            focusmap = 'warning'
        elif line.startswith('INFO'):
            focusmap = 'info'
        else:
            focusmap = 'default'

        txt = Text(line.strip())
        return AttrMap(txt, focusmap)

    def start(self):
        self.walker.append(Text("---- START LOGGING ----", align='center'))

        def log_cb(json_msg):
            line = json_msg.get('log', None)
            if not line:
                return
            self.walker.append(self.wrap(line))

        self.tui.controller.start_logs(log_cb)

    def stop(self):
        self.tui.controller.stop_logs()
Exemplo n.º 18
0
    def __init__(self, track=None, clip=None):
        self.editing = clip or track

        self.header = Text(
            'Editing clip {}'.format(clip.name) if clip else
            'Adding new clip to {}'.format(track.name) if track else 'Editor')
        self.widgets = [EditorWidget(name, label, default)
             for name, label, default
             in self.editing.get_fields()] \
             if self.editing else []
        self.body = ListBox(SimpleFocusListWalker(self.widgets))

        WidgetWrap.__init__(self, Frame(self.body, self.header))
Exemplo n.º 19
0
    def __init__(self, ui=None, track=None, number=None):
        self.ui     = ui     or self.ui
        self.track  = track  or self.track
        self.number = number or self.number
 
        self.header = TrackHeader(self.track.name, number)
        self.clips = SimpleFocusListWalker(
            [ClipButton(self.ui, c) for c in self.track.clips] +
            [AddClipButton(self.on_add_button)])

        Clip.ON_ADD.append(self.on_clip_added)

        WidgetWrap.__init__(self, Frame(ListBox(self.clips),
                                        header=self.header))
Exemplo n.º 20
0
class ActionWindow(Window):
    def __init__(self, tui):
        super().__init__(tui)
        self.body.contents.append((Text("Available Actions"), ('pack', None)))
        self.body.contents.append((Divider(), ('pack', None)))

        self.walker = SimpleFocusListWalker([])
        listbox = ListBox(self.walker)
        self.body.contents.append((listbox, ('weight', 1)))
        self.body.focus_position = 2
        self.add_hotkey('U', self.update, "update")
        self.update()

    def update(self):
        def action_cb(json_msg):
            self.walker.clear()

            def button_cb(cmd, button):
                self.tui.controller.action(cmd, None)
                self.tui.pop_window()

            self.display_errors(json_msg)
            actions = json_msg.get('actions', None)
            if not actions: return
            for action in actions:
                cmd = action['command']
                label = action['short']
                description = action['long']
                button = Button("[{}] - {}".format(label, description))
                urwid.connect_signal(button,
                                     'click',
                                     button_cb,
                                     user_args=[cmd])
                self.walker.append(AttrMap(button, None, focus_map='selected'))

        self.tui.controller.get_actions(action_cb)
Exemplo n.º 21
0
class DeviceListWindow(Window):
    def __init__(self, tui):
        super().__init__(tui)
        self.body.contents.append(
            (Text("Available CNC Devices"), ('pack', None)))
        self.body.contents.append((Divider(), ('pack', None)))

        self.walker = SimpleFocusListWalker([])
        listbox = ListBox(self.walker)
        self.body.contents.append((listbox, ('weight', 1)))
        self.body.focus_position = 2
        self.add_hotkey('U', self.update, "update")
        self.add_hotkey('w', self.webcams, "webcams")
        self.add_hotkey('a', self.actions, "actions")
        self.update()

    def update(self):
        def devlist_cb(json_msg):
            self.walker.clear()

            def button_cb(locator, device, button):
                window = DeviceWindow(self.tui, locator, device)
                self.tui.push_window(window)

            self.display_errors(json_msg)
            devices = json_msg.get('devices')
            if not devices: return
            for locator, device in devices.items():
                button = Button(device)
                urwid.connect_signal(button,
                                     'click',
                                     button_cb,
                                     user_args=[locator, device])
                self.walker.append(AttrMap(button, None, focus_map='selected'))

        self.tui.controller.get_devlist(devlist_cb)
Exemplo n.º 22
0
    def menu(self, choices, go_to_prev):
        def get_button(label, id):
            button = Button(label, None, id)
            connect_signal(button, 'click', self.chosen_item, id)
            return button

        body = []
        for c in choices:
            button = get_button(c[0], c[1])
            body.append(AttrMap(button, None, focus_map='reversed'))

        body.append(Divider())
        body.append(get_button(go_to_prev[0], go_to_prev[1]))

        return ListBox(SimpleFocusListWalker(body))
Exemplo n.º 23
0
def on_group_changed():
    focus_item = group_listbox.get_focus()

    for group_widget in GROUP_WIDGETS:
        if group_widget == focus_item[0]:
            group_widget.set_attr_map({None: 'group_focus'})
        else:
            group_widget.set_attr_map({None: None})

    group_widget = focus_item[0].original_widget[0].text

    host_listbox.body = SimpleFocusListWalker(HOST_WIDGETS[group_widget])

    for widget_attrs in HOST_WIDGETS.values():
        for host_attr in widget_attrs:
            host_attr.original_widget[0].set_state(False)
Exemplo n.º 24
0
	def __init__(self, rows, columns, title=None, headers=False, zebra=False, dividechars=1, padding=None, row_factory=None):
		self.columns = columns
		self.headers = headers
		self.zebra = zebra
		self.dividechars = dividechars
		if row_factory is not None:
			self.row_factory = row_factory


		_rows = []

		if self.headers:
			header = Columns([],dividechars=self.dividechars, min_width=self.min_width)
			for k in columns:
				head = columns[k].get('header', k)
				size = TableRow.size_options(*columns[k]['size']) if 'size' in columns[k] else TableRow.size_options()
				header.contents.append( (Text(head), size) )
			header = AttrMap(header, 'table_header')

				
		for i, row in enumerate(rows):
			r = self.build_row(row, i)
			_rows.append(r)

		self.listwalker = SimpleFocusListWalker(_rows)
		self.listbox = ListBox(self.listwalker)
		self.frame = Frame(self.listbox)
		widget = self.frame
		if padding is not None:
			widget = Padding(self.frame, left=padding[0], right=padding[1])

		if self.headers:
			self.set_title(header)
		elif title:
			self.set_title(title)

		self.__super.__init__(widget)
Exemplo n.º 25
0
    def __init__(self, app):
        ClipLauncherUI.__init__(self, app)

        # set colors
        self.app.main_loop.screen.register_palette(self.palette)

        # create widgets
        tracks = enumerate(self.app.tracks)
        self.cols = Columns(
            SimpleFocusListWalker(
                [TrackWidget(self, t, n + 1) for n, t in tracks]),
            self.track_spacing)
        self.editor = Panel()
        self.header = TransportWidget(app.transport)
        self.footer = AttrMap(Text('foo'), 'footer')

        # listen to events
        INFO.append(self.on_info)

        # init as pile of widgets
        WidgetWrap.__init__(
            self,
            Pile([('pack', self.header), self.cols, (10, self.editor),
                  ('pack', self.footer)]))
Exemplo n.º 26
0
 def __init__(self, chat):
     self.chat = chat
     self.walker = SimpleFocusListWalker([])
     super(ChatMessages, self).__init__(self.walker)
Exemplo n.º 27
0
 def __init__(self, chat):
     self.chat = chat
     self.walker = SimpleFocusListWalker([])
     super(ChatMessages, self).__init__(self.walker)
Exemplo n.º 28
0
class ProgressView(BaseView):
    def __init__(self, controller):
        self.controller = controller
        self.spinner = Spinner(controller.loop)

        self.event_listwalker = SimpleFocusListWalker([])
        self.event_listbox = ListBox(self.event_listwalker)
        self.event_linebox = MyLineBox(self.event_listbox)
        self.event_buttons = button_pile([other_btn("View full log", on_press=self.view_log)])
        event_body = [
            ('pack', Text("")),
            ('weight', 1, Padding.center_79(self.event_linebox)),
            ('pack', Text("")),
            ('pack', self.event_buttons),
            ('pack', Text("")),
        ]
        self.event_pile = Pile(event_body)

        self.log_listwalker = SimpleFocusListWalker([])
        self.log_listbox = ListBox(self.log_listwalker)
        log_linebox = MyLineBox(self.log_listbox, _("Full installer output"))
        log_body = [
            ('weight', 1, log_linebox),
            ('pack', button_pile([other_btn(_("Close"), on_press=self.close_log)])),
            ]
        self.log_pile = Pile(log_body)

        super().__init__(self.event_pile)

    def add_event(self, text):
        at_end = len(self.event_listwalker) == 0 or self.event_listbox.focus_position == len(self.event_listwalker) - 1
        if len(self.event_listwalker) > 0:
            self.event_listwalker[-1] = self.event_listwalker[-1][0]
        self.event_listwalker.append(Columns([('pack', Text(text)), ('pack', self.spinner)], dividechars=1))
        if at_end:
            self.event_listbox.set_focus(len(self.event_listwalker) - 1)
            self.event_listbox.set_focus_valign('bottom')

    def add_log_line(self, text):
        at_end = len(self.log_listwalker) == 0 or self.log_listbox.focus_position == len(self.log_listwalker) - 1
        self.log_listwalker.append(Text(text))
        if at_end:
            self.log_listbox.set_focus(len(self.log_listwalker) - 1)
            self.log_listbox.set_focus_valign('bottom')

    def set_status(self, text):
        self.event_linebox.set_title(text)

    def show_complete(self, include_exit=False):
        p = self.event_buttons.original_widget
        p.contents.append(
            (ok_btn(_("Reboot Now"), on_press=self.reboot), p.options('pack')))
        if include_exit:
            p.contents.append(
                (cancel_btn(_("Exit To Shell"), on_press=self.quit), p.options('pack')))

        w = 0
        for b, o in p.contents:
            w = max(len(b.base_widget.label), w)
        self.event_buttons.width = self.event_buttons.min_width = w + 4
        self.event_pile.focus_position = 3
        p.focus_position = 1

    def reboot(self, btn):
        self.controller.reboot()

    def quit(self, btn):
        self.controller.quit()

    def view_log(self, btn):
        self._w = self.log_pile

    def close_log(self, btn):
        self._w = self.event_pile
Exemplo n.º 29
0
class TableBox(WidgetWrap):

	headers = False

	dividechars = 0
	min_width = 1

	zebra = False
	odd = (None, 'darker gray')
	even = (None, None)

	row_factory = TableRow

	listbox = None

	def __init__(self, rows, columns, title=None, headers=False, zebra=False, dividechars=1, padding=None, row_factory=None):
		self.columns = columns
		self.headers = headers
		self.zebra = zebra
		self.dividechars = dividechars
		if row_factory is not None:
			self.row_factory = row_factory


		_rows = []

		if self.headers:
			header = Columns([],dividechars=self.dividechars, min_width=self.min_width)
			for k in columns:
				head = columns[k].get('header', k)
				size = TableRow.size_options(*columns[k]['size']) if 'size' in columns[k] else TableRow.size_options()
				header.contents.append( (Text(head), size) )
			header = AttrMap(header, 'table_header')

				
		for i, row in enumerate(rows):
			r = self.build_row(row, i)
			_rows.append(r)

		self.listwalker = SimpleFocusListWalker(_rows)
		self.listbox = ListBox(self.listwalker)
		self.frame = Frame(self.listbox)
		widget = self.frame
		if padding is not None:
			widget = Padding(self.frame, left=padding[0], right=padding[1])

		if self.headers:
			self.set_title(header)
		elif title:
			self.set_title(title)

		self.__super.__init__(widget)

	def set_title(self, txt):
		if not isinstance(txt, Widget):
			txt = Text(txt)
		self.frame.header = txt
		self.title = txt

	def build_row(self, data, i):
		tablerow = data
		if not isinstance(tablerow, Widget):
			color = None
			if self.zebra:
				color = self.even if (i+1) % 2 == 0 else self.odd
			tablerow = self.row_factory(tablerow, parent=self, color=color, dividechars=self.dividechars, min_width=self.min_width)

			if self.zebra:
				tablerow = AttrMap(tablerow, B16(*color))
		return tablerow

	def __getitem__(self, idx):
		if hasattr(self.listwalker[idx], 'original_widget'):
			return self.listwalker[idx].original_widget
		else:
			return self.listwalker[idx]

	def __setitem__(self, idx, value):
		self.listwalker[idx] = self.build_row(value, idx)

	def __delitem__(self, idx):
		del self.listwalker[idx]

	def __len__(self):
		return len(self.listwalker)

	def __iter__(self):
		return iter(self.listwalker)

	def insert(self, idx, value):
		self.listwalker.insert(idx, self.build_row(value, idx))

	def append(self, value):
		idx = len(self.listwalker)
		self.listwalker.append(self.build_row(value, idx))
Exemplo n.º 30
0
        self.open_pop_up()
    def create_pop_up (self):
        p = PopUpDialog(self.item)
        connect_signal(p, 'close',
            lambda button: self.close_pop_up())
        return p
    def get_pop_up_parameters (self):
        return {'left':0, 'top':1, 'overlay_width':25, 'overlay_height':20}
"""
    Testing
"""
if __name__ == '__main__':
    b = Button('click me')
    p1 = Process.Process(1, lambda x: x, lambda: x)
    popup = ProcessItemDialog(b, p1)
    connect_signal(b, 'click', lambda x: popup.open())
    proc = AttrMap(popup, None)
    lb = ListBox(SimpleFocusListWalker([proc]))

    def exit (p):
        if p is 'q':
            raise ExitMainLoop

    m = MainLoop(
        lb,
        palette=palette,
        pop_ups=True,
        unhandled_input=exit
    )
    m.run()
Exemplo n.º 31
0
def NoTabCyclingListBox(body):
    body = SimpleFocusListWalker(body)
    return ScrollBarListBox(UrwidListBox(body))
Exemplo n.º 32
0
        column_widget = Columns([host_widget, ipaddr_widget], dividechars=2)
        urwid.connect_signal(host_widget, 'change', on_host_selected, host)

        host_widget = AttrMap(column_widget, None, 'host_focus')
        HOST_WIDGETS[group].append(host_widget)

    group_widget = SelectableText(group, wrap='clip')
    count_widget = Text(str(len(hosts)), align='left')
    arrow_widget = Text(">", align='right')
    column_widget = Columns(
        [group_widget, count_widget, arrow_widget], dividechars=2)
    group_widget = AttrMap(column_widget, None)
    GROUP_WIDGETS.append(group_widget)

group_model = SimpleFocusListWalker(GROUP_WIDGETS)
group_listbox = ListBox(group_model)
group_box = LineBox(group_listbox, tlcorner='', tline='', lline='',
                    trcorner='', blcorner='', rline='│', bline='', brcorner='')
urwid.connect_signal(group_model, "modified", on_group_changed)

first_host_widget = HOST_WIDGETS[HOST_WIDGETS.keys()[0]]
host_model = SimpleFocusListWalker(first_host_widget)
host_listbox = ListBox(host_model)
host_box = LineBox(host_listbox, tlcorner='', tline='', lline='',
                   trcorner='', blcorner='', rline='', bline='', brcorner='')

GROUP_WIDGETS[0].set_attr_map({None: 'group_focus'})

columns = Columns([group_box, host_box])
body = LineBox(columns)
Exemplo n.º 33
0
 def _make(self, rows):
     body = SimpleFocusListWalker(rows)
     return ScrollBarListBox(UrwidListBox(body))
Exemplo n.º 34
0
class GUI(object):
    def __init__(self):
        self.screen = Screen()
        self.screen.set_input_timeouts(max_wait=0)
        self.steps = GridFlow([], 20, 2, 1, 'left')
        self.progress = SimpleFocusListWalker([])
        self.log = SimpleFocusListWalker([])

        self.widget = AttrMap(
            LineBox(Pile([
                ('fixed', 6, AttrMap(Filler(self.steps), 'default')),
                ('fixed', 1, Filler(Divider('\u2500'))),
                ('fixed', 3, ListBox(self.progress)),
                AttrMap(LineBox(ListBox(self.log), title='Message log'),
                        'default')
            ]),
                    title='Indico 1.2 -> 2.0 migration'), 'global_frame')

        self.screen.register_palette(
            [('green', 'light green', ''), ('white', 'white', ''),
             ('red', 'dark red', ''), ('yellow', 'yellow', ''),
             ('progress_empty', 'black',
              'light gray'), ('progress_progress', 'light cyan', 'light gray'),
             ('progress_done', 'black', 'light cyan'),
             ('box', 'white', 'dark gray'), ('step_done', 'light green', ''),
             ('step_working', 'dark gray',
              ''), ('global_frame', 'light cyan',
                    ''), ('fill', 'light cyan', 'dark cyan'),
             ('done', 'white', 'dark green'), ('eta', 'yellow', 'dark gray')] +
            generate_urwid_palette(PALETTE))

    def print_log(self, icon, message, prefix='', event_id=''):
        self.log.append(
            Text([
                color_segments(icon), ' ',
                color_segments(prefix), ' ' if prefix else '',
                color_segments(
                    '%[cyan][%[cyan!]{}%[cyan]]%[reset]'.format(event_id))
                if event_id else '', ' ' if event_id else '',
                color_segments(message)
            ]))
        self.log.set_focus(len(self.log) - 1)
        self.redraw()

    def start(self):
        # don't let Python warnings ruin the GUI
        warnings.filterwarnings('ignore')
        self.screen.start()
        self.redraw()

    def stop(self):
        self.screen.stop()
        warnings.filterwarnings('default')

    def create_progress_bar(self, description):
        if self.progress:
            del self.progress[:]
        return StepProgressBar(self, description)

    def set_success(self):
        if self.progress:
            del self.progress[:]
        self.progress.append(
            AttrMap(Text('Migration finished!', align='center'), 'done'))
        self.progress.append(
            AttrMap(Text('Please press any key...', align='center'), 'done'))
        self.redraw()
        self.wait_for_input()

    def wait_for_input(self):
        self.screen._getch(None)

    def set_step_banner(self, msg):
        if self.progress:
            del self.progress[:]
        self.progress.append(BoxAdapter(AttrMap(SolidFill('#'), 'fill'), 3))

    def redraw(self):
        screen_size = self.screen.get_cols_rows()
        canvas = self.widget.render(screen_size, focus=True)
        self.screen.get_input()
        self.screen.draw_screen(screen_size, canvas)
Exemplo n.º 35
0
    def _build_widget(self):
        lw = SimpleFocusListWalker(list(self.contents))

        return ListBox(lw)
Exemplo n.º 36
0
class ScrollingListBox(ListBox):
    def __init__(self, rolling_packet_buffer=None):
        """
        
        Args:
            rolling_packet_buffer (int, optional): Max packets to
                keep in the rolling buffer at a time. Defaults to unlimited.
        """
        self.walker = SimpleFocusListWalker([])
        self.packets = scapy.plist.PacketList()
        self.rolling_packet_buffer = rolling_packet_buffer
        super(ScrollingListBox, self).__init__(self.walker)

    def add(self, message, packet):
        """

        Args:
            message (str): Text message that will appear
            packet (Scapy packet): Packet that corresponds to this entry.
        """
        txt = AttrMap(Text(message), 'frame', 'selected')
        self.walker.append(txt)
        self.packets.append(packet)

        if self.rolling_packet_buffer is not None and len(
                self.walker) > self.rolling_packet_buffer:
            self.packets.pop(0)
            self.walker.pop(0)

        currently_selected = self.get_focus()
        if isinstance(currently_selected, (list, tuple)):
            currently_selected = currently_selected[0]

        # This ensures auto scrolling only engages if our selected item is the bottom one
        if len(self.walker) <= 1 or currently_selected is self.walker[-2]:
            self.set_focus(len(self.walker) - 1)

    def get_packet(self, message):
        """ Given message, return the corresponding packet. """
        return self.packets[self.walker.index(message)]

    def _keypress_up(self, size):
        # TODO: Not sure why key up is failing like this... Really need to figure out root cause
        #out = super(ScrollingListBox, self)._keypress_up(size)

        try:
            self.set_focus(self.walker.prev_position(self.walker.focus))
            return None  # No more handling needed
        except IndexError:
            # IndexError is expected when we're at the top of the list
            return True

    def _keypress_down(self, size):
        # TODO: Not sure why key up is failing like this... Really need to figure out root cause (jumping down a page before incrementing down)

        try:
            self.set_focus(self.walker.next_position(self.walker.focus))
            return None  # No more handling needed
        except IndexError:
            # IndexError is expected when we're at the top of the list
            return True