repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
rkhleics/wagtailmenus | wagtailmenus/models/pages.py | MenuPageMixin.get_text_for_repeated_menu_item | def get_text_for_repeated_menu_item(
self, request=None, current_site=None, original_menu_tag='', **kwargs
):
"""Return the a string to use as 'text' for this page when it is being
included as a 'repeated' menu item in a menu. You might want to
override this method if you're creating... | python | def get_text_for_repeated_menu_item(
self, request=None, current_site=None, original_menu_tag='', **kwargs
):
"""Return the a string to use as 'text' for this page when it is being
included as a 'repeated' menu item in a menu. You might want to
override this method if you're creating... | [
"def",
"get_text_for_repeated_menu_item",
"(",
"self",
",",
"request",
"=",
"None",
",",
"current_site",
"=",
"None",
",",
"original_menu_tag",
"=",
"''",
",",
"**",
"kwargs",
")",
":",
"source_field_name",
"=",
"settings",
".",
"PAGE_FIELD_FOR_MENU_ITEM_TEXT",
"r... | Return the a string to use as 'text' for this page when it is being
included as a 'repeated' menu item in a menu. You might want to
override this method if you're creating a multilingual site and you
have different translations of 'repeated_item_text' that you wish to
surface. | [
"Return",
"the",
"a",
"string",
"to",
"use",
"as",
"text",
"for",
"this",
"page",
"when",
"it",
"is",
"being",
"included",
"as",
"a",
"repeated",
"menu",
"item",
"in",
"a",
"menu",
".",
"You",
"might",
"want",
"to",
"override",
"this",
"method",
"if",
... | a41f240bed0d362e0d4dd4ef04a230f2b1827a93 | https://github.com/rkhleics/wagtailmenus/blob/a41f240bed0d362e0d4dd4ef04a230f2b1827a93/wagtailmenus/models/pages.py#L82-L93 | train |
rkhleics/wagtailmenus | wagtailmenus/models/pages.py | MenuPageMixin.get_repeated_menu_item | def get_repeated_menu_item(
self, current_page, current_site, apply_active_classes,
original_menu_tag, request=None, use_absolute_page_urls=False,
):
"""Return something that can be used to display a 'repeated' menu item
for this specific page."""
menuitem = copy(self)
... | python | def get_repeated_menu_item(
self, current_page, current_site, apply_active_classes,
original_menu_tag, request=None, use_absolute_page_urls=False,
):
"""Return something that can be used to display a 'repeated' menu item
for this specific page."""
menuitem = copy(self)
... | [
"def",
"get_repeated_menu_item",
"(",
"self",
",",
"current_page",
",",
"current_site",
",",
"apply_active_classes",
",",
"original_menu_tag",
",",
"request",
"=",
"None",
",",
"use_absolute_page_urls",
"=",
"False",
",",
")",
":",
"menuitem",
"=",
"copy",
"(",
... | Return something that can be used to display a 'repeated' menu item
for this specific page. | [
"Return",
"something",
"that",
"can",
"be",
"used",
"to",
"display",
"a",
"repeated",
"menu",
"item",
"for",
"this",
"specific",
"page",
"."
] | a41f240bed0d362e0d4dd4ef04a230f2b1827a93 | https://github.com/rkhleics/wagtailmenus/blob/a41f240bed0d362e0d4dd4ef04a230f2b1827a93/wagtailmenus/models/pages.py#L95-L126 | train |
rkhleics/wagtailmenus | wagtailmenus/models/pages.py | AbstractLinkPage.menu_text | def menu_text(self, request=None):
"""Return a string to use as link text when this page appears in
menus."""
source_field_name = settings.PAGE_FIELD_FOR_MENU_ITEM_TEXT
if(
source_field_name != 'menu_text' and
hasattr(self, source_field_name)
):
... | python | def menu_text(self, request=None):
"""Return a string to use as link text when this page appears in
menus."""
source_field_name = settings.PAGE_FIELD_FOR_MENU_ITEM_TEXT
if(
source_field_name != 'menu_text' and
hasattr(self, source_field_name)
):
... | [
"def",
"menu_text",
"(",
"self",
",",
"request",
"=",
"None",
")",
":",
"source_field_name",
"=",
"settings",
".",
"PAGE_FIELD_FOR_MENU_ITEM_TEXT",
"if",
"(",
"source_field_name",
"!=",
"'menu_text'",
"and",
"hasattr",
"(",
"self",
",",
"source_field_name",
")",
... | Return a string to use as link text when this page appears in
menus. | [
"Return",
"a",
"string",
"to",
"use",
"as",
"link",
"text",
"when",
"this",
"page",
"appears",
"in",
"menus",
"."
] | a41f240bed0d362e0d4dd4ef04a230f2b1827a93 | https://github.com/rkhleics/wagtailmenus/blob/a41f240bed0d362e0d4dd4ef04a230f2b1827a93/wagtailmenus/models/pages.py#L184-L193 | train |
rkhleics/wagtailmenus | wagtailmenus/models/pages.py | AbstractLinkPage.link_page_is_suitable_for_display | def link_page_is_suitable_for_display(
self, request=None, current_site=None, menu_instance=None,
original_menu_tag=''
):
"""
Like menu items, link pages linking to pages should only be included
in menus when the target page is live and is itself configured to
appear ... | python | def link_page_is_suitable_for_display(
self, request=None, current_site=None, menu_instance=None,
original_menu_tag=''
):
"""
Like menu items, link pages linking to pages should only be included
in menus when the target page is live and is itself configured to
appear ... | [
"def",
"link_page_is_suitable_for_display",
"(",
"self",
",",
"request",
"=",
"None",
",",
"current_site",
"=",
"None",
",",
"menu_instance",
"=",
"None",
",",
"original_menu_tag",
"=",
"''",
")",
":",
"if",
"self",
".",
"link_page",
":",
"if",
"(",
"not",
... | Like menu items, link pages linking to pages should only be included
in menus when the target page is live and is itself configured to
appear in menus. Returns a boolean indicating as much | [
"Like",
"menu",
"items",
"link",
"pages",
"linking",
"to",
"pages",
"should",
"only",
"be",
"included",
"in",
"menus",
"when",
"the",
"target",
"page",
"is",
"live",
"and",
"is",
"itself",
"configured",
"to",
"appear",
"in",
"menus",
".",
"Returns",
"a",
... | a41f240bed0d362e0d4dd4ef04a230f2b1827a93 | https://github.com/rkhleics/wagtailmenus/blob/a41f240bed0d362e0d4dd4ef04a230f2b1827a93/wagtailmenus/models/pages.py#L217-L233 | train |
rkhleics/wagtailmenus | wagtailmenus/models/pages.py | AbstractLinkPage.show_in_menus_custom | def show_in_menus_custom(self, request=None, current_site=None,
menu_instance=None, original_menu_tag=''):
"""
Return a boolean indicating whether this page should be included in
menus being rendered.
"""
if not self.show_in_menus:
return ... | python | def show_in_menus_custom(self, request=None, current_site=None,
menu_instance=None, original_menu_tag=''):
"""
Return a boolean indicating whether this page should be included in
menus being rendered.
"""
if not self.show_in_menus:
return ... | [
"def",
"show_in_menus_custom",
"(",
"self",
",",
"request",
"=",
"None",
",",
"current_site",
"=",
"None",
",",
"menu_instance",
"=",
"None",
",",
"original_menu_tag",
"=",
"''",
")",
":",
"if",
"not",
"self",
".",
"show_in_menus",
":",
"return",
"False",
... | Return a boolean indicating whether this page should be included in
menus being rendered. | [
"Return",
"a",
"boolean",
"indicating",
"whether",
"this",
"page",
"should",
"be",
"included",
"in",
"menus",
"being",
"rendered",
"."
] | a41f240bed0d362e0d4dd4ef04a230f2b1827a93 | https://github.com/rkhleics/wagtailmenus/blob/a41f240bed0d362e0d4dd4ef04a230f2b1827a93/wagtailmenus/models/pages.py#L235-L245 | train |
rkhleics/wagtailmenus | wagtailmenus/utils/inspection.py | accepts_kwarg | def accepts_kwarg(func, kwarg):
"""
Determine whether the callable `func` has a signature that accepts the
keyword argument `kwarg`
"""
signature = inspect.signature(func)
try:
signature.bind_partial(**{kwarg: None})
return True
except TypeError:
return False | python | def accepts_kwarg(func, kwarg):
"""
Determine whether the callable `func` has a signature that accepts the
keyword argument `kwarg`
"""
signature = inspect.signature(func)
try:
signature.bind_partial(**{kwarg: None})
return True
except TypeError:
return False | [
"def",
"accepts_kwarg",
"(",
"func",
",",
"kwarg",
")",
":",
"signature",
"=",
"inspect",
".",
"signature",
"(",
"func",
")",
"try",
":",
"signature",
".",
"bind_partial",
"(",
"**",
"{",
"kwarg",
":",
"None",
"}",
")",
"return",
"True",
"except",
"Typ... | Determine whether the callable `func` has a signature that accepts the
keyword argument `kwarg` | [
"Determine",
"whether",
"the",
"callable",
"func",
"has",
"a",
"signature",
"that",
"accepts",
"the",
"keyword",
"argument",
"kwarg"
] | a41f240bed0d362e0d4dd4ef04a230f2b1827a93 | https://github.com/rkhleics/wagtailmenus/blob/a41f240bed0d362e0d4dd4ef04a230f2b1827a93/wagtailmenus/utils/inspection.py#L10-L20 | train |
rkhleics/wagtailmenus | wagtailmenus/templatetags/menu_tags.py | section_menu | def section_menu(
context, show_section_root=True, show_multiple_levels=True,
apply_active_classes=True, allow_repeating_parents=True,
max_levels=settings.DEFAULT_SECTION_MENU_MAX_LEVELS,
template='', sub_menu_template='', sub_menu_templates=None,
use_specific=settings.DEFAULT_SECTION_MENU_USE_SPECI... | python | def section_menu(
context, show_section_root=True, show_multiple_levels=True,
apply_active_classes=True, allow_repeating_parents=True,
max_levels=settings.DEFAULT_SECTION_MENU_MAX_LEVELS,
template='', sub_menu_template='', sub_menu_templates=None,
use_specific=settings.DEFAULT_SECTION_MENU_USE_SPECI... | [
"def",
"section_menu",
"(",
"context",
",",
"show_section_root",
"=",
"True",
",",
"show_multiple_levels",
"=",
"True",
",",
"apply_active_classes",
"=",
"True",
",",
"allow_repeating_parents",
"=",
"True",
",",
"max_levels",
"=",
"settings",
".",
"DEFAULT_SECTION_M... | Render a section menu for the current section. | [
"Render",
"a",
"section",
"menu",
"for",
"the",
"current",
"section",
"."
] | a41f240bed0d362e0d4dd4ef04a230f2b1827a93 | https://github.com/rkhleics/wagtailmenus/blob/a41f240bed0d362e0d4dd4ef04a230f2b1827a93/wagtailmenus/templatetags/menu_tags.py#L84-L113 | train |
rkhleics/wagtailmenus | wagtailmenus/templatetags/menu_tags.py | sub_menu | def sub_menu(
context, menuitem_or_page, use_specific=None, allow_repeating_parents=None,
apply_active_classes=None, template='', use_absolute_page_urls=None,
add_sub_menus_inline=None, **kwargs
):
"""
Retrieve the children pages for the `menuitem_or_page` provided, turn them
into menu items, an... | python | def sub_menu(
context, menuitem_or_page, use_specific=None, allow_repeating_parents=None,
apply_active_classes=None, template='', use_absolute_page_urls=None,
add_sub_menus_inline=None, **kwargs
):
"""
Retrieve the children pages for the `menuitem_or_page` provided, turn them
into menu items, an... | [
"def",
"sub_menu",
"(",
"context",
",",
"menuitem_or_page",
",",
"use_specific",
"=",
"None",
",",
"allow_repeating_parents",
"=",
"None",
",",
"apply_active_classes",
"=",
"None",
",",
"template",
"=",
"''",
",",
"use_absolute_page_urls",
"=",
"None",
",",
"add... | Retrieve the children pages for the `menuitem_or_page` provided, turn them
into menu items, and render them to a template. | [
"Retrieve",
"the",
"children",
"pages",
"for",
"the",
"menuitem_or_page",
"provided",
"turn",
"them",
"into",
"menu",
"items",
"and",
"render",
"them",
"to",
"a",
"template",
"."
] | a41f240bed0d362e0d4dd4ef04a230f2b1827a93 | https://github.com/rkhleics/wagtailmenus/blob/a41f240bed0d362e0d4dd4ef04a230f2b1827a93/wagtailmenus/templatetags/menu_tags.py#L147-L200 | train |
opentracing-contrib/python-flask | flask_opentracing/tracing.py | FlaskTracing.trace | def trace(self, *attributes):
"""
Function decorator that traces functions
NOTE: Must be placed after the @app.route decorator
@param attributes any number of flask.Request attributes
(strings) to be set as tags on the created span
"""
def decorator(f):
... | python | def trace(self, *attributes):
"""
Function decorator that traces functions
NOTE: Must be placed after the @app.route decorator
@param attributes any number of flask.Request attributes
(strings) to be set as tags on the created span
"""
def decorator(f):
... | [
"def",
"trace",
"(",
"self",
",",
"*",
"attributes",
")",
":",
"def",
"decorator",
"(",
"f",
")",
":",
"def",
"wrapper",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"if",
"self",
".",
"_trace_all_requests",
":",
"return",
"f",
"(",
"*",
"args"... | Function decorator that traces functions
NOTE: Must be placed after the @app.route decorator
@param attributes any number of flask.Request attributes
(strings) to be set as tags on the created span | [
"Function",
"decorator",
"that",
"traces",
"functions"
] | 74bfe8bcd00eee9ce75a15c1634fda4c5d5f26ca | https://github.com/opentracing-contrib/python-flask/blob/74bfe8bcd00eee9ce75a15c1634fda4c5d5f26ca/flask_opentracing/tracing.py#L66-L93 | train |
opentracing-contrib/python-flask | flask_opentracing/tracing.py | FlaskTracing.get_span | def get_span(self, request=None):
"""
Returns the span tracing `request`, or the current request if
`request==None`.
If there is no such span, get_span returns None.
@param request the request to get the span from
"""
if request is None and stack.top:
... | python | def get_span(self, request=None):
"""
Returns the span tracing `request`, or the current request if
`request==None`.
If there is no such span, get_span returns None.
@param request the request to get the span from
"""
if request is None and stack.top:
... | [
"def",
"get_span",
"(",
"self",
",",
"request",
"=",
"None",
")",
":",
"if",
"request",
"is",
"None",
"and",
"stack",
".",
"top",
":",
"request",
"=",
"stack",
".",
"top",
".",
"request",
"scope",
"=",
"self",
".",
"_current_scopes",
".",
"get",
"(",... | Returns the span tracing `request`, or the current request if
`request==None`.
If there is no such span, get_span returns None.
@param request the request to get the span from | [
"Returns",
"the",
"span",
"tracing",
"request",
"or",
"the",
"current",
"request",
"if",
"request",
"==",
"None",
"."
] | 74bfe8bcd00eee9ce75a15c1634fda4c5d5f26ca | https://github.com/opentracing-contrib/python-flask/blob/74bfe8bcd00eee9ce75a15c1634fda4c5d5f26ca/flask_opentracing/tracing.py#L95-L108 | train |
rsinger86/django-lifecycle | django_lifecycle/__init__.py | LifecycleModelMixin.initial_value | def initial_value(self, field_name: str = None):
"""
Get initial value of field when model was instantiated.
"""
if self._meta.get_field(field_name).get_internal_type() == 'ForeignKey':
if not field_name.endswith('_id'):
field_name = field_name+'_id'
... | python | def initial_value(self, field_name: str = None):
"""
Get initial value of field when model was instantiated.
"""
if self._meta.get_field(field_name).get_internal_type() == 'ForeignKey':
if not field_name.endswith('_id'):
field_name = field_name+'_id'
... | [
"def",
"initial_value",
"(",
"self",
",",
"field_name",
":",
"str",
"=",
"None",
")",
":",
"if",
"self",
".",
"_meta",
".",
"get_field",
"(",
"field_name",
")",
".",
"get_internal_type",
"(",
")",
"==",
"'ForeignKey'",
":",
"if",
"not",
"field_name",
"."... | Get initial value of field when model was instantiated. | [
"Get",
"initial",
"value",
"of",
"field",
"when",
"model",
"was",
"instantiated",
"."
] | 2196908ef0e242e52aab5bfaa3d337930700c106 | https://github.com/rsinger86/django-lifecycle/blob/2196908ef0e242e52aab5bfaa3d337930700c106/django_lifecycle/__init__.py#L94-L107 | train |
rsinger86/django-lifecycle | django_lifecycle/__init__.py | LifecycleModelMixin.has_changed | def has_changed(self, field_name: str = None) -> bool:
"""
Check if a field has changed since the model was instantiated.
"""
changed = self._diff_with_initial.keys()
if self._meta.get_field(field_name).get_internal_type() == 'ForeignKey':
if not field_name.endswith(... | python | def has_changed(self, field_name: str = None) -> bool:
"""
Check if a field has changed since the model was instantiated.
"""
changed = self._diff_with_initial.keys()
if self._meta.get_field(field_name).get_internal_type() == 'ForeignKey':
if not field_name.endswith(... | [
"def",
"has_changed",
"(",
"self",
",",
"field_name",
":",
"str",
"=",
"None",
")",
"->",
"bool",
":",
"changed",
"=",
"self",
".",
"_diff_with_initial",
".",
"keys",
"(",
")",
"if",
"self",
".",
"_meta",
".",
"get_field",
"(",
"field_name",
")",
".",
... | Check if a field has changed since the model was instantiated. | [
"Check",
"if",
"a",
"field",
"has",
"changed",
"since",
"the",
"model",
"was",
"instantiated",
"."
] | 2196908ef0e242e52aab5bfaa3d337930700c106 | https://github.com/rsinger86/django-lifecycle/blob/2196908ef0e242e52aab5bfaa3d337930700c106/django_lifecycle/__init__.py#L109-L122 | train |
rsinger86/django-lifecycle | django_lifecycle/__init__.py | LifecycleModelMixin._descriptor_names | def _descriptor_names(self):
"""
Attributes which are Django descriptors. These represent a field
which is a one-to-many or many-to-many relationship that is
potentially defined in another model, and doesn't otherwise appear
as a field on this model.
"""
descript... | python | def _descriptor_names(self):
"""
Attributes which are Django descriptors. These represent a field
which is a one-to-many or many-to-many relationship that is
potentially defined in another model, and doesn't otherwise appear
as a field on this model.
"""
descript... | [
"def",
"_descriptor_names",
"(",
"self",
")",
":",
"descriptor_names",
"=",
"[",
"]",
"for",
"name",
"in",
"dir",
"(",
"self",
")",
":",
"try",
":",
"attr",
"=",
"getattr",
"(",
"type",
"(",
"self",
")",
",",
"name",
")",
"if",
"isinstance",
"(",
"... | Attributes which are Django descriptors. These represent a field
which is a one-to-many or many-to-many relationship that is
potentially defined in another model, and doesn't otherwise appear
as a field on this model. | [
"Attributes",
"which",
"are",
"Django",
"descriptors",
".",
"These",
"represent",
"a",
"field",
"which",
"is",
"a",
"one",
"-",
"to",
"-",
"many",
"or",
"many",
"-",
"to",
"-",
"many",
"relationship",
"that",
"is",
"potentially",
"defined",
"in",
"another"... | 2196908ef0e242e52aab5bfaa3d337930700c106 | https://github.com/rsinger86/django-lifecycle/blob/2196908ef0e242e52aab5bfaa3d337930700c106/django_lifecycle/__init__.py#L181-L201 | train |
rsinger86/django-lifecycle | django_lifecycle/__init__.py | LifecycleModelMixin._run_hooked_methods | def _run_hooked_methods(self, hook: str):
"""
Iterate through decorated methods to find those that should be
triggered by the current hook. If conditions exist, check them before
running otherwise go ahead and run.
"""
for method in self._potentially_hooked_me... | python | def _run_hooked_methods(self, hook: str):
"""
Iterate through decorated methods to find those that should be
triggered by the current hook. If conditions exist, check them before
running otherwise go ahead and run.
"""
for method in self._potentially_hooked_me... | [
"def",
"_run_hooked_methods",
"(",
"self",
",",
"hook",
":",
"str",
")",
":",
"for",
"method",
"in",
"self",
".",
"_potentially_hooked_methods",
":",
"for",
"callback_specs",
"in",
"method",
".",
"_hooked",
":",
"if",
"callback_specs",
"[",
"'hook'",
"]",
"!... | Iterate through decorated methods to find those that should be
triggered by the current hook. If conditions exist, check them before
running otherwise go ahead and run. | [
"Iterate",
"through",
"decorated",
"methods",
"to",
"find",
"those",
"that",
"should",
"be",
"triggered",
"by",
"the",
"current",
"hook",
".",
"If",
"conditions",
"exist",
"check",
"them",
"before",
"running",
"otherwise",
"go",
"ahead",
"and",
"run",
"."
] | 2196908ef0e242e52aab5bfaa3d337930700c106 | https://github.com/rsinger86/django-lifecycle/blob/2196908ef0e242e52aab5bfaa3d337930700c106/django_lifecycle/__init__.py#L228-L245 | train |
llimllib/limbo | limbo/limbo.py | loop | def loop(server, test_loop=None):
"""Run the main loop
server is a limbo Server object
test_loop, if present, is a number of times to run the loop
"""
try:
loops_without_activity = 0
while test_loop is None or test_loop > 0:
start = time.time()
loops_without_... | python | def loop(server, test_loop=None):
"""Run the main loop
server is a limbo Server object
test_loop, if present, is a number of times to run the loop
"""
try:
loops_without_activity = 0
while test_loop is None or test_loop > 0:
start = time.time()
loops_without_... | [
"def",
"loop",
"(",
"server",
",",
"test_loop",
"=",
"None",
")",
":",
"try",
":",
"loops_without_activity",
"=",
"0",
"while",
"test_loop",
"is",
"None",
"or",
"test_loop",
">",
"0",
":",
"start",
"=",
"time",
".",
"time",
"(",
")",
"loops_without_activ... | Run the main loop
server is a limbo Server object
test_loop, if present, is a number of times to run the loop | [
"Run",
"the",
"main",
"loop"
] | f0980f20f733b670debcae454b167da32c57a044 | https://github.com/llimllib/limbo/blob/f0980f20f733b670debcae454b167da32c57a044/limbo/limbo.py#L189-L258 | train |
llimllib/limbo | limbo/slack.py | SlackClient.post_message | def post_message(self, channel_id, message, **kwargs):
"""
Send a message using the slack Event API.
Event messages should be used for more complex messages. See
https://api.slack.com/methods/chat.postMessage for details on arguments can be included
with your message.
W... | python | def post_message(self, channel_id, message, **kwargs):
"""
Send a message using the slack Event API.
Event messages should be used for more complex messages. See
https://api.slack.com/methods/chat.postMessage for details on arguments can be included
with your message.
W... | [
"def",
"post_message",
"(",
"self",
",",
"channel_id",
",",
"message",
",",
"**",
"kwargs",
")",
":",
"params",
"=",
"{",
"\"post_data\"",
":",
"{",
"\"text\"",
":",
"message",
",",
"\"channel\"",
":",
"channel_id",
",",
"}",
"}",
"params",
"[",
"\"post_... | Send a message using the slack Event API.
Event messages should be used for more complex messages. See
https://api.slack.com/methods/chat.postMessage for details on arguments can be included
with your message.
When using the post_message API, to have your message look like it's sent fr... | [
"Send",
"a",
"message",
"using",
"the",
"slack",
"Event",
"API",
"."
] | f0980f20f733b670debcae454b167da32c57a044 | https://github.com/llimllib/limbo/blob/f0980f20f733b670debcae454b167da32c57a044/limbo/slack.py#L99-L119 | train |
llimllib/limbo | limbo/slack.py | SlackClient.post_reaction | def post_reaction(self, channel_id, timestamp, reaction_name, **kwargs):
"""
Send a reaction to a message using slack Event API
"""
params = {
"post_data": {
"name": reaction_name,
"channel": channel_id,
"timestamp": timestamp,
... | python | def post_reaction(self, channel_id, timestamp, reaction_name, **kwargs):
"""
Send a reaction to a message using slack Event API
"""
params = {
"post_data": {
"name": reaction_name,
"channel": channel_id,
"timestamp": timestamp,
... | [
"def",
"post_reaction",
"(",
"self",
",",
"channel_id",
",",
"timestamp",
",",
"reaction_name",
",",
"**",
"kwargs",
")",
":",
"params",
"=",
"{",
"\"post_data\"",
":",
"{",
"\"name\"",
":",
"reaction_name",
",",
"\"channel\"",
":",
"channel_id",
",",
"\"tim... | Send a reaction to a message using slack Event API | [
"Send",
"a",
"reaction",
"to",
"a",
"message",
"using",
"slack",
"Event",
"API"
] | f0980f20f733b670debcae454b167da32c57a044 | https://github.com/llimllib/limbo/blob/f0980f20f733b670debcae454b167da32c57a044/limbo/slack.py#L121-L134 | train |
llimllib/limbo | limbo/slack.py | SlackClient.get_all | def get_all(self, api_method, collection_name, **kwargs):
"""
Return all objects in an api_method, handle pagination, and pass
kwargs on to the method being called.
For example, "users.list" returns an object like:
{
"members": [{<member_obj>}, {<member_obj_2>}],
... | python | def get_all(self, api_method, collection_name, **kwargs):
"""
Return all objects in an api_method, handle pagination, and pass
kwargs on to the method being called.
For example, "users.list" returns an object like:
{
"members": [{<member_obj>}, {<member_obj_2>}],
... | [
"def",
"get_all",
"(",
"self",
",",
"api_method",
",",
"collection_name",
",",
"**",
"kwargs",
")",
":",
"objs",
"=",
"[",
"]",
"limit",
"=",
"250",
"page",
"=",
"json",
".",
"loads",
"(",
"self",
".",
"api_call",
"(",
"api_method",
",",
"limit",
"="... | Return all objects in an api_method, handle pagination, and pass
kwargs on to the method being called.
For example, "users.list" returns an object like:
{
"members": [{<member_obj>}, {<member_obj_2>}],
"response_metadata": {
"next_cursor": "cursor_id"
... | [
"Return",
"all",
"objects",
"in",
"an",
"api_method",
"handle",
"pagination",
"and",
"pass",
"kwargs",
"on",
"to",
"the",
"method",
"being",
"called",
"."
] | f0980f20f733b670debcae454b167da32c57a044 | https://github.com/llimllib/limbo/blob/f0980f20f733b670debcae454b167da32c57a044/limbo/slack.py#L182-L225 | train |
llimllib/limbo | limbo/plugins/poll.py | poll | def poll(poll, msg, server):
"""Given a question and answers, present a poll"""
poll = remove_smart_quotes(poll.replace(u"\u2014", u"--"))
try:
args = ARGPARSE.parse_args(shlex.split(poll)).poll
except ValueError:
return ERROR_INVALID_FORMAT
if not 2 < len(args) < len(POLL_EMOJIS) ... | python | def poll(poll, msg, server):
"""Given a question and answers, present a poll"""
poll = remove_smart_quotes(poll.replace(u"\u2014", u"--"))
try:
args = ARGPARSE.parse_args(shlex.split(poll)).poll
except ValueError:
return ERROR_INVALID_FORMAT
if not 2 < len(args) < len(POLL_EMOJIS) ... | [
"def",
"poll",
"(",
"poll",
",",
"msg",
",",
"server",
")",
":",
"poll",
"=",
"remove_smart_quotes",
"(",
"poll",
".",
"replace",
"(",
"u\"\\u2014\"",
",",
"u\"--\"",
")",
")",
"try",
":",
"args",
"=",
"ARGPARSE",
".",
"parse_args",
"(",
"shlex",
".",
... | Given a question and answers, present a poll | [
"Given",
"a",
"question",
"and",
"answers",
"present",
"a",
"poll"
] | f0980f20f733b670debcae454b167da32c57a044 | https://github.com/llimllib/limbo/blob/f0980f20f733b670debcae454b167da32c57a044/limbo/plugins/poll.py#L28-L50 | train |
llimllib/limbo | limbo/plugins/emoji.py | emoji_list | def emoji_list(server, n=1):
"""return a list of `n` random emoji"""
global EMOJI
if EMOJI is None:
EMOJI = EmojiCache(server)
return EMOJI.get(n) | python | def emoji_list(server, n=1):
"""return a list of `n` random emoji"""
global EMOJI
if EMOJI is None:
EMOJI = EmojiCache(server)
return EMOJI.get(n) | [
"def",
"emoji_list",
"(",
"server",
",",
"n",
"=",
"1",
")",
":",
"global",
"EMOJI",
"if",
"EMOJI",
"is",
"None",
":",
"EMOJI",
"=",
"EmojiCache",
"(",
"server",
")",
"return",
"EMOJI",
".",
"get",
"(",
"n",
")"
] | return a list of `n` random emoji | [
"return",
"a",
"list",
"of",
"n",
"random",
"emoji"
] | f0980f20f733b670debcae454b167da32c57a044 | https://github.com/llimllib/limbo/blob/f0980f20f733b670debcae454b167da32c57a044/limbo/plugins/emoji.py#L46-L51 | train |
llimllib/limbo | limbo/plugins/wiki.py | wiki | def wiki(searchterm):
"""return the top wiki search result for the term"""
searchterm = quote(searchterm)
url = "https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch={0}&format=json"
url = url.format(searchterm)
result = requests.get(url).json()
pages = result["query"]["search... | python | def wiki(searchterm):
"""return the top wiki search result for the term"""
searchterm = quote(searchterm)
url = "https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch={0}&format=json"
url = url.format(searchterm)
result = requests.get(url).json()
pages = result["query"]["search... | [
"def",
"wiki",
"(",
"searchterm",
")",
":",
"searchterm",
"=",
"quote",
"(",
"searchterm",
")",
"url",
"=",
"\"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch={0}&format=json\"",
"url",
"=",
"url",
".",
"format",
"(",
"searchterm",
")",
"result",
... | return the top wiki search result for the term | [
"return",
"the",
"top",
"wiki",
"search",
"result",
"for",
"the",
"term"
] | f0980f20f733b670debcae454b167da32c57a044 | https://github.com/llimllib/limbo/blob/f0980f20f733b670debcae454b167da32c57a044/limbo/plugins/wiki.py#L12-L39 | train |
llimllib/limbo | limbo/plugins/gif.py | gif | def gif(search, unsafe=False):
"""given a search string, return a gif URL via google search"""
searchb = quote(search.encode("utf8"))
safe = "&safe=" if unsafe else "&safe=active"
searchurl = "https://www.google.com/search?tbs=itp:animated&tbm=isch&q={0}{1}" \
.format(searchb, safe)
# this... | python | def gif(search, unsafe=False):
"""given a search string, return a gif URL via google search"""
searchb = quote(search.encode("utf8"))
safe = "&safe=" if unsafe else "&safe=active"
searchurl = "https://www.google.com/search?tbs=itp:animated&tbm=isch&q={0}{1}" \
.format(searchb, safe)
# this... | [
"def",
"gif",
"(",
"search",
",",
"unsafe",
"=",
"False",
")",
":",
"searchb",
"=",
"quote",
"(",
"search",
".",
"encode",
"(",
"\"utf8\"",
")",
")",
"safe",
"=",
"\"&safe=\"",
"if",
"unsafe",
"else",
"\"&safe=active\"",
"searchurl",
"=",
"\"https://www.go... | given a search string, return a gif URL via google search | [
"given",
"a",
"search",
"string",
"return",
"a",
"gif",
"URL",
"via",
"google",
"search"
] | f0980f20f733b670debcae454b167da32c57a044 | https://github.com/llimllib/limbo/blob/f0980f20f733b670debcae454b167da32c57a044/limbo/plugins/gif.py#L19-L38 | train |
llimllib/limbo | limbo/plugins/gif.py | on_message | def on_message(msg, server):
"""handle a message and return an gif"""
text = msg.get("text", "")
match = re.findall(r"!gif (.*)", text)
if not match:
return
res = gif(match[0])
if not res:
return
attachment = {
"fallback": match[0],
"title": match[0],
... | python | def on_message(msg, server):
"""handle a message and return an gif"""
text = msg.get("text", "")
match = re.findall(r"!gif (.*)", text)
if not match:
return
res = gif(match[0])
if not res:
return
attachment = {
"fallback": match[0],
"title": match[0],
... | [
"def",
"on_message",
"(",
"msg",
",",
"server",
")",
":",
"text",
"=",
"msg",
".",
"get",
"(",
"\"text\"",
",",
"\"\"",
")",
"match",
"=",
"re",
".",
"findall",
"(",
"r\"!gif (.*)\"",
",",
"text",
")",
"if",
"not",
"match",
":",
"return",
"res",
"=... | handle a message and return an gif | [
"handle",
"a",
"message",
"and",
"return",
"an",
"gif"
] | f0980f20f733b670debcae454b167da32c57a044 | https://github.com/llimllib/limbo/blob/f0980f20f733b670debcae454b167da32c57a044/limbo/plugins/gif.py#L41-L62 | train |
btel/svg_utils | src/svgutils/transform.py | fromfile | def fromfile(fname):
"""Open SVG figure from file.
Parameters
----------
fname : str
name of the SVG file
Returns
-------
SVGFigure
newly created :py:class:`SVGFigure` initialised with the file content
"""
fig = SVGFigure()
with open(fname) as fid:
svg_f... | python | def fromfile(fname):
"""Open SVG figure from file.
Parameters
----------
fname : str
name of the SVG file
Returns
-------
SVGFigure
newly created :py:class:`SVGFigure` initialised with the file content
"""
fig = SVGFigure()
with open(fname) as fid:
svg_f... | [
"def",
"fromfile",
"(",
"fname",
")",
":",
"fig",
"=",
"SVGFigure",
"(",
")",
"with",
"open",
"(",
"fname",
")",
"as",
"fid",
":",
"svg_file",
"=",
"etree",
".",
"parse",
"(",
"fid",
")",
"fig",
".",
"root",
"=",
"svg_file",
".",
"getroot",
"(",
... | Open SVG figure from file.
Parameters
----------
fname : str
name of the SVG file
Returns
-------
SVGFigure
newly created :py:class:`SVGFigure` initialised with the file content | [
"Open",
"SVG",
"figure",
"from",
"file",
"."
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/transform.py#L294-L312 | train |
btel/svg_utils | src/svgutils/transform.py | fromstring | def fromstring(text):
"""Create a SVG figure from a string.
Parameters
----------
text : str
string representing the SVG content. Must be valid SVG.
Returns
-------
SVGFigure
newly created :py:class:`SVGFigure` initialised with the string
content.
"""
fig = ... | python | def fromstring(text):
"""Create a SVG figure from a string.
Parameters
----------
text : str
string representing the SVG content. Must be valid SVG.
Returns
-------
SVGFigure
newly created :py:class:`SVGFigure` initialised with the string
content.
"""
fig = ... | [
"def",
"fromstring",
"(",
"text",
")",
":",
"fig",
"=",
"SVGFigure",
"(",
")",
"svg",
"=",
"etree",
".",
"fromstring",
"(",
"text",
".",
"encode",
"(",
")",
")",
"fig",
".",
"root",
"=",
"svg",
"return",
"fig"
] | Create a SVG figure from a string.
Parameters
----------
text : str
string representing the SVG content. Must be valid SVG.
Returns
-------
SVGFigure
newly created :py:class:`SVGFigure` initialised with the string
content. | [
"Create",
"a",
"SVG",
"figure",
"from",
"a",
"string",
"."
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/transform.py#L315-L334 | train |
btel/svg_utils | src/svgutils/transform.py | from_mpl | def from_mpl(fig, savefig_kw=None):
"""Create a SVG figure from a ``matplotlib`` figure.
Parameters
----------
fig : matplotlib.Figure instance
savefig_kw : dict
keyword arguments to be passed to matplotlib's
`savefig`
Returns
-------
SVGFigure
newly create... | python | def from_mpl(fig, savefig_kw=None):
"""Create a SVG figure from a ``matplotlib`` figure.
Parameters
----------
fig : matplotlib.Figure instance
savefig_kw : dict
keyword arguments to be passed to matplotlib's
`savefig`
Returns
-------
SVGFigure
newly create... | [
"def",
"from_mpl",
"(",
"fig",
",",
"savefig_kw",
"=",
"None",
")",
":",
"fid",
"=",
"StringIO",
"(",
")",
"if",
"savefig_kw",
"is",
"None",
":",
"savefig_kw",
"=",
"{",
"}",
"try",
":",
"fig",
".",
"savefig",
"(",
"fid",
",",
"format",
"=",
"'svg'... | Create a SVG figure from a ``matplotlib`` figure.
Parameters
----------
fig : matplotlib.Figure instance
savefig_kw : dict
keyword arguments to be passed to matplotlib's
`savefig`
Returns
-------
SVGFigure
newly created :py:class:`SVGFigure` initialised with th... | [
"Create",
"a",
"SVG",
"figure",
"from",
"a",
"matplotlib",
"figure",
"."
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/transform.py#L337-L390 | train |
btel/svg_utils | src/svgutils/transform.py | FigureElement.moveto | def moveto(self, x, y, scale=1):
"""Move and scale element.
Parameters
----------
x, y : float
displacement in x and y coordinates in user units ('px').
scale : float
scaling factor. To scale down scale < 1, scale up scale > 1.
For no scal... | python | def moveto(self, x, y, scale=1):
"""Move and scale element.
Parameters
----------
x, y : float
displacement in x and y coordinates in user units ('px').
scale : float
scaling factor. To scale down scale < 1, scale up scale > 1.
For no scal... | [
"def",
"moveto",
"(",
"self",
",",
"x",
",",
"y",
",",
"scale",
"=",
"1",
")",
":",
"self",
".",
"root",
".",
"set",
"(",
"\"transform\"",
",",
"\"translate(%s, %s) scale(%s) %s\"",
"%",
"(",
"x",
",",
"y",
",",
"scale",
",",
"self",
".",
"root",
"... | Move and scale element.
Parameters
----------
x, y : float
displacement in x and y coordinates in user units ('px').
scale : float
scaling factor. To scale down scale < 1, scale up scale > 1.
For no scaling scale = 1. | [
"Move",
"and",
"scale",
"element",
"."
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/transform.py#L24-L36 | train |
btel/svg_utils | src/svgutils/transform.py | FigureElement.rotate | def rotate(self, angle, x=0, y=0):
"""Rotate element by given angle around given pivot.
Parameters
----------
angle : float
rotation angle in degrees
x, y : float
pivot coordinates in user coordinate system (defaults to top-left
corner of the ... | python | def rotate(self, angle, x=0, y=0):
"""Rotate element by given angle around given pivot.
Parameters
----------
angle : float
rotation angle in degrees
x, y : float
pivot coordinates in user coordinate system (defaults to top-left
corner of the ... | [
"def",
"rotate",
"(",
"self",
",",
"angle",
",",
"x",
"=",
"0",
",",
"y",
"=",
"0",
")",
":",
"self",
".",
"root",
".",
"set",
"(",
"\"transform\"",
",",
"\"%s rotate(%f %f %f)\"",
"%",
"(",
"self",
".",
"root",
".",
"get",
"(",
"\"transform\"",
")... | Rotate element by given angle around given pivot.
Parameters
----------
angle : float
rotation angle in degrees
x, y : float
pivot coordinates in user coordinate system (defaults to top-left
corner of the figure) | [
"Rotate",
"element",
"by",
"given",
"angle",
"around",
"given",
"pivot",
"."
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/transform.py#L38-L50 | train |
btel/svg_utils | src/svgutils/transform.py | FigureElement.skew | def skew(self, x=0, y=0):
"""Skew the element by x and y degrees
Convenience function which calls skew_x and skew_y
Parameters
----------
x,y : float, float
skew angle in degrees (default 0)
If an x/y angle is given as zero degrees, that transformation i... | python | def skew(self, x=0, y=0):
"""Skew the element by x and y degrees
Convenience function which calls skew_x and skew_y
Parameters
----------
x,y : float, float
skew angle in degrees (default 0)
If an x/y angle is given as zero degrees, that transformation i... | [
"def",
"skew",
"(",
"self",
",",
"x",
"=",
"0",
",",
"y",
"=",
"0",
")",
":",
"if",
"x",
"is",
"not",
"0",
":",
"self",
".",
"skew_x",
"(",
"x",
")",
"if",
"y",
"is",
"not",
"0",
":",
"self",
".",
"skew_y",
"(",
"y",
")",
"return",
"self"... | Skew the element by x and y degrees
Convenience function which calls skew_x and skew_y
Parameters
----------
x,y : float, float
skew angle in degrees (default 0)
If an x/y angle is given as zero degrees, that transformation is omitted. | [
"Skew",
"the",
"element",
"by",
"x",
"and",
"y",
"degrees",
"Convenience",
"function",
"which",
"calls",
"skew_x",
"and",
"skew_y"
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/transform.py#L52-L68 | train |
btel/svg_utils | src/svgutils/transform.py | FigureElement.skew_x | def skew_x(self, x):
"""Skew element along the x-axis by the given angle.
Parameters
----------
x : float
x-axis skew angle in degrees
"""
self.root.set("transform", "%s skewX(%f)" %
(self.root.get("transform") or '', x))
return ... | python | def skew_x(self, x):
"""Skew element along the x-axis by the given angle.
Parameters
----------
x : float
x-axis skew angle in degrees
"""
self.root.set("transform", "%s skewX(%f)" %
(self.root.get("transform") or '', x))
return ... | [
"def",
"skew_x",
"(",
"self",
",",
"x",
")",
":",
"self",
".",
"root",
".",
"set",
"(",
"\"transform\"",
",",
"\"%s skewX(%f)\"",
"%",
"(",
"self",
".",
"root",
".",
"get",
"(",
"\"transform\"",
")",
"or",
"''",
",",
"x",
")",
")",
"return",
"self"... | Skew element along the x-axis by the given angle.
Parameters
----------
x : float
x-axis skew angle in degrees | [
"Skew",
"element",
"along",
"the",
"x",
"-",
"axis",
"by",
"the",
"given",
"angle",
"."
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/transform.py#L70-L80 | train |
btel/svg_utils | src/svgutils/transform.py | FigureElement.skew_y | def skew_y(self, y):
"""Skew element along the y-axis by the given angle.
Parameters
----------
y : float
y-axis skew angle in degrees
"""
self.root.set("transform", "%s skewY(%f)" %
(self.root.get("transform") or '', y))
return ... | python | def skew_y(self, y):
"""Skew element along the y-axis by the given angle.
Parameters
----------
y : float
y-axis skew angle in degrees
"""
self.root.set("transform", "%s skewY(%f)" %
(self.root.get("transform") or '', y))
return ... | [
"def",
"skew_y",
"(",
"self",
",",
"y",
")",
":",
"self",
".",
"root",
".",
"set",
"(",
"\"transform\"",
",",
"\"%s skewY(%f)\"",
"%",
"(",
"self",
".",
"root",
".",
"get",
"(",
"\"transform\"",
")",
"or",
"''",
",",
"y",
")",
")",
"return",
"self"... | Skew element along the y-axis by the given angle.
Parameters
----------
y : float
y-axis skew angle in degrees | [
"Skew",
"element",
"along",
"the",
"y",
"-",
"axis",
"by",
"the",
"given",
"angle",
"."
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/transform.py#L82-L92 | train |
btel/svg_utils | src/svgutils/transform.py | FigureElement.find_id | def find_id(self, element_id):
"""Find element by its id.
Parameters
----------
element_id : str
ID of the element to find
Returns
-------
FigureElement
one of the children element with the given ID."""
find = etree.XPath("//*[@id... | python | def find_id(self, element_id):
"""Find element by its id.
Parameters
----------
element_id : str
ID of the element to find
Returns
-------
FigureElement
one of the children element with the given ID."""
find = etree.XPath("//*[@id... | [
"def",
"find_id",
"(",
"self",
",",
"element_id",
")",
":",
"find",
"=",
"etree",
".",
"XPath",
"(",
"\"//*[@id=$id]\"",
")",
"return",
"FigureElement",
"(",
"find",
"(",
"self",
".",
"root",
",",
"id",
"=",
"element_id",
")",
"[",
"0",
"]",
")"
] | Find element by its id.
Parameters
----------
element_id : str
ID of the element to find
Returns
-------
FigureElement
one of the children element with the given ID. | [
"Find",
"element",
"by",
"its",
"id",
"."
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/transform.py#L122-L135 | train |
btel/svg_utils | src/svgutils/transform.py | SVGFigure.append | def append(self, element):
"""Append new element to the SVG figure"""
try:
self.root.append(element.root)
except AttributeError:
self.root.append(GroupElement(element).root) | python | def append(self, element):
"""Append new element to the SVG figure"""
try:
self.root.append(element.root)
except AttributeError:
self.root.append(GroupElement(element).root) | [
"def",
"append",
"(",
"self",
",",
"element",
")",
":",
"try",
":",
"self",
".",
"root",
".",
"append",
"(",
"element",
".",
"root",
")",
"except",
"AttributeError",
":",
"self",
".",
"root",
".",
"append",
"(",
"GroupElement",
"(",
"element",
")",
"... | Append new element to the SVG figure | [
"Append",
"new",
"element",
"to",
"the",
"SVG",
"figure"
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/transform.py#L238-L243 | train |
btel/svg_utils | src/svgutils/transform.py | SVGFigure.getroot | def getroot(self):
"""Return the root element of the figure.
The root element is a group of elements after stripping the toplevel
``<svg>`` tag.
Returns
-------
GroupElement
All elements of the figure without the ``<svg>`` tag.
"""
if 'class'... | python | def getroot(self):
"""Return the root element of the figure.
The root element is a group of elements after stripping the toplevel
``<svg>`` tag.
Returns
-------
GroupElement
All elements of the figure without the ``<svg>`` tag.
"""
if 'class'... | [
"def",
"getroot",
"(",
"self",
")",
":",
"if",
"'class'",
"in",
"self",
".",
"root",
".",
"attrib",
":",
"attrib",
"=",
"{",
"'class'",
":",
"self",
".",
"root",
".",
"attrib",
"[",
"'class'",
"]",
"}",
"else",
":",
"attrib",
"=",
"None",
"return",... | Return the root element of the figure.
The root element is a group of elements after stripping the toplevel
``<svg>`` tag.
Returns
-------
GroupElement
All elements of the figure without the ``<svg>`` tag. | [
"Return",
"the",
"root",
"element",
"of",
"the",
"figure",
"."
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/transform.py#L245-L260 | train |
btel/svg_utils | src/svgutils/transform.py | SVGFigure.to_str | def to_str(self):
"""
Returns a string of the SVG figure.
"""
return etree.tostring(self.root, xml_declaration=True,
standalone=True,
pretty_print=True) | python | def to_str(self):
"""
Returns a string of the SVG figure.
"""
return etree.tostring(self.root, xml_declaration=True,
standalone=True,
pretty_print=True) | [
"def",
"to_str",
"(",
"self",
")",
":",
"return",
"etree",
".",
"tostring",
"(",
"self",
".",
"root",
",",
"xml_declaration",
"=",
"True",
",",
"standalone",
"=",
"True",
",",
"pretty_print",
"=",
"True",
")"
] | Returns a string of the SVG figure. | [
"Returns",
"a",
"string",
"of",
"the",
"SVG",
"figure",
"."
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/transform.py#L262-L268 | train |
btel/svg_utils | src/svgutils/transform.py | SVGFigure.save | def save(self, fname):
"""Save figure to a file"""
out = etree.tostring(self.root, xml_declaration=True,
standalone=True,
pretty_print=True)
with open(fname, 'wb') as fid:
fid.write(out) | python | def save(self, fname):
"""Save figure to a file"""
out = etree.tostring(self.root, xml_declaration=True,
standalone=True,
pretty_print=True)
with open(fname, 'wb') as fid:
fid.write(out) | [
"def",
"save",
"(",
"self",
",",
"fname",
")",
":",
"out",
"=",
"etree",
".",
"tostring",
"(",
"self",
".",
"root",
",",
"xml_declaration",
"=",
"True",
",",
"standalone",
"=",
"True",
",",
"pretty_print",
"=",
"True",
")",
"with",
"open",
"(",
"fnam... | Save figure to a file | [
"Save",
"figure",
"to",
"a",
"file"
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/transform.py#L270-L276 | train |
btel/svg_utils | src/svgutils/transform.py | SVGFigure.set_size | def set_size(self, size):
"""Set figure size"""
w, h = size
self.root.set('width', w)
self.root.set('height', h) | python | def set_size(self, size):
"""Set figure size"""
w, h = size
self.root.set('width', w)
self.root.set('height', h) | [
"def",
"set_size",
"(",
"self",
",",
"size",
")",
":",
"w",
",",
"h",
"=",
"size",
"self",
".",
"root",
".",
"set",
"(",
"'width'",
",",
"w",
")",
"self",
".",
"root",
".",
"set",
"(",
"'height'",
",",
"h",
")"
] | Set figure size | [
"Set",
"figure",
"size"
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/transform.py#L287-L291 | train |
btel/svg_utils | src/svgutils/compose.py | Element.find_id | def find_id(self, element_id):
"""Find a single element with the given ID.
Parameters
----------
element_id : str
ID of the element to find
Returns
-------
found element
"""
element = _transform.FigureElement.find_id(self, element_id)... | python | def find_id(self, element_id):
"""Find a single element with the given ID.
Parameters
----------
element_id : str
ID of the element to find
Returns
-------
found element
"""
element = _transform.FigureElement.find_id(self, element_id)... | [
"def",
"find_id",
"(",
"self",
",",
"element_id",
")",
":",
"element",
"=",
"_transform",
".",
"FigureElement",
".",
"find_id",
"(",
"self",
",",
"element_id",
")",
"return",
"Element",
"(",
"element",
".",
"root",
")"
] | Find a single element with the given ID.
Parameters
----------
element_id : str
ID of the element to find
Returns
-------
found element | [
"Find",
"a",
"single",
"element",
"with",
"the",
"given",
"ID",
"."
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/compose.py#L67-L80 | train |
btel/svg_utils | src/svgutils/compose.py | Element.find_ids | def find_ids(self, element_ids):
"""Find elements with given IDs.
Parameters
----------
element_ids : list of strings
list of IDs to find
Returns
-------
a new `Panel` object which contains all the found elements.
"""
elements = [_tra... | python | def find_ids(self, element_ids):
"""Find elements with given IDs.
Parameters
----------
element_ids : list of strings
list of IDs to find
Returns
-------
a new `Panel` object which contains all the found elements.
"""
elements = [_tra... | [
"def",
"find_ids",
"(",
"self",
",",
"element_ids",
")",
":",
"elements",
"=",
"[",
"_transform",
".",
"FigureElement",
".",
"find_id",
"(",
"self",
",",
"eid",
")",
"for",
"eid",
"in",
"element_ids",
"]",
"return",
"Panel",
"(",
"*",
"elements",
")"
] | Find elements with given IDs.
Parameters
----------
element_ids : list of strings
list of IDs to find
Returns
-------
a new `Panel` object which contains all the found elements. | [
"Find",
"elements",
"with",
"given",
"IDs",
"."
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/compose.py#L82-L96 | train |
btel/svg_utils | src/svgutils/compose.py | Figure.save | def save(self, fname):
"""Save figure to SVG file.
Parameters
----------
fname : str
Full path to file.
"""
element = _transform.SVGFigure(self.width, self.height)
element.append(self)
element.save(os.path.join(CONFIG['figure.save_path'], fnam... | python | def save(self, fname):
"""Save figure to SVG file.
Parameters
----------
fname : str
Full path to file.
"""
element = _transform.SVGFigure(self.width, self.height)
element.append(self)
element.save(os.path.join(CONFIG['figure.save_path'], fnam... | [
"def",
"save",
"(",
"self",
",",
"fname",
")",
":",
"element",
"=",
"_transform",
".",
"SVGFigure",
"(",
"self",
".",
"width",
",",
"self",
".",
"height",
")",
"element",
".",
"append",
"(",
"self",
")",
"element",
".",
"save",
"(",
"os",
".",
"pat... | Save figure to SVG file.
Parameters
----------
fname : str
Full path to file. | [
"Save",
"figure",
"to",
"SVG",
"file",
"."
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/compose.py#L292-L302 | train |
btel/svg_utils | src/svgutils/compose.py | Figure.tostr | def tostr(self):
"""Export SVG as a string"""
element = _transform.SVGFigure(self.width, self.height)
element.append(self)
svgstr = element.to_str()
return svgstr | python | def tostr(self):
"""Export SVG as a string"""
element = _transform.SVGFigure(self.width, self.height)
element.append(self)
svgstr = element.to_str()
return svgstr | [
"def",
"tostr",
"(",
"self",
")",
":",
"element",
"=",
"_transform",
".",
"SVGFigure",
"(",
"self",
".",
"width",
",",
"self",
".",
"height",
")",
"element",
".",
"append",
"(",
"self",
")",
"svgstr",
"=",
"element",
".",
"to_str",
"(",
")",
"return"... | Export SVG as a string | [
"Export",
"SVG",
"as",
"a",
"string"
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/compose.py#L304-L309 | train |
btel/svg_utils | src/svgutils/compose.py | Figure.tile | def tile(self, ncols, nrows):
"""Automatically tile the panels of the figure.
This will re-arranged all elements of the figure (first in the
hierarchy) so that they will uniformly cover the figure area.
Parameters
----------
ncols, nrows : type
The number of... | python | def tile(self, ncols, nrows):
"""Automatically tile the panels of the figure.
This will re-arranged all elements of the figure (first in the
hierarchy) so that they will uniformly cover the figure area.
Parameters
----------
ncols, nrows : type
The number of... | [
"def",
"tile",
"(",
"self",
",",
"ncols",
",",
"nrows",
")",
":",
"dx",
"=",
"(",
"self",
".",
"width",
"/",
"ncols",
")",
".",
"to",
"(",
"'px'",
")",
".",
"value",
"dy",
"=",
"(",
"self",
".",
"height",
"/",
"nrows",
")",
".",
"to",
"(",
... | Automatically tile the panels of the figure.
This will re-arranged all elements of the figure (first in the
hierarchy) so that they will uniformly cover the figure area.
Parameters
----------
ncols, nrows : type
The number of columns and rows to arange the elements ... | [
"Automatically",
"tile",
"the",
"panels",
"of",
"the",
"figure",
"."
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/compose.py#L314-L342 | train |
btel/svg_utils | src/svgutils/compose.py | Unit.to | def to(self, unit):
"""Convert to a given unit.
Parameters
----------
unit : str
Name of the unit to convert to.
Returns
-------
u : Unit
new Unit object with the requested unit and computed value.
"""
u = Unit("0cm")
... | python | def to(self, unit):
"""Convert to a given unit.
Parameters
----------
unit : str
Name of the unit to convert to.
Returns
-------
u : Unit
new Unit object with the requested unit and computed value.
"""
u = Unit("0cm")
... | [
"def",
"to",
"(",
"self",
",",
"unit",
")",
":",
"u",
"=",
"Unit",
"(",
"\"0cm\"",
")",
"u",
".",
"value",
"=",
"self",
".",
"value",
"/",
"self",
".",
"per_inch",
"[",
"self",
".",
"unit",
"]",
"*",
"self",
".",
"per_inch",
"[",
"unit",
"]",
... | Convert to a given unit.
Parameters
----------
unit : str
Name of the unit to convert to.
Returns
-------
u : Unit
new Unit object with the requested unit and computed value. | [
"Convert",
"to",
"a",
"given",
"unit",
"."
] | ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3 | https://github.com/btel/svg_utils/blob/ee00726ebed1bd97fd496b15b6a8e7f233ebb5e3/src/svgutils/compose.py#L369-L385 | train |
Kozea/cairocffi | cairocffi/__init__.py | dlopen | def dlopen(ffi, *names):
"""Try various names for the same library, for different platforms."""
for name in names:
for lib_name in (name, 'lib' + name):
try:
path = ctypes.util.find_library(lib_name)
lib = ffi.dlopen(path or lib_name)
if lib:
... | python | def dlopen(ffi, *names):
"""Try various names for the same library, for different platforms."""
for name in names:
for lib_name in (name, 'lib' + name):
try:
path = ctypes.util.find_library(lib_name)
lib = ffi.dlopen(path or lib_name)
if lib:
... | [
"def",
"dlopen",
"(",
"ffi",
",",
"*",
"names",
")",
":",
"for",
"name",
"in",
"names",
":",
"for",
"lib_name",
"in",
"(",
"name",
",",
"'lib'",
"+",
"name",
")",
":",
"try",
":",
"path",
"=",
"ctypes",
".",
"util",
".",
"find_library",
"(",
"lib... | Try various names for the same library, for different platforms. | [
"Try",
"various",
"names",
"for",
"the",
"same",
"library",
"for",
"different",
"platforms",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/__init__.py#L25-L36 | train |
Kozea/cairocffi | cairocffi/context.py | Context.set_source_rgba | def set_source_rgba(self, red, green, blue, alpha=1):
"""Sets the source pattern within this context to a solid color.
This color will then be used for any subsequent drawing operation
until a new source pattern is set.
The color and alpha components are
floating point numbers ... | python | def set_source_rgba(self, red, green, blue, alpha=1):
"""Sets the source pattern within this context to a solid color.
This color will then be used for any subsequent drawing operation
until a new source pattern is set.
The color and alpha components are
floating point numbers ... | [
"def",
"set_source_rgba",
"(",
"self",
",",
"red",
",",
"green",
",",
"blue",
",",
"alpha",
"=",
"1",
")",
":",
"cairo",
".",
"cairo_set_source_rgba",
"(",
"self",
".",
"_pointer",
",",
"red",
",",
"green",
",",
"blue",
",",
"alpha",
")",
"self",
"."... | Sets the source pattern within this context to a solid color.
This color will then be used for any subsequent drawing operation
until a new source pattern is set.
The color and alpha components are
floating point numbers in the range 0 to 1.
If the values passed in are outside ... | [
"Sets",
"the",
"source",
"pattern",
"within",
"this",
"context",
"to",
"a",
"solid",
"color",
".",
"This",
"color",
"will",
"then",
"be",
"used",
"for",
"any",
"subsequent",
"drawing",
"operation",
"until",
"a",
"new",
"source",
"pattern",
"is",
"set",
"."... | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L306-L331 | train |
Kozea/cairocffi | cairocffi/context.py | Context.get_dash | def get_dash(self):
"""Return the current dash pattern.
:returns:
A ``(dashes, offset)`` tuple of a list and a float.
:obj:`dashes` is a list of floats,
empty if no dashing is in effect.
"""
dashes = ffi.new('double[]', cairo.cairo_get_dash_count(sel... | python | def get_dash(self):
"""Return the current dash pattern.
:returns:
A ``(dashes, offset)`` tuple of a list and a float.
:obj:`dashes` is a list of floats,
empty if no dashing is in effect.
"""
dashes = ffi.new('double[]', cairo.cairo_get_dash_count(sel... | [
"def",
"get_dash",
"(",
"self",
")",
":",
"dashes",
"=",
"ffi",
".",
"new",
"(",
"'double[]'",
",",
"cairo",
".",
"cairo_get_dash_count",
"(",
"self",
".",
"_pointer",
")",
")",
"offset",
"=",
"ffi",
".",
"new",
"(",
"'double *'",
")",
"cairo",
".",
... | Return the current dash pattern.
:returns:
A ``(dashes, offset)`` tuple of a list and a float.
:obj:`dashes` is a list of floats,
empty if no dashing is in effect. | [
"Return",
"the",
"current",
"dash",
"pattern",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L472-L485 | train |
Kozea/cairocffi | cairocffi/context.py | Context.set_miter_limit | def set_miter_limit(self, limit):
"""Sets the current miter limit within the cairo context.
If the current line join style is set to :obj:`MITER <LINE_JOIN_MITER>`
(see :meth:`set_line_join`),
the miter limit is used to determine
whether the lines should be joined with a bevel i... | python | def set_miter_limit(self, limit):
"""Sets the current miter limit within the cairo context.
If the current line join style is set to :obj:`MITER <LINE_JOIN_MITER>`
(see :meth:`set_line_join`),
the miter limit is used to determine
whether the lines should be joined with a bevel i... | [
"def",
"set_miter_limit",
"(",
"self",
",",
"limit",
")",
":",
"cairo",
".",
"cairo_set_miter_limit",
"(",
"self",
".",
"_pointer",
",",
"limit",
")",
"self",
".",
"_check_status",
"(",
")"
] | Sets the current miter limit within the cairo context.
If the current line join style is set to :obj:`MITER <LINE_JOIN_MITER>`
(see :meth:`set_line_join`),
the miter limit is used to determine
whether the lines should be joined with a bevel instead of a miter.
Cairo divides the ... | [
"Sets",
"the",
"current",
"miter",
"limit",
"within",
"the",
"cairo",
"context",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L587-L618 | train |
Kozea/cairocffi | cairocffi/context.py | Context.get_current_point | def get_current_point(self):
"""Return the current point of the current path,
which is conceptually the final point reached by the path so far.
The current point is returned in the user-space coordinate system.
If there is no defined current point
or if the context is in an erro... | python | def get_current_point(self):
"""Return the current point of the current path,
which is conceptually the final point reached by the path so far.
The current point is returned in the user-space coordinate system.
If there is no defined current point
or if the context is in an erro... | [
"def",
"get_current_point",
"(",
"self",
")",
":",
"xy",
"=",
"ffi",
".",
"new",
"(",
"'double[2]'",
")",
"cairo",
".",
"cairo_get_current_point",
"(",
"self",
".",
"_pointer",
",",
"xy",
"+",
"0",
",",
"xy",
"+",
"1",
")",
"self",
".",
"_check_status"... | Return the current point of the current path,
which is conceptually the final point reached by the path so far.
The current point is returned in the user-space coordinate system.
If there is no defined current point
or if the context is in an error status,
``(0, 0)`` is returned... | [
"Return",
"the",
"current",
"point",
"of",
"the",
"current",
"path",
"which",
"is",
"conceptually",
"the",
"final",
"point",
"reached",
"by",
"the",
"path",
"so",
"far",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L850-L898 | train |
Kozea/cairocffi | cairocffi/context.py | Context.copy_path | def copy_path(self):
"""Return a copy of the current path.
:returns:
A list of ``(path_operation, coordinates)`` tuples
of a :ref:`PATH_OPERATION` string
and a tuple of floats coordinates
whose content depends on the operation type:
* :obj:`M... | python | def copy_path(self):
"""Return a copy of the current path.
:returns:
A list of ``(path_operation, coordinates)`` tuples
of a :ref:`PATH_OPERATION` string
and a tuple of floats coordinates
whose content depends on the operation type:
* :obj:`M... | [
"def",
"copy_path",
"(",
"self",
")",
":",
"path",
"=",
"cairo",
".",
"cairo_copy_path",
"(",
"self",
".",
"_pointer",
")",
"result",
"=",
"list",
"(",
"_iter_path",
"(",
"path",
")",
")",
"cairo",
".",
"cairo_path_destroy",
"(",
"path",
")",
"return",
... | Return a copy of the current path.
:returns:
A list of ``(path_operation, coordinates)`` tuples
of a :ref:`PATH_OPERATION` string
and a tuple of floats coordinates
whose content depends on the operation type:
* :obj:`MOVE_TO <PATH_MOVE_TO>`: 1 point ... | [
"Return",
"a",
"copy",
"of",
"the",
"current",
"path",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L1245-L1264 | train |
Kozea/cairocffi | cairocffi/context.py | Context.copy_path_flat | def copy_path_flat(self):
"""Return a flattened copy of the current path
This method is like :meth:`copy_path`
except that any curves in the path will be approximated
with piecewise-linear approximations,
(accurate to within the current tolerance value,
see :meth:`set_to... | python | def copy_path_flat(self):
"""Return a flattened copy of the current path
This method is like :meth:`copy_path`
except that any curves in the path will be approximated
with piecewise-linear approximations,
(accurate to within the current tolerance value,
see :meth:`set_to... | [
"def",
"copy_path_flat",
"(",
"self",
")",
":",
"path",
"=",
"cairo",
".",
"cairo_copy_path_flat",
"(",
"self",
".",
"_pointer",
")",
"result",
"=",
"list",
"(",
"_iter_path",
"(",
"path",
")",
")",
"cairo",
".",
"cairo_path_destroy",
"(",
"path",
")",
"... | Return a flattened copy of the current path
This method is like :meth:`copy_path`
except that any curves in the path will be approximated
with piecewise-linear approximations,
(accurate to within the current tolerance value,
see :meth:`set_tolerance`).
That is,
t... | [
"Return",
"a",
"flattened",
"copy",
"of",
"the",
"current",
"path"
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L1266-L1288 | train |
Kozea/cairocffi | cairocffi/context.py | Context.clip_extents | def clip_extents(self):
"""Computes a bounding box in user coordinates
covering the area inside the current clip.
:return:
A ``(x1, y1, x2, y2)`` tuple of floats:
the left, top, right and bottom of the resulting extents,
respectively.
"""
ext... | python | def clip_extents(self):
"""Computes a bounding box in user coordinates
covering the area inside the current clip.
:return:
A ``(x1, y1, x2, y2)`` tuple of floats:
the left, top, right and bottom of the resulting extents,
respectively.
"""
ext... | [
"def",
"clip_extents",
"(",
"self",
")",
":",
"extents",
"=",
"ffi",
".",
"new",
"(",
"'double[4]'",
")",
"cairo",
".",
"cairo_clip_extents",
"(",
"self",
".",
"_pointer",
",",
"extents",
"+",
"0",
",",
"extents",
"+",
"1",
",",
"extents",
"+",
"2",
... | Computes a bounding box in user coordinates
covering the area inside the current clip.
:return:
A ``(x1, y1, x2, y2)`` tuple of floats:
the left, top, right and bottom of the resulting extents,
respectively. | [
"Computes",
"a",
"bounding",
"box",
"in",
"user",
"coordinates",
"covering",
"the",
"area",
"inside",
"the",
"current",
"clip",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L1629-L1643 | train |
Kozea/cairocffi | cairocffi/context.py | Context.copy_clip_rectangle_list | def copy_clip_rectangle_list(self):
"""Return the current clip region as a list of rectangles
in user coordinates.
:return:
A list of rectangles,
as ``(x, y, width, height)`` tuples of floats.
:raises:
:exc:`CairoError`
if the clip region... | python | def copy_clip_rectangle_list(self):
"""Return the current clip region as a list of rectangles
in user coordinates.
:return:
A list of rectangles,
as ``(x, y, width, height)`` tuples of floats.
:raises:
:exc:`CairoError`
if the clip region... | [
"def",
"copy_clip_rectangle_list",
"(",
"self",
")",
":",
"rectangle_list",
"=",
"cairo",
".",
"cairo_copy_clip_rectangle_list",
"(",
"self",
".",
"_pointer",
")",
"_check_status",
"(",
"rectangle_list",
".",
"status",
")",
"rectangles",
"=",
"rectangle_list",
".",
... | Return the current clip region as a list of rectangles
in user coordinates.
:return:
A list of rectangles,
as ``(x, y, width, height)`` tuples of floats.
:raises:
:exc:`CairoError`
if the clip region cannot be represented as a list
of... | [
"Return",
"the",
"current",
"clip",
"region",
"as",
"a",
"list",
"of",
"rectangles",
"in",
"user",
"coordinates",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L1645-L1666 | train |
Kozea/cairocffi | cairocffi/context.py | Context.select_font_face | def select_font_face(self, family='', slant=constants.FONT_SLANT_NORMAL,
weight=constants.FONT_WEIGHT_NORMAL):
"""Selects a family and style of font from a simplified description
as a family name, slant and weight.
.. note::
The :meth:`select_font_face` met... | python | def select_font_face(self, family='', slant=constants.FONT_SLANT_NORMAL,
weight=constants.FONT_WEIGHT_NORMAL):
"""Selects a family and style of font from a simplified description
as a family name, slant and weight.
.. note::
The :meth:`select_font_face` met... | [
"def",
"select_font_face",
"(",
"self",
",",
"family",
"=",
"''",
",",
"slant",
"=",
"constants",
".",
"FONT_SLANT_NORMAL",
",",
"weight",
"=",
"constants",
".",
"FONT_WEIGHT_NORMAL",
")",
":",
"cairo",
".",
"cairo_select_font_face",
"(",
"self",
".",
"_pointe... | Selects a family and style of font from a simplified description
as a family name, slant and weight.
.. note::
The :meth:`select_font_face` method is part of
what the cairo designers call the "toy" text API.
It is convenient for short demos and simple programs,
... | [
"Selects",
"a",
"family",
"and",
"style",
"of",
"font",
"from",
"a",
"simplified",
"description",
"as",
"a",
"family",
"name",
"slant",
"and",
"weight",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L1709-L1752 | train |
Kozea/cairocffi | cairocffi/context.py | Context.get_font_face | def get_font_face(self):
"""Return the current font face.
:param font_face:
A new :class:`FontFace` object
wrapping an existing cairo object.
"""
return FontFace._from_pointer(
cairo.cairo_get_font_face(self._pointer), incref=True) | python | def get_font_face(self):
"""Return the current font face.
:param font_face:
A new :class:`FontFace` object
wrapping an existing cairo object.
"""
return FontFace._from_pointer(
cairo.cairo_get_font_face(self._pointer), incref=True) | [
"def",
"get_font_face",
"(",
"self",
")",
":",
"return",
"FontFace",
".",
"_from_pointer",
"(",
"cairo",
".",
"cairo_get_font_face",
"(",
"self",
".",
"_pointer",
")",
",",
"incref",
"=",
"True",
")"
] | Return the current font face.
:param font_face:
A new :class:`FontFace` object
wrapping an existing cairo object. | [
"Return",
"the",
"current",
"font",
"face",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L1766-L1775 | train |
Kozea/cairocffi | cairocffi/context.py | Context.get_scaled_font | def get_scaled_font(self):
"""Return the current scaled font.
:return:
A new :class:`ScaledFont` object,
wrapping an existing cairo object.
"""
return ScaledFont._from_pointer(
cairo.cairo_get_scaled_font(self._pointer), incref=True) | python | def get_scaled_font(self):
"""Return the current scaled font.
:return:
A new :class:`ScaledFont` object,
wrapping an existing cairo object.
"""
return ScaledFont._from_pointer(
cairo.cairo_get_scaled_font(self._pointer), incref=True) | [
"def",
"get_scaled_font",
"(",
"self",
")",
":",
"return",
"ScaledFont",
".",
"_from_pointer",
"(",
"cairo",
".",
"cairo_get_scaled_font",
"(",
"self",
".",
"_pointer",
")",
",",
"incref",
"=",
"True",
")"
] | Return the current scaled font.
:return:
A new :class:`ScaledFont` object,
wrapping an existing cairo object. | [
"Return",
"the",
"current",
"scaled",
"font",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L1865-L1874 | train |
Kozea/cairocffi | cairocffi/context.py | Context.font_extents | def font_extents(self):
"""Return the extents of the currently selected font.
Values are given in the current user-space coordinate system.
Because font metrics are in user-space coordinates, they are mostly,
but not entirely, independent of the current transformation matrix.
I... | python | def font_extents(self):
"""Return the extents of the currently selected font.
Values are given in the current user-space coordinate system.
Because font metrics are in user-space coordinates, they are mostly,
but not entirely, independent of the current transformation matrix.
I... | [
"def",
"font_extents",
"(",
"self",
")",
":",
"extents",
"=",
"ffi",
".",
"new",
"(",
"'cairo_font_extents_t *'",
")",
"cairo",
".",
"cairo_font_extents",
"(",
"self",
".",
"_pointer",
",",
"extents",
")",
"self",
".",
"_check_status",
"(",
")",
"return",
... | Return the extents of the currently selected font.
Values are given in the current user-space coordinate system.
Because font metrics are in user-space coordinates, they are mostly,
but not entirely, independent of the current transformation matrix.
If you call :meth:`context.scale(2) ... | [
"Return",
"the",
"extents",
"of",
"the",
"currently",
"selected",
"font",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L1876-L1933 | train |
Kozea/cairocffi | cairocffi/context.py | Context.text_extents | def text_extents(self, text):
"""Returns the extents for a string of text.
The extents describe a user-space rectangle
that encloses the "inked" portion of the text,
(as it would be drawn by :meth:`show_text`).
Additionally, the :obj:`x_advance` and :obj:`y_advance` values
... | python | def text_extents(self, text):
"""Returns the extents for a string of text.
The extents describe a user-space rectangle
that encloses the "inked" portion of the text,
(as it would be drawn by :meth:`show_text`).
Additionally, the :obj:`x_advance` and :obj:`y_advance` values
... | [
"def",
"text_extents",
"(",
"self",
",",
"text",
")",
":",
"extents",
"=",
"ffi",
".",
"new",
"(",
"'cairo_text_extents_t *'",
")",
"cairo",
".",
"cairo_text_extents",
"(",
"self",
".",
"_pointer",
",",
"_encode_string",
"(",
"text",
")",
",",
"extents",
"... | Returns the extents for a string of text.
The extents describe a user-space rectangle
that encloses the "inked" portion of the text,
(as it would be drawn by :meth:`show_text`).
Additionally, the :obj:`x_advance` and :obj:`y_advance` values
indicate the amount by which the curre... | [
"Returns",
"the",
"extents",
"for",
"a",
"string",
"of",
"text",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L1939-L2009 | train |
Kozea/cairocffi | cairocffi/context.py | Context.glyph_extents | def glyph_extents(self, glyphs):
"""Returns the extents for a list of glyphs.
The extents describe a user-space rectangle
that encloses the "inked" portion of the glyphs,
(as it would be drawn by :meth:`show_glyphs`).
Additionally, the :obj:`x_advance` and :obj:`y_advance` value... | python | def glyph_extents(self, glyphs):
"""Returns the extents for a list of glyphs.
The extents describe a user-space rectangle
that encloses the "inked" portion of the glyphs,
(as it would be drawn by :meth:`show_glyphs`).
Additionally, the :obj:`x_advance` and :obj:`y_advance` value... | [
"def",
"glyph_extents",
"(",
"self",
",",
"glyphs",
")",
":",
"glyphs",
"=",
"ffi",
".",
"new",
"(",
"'cairo_glyph_t[]'",
",",
"glyphs",
")",
"extents",
"=",
"ffi",
".",
"new",
"(",
"'cairo_text_extents_t *'",
")",
"cairo",
".",
"cairo_glyph_extents",
"(",
... | Returns the extents for a list of glyphs.
The extents describe a user-space rectangle
that encloses the "inked" portion of the glyphs,
(as it would be drawn by :meth:`show_glyphs`).
Additionally, the :obj:`x_advance` and :obj:`y_advance` values
indicate the amount by which the c... | [
"Returns",
"the",
"extents",
"for",
"a",
"list",
"of",
"glyphs",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L2011-L2038 | train |
Kozea/cairocffi | cairocffi/context.py | Context.tag_begin | def tag_begin(self, tag_name, attributes=None):
"""Marks the beginning of the ``tag_name`` structure.
Call :meth:`tag_end` with the same ``tag_name`` to mark the end of the
structure.
The attributes string is of the form "key1=value2 key2=value2 ...".
Values may be boolean (tru... | python | def tag_begin(self, tag_name, attributes=None):
"""Marks the beginning of the ``tag_name`` structure.
Call :meth:`tag_end` with the same ``tag_name`` to mark the end of the
structure.
The attributes string is of the form "key1=value2 key2=value2 ...".
Values may be boolean (tru... | [
"def",
"tag_begin",
"(",
"self",
",",
"tag_name",
",",
"attributes",
"=",
"None",
")",
":",
"if",
"attributes",
"is",
"None",
":",
"attributes",
"=",
"''",
"cairo",
".",
"cairo_tag_begin",
"(",
"self",
".",
"_pointer",
",",
"_encode_string",
"(",
"tag_name... | Marks the beginning of the ``tag_name`` structure.
Call :meth:`tag_end` with the same ``tag_name`` to mark the end of the
structure.
The attributes string is of the form "key1=value2 key2=value2 ...".
Values may be boolean (true/false or 1/0), integer, float, string, or
an arra... | [
"Marks",
"the",
"beginning",
"of",
"the",
"tag_name",
"structure",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L2198-L2240 | train |
Kozea/cairocffi | cairocffi/context.py | Context.tag_end | def tag_end(self, tag_name):
"""Marks the end of the ``tag_name`` structure.
Invalid nesting of tags will cause @cr to shutdown with a status of
``CAIRO_STATUS_TAG_ERROR``.
See :meth:`tag_begin`.
:param tag_name: tag name
*New in cairo 1.16.*
*New in cairocff... | python | def tag_end(self, tag_name):
"""Marks the end of the ``tag_name`` structure.
Invalid nesting of tags will cause @cr to shutdown with a status of
``CAIRO_STATUS_TAG_ERROR``.
See :meth:`tag_begin`.
:param tag_name: tag name
*New in cairo 1.16.*
*New in cairocff... | [
"def",
"tag_end",
"(",
"self",
",",
"tag_name",
")",
":",
"cairo",
".",
"cairo_tag_end",
"(",
"self",
".",
"_pointer",
",",
"_encode_string",
"(",
"tag_name",
")",
")",
"self",
".",
"_check_status",
"(",
")"
] | Marks the end of the ``tag_name`` structure.
Invalid nesting of tags will cause @cr to shutdown with a status of
``CAIRO_STATUS_TAG_ERROR``.
See :meth:`tag_begin`.
:param tag_name: tag name
*New in cairo 1.16.*
*New in cairocffi 0.9.* | [
"Marks",
"the",
"end",
"of",
"the",
"tag_name",
"structure",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/context.py#L2242-L2258 | train |
Kozea/cairocffi | cairocffi/surfaces.py | _make_read_func | def _make_read_func(file_obj):
"""Return a CFFI callback that reads from a file-like object."""
@ffi.callback("cairo_read_func_t", error=constants.STATUS_READ_ERROR)
def read_func(_closure, data, length):
string = file_obj.read(length)
if len(string) < length: # EOF too early
re... | python | def _make_read_func(file_obj):
"""Return a CFFI callback that reads from a file-like object."""
@ffi.callback("cairo_read_func_t", error=constants.STATUS_READ_ERROR)
def read_func(_closure, data, length):
string = file_obj.read(length)
if len(string) < length: # EOF too early
re... | [
"def",
"_make_read_func",
"(",
"file_obj",
")",
":",
"@",
"ffi",
".",
"callback",
"(",
"\"cairo_read_func_t\"",
",",
"error",
"=",
"constants",
".",
"STATUS_READ_ERROR",
")",
"def",
"read_func",
"(",
"_closure",
",",
"data",
",",
"length",
")",
":",
"string"... | Return a CFFI callback that reads from a file-like object. | [
"Return",
"a",
"CFFI",
"callback",
"that",
"reads",
"from",
"a",
"file",
"-",
"like",
"object",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L24-L33 | train |
Kozea/cairocffi | cairocffi/surfaces.py | _make_write_func | def _make_write_func(file_obj):
"""Return a CFFI callback that writes to a file-like object."""
if file_obj is None:
return ffi.NULL
@ffi.callback("cairo_write_func_t", error=constants.STATUS_WRITE_ERROR)
def write_func(_closure, data, length):
file_obj.write(ffi.buffer(data, length))
... | python | def _make_write_func(file_obj):
"""Return a CFFI callback that writes to a file-like object."""
if file_obj is None:
return ffi.NULL
@ffi.callback("cairo_write_func_t", error=constants.STATUS_WRITE_ERROR)
def write_func(_closure, data, length):
file_obj.write(ffi.buffer(data, length))
... | [
"def",
"_make_write_func",
"(",
"file_obj",
")",
":",
"if",
"file_obj",
"is",
"None",
":",
"return",
"ffi",
".",
"NULL",
"@",
"ffi",
".",
"callback",
"(",
"\"cairo_write_func_t\"",
",",
"error",
"=",
"constants",
".",
"STATUS_WRITE_ERROR",
")",
"def",
"write... | Return a CFFI callback that writes to a file-like object. | [
"Return",
"a",
"CFFI",
"callback",
"that",
"writes",
"to",
"a",
"file",
"-",
"like",
"object",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L36-L45 | train |
Kozea/cairocffi | cairocffi/surfaces.py | _encode_filename | def _encode_filename(filename): # pragma: no cover
"""Return a byte string suitable for a filename.
Unicode is encoded using an encoding adapted to what both cairo and the
filesystem want.
"""
# Don't replace unknown characters as '?' is forbidden in Windows filenames
errors = 'ignore' if os.... | python | def _encode_filename(filename): # pragma: no cover
"""Return a byte string suitable for a filename.
Unicode is encoded using an encoding adapted to what both cairo and the
filesystem want.
"""
# Don't replace unknown characters as '?' is forbidden in Windows filenames
errors = 'ignore' if os.... | [
"def",
"_encode_filename",
"(",
"filename",
")",
":",
"errors",
"=",
"'ignore'",
"if",
"os",
".",
"name",
"==",
"'nt'",
"else",
"'replace'",
"if",
"not",
"isinstance",
"(",
"filename",
",",
"bytes",
")",
":",
"if",
"os",
".",
"name",
"==",
"'nt'",
"and... | Return a byte string suitable for a filename.
Unicode is encoded using an encoding adapted to what both cairo and the
filesystem want. | [
"Return",
"a",
"byte",
"string",
"suitable",
"for",
"a",
"filename",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L48-L70 | train |
Kozea/cairocffi | cairocffi/surfaces.py | Surface.create_similar_image | def create_similar_image(self, content, width, height):
"""
Create a new image surface that is as compatible as possible
for uploading to and the use in conjunction with this surface.
However, this surface can still be used like any normal image surface.
Initially the surface co... | python | def create_similar_image(self, content, width, height):
"""
Create a new image surface that is as compatible as possible
for uploading to and the use in conjunction with this surface.
However, this surface can still be used like any normal image surface.
Initially the surface co... | [
"def",
"create_similar_image",
"(",
"self",
",",
"content",
",",
"width",
",",
"height",
")",
":",
"return",
"Surface",
".",
"_from_pointer",
"(",
"cairo",
".",
"cairo_surface_create_similar_image",
"(",
"self",
".",
"_pointer",
",",
"content",
",",
"width",
"... | Create a new image surface that is as compatible as possible
for uploading to and the use in conjunction with this surface.
However, this surface can still be used like any normal image surface.
Initially the surface contents are all 0
(transparent if contents have transparency, black o... | [
"Create",
"a",
"new",
"image",
"surface",
"that",
"is",
"as",
"compatible",
"as",
"possible",
"for",
"uploading",
"to",
"and",
"the",
"use",
"in",
"conjunction",
"with",
"this",
"surface",
".",
"However",
"this",
"surface",
"can",
"still",
"be",
"used",
"l... | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L209-L232 | train |
Kozea/cairocffi | cairocffi/surfaces.py | Surface.create_for_rectangle | def create_for_rectangle(self, x, y, width, height):
"""
Create a new surface that is a rectangle within this surface.
All operations drawn to this surface are then clipped and translated
onto the target surface.
Nothing drawn via this sub-surface outside of its bounds
is... | python | def create_for_rectangle(self, x, y, width, height):
"""
Create a new surface that is a rectangle within this surface.
All operations drawn to this surface are then clipped and translated
onto the target surface.
Nothing drawn via this sub-surface outside of its bounds
is... | [
"def",
"create_for_rectangle",
"(",
"self",
",",
"x",
",",
"y",
",",
"width",
",",
"height",
")",
":",
"return",
"Surface",
".",
"_from_pointer",
"(",
"cairo",
".",
"cairo_surface_create_for_rectangle",
"(",
"self",
".",
"_pointer",
",",
"x",
",",
"y",
","... | Create a new surface that is a rectangle within this surface.
All operations drawn to this surface are then clipped and translated
onto the target surface.
Nothing drawn via this sub-surface outside of its bounds
is drawn onto the target surface,
making this a useful method for p... | [
"Create",
"a",
"new",
"surface",
"that",
"is",
"a",
"rectangle",
"within",
"this",
"surface",
".",
"All",
"operations",
"drawn",
"to",
"this",
"surface",
"are",
"then",
"clipped",
"and",
"translated",
"onto",
"the",
"target",
"surface",
".",
"Nothing",
"draw... | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L234-L277 | train |
Kozea/cairocffi | cairocffi/surfaces.py | Surface.set_fallback_resolution | def set_fallback_resolution(self, x_pixels_per_inch, y_pixels_per_inch):
"""
Set the horizontal and vertical resolution for image fallbacks.
When certain operations aren't supported natively by a backend,
cairo will fallback by rendering operations to an image
and then overlayin... | python | def set_fallback_resolution(self, x_pixels_per_inch, y_pixels_per_inch):
"""
Set the horizontal and vertical resolution for image fallbacks.
When certain operations aren't supported natively by a backend,
cairo will fallback by rendering operations to an image
and then overlayin... | [
"def",
"set_fallback_resolution",
"(",
"self",
",",
"x_pixels_per_inch",
",",
"y_pixels_per_inch",
")",
":",
"cairo",
".",
"cairo_surface_set_fallback_resolution",
"(",
"self",
".",
"_pointer",
",",
"x_pixels_per_inch",
",",
"y_pixels_per_inch",
")",
"self",
".",
"_ch... | Set the horizontal and vertical resolution for image fallbacks.
When certain operations aren't supported natively by a backend,
cairo will fallback by rendering operations to an image
and then overlaying that image onto the output.
For backends that are natively vector-oriented,
... | [
"Set",
"the",
"horizontal",
"and",
"vertical",
"resolution",
"for",
"image",
"fallbacks",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L342-L382 | train |
Kozea/cairocffi | cairocffi/surfaces.py | Surface.get_font_options | def get_font_options(self):
"""Retrieves the default font rendering options for the surface.
This allows display surfaces to report the correct subpixel order
for rendering on them,
print surfaces to disable hinting of metrics and so forth.
The result can then be used with :clas... | python | def get_font_options(self):
"""Retrieves the default font rendering options for the surface.
This allows display surfaces to report the correct subpixel order
for rendering on them,
print surfaces to disable hinting of metrics and so forth.
The result can then be used with :clas... | [
"def",
"get_font_options",
"(",
"self",
")",
":",
"font_options",
"=",
"FontOptions",
"(",
")",
"cairo",
".",
"cairo_surface_get_font_options",
"(",
"self",
".",
"_pointer",
",",
"font_options",
".",
"_pointer",
")",
"return",
"font_options"
] | Retrieves the default font rendering options for the surface.
This allows display surfaces to report the correct subpixel order
for rendering on them,
print surfaces to disable hinting of metrics and so forth.
The result can then be used with :class:`ScaledFont`.
:returns: A ne... | [
"Retrieves",
"the",
"default",
"font",
"rendering",
"options",
"for",
"the",
"surface",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L397-L411 | train |
Kozea/cairocffi | cairocffi/surfaces.py | Surface.set_device_scale | def set_device_scale(self, x_scale, y_scale):
"""Sets a scale that is multiplied to the device coordinates determined
by the CTM when drawing to surface.
One common use for this is to render to very high resolution display
devices at a scale factor, so that code that assumes 1 pixel wil... | python | def set_device_scale(self, x_scale, y_scale):
"""Sets a scale that is multiplied to the device coordinates determined
by the CTM when drawing to surface.
One common use for this is to render to very high resolution display
devices at a scale factor, so that code that assumes 1 pixel wil... | [
"def",
"set_device_scale",
"(",
"self",
",",
"x_scale",
",",
"y_scale",
")",
":",
"cairo",
".",
"cairo_surface_set_device_scale",
"(",
"self",
".",
"_pointer",
",",
"x_scale",
",",
"y_scale",
")",
"self",
".",
"_check_status",
"(",
")"
] | Sets a scale that is multiplied to the device coordinates determined
by the CTM when drawing to surface.
One common use for this is to render to very high resolution display
devices at a scale factor, so that code that assumes 1 pixel will be a
certain size will still work. Setting a t... | [
"Sets",
"a",
"scale",
"that",
"is",
"multiplied",
"to",
"the",
"device",
"coordinates",
"determined",
"by",
"the",
"CTM",
"when",
"drawing",
"to",
"surface",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L413-L435 | train |
Kozea/cairocffi | cairocffi/surfaces.py | Surface.get_mime_data | def get_mime_data(self, mime_type):
"""Return mime data previously attached to surface
using the specified mime type.
:param mime_type: The MIME type of the image data.
:type mime_type: ASCII string
:returns:
A CFFI buffer object, or :obj:`None`
if no dat... | python | def get_mime_data(self, mime_type):
"""Return mime data previously attached to surface
using the specified mime type.
:param mime_type: The MIME type of the image data.
:type mime_type: ASCII string
:returns:
A CFFI buffer object, or :obj:`None`
if no dat... | [
"def",
"get_mime_data",
"(",
"self",
",",
"mime_type",
")",
":",
"buffer_address",
"=",
"ffi",
".",
"new",
"(",
"'unsigned char **'",
")",
"buffer_length",
"=",
"ffi",
".",
"new",
"(",
"'unsigned long *'",
")",
"mime_type",
"=",
"ffi",
".",
"new",
"(",
"'c... | Return mime data previously attached to surface
using the specified mime type.
:param mime_type: The MIME type of the image data.
:type mime_type: ASCII string
:returns:
A CFFI buffer object, or :obj:`None`
if no data has been attached with the given mime type.
... | [
"Return",
"mime",
"data",
"previously",
"attached",
"to",
"surface",
"using",
"the",
"specified",
"mime",
"type",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L504-L523 | train |
Kozea/cairocffi | cairocffi/surfaces.py | Surface.write_to_png | def write_to_png(self, target=None):
"""Writes the contents of surface as a PNG image.
:param target:
A filename,
a binary mode file-like object with a :meth:`~file.write` method,
or :obj:`None`.
:returns:
If :obj:`target` is :obj:`None`,
... | python | def write_to_png(self, target=None):
"""Writes the contents of surface as a PNG image.
:param target:
A filename,
a binary mode file-like object with a :meth:`~file.write` method,
or :obj:`None`.
:returns:
If :obj:`target` is :obj:`None`,
... | [
"def",
"write_to_png",
"(",
"self",
",",
"target",
"=",
"None",
")",
":",
"return_bytes",
"=",
"target",
"is",
"None",
"if",
"return_bytes",
":",
"target",
"=",
"io",
".",
"BytesIO",
"(",
")",
"if",
"hasattr",
"(",
"target",
",",
"'write'",
")",
":",
... | Writes the contents of surface as a PNG image.
:param target:
A filename,
a binary mode file-like object with a :meth:`~file.write` method,
or :obj:`None`.
:returns:
If :obj:`target` is :obj:`None`,
return the PNG contents as a byte string. | [
"Writes",
"the",
"contents",
"of",
"surface",
"as",
"a",
"PNG",
"image",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L630-L653 | train |
Kozea/cairocffi | cairocffi/surfaces.py | ImageSurface.create_from_png | def create_from_png(cls, source):
"""Decode a PNG file into a new image surface.
:param source:
A filename or
a binary mode file-like object with a :meth:`~file.read` method.
If you already have a byte string in memory,
use :class:`io.BytesIO`.
:r... | python | def create_from_png(cls, source):
"""Decode a PNG file into a new image surface.
:param source:
A filename or
a binary mode file-like object with a :meth:`~file.read` method.
If you already have a byte string in memory,
use :class:`io.BytesIO`.
:r... | [
"def",
"create_from_png",
"(",
"cls",
",",
"source",
")",
":",
"if",
"hasattr",
"(",
"source",
",",
"'read'",
")",
":",
"read_func",
"=",
"_make_read_func",
"(",
"source",
")",
"pointer",
"=",
"cairo",
".",
"cairo_image_surface_create_from_png_stream",
"(",
"r... | Decode a PNG file into a new image surface.
:param source:
A filename or
a binary mode file-like object with a :meth:`~file.read` method.
If you already have a byte string in memory,
use :class:`io.BytesIO`.
:returns: A new :class:`ImageSurface` instance. | [
"Decode",
"a",
"PNG",
"file",
"into",
"a",
"new",
"image",
"surface",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L742-L762 | train |
Kozea/cairocffi | cairocffi/surfaces.py | PDFSurface.add_outline | def add_outline(self, parent_id, utf8, link_attribs, flags=None):
"""Add an item to the document outline hierarchy.
The outline has the ``utf8`` name and links to the location specified
by ``link_attribs``. Link attributes have the same keys and values as
the Link Tag, excluding the ``r... | python | def add_outline(self, parent_id, utf8, link_attribs, flags=None):
"""Add an item to the document outline hierarchy.
The outline has the ``utf8`` name and links to the location specified
by ``link_attribs``. Link attributes have the same keys and values as
the Link Tag, excluding the ``r... | [
"def",
"add_outline",
"(",
"self",
",",
"parent_id",
",",
"utf8",
",",
"link_attribs",
",",
"flags",
"=",
"None",
")",
":",
"if",
"flags",
"is",
"None",
":",
"flags",
"=",
"0",
"value",
"=",
"cairo",
".",
"cairo_pdf_surface_add_outline",
"(",
"self",
"."... | Add an item to the document outline hierarchy.
The outline has the ``utf8`` name and links to the location specified
by ``link_attribs``. Link attributes have the same keys and values as
the Link Tag, excluding the ``rect`` attribute. The item will be a
child of the item with id ``paren... | [
"Add",
"an",
"item",
"to",
"the",
"document",
"outline",
"hierarchy",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L873-L903 | train |
Kozea/cairocffi | cairocffi/surfaces.py | PDFSurface.set_metadata | def set_metadata(self, metadata, utf8):
"""Sets document metadata.
The ``PDF_METADATA_CREATE_DATE`` and ``PDF_METADATA_MOD_DATE``
values must be in ISO-8601 format: YYYY-MM-DDThh:mm:ss. An optional
timezone of the form "[+/-]hh:mm" or "Z" for UTC time can be appended.
All other ... | python | def set_metadata(self, metadata, utf8):
"""Sets document metadata.
The ``PDF_METADATA_CREATE_DATE`` and ``PDF_METADATA_MOD_DATE``
values must be in ISO-8601 format: YYYY-MM-DDThh:mm:ss. An optional
timezone of the form "[+/-]hh:mm" or "Z" for UTC time can be appended.
All other ... | [
"def",
"set_metadata",
"(",
"self",
",",
"metadata",
",",
"utf8",
")",
":",
"cairo",
".",
"cairo_pdf_surface_set_metadata",
"(",
"self",
".",
"_pointer",
",",
"metadata",
",",
"_encode_string",
"(",
"utf8",
")",
")",
"self",
".",
"_check_status",
"(",
")"
] | Sets document metadata.
The ``PDF_METADATA_CREATE_DATE`` and ``PDF_METADATA_MOD_DATE``
values must be in ISO-8601 format: YYYY-MM-DDThh:mm:ss. An optional
timezone of the form "[+/-]hh:mm" or "Z" for UTC time can be appended.
All other metadata values can be any UTF-8 string.
:... | [
"Sets",
"document",
"metadata",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L905-L923 | train |
Kozea/cairocffi | cairocffi/surfaces.py | PDFSurface.set_thumbnail_size | def set_thumbnail_size(self, width, height):
"""Set thumbnail image size for the current and all subsequent pages.
Setting a width or height of 0 disables thumbnails for the current and
subsequent pages.
:param width: thumbnail width.
:param height: thumbnail height.
*... | python | def set_thumbnail_size(self, width, height):
"""Set thumbnail image size for the current and all subsequent pages.
Setting a width or height of 0 disables thumbnails for the current and
subsequent pages.
:param width: thumbnail width.
:param height: thumbnail height.
*... | [
"def",
"set_thumbnail_size",
"(",
"self",
",",
"width",
",",
"height",
")",
":",
"cairo",
".",
"cairo_pdf_surface_set_thumbnail_size",
"(",
"self",
".",
"_pointer",
",",
"width",
",",
"height",
")"
] | Set thumbnail image size for the current and all subsequent pages.
Setting a width or height of 0 disables thumbnails for the current and
subsequent pages.
:param width: thumbnail width.
:param height: thumbnail height.
*New in cairo 1.16.*
*New in cairocffi 0.9.* | [
"Set",
"thumbnail",
"image",
"size",
"for",
"the",
"current",
"and",
"all",
"subsequent",
"pages",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L938-L953 | train |
Kozea/cairocffi | cairocffi/surfaces.py | PSSurface.dsc_comment | def dsc_comment(self, comment):
""" Emit a comment into the PostScript output for the given surface.
The comment is expected to conform to
the PostScript Language Document Structuring Conventions (DSC).
Please see that manual for details on the available comments
and their meani... | python | def dsc_comment(self, comment):
""" Emit a comment into the PostScript output for the given surface.
The comment is expected to conform to
the PostScript Language Document Structuring Conventions (DSC).
Please see that manual for details on the available comments
and their meani... | [
"def",
"dsc_comment",
"(",
"self",
",",
"comment",
")",
":",
"cairo",
".",
"cairo_ps_surface_dsc_comment",
"(",
"self",
".",
"_pointer",
",",
"_encode_string",
"(",
"comment",
")",
")",
"self",
".",
"_check_status",
"(",
")"
] | Emit a comment into the PostScript output for the given surface.
The comment is expected to conform to
the PostScript Language Document Structuring Conventions (DSC).
Please see that manual for details on the available comments
and their meanings.
In particular, the ``%%IncludeF... | [
"Emit",
"a",
"comment",
"into",
"the",
"PostScript",
"output",
"for",
"the",
"given",
"surface",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L1047-L1123 | train |
Kozea/cairocffi | cairocffi/surfaces.py | SVGSurface.set_document_unit | def set_document_unit(self, unit):
"""Use specified unit for width and height of generated SVG file.
See ``SVG_UNIT_*`` enumerated values for a list of available unit
values that can be used here.
This function can be called at any time before generating the SVG file.
However ... | python | def set_document_unit(self, unit):
"""Use specified unit for width and height of generated SVG file.
See ``SVG_UNIT_*`` enumerated values for a list of available unit
values that can be used here.
This function can be called at any time before generating the SVG file.
However ... | [
"def",
"set_document_unit",
"(",
"self",
",",
"unit",
")",
":",
"cairo",
".",
"cairo_svg_surface_set_document_unit",
"(",
"self",
".",
"_pointer",
",",
"unit",
")",
"self",
".",
"_check_status",
"(",
")"
] | Use specified unit for width and height of generated SVG file.
See ``SVG_UNIT_*`` enumerated values for a list of available unit
values that can be used here.
This function can be called at any time before generating the SVG file.
However to minimize the risk of ambiguities it's recom... | [
"Use",
"specified",
"unit",
"for",
"width",
"and",
"height",
"of",
"generated",
"SVG",
"file",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L1309-L1336 | train |
Kozea/cairocffi | cairocffi/surfaces.py | SVGSurface.get_document_unit | def get_document_unit(self):
"""Get the unit of the SVG surface.
If the surface passed as an argument is not a SVG surface, the function
sets the error status to ``STATUS_SURFACE_TYPE_MISMATCH`` and
returns :ref:`SVG_UNIT_USER`.
:return: The SVG unit of the SVG surface.
... | python | def get_document_unit(self):
"""Get the unit of the SVG surface.
If the surface passed as an argument is not a SVG surface, the function
sets the error status to ``STATUS_SURFACE_TYPE_MISMATCH`` and
returns :ref:`SVG_UNIT_USER`.
:return: The SVG unit of the SVG surface.
... | [
"def",
"get_document_unit",
"(",
"self",
")",
":",
"unit",
"=",
"cairo",
".",
"cairo_svg_surface_get_document_unit",
"(",
"self",
".",
"_pointer",
")",
"self",
".",
"_check_status",
"(",
")",
"return",
"unit"
] | Get the unit of the SVG surface.
If the surface passed as an argument is not a SVG surface, the function
sets the error status to ``STATUS_SURFACE_TYPE_MISMATCH`` and
returns :ref:`SVG_UNIT_USER`.
:return: The SVG unit of the SVG surface.
*New in cairo 1.16.*
*New in ... | [
"Get",
"the",
"unit",
"of",
"the",
"SVG",
"surface",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L1338-L1354 | train |
Kozea/cairocffi | cairocffi/surfaces.py | RecordingSurface.get_extents | def get_extents(self):
"""Return the extents of the recording-surface.
:returns:
A ``(x, y, width, height)`` tuple of floats,
or :obj:`None` if the surface is unbounded.
*New in cairo 1.12*
"""
extents = ffi.new('cairo_rectangle_t *')
if cairo.c... | python | def get_extents(self):
"""Return the extents of the recording-surface.
:returns:
A ``(x, y, width, height)`` tuple of floats,
or :obj:`None` if the surface is unbounded.
*New in cairo 1.12*
"""
extents = ffi.new('cairo_rectangle_t *')
if cairo.c... | [
"def",
"get_extents",
"(",
"self",
")",
":",
"extents",
"=",
"ffi",
".",
"new",
"(",
"'cairo_rectangle_t *'",
")",
"if",
"cairo",
".",
"cairo_recording_surface_get_extents",
"(",
"self",
".",
"_pointer",
",",
"extents",
")",
":",
"return",
"(",
"extents",
".... | Return the extents of the recording-surface.
:returns:
A ``(x, y, width, height)`` tuple of floats,
or :obj:`None` if the surface is unbounded.
*New in cairo 1.12* | [
"Return",
"the",
"extents",
"of",
"the",
"recording",
"-",
"surface",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/surfaces.py#L1430-L1442 | train |
Kozea/cairocffi | cairocffi/patterns.py | Gradient.add_color_stop_rgba | def add_color_stop_rgba(self, offset, red, green, blue, alpha=1):
"""Adds a translucent color stop to a gradient pattern.
The offset specifies the location along the gradient's control vector.
For example,
a linear gradient's control vector is from (x0,y0) to (x1,y1)
while a rad... | python | def add_color_stop_rgba(self, offset, red, green, blue, alpha=1):
"""Adds a translucent color stop to a gradient pattern.
The offset specifies the location along the gradient's control vector.
For example,
a linear gradient's control vector is from (x0,y0) to (x1,y1)
while a rad... | [
"def",
"add_color_stop_rgba",
"(",
"self",
",",
"offset",
",",
"red",
",",
"green",
",",
"blue",
",",
"alpha",
"=",
"1",
")",
":",
"cairo",
".",
"cairo_pattern_add_color_stop_rgba",
"(",
"self",
".",
"_pointer",
",",
"offset",
",",
"red",
",",
"green",
"... | Adds a translucent color stop to a gradient pattern.
The offset specifies the location along the gradient's control vector.
For example,
a linear gradient's control vector is from (x0,y0) to (x1,y1)
while a radial gradient's control vector is
from any point on the start circle
... | [
"Adds",
"a",
"translucent",
"color",
"stop",
"to",
"a",
"gradient",
"pattern",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/patterns.py#L219-L255 | train |
Kozea/cairocffi | cairocffi/fonts.py | _encode_string | def _encode_string(string):
"""Return a byte string, encoding Unicode with UTF-8."""
if not isinstance(string, bytes):
string = string.encode('utf8')
return ffi.new('char[]', string) | python | def _encode_string(string):
"""Return a byte string, encoding Unicode with UTF-8."""
if not isinstance(string, bytes):
string = string.encode('utf8')
return ffi.new('char[]', string) | [
"def",
"_encode_string",
"(",
"string",
")",
":",
"if",
"not",
"isinstance",
"(",
"string",
",",
"bytes",
")",
":",
"string",
"=",
"string",
".",
"encode",
"(",
"'utf8'",
")",
"return",
"ffi",
".",
"new",
"(",
"'char[]'",
",",
"string",
")"
] | Return a byte string, encoding Unicode with UTF-8. | [
"Return",
"a",
"byte",
"string",
"encoding",
"Unicode",
"with",
"UTF",
"-",
"8",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/fonts.py#L16-L20 | train |
Kozea/cairocffi | cairocffi/fonts.py | ScaledFont.text_to_glyphs | def text_to_glyphs(self, x, y, text, with_clusters):
"""Converts a string of text to a list of glyphs,
optionally with cluster mapping,
that can be used to render later using this scaled font.
The output values can be readily passed to
:meth:`Context.show_text_glyphs`, :meth:`Co... | python | def text_to_glyphs(self, x, y, text, with_clusters):
"""Converts a string of text to a list of glyphs,
optionally with cluster mapping,
that can be used to render later using this scaled font.
The output values can be readily passed to
:meth:`Context.show_text_glyphs`, :meth:`Co... | [
"def",
"text_to_glyphs",
"(",
"self",
",",
"x",
",",
"y",
",",
"text",
",",
"with_clusters",
")",
":",
"glyphs",
"=",
"ffi",
".",
"new",
"(",
"'cairo_glyph_t **'",
",",
"ffi",
".",
"NULL",
")",
"num_glyphs",
"=",
"ffi",
".",
"new",
"(",
"'int *'",
")... | Converts a string of text to a list of glyphs,
optionally with cluster mapping,
that can be used to render later using this scaled font.
The output values can be readily passed to
:meth:`Context.show_text_glyphs`, :meth:`Context.show_glyphs`
or related methods,
assuming ... | [
"Converts",
"a",
"string",
"of",
"text",
"to",
"a",
"list",
"of",
"glyphs",
"optionally",
"with",
"cluster",
"mapping",
"that",
"can",
"be",
"used",
"to",
"render",
"later",
"using",
"this",
"scaled",
"font",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/fonts.py#L301-L366 | train |
Kozea/cairocffi | cairocffi/fonts.py | FontOptions.set_variations | def set_variations(self, variations):
"""Sets the OpenType font variations for the font options object.
Font variations are specified as a string with a format that is similar
to the CSS font-variation-settings. The string contains a
comma-separated list of axis assignments, which each ... | python | def set_variations(self, variations):
"""Sets the OpenType font variations for the font options object.
Font variations are specified as a string with a format that is similar
to the CSS font-variation-settings. The string contains a
comma-separated list of axis assignments, which each ... | [
"def",
"set_variations",
"(",
"self",
",",
"variations",
")",
":",
"if",
"variations",
"is",
"None",
":",
"variations",
"=",
"ffi",
".",
"NULL",
"else",
":",
"variations",
"=",
"_encode_string",
"(",
"variations",
")",
"cairo",
".",
"cairo_font_options_set_var... | Sets the OpenType font variations for the font options object.
Font variations are specified as a string with a format that is similar
to the CSS font-variation-settings. The string contains a
comma-separated list of axis assignments, which each assignment
consists of a 4-character axis... | [
"Sets",
"the",
"OpenType",
"font",
"variations",
"for",
"the",
"font",
"options",
"object",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/fonts.py#L494-L515 | train |
Kozea/cairocffi | cairocffi/fonts.py | FontOptions.get_variations | def get_variations(self):
"""Gets the OpenType font variations for the font options object.
See :meth:`set_variations` for details about the
string format.
:return: the font variations for the font options object. The
returned string belongs to the ``options`` and must not be m... | python | def get_variations(self):
"""Gets the OpenType font variations for the font options object.
See :meth:`set_variations` for details about the
string format.
:return: the font variations for the font options object. The
returned string belongs to the ``options`` and must not be m... | [
"def",
"get_variations",
"(",
"self",
")",
":",
"variations",
"=",
"cairo",
".",
"cairo_font_options_get_variations",
"(",
"self",
".",
"_pointer",
")",
"if",
"variations",
"!=",
"ffi",
".",
"NULL",
":",
"return",
"ffi",
".",
"string",
"(",
"variations",
")"... | Gets the OpenType font variations for the font options object.
See :meth:`set_variations` for details about the
string format.
:return: the font variations for the font options object. The
returned string belongs to the ``options`` and must not be modified.
It is valid until ei... | [
"Gets",
"the",
"OpenType",
"font",
"variations",
"for",
"the",
"font",
"options",
"object",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/fonts.py#L517-L535 | train |
Kozea/cairocffi | cairocffi/pixbuf.py | decode_to_pixbuf | def decode_to_pixbuf(image_data, width=None, height=None):
"""Decode an image from memory with GDK-PixBuf.
The file format is detected automatically.
:param image_data: A byte string
:param width: Integer width in pixels or None
:param height: Integer height in pixels or None
:returns:
... | python | def decode_to_pixbuf(image_data, width=None, height=None):
"""Decode an image from memory with GDK-PixBuf.
The file format is detected automatically.
:param image_data: A byte string
:param width: Integer width in pixels or None
:param height: Integer height in pixels or None
:returns:
... | [
"def",
"decode_to_pixbuf",
"(",
"image_data",
",",
"width",
"=",
"None",
",",
"height",
"=",
"None",
")",
":",
"loader",
"=",
"ffi",
".",
"gc",
"(",
"gdk_pixbuf",
".",
"gdk_pixbuf_loader_new",
"(",
")",
",",
"gobject",
".",
"g_object_unref",
")",
"error",
... | Decode an image from memory with GDK-PixBuf.
The file format is detected automatically.
:param image_data: A byte string
:param width: Integer width in pixels or None
:param height: Integer height in pixels or None
:returns:
A tuple of a new :class:`PixBuf` object
and the name of th... | [
"Decode",
"an",
"image",
"from",
"memory",
"with",
"GDK",
"-",
"PixBuf",
".",
"The",
"file",
"format",
"is",
"detected",
"automatically",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/pixbuf.py#L69-L102 | train |
Kozea/cairocffi | cairocffi/pixbuf.py | decode_to_image_surface | def decode_to_image_surface(image_data, width=None, height=None):
"""Decode an image from memory into a cairo surface.
The file format is detected automatically.
:param image_data: A byte string
:param width: Integer width in pixels or None
:param height: Integer height in pixels or None
:retur... | python | def decode_to_image_surface(image_data, width=None, height=None):
"""Decode an image from memory into a cairo surface.
The file format is detected automatically.
:param image_data: A byte string
:param width: Integer width in pixels or None
:param height: Integer height in pixels or None
:retur... | [
"def",
"decode_to_image_surface",
"(",
"image_data",
",",
"width",
"=",
"None",
",",
"height",
"=",
"None",
")",
":",
"pixbuf",
",",
"format_name",
"=",
"decode_to_pixbuf",
"(",
"image_data",
",",
"width",
",",
"height",
")",
"surface",
"=",
"(",
"pixbuf_to_... | Decode an image from memory into a cairo surface.
The file format is detected automatically.
:param image_data: A byte string
:param width: Integer width in pixels or None
:param height: Integer height in pixels or None
:returns:
A tuple of a new :class:`~cairocffi.ImageSurface` object
... | [
"Decode",
"an",
"image",
"from",
"memory",
"into",
"a",
"cairo",
"surface",
".",
"The",
"file",
"format",
"is",
"detected",
"automatically",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/pixbuf.py#L105-L125 | train |
Kozea/cairocffi | cairocffi/pixbuf.py | pixbuf_to_cairo_gdk | def pixbuf_to_cairo_gdk(pixbuf):
"""Convert from PixBuf to ImageSurface, using GDK.
This method is fastest but GDK is not always available.
"""
dummy_context = Context(ImageSurface(constants.FORMAT_ARGB32, 1, 1))
gdk.gdk_cairo_set_source_pixbuf(
dummy_context._pointer, pixbuf._pointer, 0, ... | python | def pixbuf_to_cairo_gdk(pixbuf):
"""Convert from PixBuf to ImageSurface, using GDK.
This method is fastest but GDK is not always available.
"""
dummy_context = Context(ImageSurface(constants.FORMAT_ARGB32, 1, 1))
gdk.gdk_cairo_set_source_pixbuf(
dummy_context._pointer, pixbuf._pointer, 0, ... | [
"def",
"pixbuf_to_cairo_gdk",
"(",
"pixbuf",
")",
":",
"dummy_context",
"=",
"Context",
"(",
"ImageSurface",
"(",
"constants",
".",
"FORMAT_ARGB32",
",",
"1",
",",
"1",
")",
")",
"gdk",
".",
"gdk_cairo_set_source_pixbuf",
"(",
"dummy_context",
".",
"_pointer",
... | Convert from PixBuf to ImageSurface, using GDK.
This method is fastest but GDK is not always available. | [
"Convert",
"from",
"PixBuf",
"to",
"ImageSurface",
"using",
"GDK",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/pixbuf.py#L128-L137 | train |
Kozea/cairocffi | cairocffi/pixbuf.py | pixbuf_to_cairo_slices | def pixbuf_to_cairo_slices(pixbuf):
"""Convert from PixBuf to ImageSurface, using slice-based byte swapping.
This method is 2~5x slower than GDK but does not support an alpha channel.
(cairo uses pre-multiplied alpha, but not Pixbuf.)
"""
assert pixbuf.get_colorspace() == gdk_pixbuf.GDK_COLORSPACE... | python | def pixbuf_to_cairo_slices(pixbuf):
"""Convert from PixBuf to ImageSurface, using slice-based byte swapping.
This method is 2~5x slower than GDK but does not support an alpha channel.
(cairo uses pre-multiplied alpha, but not Pixbuf.)
"""
assert pixbuf.get_colorspace() == gdk_pixbuf.GDK_COLORSPACE... | [
"def",
"pixbuf_to_cairo_slices",
"(",
"pixbuf",
")",
":",
"assert",
"pixbuf",
".",
"get_colorspace",
"(",
")",
"==",
"gdk_pixbuf",
".",
"GDK_COLORSPACE_RGB",
"assert",
"pixbuf",
".",
"get_n_channels",
"(",
")",
"==",
"3",
"assert",
"pixbuf",
".",
"get_bits_per_s... | Convert from PixBuf to ImageSurface, using slice-based byte swapping.
This method is 2~5x slower than GDK but does not support an alpha channel.
(cairo uses pre-multiplied alpha, but not Pixbuf.) | [
"Convert",
"from",
"PixBuf",
"to",
"ImageSurface",
"using",
"slice",
"-",
"based",
"byte",
"swapping",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/pixbuf.py#L140-L187 | train |
Kozea/cairocffi | cairocffi/pixbuf.py | pixbuf_to_cairo_png | def pixbuf_to_cairo_png(pixbuf):
"""Convert from PixBuf to ImageSurface, by going through the PNG format.
This method is 10~30x slower than GDK but always works.
"""
buffer_pointer = ffi.new('gchar **')
buffer_size = ffi.new('gsize *')
error = ffi.new('GError **')
handle_g_error(error, pix... | python | def pixbuf_to_cairo_png(pixbuf):
"""Convert from PixBuf to ImageSurface, by going through the PNG format.
This method is 10~30x slower than GDK but always works.
"""
buffer_pointer = ffi.new('gchar **')
buffer_size = ffi.new('gsize *')
error = ffi.new('GError **')
handle_g_error(error, pix... | [
"def",
"pixbuf_to_cairo_png",
"(",
"pixbuf",
")",
":",
"buffer_pointer",
"=",
"ffi",
".",
"new",
"(",
"'gchar **'",
")",
"buffer_size",
"=",
"ffi",
".",
"new",
"(",
"'gsize *'",
")",
"error",
"=",
"ffi",
".",
"new",
"(",
"'GError **'",
")",
"handle_g_error... | Convert from PixBuf to ImageSurface, by going through the PNG format.
This method is 10~30x slower than GDK but always works. | [
"Convert",
"from",
"PixBuf",
"to",
"ImageSurface",
"by",
"going",
"through",
"the",
"PNG",
"format",
"."
] | 450853add7e32eea20985b6aa5f54d9cb3cd04fe | https://github.com/Kozea/cairocffi/blob/450853add7e32eea20985b6aa5f54d9cb3cd04fe/cairocffi/pixbuf.py#L190-L204 | train |
coderholic/pyradio | pyradio/player.py | probePlayer | def probePlayer(requested_player=''):
""" Probes the multimedia players which are available on the host
system."""
ret_player = None
if logger.isEnabledFor(logging.INFO):
logger.info("Probing available multimedia players...")
implementedPlayers = Player.__subclasses__()
if logger.isEnabl... | python | def probePlayer(requested_player=''):
""" Probes the multimedia players which are available on the host
system."""
ret_player = None
if logger.isEnabledFor(logging.INFO):
logger.info("Probing available multimedia players...")
implementedPlayers = Player.__subclasses__()
if logger.isEnabl... | [
"def",
"probePlayer",
"(",
"requested_player",
"=",
"''",
")",
":",
"ret_player",
"=",
"None",
"if",
"logger",
".",
"isEnabledFor",
"(",
"logging",
".",
"INFO",
")",
":",
"logger",
".",
"info",
"(",
"\"Probing available multimedia players...\"",
")",
"implemente... | Probes the multimedia players which are available on the host
system. | [
"Probes",
"the",
"multimedia",
"players",
"which",
"are",
"available",
"on",
"the",
"host",
"system",
"."
] | c5219d350bccbccd49dbd627c1f886a952ea1963 | https://github.com/coderholic/pyradio/blob/c5219d350bccbccd49dbd627c1f886a952ea1963/pyradio/player.py#L763-L793 | train |
coderholic/pyradio | pyradio/player.py | Player.play | def play(self, name, streamUrl, encoding = ''):
""" use a multimedia player to play a stream """
self.close()
self.name = name
self.oldUserInput = {'Input': '', 'Volume': '', 'Title': ''}
self.muted = False
self.show_volume = True
self.title_prefix = ''
se... | python | def play(self, name, streamUrl, encoding = ''):
""" use a multimedia player to play a stream """
self.close()
self.name = name
self.oldUserInput = {'Input': '', 'Volume': '', 'Title': ''}
self.muted = False
self.show_volume = True
self.title_prefix = ''
se... | [
"def",
"play",
"(",
"self",
",",
"name",
",",
"streamUrl",
",",
"encoding",
"=",
"''",
")",
":",
"self",
".",
"close",
"(",
")",
"self",
".",
"name",
"=",
"name",
"self",
".",
"oldUserInput",
"=",
"{",
"'Input'",
":",
"''",
",",
"'Volume'",
":",
... | use a multimedia player to play a stream | [
"use",
"a",
"multimedia",
"player",
"to",
"play",
"a",
"stream"
] | c5219d350bccbccd49dbd627c1f886a952ea1963 | https://github.com/coderholic/pyradio/blob/c5219d350bccbccd49dbd627c1f886a952ea1963/pyradio/player.py#L285-L319 | train |
coderholic/pyradio | pyradio/player.py | Player._sendCommand | def _sendCommand(self, command):
""" send keystroke command to player """
if(self.process is not None):
try:
if logger.isEnabledFor(logging.DEBUG):
logger.debug("Command: {}".format(command).strip())
self.process.stdin.write(command.encode... | python | def _sendCommand(self, command):
""" send keystroke command to player """
if(self.process is not None):
try:
if logger.isEnabledFor(logging.DEBUG):
logger.debug("Command: {}".format(command).strip())
self.process.stdin.write(command.encode... | [
"def",
"_sendCommand",
"(",
"self",
",",
"command",
")",
":",
"if",
"(",
"self",
".",
"process",
"is",
"not",
"None",
")",
":",
"try",
":",
"if",
"logger",
".",
"isEnabledFor",
"(",
"logging",
".",
"DEBUG",
")",
":",
"logger",
".",
"debug",
"(",
"\... | send keystroke command to player | [
"send",
"keystroke",
"command",
"to",
"player"
] | c5219d350bccbccd49dbd627c1f886a952ea1963 | https://github.com/coderholic/pyradio/blob/c5219d350bccbccd49dbd627c1f886a952ea1963/pyradio/player.py#L321-L333 | train |
coderholic/pyradio | pyradio/player.py | MpvPlayer._format_title_string | def _format_title_string(self, title_string):
""" format mpv's title """
return self._title_string_format_text_tag(title_string.replace(self.icy_tokkens[0], self.icy_title_prefix)) | python | def _format_title_string(self, title_string):
""" format mpv's title """
return self._title_string_format_text_tag(title_string.replace(self.icy_tokkens[0], self.icy_title_prefix)) | [
"def",
"_format_title_string",
"(",
"self",
",",
"title_string",
")",
":",
"return",
"self",
".",
"_title_string_format_text_tag",
"(",
"title_string",
".",
"replace",
"(",
"self",
".",
"icy_tokkens",
"[",
"0",
"]",
",",
"self",
".",
"icy_title_prefix",
")",
"... | format mpv's title | [
"format",
"mpv",
"s",
"title"
] | c5219d350bccbccd49dbd627c1f886a952ea1963 | https://github.com/coderholic/pyradio/blob/c5219d350bccbccd49dbd627c1f886a952ea1963/pyradio/player.py#L529-L531 | train |
coderholic/pyradio | pyradio/player.py | MpPlayer._format_title_string | def _format_title_string(self, title_string):
""" format mplayer's title """
if "StreamTitle='" in title_string:
tmp = title_string[title_string.find("StreamTitle='"):].replace("StreamTitle='", self.icy_title_prefix)
ret_string = tmp[:tmp.find("';")]
else:
ret... | python | def _format_title_string(self, title_string):
""" format mplayer's title """
if "StreamTitle='" in title_string:
tmp = title_string[title_string.find("StreamTitle='"):].replace("StreamTitle='", self.icy_title_prefix)
ret_string = tmp[:tmp.find("';")]
else:
ret... | [
"def",
"_format_title_string",
"(",
"self",
",",
"title_string",
")",
":",
"if",
"\"StreamTitle='\"",
"in",
"title_string",
":",
"tmp",
"=",
"title_string",
"[",
"title_string",
".",
"find",
"(",
"\"StreamTitle='\"",
")",
":",
"]",
".",
"replace",
"(",
"\"Stre... | format mplayer's title | [
"format",
"mplayer",
"s",
"title"
] | c5219d350bccbccd49dbd627c1f886a952ea1963 | https://github.com/coderholic/pyradio/blob/c5219d350bccbccd49dbd627c1f886a952ea1963/pyradio/player.py#L625-L638 | train |
coderholic/pyradio | pyradio/player.py | MpPlayer._format_volume_string | def _format_volume_string(self, volume_string):
""" format mplayer's volume """
return '[' + volume_string[volume_string.find(self.volume_string):].replace(' %','%').replace('ume', '')+'] ' | python | def _format_volume_string(self, volume_string):
""" format mplayer's volume """
return '[' + volume_string[volume_string.find(self.volume_string):].replace(' %','%').replace('ume', '')+'] ' | [
"def",
"_format_volume_string",
"(",
"self",
",",
"volume_string",
")",
":",
"return",
"'['",
"+",
"volume_string",
"[",
"volume_string",
".",
"find",
"(",
"self",
".",
"volume_string",
")",
":",
"]",
".",
"replace",
"(",
"' %'",
",",
"'%'",
")",
".",
"r... | format mplayer's volume | [
"format",
"mplayer",
"s",
"volume"
] | c5219d350bccbccd49dbd627c1f886a952ea1963 | https://github.com/coderholic/pyradio/blob/c5219d350bccbccd49dbd627c1f886a952ea1963/pyradio/player.py#L640-L642 | train |
coderholic/pyradio | pyradio/player.py | VlcPlayer._format_volume_string | def _format_volume_string(self, volume_string):
""" format vlc's volume """
self.actual_volume = int(volume_string.split(self.volume_string)[1].split(',')[0].split()[0])
return '[Vol: {}%] '.format(int(100 * self.actual_volume / self.max_volume)) | python | def _format_volume_string(self, volume_string):
""" format vlc's volume """
self.actual_volume = int(volume_string.split(self.volume_string)[1].split(',')[0].split()[0])
return '[Vol: {}%] '.format(int(100 * self.actual_volume / self.max_volume)) | [
"def",
"_format_volume_string",
"(",
"self",
",",
"volume_string",
")",
":",
"self",
".",
"actual_volume",
"=",
"int",
"(",
"volume_string",
".",
"split",
"(",
"self",
".",
"volume_string",
")",
"[",
"1",
"]",
".",
"split",
"(",
"','",
")",
"[",
"0",
"... | format vlc's volume | [
"format",
"vlc",
"s",
"volume"
] | c5219d350bccbccd49dbd627c1f886a952ea1963 | https://github.com/coderholic/pyradio/blob/c5219d350bccbccd49dbd627c1f886a952ea1963/pyradio/player.py#L706-L709 | train |
coderholic/pyradio | pyradio/player.py | VlcPlayer._format_title_string | def _format_title_string(self, title_string):
""" format vlc's title """
sp = title_string.split(self.icy_tokkens[0])
if sp[0] == title_string:
ret_string = title_string
else:
ret_string = self.icy_title_prefix + sp[1]
return self._title_string_format_text... | python | def _format_title_string(self, title_string):
""" format vlc's title """
sp = title_string.split(self.icy_tokkens[0])
if sp[0] == title_string:
ret_string = title_string
else:
ret_string = self.icy_title_prefix + sp[1]
return self._title_string_format_text... | [
"def",
"_format_title_string",
"(",
"self",
",",
"title_string",
")",
":",
"sp",
"=",
"title_string",
".",
"split",
"(",
"self",
".",
"icy_tokkens",
"[",
"0",
"]",
")",
"if",
"sp",
"[",
"0",
"]",
"==",
"title_string",
":",
"ret_string",
"=",
"title_strin... | format vlc's title | [
"format",
"vlc",
"s",
"title"
] | c5219d350bccbccd49dbd627c1f886a952ea1963 | https://github.com/coderholic/pyradio/blob/c5219d350bccbccd49dbd627c1f886a952ea1963/pyradio/player.py#L711-L718 | train |
coderholic/pyradio | pyradio/player.py | VlcPlayer._is_accepted_input | def _is_accepted_input(self, input_string):
""" vlc input filtering """
ret = False
accept_filter = (self.volume_string, "http stream debug: ")
reject_filter = ()
for n in accept_filter:
if n in input_string:
ret = True
break
if... | python | def _is_accepted_input(self, input_string):
""" vlc input filtering """
ret = False
accept_filter = (self.volume_string, "http stream debug: ")
reject_filter = ()
for n in accept_filter:
if n in input_string:
ret = True
break
if... | [
"def",
"_is_accepted_input",
"(",
"self",
",",
"input_string",
")",
":",
"ret",
"=",
"False",
"accept_filter",
"=",
"(",
"self",
".",
"volume_string",
",",
"\"http stream debug: \"",
")",
"reject_filter",
"=",
"(",
")",
"for",
"n",
"in",
"accept_filter",
":",
... | vlc input filtering | [
"vlc",
"input",
"filtering"
] | c5219d350bccbccd49dbd627c1f886a952ea1963 | https://github.com/coderholic/pyradio/blob/c5219d350bccbccd49dbd627c1f886a952ea1963/pyradio/player.py#L720-L734 | train |
coderholic/pyradio | pyradio/player.py | VlcPlayer._no_mute_on_stop_playback | def _no_mute_on_stop_playback(self):
""" make sure vlc does not stop muted """
if self.ctrl_c_pressed:
return
if self.isPlaying():
if self.actual_volume == -1:
self._get_volume()
while self.actual_volume == -1:
pass
... | python | def _no_mute_on_stop_playback(self):
""" make sure vlc does not stop muted """
if self.ctrl_c_pressed:
return
if self.isPlaying():
if self.actual_volume == -1:
self._get_volume()
while self.actual_volume == -1:
pass
... | [
"def",
"_no_mute_on_stop_playback",
"(",
"self",
")",
":",
"if",
"self",
".",
"ctrl_c_pressed",
":",
"return",
"if",
"self",
".",
"isPlaying",
"(",
")",
":",
"if",
"self",
".",
"actual_volume",
"==",
"-",
"1",
":",
"self",
".",
"_get_volume",
"(",
")",
... | make sure vlc does not stop muted | [
"make",
"sure",
"vlc",
"does",
"not",
"stop",
"muted"
] | c5219d350bccbccd49dbd627c1f886a952ea1963 | https://github.com/coderholic/pyradio/blob/c5219d350bccbccd49dbd627c1f886a952ea1963/pyradio/player.py#L741-L761 | train |
coderholic/pyradio | pyradio/config.py | PyRadioStations._check_stations_csv | def _check_stations_csv(self, usr, root):
''' Reclocate a stations.csv copy in user home for easy manage.
E.g. not need sudo when you add new station, etc '''
if path.exists(path.join(usr, 'stations.csv')):
return
else:
copyfile(root, path.join(usr, 'stations... | python | def _check_stations_csv(self, usr, root):
''' Reclocate a stations.csv copy in user home for easy manage.
E.g. not need sudo when you add new station, etc '''
if path.exists(path.join(usr, 'stations.csv')):
return
else:
copyfile(root, path.join(usr, 'stations... | [
"def",
"_check_stations_csv",
"(",
"self",
",",
"usr",
",",
"root",
")",
":",
"if",
"path",
".",
"exists",
"(",
"path",
".",
"join",
"(",
"usr",
",",
"'stations.csv'",
")",
")",
":",
"return",
"else",
":",
"copyfile",
"(",
"root",
",",
"path",
".",
... | Reclocate a stations.csv copy in user home for easy manage.
E.g. not need sudo when you add new station, etc | [
"Reclocate",
"a",
"stations",
".",
"csv",
"copy",
"in",
"user",
"home",
"for",
"easy",
"manage",
".",
"E",
".",
"g",
".",
"not",
"need",
"sudo",
"when",
"you",
"add",
"new",
"station",
"etc"
] | c5219d350bccbccd49dbd627c1f886a952ea1963 | https://github.com/coderholic/pyradio/blob/c5219d350bccbccd49dbd627c1f886a952ea1963/pyradio/config.py#L89-L96 | train |
coderholic/pyradio | pyradio/config.py | PyRadioStations._is_playlist_in_config_dir | def _is_playlist_in_config_dir(self):
""" Check if a csv file is in the config dir """
if path.dirname(self.stations_file) == self.stations_dir:
self.foreign_file = False
self.foreign_filename_only_no_extension = ''
else:
self.foreign_file = True
s... | python | def _is_playlist_in_config_dir(self):
""" Check if a csv file is in the config dir """
if path.dirname(self.stations_file) == self.stations_dir:
self.foreign_file = False
self.foreign_filename_only_no_extension = ''
else:
self.foreign_file = True
s... | [
"def",
"_is_playlist_in_config_dir",
"(",
"self",
")",
":",
"if",
"path",
".",
"dirname",
"(",
"self",
".",
"stations_file",
")",
"==",
"self",
".",
"stations_dir",
":",
"self",
".",
"foreign_file",
"=",
"False",
"self",
".",
"foreign_filename_only_no_extension"... | Check if a csv file is in the config dir | [
"Check",
"if",
"a",
"csv",
"file",
"is",
"in",
"the",
"config",
"dir"
] | c5219d350bccbccd49dbd627c1f886a952ea1963 | https://github.com/coderholic/pyradio/blob/c5219d350bccbccd49dbd627c1f886a952ea1963/pyradio/config.py#L134-L142 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.