本文整理匯總了Python中gi.repository.GdkPixbuf.Pixbuf方法的典型用法代碼示例。如果您正苦於以下問題:Python GdkPixbuf.Pixbuf方法的具體用法?Python GdkPixbuf.Pixbuf怎麽用?Python GdkPixbuf.Pixbuf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gi.repository.GdkPixbuf
的用法示例。
在下文中一共展示了GdkPixbuf.Pixbuf方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: find_mime_type_pixbuf
# 需要導入模塊: from gi.repository import GdkPixbuf [as 別名]
# 或者: from gi.repository.GdkPixbuf import Pixbuf [as 別名]
def find_mime_type_pixbuf(mime_type):
try:
icontmp = mime_type.replace('/','-')
newicon = "gnome-mime-%s" % icontmp
try:
return _icon_theme.load_icon(newicon,48,0)
except:
icontmp = mime_type.split('/')[0]
try:
newicon = "gnome-mime-%s" % icontmp
return _icon_theme.load_icon(newicon,48,0)
except:
return GdkPixbuf.Pixbuf.new_from_file(ICON)
except:
return GdkPixbuf.Pixbuf.new_from_file(ICON)
#-------------------------------------------------------------------------
#
# run_thumbnailer
#
#-------------------------------------------------------------------------
示例2: get_thumbnail_path
# 需要導入模塊: from gi.repository import GdkPixbuf [as 別名]
# 或者: from gi.repository.GdkPixbuf import Pixbuf [as 別名]
def get_thumbnail_path(src_file, mtype=None, rectangle=None, size=SIZE_NORMAL):
"""
Return the path to the thumbnail image associated with the
source file passed to the function. If the thumbnail does not exist,
or if it is older than the source file, we create a new thumbnail image.
:param src_file: Source media file
:type src_file: unicode
:param mime_type: mime type of the source file
:type mime_type: unicode
:param rectangle: subsection rectangle
:type rectangle: tuple
:returns: thumbnail representing the source file
:rtype: GdkPixbuf.Pixbuf
"""
filename = __build_thumb_path(src_file, rectangle, size)
if not os.path.isfile(src_file):
return os.path.join(IMAGE_DIR, "image-missing.png")
else:
if (not os.path.isfile(filename)) or (
os.path.getmtime(src_file) > os.path.getmtime(filename)):
if not __create_thumbnail_image(src_file, mtype, rectangle, size):
return os.path.join(IMAGE_DIR, "document.png")
return os.path.abspath(filename)
示例3: __load_icon
# 需要導入模塊: from gi.repository import GdkPixbuf [as 別名]
# 或者: from gi.repository.GdkPixbuf import Pixbuf [as 別名]
def __load_icon(self):
"""
Loads emblem icons from the current icon theme
Sometimes an icon can't be loaded because of a bug in system
libraries, e.g. bug #1079587. Gracefuly degradate and skip
the loading of a corrupted icon.
"""
self.symbol_model = Gtk.ListStore(GdkPixbuf.Pixbuf, str)
for icon in Gtk.IconTheme.get_default().list_icons(context="Emblems"):
try:
img = Gtk.IconTheme.get_default().load_icon(icon, 16, 0)
self.symbol_model.append([img, icon])
except GObject.GError:
log.error(f"Failed to load icon '{icon}'")
self.symbol_iv.set_model(self.symbol_model)
self.loaded = True
# PUBLIC IF #####
示例4: render_theme
# 需要導入模塊: from gi.repository import GdkPixbuf [as 別名]
# 或者: from gi.repository.GdkPixbuf import Pixbuf [as 別名]
def render_theme(self):
sample_path = files.get_sample_path(self.selected_file)
try:
self.color_list = color.get_color_list(self.selected_file)
except SystemExit:
self.color_list = themer.set_fallback_theme(self.selected_file)
self.render_buttons()
try:
self.pixbuf_sample = GdkPixbuf.Pixbuf\
.new_from_file_at_size(sample_path, width=500, height=300)
except:
sample.create_sample(self.color_list, sample_path)
self.pixbuf_sample = GdkPixbuf.Pixbuf\
.new_from_file_at_size(sample_path, width=500, height=300)
self.sample.set_from_pixbuf(self.pixbuf_sample)
self.parent.sample.set_from_pixbuf(self.pixbuf_sample)
示例5: __init__
# 需要導入模塊: from gi.repository import GdkPixbuf [as 別名]
# 或者: from gi.repository.GdkPixbuf import Pixbuf [as 別名]
def __init__(self, app):
"""Set default values for attributes."""
super(Image, self).__init__()
self._app = app
# Settings and defaults
self.fit_image = "overzoom"
self._pixbuf_iter = GdkPixbuf.PixbufAnimationIter()
self._pixbuf_original = GdkPixbuf.Pixbuf()
self.zoom_percent = 1
self._identifier = 0
self._size = (1, 1)
self._timer_id = 0
self._faulty_image = False
# Connect signals
self._app["transform"].connect("changed", self._on_image_changed)
self._app["commandline"].search.connect("search-completed",
self._on_search_completed)
settings.connect("changed", self._on_settings_changed)
示例6: _update
# 需要導入模塊: from gi.repository import GdkPixbuf [as 別名]
# 或者: from gi.repository.GdkPixbuf import Pixbuf [as 別名]
def _update(self):
"""Show the final image."""
if not self._app.get_paths() or self._faulty_image:
return
# Scale image
pbo_width = self._pixbuf_original.get_width()
pbo_height = self._pixbuf_original.get_height()
pbf_width = int(pbo_width * self.zoom_percent)
pbf_height = int(pbo_height * self.zoom_percent)
# Rescaling of svg
if is_svg(self._app.get_path()) and settings["rescale_svg"].get_value():
pixbuf_final = GdkPixbuf.Pixbuf.new_from_file_at_scale(
self._app.get_path(), -1, pbf_height, True)
else:
pixbuf_final = self._pixbuf_original.scale_simple(
pbf_width, pbf_height, GdkPixbuf.InterpType.BILINEAR)
self.set_from_pixbuf(pixbuf_final)
# Update the statusbar
self._app["statusbar"].update_info()
示例7: _load_thread
# 需要導入模塊: from gi.repository import GdkPixbuf [as 別名]
# 或者: from gi.repository.GdkPixbuf import Pixbuf [as 別名]
def _load_thread(self, loader, path):
# The try ... except wrapper and the _faulty_image attribute are used to
# catch weird images that break GdkPixbufLoader but work otherwise
# See https://github.com/karlch/vimiv/issues/49 for more information
try:
self._faulty_image = True
with open(path, "rb") as f:
image_bytes = f.read()
loader.write(image_bytes)
self._faulty_image = False
loader.close()
except GLib.GError:
self._pixbuf_original = GdkPixbuf.Pixbuf.new_from_file(path)
self._faulty_image = False
self._set_image_pixbuf()
GLib.idle_add(self._update)
示例8: save_pixbuf
# 需要導入模塊: from gi.repository import GdkPixbuf [as 別名]
# 或者: from gi.repository.GdkPixbuf import Pixbuf [as 別名]
def save_pixbuf(pixbuf, filename, update_orientation_tag=False):
"""Save the image with all the exif keys that exist if we have exif support.
NOTE: This is used to override edited images, not to save images to new
paths. The filename must exist as it is used to retrieve the image
format and exif data.
Args:
pixbuf: GdkPixbuf.Pixbuf image to act on.
filename: Name of the image to save.
update_orientation_tag: If True, set orientation tag to NORMAL.
"""
if not os.path.isfile(filename):
raise FileNotFoundError("Original file to retrieve data from not found")
# Get needed information
info = GdkPixbuf.Pixbuf.get_file_info(filename)[0]
extension = info.get_extensions()[0]
if _has_exif:
exif = GExiv2.Metadata(filename)
# Save
pixbuf.savev(filename, extension, [], [])
if _has_exif and exif.get_supports_exif():
if update_orientation_tag:
exif.set_orientation(GExiv2.Orientation.NORMAL)
exif.save_file()
示例9: enhance_bc
# 需要導入模塊: from gi.repository import GdkPixbuf [as 別名]
# 或者: from gi.repository.GdkPixbuf import Pixbuf [as 別名]
def enhance_bc(pixbuf, brightness, contrast):
"""Enhance brightness and contrast of a GdkPixbuf.Pixbuf.
Args:
pixbuf: Original GdkPixbuf.Pixbuf to work with.
brightness: Float between -1.0 and 1.0 to change brightness.
contrast: Float between -1.0 and 1.0 to change contrast.
Return:
The enhanced GdkPixbuf.Pixbuf
"""
data = pixbuf.get_pixels()
has_alpha = pixbuf.get_has_alpha()
c_has_alpha = 1 if has_alpha else 0 # Numbers are easier for C
# Update plain bytes using C extension
# Pylint does not read this properly
# pylint: disable=no-member
data = _image_enhance.enhance_bc(data, c_has_alpha, brightness, contrast)
gdata = GLib.Bytes.new(data)
return GdkPixbuf.Pixbuf.new_from_bytes(gdata,
pixbuf.get_colorspace(),
has_alpha,
pixbuf.get_bits_per_sample(),
pixbuf.get_width(),
pixbuf.get_height(),
pixbuf.get_rowstride())
示例10: createCombo
# 需要導入模塊: from gi.repository import GdkPixbuf [as 別名]
# 或者: from gi.repository.GdkPixbuf import Pixbuf [as 別名]
def createCombo(combo, data=[], name=None, ellipsize_mode=None):
if name is not None:
combo.set_name(name)
lst_store = Gtk.ListStore(Pixbuf, str)
for row in data:
lst_store.append(row)
combo.clear()
combo.set_model(lst_store)
crp = Gtk.CellRendererPixbuf()
crp.set_property('xalign', 0)
crp.set_property('xpad', 2)
combo.pack_start(crp, False)
combo.add_attribute(crp, 'pixbuf', 0)
crt = Gtk.CellRendererText()
crt.set_property('xalign', 0)
crt.set_property('xpad', 4)
combo.pack_start(crt, True)
combo.add_attribute(crt, 'text', 1)
if ellipsize_mode is not None:
crt.set_property('ellipsize', ellipsize_mode)
示例11: __init__
# 需要導入模塊: from gi.repository import GdkPixbuf [as 別名]
# 或者: from gi.repository.GdkPixbuf import Pixbuf [as 別名]
def __init__(self, database, host, *args, **kwargs):
super(PortsTree, self).__init__(*args, **kwargs)
""" Single host ports treeview class """
self.set_model(Gtk.ListStore(GdkPixbuf.Pixbuf, int, str, str, str, str, str, int))
self.port_liststore = self.get_model()
for i, column_title in enumerate(["#","Port", "State", "Type", "Service", "Banner", "Fingerprint"]):
if i == 0:
renderer = Gtk.CellRendererPixbuf()
column = Gtk.TreeViewColumn(column_title, renderer, pixbuf=0)
else:
renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(column_title, renderer, text=i)
self.append_column(column)
self.show_all()
self.database = database
self.host = host
self.refresh(self.database, self.host)
示例12: display_song_album_art_callback
# 需要導入模塊: from gi.repository import GdkPixbuf [as 別名]
# 或者: from gi.repository.GdkPixbuf import Pixbuf [as 別名]
def display_song_album_art_callback(self, *args):
# key, filename, data, entry):
"""
RBExtDB signal callback to display the album-art
"""
# rhythmbox 3.2 breaks the API - need to find the parameter with the
# pixbuf
data = None
for data in args:
if isinstance(data, GdkPixbuf.Pixbuf):
break
if ((data is not None) and (isinstance(data, GdkPixbuf.Pixbuf))):
self.cover_pixbuf = data
scale_cover = \
self.cover_pixbuf.scale_simple(34, 34,
GdkPixbuf.InterpType.HYPER)
self.album_cover.set_from_pixbuf(scale_cover)
else:
self.cover_pixbuf = None
self.album_cover.clear()
self.album_cover.trigger_tooltip_query()
示例13: test_get_from_name_load_icon_exception
# 需要導入模塊: from gi.repository import GdkPixbuf [as 別名]
# 或者: from gi.repository.GdkPixbuf import Pixbuf [as 別名]
def test_get_from_name_load_icon_exception(self):
"""On exception `load_icon()` should be called again."""
m_pixbuf = mock.Mock(spec=GdkPixbuf.Pixbuf, get_height=lambda: DEFAULT_SIZE)
with patch_load_icon(side_effect=[Exception, m_pixbuf]) as m_load_icon, patch_log() as m_log:
m_load_icon.return_value.scale_simple.return_value = m_pixbuf
pixbuf = get_from_name()
self.assertEqual(
m_load_icon.call_args_list,
[mock.call("gtk-execute", 24, 0), mock.call("gtk-execute", 24, 0)]
)
self.assertEqual(m_log.warning.call_count, 1)
self.assertEqual(m_log.error.call_count, 0)
self.assertEqual(pixbuf, m_pixbuf)
# more than one exception would fallback to random alter icon loading
with patch_load_icon(side_effect=[Exception, Exception, m_pixbuf]) as m_load_icon, patch_log() as m_log:
m_load_icon.return_value.scale_simple.return_value = m_pixbuf
pixbuf = get_from_name()
self.assertEqual(
m_load_icon.call_args_list,
[mock.call("gtk-execute", 24, 0), mock.call("gtk-execute", 24, 0), mock.call(mock.ANY, 24, 0)]
)
self.assertEqual(m_log.warning.call_count, 1)
self.assertEqual(m_log.error.call_count, 1)
self.assertEqual(pixbuf, m_pixbuf)
示例14: test_get_from_list
# 需要導入模塊: from gi.repository import GdkPixbuf [as 別名]
# 或者: from gi.repository.GdkPixbuf import Pixbuf [as 別名]
def test_get_from_list(self):
"""Only the last working pixbuf loaded should be returned."""
m_pixbuf = mock.Mock(spec=GdkPixbuf.Pixbuf, get_height=lambda: DEFAULT_SIZE)
names = ("icon-name1", "icon-name2")
size = 1234
with patch_load_icon() as m_load_icon, patch_log() as m_log, patch_get_from_name() as m_get_from_name:
m_load_icon.side_effect = [None, m_pixbuf]
pixbuf = get_from_list(names, size)
self.assertEqual(
m_load_icon.call_args_list, [
mock.call("icon-name1", size, Gtk.IconLookupFlags.USE_BUILTIN),
mock.call("icon-name2", size, Gtk.IconLookupFlags.USE_BUILTIN)
]
)
self.assertEqual(m_log.method_calls, [])
self.assertEqual(m_get_from_name.call_args_list, [])
self.assertEqual(pixbuf, m_pixbuf)
示例15: test_get_from_list_exception
# 需要導入模塊: from gi.repository import GdkPixbuf [as 別名]
# 或者: from gi.repository.GdkPixbuf import Pixbuf [as 別名]
def test_get_from_list_exception(self):
"""On exception the next pixbuf is returned."""
m_pixbuf = mock.Mock(spec=GdkPixbuf.Pixbuf, get_height=lambda: DEFAULT_SIZE)
names = ("icon-name1", "icon-name2")
size = 1234
with patch_load_icon() as m_load_icon, patch_log() as m_log, patch_get_from_name() as m_get_from_name:
m_load_icon.side_effect = [Exception, m_pixbuf]
pixbuf = get_from_list(names, size)
self.assertEqual(
m_load_icon.call_args_list, [
mock.call("icon-name1", size, Gtk.IconLookupFlags.USE_BUILTIN),
mock.call("icon-name2", size, Gtk.IconLookupFlags.USE_BUILTIN)
]
)
self.assertEqual(
m_log.method_calls,
[mock.call.warning('get_from_list for icon-name1 failed, try next')]
)
self.assertEqual(m_get_from_name.call_args_list, [])
self.assertEqual(pixbuf, m_pixbuf)