kuuko pushed a commit to branch master.
commit 0c9f6c7590f6915b313e8af10203971bf5f2fe7a
Author: Kai Huuhko <[email protected]>
Date: Sat Apr 20 10:30:26 2013 +0000
Elementary: Add Calendar.marks (get/del only) and improve documentation.
---
efl/elementary/calendar_elm.pxd | 8 +-
efl/elementary/calendar_elm.pyx | 202 ++++++++++++++++++++++------------------
efl/elementary/object_item.pyx | 1 +
3 files changed, 114 insertions(+), 97 deletions(-)
diff --git a/efl/elementary/calendar_elm.pxd b/efl/elementary/calendar_elm.pxd
index 98d81ae..b2cf18a 100644
--- a/efl/elementary/calendar_elm.pxd
+++ b/efl/elementary/calendar_elm.pxd
@@ -27,11 +27,7 @@ cdef extern from "Elementary.h":
ctypedef char *(*Elm_Calendar_Format_Cb) (tm *stime)
ctypedef struct Elm_Calendar_Mark:
- Evas_Object *obj
- Eina_List *node
- tm *mark_time
- const_char *mark_type
- Elm_Calendar_Mark_Repeat_Type repeat
+ pass
Evas_Object * elm_calendar_add(Evas_Object *parent)
const_char ** elm_calendar_weekdays_names_get(Evas_Object
*obj)
@@ -46,7 +42,7 @@ cdef extern from "Elementary.h":
Elm_Calendar_Mark * elm_calendar_mark_add(Evas_Object *obj,
const_char *mark_type, tm *mark_time, Elm_Calendar_Mark_Repeat_Type repeat)
void elm_calendar_mark_del(Elm_Calendar_Mark *mark)
void elm_calendar_marks_clear(Evas_Object *obj)
- #TODO: const_Eina_List * elm_calendar_marks_get(Evas_Object *obj)
+ const_Eina_List * elm_calendar_marks_get(Evas_Object *obj)
void elm_calendar_marks_draw(Evas_Object *obj)
void elm_calendar_interval_set(Evas_Object *obj,
double interval)
double elm_calendar_interval_get(Evas_Object *obj)
diff --git a/efl/elementary/calendar_elm.pyx b/efl/elementary/calendar_elm.pyx
index 4f3e12d..7fe151d 100644
--- a/efl/elementary/calendar_elm.pyx
+++ b/efl/elementary/calendar_elm.pyx
@@ -41,7 +41,9 @@ This widget emits the following signals, besides the ones
sent from
- ``changed`` - emitted when the date in the calendar is changed.
-.. rubric:: Calendar mark types
+.. _Elm_Calendar_Mark_Repeat_Type:
+
+.. rubric:: Calendar mark repeat types
.. data:: ELM_CALENDAR_UNIQUE
@@ -77,6 +79,8 @@ This widget emits the following signals, besides the ones
sent from
(inclusive).
+.. _Elm_Calendar_Select_Mode:
+
.. rubric:: Calendar selection modes
.. data:: ELM_CALENDAR_SELECT_MODE_DEFAULT
@@ -96,6 +100,8 @@ This widget emits the following signals, besides the ones
sent from
Select on demand
+.. _Elm_Calendar_Selectable:
+
.. rubric:: Selectable
.. data:: ELM_CALENDAR_SELECTABLE_NONE
@@ -115,6 +121,8 @@ This widget emits the following signals, besides the ones
sent from
Day is selectable
+.. _Elm_Calendar_Weekday:
+
.. rubric:: Days
.. data:: ELM_DAY_SUNDAY
@@ -150,6 +158,8 @@ This widget emits the following signals, besides the ones
sent from
include "widget_header.pxi"
from cpython cimport PyMem_Malloc, PyMem_Free
+from efl.eo cimport convert_array_of_strings_to_python_list, \
+ convert_python_list_strings_to_array_of_strings
from layout_class cimport LayoutClass
from datetime import date
@@ -177,18 +187,62 @@ ELM_DAY_FRIDAY = enums.ELM_DAY_FRIDAY
ELM_DAY_SATURDAY = enums.ELM_DAY_SATURDAY
ELM_DAY_LAST = enums.ELM_DAY_LAST
+
cdef class CalendarMark(object):
- """
+ """An item for the Calendar widget.
+
+ A mark that will be drawn in the calendar respecting the insertion
+ time and periodicity. It will emit the type as signal to the widget theme.
+ Default theme supports "holiday" and "checked", but it can be extended.
+
+ Instantiating it won't immediately update the calendar, drawing the marks.
+ For this, call :py:func:`Calendar.marks_draw`. However, when user selects
+ next or previous month calendar forces marks drawn.
+
+ Marks created with this method can be deleted with :py:func:`delete`.
+
+ Example::
+
+ import time
+ from datetime import date
+
+ cal = Calendar(win)
+
+ current_time = time.time() + 5 * 84600
+ selected_time = date.fromtimestamp(current_time)
+ CalendarMark(cal, "holiday", selected_time, ELM_CALENDAR_ANNUALLY)
- An item for the Calendar widget.
+ current_time = time.time() + 1 * 84600
+ selected_time = date.fromtimestamp(current_time)
+ CalendarMark(cal, "checked", selected_time, ELM_CALENDAR_UNIQUE)
+
+ cal.marks_draw()
"""
cdef Elm_Calendar_Mark *obj
- def __init__(self, evasObject cal, mark_type, mark_time, repeat):
- """.. seealso:: :py:func:`Calendar.mark_add()`"""
+ def __init__(self, evasObject cal, mark_type, mark_time,
+ Elm_Calendar_Mark_Repeat_Type repeat):
+ """
+
+ :param mark_type: A string used to define the type of mark. It will be
+ emitted to the theme, that should display a related modification
on these
+ days representation.
+ :type mark_type: string
+ :param mark_time: A date object to represent the date of inclusion of
the
+ mark. For marks that repeats it will just be displayed after the
inclusion
+ date in the calendar.
+ :type mark_time: datetime.date
+ :param repeat: Repeat the event following this periodicity. Can be a
unique
+ mark (that don't repeat), daily, weekly, monthly or annually.
+ :type repeat: :ref:`Calendar repeat type
<Elm_Calendar_Mark_Repeat_Type>`
+
+ :return: The created mark or ``None`` upon failure.
+ :rtype: :py:class:`CalendarMark`
+
+ """
cdef tm time
tmtup = mark_time.timetuple()
time.tm_mday = tmtup.tm_mday
@@ -220,11 +274,7 @@ cdef class CalendarMark(object):
cdef class Calendar(LayoutClass):
- """
-
- This is the class that actually implement the widget.
-
- """
+ """This is the class that actually implements the widget."""
def __init__(self, evasObject parent):
self._set_obj(elm_calendar_add(parent.obj))
@@ -252,26 +302,12 @@ cdef class Calendar(LayoutClass):
"""
def __get__(self):
- cdef const_char **lst, *weekday
- cdef int i
- ret = []
- lst = elm_calendar_weekdays_names_get(self.obj)
- for i in range(7):
- weekday = lst[i]
- if weekday != NULL:
- ret.append(_ctouni(weekday))
- return ret
+ return convert_array_of_strings_to_python_list(
+ elm_calendar_weekdays_names_get(self.obj), 7)
def __set__(self, weekdays):
- cdef int i, day_len
- cdef const_char **days, *day
- days = <const_char **>PyMem_Malloc(7 * sizeof(const_char *))
- for i in range(7):
- weekday = weekdays[i]
- if isinstance(weekday, unicode): weekday =
PyUnicode_AsUTF8String(weekday)
- day = <const_char *>weekday if weekday is not None else NULL
- days[i] = <const_char *>strdup(day)
- elm_calendar_weekdays_names_set(self.obj, <const_char **>days)
+ elm_calendar_weekdays_names_set(self.obj,
+ convert_python_list_strings_to_array_of_strings(weekdays))
property min_max_year:
"""The minimum and maximum values for the year
@@ -298,7 +334,7 @@ cdef class Calendar(LayoutClass):
property select_mode:
"""The day selection mode used.
- :type: Elm_Calendar_Select_Mode
+ :type: :ref:`Calendar select mode <Elm_Calendar_Select_Mode>`
"""
def __get__(self):
@@ -335,82 +371,52 @@ cdef class Calendar(LayoutClass):
time.tm_isdst = tmtup.tm_isdst
elm_calendar_selected_time_set(self.obj, &time)
- property format_function:
- """Set a function to format the string that will be used to display
- month and year.
-
- By default it uses strftime with "%B %Y" format string.
- It should allocate the memory that will be used by the string,
- that will be freed by the widget after usage.
- A pointer to the string and a pointer to the time struct will be
provided.
-
- Example::
-
- static char *
- _format_month_year(struct tm selected_time)
- {
- char buf[32];
- if (!strftime(buf, sizeof(buf), "%B %Y", selected_time))
return NULL;
- return strdup(buf);
- }
+ # TODO:
+ # property format_function:
+ # """Set a function to format the string that will be used to display
+ # month and year.
- elm_calendar_format_function_set(calendar, _format_month_year);
+ # By default it uses strftime with "%B %Y" format string.
+ # It should allocate the memory that will be used by the string,
+ # that will be freed by the widget after usage.
+ # A pointer to the string and a pointer to the time struct will be
provided.
- :param format_func: Function to set the month-year string given
- the selected date
- :type format_func: function
+ # Example::
- """
- def __set__(self, format_func):
- pass
- #TODO: elm_calendar_format_function_set(self.obj, format_func)
-
- def mark_add(self, mark_type, mark_time, repeat):
- """mark_add(mark_type, mark_time, repeat) -> CalendarMark
-
- Add a new mark to the calendar
-
- Add a mark that will be drawn in the calendar respecting the insertion
- time and periodicity. It will emit the type as signal to the widget
theme.
- Default theme supports "holiday" and "checked", but it can be extended.
-
- It won't immediately update the calendar, drawing the marks.
- For this, call :py:func:`marks_draw()`. However, when user selects
- next or previous month calendar forces marks drawn.
-
- Marks created with this method can be deleted with
:py:func:`mark_del()`.
+ # static char *
+ # _format_month_year(struct tm selected_time)
+ # {
+ # char buf[32];
+ # if (!strftime(buf, sizeof(buf), "%B %Y", selected_time))
return NULL;
+ # return strdup(buf);
+ # }
- Example::
+ # elm_calendar_format_function_set(calendar, _format_month_year);
- struct tm selected_time;
- time_t current_time;
+ # :param format_func: Function to set the month-year string given
+ # the selected date
+ # :type format_func: function
- current_time = time(NULL) + 5 84600;
- localtime_r(¤t_time, &selected_time);
- elm_calendar_mark_add(cal, "holiday", selected_time,
- ELM_CALENDAR_ANNUALLY);
+ # """
+ # def __set__(self, format_func):
+ # elm_calendar_format_function_set(self.obj, format_func)
- current_time = time(NULL) + 1 84600;
- localtime_r(¤t_time, &selected_time);
- elm_calendar_mark_add(cal, "checked", selected_time,
ELM_CALENDAR_UNIQUE);
+ def mark_add(self, mark_type, mark_time, Elm_Calendar_Mark_Repeat_Type
repeat):
+ """mark_add(mark_type, mark_time, Elm_Calendar_Mark_Repeat_Type
repeat) -> CalendarMark
- elm_calendar_marks_draw(cal);
-
- .. seealso::
- :py:func:`marks_draw()`
- :py:func:`mark_del()`
+ A constructor for a :py:class:`CalendarMark`.
:param mark_type: A string used to define the type of mark. It will be
emitted to the theme, that should display a related modification
on these
days representation.
:type mark_type: string
- :param mark_time: A time struct to represent the date of inclusion of
the
+ :param mark_time: A date object to represent the date of inclusion of
the
mark. For marks that repeats it will just be displayed after the
inclusion
date in the calendar.
- :type mark_time: tm struct
+ :type mark_time: datetime.date
:param repeat: Repeat the event following this periodicity. Can be a
unique
mark (that don't repeat), daily, weekly, monthly or annually.
- :type repeat: Elm_Calendar_Mark_Repeat_Type
+ :type repeat: :ref:`Calendar repeat type
<Elm_Calendar_Mark_Repeat_Type>`
:return: The created mark or ``None`` upon failure.
:rtype: :py:class:`CalendarMark`
@@ -423,8 +429,22 @@ cdef class Calendar(LayoutClass):
:type: tuple of :py:class:`CalendarMark`
"""
- #TODO: def __get__(self):
- #const_Eina_List *elm_calendar_marks_get(self.obj)
+ def __get__(self):
+ cdef:
+ Elm_Calendar_Mark *obj
+ const_Eina_List *lst = elm_calendar_marks_get(self.obj)
+ list ret = list()
+ CalendarMark o
+
+ while lst:
+ obj = <Elm_Calendar_Mark *>lst.data
+ lst = lst.next
+ o = CalendarMark.__new__(CalendarMark)
+ o.obj = obj
+ if o is not None:
+ ret.append(o)
+ return ret
+
#TODO: def __set__(self, value):
def __del__(self):
elm_calendar_marks_clear(self.obj)
@@ -490,7 +510,7 @@ cdef class Calendar(LayoutClass):
property selectable:
"""How selected_time manages a date
- :type: Selectable
+ :type: :ref:`Calendar selectable <Elm_Calendar_Selectable>`
"""
def __set__(self, Elm_Calendar_Selectable selectable):
diff --git a/efl/elementary/object_item.pyx b/efl/elementary/object_item.pyx
index 831f75f..56ac115 100644
--- a/efl/elementary/object_item.pyx
+++ b/efl/elementary/object_item.pyx
@@ -325,6 +325,7 @@ cdef class ObjectItem(object):
def disabled_get(self):
return bool(elm_object_item_disabled_get(self.item))
+ # TODO: ?
#def delete_cb_set(self, del_cb):
#elm_object_item_del_cb_set(self.item, del_cb)
--
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter