Beispiel #1
0
    def __init__(self, parent: AppWidget):
        super().__init__(parent, "Time")

        d = TimeWidget(self,
                       Config.DateTime.date_format(),
                       h_alignment=TextWidget.HAlignment.CENTER)
        d.rectangle = Rectangle(AnchoredPoint(0, 0, Anchor.TOP_LEFT),
                                self.size)
        d.fit_font_size()
        d.set_height(d.preferred_size.height, VAnchor.TOP)

        t = TimeWidget(self, Config.DateTime.time_format())
        t.rectangle = Rectangle(
            d.position(Anchor.BOTTOM_LEFT).anchored(Anchor.TOP_LEFT) +
            Point(0, 2), self.size)
        t.fit_font_size()
        t.set_height(t.preferred_size.height, VAnchor.TOP)

        h = self.height - t.bottom
        s = SplitSecondSpinner(self)
        s.rectangle = Rectangle(
            t.position(Anchor.BOTTOM_RIGHT).anchored(Anchor.TOP_RIGHT),
            Size(h, h))

        self.uptime = App.uptime()
        self.uptime_widget = TextWidget(self, self._uptime(), Font(size=10))
        self.uptime_widget.rectangle = Rectangle(
            self.position(Anchor.BOTTOM_LEFT),
            Size(s.left, self.uptime_widget.preferred_size.height))
        self.app.scheduler.schedule_synchronous(timedelta(minutes=1),
                                                self._update_uptime)
        self._update_uptime()
Beispiel #2
0
 def do_layout(self):
     for child in self.children:
         if isinstance(child, TextWidget):
             child.set_size(Size(self.width, child.height), Anchor.TOP_LEFT)
     self._icon_widget.rectangle = Rectangle(
         self.size.position(Anchor.CENTER_RIGHT) + Point(5, 0),
         self.size / 1.5)
Beispiel #3
0
 def text_extents(self, text: str, inked: bool = True, ctx: Optional[Context] = None) -> Size:
     """
     :param text: Arbitrary text
     :param inked: If true, only the extend of the inked area is returned.
     :param ctx: If None, a dummy context will be created.
     :return: Extents of the given text.
     """
     layout = self.get_layout(text, ctx)
     extents = layout.get_extents()[0 if inked else 1]
     return Size(extents.width / 1000, extents.height / 1000)
Beispiel #4
0
    def __init__(self,
                 parent: ContainerWidget,
                 weather_periods: Optional[List[WeatherPeriod]],
                 download_manager: DownloadManager,
                 font: Font = Font(size=12)):
        super().__init__(parent)
        self._weather_periods = weather_periods
        self._font = font
        for i in range(5):
            w = WeatherWidget(self, None, download_manager)
            w.rectangle = Rectangle(
                AnchoredPoint(i * (w.preferred_size.width + 3), 0,
                              Anchor.TOP_LEFT), w.preferred_size)

            l: Line = Line(self, Line.Orientation.VERTICAL)
            l.foreground = Color.GRAY67
            l.rectangle = Rectangle(
                w.position(Anchor.TOP_RIGHT).anchored(Anchor.TOP_LEFT),
                Size(l.preferred_size().width, w.height))
        self._update_children()
Beispiel #5
0
 def do_layout(self):
     h = self._font.text_extents('Ag').height
     p = ZERO_TOP_LEFT
     for child in self.children:
         child.rectangle = Rectangle(p, Size(self.width, h + 2))
         p = child.position(Anchor.BOTTOM_LEFT).anchored(Anchor.TOP_LEFT)
Beispiel #6
0
 def fit_size(self, space: Size, text: str, ctx: Context = None) -> Font:
     s = Size(space.width, space.height)
     return dataclasses.replace(self, size=Font._narrow(self, s, text, 0, 10000, ctx))
Beispiel #7
0
    def __init__(self, parent: AppWidget):
        super().__init__(parent, "Main")

        self.lv2_3 = Line(self, Line.Orientation.VERTICAL)
        self.lv2_3.rectangle = Rectangle(AnchoredPoint(self.width / 3 * 2, 0, Anchor.TOP_LEFT),
                                         Size(self.lv2_3.preferred_size().width, self.height))

        self.date = TimeWidget(self, Config.DateTime.date_format(), h_alignment=TextWidget.HAlignment.CENTER)
        self.date.rectangle = Rectangle(self.lv2_3.position(Anchor.TOP_RIGHT).anchored(Anchor.TOP_LEFT),
                                        self.position(Anchor.BOTTOM_RIGHT))
        self.date.font = dataclasses.replace(self.date.font, bold=True)
        self.date.fit_font_size()
        self.date.set_height(self.date.preferred_size.height, VAnchor.TOP)
        self.date.foreground = Color.GRAY75

        self.time = TimeWidget(self, Config.DateTime.time_format())
        self.time.rectangle = Rectangle(self.date.position(Anchor.BOTTOM_LEFT).anchored(Anchor.TOP_LEFT) + Point(0, 2),
                                        self.position(Anchor.BOTTOM_RIGHT))
        self.time.fit_font_size()
        self.time.set_height(self.time.preferred_size.height, VAnchor.TOP)
        self.time.foreground = self.date.foreground

        self.lh1 = Line(self, Line.Orientation.HORIZONTAL)
        self.lh1.rectangle = Rectangle(self.time.position(Anchor.BOTTOM_LEFT).anchored(Anchor.TOP_LEFT),
                                       Size(self.width - self.lv2_3.left, self.lh1.preferred_size().height))

        self.wetter_com = WetterCom(Config.Weather.city_code(), Global.download_manager)
        self.weather_widgets = WeatherWidgets(self, None, Global.download_manager)
        self.weather_widgets.rectangle = Rectangle(self.position(Anchor.BOTTOM_LEFT),
                                                   self.weather_widgets.preferred_size)
        self.load_weather()
        self.app.scheduler.schedule_synchronous(timedelta(minutes=10), self.load_weather)

        temp_font = Font(size=11, bold=True)
        self.out_temp = TextWidget(self, 'Out: -00.0° - -00.0°', temp_font)
        self.out_temp.rectangle = Rectangle(self.weather_widgets.position(Anchor.TOP_LEFT).anchored(Anchor.BOTTOM_LEFT)
                                            + Point(0, -1),
                                            self.out_temp.preferred_size + Size(0, 2))
        self.out_temp.foreground = Color.GRAY80
        self.out_temp.escape = False

        self.in_temp = TextWidget(self, 'In: -00.0° - -00.0°', temp_font)
        self.in_temp.rectangle = Rectangle(AnchoredPoint(self.width, self.out_temp.top, Anchor.TOP_RIGHT),
                                           self.in_temp.preferred_size)
        self.in_temp.foreground = Color.GRAY80
        self.in_temp.escape = False
        self.in_temp.h_alignment = TextWidget.HAlignment.RIGHT

        self.balcony_temp = TextWidget(self, 'Blk: -00.0°', temp_font)
        self.balcony_temp.rectangle = Rectangle(AnchoredPoint((self.out_temp.right + self.in_temp.left) / 2,
                                                              self.out_temp.top, Anchor.TOP_CENTER),
                                                self.balcony_temp.preferred_size)
        self.balcony_temp.foreground = Color.GRAY80
        self.balcony_temp.escape = False
        self.balcony_temp.h_alignment = TextWidget.HAlignment.CENTER

        def get_temp_values(_): Global.download_manager.get(Config.Weather.temp_values_url(),
                                                            self.load_temp_values,
                                                            timedelta(seconds=29))

        get_temp_values(None)
        self.app.scheduler.schedule_synchronous(timedelta(minutes=1), get_temp_values)

        self.lh3 = Line(self, Line.Orientation.HORIZONTAL)
        self.lh3.rectangle = Rectangle(self.out_temp.position(Anchor.TOP_LEFT).anchored(Anchor.BOTTOM_LEFT)
                                       + Point(0, -1),
                                       Size(self.width, self.lh3.preferred_size().height))

        self.track_title = MediaPlayerTrackTitleWidget(self, Global.media_player, Font(size=14))
        self.track_title.rectangle = Rectangle(self.lh3.position(Anchor.TOP_LEFT).anchored(Anchor.BOTTOM_LEFT),
                                               Size(self.width, self.track_title.font.font_extents().height))

        track_position_font = Font(size=11, bold=True)
        self.track_position = MediaPlayerTrackPositionWidget(self, Global.media_player, track_position_font)
        self.track_position.rectangle = Rectangle(
            self.track_title.position(Anchor.TOP_LEFT).anchored(Anchor.BOTTOM_LEFT),
            Size(self.width / 3, self.track_position.font.font_extents().height))

        self.track_duration = MediaPlayerTrackDurationWidget(self, Global.media_player, track_position_font)
        self.track_duration.rectangle = Rectangle(
            self.track_title.position(Anchor.TOP_CENTER).anchored(Anchor.BOTTOM_CENTER),
            Size(self.width / 3, self.track_duration.font.font_extents().height))
        self.track_duration.h_alignment = TextWidget.HAlignment.CENTER

        self.track_remaining = MediaPlayerTrackRemainingWidget(self, Global.media_player, track_position_font)
        self.track_remaining.rectangle = Rectangle(
            self.track_title.position(Anchor.TOP_RIGHT).anchored(Anchor.BOTTOM_RIGHT),
            Size(self.width / 3, self.track_remaining.font.font_extents().height))
        self.track_remaining.h_alignment = TextWidget.HAlignment.RIGHT

        self.lh2 = Line(self, Line.Orientation.HORIZONTAL)
        self.lh2.rectangle = Rectangle(
            self.track_position.position(Anchor.TOP_LEFT).anchored(Anchor.BOTTOM_LEFT) + Point(0, -1),
            Size(self.width, self.lh2.preferred_size().height))

        self.lv2_3.set_height(self.lh2.bottom, VAnchor.TOP)

        self.cpu_load_text = CpuLoadTextWidget(self, Font(size=12), h_alignment=TextWidget.HAlignment.CENTER)
        self.cpu_load_text.rectangle = Rectangle(self.lh2.position(Anchor.TOP_LEFT).anchored(Anchor.BOTTOM_LEFT)
                                                 + Point(0, -1), self.cpu_load_text.preferred_size)
        self.cpu_load_text.foreground = Color.GRAY90

        self.cpu_load_bar = CpuLoadBarWidget(self, BarWidget.Orientation.VERTICAL_UP, Color.GRAY75)
        self.cpu_load_bar.rectangle = Rectangle(
            self.cpu_load_text.position(Anchor.TOP_LEFT).anchored(Anchor.BOTTOM_LEFT),
            Size(self.cpu_load_text.width, self.cpu_load_text.top))

        self.mem_stats_bar = MemStatsBar(self, Font(size=12), Color.GRAY75)
        self.mem_stats_bar.rectangle = \
            Rectangle(AnchoredPoint(self.cpu_load_bar.right, 0, Anchor.TOP_LEFT) + Point(1, 0),
                      Size(self.lv2_3.left - self.cpu_load_bar.right - 2, self.cpu_load_bar.width))
        self.mem_stats_bar.foreground = Color.WHITE.with_value(alpha=0.9)

        self.disk_stats = DiskStats(self, Font(size=12))
        self.disk_stats.rectangle = Rectangle(self.lv2_3.position(Anchor.BOTTOM_LEFT).anchored(Anchor.BOTTOM_RIGHT)
                                              + Point(0, -3), self.cpu_load_text.position(Anchor.TOP_RIGHT))
        self.disk_stats.h_alignment = TextWidget.HAlignment.CENTER

        self.lhs = Line(self, Line.Orientation.HORIZONTAL)
        self.lhs.rectangle = Rectangle(self.disk_stats.position(Anchor.TOP_LEFT).anchored(Anchor.BOTTOM_LEFT)
                                       + Point(0, -1), Size(self.disk_stats.width, self.lhs.preferred_size().height))
        self.lhs.foreground = Color.GRAY50

        self.processes = ProcessList(self, 5, Font(size=12))
        self.processes.rectangle = Rectangle(self.mem_stats_bar.position(Anchor.BOTTOM_LEFT).anchored(Anchor.TOP_LEFT)
                                             + Point(2, 5),
                                             self.lhs.position(Anchor.TOP_RIGHT))

        self.fritz_box = FritzBox(self.app.scheduler, Config.FritzBox.address(), Config.FritzBox.password())
        self.fritz_box_connected = FritzBoxConnectedWidget(self, self.fritz_box, Font(size=12))
        self.fritz_box_connected.rectangle = Rectangle(
            self.lh1.position(Anchor.BOTTOM_LEFT).anchored(Anchor.TOP_LEFT) + Point(1, 1),
            Size(self.lh1.width, self.fritz_box_connected.preferred_size.height))

        self.fritz_box_speed = FritzBoxSpeedWidget(self, self.fritz_box, Font(size=12))
        self.fritz_box_speed.rectangle = Rectangle(
            self.fritz_box_connected.position(Anchor.BOTTOM_LEFT).anchored(Anchor.TOP_LEFT) + Point(0, 1),
            Size(self.fritz_box_connected.width, self.fritz_box_speed.preferred_size.height))

        self.fritz_box_hosts = FritzBoxHostsWidget(self, self.fritz_box, Font(size=12))
        self.fritz_box_hosts.rectangle = Rectangle(
            self.fritz_box_speed.position(Anchor.BOTTOM_LEFT).anchored(Anchor.TOP_LEFT) + Point(0, 1),
            Size(self.fritz_box_connected.width, self.fritz_box_hosts.preferred_size.height))

        self.fritz_box_ip6 = FritzBoxIp6Widget(self, self.fritz_box, Font(size=12))
        self.fritz_box_ip6.rectangle = Rectangle(
            self.lv2_3.position(Anchor.BOTTOM_RIGHT).anchored(Anchor.BOTTOM_LEFT) + Point(1, -3),
            Size(self.fritz_box_connected.width, self.fritz_box_ip6.preferred_size.height))
        self.fritz_box_ip6.fit_font_size()
        self.fritz_box_ip6.set_height(self.fritz_box_ip6.preferred_size.height, VAnchor.BOTTOM)

        self.fritz_box_ip4 = FritzBoxIp4Widget(self, self.fritz_box, Font(size=12))
        self.fritz_box_ip4.rectangle = Rectangle(
            self.fritz_box_ip6.position(Anchor.TOP_LEFT).anchored(Anchor.BOTTOM_LEFT) + Point(0, -1),
            Size(self.fritz_box_connected.width, self.fritz_box_ip4.preferred_size.height))

        self.fritz_box_traffic = FritzBoxTrafficWidget(self, self.fritz_box, Font(size=12))
        self.fritz_box_traffic.rectangle = Rectangle(
            self.fritz_box_hosts.position(Anchor.BOTTOM_LEFT).anchored(Anchor.TOP_LEFT) + Point(0, 1),
            self.fritz_box_ip4.position(Anchor.TOP_RIGHT) + Point(0, -1))
Beispiel #8
0
 def preferred_size(self) -> Size:
     return Size(self.children[-1].right, self.children[0].bottom)
Beispiel #9
0
 def preferred_size(self) -> Size:
     return Size(64 - 3 * 4 / 5, self._rain_widget.bottom)
Beispiel #10
0
 def set_height(self, height: float, anchor: VAnchor):
     self.rectangle = Rectangle(self.position(anchor + HAnchor.LEFT),
                                Size(self.width, height))
     self.dirty = True
Beispiel #11
0
 def set_width(self, width: float, anchor: HAnchor):
     self.rectangle = Rectangle(self.position(VAnchor.TOP + anchor),
                                Size(width, self.width))
Beispiel #12
0
 def image_size(self) -> Size:
     return Size(320, 240)
Beispiel #13
0
 def preferred_size(self) -> Size:
     if self.orientation == Line.Orientation.HORIZONTAL:
         return Size(self.width, self.margin * 2 + self.width)
     return Size(self.margin * 2 + self.width, self.height)