summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2012-08-12 17:48:47 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2012-08-12 17:48:47 +0000
commit506d525480c67fa7c8fb275805c834273cef1f6d (patch)
tree3690ef541842d6a7b5d527b1b2d03b6617a51609
parent8655280ca5270d4a4ca7bd44cc38cf9d3f35a813 (diff)
fix test and conversion to and from unicode.
SVN revision: 75165
-rw-r--r--evas/evas.c_evas.pyx16
-rw-r--r--evas/evas.c_evas_object_text.pxi32
-rw-r--r--evas/evas.c_evas_object_textblock.pxi33
-rwxr-xr-xtests/10-object_text.py2
4 files changed, 24 insertions, 59 deletions
diff --git a/evas/evas.c_evas.pyx b/evas/evas.c_evas.pyx
index d9f6590..3c469d0 100644
--- a/evas/evas.c_evas.pyx
+++ b/evas/evas.c_evas.pyx
@@ -265,25 +265,9 @@ cdef int PY_REFCOUNT(object o):
265 cdef PyObject *obj = <PyObject *>o 265 cdef PyObject *obj = <PyObject *>o
266 return obj.ob_refcnt 266 return obj.ob_refcnt
267 267
268cdef unicode _touni(char* s):
269 return s.decode('UTF-8', 'strict')
270
271cdef unicode _ctouni(const_char_ptr s): 268cdef unicode _ctouni(const_char_ptr s):
272 return s.decode('UTF-8', 'strict') 269 return s.decode('UTF-8', 'strict')
273 270
274cdef char* _fruni(s):
275 cdef char* c_string
276 if not s:
277 return NULL
278 if isinstance(s, unicode):
279 string = s.encode('UTF-8')
280 c_string = string
281 elif isinstance(s, str):
282 c_string = s
283 else:
284 raise TypeError("Expected str or unicode object, got %s" % (type(s).__name__))
285 return c_string
286
287cdef const_char_ptr _cfruni(s): 271cdef const_char_ptr _cfruni(s):
288 cdef const_char_ptr c_string 272 cdef const_char_ptr c_string
289 if not s: 273 if not s:
diff --git a/evas/evas.c_evas_object_text.pxi b/evas/evas.c_evas_object_text.pxi
index 71705ca..74e45bb 100644
--- a/evas/evas.c_evas_object_text.pxi
+++ b/evas/evas.c_evas_object_text.pxi
@@ -94,20 +94,17 @@ cdef public class Text(Object) [object PyEvasText, type PyEvasText_Type]:
94 94
95 def font_source_get(self): 95 def font_source_get(self):
96 """@rtype: str""" 96 """@rtype: str"""
97 cdef const_char_ptr s 97 return _ctouni(evas_object_text_font_source_get(self.obj))
98 s = evas_object_text_font_source_get(self.obj)
99 if s != NULL:
100 return s
101 98
102 def font_source_set(self, const_char_ptr value): 99 def font_source_set(self, value):
103 """Set where to find the font (ie: EET/Edje).""" 100 """Set where to find the font (ie: EET/Edje)."""
104 evas_object_text_font_source_set(self.obj, value) 101 evas_object_text_font_source_set(self.obj, _cfruni(value))
105 102
106 property font_source: 103 property font_source:
107 def __get__(self): 104 def __get__(self):
108 return self.font_source_get() 105 return self.font_source_get()
109 106
110 def __set__(self, const_char_ptr value): 107 def __set__(self, value):
111 self.font_source_set(value) 108 self.font_source_set(value)
112 109
113 def font_get(self): 110 def font_get(self):
@@ -115,19 +112,15 @@ cdef public class Text(Object) [object PyEvasText, type PyEvasText_Type]:
115 cdef const_char_ptr f 112 cdef const_char_ptr f
116 cdef int size 113 cdef int size
117 evas_object_text_font_get(self.obj, &f, &size) 114 evas_object_text_font_get(self.obj, &f, &size)
118 if f == NULL: 115 return (_ctouni(f), size)
119 font = None
120 else:
121 font = f
122 return (font, size)
123 116
124 def font_set(self, const_char_ptr font, int size=10): 117 def font_set(self, font, int size=10):
125 """Set font to use. 118 """Set font to use.
126 119
127 @param font:. 120 @param font:.
128 @param size:. 121 @param size:.
129 """ 122 """
130 evas_object_text_font_set(self.obj, font, size) 123 evas_object_text_font_set(self.obj, _cfruni(font), size)
131 124
132 property font: 125 property font:
133 def __get__(self): 126 def __get__(self):
@@ -140,20 +133,17 @@ cdef public class Text(Object) [object PyEvasText, type PyEvasText_Type]:
140 133
141 def text_get(self): 134 def text_get(self):
142 """@rtype: str""" 135 """@rtype: str"""
143 cdef const_char_ptr s 136 return _ctouni(evas_object_text_text_get(self.obj))
144 s = evas_object_text_text_get(self.obj)
145 if s != NULL:
146 return s
147 137
148 def text_set(self, const_char_ptr value): 138 def text_set(self, value):
149 """Change text to be used""" 139 """Change text to be used"""
150 evas_object_text_text_set(self.obj, value) 140 evas_object_text_text_set(self.obj, _cfruni(value))
151 141
152 property text: 142 property text:
153 def __get__(self): 143 def __get__(self):
154 return self.text_get() 144 return self.text_get()
155 145
156 def __set__(self, const_char_ptr value): 146 def __set__(self, value):
157 self.text_set(value) 147 self.text_set(value)
158 148
159 def ascent_get(self): 149 def ascent_get(self):
diff --git a/evas/evas.c_evas_object_textblock.pxi b/evas/evas.c_evas_object_textblock.pxi
index 1b1d4c8..475b501 100644
--- a/evas/evas.c_evas_object_textblock.pxi
+++ b/evas/evas.c_evas_object_textblock.pxi
@@ -61,19 +61,16 @@ cdef public class Textblock(Object) [object PyEvasTextblock, type PyEvasTextbloc
61 @rtype: str 61 @rtype: str
62 """ 62 """
63 cdef const_Evas_Textblock_Style *style 63 cdef const_Evas_Textblock_Style *style
64 cdef const_char_ptr s
65 style = evas_object_textblock_style_get(self.obj) 64 style = evas_object_textblock_style_get(self.obj)
66 s = evas_textblock_style_get(style) 65 return _ctouni(evas_textblock_style_get(style))
67 if s != NULL:
68 return s
69 66
70 def style_set(self, const_char_ptr value): 67 def style_set(self, value):
71 """set the textblock style information 68 """set the textblock style information
72 69
73 @param value: 70 @param value:
74 """ 71 """
75 cdef Evas_Textblock_Style *style = evas_textblock_style_new() 72 cdef Evas_Textblock_Style *style = evas_textblock_style_new()
76 evas_textblock_style_set(style, value) 73 evas_textblock_style_set(style, _cfruni(value))
77 evas_object_textblock_style_set(self.obj, style) 74 evas_object_textblock_style_set(self.obj, style)
78 evas_textblock_style_free(style) 75 evas_textblock_style_free(style)
79 76
@@ -81,7 +78,7 @@ cdef public class Textblock(Object) [object PyEvasTextblock, type PyEvasTextbloc
81 def __get__(self): 78 def __get__(self):
82 return self.style_get() 79 return self.style_get()
83 80
84 def __set__(self, const_char_ptr value): 81 def __set__(self, value):
85 self.style_set(value) 82 self.style_set(value)
86 83
87 def text_markup_get(self): 84 def text_markup_get(self):
@@ -89,39 +86,33 @@ cdef public class Textblock(Object) [object PyEvasTextblock, type PyEvasTextbloc
89 86
90 @rtype: str 87 @rtype: str
91 """ 88 """
92 cdef const_char_ptr s 89 return _ctouni(evas_object_textblock_text_markup_get(self.obj))
93 s = evas_object_textblock_text_markup_get(self.obj)
94 if s != NULL:
95 return s
96 90
97 def text_markup_set(self, const_char_ptr value): 91 def text_markup_set(self, value):
98 """set the textblock markup information 92 """set the textblock markup information
99 93
100 @param value: 94 @param value:
101 """ 95 """
102 evas_object_textblock_text_markup_set(self.obj, value) 96 evas_object_textblock_text_markup_set(self.obj, _cfruni(value))
103 97
104 property text_markup: 98 property text_markup:
105 def __get__(self): 99 def __get__(self):
106 return self.text_markup_get() 100 return self.text_markup_get()
107 101
108 def __set__(self, const_char_ptr value): 102 def __set__(self, value):
109 self.text_markup_set(value) 103 self.text_markup_set(value)
110 104
111 def replace_char_get(self): 105 def replace_char_get(self):
112 cdef const_char_ptr s 106 return _ctouni(evas_object_textblock_replace_char_get(self.obj))
113 s = evas_object_textblock_replace_char_get(self.obj)
114 if s != NULL:
115 return s
116 107
117 def replace_char_set(self, const_char_ptr value): 108 def replace_char_set(self, value):
118 evas_object_textblock_replace_char_set(self.obj, value) 109 evas_object_textblock_replace_char_set(self.obj, _cfruni(value))
119 110
120 property replace_char: 111 property replace_char:
121 def __get__(self): 112 def __get__(self):
122 return self.replace_char_get() 113 return self.replace_char_get()
123 114
124 def __set__(self, const_char_ptr value): 115 def __set__(self, value):
125 self.replace_char_set(value) 116 self.replace_char_set(value)
126 117
127 def line_number_geometry_get(self, int index): 118 def line_number_geometry_get(self, int index):
diff --git a/tests/10-object_text.py b/tests/10-object_text.py
index 69ffd80..517bb15 100755
--- a/tests/10-object_text.py
+++ b/tests/10-object_text.py
@@ -37,7 +37,7 @@ class TextBasics(unittest.TestCase):
37 text = "ASCII" 37 text = "ASCII"
38 o = self.canvas.Text(text=text, font=("sans serif", 20), 38 o = self.canvas.Text(text=text, font=("sans serif", 20),
39 color="#ff0000") 39 color="#ff0000")
40 self.assertEqual(isinstance(o.text_get(), str), True) 40 self.assertEqual(isinstance(o.text_get(), unicode), True)
41 self.assertEqual(o.text_get(), text) 41 self.assertEqual(o.text_get(), text)
42 42
43 def testUnicode1(self): 43 def testUnicode1(self):