Beispiel #1
0
    def refresh(self):
        """
        Refreshes the list of drives
        """

        counter_index = 0

        self.panel.children = [
            self.get_header_label('Drives ({})'.format(
                len(self.application.data_provider.partitions)))
        ]

        is_first_control = True

        drives = list()

        for p in self.application.data_provider.partitions:

            drive = DiskDrive(p)
            drives.append(drive)

            if drive.can_get_usage() and counter_index < len(
                    self.application.data_provider.disk_counters):
                key = "PhysicalDrive" + str(counter_index)
                if key in self.application.data_provider.disk_counters:
                    drive.load_counters(
                        key, self.application.data_provider.disk_counters[key])
                else:
                    key = self.application.data_provider.disk_counters.keys(
                    )[counter_index]
                    drive.load_counters(
                        key, self.application.data_provider.disk_counters[key])
                counter_index += 1

            text = drive.get_display_text()

            lbl = self.get_list_label(text)
            chart = BarChart(self.display,
                             self,
                             float(drive.usage_percent),
                             width=lbl.font.size * 2,
                             height=lbl.font.size)
            sp = StackPanel(self.display, self, is_horizontal=True)
            sp.children = [chart, lbl]

            mi = MenuItem(self.controller.display, self, sp)
            mi.data_context = drive

            self.panel.children.append(mi)

            if is_first_control and not self.selected_device:
                self.set_focus(mi, play_sound=False)
                is_first_control = False
            elif self.selected_device and self.selected_device == drive.device:
                self.set_focus(mi, play_sound=False)

        self.last_refresh = datetime.now()
Beispiel #2
0
    def __init__(self, display, page, label):
        super(CheckBox, self).__init__(display, page)

        self.text = label
        self.label = TextBlock(display, page, label)
        self.glyph = CheckBoxGlyph(display, page)

        self.panel = StackPanel(display, page, is_horizontal=True)
        self.panel.center_align = True
        self.panel.children = [self.label, self.glyph]
Beispiel #3
0
class BarChartDashboardWidget(DashboardWidget):
    def __init__(self, display, page, title, value=0, range_low=0, range_high=100, status=DashboardStatus.Passive):
        super(BarChartDashboardWidget, self).__init__(display, page, status)

        self.width = 150

        self.title = title
        self.value = value

        self.panel = StackPanel(display, page)

        self.lbl_title = TextBlock(display, page, title, is_highlighted=True)
        self.lbl_title.font = display.fonts.list
        self.panel.children.append(self.lbl_title)

        self.chart = BarChart(display, page, value=value, range_low=range_low, range_high=range_high)
        self.chart.width = self.width
        self.chart.height = 15
        self.panel.children.append(self.chart)

    def arrange(self):

        self.lbl_title.text = self.title
        self.chart.value = self.value
        self.panel.arrange()
        self.desired_size = 150 + (self.padding * 2), self.panel.desired_size[1] + (self.padding * 2)

        return self.desired_size

    def render(self):

        # Colorize as needed
        color = self.get_color()
        self.chart.color = color
        self.lbl_title.color = self.get_title_color()

        # Render an outline around the entire control
        rect = Rect(self.pos[0], self.pos[1], self.desired_size[0], self.desired_size[1])

        # Some statuses need custom backgrounds
        if self.status == DashboardStatus.Caution:
            render_rectangle(self.display, self.display.color_scheme.caution_bg, rect, width=0)
        elif self.status == DashboardStatus.Critical:
            render_rectangle(self.display, self.display.color_scheme.critical_bg, rect, width=0)

        # Render the outline
        render_rectangle(self.display, color, rect)

        # Render the base content with some padding
        pos = self.pos[0] + self.padding, self.pos[1] + self.padding
        self.panel.render_at(pos)

        # Assume the width of the outer outline
        return self.set_dimensions_from_rect(rect)
Beispiel #4
0
    def __init__(self, controller, application):
        super(MapInfoPage, self).__init__(controller, application)

        self.map_context = application.data_provider.map_context
        self.lbl_header = self.get_header_label('{}')
        self.lbl_pos = self.get_label("GPS: {}, {}")
        self.pnl_tags = StackPanel(controller.display, self)
        self.pnl_image = StackPanel(controller.display, self)
        self.pnl_horizontal = StackPanel(controller.display,
                                         self,
                                         is_horizontal=True)
        self.pnl_horizontal.children = [self.pnl_image, self.pnl_tags]
        self.panel.children = [
            self.lbl_header, self.lbl_pos, self.pnl_horizontal
        ]
Beispiel #5
0
    def __init__(self, display, page, label=None, text=None, text_width=100):
        super(TextBox, self).__init__(display, page)

        if text:
            text = str(text)
            
        self.text = text
        self.label_text = label
        self.label = TextBlock(display, page, label)
        self.glyph = TextGlyph(display, page)
        self.text_width = text_width

        self.panel = StackPanel(display, page, is_horizontal=True)
        self.panel.center_align = True
        self.panel.children = [self.label, self.glyph]
Beispiel #6
0
    def __init__(self, display, page, label, value, items=None):

        """
        :type items: list
        """
        if not items:
            items = []

        super(SpinnerBox, self).__init__(display, page)
        self.label = label
        self.value = value
        self.label_block = TextBlock(display, page, label)
        self.value_block = TextBlock(display, page, value)
        self.panel = StackPanel(display, page, is_horizontal=True)
        self.panel.children = [self.label_block, self.value_block]
        self.items = items
Beispiel #7
0
    def __init__(self, display, page, title, value, status=DashboardStatus.Passive):
        super(TextDashboardWidget, self).__init__(display, page, status)

        self.title = title
        self.value = value
        self.width = 150
        self.value_font = display.fonts.list

        self.panel = StackPanel(display, page)

        self.lbl_title = TextBlock(display, page, title, is_highlighted=True)
        self.lbl_title.font = display.fonts.list
        self.panel.children.append(self.lbl_title)

        self.lbl_value = TextBlock(display, page, value)
        self.lbl_value.font = display.fonts.list
        self.panel.children.append(self.lbl_value)
Beispiel #8
0
    def __init__(self, controller, application, auto_scroll=True):
        super(PerformancePage, self).__init__(controller, application,
                                              auto_scroll)

        self.pnl_cpu = StackPanel(controller.display, self)
        self.pnl_virt_mem = StackPanel(controller.display, self)
        self.pnl_swap_mem = StackPanel(controller.display, self)

        self.panel.is_horizontal = True
        self.panel.auto_orient = True
        self.panel.children = [
            self.pnl_cpu, self.pnl_virt_mem, self.pnl_swap_mem
        ]

        self.refresh()

        self.last_refresh = datetime.now()
Beispiel #9
0
    def __init__(self, controller, application, auto_scroll=True):
        super(DataCategoriesPage, self).__init__(controller, application, auto_scroll)

        self.lbl_header = self.get_header_label("Data Categories")

        self.pnl_items = StackPanel(self.display, self)

        self.panel.children = [self.lbl_header, self.pnl_items]
Beispiel #10
0
    def __init__(self, display, page, title, value=0, range_low=0, range_high=100, status=DashboardStatus.Passive):
        super(BarChartDashboardWidget, self).__init__(display, page, status)

        self.width = 150

        self.title = title
        self.value = value

        self.panel = StackPanel(display, page)

        self.lbl_title = TextBlock(display, page, title, is_highlighted=True)
        self.lbl_title.font = display.fonts.list
        self.panel.children.append(self.lbl_title)

        self.chart = BarChart(display, page, value=value, range_low=range_low, range_high=range_high)
        self.chart.width = self.width
        self.chart.height = 15
        self.panel.children.append(self.chart)
Beispiel #11
0
    def __init__(self, controller, application):
        super(WMIServicesPage, self).__init__(controller, application)

        self.services = list()

        self.lbl_header = self.get_header_label('Services')
        self.pnl_services = StackPanel(controller.display, self)
        self.panel.children = [self.lbl_header, self.pnl_services]

        self.refresh_services()
Beispiel #12
0
    def __init__(self, controller, application, data_page_provider, auto_scroll=True):
        super(DataPage, self).__init__(controller, application, auto_scroll)

        self.data_page_provider = data_page_provider
        self.lbl_header = self.get_header_label(data_page_provider.name)
        self.pnl_data = StackPanel(controller.display, self)

        self.refresh_children()

        self.panel.children = [self.lbl_header, self.pnl_data]
Beispiel #13
0
    def __init__(self,
                 display,
                 page,
                 title="CPU",
                 values=None,
                 status=DashboardStatus.Passive):
        super(CpuDashboardWidget, self).__init__(display, page, status)

        self.title = title
        self.values = values

        self.panel = StackPanel(display, page)

        self.lbl_title = TextBlock(display, page, title, is_highlighted=True)
        self.lbl_title.font = display.fonts.list
        self.panel.children.append(self.lbl_title)

        self.pnl_charts = StackPanel(display, page, is_horizontal=True)
        self.pnl_charts.padding = 2, 0
        self.panel.children.append(self.pnl_charts)
Beispiel #14
0
    def __init__(self, controller, application, drive, auto_scroll=True):
        super(DiskDetailsPage, self).__init__(controller, application,
                                              auto_scroll)

        self.drive = drive

        self.segment_panel = StackPanel(self.display,
                                        self,
                                        is_horizontal=True,
                                        auto_orient=True,
                                        keep_together=True)
        self.panel.children = [
            self.get_header_label("Drive Information"), self.segment_panel
        ]

        # Display basic attributes for the drive
        general_panel = StackPanel(self.display, self)
        general_panel.children.append(self.get_label("General"))
        for info_item in self.drive.get_general_info():
            lbl = self.get_label(info_item)
            lbl.font = self.controller.display.fonts.list
            general_panel.children.append(lbl)
        self.segment_panel.children.append(general_panel)

        if drive.can_get_usage():
            usage_panel = StackPanel(self.display, self)
            usage_panel.children.append(self.get_label("Storage"))
            for info_item in self.drive.get_storage_info():
                lbl = self.get_list_label(info_item)
                if info_item.endswith('% Full'):
                    chart = BarChart(self.display,
                                     self,
                                     value=float(self.drive.usage_percent))
                    chart.height = lbl.font.size
                    chart.width = lbl.font.size
                    pnl = StackPanel(self.display, self, is_horizontal=True)
                    pnl.children = [chart, lbl]
                    usage_panel.children.append(pnl)
                else:
                    usage_panel.children.append(lbl)

            self.segment_panel.children.append(usage_panel)

        if self.drive.counters:
            self.perf_panel = StackPanel(self.display, self)
            self.refresh_performance_counters()
            self.segment_panel.children.append(self.perf_panel)
            self.last_refresh = datetime.now()
Beispiel #15
0
    def __init__(self,
                 display,
                 page,
                 title,
                 weather=None,
                 forecast=None,
                 is_forecast=True):
        super(WeatherForecastDashboardWidget,
              self).__init__(display, page, DashboardStatus.Inactive)

        self.title = title
        self.forecast = forecast
        self.weather = weather
        self.is_forecast = is_forecast
        self.minutes_to_clean_frost = None

        self.panel = StackPanel(display, page)

        self.lbl_title = TextBlock(display, page, title, is_highlighted=True)
        self.lbl_title.font = display.fonts.list
        self.panel.children.append(self.lbl_title)

        pnl_value = StackPanel(display, page, is_horizontal=True)
        pnl_value.center_align = True

        self.lbl_condition = TextBlock(display, page, "{}")
        self.lbl_condition.font = display.fonts.weather

        self.lbl_value = TextBlock(display, page, "Offline")
        self.lbl_value.font = display.fonts.list

        pnl_value.children = [self.lbl_value, self.lbl_condition]

        self.panel.children.append(pnl_value)

        self.chart = BoxChart(display, page)
        self.chart.width = 150
        self.chart.range_low = -20
        self.chart.range_high = 120
        self.chart.is_highlighted = False
        self.chart.box_width = 0
        self.chart.ticks = (0, 32, 100)
        self.panel.children.append(self.chart)

        self.lbl_frost = TextBlock(display, page, None)
        self.lbl_frost.font = display.fonts.list
        self.panel.children.append(self.lbl_frost)
Beispiel #16
0
class CheckBox(FocusableWidget):
    """
    A CheckBox with an associated label.
    """

    text = None
    panel = None
    label = None
    glyph = None
    checked = False

    def __init__(self, display, page, label):
        super(CheckBox, self).__init__(display, page)

        self.text = label
        self.label = TextBlock(display, page, label)
        self.glyph = CheckBoxGlyph(display, page)

        self.panel = StackPanel(display, page, is_horizontal=True)
        self.panel.center_align = True
        self.panel.children = [self.label, self.glyph]

    def arrange(self):

        self.desired_size = self.panel.arrange()

        return super(CheckBox, self).arrange()

    def render(self):
        """
        Renders the checkbox with its current state
        :return: The rectangle of the checkbox
        """

        # Pass along our values to the children
        self.label.text = self.text
        self.glyph.checked = self.checked

        # Render the panel's contents
        self.panel.set_dimensions_from(self)
        self.panel.render()

        return self.set_dimensions_from(self.panel)

    def got_focus(self):
        """
        Occurs when the control gets focus
        """
        self.label.is_highlighted = True
        self.glyph.render_focus = True
        super(CheckBox, self).got_focus()

    def lost_focus(self):
        """
        Occurs when the control loses focus
        """
        self.label.is_highlighted = False
        self.glyph.render_focus = False
        super(CheckBox, self).lost_focus()

    def handle_key(self, key):
        """
        Handles a keypress
        :param key: The keycode
        :returns: True if the event was handled; otherwise False
        """

        if is_enter_key(key) or key == Keycodes.KEY_SPACE:

            if self.checked:
                self.checked = False
            else:
                self.checked = True

            self.state_changed()

            return True

        else:
            return super(CheckBox, self).handle_key(key)
Beispiel #17
0
class SpinnerBox(FocusableWidget):
    """
    Represents a segment of text
    """

    label_block = None
    label = None
    value_block = None
    value = None
    panel = None
    items = []

    def __init__(self, display, page, label, value, items=None):

        """
        :type items: list
        """
        if not items:
            items = []

        super(SpinnerBox, self).__init__(display, page)
        self.label = label
        self.value = value
        self.label_block = TextBlock(display, page, label)
        self.value_block = TextBlock(display, page, value)
        self.panel = StackPanel(display, page, is_horizontal=True)
        self.panel.children = [self.label_block, self.value_block]
        self.items = items

    def arrange(self):

        self.label_block.text = self.label
        self.value_block.text = self.value
        self.label_block.is_highlighted = self.is_focused()
        self.value_block.is_highlighted = self.is_focused()

        self.desired_size = self.panel.arrange()

        return super(SpinnerBox, self).arrange()

    def render(self):
        """
        Renders the textblock to the default surface using the current properties of this object
        :rtype : RectType
        """

        return self.set_dimensions_from_rect(self.panel.render_at(self.pos))

    def handle_key(self, key):

        if is_plus_key(key) or is_right_key(key) or is_enter_key(key):
            self.move_next()
            return True

        if is_minus_key(key) or is_left_key(key):
            self.move_previous()
            return True

        return super(SpinnerBox, self).handle_key(key)

    def get_selected_index(self):

        if not self.items or self.value not in self.items:
            return -1

        return self.items.index(self.value)

    def move_next(self):

        if not self.items or len(self.items) <= 0:
            return

        current_index = self.get_selected_index()

        if current_index < 0:
            current_index = 0
        elif current_index >= len(self.items) - 1:
            current_index = 0
        else:
            current_index += 1

        new_value = self.items[current_index]
        if self.value != new_value:
            self.value = new_value
            self.state_changed()

    def move_previous(self):

        if not self.items or len(self.items) <= 0:
            return

        current_index = self.get_selected_index()

        if current_index < 0:
            current_index = len(self.items) - 1
        elif current_index >= len(self.items):
            current_index = 0
        else:
            current_index -= 1

        new_value = self.items[current_index]
        if self.value != new_value:
            self.value = new_value
            self.state_changed()
Beispiel #18
0
class TextBox(FocusableWidget):
    """
    Represents a text entry control with associated label.
    """

    label_text = None
    text = ''
    text_width = 100
    max_length = None
    allow_alpha = True
    allow_numeric = True
    allow_space = True
    allow_negative = True
    allow_decimal = True

    def __init__(self, display, page, label=None, text=None, text_width=100):
        super(TextBox, self).__init__(display, page)

        if text:
            text = str(text)
            
        self.text = text
        self.label_text = label
        self.label = TextBlock(display, page, label)
        self.glyph = TextGlyph(display, page)
        self.text_width = text_width

        self.panel = StackPanel(display, page, is_horizontal=True)
        self.panel.center_align = True
        self.panel.children = [self.label, self.glyph]

    def arrange(self):

        # Pass along our values to the children
        self.label.text = self.label_text
        self.glyph.text_width = self.text_width
        self.glyph.text = self.text

        self.desired_size = self.panel.arrange()

        return super(TextBox, self).arrange()

    def render(self):
        """
        Renders the TextBox with its current state
        :return: The rectangle of the TextBox
        """

        # Render the panel's contents
        self.panel.set_dimensions_from(self)
        self.panel.render()

        return self.set_dimensions_from(self.panel)

    def set_alphanumeric(self):
        self.allow_alpha = True
        self.allow_negative = True
        self.allow_numeric = True
        self.allow_decimal = True
        self.allow_space = True

    def set_numeric(self, allow_negative=True, allow_decimal=True):
        self.allow_alpha = False
        self.allow_negative = allow_negative
        self.allow_decimal = allow_decimal
        self.allow_numeric = True
        self.allow_space = False

    def got_focus(self):
        """
        Occurs when the control gets focus
        """
        self.label.is_highlighted = True
        self.glyph.render_focus = True
        super(TextBox, self).got_focus()

    def lost_focus(self):
        """
        Occurs when the control loses focus
        """
        self.label.is_highlighted = False
        self.glyph.render_focus = False
        super(TextBox, self).lost_focus()

    def can_input_more(self):
        """
        Returns whether or not there is room to enter more characters (according to max_length)
        :return: whether or not there is room to enter more characters (according to max_length)
        """
        return self.max_length is None or len(self.text) < self.max_length

    def handle_key(self, key):
        """
        Handles a keypress
        :param key: The keycode
        :returns: True if the event was handled; otherwise False
        """

        # ensure we have text in the textbox
        if not self.text:
            self.text = ''

        if key == Keycodes.KEY_BACKSPACE:
            if self.text and len(self.text) > 0:
                self.text = self.text[:-1]  # TODO: This is simplistic and needs to work with a cursor index
                return True

        if key == Keycodes.KEY_DELETE:
            if self.text and len(self.text) > 0:
                self.text = self.text[1:]  # TODO: This is simplistic and needs to work with a cursor index
                return True

        if self.allow_numeric and Keycodes.KEY_0 <= key <= Keycodes.KEY_9 and self.can_input_more():
            char = key - Keycodes.KEY_0
            self.text += str(char)  # TODO: This will need to take cursor location into account
            self.state_changed()
            return True

        if self.allow_alpha and Keycodes.KEY_a <= key <= Keycodes.KEY_z and self.can_input_more():
            char = chr(key)
            self.text += str(char).upper()  # TODO: This will need to take cursor location into account
            self.state_changed()
            return True

        if self.allow_negative and key in [Keycodes.KEY_KP_MINUS, Keycodes.KEY_MINUS]:
            self.text += '-'
            self.state_changed()
            return True

        if self.allow_decimal and key in [Keycodes.KEY_KP_PERIOD, Keycodes.KEY_PERIOD]:
            self.text += '.'
            self.state_changed()
            return True

        if self.allow_space and key == Keycodes.KEY_SPACE and self.can_input_more():
            self.text += ' '
            self.state_changed()
            return True

        return super(TextBox, self).handle_key(key)

    def has_text(self):

        return self.text and len(self.text) > 0
Beispiel #19
0
 def get_panel(self):
     """
     :type display: PiMFD.UI.DisplayManager.DisplayManager
     """
     return StackPanel(self.display, self)
Beispiel #20
0
class CpuDashboardWidget(DashboardWidget):
    charts = None

    def __init__(self,
                 display,
                 page,
                 title="CPU",
                 values=None,
                 status=DashboardStatus.Passive):
        super(CpuDashboardWidget, self).__init__(display, page, status)

        self.title = title
        self.values = values

        self.panel = StackPanel(display, page)

        self.lbl_title = TextBlock(display, page, title, is_highlighted=True)
        self.lbl_title.font = display.fonts.list
        self.panel.children.append(self.lbl_title)

        self.pnl_charts = StackPanel(display, page, is_horizontal=True)
        self.pnl_charts.padding = 2, 0
        self.panel.children.append(self.pnl_charts)

    def get_percent_status(self, percentage):

        if percentage > 95:
            return DashboardStatus.Critical
        elif percentage > 80:
            return DashboardStatus.Caution
        elif percentage < 0:
            return DashboardStatus.Inactive
        else:
            return DashboardStatus.Passive

    def arrange(self):

        max_value = -1

        if not self.charts and self.values and len(self.values) > 0:
            self.charts = []

            chart_width = (150 - (len(self.values) * 1)) / len(self.values)

            for value in self.values:
                chart = BarChart(self.display, self.page, value=value)
                chart.width = chart_width
                chart.height = 15
                chart.color = self.get_status_color(
                    self.get_percent_status(value))
                self.charts.append(chart)
                self.pnl_charts.children.append(chart)
                max_value = max(value, max_value)

        elif self.charts and self.values and len(self.values) > 0:

            for chart, value in zip(self.charts, self.values):
                chart.value = value
                chart.color = self.get_status_color(
                    self.get_percent_status(value))
                max_value = max(value, max_value)

        self.status = self.get_percent_status(max_value)

        self.lbl_title.text = self.title

        self.panel.arrange()
        self.desired_size = 150 + (
            self.padding * 2), self.panel.desired_size[1] + (self.padding * 2)
        return self.desired_size

    def render(self):

        # Colorize as needed
        color = self.get_color()
        self.lbl_title.color = self.get_title_color()

        # Render an outline around the entire control
        rect = Rect(self.pos[0], self.pos[1], self.desired_size[0],
                    self.desired_size[1])

        # Some statuses need custom backgrounds
        if self.status == DashboardStatus.Caution:
            render_rectangle(self.display,
                             self.display.color_scheme.caution_bg,
                             rect,
                             width=0)
        elif self.status == DashboardStatus.Critical:
            render_rectangle(self.display,
                             self.display.color_scheme.critical_bg,
                             rect,
                             width=0)

        # Render the outline
        render_rectangle(self.display, color, rect)

        # Render the base content with some padding
        pos = self.pos[0] + self.padding, self.pos[1] + self.padding
        self.panel.render_at(pos)

        # Assume the width of the outer outline
        return self.set_dimensions_from_rect(rect)
Beispiel #21
0
    def refresh_performance_counters(self):

        self.panel.children = [
            self.get_header_label("{} (PID: {})".format(
                self.name, self.process.pid))
        ]

        # Render CPU
        pct = self.process.cpu_percent()
        if not pct:
            pct = 0.0

        lbl_cpu = self.get_list_label("CPU:")
        lbl_cpu_pct = self.get_list_label("{} %".format(pct))
        chrt_cpu = BarChart(self.display,
                            self,
                            pct,
                            width=25,
                            height=lbl_cpu.font.size)
        pnl_cpu = StackPanel(self.display, self, is_horizontal=True)
        pnl_cpu.children = [lbl_cpu, chrt_cpu, lbl_cpu_pct]

        self.panel.children.append(pnl_cpu)

        # Render Memory
        mem = self.process.memory_info()
        if mem:
            pnl_mem = StackPanel(self.display, self)
            pnl_mem.children.append(self.get_label("Memory"))
            pnl_mem.children.append(
                self.get_list_label("Memory Usage: {}".format(
                    format_size(mem.rss))))
            pnl_mem.children.append(
                self.get_list_label("Virtual Memory Size: {}".format(
                    format_size(mem.vms))))
            self.panel.children.append(pnl_mem)

        # Render Connections
        try:
            connections = self.process.connections()
            if connections:
                pnl_connections = StackPanel(self.display, self)
                pnl_connections.children.append(
                    self.get_label("Connections ({})".format(
                        len(connections))))
                self.panel.children.append(pnl_connections)

                for c in connections:
                    if c.laddr == c.raddr:
                        address_text = NetworkPage.get_address_text(c.raddr)
                    else:
                        address_text = "{}({})".format(
                            NetworkPage.get_address_text(c.raddr),
                            NetworkPage.get_address_text(c.laddr))

                    text = "{} {} {}/{}".format(
                        c.status, address_text,
                        NetworkPage.get_connection_type_text(c.type),
                        NetworkPage.get_connection_family_text(c.family))

                    lbl = self.get_list_label(text)
                    pnl_connections.children.append(lbl)

        except psutil.NoSuchProcess or psutil.AccessDenied:
            pass

        # Render Files
        try:
            files = self.process.open_files()
        except psutil.AccessDenied:
            files = None

        if files:
            pnl_files = StackPanel(self.display, self)
            pnl_files.children.append(
                self.get_label("Files ({})".format(len(files))))

            for f in files:
                lbl = self.get_list_label(f.path)
                lbl.data_context = f
                pnl_files.children.append(lbl)

            self.panel.children.append(pnl_files)

        # Render Children
        try:
            children = self.process.children()
        except psutil.NoSuchProcess or psutil.AccessDenied:
            children = None

        if children:
            pnl_children = StackPanel(self.display, self)
            pnl_children.children.append(
                self.get_label("Children ({})".format(len(children))))

            for c in children:
                name = self.get_process_name(c)
                lbl = self.get_list_label("{}: {}".format(c.pid, name))
                lbl.data_context = c
                pnl_children.children.append(lbl)

            self.panel.children.append(pnl_children)

        # Render threads
        try:
            threads = self.process.threads()
        except psutil.AccessDenied or psutil.NoSuchProcess:
            threads = None

        if threads:
            pnl_threads = StackPanel(self.display, self)
            pnl_threads.children = [
                self.get_label("Threads ({})".format(len(threads)))
            ]

            for t in threads:
                lbl = self.get_list_label("{}: User: {}, SYS: {}".format(
                    t.id, t.user_time, t.system_time))
                pnl_threads.children.append(lbl)

            self.panel.children.append(pnl_threads)
Beispiel #22
0
class WeatherForecastDashboardWidget(DashboardWidget):
    """
    A dashboard widget containing weather condition information
    :type display: PiMFD.UI.DisplayManager.DisplayManager
    :type page: PiMFD.Applications.Core.DashboardPages.DashboardPage
    :type title: str The name of the widget
    :type value: str The value used in the widget
    """
    def __init__(self,
                 display,
                 page,
                 title,
                 weather=None,
                 forecast=None,
                 is_forecast=True):
        super(WeatherForecastDashboardWidget,
              self).__init__(display, page, DashboardStatus.Inactive)

        self.title = title
        self.forecast = forecast
        self.weather = weather
        self.is_forecast = is_forecast
        self.minutes_to_clean_frost = None

        self.panel = StackPanel(display, page)

        self.lbl_title = TextBlock(display, page, title, is_highlighted=True)
        self.lbl_title.font = display.fonts.list
        self.panel.children.append(self.lbl_title)

        pnl_value = StackPanel(display, page, is_horizontal=True)
        pnl_value.center_align = True

        self.lbl_condition = TextBlock(display, page, "{}")
        self.lbl_condition.font = display.fonts.weather

        self.lbl_value = TextBlock(display, page, "Offline")
        self.lbl_value.font = display.fonts.list

        pnl_value.children = [self.lbl_value, self.lbl_condition]

        self.panel.children.append(pnl_value)

        self.chart = BoxChart(display, page)
        self.chart.width = 150
        self.chart.range_low = -20
        self.chart.range_high = 120
        self.chart.is_highlighted = False
        self.chart.box_width = 0
        self.chart.ticks = (0, 32, 100)
        self.panel.children.append(self.chart)

        self.lbl_frost = TextBlock(display, page, None)
        self.lbl_frost.font = display.fonts.list
        self.panel.children.append(self.lbl_frost)

    def render(self):

        # Colorize as needed
        color = self.get_color()
        self.lbl_value.color = color
        self.lbl_title.color = self.get_title_color()
        self.lbl_condition.color = color
        self.chart.color = color

        # Render an outline around the entire control
        rect = Rect(self.pos[0], self.pos[1],
                    self.panel.desired_size[0] + (self.padding * 2),
                    self.panel.desired_size[1] + (self.padding * 2))

        # Some statuses need custom backgrounds
        if self.status == DashboardStatus.Caution:
            render_rectangle(self.display,
                             self.display.color_scheme.caution_bg,
                             rect,
                             width=0)
        elif self.status == DashboardStatus.Critical:
            render_rectangle(self.display,
                             self.display.color_scheme.critical_bg,
                             rect,
                             width=0)

        # Render the outline
        render_rectangle(self.display, color, rect)

        # Render the base content with some padding
        pos = self.pos[0] + self.padding, self.pos[1] + self.padding
        self.panel.render_at(pos)

        # Assume the width of the outer outline
        return self.set_dimensions_from_rect(rect)

    def arrange(self):

        self.status = self.get_status()
        self.lbl_title.text = self.title
        if self.forecast and self.weather:
            if not self.is_forecast:
                self.lbl_condition.text_data = get_condition_icon(
                    self.weather.code)
                self.lbl_value.text = u'{}{}'.format(self.weather.temperature,
                                                     self.weather.temp_units)
            else:
                self.lbl_condition.text_data = get_condition_icon(
                    self.forecast.code)
                self.lbl_value.text = u'{}'.format(self.forecast.temp_range)
        else:
            self.lbl_condition.text_data = None
            self.lbl_value.text = 'Offline'

        if self.minutes_to_clean_frost and self.minutes_to_clean_frost > 0.1:
            self.lbl_frost.visible = True
            self.lbl_frost.text = '{} Minutes Frost'.format(
                round(self.minutes_to_clean_frost, 1))
        else:
            self.lbl_frost.visible = False
            self.lbl_frost.text = None

        if self.forecast:

            if not self.is_forecast:
                temp = float(self.weather.temperature)
                if temp >= 0:
                    self.chart.value_low = 0
                    self.chart.value_high = temp
                else:
                    self.chart.value_low = temp
                    self.chart.value_high = 0

            else:
                self.chart.value_low = self.forecast.low
                self.chart.value_high = self.forecast.high

        self.panel.arrange()
        self.desired_size = self.panel.desired_size[0] + (
            self.padding * 2), self.panel.desired_size[1] + (self.padding * 2)
        return self.desired_size

    def get_status(self):

        if not self.weather or not self.forecast:
            return DashboardStatus.Inactive

        temp_status = self.get_temperature_status()
        cond_status = get_condition_status(self.forecast.code)

        if cond_status == DashboardStatus.Critical or temp_status == DashboardStatus.Critical:
            return DashboardStatus.Critical

        if cond_status == DashboardStatus.Caution or temp_status == DashboardStatus.Caution:
            return DashboardStatus.Caution

        return temp_status

    def get_temperature_status(self):

        if not self.weather or not self.forecast:
            return DashboardStatus.Inactive

        # Certain Temperatures should function as alerts
        low = self.forecast.low
        high = self.forecast.high

        # If it's today, we don't care about forecast - go off of current temperature
        if not self.is_forecast:
            low = high = float(self.weather.temperature)

        if low <= 10 or high >= 100:
            return DashboardStatus.Critical
        elif low <= 32 or high >= 90:
            return DashboardStatus.Caution
        else:
            return DashboardStatus.Passive
Beispiel #23
0
    def __init__(self, controller, application, weather_provider):
        super(WeatherPage, self).__init__(controller, application)

        self.weather_provider = weather_provider

        # Build out the Today Panel
        self.pnl_today = StackPanel(controller.display, self)
        self.lbl_today_header = self.get_header_label("{} Weather")
        self.lbl_temp = self.get_label(u"      Temp: {}{} (Chill: {}{})")
        self.lbl_cond = self.get_label(u"Conditions: {}")
        self.lbl_cond_icon = self.get_label(u"{}")
        self.lbl_cond_icon.font = controller.display.fonts.weather
        pnl_cond = StackPanel(controller.display, self, is_horizontal=True)
        pnl_cond.children = (self.lbl_cond, self.lbl_cond_icon)
        self.lbl_wind = self.get_label(u"      Wind: {} {} {}")
        self.lbl_humidity = self.get_label(u"  Humidity: {} %")
        self.lbl_visible = self.get_label(u"Visibility: {} {}")
        self.lbl_pressure = self.get_label(u"  Pressure: {} {}")
        self.lbl_daylight = self.get_label(u"  Daylight: {} - {}")
        self.lbl_gps = self.get_label(u"       GPS: {}, {}")

        self.pnl_today.children = (self.lbl_today_header, self.lbl_temp,
                                   pnl_cond, self.lbl_wind, self.lbl_humidity,
                                   self.lbl_visible, self.lbl_pressure,
                                   self.lbl_daylight, self.lbl_gps)

        # Build out the Forecast Panel
        self.pnl_forecast = StackPanel(controller.display, self)
        forecast_header = self.get_header_label("Forecast")
        self.pnl_forecast.children.append(forecast_header)

        # Add placeholders for the individual forecasts
        self.lbl_forecast = dict()
        self.lbl_forecast_icon = dict()
        self.chart_forecast = dict()
        for i in range(0, self.max_forecasts):
            label = self.get_label(u"{}: {}-{}{}")
            self.lbl_forecast[i] = label

            icon = self.get_label(u"{}")
            icon.font = controller.display.fonts.weather
            self.lbl_forecast_icon[i] = icon

            pnl_day = StackPanel(controller.display, self, is_horizontal=True)
            pnl_day.children = (label, icon)

            self.pnl_forecast.children.append(pnl_day)

            chart = BoxChart(controller.display, self)
            chart.width = 225
            chart.range_low = -20
            chart.range_high = 120
            chart.ticks = (0, 32, 100)
            self.chart_forecast[i] = chart
            self.pnl_forecast.children.append(chart)

        self.pnl_forecast.children.append(SpacerLine(controller.display, self))

        # Set up the main content panel
        self.content_panel = StackPanel(controller.display,
                                        self,
                                        is_horizontal=True,
                                        keep_together=True)
        self.content_panel.pad_last_item = True
        self.content_panel.auto_orient = True
        self.content_panel.children = (self.pnl_today, self.pnl_forecast)

        # Set up the master panel
        self.panel.children = [self.content_panel]
        self.panel.pad_last_item = False
Beispiel #24
0
class TextDashboardWidget(DashboardWidget):
    """
    A simple labeled dashboard widget
    :type display: PiMFD.UI.DisplayManager.DisplayManager
    :type page: PiMFD.Applications.Core.DashboardPages.DashboardPage
    :type title: str The name of the widget
    :type value: str The value used in the widget
    """

    def __init__(self, display, page, title, value, status=DashboardStatus.Passive):
        super(TextDashboardWidget, self).__init__(display, page, status)

        self.title = title
        self.value = value
        self.width = 150
        self.value_font = display.fonts.list

        self.panel = StackPanel(display, page)

        self.lbl_title = TextBlock(display, page, title, is_highlighted=True)
        self.lbl_title.font = display.fonts.list
        self.panel.children.append(self.lbl_title)

        self.lbl_value = TextBlock(display, page, value)
        self.lbl_value.font = display.fonts.list
        self.panel.children.append(self.lbl_value)

    def render(self):

        # Colorize as needed
        color = self.get_color()        
        self.lbl_value.color = color
        self.lbl_title.color = self.get_title_color()

        # Render an outline around the entire control
        rect = Rect(self.pos[0], self.pos[1], self.desired_size[0], self.desired_size[1])
        
        # Some statuses need custom backgrounds
        if self.status == DashboardStatus.Caution:
            render_rectangle(self.display, self.display.color_scheme.caution_bg, rect, width=0)
        elif self.status == DashboardStatus.Critical:
            render_rectangle(self.display, self.display.color_scheme.critical_bg, rect, width=0)
            
        # Render the outline
        render_rectangle(self.display, color, rect)

        # Render the base content with some padding
        pos = self.pos[0] + self.padding, self.pos[1] + self.padding
        self.panel.render_at(pos)

        # Assume the width of the outer outline
        return self.set_dimensions_from_rect(rect) 

    def arrange(self):
        self.lbl_title.text = self.title
        self.lbl_value.text = self.value
        self.lbl_value.font = self.value_font

        self.panel.arrange()
        self.desired_size = 150 + (self.padding * 2), self.panel.desired_size[1] + (self.padding * 2)
        return self.desired_size
Beispiel #25
0
    def refresh(self):
        """
        Refreshes the list of drives
        """

        # CPU Usage
        if self.application.data_provider.percentages:
            self.pnl_cpu.children = [self.get_header_label('CPU Performance')]
            cpu_index = 1
            for percent in self.application.data_provider.percentages:

                # Protect against bad values on first round
                if not percent:
                    percent = 0.0

                pnl = StackPanel(self.display, self, is_horizontal=True)
                lbl = self.get_list_label('{:02.1f} %'.format(percent))
                chart = BarChart(self.display, self)
                chart.value = percent
                chart.width, chart.height = 50, lbl.font.size
                pnl.children = [
                    self.get_list_label('{}:'.format(cpu_index)), chart, lbl
                ]
                self.pnl_cpu.children.append(pnl)
                cpu_index += 1

        # Virtual Memory
        virt_mem = self.application.data_provider.virt_mem
        if virt_mem:
            self.pnl_virt_mem.children = [
                self.get_header_label('Virtual Memory')
            ]
            self.pnl_virt_mem.children.append(
                self.get_list_label("Percent Used: {} %".format(
                    virt_mem.percent)))

            self.pnl_virt_mem.children.append(
                BarChart(self.display,
                         self,
                         value=virt_mem.percent,
                         width=200,
                         height=5))

            self.pnl_virt_mem.children.append(
                self.get_list_label("Total: {}".format(
                    format_size(virt_mem.total))))
            self.pnl_virt_mem.children.append(
                self.get_list_label("Used: {}".format(
                    format_size(virt_mem.used))))
            self.pnl_virt_mem.children.append(
                self.get_list_label("Free: {}".format(
                    format_size(virt_mem.free))))
            if virt_mem.free != virt_mem.available:
                self.pnl_virt_mem.children.append(
                    self.get_list_label("Available: {}".format(
                        format_size(virt_mem.available))))

        # Swap Memory
        swap_mem = self.application.data_provider.swap_mem
        if swap_mem:
            self.pnl_swap_mem.children = [self.get_header_label('Swap Memory')]
            self.pnl_swap_mem.children.append(
                self.get_list_label("Percent Used: {} %".format(
                    swap_mem.percent)))

            self.pnl_swap_mem.children.append(
                BarChart(self.display,
                         self,
                         value=swap_mem.percent,
                         width=200,
                         height=5))

            self.pnl_swap_mem.children.append(
                self.get_list_label("Total: {}".format(
                    format_size(swap_mem.total))))
            self.pnl_swap_mem.children.append(
                self.get_list_label("Used: {}".format(
                    format_size(swap_mem.used))))
            self.pnl_swap_mem.children.append(
                self.get_list_label("Free: {}".format(
                    format_size(swap_mem.free))))