kuuko pushed a commit to branch master.
commit cdfa89f8cb6e84ace0f9e7a82982448bb35a3efc
Author: Kai Huuhko <[email protected]>
Date: Tue Apr 16 08:02:09 2013 +0000
Elementary: Implement adding context menu items for Entry.
---
efl/elementary/entry.pxd | 10 ++++----
efl/elementary/entry.pyx | 59 +++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 62 insertions(+), 7 deletions(-)
diff --git a/efl/elementary/entry.pxd b/efl/elementary/entry.pxd
index b9988a0..ae6cedb 100644
--- a/efl/elementary/entry.pxd
+++ b/efl/elementary/entry.pxd
@@ -1,10 +1,11 @@
from efl.evas cimport Eina_Bool, Eina_Rectangle, Evas_Object, \
- const_Evas_Object, Evas_Coord
+ const_Evas_Object, Evas_Coord, Evas_Smart_Cb
from enums cimport Elm_Wrap_Type, Elm_Text_Format, Elm_Cnp_Mode, \
Elm_Scroller_Policy, Elm_Input_Panel_Layout, Elm_Input_Panel_Lang, \
Elm_Input_Panel_Lang, Elm_Input_Panel_Return_Key_Type, \
- Elm_Autocapital_Type
+ Elm_Autocapital_Type, Elm_Icon_Type
from libc.string cimport const_char
+from libc.stdlib cimport const_void
cdef extern from "Elementary.h":
ctypedef struct Elm_Entry_Anchor_Info:
@@ -24,7 +25,8 @@ cdef extern from "Elementary.h":
Eina_Bool hover_top
Eina_Bool hover_bottom
-
+ ctypedef struct Elm_Entry_Context_Menu_Item:
+ pass
# Data for the elm_entry_filter_limit_size() entry filter.
ctypedef struct Elm_Entry_Filter_Limit_Size:
@@ -78,7 +80,7 @@ cdef extern from "Elementary.h":
void elm_entry_selection_copy(Evas_Object *obj)
void elm_entry_selection_paste(Evas_Object *obj)
void elm_entry_context_menu_clear(Evas_Object *obj)
- # TODO: void elm_entry_context_menu_item_add(Evas_Object
*obj, const_char *label, const_char *icon_file, Elm_Icon_Type icon_type,
Evas_Smart_Cb func, const_void *data)
+ void elm_entry_context_menu_item_add(Evas_Object *obj,
const_char *label, const_char *icon_file, Elm_Icon_Type icon_type,
Evas_Smart_Cb func, const_void *data)
void elm_entry_context_menu_disabled_set(Evas_Object
*obj, Eina_Bool disabled)
Eina_Bool elm_entry_context_menu_disabled_get(Evas_Object
*obj)
# TODO: void elm_entry_item_provider_append(Evas_Object
*obj, Elm_Entry_Item_Provider_Cb func, void *data)
diff --git a/efl/elementary/entry.pyx b/efl/elementary/entry.pyx
index 50fccd4..e48a4ed 100644
--- a/efl/elementary/entry.pyx
+++ b/efl/elementary/entry.pyx
@@ -428,6 +428,24 @@ Default text parts of the entry that you can use for are:
Word wrap, and if that fails, char wrap
+
+.. _Elm_Icon_Type:
+
+.. rubric:: Icon types
+
+.. data:: ELM_ICON_NONE
+
+ No icon
+
+.. data:: ELM_ICON_FILE
+
+ Icon is a file
+
+.. data:: ELM_ICON_STANDARD
+
+ Icon is set with standards names
+
+
"""
include "widget_header.pxi"
@@ -483,6 +501,20 @@ ELM_WRAP_CHAR = enums.ELM_WRAP_CHAR
ELM_WRAP_WORD = enums.ELM_WRAP_WORD
ELM_WRAP_MIXED = enums.ELM_WRAP_MIXED
+ELM_ICON_NONE = enums.ELM_ICON_NONE
+ELM_ICON_FILE = enums.ELM_ICON_FILE
+ELM_ICON_STANDARD = enums.ELM_ICON_STANDARD
+
+import traceback
+
+cdef void _entry_context_menu_callback(void *data, Evas_Object *obj, void
*event_info) with gil:
+ (callback, a, ka) = <object>data
+ try:
+ o = object_from_instance(obj)
+ callback(o, *a, **ka)
+ except Exception as e:
+ traceback.print_exc()
+
def Entry_markup_to_utf8(string):
if isinstance(string, unicode): string = string.encode("UTF-8")
return _touni(elm_entry_markup_to_utf8(
@@ -493,6 +525,16 @@ def Entry_utf8_to_markup(string):
return _touni(elm_entry_utf8_to_markup(
<const_char *>string if string is not None else NULL))
+
+cdef class EntryContextMenuItem(object):
+ """
+
+ Type of contextual item that can be added in to long press menu.
+ :since: 1.8
+
+ """
+ cdef Elm_Entry_Context_Menu_Item *item
+
class EntryAnchorInfo(object):
"""
@@ -1067,8 +1109,7 @@ cdef class Entry(Object):
"""
elm_entry_context_menu_clear(self.obj)
- # TODO:
- # def context_menu_item_add(self, label, icon_file, icon_type, cb, data):
+ def context_menu_item_add(self, label = None, icon_file = None,
Elm_Icon_Type icon_type = enums.ELM_ICON_NONE, func = None, *args, **kwargs):
"""This adds an item to the entry's contextual menu.
A longpress on an entry will make the contextual menu show up, if this
@@ -1090,7 +1131,19 @@ cdef class Entry(Object):
:type func: function
"""
- #elm_entry_context_menu_item_add(self.obj, label, icon_file,
icon_type, func, data);
+ cdef Evas_Smart_Cb cb = NULL
+ if func is not None:
+ if not callable(func):
+ raise TypeError("func is not callable.")
+ cb = _entry_context_menu_callback
+ data = (func, args, kwargs)
+
+ elm_entry_context_menu_item_add(self.obj,
+ <const_char *>label if label is not None else NULL,
+ <const_char *>icon_file if icon_file is not None else NULL,
+ icon_type,
+ cb,
+ <void *>data if func is not None else NULL)
property context_menu_disabled:
"""This disables the entry's contextual (longpress) menu.
--
------------------------------------------------------------------------------
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