示例#1
0
    def __init__(self, title, fileobj, parent):
        super(BigCenteredImage, self).__init__(type=Gtk.WindowType.POPUP)
        self.set_type_hint(Gdk.WindowTypeHint.TOOLTIP)

        assert parent
        parent = qltk.get_top_parent(parent)
        self.set_transient_for(parent)

        if qltk.is_wayland():
            # no screen size with wayland, the parent window is
            # the next best thing..
            width, height = parent.get_size()
            width = int(width / 1.1)
            height = int(height / 1.1)
        else:
            width = int(Gdk.Screen.width() / 1.8)
            height = int(Gdk.Screen.height() / 1.8)

        self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)

        scale_factor = self.get_scale_factor()

        pixbuf = None
        try:
            pixbuf = pixbuf_from_file(fileobj, (width, height), scale_factor)
        except GLib.GError:
            pass

        # failed to load, abort
        if not pixbuf:
            self.destroy()
            return

        image = Gtk.Image()
        image.set_from_surface(get_surface_for_pixbuf(self, pixbuf))

        event_box = Gtk.EventBox()
        event_box.add(image)

        frame = Gtk.Frame()
        frame.set_shadow_type(Gtk.ShadowType.OUT)
        frame.add(event_box)

        self.add(frame)

        event_box.connect('button-press-event', self.__destroy)
        event_box.connect('key-press-event', self.__destroy)
        self.get_child().show_all()
示例#2
0
    def __init__(self, title, fileobj, parent):
        super(BigCenteredImage, self).__init__(type=Gtk.WindowType.POPUP)
        self.set_type_hint(Gdk.WindowTypeHint.TOOLTIP)

        assert parent
        parent = qltk.get_top_parent(parent)
        self.set_transient_for(parent)

        if qltk.is_wayland():
            # no screen size with wayland, the parent window is
            # the next best thing..
            width, height = parent.get_size()
            width = int(width / 1.1)
            height = int(height / 1.1)
        else:
            width = int(Gdk.Screen.width() / 1.75)
            height = int(Gdk.Screen.height() / 1.75)

        self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)

        scale_factor = get_scale_factor(self)

        pixbuf = None
        try:
            pixbuf = pixbuf_from_file(fileobj, (width, height), scale_factor)
        except GLib.GError:
            pass

        # failed to load, abort
        if not pixbuf:
            self.destroy()
            return

        image = Gtk.Image()
        set_image_from_pbosf(image, get_pbosf_for_pixbuf(self, pixbuf))

        event_box = Gtk.EventBox()
        event_box.add(image)

        frame = Gtk.Frame()
        frame.set_shadow_type(Gtk.ShadowType.OUT)
        frame.add(event_box)

        self.add(frame)

        event_box.connect('button-press-event', self.__destroy)
        event_box.connect('key-press-event', self.__destroy)
        self.get_child().show_all()
示例#3
0
    def set_image(self, file, parent, scale=0.5):
        scale_factor = self.get_scale_factor()

        (width, height) = self.__calculate_screen_width(parent, scale)

        pixbuf = None
        try:
            pixbuf = pixbuf_from_file(file, (width, height), scale_factor)
        except GLib.GError:
            return False

        # failed to load, abort
        if not pixbuf:
            return False

        self.__image = Gtk.Image()
        self.__image.set_from_surface(get_surface_for_pixbuf(self, pixbuf))

        return True
示例#4
0
文件: cover.py 项目: zsau/quodlibet
    def set_image(self, file, parent):
        scale_factor = self.get_scale_factor()

        (width, height) = self.__calculate_screen_width(parent)

        pixbuf = None
        try:
            pixbuf = pixbuf_from_file(file, (width, height), scale_factor)
        except GLib.GError:
            return False

        # failed to load, abort
        if not pixbuf:
            return False

        self.__image = Gtk.Image()
        self.__image.set_from_surface(get_surface_for_pixbuf(self, pixbuf))

        return True
示例#5
0
    def __init__(self, title, fileobj, parent):
        super(BigCenteredImage, self).__init__(type=Gtk.WindowType.POPUP)
        self.set_type_hint(Gdk.WindowTypeHint.TOOLTIP)

        assert parent
        parent = qltk.get_top_parent(parent)
        self.set_transient_for(parent)

        if qltk.is_wayland():
            # no screen size with wayland, the parent window is
            # the next best thing..
            width, height = parent.get_size()
            width = int(width / 1.1)
            height = int(height / 1.1)
        else:
            win = parent.get_window()
            if win:
                if qltk.gtk_version[:2] >= (3, 22):
                    disp = Gdk.Display.get_default()
                    mon = disp.get_monitor_at_window(win)
                    rect = mon.get_geometry()
                else:
                    # The result should be the same as above, just using
                    # deprecated methods instead
                    screen = Gdk.Screen.get_default()
                    mon_num = screen.get_monitor_at_window(win)
                    rect = screen.get_monitor_geometry(mon_num)
                width = int(rect.width / 1.8)
                height = int(rect.height / 1.8)
            else:
                width = int(Gdk.Screen.width() / 1.8)
                height = int(Gdk.Screen.height() / 1.8)

        self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)

        scale_factor = self.get_scale_factor()

        pixbuf = None
        try:
            pixbuf = pixbuf_from_file(fileobj, (width, height), scale_factor)
        except GLib.GError:
            pass

        # failed to load, abort
        if not pixbuf:
            self.destroy()
            return

        image = Gtk.Image()
        image.set_from_surface(get_surface_for_pixbuf(self, pixbuf))

        event_box = Gtk.EventBox()
        event_box.add(image)

        frame = Gtk.Frame()
        frame.set_shadow_type(Gtk.ShadowType.OUT)
        frame.add(event_box)

        self.add(frame)

        event_box.connect('button-press-event', self.__destroy)
        event_box.connect('key-press-event', self.__destroy)
        self.get_child().show_all()
示例#6
0
    def __init__(self, title, fileobj, parent):
        super(BigCenteredImage, self).__init__(type=Gtk.WindowType.POPUP)
        self.set_type_hint(Gdk.WindowTypeHint.TOOLTIP)

        assert parent
        parent = qltk.get_top_parent(parent)
        self.set_transient_for(parent)

        if qltk.is_wayland():
            # no screen size with wayland, the parent window is
            # the next best thing..
            width, height = parent.get_size()
            width = int(width / 1.1)
            height = int(height / 1.1)
        else:
            win = parent.get_window()
            if win:
                if qltk.gtk_version[:2] >= (3, 22):
                    disp = Gdk.Display.get_default()
                    mon = disp.get_monitor_at_window(win)
                    rect = mon.get_geometry()
                else:
                    # The result should be the same as above, just using
                    # deprecated methods instead
                    screen = Gdk.Screen.get_default()
                    mon_num = screen.get_monitor_at_window(win)
                    rect = screen.get_monitor_geometry(mon_num)
                width = int(rect.width / 1.8)
                height = int(rect.height / 1.8)
            else:
                width = int(Gdk.Screen.width() / 1.8)
                height = int(Gdk.Screen.height() / 1.8)

        self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)

        scale_factor = self.get_scale_factor()

        pixbuf = None
        try:
            pixbuf = pixbuf_from_file(fileobj, (width, height), scale_factor)
        except GLib.GError:
            pass

        # failed to load, abort
        if not pixbuf:
            self.destroy()
            return

        image = Gtk.Image()
        image.set_from_surface(get_surface_for_pixbuf(self, pixbuf))

        event_box = Gtk.EventBox()
        event_box.add(image)

        frame = Gtk.Frame()
        frame.set_shadow_type(Gtk.ShadowType.OUT)
        frame.add(event_box)

        self.add(frame)

        event_box.connect('button-press-event', self.__destroy)
        event_box.connect('key-press-event', self.__destroy)
        self.get_child().show_all()