Exemplo n.º 1
0
def _smart_fn(filename):
    try:
        image_w, image_h = Util.get_size(filename)
        primary_w, primary_h = Util.get_primary_display_size(hidpi_scaled=True)
        total_w, total_h = Util.get_multimonitor_display_size()
        if image_w * image_h * 10 < primary_w * primary_h:
            # image way smaller than primary monitor, tile it
            return DisplayModeData(set_wallpaper_param="wallpaper")
        else:
            image_ratio = image_w / image_h
            primary_ratio = primary_w / primary_h
            total_ratio = total_w / total_h
            if 2 * abs(image_ratio - primary_ratio) / (image_ratio +
                                                       primary_ratio) < 0.2:
                # image ratio is close to primary screen ratio, zoom
                return DisplayModeData(set_wallpaper_param="zoom")
            elif 2 * abs(image_ratio - total_ratio) / (image_ratio +
                                                       total_ratio) < 0.2:
                # image ratio is close to multimonitor total screen ratio, span it
                return DisplayModeData(set_wallpaper_param="spanned")
            else:
                # image ratio not close to screen ratio, fit with a blurred background
                cmd = IMAGEMAGICK_FIT_WITH_BLUR.replace(
                    "%W", str(primary_w)).replace("%H", str(primary_h))
                return DisplayModeData(set_wallpaper_param="zoom",
                                       imagemagick_cmd=cmd)
    except:
        return DisplayModeData(set_wallpaper_param="zoom")
Exemplo n.º 2
0
def _fill_with_blur(filename):
    w, h = Util.get_primary_display_size()
    return (
        "zoom",
        "-resize %dx%d^ -gravity center -extent %dx%d -blur 0x10 -clone 0 -resize %dx%d -size %dx%d -gravity center -composite"
        % (w, h, w, h, w, h, w, h),
    )
Exemplo n.º 3
0
def _fill_with_black(filename):
    w, h = Util.get_primary_display_size()
    return (
        "zoom",
        "-resize %dx%d\> -size %dx%d xc:black +swap -gravity center -composite"
        % (w, h, w, h),
    )
Exemplo n.º 4
0
    def fill_queue(self):
        if time.time() - UnsplashDownloader.rate_limiting_started_time < 3600:
            logger.info(
                lambda:
                "Unsplash queue empty, but rate limit reached, will try again later"
            )
            return []

        url = self.get_unsplash_api_url()
        logger.info(lambda: "Filling Unsplash queue from " + url)

        r = Util.request(url)
        if int(r.headers.get("X-Ratelimit-Remaining", 1000000)) < 1000:
            UnsplashDownloader.rate_limiting_started_time = time.time()

        queue = []
        for item in r.json():
            try:
                width = item["width"]
                height = item["height"]
                if self.is_size_inadequate(width, height):
                    continue

                image_url = item["urls"]["full"] + "&w={}".format(
                    max(1980, int(Util.get_primary_display_size()[0] * 1.2)))
                origin_url = item["links"][
                    "html"] + UnsplashDownloader.UTM_PARAMS

                extra_metadata = {
                    "sourceType":
                    "unsplash",
                    "sfwRating":
                    100,
                    "author":
                    item["user"]["name"],
                    "authorURL":
                    item["user"]["links"]["html"] +
                    UnsplashDownloader.UTM_PARAMS,
                    "keywords": [
                        cat["title"].lower().strip()
                        for cat in item["categories"]
                    ],
                    "extraData": {
                        "unsplashDownloadLocation":
                        item["links"]["download_location"],
                        "unsplashDownloadReported":
                        False,
                    },
                }

                queue.append((origin_url, image_url, extra_metadata))
            except:
                logger.exception(
                    lambda: "Could not process an item from Unsplash")
                raise

        random.shuffle(queue)
        return queue
Exemplo n.º 5
0
 def fn(filename: str):
     w, h = Util.get_primary_display_size()
     if imagemagick_cmd:
         final_cmd = imagemagick_cmd.replace("%W", str(w)).replace(
             "%H", str(h))
     else:
         final_cmd = None
     return DisplayModeData(set_wallpaper_param=set_wallpaper_param,
                            imagemagick_cmd=final_cmd)
Exemplo n.º 6
0
    def write_quote_on_surface(surface,
                               quote,
                               author=None,
                               options=None,
                               margin=30):
        qcontext = cairo.Context(surface)  # pylint: disable=no-member
        acontext = cairo.Context(surface)  # pylint: disable=no-member

        iw = surface.get_width()
        ih = surface.get_height()

        sw, sh = Util.get_primary_display_size(hidpi_scaled=True)
        trimw, trimh = Util.compute_trimmed_offsets((iw, ih), (sw, sh))

        width = max(200, sw * options.quotes_width //
                    100)  # use quotes_width percent of the visible width

        qlayout = PangoCairo.create_layout(qcontext)
        qlayout.set_width((width - 4 * margin) * Pango.SCALE)
        qlayout.set_alignment(Pango.Alignment.LEFT)
        qlayout.set_wrap(Pango.WrapMode.WORD)
        font = options.quotes_font if options else "Serif 30"
        qlayout.set_font_description(Pango.FontDescription(font))
        qlayout.set_text(quote, -1)

        qheight = qlayout.get_pixel_size()[1]
        qwidth = qlayout.get_pixel_size()[0]
        if options.quotes_width < 98:
            width = qwidth + 4 * margin
        else:
            width = sw

        alayout = PangoCairo.create_layout(acontext)
        aheight = 0
        if author:
            alayout.set_width(qwidth * Pango.SCALE)
            alayout.set_alignment(Pango.Alignment.RIGHT)
            alayout.set_wrap(Pango.WrapMode.WORD)
            alayout.set_font_description(Pango.FontDescription(font))
            alayout.set_text(author, -1)

            aheight = alayout.get_pixel_size()[1]

        height = qheight + aheight + 2.5 * margin

        bgc = options.quotes_bg_color
        qcontext.set_source_rgba(bgc[0] / 255.0, bgc[1] / 255.0,
                                 bgc[2] / 255.0, options.quotes_bg_opacity /
                                 100.0)  # gray semi-transparent background

        hpos = trimw + (sw - width) * options.quotes_hpos // 100
        vpos = trimh + (sh - height) * options.quotes_vpos // 100
        qcontext.rectangle(hpos, vpos, width, height)
        qcontext.fill()

        qcontext.translate(hpos + (width - qwidth) / 2, vpos + margin)

        if options.quotes_text_shadow:
            qcontext.set_source_rgba(0, 0, 0, 0.2)
            PangoCairo.update_layout(qcontext, qlayout)
            PangoCairo.show_layout(qcontext, qlayout)
            qcontext.translate(-2, -2)

        tc = options.quotes_text_color

        qcontext.set_source_rgb(tc[0] / 255.0, tc[1] / 255.0, tc[2] / 255.0)
        PangoCairo.update_layout(qcontext, qlayout)
        PangoCairo.show_layout(qcontext, qlayout)

        acontext.translate(hpos + (width - qwidth) / 2,
                           vpos + margin + qheight + margin / 2)

        if options.quotes_text_shadow:
            acontext.set_source_rgba(0, 0, 0, 0.2)
            PangoCairo.update_layout(acontext, alayout)
            PangoCairo.show_layout(acontext, alayout)
            acontext.translate(-2, -2)

        acontext.set_source_rgb(tc[0] / 255.0, tc[1] / 255.0, tc[2] / 255.0)
        PangoCairo.update_layout(acontext, alayout)
        PangoCairo.show_layout(acontext, alayout)

        qcontext.show_page()
        acontext.show_page()
Exemplo n.º 7
0
def _zoom(filename):
    w, h = Util.get_primary_display_size()
    return "zoom", "-scale %dx%d^ " % (w, h)