def __init__(self, conf, song): Gtk.Window.__init__(self, Gtk.WindowType.POPUP) self.set_type_hint(Gdk.WindowTypeHint.NOTIFICATION) screen = self.get_screen() rgba = screen.get_rgba_visual() if rgba is not None: self.set_visual(rgba) self.conf = conf self.iteration_source = None self.fading_in = False self.fade_start_time = 0 mgeo = screen.get_monitor_geometry(conf.monitor) textwidth = mgeo.width - 2 * (self.BORDER + self.MARGIN) scale_factor = get_scale_factor(self) self.cover_pixbuf = app.cover_manager.get_pixbuf( song, conf.coversize * scale_factor, conf.coversize * scale_factor) coverheight = 0 coverwidth = 0 if self.cover_pixbuf: self.cover_pixbuf = get_pbosf_for_pixbuf(self, self.cover_pixbuf) coverwidth = self.cover_pixbuf.get_width() // scale_factor coverheight = self.cover_pixbuf.get_height() // scale_factor textwidth -= coverwidth + self.BORDER layout = self.create_pango_layout('') layout.set_alignment((Pango.Alignment.LEFT, Pango.Alignment.CENTER, Pango.Alignment.RIGHT)[conf.align]) layout.set_spacing(Pango.SCALE * 7) layout.set_font_description(Pango.FontDescription(conf.font)) try: layout.set_markup(pattern.XMLFromMarkupPattern(conf.string) % song) except pattern.error: layout.set_markup("") layout.set_width(Pango.SCALE * textwidth) layoutsize = layout.get_pixel_size() if layoutsize[0] < textwidth: layout.set_width(Pango.SCALE * layoutsize[0]) layoutsize = layout.get_pixel_size() self.title_layout = layout winw = layoutsize[0] + 2 * self.BORDER if coverwidth: winw += coverwidth + self.BORDER winh = max(coverheight, layoutsize[1]) + 2 * self.BORDER self.set_default_size(winw, winh) rect = namedtuple("Rect", ["x", "y", "width", "height"]) rect.x = self.BORDER rect.y = (winh - coverheight) // 2 rect.width = coverwidth rect.height = coverheight self.cover_rectangle = rect winx = int((mgeo.width - winw) * self.POS_X) winx = max(self.MARGIN, min(mgeo.width - self.MARGIN - winw, winx)) winy = int((mgeo.height - winh) * conf.pos_y) winy = max(self.MARGIN, min(mgeo.height - self.MARGIN - winh, winy)) self.move(winx + mgeo.x, winy + mgeo.y)
textwidth = mgeo.width - 2 * (conf.border + conf.margin) if cover is not None: textwidth -= coverwidth + conf.border coverheight = int(cover.get_height() * float(coverwidth) / cover.get_width()) else: coverheight = 0 self.cover_pixbuf = cover layout = self.create_pango_layout('') layout.set_alignment((Pango.Alignment.LEFT, Pango.Alignment.CENTER, Pango.Alignment.RIGHT)[conf.align]) layout.set_spacing(Pango.SCALE * 7) layout.set_font_description(Pango.FontDescription(conf.font)) try: layout.set_markup(pattern.XMLFromMarkupPattern(conf.string) % song) except pattern.error: layout.set_markup("") layout.set_width(Pango.SCALE * textwidth) layoutsize = layout.get_pixel_size() if layoutsize[0] < textwidth: layout.set_width(Pango.SCALE * layoutsize[0]) layoutsize = layout.get_pixel_size() self.title_layout = layout winw = layoutsize[0] + 2 * conf.border if cover is not None: winw += coverwidth + conf.border winh = max(coverheight, layoutsize[1]) + 2 * conf.border self.set_default_size(winw, winh)