2015-01-02 11:03:53 -08:00
|
|
|
# Copyright (C) 2007-2015 various contributors (see AUTHORS)
|
2013-02-17 11:35:20 -08:00
|
|
|
#
|
|
|
|
# This file is part of Python-EFL.
|
|
|
|
#
|
|
|
|
# Python-EFL is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
2013-12-07 08:54:58 -08:00
|
|
|
# version 3 of the License, or (at your option) any later version.
|
2013-02-17 11:35:20 -08:00
|
|
|
#
|
|
|
|
# Python-EFL is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License
|
|
|
|
# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
2015-04-17 18:45:11 -07:00
|
|
|
include "background_cdef.pxi"
|
2013-02-17 11:35:20 -08:00
|
|
|
|
|
|
|
|
|
|
|
cdef class Background(LayoutClass):
|
2015-01-03 11:17:24 -08:00
|
|
|
"""
|
2013-02-17 11:35:20 -08:00
|
|
|
|
2015-01-03 11:17:24 -08:00
|
|
|
This is the class that actually implements the widget.
|
|
|
|
|
|
|
|
"""
|
2013-02-17 11:35:20 -08:00
|
|
|
|
2013-10-25 07:38:01 -07:00
|
|
|
def __init__(self, evasObject parent, *args, **kwargs):
|
2015-01-03 11:17:24 -08:00
|
|
|
"""Background(...)
|
|
|
|
|
|
|
|
:param parent: The parent object
|
|
|
|
:type parent: :py:class:`efl.evas.Object`
|
|
|
|
:param \**kwargs: All the remaining keyword arguments are interpreted
|
|
|
|
as properties of the instance
|
|
|
|
|
|
|
|
"""
|
2013-02-17 11:35:20 -08:00
|
|
|
self._set_obj(elm_bg_add(parent.obj))
|
2013-10-25 07:38:01 -07:00
|
|
|
self._set_properties_from_keyword_args(kwargs)
|
2013-02-17 11:35:20 -08:00
|
|
|
|
2013-12-05 01:29:12 -08:00
|
|
|
cdef int _set_properties_from_keyword_args(self, dict kwargs) except 0:
|
|
|
|
# Bypass the Evas one so that color works as expected
|
|
|
|
return Eo._set_properties_from_keyword_args(self, kwargs)
|
|
|
|
|
2013-02-17 11:35:20 -08:00
|
|
|
property file:
|
|
|
|
"""The file (image or edje collection) giving life for the background.
|
|
|
|
|
|
|
|
This property contains the image file name (and edje group) used in
|
|
|
|
the background object. If the image comes from an Edje group, it
|
|
|
|
will be stretched to completely fill the background object. If it
|
|
|
|
comes from a traditional image file, it will by default be centered
|
|
|
|
in this widget's are (thus retaining its aspect), what could lead to
|
|
|
|
some parts being not visible. You may change the mode of exhibition
|
|
|
|
for a real image file with :py:attr:`option`.
|
|
|
|
|
|
|
|
.. note:: Once the image is set, a previously set one will be deleted,
|
|
|
|
even if **file** is *None*.
|
|
|
|
|
|
|
|
.. note:: This will only affect the contents of one of the background's
|
|
|
|
swallow spots, namely *"elm.swallow.background"*. If you want to
|
2013-02-22 02:53:41 -08:00
|
|
|
achieve the :py:class:`efl.elementary.layout_class.LayoutClass`'s file setting
|
2013-02-17 11:35:20 -08:00
|
|
|
behavior, you'll have to call that method on this object.
|
|
|
|
|
2015-03-05 04:19:48 -08:00
|
|
|
:type: string **file**, *optional* string **group**
|
2013-02-17 11:35:20 -08:00
|
|
|
|
2015-03-05 04:19:48 -08:00
|
|
|
:raise RuntimeError: if setting the file failed.
|
2013-11-27 14:29:43 -08:00
|
|
|
|
2013-02-17 11:35:20 -08:00
|
|
|
"""
|
|
|
|
def __get__(self):
|
2014-01-24 12:49:18 -08:00
|
|
|
cdef:
|
2014-04-04 17:13:15 -07:00
|
|
|
const char *filename
|
|
|
|
const char *group
|
2014-01-24 12:49:18 -08:00
|
|
|
|
2013-11-04 17:09:44 -08:00
|
|
|
elm_bg_file_get(self.obj, &filename, &group)
|
|
|
|
return (_ctouni(filename), _ctouni(group))
|
2013-02-17 11:35:20 -08:00
|
|
|
|
|
|
|
def __set__(self, value):
|
2013-02-22 02:53:41 -08:00
|
|
|
cdef int ret
|
2013-02-17 11:35:20 -08:00
|
|
|
if isinstance(value, tuple) or isinstance(value, list):
|
|
|
|
filename, group = value
|
|
|
|
else:
|
|
|
|
filename = value
|
|
|
|
group = ""
|
2014-04-06 13:48:16 -07:00
|
|
|
if isinstance(filename, unicode): filename = PyUnicode_AsUTF8String(filename)
|
|
|
|
if isinstance(group, unicode): group = PyUnicode_AsUTF8String(group)
|
2013-11-04 17:09:44 -08:00
|
|
|
if not elm_bg_file_set(self.obj,
|
2014-04-04 17:13:15 -07:00
|
|
|
<const char *>filename if filename is not None else NULL,
|
|
|
|
<const char *>group if group is not None else NULL):
|
2013-11-04 17:09:44 -08:00
|
|
|
raise RuntimeError("Could not set background file.")
|
|
|
|
|
|
|
|
def file_set(self, filename, group = None):
|
2014-04-06 13:48:16 -07:00
|
|
|
if isinstance(filename, unicode): filename = PyUnicode_AsUTF8String(filename)
|
|
|
|
if isinstance(group, unicode): group = PyUnicode_AsUTF8String(group)
|
2013-04-02 04:35:20 -07:00
|
|
|
if not elm_bg_file_set(self.obj,
|
2014-04-04 17:13:15 -07:00
|
|
|
<const char *>filename if filename is not None else NULL,
|
|
|
|
<const char *>group if group is not None else NULL):
|
2013-02-22 02:53:41 -08:00
|
|
|
raise RuntimeError("Could not set background file.")
|
2013-11-04 17:09:44 -08:00
|
|
|
def file_get(self):
|
2014-01-24 12:49:18 -08:00
|
|
|
cdef:
|
2014-04-04 17:13:15 -07:00
|
|
|
const char *filename
|
|
|
|
const char *group
|
2014-01-24 12:49:18 -08:00
|
|
|
|
2013-02-17 11:35:20 -08:00
|
|
|
elm_bg_file_get(self.obj, &filename, &group)
|
|
|
|
return (_ctouni(filename), _ctouni(group))
|
|
|
|
|
|
|
|
property option:
|
|
|
|
"""The mode of display for a given background widget's image.
|
|
|
|
|
|
|
|
This property reflects how the background widget will display its
|
|
|
|
image. This will only work if :py:attr:`file` was previously set with an
|
|
|
|
image file. The image can be displayed tiled, scaled, centered or
|
|
|
|
stretched.
|
|
|
|
|
2013-04-27 07:43:22 -07:00
|
|
|
:type: :ref:`Elm_Bg_Option`
|
2013-02-17 11:35:20 -08:00
|
|
|
|
|
|
|
"""
|
|
|
|
def __get__(self):
|
|
|
|
return elm_bg_option_get(self.obj)
|
|
|
|
|
|
|
|
def __set__(self, value):
|
|
|
|
elm_bg_option_set(self.obj, value)
|
|
|
|
|
|
|
|
def option_set(self, option):
|
|
|
|
elm_bg_option_set(self.obj, option)
|
|
|
|
def option_get(self):
|
|
|
|
return elm_bg_option_get(self.obj)
|
|
|
|
|
|
|
|
property color:
|
|
|
|
"""The color on a given background widget.
|
|
|
|
|
|
|
|
This property reflects the color used for the background rectangle,
|
|
|
|
in RGB format. Each color component's range is from 0 to 255.
|
|
|
|
|
|
|
|
.. note:: You probably only want to use this property if you haven't
|
|
|
|
previously set :py:attr:`file`, so that you just want a solid color
|
|
|
|
background.
|
|
|
|
|
2013-04-27 07:43:22 -07:00
|
|
|
:type: (int **r**, int **g**, int **b**)
|
2013-02-17 11:35:20 -08:00
|
|
|
|
|
|
|
"""
|
|
|
|
def __get__(self):
|
|
|
|
cdef int r, g, b
|
|
|
|
elm_bg_color_get(self.obj, &r, &g, &b)
|
|
|
|
return (r, g, b)
|
|
|
|
|
|
|
|
def __set__(self, value):
|
|
|
|
cdef int r, g, b
|
|
|
|
r, g, b = value
|
|
|
|
elm_bg_color_set(self.obj, r, g, b)
|
|
|
|
|
|
|
|
def color_set(self, r, g, b):
|
|
|
|
elm_bg_color_set(self.obj, r, g, b)
|
|
|
|
def color_get(self):
|
|
|
|
cdef int r, g, b
|
|
|
|
elm_bg_color_get(self.obj, &r, &g, &b)
|
|
|
|
return (r, g, b)
|
|
|
|
|
|
|
|
property load_size:
|
|
|
|
"""The size of the pixmap representation of the image set on a given
|
|
|
|
background widget.
|
|
|
|
|
|
|
|
This property sets a new size for pixmap representation of the
|
|
|
|
given bg image. It allows for the image to be loaded already in the
|
|
|
|
specified size, reducing the memory usage and load time (for
|
|
|
|
example, when loading a big image file with its load size set to a
|
|
|
|
smaller size)
|
|
|
|
|
|
|
|
.. note:: This is just a hint for the underlying system. The real size
|
|
|
|
of the pixmap may differ depending on the type of image being
|
|
|
|
loaded, being bigger than requested.
|
|
|
|
|
|
|
|
.. warning:: This function just makes sense if an image file was set
|
|
|
|
with :py:attr:`file`.
|
|
|
|
|
2013-04-27 07:43:22 -07:00
|
|
|
:type: (int **w**, int **h**)
|
2013-02-17 11:35:20 -08:00
|
|
|
|
|
|
|
"""
|
|
|
|
def __set__(self, value):
|
|
|
|
cdef Evas_Coord w, h
|
|
|
|
w, h = value
|
|
|
|
elm_bg_load_size_set(self.obj, w, h)
|
|
|
|
|
|
|
|
def load_size_set(self, w, h):
|
|
|
|
elm_bg_load_size_set(self.obj, w, h)
|
|
|
|
|
2013-11-07 06:45:02 -08:00
|
|
|
_object_mapping_register("Elm_Bg", Background)
|