Example #1
0
 def __init__(self, path, application, with_menu=True):
     super(UrwidWindow, self).__init__(path, application)
     urwid.set_encoding("utf8")
     self._builder = UrwidUIBuilder(self.application)
     self.with_menu = with_menu
     self.logger.debug("Creating urwid tui for '%s'" % application)
     self.logger.debug("Detected encoding: %s" % urwid.get_encoding_mode())
Example #2
0
    def graph_controls(self):
        modes = self.controller.get_modes()
        self.mode_buttons = []
        group = []
        for m in modes:
            rb = self.radio_button( group, m, self.on_mode_button )
            self.mode_buttons.append( rb )

        if urwid.get_encoding_mode() == "utf8":
            unicode_checkbox = urwid.CheckBox(
                "Enable Unicode Graphics",
                on_state_change=self.on_unicode_checkbox)
        else:
            unicode_checkbox = urwid.Text(
                "UTF-8 encoding not detected")

        l = [    urwid.Text("Mode",align="center"),
            ] + self.mode_buttons + [
            urwid.Divider(),
            urwid.Text("Animation",align="center"),
            urwid.Divider(),
            urwid.LineBox( unicode_checkbox ),
            urwid.Divider(),
            self.button("Quit", self.exit_program ),
            ]
        w = urwid.ListBox(urwid.SimpleListWalker(l))
        return w
Example #3
0
    def graph_controls(self):
        modes = self.controller.get_modes()
        self.mode_buttons = []
        group = []
        for m in modes:
            rb = self.radio_button(group, m, self.on_mode_button)
            self.mode_buttons.append(rb)

        if urwid.get_encoding_mode() == "utf8":
            unicode_checkbox = urwid.CheckBox(
                "Enable Unicode Graphics",
                on_state_change=self.on_unicode_checkbox)
        else:
            unicode_checkbox = urwid.Text("UTF-8 encoding not detected")

        l = [
            urwid.Text("Mode", align="center"),
        ] + self.mode_buttons + [
            urwid.Divider(),
            urwid.Text("Animation", align="center"),
            urwid.Divider(),
            urwid.LineBox(unicode_checkbox),
            urwid.Divider(),
            self.button("Quit", self.exit_program),
        ]
        w = urwid.ListBox(urwid.SimpleListWalker(l))
        return w
Example #4
0
 def __init__(self, path, application, with_menu=True):
     super(UrwidWindow, self).__init__(path, application)
     urwid.set_encoding("utf8")
     self._builder = UrwidUIBuilder(self.application)
     self.with_menu = with_menu
     self.logger.debug("Creating urwid tui for '%s'" % application)
     self.logger.debug("Detected encoding: %s" % urwid.get_encoding_mode())
Example #5
0
    def graph_controls(self):
        """ Dislplay sidebar controls. i.e. buttons, and controls"""
        modes = self.controller.get_modes()
        # setup mode radio buttons
        group = []
        for m in modes:
            rb = radio_button(group, m, self.on_mode_button)
            self.mode_buttons.append(rb)

        # Create list of buttons
        control_options = [button("Reset", self.on_reset_button)]
        if stress_installed:
            control_options.append(button('Stress Options', self.on_stress_menu_open))
        control_options.append(button('Temp Sensors', self.on_temp_sensors_menu_open))
        control_options.append(button('Help', self.on_help_menu_open))
        control_options.append(button('About', self.on_about_menu_open))

        # Create the menu
        animate_controls = urwid.GridFlow(control_options, 18, 2, 0, 'center')


        if urwid.get_encoding_mode() == "utf8":
            unicode_checkbox = urwid.CheckBox(
                "Smooth Graph", state=False,
                on_state_change=self.on_unicode_checkbox)
        else:
            unicode_checkbox = urwid.Text(
                "UTF-8 encoding not detected")


        install_stress_message = urwid.Text("")
        if not stress_installed:
            install_stress_message = urwid.Text(('button normal', u"(N/A) install stress"))


        graph_checkboxes = [urwid.CheckBox(x.get_graph_name(), state=True,
                            on_state_change=lambda w, state, x=x:  self.change_checkbox_state(x, state))
                            for x in self.available_graphs.values()]
        unavalable_graphs = [urwid.Text(( "[N/A] " + x.get_graph_name()) ) for x in self.graphs.values() if x.source.get_is_available() == False]
        graph_checkboxes += unavalable_graphs

        buttons = [urwid.Text(('bold text', u"Modes"), align="center"),
                   ] +  self.mode_buttons + [
            install_stress_message,
            urwid.Divider(),
            urwid.Text(('bold text', u"Control Options"), align="center"),
            animate_controls,
            urwid.Divider(),
            self.refresh_rate_ctrl,
            urwid.Divider(),
            urwid.LineBox(urwid.Pile(graph_checkboxes)),
            urwid.LineBox(unicode_checkbox),
            urwid.Divider(),
            button("Quit", self.exit_program),
            ]

        return buttons
Example #6
0
    def __init__(self, event_loop, palette, interpreter, config):
        super().__init__(interpreter, config)

        self._redraw_handle = None
        self._redraw_pending = False
        self._redraw_time = 0

        self.listbox = BPythonListBox(urwid.SimpleListWalker([]))

        self.tooltip = urwid.ListBox(urwid.SimpleListWalker([]))
        self.tooltip.grid = None
        self.overlay = Tooltip(self.listbox, self.tooltip)
        self.stdout_hist = ""  # native str (unicode in Py3)

        self.frame = urwid.Frame(self.overlay)

        if urwid.get_encoding_mode() == "narrow":
            input_filter = decoding_input_filter
        else:
            input_filter = None

        # This constructs a raw_display.Screen, which nabs sys.stdin/out.
        self.main_loop = urwid.MainLoop(
            self.frame,
            palette,
            event_loop=event_loop,
            unhandled_input=self.handle_input,
            input_filter=input_filter,
            handle_mouse=False,
        )

        # String is straight from bpython.cli
        self.statusbar = Statusbar(
            config,
            _(" <%s> Rewind  <%s> Save  <%s> Pastebin "
              " <%s> Pager  <%s> Show Source ") % (
                  config.undo_key,
                  config.save_key,
                  config.pastebin_key,
                  config.last_output_key,
                  config.show_source_key,
              ),
            self.main_loop,
        )
        self.frame.set_footer(self.statusbar.widget)
        self.interact = URWIDInteraction(self.config, self.statusbar,
                                         self.frame)

        self.edits = []
        self.edit = None
        self.current_output = None
        self._completion_update_suppressed = False

        # Bulletproof: this is a value extract_exit_value accepts.
        self.exit_value = ()

        load_urwid_command_map(config)
Example #7
0
    def setup_view(self):
        fonts = urwid.get_all_fonts()
        # setup mode radio buttons
        self.font_buttons = []
        group = []
        utf8 = urwid.get_encoding_mode() == "utf8"
        for name, fontcls in fonts:
            font = fontcls()
            if font.utf8_required and not utf8:
                rb = self.create_disabled_radio_button(name)
            else:
                rb = self.create_radio_button(group, name, font,
                    self.set_font_event)
                if fontcls == urwid.Thin6x6Font:
                    chosen_font_rb = rb
                    exit_font = font
            self.font_buttons.append( rb )
        
        # Create BigText
        self.bigtext = urwid.BigText("", None)
        bt = SwitchingPadding(self.bigtext, 'left', None)
        bt = urwid.AttrWrap(bt, 'bigtext')
        bt = urwid.Filler(bt, 'bottom', None, 7)
        bt = urwid.BoxAdapter(bt, 7)
        
        # Create chars_avail
        cah = urwid.Text("Characters Available:")
        self.chars_avail = urwid.Text("", wrap='any')
        ca = urwid.AttrWrap(self.chars_avail, 'chars')
        
        chosen_font_rb.set_state(True) # causes set_font_event call
    
        # Create Edit widget
        edit = self.create_edit("", "Urwid "+urwid.__version__,
            self.edit_change_event)
        
        # ListBox
        chars = urwid.Pile([cah, ca])
        fonts = urwid.Pile([urwid.Text("Fonts:")] + self.font_buttons,
            focus_item=1)
        col = urwid.Columns([('fixed',16,chars), fonts], 3, 
            focus_column=1)
        bt = urwid.Pile([bt, edit], focus_item=1)
        l = [bt, urwid.Divider(), col]
        w = urwid.ListBox(urwid.SimpleListWalker(l))
        
        # Frame
        w = urwid.AttrWrap(w, 'body')
        hdr = urwid.Text("Urwid BigText example program - F8 exits.")
        hdr = urwid.AttrWrap(hdr, 'header')
        w = urwid.Frame(header=hdr, body=w)

        # Exit message
        exit = urwid.BigText(('exit'," Quit? "), exit_font)
        exit = urwid.Overlay(exit, w, 'center', None, 'middle', None)
        return w, exit
Example #8
0
    def setup_view(self):
        fonts = urwid.get_all_fonts()
        # setup mode radio buttons
        self.font_buttons = []
        group = []
        utf8 = urwid.get_encoding_mode() == "utf8"
        for name, fontcls in fonts:
            font = fontcls()
            if font.utf8_required and not utf8:
                rb = self.create_disabled_radio_button(name)
            else:
                rb = self.create_radio_button(group, name, font,
                    self.set_font_event)
                if fontcls == urwid.Thin6x6Font:
                    chosen_font_rb = rb
                    exit_font = font
            self.font_buttons.append( rb )

        # Create BigText
        self.bigtext = urwid.BigText("", None)
        bt = SwitchingPadding(self.bigtext, 'left', None)
        bt = urwid.AttrWrap(bt, 'bigtext')
        bt = urwid.Filler(bt, 'bottom', None, 7)
        bt = urwid.BoxAdapter(bt, 7)

        # Create chars_avail
        cah = urwid.Text("Characters Available:")
        self.chars_avail = urwid.Text("", wrap='any')
        ca = urwid.AttrWrap(self.chars_avail, 'chars')

        chosen_font_rb.set_state(True) # causes set_font_event call

        # Create Edit widget
        edit = self.create_edit("", "Urwid "+urwid.__version__,
            self.edit_change_event)

        # ListBox
        chars = urwid.Pile([cah, ca])
        fonts = urwid.Pile([urwid.Text("Fonts:")] + self.font_buttons,
            focus_item=1)
        col = urwid.Columns([('fixed',16,chars), fonts], 3,
            focus_column=1)
        bt = urwid.Pile([bt, edit], focus_item=1)
        l = [bt, urwid.Divider(), col]
        w = urwid.ListBox(urwid.SimpleListWalker(l))

        # Frame
        w = urwid.AttrWrap(w, 'body')
        hdr = urwid.Text("Urwid BigText example program - F8 exits.")
        hdr = urwid.AttrWrap(hdr, 'header')
        w = urwid.Frame(header=hdr, body=w)

        # Exit message
        exit = urwid.BigText(('exit'," Quit? "), exit_font)
        exit = urwid.Overlay(exit, w, 'center', None, 'middle', None)
        return w, exit
Example #9
0
    def __init__(self, event_loop, palette, interpreter, config):
        repl.Repl.__init__(self, interpreter, config)

        self._redraw_handle = None
        self._redraw_pending = False
        self._redraw_time = 0

        self.listbox = BPythonListBox(urwid.SimpleListWalker([]))

        self.tooltip = urwid.ListBox(urwid.SimpleListWalker([]))
        self.tooltip.grid = None
        self.overlay = Tooltip(self.listbox, self.tooltip)
        self.stdout_hist = ''

        self.frame = urwid.Frame(self.overlay)

        if urwid.get_encoding_mode() == 'narrow':
            input_filter = decoding_input_filter
        else:
            input_filter = None

        # This constructs a raw_display.Screen, which nabs sys.stdin/out.
        self.main_loop = urwid.MainLoop(
            self.frame, palette,
            event_loop=event_loop, unhandled_input=self.handle_input,
            input_filter=input_filter, handle_mouse=False)

        menu_string = ''
        for name, key in (
            ('Rewind', config.undo_key),
            ('Save', config.save_key),
            ('Pastebin', config.pastebin_key),
            ('Pager', config.last_output_key),
            ('Show Source', config.show_source_key)
        ):
            if key:
                menu_string += ' <%s> %s ' % (key, name)

        # String is straight from bpython.cli
        self.statusbar = Statusbar(config, menu_string, self.main_loop)
        self.frame.set_footer(self.statusbar.widget)
        self.interact = URWIDInteraction(
            self.config,
            self.statusbar,
            self.frame)

        self.edits = []
        self.edit = None
        self.current_output = None
        self._completion_update_suppressed = False

        # Bulletproof: this is a value extract_exit_value accepts.
        self.exit_value = ()

        load_urwid_command_map(config)
Example #10
0
    def __init__(self, event_loop, palette, interpreter, config):
        repl.Repl.__init__(self, interpreter, config)

        self._redraw_handle = None
        self._redraw_pending = False
        self._redraw_time = 0

        self.listbox = BPythonListBox(urwid.SimpleListWalker([]))

        self.tooltip = urwid.ListBox(urwid.SimpleListWalker([]))
        self.tooltip.grid = None
        self.overlay = Tooltip(self.listbox, self.tooltip)
        self.stdout_hist = ""

        self.frame = urwid.Frame(self.overlay)

        if urwid.get_encoding_mode() == "narrow":
            input_filter = decoding_input_filter
        else:
            input_filter = None

        # This constructs a raw_display.Screen, which nabs sys.stdin/out.
        self.main_loop = urwid.MainLoop(
            self.frame,
            palette,
            event_loop=event_loop,
            unhandled_input=self.handle_input,
            input_filter=input_filter,
            handle_mouse=False,
        )

        # String is straight from bpython.cli
        self.statusbar = Statusbar(
            config,
            _(" <%s> Rewind  <%s> Save  <%s> Pastebin " " <%s> Pager  <%s> Show Source ")
            % (config.undo_key, config.save_key, config.pastebin_key, config.last_output_key, config.show_source_key),
            self.main_loop,
        )
        self.frame.set_footer(self.statusbar.widget)
        self.interact = URWIDInteraction(self.config, self.statusbar, self.frame)

        self.edits = []
        self.edit = None
        self.current_output = None
        self._completion_update_suppressed = False

        load_urwid_command_map(config)
Example #11
0
    def __init__(self, parent, packet, frontend, focused=False):

        self.packet = packet
        self.frontend = frontend
        self.is_root = False
        self.focused = focused

        if urwid.get_encoding_mode() == "utf8" and not frontend.ascii_only:
            self.ICONS = self.UTF8_ICONS
        else:
            self.ICONS = self.ASCII_ICONS

        super().__init__(parent)

        self.expanded = False
        self.is_leaf = not packet.subordinate_packets
        self._wrapped_widget = self.get_row_widget()
Example #12
0
    def graph_controls(self):
        modes = self.controller.get_modes()
        # setup mode radio buttons
        self.mode_buttons = []
        group = []
        for m in modes:
            rb = self.radio_button( group, m, self.on_mode_button )
            self.mode_buttons.append( rb )
        # setup animate button
        self.animate_button = self.button( "", self.on_animate_button)
        self.on_animate_button( self.animate_button )
        self.offset = 0
        self.animate_progress = self.progress_bar()
        animate_controls = urwid.GridFlow( [
            self.animate_button,
            self.button("Reset", self.on_reset_button),
            ], 9, 2, 0, 'center')

        if urwid.get_encoding_mode() == "utf8":
            unicode_checkbox = urwid.CheckBox(
                "Enable Unicode Graphics",
                on_state_change=self.on_unicode_checkbox)
        else:
            unicode_checkbox = urwid.Text(
                "UTF-8 encoding not detected")

        self.animate_progress_wrap = urwid.WidgetWrap(
            self.animate_progress)

        l = [urwid.Text("The display widget",align="left"),
             urwid.Text("Mode",align="left"),
            ] + self.mode_buttons + [
            urwid.Divider(),
            urwid.Text("Animation",align="left"),
            animate_controls,
            self.animate_progress_wrap,
            urwid.Divider(),
            urwid.LineBox( unicode_checkbox ),
            urwid.Divider(),
            self.button("Quit", self.exit_program ),
            ]
        w = urwid.ListBox(urwid.SimpleListWalker(l))
        return w
Example #13
0
 def graph_controls(self):
     modes = self.controller.get_modes()
     # setup mode radio buttons
     self.mode_buttons = []
     group = []
     for m in modes:
         rb = self.radio_button( group, m, self.on_mode_button )
         self.mode_buttons.append( rb )
     # setup animate button
     self.animate_button = self.button( "", self.on_animate_button)
     self.on_animate_button( self.animate_button )
     self.offset = 0
     self.animate_progress = self.progress_bar()
     animate_controls = urwid.GridFlow( [ 
         self.animate_button,
         self.button("Reset", self.on_reset_button),
         ], 9, 2, 0, 'center')
     
     if urwid.get_encoding_mode() == "utf8":
         unicode_checkbox = urwid.CheckBox(
             "Enable Unicode Graphics",
             on_state_change=self.on_unicode_checkbox)
     else:
         unicode_checkbox = urwid.Text(
             "UTF-8 encoding not detected")
         
     self.animate_progress_wrap = urwid.WidgetWrap(
         self.animate_progress)
     
     l = [    urwid.Text("Mode",align="center"),
         ] + self.mode_buttons + [
         urwid.Divider(),
         urwid.Text("Animation",align="center"),
         animate_controls,
         self.animate_progress_wrap,
         urwid.Divider(),
         urwid.LineBox( unicode_checkbox ),
         urwid.Divider(),
         self.button("Quit", self.exit_program ),
         ]
     w = urwid.ListBox(urwid.SimpleListWalker(l))
     return w
Example #14
0
    def __init__(self, event_loop, palette, interpreter, config):

        import urwid_geventloop
        from bpython import repl
        #super(MyURWIDRepl, self).__init__(urwid_geventloop.GeventLoop(), palette, interpreter, config)
        repl.Repl.__init__(self, interpreter, config)

        self._redraw_handle = None
        self._redraw_pending = False
        self._redraw_time = 0

        self.listbox = bpython.BPythonListBox(urwid.SimpleListWalker([]))

        self.tooltip = urwid.ListBox(urwid.SimpleListWalker([]))
        self.tooltip.grid = None
        self.overlay = bpython.Tooltip(self.listbox, self.tooltip)
        self.stdout_hist = ''

        self.frame = urwid.Frame(self.overlay)

        if urwid.get_encoding_mode() == 'narrow':
            input_filter = decoding_input_filter
        else:
            input_filter = None

        # This constructs a raw_display.Screen, which nabs sys.stdin/out.
        self.main_loop = urwid.MainLoop(
            self.frame, palette,
            event_loop=urwid_geventloop.GeventLoop(), unhandled_input=self.handle_input,
            input_filter=input_filter, handle_mouse=False, screen = MyScreen())

        # String is straight from bpython.cli
        self.statusbar = bpython.Statusbar(config,
            bpython._(" <%s> Rewind  <%s> Save  <%s> Pastebin "
              " <%s> Pager  <%s> Show Source ") %
              (config.undo_key, config.save_key, config.pastebin_key,
               config.last_output_key, config.show_source_key), self.main_loop)
        self.frame.set_footer(self.statusbar.widget)
        self.interact = bpython.URWIDInteraction(self.config, self.statusbar, self.frame)

        self.edits = []
        self.edit = None
        self.current_output = None
        self._completion_update_suppressed = False

        # Bulletproof: this is a value extract_exit_value accepts.
        self.exit_value = ()

        bpython.load_urwid_command_map(config)



        logging.root.handlers=[MyLogHandler(self), logging.StreamHandler(file('/tmp/upnpy_browser.log', 'w'))]
        logging.root.setLevel(logging.INFO)
        logging.getLogger('http.access').setLevel(logging.ERROR)

        self.devices = urwid.ListBox(urwid.SimpleListWalker([urwid.Text('Devices:')]))
        self.logs = urwid.ListBox(urwid.SimpleListWalker([]))

        self.frame.set_footer(urwid.BoxAdapter(self.logs, 15))

        self.main_frame = urwid.Columns([
                self.frame,
                ('fixed', 35, self.devices),
                ])

        self.main_loop.widget = self.main_frame

        self.handler = MyDiscoverHandler(u, self)
        u.add_handler(self.handler)
Example #15
0
        delta = graph_min()
        s = [(x - delta, cap) for x, cap in s]
    return list(reversed(s))


def graph_lines():
    return [x[0] for x in graph_lines_captions()]


URWID_IMPORTED = False
URWID_UTF8 = False
try:
    import urwid
    if urwid.VERSION >= (0, 9, 9, 1):
        URWID_IMPORTED = True
        URWID_UTF8 = urwid.get_encoding_mode() == "utf8"
except (ImportError, AttributeError):
    pass


class Speedometer:
    def __init__(self, maxlog=5):
        """speedometer(maxlog=5)
        maxlog is the number of readings that will be stored"""
        self.log = []
        self.start = None
        self.maxlog = maxlog

    def get_log(self):
        return self.log
Example #16
0
    if logarithmic_scale:
        s = [(math.log(x, 2), cap) for x, cap in s]
        # XXX: quick hack to make this work like it used to
        delta = graph_min()
        s = [(x - delta, cap) for x, cap in s]
    return list(reversed(s))

def graph_lines(): return [x[0] for x in graph_lines_captions()]

URWID_IMPORTED = False
URWID_UTF8 = False
try:
    import urwid
    if urwid.VERSION >= (0, 9, 9, 1):
        URWID_IMPORTED = True
        URWID_UTF8 = urwid.get_encoding_mode() == "utf8"
except (ImportError, AttributeError):
    pass


class Speedometer:
    def __init__(self,maxlog=5):
        """speedometer(maxlog=5)
        maxlog is the number of readings that will be stored"""
        self.log = []
        self.start = None
        self.maxlog = maxlog

    def get_log(self):
        return self.log
Example #17
0
    def _generate_graph_controls(self):
        """ Display sidebar controls. i.e. buttons, and controls"""
        # setup mode radio buttons
        stress_modes = self.controller.stress_conroller.get_modes()
        group = []
        for mode in stress_modes:
            self.mode_buttons.append(
                radio_button(group, mode, self.on_mode_button))

        # Set default radio button to "Monitor" mode
        self.mode_buttons[0].set_state(True, do_callback=False)

        # Create list of buttons
        control_options = list()
        control_options.append(button('Graphs', self.on_graphs_menu_open))
        control_options.append(button('Summaries', self.on_summary_menu_open))
        if self.controller.stress_exe:
            control_options.append(
                button('Stress Options', self.on_stress_menu_open))
        control_options.append(button("Reset", self.on_reset_button))
        control_options.append(button('Help', self.on_help_menu_open))
        control_options.append(button('About', self.on_about_menu_open))
        control_options.append(button("Save Settings", self.on_save_settings))
        control_options.append(button("Quit", self.on_exit_program))

        # Create the menu
        animate_controls = urwid.GridFlow(control_options, 18, 2, 0, 'center')

        # Create smooth graph selection button
        default_smooth = self.controller.smooth_graph_mode
        if urwid.get_encoding_mode() == "utf8":
            unicode_checkbox = urwid.CheckBox(
                "UTF-8",
                state=default_smooth,
                on_state_change=self.on_unicode_checkbox)
            # Init the state of the graph accoding to the selected mode
            self.on_unicode_checkbox(state=default_smooth)
        else:
            unicode_checkbox = urwid.Text("[N/A] UTF-8")

        install_stress_message = urwid.Text("")
        if not self.controller.firestarter and not self.controller.stress_exe:
            install_stress_message = urwid.Text(
                ('button normal', u"(N/A) install stress"))

        clock_widget = []
        # if self.controller.stress_exe or self.controller.firestarter:
        if self.controller.stress_exe or self.controller.firestarter:
            clock_widget = [
                urwid.Text(('bold text', u"Stress Timer"), align="center"),
                self.clock_view
            ]

        controls = [urwid.Text(('bold text', u"Modes"), align="center")]
        controls += self.mode_buttons
        controls += [install_stress_message]
        controls += clock_widget
        controls += [
            urwid.Divider(),
            urwid.Text(('bold text', u"Control Options"), align="center"),
            animate_controls,
            urwid.Divider(),
            urwid.Text(('bold text', u"Visual Options"), align="center"),
            unicode_checkbox,
            self.refresh_rate_ctrl,
            urwid.Divider(),
            urwid.Text(('bold text', u"Summaries"), align="center"),
        ]

        return controls
Example #18
0
    def graph_controls(self):
        """ Dislplay sidebar controls. i.e. buttons, and controls"""
        modes = self.controller.get_modes()
        # setup mode radio buttons
        group = []
        for m in modes:
            rb = self.radio_button(group, m, self.on_mode_button)
            self.mode_buttons.append(rb)

        # Create list of buttons
        control_options = [self.button("Reset", self.on_reset_button)]
        if stress_installed:
            control_options.append(
                self.button('Stress Options', self.on_stress_menu_open))
        control_options.append(self.button('Help', self.on_help_menu_open))
        control_options.append(self.button('About', self.on_about_menu_open))

        # Create the menu
        animate_controls = urwid.GridFlow(control_options, 18, 2, 0, 'center')

        if urwid.get_encoding_mode() == "utf8":
            unicode_checkbox = urwid.CheckBox(
                "Smooth Graph", on_state_change=self.on_unicode_checkbox)
        else:
            unicode_checkbox = urwid.Text("UTF-8 encoding not detected")

        hline = urwid.AttrWrap(urwid.SolidFill(u'\N{LOWER ONE QUARTER BLOCK}'),
                               'line')

        install_stress_message = urwid.Text("")
        if not stress_installed:
            install_stress_message = urwid.Text("\nstress not installed")

        graph_checkboxes = [
            urwid.CheckBox('Frequency',
                           state=True,
                           on_state_change=self.show_frequency),
            urwid.CheckBox('Temperature',
                           state=True,
                           on_state_change=self.show_temperature),
            urwid.CheckBox('Utilization',
                           state=True,
                           on_state_change=self.show_utilization)
        ]

        if self.data.is_power_measurement_available():
            graph_checkboxes.append(
                urwid.CheckBox('Power',
                               state=True,
                               on_state_change=self.show_power))

        buttons = [
            urwid.Text(u"Mode", align="center"),
        ] + self.mode_buttons + [
            urwid.Divider(),
            urwid.Text("Control Options", align="center"),
            animate_controls,
            install_stress_message,
            urwid.Divider(),
            urwid.LineBox(unicode_checkbox),
            urwid.Divider(),
            urwid.LineBox(urwid.Pile(graph_checkboxes)),
            urwid.Divider(),
            self.button("Quit", self.exit_program),
        ]

        return buttons
Example #19
0
    def graph_controls(self, conf):
        """ Display sidebar controls. i.e. buttons, and controls"""
        modes = self.controller.get_modes()
        # setup mode radio buttons
        group = []
        for m in modes:
            rb = radio_button(group, m, self.on_mode_button)
            self.mode_buttons.append(rb)

        # Create list of buttons
        control_options = [button("Reset", self.on_reset_button)]
        if stress_installed:
            control_options.append(button('Stress Options',
                                          self.on_stress_menu_open))
        control_options.append(button('Sensors',
                                      self.on_sensors_menu_open))
        control_options.append(button('Help', self.on_help_menu_open))
        control_options.append(button('About', self.on_about_menu_open))

        # Create the menu
        animate_controls = urwid.GridFlow(control_options, 18, 2, 0, 'center')

        # Create smooth graph selection button
        default_smooth = self.controller.smooth_graph_mode
        if urwid.get_encoding_mode() == "utf8":
            unicode_checkbox = urwid.CheckBox(
                "Smooth Graph", state=default_smooth,
                on_state_change=self.on_unicode_checkbox)
            # Init the state of the graph accoding to the selected mode
            self.on_unicode_checkbox(state=default_smooth)
        else:
            unicode_checkbox = urwid.Text(
                "UTF-8 encoding not detected")

        install_stress_message = urwid.Text("")
        if not stress_installed:
            install_stress_message = urwid.Text(
                ('button normal', u"(N/A) install stress"))

        # Disable graphs the user selected not to display in config file
        # TODO: Get this from graph state
        graphs_available_state = dict()
        for g in self.available_graphs.values():
            try:
                graphs_available_state[g.get_graph_name()] = conf.getboolean(
                    'GraphControll', g.get_graph_name())
            except(AttributeError, configparser.NoOptionError,
                   configparser.NoSectionError):
                graphs_available_state[g.get_graph_name()] = True

        graph_checkboxes = [urwid.CheckBox(x.get_graph_name(),
                            graphs_available_state[x.get_graph_name()],
                            on_state_change=lambda w,
                            state, x=x:  self.change_checkbox_state(x, state))
                            for x in self.available_graphs.values()]

        buttons = [urwid.Text(('bold text', u"Modes"), align="center"),
                   ] + self.mode_buttons + [
            install_stress_message,
            urwid.LineBox(self.clock_view),
            urwid.Divider(),
            urwid.Text(('bold text', u"Control Options"), align="center"),
            animate_controls,
            urwid.Divider(),
            self.refresh_rate_ctrl,
            urwid.Divider(),
            urwid.LineBox(urwid.Pile(graph_checkboxes)),
            urwid.LineBox(unicode_checkbox),
            urwid.Divider(),
            button("Save Settings", self.save_settings),
            urwid.Divider(),
            button("Quit", self.exit_program),
        ]

        return buttons
Example #20
0
class VSBPacketWidget(urwid.TreeWidget):
    """ Widget that renders tree elements as text. """

    # If we're in utf8 mode,use fancier widgets than we would in ASCII mode.
    if urwid.get_encoding_mode() == "utf8":
        ICONS = {
            'unexpanded': urwid.SelectableIcon('⊞', 0),
            'expanded':   urwid.SelectableIcon('⊟', 0),
            'leaf':       urwid.Text('•'),
            'in':         urwid.Text(('data', '↩  IN')),
            'out':        urwid.Text(('data', 'OUT ↪')),
        }
    else:
        ICONS = {
            'unexpanded': urwid.SelectableIcon('+', 0),
            'expanded':   urwid.SelectableIcon('-', 0),
            'leaf':       urwid.Text('*'),
            'in':         urwid.Text('<I'),
            'out':        urwid.Text('O>')
        }


    def __init__(self, parent, packet, frontend, focused=False):

        self.packet = packet
        self.frontend = frontend
        self.is_root = False
        self.focused = focused

        super().__init__(parent)

        self.expanded = False
        self.is_leaf = not packet.subordinate_packets
        self._wrapped_widget = self.get_row_widget()


    def get_icon(self):
        """ Retrieve the icon to display whether the node can be expanded or collapsed. """

        # If we have a leaf, render it's single state icon.
        if self.is_leaf:
            icon = self.ICONS['leaf']
        # If we have a parent, return the icon corresponding to its expanded state.
        else:
            icon = self.ICONS['expanded'] if self.expanded else self.ICONS['unexpanded']

        return urwid.AttrWrap(icon, 'icon')


    def update_expanded_icon(self):
        self.core_widget.widget_list[0] = self.get_icon()


    @classmethod
    def _get_text_column(cls, value, style='summary', autohex=True, width=None, weighted=False, align='left', empty='--'):

        if value is None:
            value = empty

        if autohex and isinstance(value, int):
            value = "{:x}".format(value)

        # ... wrap it with a text object...
        widget = urwid.Text((style, str(value)), align=align)

        # ... optionally add a width for urwid.Columns...
        if width is not None:
            if weighted:
                widget = ('weight', width, widget)
            else:
                widget = (width, widget)

        # ... and return the new widget.
        return widget


    def _get_direction_icon(self, direction, width=6):

        if direction == USBDirection.IN:
            return (width, self.ICONS['in'])
        elif direction == USBDirection.OUT:
            return (width, self.ICONS['out'])
        else:
            return (width, urwid.Text(""))


    @classmethod
    def get_row_headers(cls, style=''):
        """ Returns a columns object suitable for column headers."""

        return urwid.Columns([
            #cls._get_text_column('Bus',    style=style, width=3),
            cls._get_text_column('Dev',    style=style, width=3),
            cls._get_text_column('EP',     style=style, width=3),
            cls._get_text_column('Dir',    style=style, width=6),
            cls._get_text_column('Len',    style=style, width=5),
            cls._get_text_column('   Packet', style=style)
        ], dividechars=1)



    def get_row_widget(self):
        """ Returns the widget that represents the given packet. """

        # Get a quick reference to our core packet.
        packet = self.packet

        if packet.get_summary_fields is None:
            return urwid.Text("")

        summary = packet.get_summary_fields()

        # Generate the style for our packet's style.
        status_style = 'okay'
        if summary['style'] and ('exceptional' in summary['style']):
            status_style = 'error'

        # Get the fields of our packet entry.
        return urwid.Columns([
            #self._get_text_column(summary['bus_number'],      width=3),
            self._get_text_column(summary['device_address'],  width=3),
            self._get_text_column(summary['endpoint'],        width=3),
            self._get_direction_icon(summary['is_in']),
            self._get_text_column(summary['length'], autohex=False, width=5, empty=''),
            self.get_indented_core(),
            self._get_text_column(summary['status'], style=status_style, width=6, align='center'),
            self._get_text_column(summary['data_summary'], style='data')
        ], dividechars=1)


    def get_indented_core(self):
        widget = self.get_inner_widget()
        icon   = ('fixed', 1, self.get_icon())

        self.core_widget = urwid.Columns([icon, widget], dividechars=1)

        indent_cols = self.get_indent_cols()
        return urwid.Padding(self.core_widget, width=('relative', 100), left=indent_cols + 1)


    def prev_inorder(self):

        # Use the normal algorithm to identify our predecessor...
        prev = super().prev_inorder()

        # .. but if the previous would be our root widget, return none.
        # This ensures we never select the invisible root widget.
        if isinstance(prev, VSBRootNode.NonDisplayingWidget):
            return None
        else:
            return prev


    def get_display_text(self):
        return [('summary', self.packet.summarize())]

    def selectable(self):
        # Always allow our packets to be selectable, so the user can
        # get more analysis information.
        return True


    def get_indent_cols(self):
        return self.indent_cols * (self.get_node().get_depth() - 1)
Example #21
0
    def __init__(self, event_loop, palette, interpreter, config):

        import urwid_geventloop
        from bpython import repl
        #super(MyURWIDRepl, self).__init__(urwid_geventloop.GeventLoop(), palette, interpreter, config)
        repl.Repl.__init__(self, interpreter, config)

        self._redraw_handle = None
        self._redraw_pending = False
        self._redraw_time = 0

        self.listbox = bpython.BPythonListBox(urwid.SimpleListWalker([]))

        self.tooltip = urwid.ListBox(urwid.SimpleListWalker([]))
        self.tooltip.grid = None
        self.overlay = bpython.Tooltip(self.listbox, self.tooltip)
        self.stdout_hist = ''

        self.frame = urwid.Frame(self.overlay)

        if urwid.get_encoding_mode() == 'narrow':
            input_filter = decoding_input_filter
        else:
            input_filter = None

        # This constructs a raw_display.Screen, which nabs sys.stdin/out.
        self.main_loop = urwid.MainLoop(
            self.frame,
            palette,
            event_loop=urwid_geventloop.GeventLoop(),
            unhandled_input=self.handle_input,
            input_filter=input_filter,
            handle_mouse=False,
            screen=MyScreen())

        # String is straight from bpython.cli
        self.statusbar = bpython.Statusbar(
            config,
            bpython._(" <%s> Rewind  <%s> Save  <%s> Pastebin "
                      " <%s> Pager  <%s> Show Source ") %
            (config.undo_key, config.save_key, config.pastebin_key,
             config.last_output_key, config.show_source_key), self.main_loop)
        self.frame.set_footer(self.statusbar.widget)
        self.interact = bpython.URWIDInteraction(self.config, self.statusbar,
                                                 self.frame)

        self.edits = []
        self.edit = None
        self.current_output = None
        self._completion_update_suppressed = False

        # Bulletproof: this is a value extract_exit_value accepts.
        self.exit_value = ()

        bpython.load_urwid_command_map(config)

        logging.root.handlers = [
            MyLogHandler(self),
            logging.StreamHandler(file('/tmp/upnpy_browser.log', 'w'))
        ]
        logging.root.setLevel(logging.INFO)
        logging.getLogger('http.access').setLevel(logging.ERROR)

        self.devices = urwid.ListBox(
            urwid.SimpleListWalker([urwid.Text('Devices:')]))
        self.logs = urwid.ListBox(urwid.SimpleListWalker([]))

        self.frame.set_footer(urwid.BoxAdapter(self.logs, 15))

        self.main_frame = urwid.Columns([
            self.frame,
            ('fixed', 35, self.devices),
        ])

        self.main_loop.widget = self.main_frame

        self.handler = MyDiscoverHandler(u, self)
        u.add_handler(self.handler)
Example #22
0
try: True # old python?
except: False, True = 0, 1

LN_TO_LG_SCALE = 1.4426950408889634 # LN_TO_LG_SCALE * ln(x) == lg(x)

try:
	import urwid
	try:
		from urwid.raw_display import Screen
	except:
		from urwid.curses_display import Screen
	urwid.BarGraph
	URWID_IMPORTED = True
	URWID_UTF8 = False
	try:
		if urwid.get_encoding_mode() == "utf8":
			from urwid.raw_display import Screen
			URWID_UTF8 = True
	except: 
		pass
except:
	URWID_IMPORTED = False
	URWID_UTF8 = False
	

class Speedometer:
	def __init__(self,maxlog=5):
		"""speedometer(maxlog=5)
		maxlog is the number of readings that will be stored"""
		self.log = []
		self.start = None
Example #23
0
    def controls(self):
        songs = list_songs()
        self.song_buttons = []
        group = []
        for song in songs:
            title = song_to_title(song)
            radio_button = make_radio_button(group,
                                             title if title else filename,
                                             self.on_song_button)
            self.song_buttons.append(radio_button)

        # setup animate button
        self.start_button = make_button("Start", self.on_start_button)

        self.started = False
        self.composer.stop()

        self.animate_progress = make_progress_bar()
        animate_controls = urwid.GridFlow(
            [self.start_button,
             make_button("Reset", self.on_reset_button)], 9, 2, 0, "center")

        self.animate_progress_wrap = urwid.WidgetWrap(self.animate_progress)

        if urwid.get_encoding_mode() == "utf8":
            unicode_checkbox = urwid.CheckBox(
                "Enable Unicode Graphics",
                on_state_change=self.on_unicode_checkbox)
        else:
            unicode_checkbox = urwid.Text("UTF-8 encoding not detected")

        # setup MIDI I/O radio buttons
        self.input_port_buttons = []
        group = []
        for port in get_input_names():
            radio_button = make_radio_button(group, port,
                                             self.on_input_port_button)
            self.input_port_buttons.append(radio_button)

        self.output_port_buttons = []
        group = []
        for port in get_output_names():
            radio_button = make_radio_button(group, port,
                                             self.on_output_port_button)
            self.output_port_buttons.append(radio_button)

        ipb = [urwid.Text("No MIDI Input Ports available", align="center")]
        if self.input_port_buttons:
            ipb = [urwid.Text("MIDI Input Port", align="center")
                   ] + self.input_port_buttons

        opb = [urwid.Text("No MIDI Output Ports available", align="center")]
        if self.output_port_buttons:
            opb = [urwid.Text("MIDI Output Port", align="center")
                   ] + self.output_port_buttons

        components = [urwid.Text("Song", align="center")] + \
            self.song_buttons + \
            ([urwid.Divider()] + ipb if ipb else []) + \
            ([urwid.Divider()] + opb if opb else []) + \
            [urwid.Divider(),
             urwid.Text("Generation", align="center"),
             animate_controls,
             self.animate_progress_wrap,
             urwid.Divider(),
             urwid.LineBox(unicode_checkbox),
             urwid.Divider(),
             make_button("Quit", self.exit_program)]
        return urwid.ListBox(urwid.SimpleListWalker(components))