davemds pushed a commit to branch master.

http://git.enlightenment.org/bindings/python/python-efl.git/commit/?id=8106e2b1aad6afb7ccfb25943147e3a3c98f2096

commit 8106e2b1aad6afb7ccfb25943147e3a3c98f2096
Author: Dave Andreoli <d...@gurumeditation.it>
Date:   Sat Feb 7 20:07:55 2015 +0100

    fixed elm.Entry.cursor_content_get() to not crash when called
    
    With a new test Entry Notepad
---
 ChangeLog                         |  6 ++++
 efl/elementary/entry.pyx          |  7 +---
 examples/elementary/test.py       |  1 +
 examples/elementary/test_entry.py | 67 +++++++++++++++++++++++++++++++++++++--
 4 files changed, 72 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fbe9cde..0ced85e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,7 @@ Improvements:
  * some new elm examples/tests
  * new efl.utils.setup helper module to simplify user setup.py
  * new uninstall setup.py command
+ * fixed elm.Entry.cursor_content_get() to not crash when called
 
 
 Changes:
@@ -45,6 +46,11 @@ Additions:
  * evas.FILL_HORIZ
  * evas.FILL_VERT
 
+
+Deprecation:
+
+ * elm.Configuration.engine
+ * elm.Configuration.preferred_engine
  
 ===================
 2014-11-23  v1.12.0
diff --git a/efl/elementary/entry.pyx b/efl/elementary/entry.pyx
index d947335..06ba28b 100644
--- a/efl/elementary/entry.pyx
+++ b/efl/elementary/entry.pyx
@@ -1290,12 +1290,7 @@ cdef class Entry(LayoutClass):
         :rtype: unicode
 
         """
-        cdef:
-            const char *text = elm_entry_cursor_content_get(self.obj)
-            unicode ret = _ctouni(text)
-
-        free(<void *>text)
-        return ret
+        return _ctouni(elm_entry_cursor_content_get(self.obj))
 
     def cursor_geometry_get(self):
         """This function returns the geometry of the cursor.
diff --git a/examples/elementary/test.py b/examples/elementary/test.py
index e8ef6af..3bb1abb 100755
--- a/examples/elementary/test.py
+++ b/examples/elementary/test.py
@@ -129,6 +129,7 @@ items = [
         ("Entry", "test_entry", "entry_clicked"),
         ("Entry Scrolled", "test_entry", "entry_scrolled_clicked"),
         ("Entry Anchor", "test_entry", "entry_anchor_clicked"),
+        ("Entry Notepad", "test_entry", "entry_notepad_clicked"),
         
("MultiButtonEntry","test_multibuttonentry","multibuttonentry_clicked"),
     ]),
     ("Focus", [
diff --git a/examples/elementary/test_entry.py 
b/examples/elementary/test_entry.py
index a9fd125..de896d7 100644
--- a/examples/elementary/test_entry.py
+++ b/examples/elementary/test_entry.py
@@ -4,12 +4,13 @@
 from efl.evas import EVAS_HINT_EXPAND, EVAS_HINT_FILL, EXPAND_BOTH, FILL_BOTH, 
\
     EXPAND_HORIZ, FILL_HORIZ
 from efl import elementary
+from efl.elementary.check import Check
 from efl.elementary.window import StandardWindow
 from efl.elementary.background import Background
 from efl.elementary.box import Box
 from efl.elementary.button import Button
-from efl.elementary.entry import Entry, ELM_SCROLLER_POLICY_OFF, \
-    ELM_SCROLLER_POLICY_ON, Entry_markup_to_utf8
+from efl.elementary.entry import Entry, Entry_markup_to_utf8, ELM_WRAP_WORD, \
+    ELM_TEXT_FORMAT_PLAIN_UTF8
 from efl.elementary.list import List
 from efl.elementary.frame import Frame
 from efl.elementary.hover import Hover
@@ -387,6 +388,65 @@ def entry_anchor_clicked(obj, item=None):
     win.show()
 
 
+## Test "Entry Notepad"
+def entry_notepad_label_update(en, lb):
+    lb.text = "<b>cursor</b>  pos:%d  char:'%s'  geom:%s" % (
+               en.cursor_pos,
+               en.cursor_content_get().replace('<','&lt;').replace('>','&gt;'),
+               en.cursor_geometry_get()
+              )
+
+def entry_notepad_changed_cb(entry,  label):
+    print("entry changed")
+
+def entry_notepad_cursor_changed_cb(entry, label):
+    print("cursor changed")
+    entry_notepad_label_update(entry, label)
+
+
+def entry_notepad_clicked(obj, item=None):
+    win = StandardWindow("entry", "Entry Notepad", autodel=True, 
size=(400,400))
+
+    box = Box(win, size_hint_weight=EXPAND_BOTH)
+    win.resize_object_add(box)
+    box.show()
+
+    label = Label(box, text="Info")
+    box.pack_end(label)
+    label.show()
+
+    entry = Entry(box, scrollable=True, line_wrap=ELM_WRAP_WORD,
+                  size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
+    entry.callback_changed_add(entry_notepad_changed_cb, label)
+    entry.callback_cursor_changed_add(entry_notepad_cursor_changed_cb, label)
+    try: # do not fail if the file do not exists, entry can manage the case
+        entry.file=("note.txt", ELM_TEXT_FORMAT_PLAIN_UTF8)
+    except RuntimeError:
+        pass
+    box.pack_end(entry)
+    entry.show()
+
+    hbox = Box(box, horizontal=True, size_hint_weight=EXPAND_HORIZ)
+    box.pack_end(hbox)
+    hbox.show()
+
+    bt = Button(hbox, text="Clear")
+    bt.callback_clicked_add(lambda b: setattr(entry, "text", ""))
+    hbox.pack_end(bt)
+    bt.show()
+
+    bt = Button(hbox, text="Save")
+    bt.callback_clicked_add(lambda b: entry.file_save())
+    hbox.pack_end(bt)
+    bt.show()
+
+    ck = Check(hbox, text="Auto Save", state=entry.autosave)
+    ck.callback_changed_add(lambda c: setattr(entry, "autosave", c.state))
+    hbox.pack_end(ck)
+    ck.show()
+
+    win.show()
+
 if __name__ == "__main__":
     elementary.init()
     win = StandardWindow("test", "python-elementary test application",
@@ -409,7 +469,8 @@ if __name__ == "__main__":
 
     items = [("Entry", entry_clicked),
              ("Entry Scrolled", entry_scrolled_clicked),
-             ("Entry Anchor", entry_anchor_clicked)
+             ("Entry Anchor", entry_anchor_clicked),
+             ("Entry Notepad", entry_notepad_clicked)
             ]
 
     li = List(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)

-- 


Reply via email to