本文整理汇总了Python中sugar3.graphics.style.zoom函数的典型用法代码示例。如果您正苦于以下问题:Python zoom函数的具体用法?Python zoom怎么用?Python zoom使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zoom函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_preview_data
def _get_preview_data(screenshot_surface):
screenshot_width = screenshot_surface.get_width()
screenshot_height = screenshot_surface.get_height()
preview_width, preview_height = style.zoom(300), style.zoom(225)
preview_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
preview_width, preview_height)
cr = cairo.Context(preview_surface)
scale_w = preview_width * 1.0 / screenshot_width
scale_h = preview_height * 1.0 / screenshot_height
scale = min(scale_w, scale_h)
translate_x = int((preview_width - (screenshot_width * scale)) / 2)
translate_y = int((preview_height - (screenshot_height * scale)) / 2)
cr.translate(translate_x, translate_y)
cr.scale(scale, scale)
cr.set_source_rgba(1, 1, 1, 0)
cr.set_operator(cairo.OPERATOR_SOURCE)
cr.paint()
cr.set_source_surface(screenshot_surface)
cr.paint()
preview_str = StringIO.StringIO()
preview_surface.write_to_png(preview_str)
return dbus.ByteArray(preview_str.getvalue())
示例2: set_empty_image
def set_empty_image(self, page, fill='#0000ff', stroke='#4d4c4f'):
img = Gtk.Image()
bg_width, bg_height = style.zoom(120), style.zoom(110)
bg_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, bg_width,
bg_height)
context = cairo.Context(bg_surface)
# draw a rectangle in the background with the selected colors
context.set_line_width(style.zoom(10))
context.set_source_rgba(*style.Color(fill).get_rgba())
context.rectangle(0, 0, bg_width, bg_height)
context.fill_preserve()
context.set_source_rgba(*style.Color(stroke).get_rgba())
context.stroke()
# add the page number
context.set_font_size(style.zoom(60))
text = str(page)
x, y = bg_width / 2, bg_height / 2
xbearing, ybearing, width, height, xadvance, yadvance = \
context.text_extents(text)
context.move_to(x - width / 2, y + height / 2)
context.show_text(text)
context.stroke()
pixbuf_bg = Gdk.pixbuf_get_from_surface(bg_surface, 0, 0,
bg_width, bg_height)
img.set_from_pixbuf(pixbuf_bg)
self.set_icon_widget(img)
img.show()
示例3: _get_preview_image
def _get_preview_image(self, file_name):
preview_width, preview_height = style.zoom(300), style.zoom(225)
pixbuf = GdkPixbuf.Pixbuf.new_from_file(file_name)
width, height = pixbuf.get_width(), pixbuf.get_height()
scale = 1
if (width > preview_width) or (height > preview_height):
scale_x = preview_width / float(width)
scale_y = preview_height / float(height)
scale = min(scale_x, scale_y)
pixbuf2 = GdkPixbuf.Pixbuf.new(
GdkPixbuf.Colorspace.RGB, pixbuf.get_has_alpha(),
pixbuf.get_bits_per_sample(), preview_width, preview_height)
pixbuf2.fill(style.COLOR_WHITE.get_int())
margin_x = int((preview_width - (width * scale)) / 2)
margin_y = int((preview_height - (height * scale)) / 2)
pixbuf.scale(pixbuf2, margin_x, margin_y,
preview_width - (margin_x * 2),
preview_height - (margin_y * 2),
margin_x, margin_y, scale, scale,
GdkPixbuf.InterpType.BILINEAR)
succes, preview_data = pixbuf2.save_to_bufferv('png', [], [])
return dbus.ByteArray(preview_data)
示例4: hide_thumb
def hide_thumb(self):
xo_buddy = os.path.join(os.path.dirname(__file__), "icons/link.svg")
bg_surface = self._read_link_background(xo_buddy)
bg_width, bg_height = style.zoom(120), style.zoom(110)
pixbuf = Gdk.pixbuf_get_from_surface(bg_surface, 0, 0,
bg_width, bg_height)
self._img.set_from_pixbuf(pixbuf)
示例5: get_preview
def get_preview(self):
"""Returns an image representing the state of the activity. Generally
this is what the user is seeing in this moment.
Activities can override this method, which should return a str with the
binary content of a png image with a width of 300 and a height of 225
pixels.
The method does create a cairo surface similar to that of the canvas'
window and draws on that. Then we create a cairo image surface with
the desired preview size and scale the canvas surface on that.
"""
if self.canvas is None or not hasattr(self.canvas, 'get_window'):
return None
window = self.canvas.get_window()
alloc = self.canvas.get_allocation()
dummy_cr = Gdk.cairo_create(window)
target = dummy_cr.get_target()
canvas_width, canvas_height = alloc.width, alloc.height
screenshot_surface = target.create_similar(cairo.CONTENT_COLOR,
canvas_width, canvas_height)
del dummy_cr, target
cr = cairo.Context(screenshot_surface)
r, g, b, a_ = style.COLOR_PANEL_GREY.get_rgba()
cr.set_source_rgb(r, g, b)
cr.paint()
self.canvas.draw(cr)
del cr
preview_width, preview_height = style.zoom(300), style.zoom(225)
preview_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
preview_width, preview_height)
cr = cairo.Context(preview_surface)
scale_w = preview_width * 1.0 / canvas_width
scale_h = preview_height * 1.0 / canvas_height
scale = min(scale_w, scale_h)
translate_x = int((preview_width - (canvas_width * scale)) / 2)
translate_y = int((preview_height - (canvas_height * scale)) / 2)
cr.translate(translate_x, translate_y)
cr.scale(scale, scale)
cr.set_source_rgba(1, 1, 1, 0)
cr.set_operator(cairo.OPERATOR_SOURCE)
cr.paint()
cr.set_source_surface(screenshot_surface)
cr.paint()
preview_str = StringIO.StringIO()
preview_surface.write_to_png(preview_str)
return preview_str.getvalue()
示例6: __expose_cb
def __expose_cb(self, widget, cr):
rect = self.get_allocation()
hmargin = style.zoom(15)
x = hmargin
y = 0
width = rect.width - _BORDER_DEFAULT * 2. - hmargin * 2
if self.tail is not None:
height = rect.height - _BORDER_DEFAULT * 2. - self._radius
else:
height = rect.height - _BORDER_DEFAULT * 2.
cr.move_to(x + self._radius, y)
cr.arc(x + width - self._radius, y + self._radius,
self._radius, math.pi * 1.5, math.pi * 2)
tail_height = style.zoom(5)
if self.tail == 'right':
cr.arc(x + width - self._radius, y + height - self._radius * 2,
self._radius, 0, math.pi * 0.5)
cr.line_to(x + width - self._radius, y + height)
cr.line_to(x + width - tail_height * self._radius,
y + height - self._radius)
cr.arc(x + self._radius, y + height - self._radius * 2,
self._radius, math.pi * 0.5, math.pi)
elif self.tail == 'left':
cr.arc(x + width - self._radius, y + height - self._radius * 2,
self._radius, 0, math.pi * 0.5)
cr.line_to(x + self._radius * tail_height,
y + height - self._radius)
cr.line_to(x + self._radius, y + height)
cr.line_to(x + self._radius, y + height - self._radius)
cr.arc(x + self._radius, y + height - self._radius * 2,
self._radius, math.pi * 0.5, math.pi)
else:
cr.arc(x + width - self._radius, y + height - self._radius,
self._radius, 0, math.pi * 0.5)
cr.arc(x + self._radius, y + height - self._radius,
self._radius, math.pi * 0.5, math.pi)
cr.arc(x + self._radius, y + self._radius, self._radius,
math.pi, math.pi * 1.5)
cr.close_path()
if self.background_color is not None:
r, g, b, __ = self.background_color.get_rgba()
cr.set_source_rgb(r, g, b)
cr.fill_preserve()
if self.border_color is not None:
r, g, b, __ = self.border_color.get_rgba()
cr.set_source_rgb(r, g, b)
cr.set_line_width(_BORDER_DEFAULT)
cr.stroke()
return False
示例7: create_preview_metadata
def create_preview_metadata(self, filename):
file_mimetype = mime.get_for_file(filename)
if not file_mimetype.startswith('image/'):
return ''
scaled_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(filename,
style.zoom(320), style.zoom(240))
preview_data = []
succes, preview_data = scaled_pixbuf.save_to_bufferv('png', [], [])
preview_data = ''.join(preview_data)
return preview_data
示例8: __init__
def __init__(self, start_on_age_page):
Gtk.VBox.__init__(self)
self.set_border_width(style.zoom(30))
self._page = self.PAGE_NAME
self._name_page = _NamePage(self)
self._color_page = _ColorPage()
self._gender_page = _GenderPage()
self._age_page = _AgePage(None)
self._current_page = None
self._next_button = None
settings = Gio.Settings('org.sugarlabs.user')
default_nick = settings.get_string('default-nick')
if default_nick != 'disabled':
self._page = self.PAGE_COLOR
if default_nick == 'system':
pwd_entry = pwd.getpwuid(os.getuid())
default_nick = (pwd_entry.pw_gecos.split(',')[0] or
pwd_entry.pw_name)
self._name_page.set_name(default_nick)
# XXX should also consider whether or not there is a nick
nick = settings.get_string('nick')
if start_on_age_page and nick:
self._page = self.PAGE_AGE
self._setup_page()
示例9: __init__
def __init__(self, primary_text):
Palette.__init__(self, primary_text)
self._level = 0
self._time = 0
self._status = _STATUS_NOT_PRESENT
self._warning_capacity = _settings_get('warning-capacity')
self._progress_widget = PaletteMenuBox()
self.set_content(self._progress_widget)
self._progress_widget.show()
inner_box = Gtk.VBox()
inner_box.set_spacing(style.DEFAULT_PADDING)
self._progress_widget.append_item(inner_box, vertical_padding=0)
inner_box.show()
self._progress_bar = Gtk.ProgressBar()
self._progress_bar.set_size_request(
style.zoom(style.GRID_CELL_SIZE * 4), -1)
inner_box.pack_start(self._progress_bar, True, True, 0)
self._progress_bar.show()
self._status_label = Gtk.Label()
inner_box.pack_start(self._status_label, True, True, 0)
self._status_label.show()
示例10: __init__
def __init__(self, handle):
"The entry point to the Activity"
global page
activity.Activity.__init__(self, handle)
toolbox = widgets.ActivityToolbar(self)
toolbox.share.props.visible = False
stop_button = StopButton(self)
stop_button.show()
toolbox.insert(stop_button, -1)
self.set_toolbar_box(toolbox)
toolbox.show()
self.scrolled_window = Gtk.ScrolledWindow()
self.scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
self.textview = Gtk.TextView()
self.textview.set_editable(False)
self.textview.set_cursor_visible(False)
self.textview.set_left_margin(50)
self.textview.connect("key_press_event", self.keypress_cb)
self.scrolled_window.add(self.textview)
self.set_canvas(self.scrolled_window)
self.textview.show()
self.scrolled_window.show()
page = 0
self.textview.grab_focus()
self.font_desc = Pango.FontDescription("sans %d" % style.zoom(10))
self.textview.modify_font(self.font_desc)
示例11: get_preview
def get_preview(self):
if not hasattr(self.abiword_canvas, 'render_page_to_image'):
return activity.Activity.get_preview(self)
pixbuf = self.abiword_canvas.render_page_to_image(1)
pixbuf = pixbuf.scale_simple(style.zoom(300), style.zoom(225),
GdkPixbuf.InterpType.BILINEAR)
preview_data = []
def save_func(buf, data):
data.append(buf)
##pixbuf.save_to_callback(save_func, 'png', user_data=preview_data)
preview_data = ''.join(preview_data)
return preview_data
示例12: update_preview_cb
def update_preview_cb(self, file_chooser, preview):
filename = file_chooser.get_preview_filename()
try:
file_mimetype = mime.get_for_file(filename)
if file_mimetype == 'application/x-cbz' or file_mimetype == 'application/zip':
fname = self.extract_image(filename)
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(fname,
style.zoom(320), style.zoom(240))
preview.set_from_pixbuf(pixbuf)
have_preview = True
os.remove(fname)
else:
have_preview = False
except:
have_preview = False
file_chooser.set_preview_widget_active(have_preview)
return
示例13: set_image
def set_image(self, buf, fill='#0000ff', stroke='#4d4c4f'):
img = Gtk.Image()
str_buf = StringIO.StringIO(buf)
thumb_surface = cairo.ImageSurface.create_from_png(str_buf)
bg_width, bg_height = style.zoom(120), style.zoom(110)
bg_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, bg_width,
bg_height)
context = cairo.Context(bg_surface)
# draw a rectangle in the background with the selected colors
context.set_line_width(style.zoom(10))
context.set_source_rgba(*style.Color(fill).get_rgba())
context.rectangle(0, 0, bg_width, bg_height)
context.fill_preserve()
context.set_source_rgba(*style.Color(stroke).get_rgba())
context.stroke()
# add the screenshot
dest_x = style.zoom(10)
dest_y = style.zoom(20)
context.set_source_surface(thumb_surface, dest_x, dest_y)
thumb_width, thumb_height = style.zoom(100), style.zoom(80)
context.rectangle(dest_x, dest_y, thumb_width, thumb_height)
context.fill()
pixbuf_bg = Gdk.pixbuf_get_from_surface(bg_surface, 0, 0,
bg_width, bg_height)
img.set_from_pixbuf(pixbuf_bg)
self.set_icon_widget(img)
img.show()
示例14: __init__
def __init__(self):
self._palette_invoker = ToolInvoker()
Gtk.ToolItem.__init__(self)
self._font_label = FontLabel()
bt = Gtk.Button('')
bt.set_can_focus(False)
bt.remove(bt.get_children()[0])
box = Gtk.HBox()
bt.add(box)
icon = Icon(icon_name='font-text')
box.pack_start(icon, False, False, 10)
box.pack_start(self._font_label, False, False, 10)
self.add(bt)
self.show_all()
self._font_name = 'Sans'
# theme the button, can be removed if add the style to the sugar css
if style.zoom(100) == 100:
subcell_size = 15
else:
subcell_size = 11
radius = 2 * subcell_size
theme = "GtkButton {border-radius: %dpx;}" % radius
css_provider = Gtk.CssProvider()
css_provider.load_from_data(theme)
style_context = bt.get_style_context()
style_context.add_provider(css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_USER)
# init palette
self._hide_tooltip_on_click = True
self._palette_invoker.attach_tool(self)
self._palette_invoker.props.toggle_palette = True
self.palette = Palette(_('Select font'))
self.palette.set_invoker(self._palette_invoker)
# load the fonts in the palette menu
self._menu_box = PaletteMenuBox()
self.props.palette.set_content(self._menu_box)
self._menu_box.show()
context = self.get_pango_context()
self._init_font_list()
tmp_list = []
for family in context.list_families():
name = family.get_name()
if name in self._font_white_list:
tmp_list.append(name)
for name in sorted(tmp_list):
self._add_menu(name, self.__font_selected_cb)
self._font_label.set_font(self._font_name)
示例15: __init__
def __init__(self, **kwargs):
Gtk.HBox.__init__(self, **kwargs)
self._radius = style.zoom(10)
self.border = self._BORDER_DEFAULT
self.border_color = style.COLOR_BLACK
self.background_color = None
self.connect("draw", self.__draw_cb)
self.connect("size-allocate", self.__size_allocate_cb)
self.connect("add", self.__add_cb)