Пример #1
0
    def __init__(self, return_fn, source_list):

        self.return_fn = return_fn

        # create the cancel and apply buttons, and put the in an urwid column
        cancel_button = urwid.Button('Cancel', on_press=self.on_cancel)
        cancel_button._label.align = 'center'
        apply_button = urwid.Button('Apply', on_press=self.on_apply)
        apply_button._label.align = 'center'

        if_buttons = urwid.Columns([apply_button, cancel_button])

        self.sensor_status_dict = {}
        sensor_column_list = []
        self.sensor_button_dict = {}
        self.sensor_current_active_dict = {}
        for source in source_list:
            # TODO use saved values for default windows that are open
            source_name = source.get_source_name()

            # get the saves sensor visibility list
            self.sensor_status_dict[source_name] =\
                [True] * len(source.get_sensor_list())
            self.sensor_button_dict[source_name] = []
            self.sensor_current_active_dict[source_name] = []

            # add the title at the head of the checkbox column
            sensor_title_str = "  " + source_name + " Sensors  \n"
            sensor_title = urwid.Text(('bold text', sensor_title_str),
                                      'center')

            # create the checkbox buttons with the saved visibility
            for sensor, s_tatus in \
                    zip(source.get_sensor_list(),
                        self.sensor_status_dict[source_name]):
                cb = urwid.CheckBox(sensor, s_tatus)
                self.sensor_button_dict[source_name].append(cb)
                self.sensor_current_active_dict[source_name].append(s_tatus)

            sensor_title_and_buttons = \
                [sensor_title] + self.sensor_button_dict[source_name]
            listw = urwid.SimpleFocusListWalker(sensor_title_and_buttons)

            sensor_column_list.append(urwid.Pile(listw))

        sensor_select_widget = urwid.Columns(sensor_column_list)

        list_temp = [sensor_select_widget, if_buttons]
        listw = urwid.SimpleFocusListWalker(list_temp)
        self.main_window = urwid.LineBox(ViListBox(listw))

        max_height = 6
        for sensor, s_tatus in self.sensor_current_active_dict.items():
            max_height = max(max_height, len(s_tatus) + 6)

        self.size = max_height, self.MAX_TITLE_LEN
Пример #2
0
    def __init__(self, return_fn):

        # What is shown in menu
        self.current_mode = None
        # Sensor Applied
        self.current_active_mode = None

        self.no_malloc = False

        title = urwid.Text(
            ('bold text', u"  Available Temperature Sensors  \n"), 'center')

        self.available_sensors = []
        sensors_dict = dict()
        try:
            sensors_dict = psutil.sensors_temperatures()
        except (AttributeError, IOError):
            logging.debug("Unable to create sensors dict")
        for key, value in sensors_dict.items():
            sensor_name = key
            for itr in range(len(value)):
                sensor_label = ""
                try:
                    sensor_label = value[itr].label
                    logging.debug("Sensor Label")
                    logging.debug(sensor_label)
                except (IndexError):
                    pass

                self.available_sensors.append(sensor_name +\
                                              "," +str(itr) +\
                                              "," + sensor_label)
        group = []
        self.sensor_buttons = []
        for sensor in self.available_sensors:
            rb = radio_button(group, sensor, self.on_mode_button)
            self.sensor_buttons.append(rb)

        #rb = radio_button(group, "INVALID", self.on_mode_button)
        #self.sensor_buttons.append(rb)

        self.return_fn = return_fn

        cancel_button = urwid.Button('Cancel', on_press=self.on_cancel)
        cancel_button._label.align = 'center'
        apply_button = urwid.Button('Apply', on_press=self.on_apply)
        apply_button._label.align = 'center'

        if_buttons = urwid.Columns([apply_button, cancel_button])

        self.titles = [title] + self.sensor_buttons + [if_buttons]

        self.main_window = urwid.LineBox(ViListBox(self.titles))
Пример #3
0
    def main_window(self):

        # initiating the graphs
        self.graphs = OrderedDict()
        self.summaries = OrderedDict()

        # TODO: Update to find sensors automatically


        freq_source = FreqSource(is_admin)
        self.graphs[freq_source.get_source_name()] = StuiBarGraph(freq_source, 'freq light', 'freq dark', 'freq light smooth', 'freq dark smooth')
        self.summaries[freq_source.get_source_name()] = SummaryTextList(freq_source)

        util_source = UtilSource()
        self.graphs[util_source.get_source_name()] = StuiBarGraph(util_source, 'util light', 'util dark', 'util light smooth', 'util dark smooth')
        self.summaries[util_source.get_source_name()] = SummaryTextList(util_source)

        temp_source = TemperatureSource(self.custom_temp)
        alert_colors = ['high temp light', 'high temp dark', 'high temp light smooth', 'high temp dark smooth']
        self.graphs[temp_source.get_source_name()] = StuiBarGraph(temp_source, 'temp light', 'temp dark', 'temp light smooth', 'temp dark smooth', alert_colors=alert_colors)
        self.summaries[temp_source.get_source_name()] = SummaryTextList(temp_source, 'high temp txt')

        rapl_power_source = RaplPowerSource()
        self.graphs[rapl_power_source.get_source_name()] = StuiBarGraph(rapl_power_source, 'power dark', 'power light', 'power dark smooth', 'power light smooth')
        self.summaries[rapl_power_source.get_source_name()] = SummaryTextList(rapl_power_source)

        # only interested in available graph
        self.available_graphs = OrderedDict((key, val) for key, val in self.graphs.items() if val.get_is_available())
        self.available_summaries = OrderedDict((key, val) for key, val in self.summaries.items() if val.get_is_available())

        self.visible_graphs = self.available_graphs.copy()
        self.show_graphs()

        cpu_stats = self.cpu_stats()
        graph_controls = self.graph_controls()
        graph_stats = self.graph_stats()

        text_col = ViListBox(urwid.SimpleListWalker(cpu_stats + graph_controls + [urwid.Divider()] + graph_stats))

        vline = urwid.AttrWrap(urwid.SolidFill(u'\u2502'), 'line')
        w = urwid.Columns([
                           ('fixed',  20, text_col),
                           ('fixed',  1, vline),
                           ('weight', 2, self.graph_place_holder),
                           ],
                          dividechars=1, focus_column=0)

        w = urwid.Padding(w, ('fixed left', 1), ('fixed right', 0))
        w = urwid.AttrWrap(w, 'body')
        w = urwid.LineBox(w)
        w = urwid.AttrWrap(w, 'line')
        self.main_window_w = w
        return self.main_window_w
Пример #4
0
    def __init__(self, return_fn):

        self.return_fn = return_fn

        self.about_message = ABOUT_MESSAGE

        self.time_out_ctrl = urwid.Text(self.about_message)

        cancel_button = urwid.Button('Exit', on_press=self.on_cancel)
        cancel_button._label.align = 'center'

        if_buttons = urwid.Columns([cancel_button])

        title = urwid.Text(('bold text', u"  About Menu  \n"), 'center')

        self.titles = [title, self.time_out_ctrl, if_buttons]

        self.main_window = urwid.LineBox(ViListBox(self.titles))
Пример #5
0
    def main_window(self):
        # initiating the graphs
        self.graphs = OrderedDict()
        self.summaries = OrderedDict()
        # construct frequency graph and source
        for source in self.source_list:
            source_name = source.get_source_name()
            color_pallet = source.get_pallet()
            alert_pallet = source.get_alert_pallet()
            self.graphs[source_name] = StuiBarGraphVector(
                source, color_pallet[0], color_pallet[1],
                color_pallet[2], color_pallet[3],
                len(source.get_sensor_list()),
                self.sensors_menu.sensor_current_active_dict[source_name],
                alert_colors=alert_pallet
            )

            self.summaries[source_name] = SummaryTextList(
                self.graphs[source_name].source
            )

        fan_source = FanSource()
        if fan_source.get_is_available():
            self.summaries[fan_source.get_source_name()] = SummaryTextList(
                fan_source)

        # only interested in available graph
        self.available_graphs = OrderedDict(
            (key, val) for key, val in self.graphs.items()
            if val.get_is_available())
        self.available_summaries = OrderedDict(
            (key, val) for key, val in self.summaries.items() if
            val.get_is_available())

        self.visible_graphs = self.available_graphs

        # Remove graphs from shown graphs if user configured them out
        # TODO: get this information from the state
        conf = self.controller.conf
        for graph_name in self.available_graphs.keys():
            try:
                if conf.getboolean('GraphControll', graph_name) is False:
                    del self.visible_graphs[graph_name]
            except (AttributeError, configparser.NoOptionError, ValueError,
                    configparser.NoSectionError):
                pass

        self.show_graphs()

        cpu_stats = self.cpu_stats()
        graph_controls = self.graph_controls(conf)
        graph_stats = self.graph_stats()

        text_col = ViListBox(urwid.SimpleListWalker(cpu_stats +
                                                    graph_controls +
                                                    [urwid.Divider()] +
                                                    [graph_stats]))

        vline = urwid.AttrWrap(urwid.SolidFill(u'\u2502'), 'line')
        w = urwid.Columns([
                          ('fixed',  20, text_col),
                          ('fixed',  1, vline),
                          ('weight', 2, self.graph_place_holder),
                          ],
                          dividechars=1, focus_column=0)

        w = urwid.Padding(w, ('fixed left', 1), ('fixed right', 0))
        w = urwid.AttrWrap(w, 'body')
        w = urwid.LineBox(w)
        w = urwid.AttrWrap(w, 'line')
        self.main_window_w = w

        return self.main_window_w
Пример #6
0
    def main_window(self):
        # initiating the graphs
        self.graphs = OrderedDict()
        self.summaries = OrderedDict()

        # TODO: Update to find sensors automatically
        '''
        freq_source = FreqSource(is_admin)

        self.graphs[freq_source.get_source_name()] = StuiBarGraph(
            freq_source, 'freq light', 'freq dark',
            'freq light smooth', 'freq dark smooth'
        )

        self.summaries[freq_source.get_source_name()] = SummaryTextList(
            freq_source
        )
        '''

        util_source = UtilSource()

        self.graphs[util_source.get_source_name()] = StuiBarGraph(
            util_source, 'util light', 'util dark', 'util light smooth',
            'util dark smooth')

        self.summaries[util_source.get_source_name()] = SummaryTextList(
            util_source)

        temp_source = TempSource(self.controller.custom_temp,
                                 self.controller.temp_thresh)

        if self.controller.script_hooks_enabled:
            temp_source.add_edge_hook(
                self.controller.script_loader.load_script(
                    temp_source.__class__.__name__, 30000)
            )  # Invoke threshold script every 30s while threshold is exceeded.

        alert_colors = [
            'high temp light', 'high temp dark', 'high temp light smooth',
            'high temp dark smooth'
        ]

        self.graphs[temp_source.get_source_name()] = StuiBarGraph(
            temp_source,
            'temp light',
            'temp dark',
            'temp light smooth',
            'temp dark smooth',
            alert_colors=alert_colors)

        self.summaries[temp_source.get_source_name()] = SummaryTextList(
            temp_source, 'high temp txt')

        mem_source = MemorySource()

        self.graphs[mem_source.get_source_name()] = StuiBarGraph(
            mem_source, 'power dark', 'power light', 'power dark smooth',
            'power light smooth')

        self.summaries[mem_source.get_source_name()] = SummaryTextList(
            mem_source)

        #fan_source = FanSource(self.controller.args.custom_fan)
        #self.summaries[fan_source.get_source_name()] = SummaryTextList(
        #    fan_source)

        # only interested in available graph
        self.available_graphs = OrderedDict(
            (key, val) for key, val in self.graphs.items()
            if val.get_is_available())
        self.available_summaries = OrderedDict(
            (key, val) for key, val in self.summaries.items()
            if val.get_is_available())

        self.visible_graphs = self.available_graphs.copy()

        # Remove graphs from shown graphs if user configed them out
        # TODO: get this information from the state
        conf = self.controller.conf
        for graph_name in self.available_graphs.keys():
            try:
                if conf.getboolean('GraphControll', graph_name) is False:
                    del self.visible_graphs[graph_name]
            except (AttributeError, configparser.NoOptionError, ValueError,
                    configparser.NoSectionError):
                pass

        self.show_graphs()

        cpu_stats = self.cpu_stats()
        graph_controls = self.graph_controls(conf)
        graph_stats = self.graph_stats()

        text_col = ViListBox(
            urwid.SimpleListWalker(cpu_stats + graph_controls +
                                   [urwid.Divider()] + graph_stats))

        vline = urwid.AttrWrap(urwid.SolidFill(u'\u2502'), 'line')
        w = urwid.Columns([
            ('fixed', 20, text_col),
            ('fixed', 1, vline),
            ('weight', 2, self.graph_place_holder),
        ],
                          dividechars=1,
                          focus_column=0)

        w = urwid.Padding(w, ('fixed left', 1), ('fixed right', 0))
        w = urwid.AttrWrap(w, 'body')
        w = urwid.LineBox(w)
        w = urwid.AttrWrap(w, 'line')
        self.main_window_w = w
        return self.main_window_w
Пример #7
0
    def main_window(self):

        user_config_path = None
        if not user_config_dir_exists():
            user_config_path = make_user_config_dir()
        else:
            user_config_path = get_user_config_path()

        script_hooks_enabled = True
        if user_config_path is None:
            logging.warn('Failed to find or create scripts directory, proceeding without scripting support')
            script_hooks_enabled = False
        else:
            self.script_loader = ScriptHookLoader(user_config_path)

        # initiating the graphs
        self.graphs = OrderedDict()
        self.summaries = OrderedDict()

        # TODO: Update to find sensors automatically


        freq_source = FreqSource(is_admin)
        self.graphs[freq_source.get_source_name()] = StuiBarGraph(freq_source, 'freq light', 'freq dark', 'freq light smooth', 'freq dark smooth')
        self.summaries[freq_source.get_source_name()] = SummaryTextList(freq_source)

        util_source = UtilSource()
        self.graphs[util_source.get_source_name()] = StuiBarGraph(util_source, 'util light', 'util dark', 'util light smooth', 'util dark smooth')
        self.summaries[util_source.get_source_name()] = SummaryTextList(util_source)

        temp_source = TemperatureSource(self.custom_temp)

        if script_hooks_enabled:
            temp_source.add_edge_hook(self.script_loader.load_script(temp_source.__class__.__name__, 30000)) # Invoke threshold script every 30s while threshold is exceeded.

        alert_colors = ['high temp light', 'high temp dark', 'high temp light smooth', 'high temp dark smooth']
        self.graphs[temp_source.get_source_name()] = StuiBarGraph(temp_source, 'temp light', 'temp dark', 'temp light smooth', 'temp dark smooth', alert_colors=alert_colors)
        self.summaries[temp_source.get_source_name()] = SummaryTextList(temp_source, 'high temp txt')

        rapl_power_source = RaplPowerSource()
        self.graphs[rapl_power_source.get_source_name()] = StuiBarGraph(rapl_power_source, 'power dark', 'power light', 'power dark smooth', 'power light smooth')
        self.summaries[rapl_power_source.get_source_name()] = SummaryTextList(rapl_power_source)

        fan_source = FanSource(self.custom_fan)
        self.summaries[fan_source.get_source_name()] = SummaryTextList(fan_source)

        # only interested in available graph
        self.available_graphs = OrderedDict((key, val) for key, val in self.graphs.items() if val.get_is_available())
        self.available_summaries = OrderedDict((key, val) for key, val in self.summaries.items() if val.get_is_available())

        self.visible_graphs = self.available_graphs.copy()
        self.show_graphs()

        cpu_stats = self.cpu_stats()
        graph_controls = self.graph_controls()
        graph_stats = self.graph_stats()

        text_col = ViListBox(urwid.SimpleListWalker(cpu_stats + graph_controls + [urwid.Divider()] + graph_stats))

        vline = urwid.AttrWrap(urwid.SolidFill(u'\u2502'), 'line')
        w = urwid.Columns([
                           ('fixed',  20, text_col),
                           ('fixed',  1, vline),
                           ('weight', 2, self.graph_place_holder),
                           ],
                          dividechars=1, focus_column=0)

        w = urwid.Padding(w, ('fixed left', 1), ('fixed right', 0))
        w = urwid.AttrWrap(w, 'body')
        w = urwid.LineBox(w)
        w = urwid.AttrWrap(w, 'line')
        self.main_window_w = w
        return self.main_window_w