summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2015-05-03 13:05:15 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2015-05-03 13:05:15 +0300
commitacf2d339691af35d1301d382920a0cb4c9ad2597 (patch)
tree82c3fccb44a0d460048bc169b685a54292cc2c73
parentfb34f48c9d4a4ce80b9d4543fae1e986e0483aaf (diff)
Evas.Textgrid: Fix memleak
Had to change the type of cellrows from list to custom tuple-like type.
-rw-r--r--efl/evas/efl.evas_object_textgrid.pxi74
-rw-r--r--examples/elementary/test_evas_textgrid.py47
2 files changed, 72 insertions, 49 deletions
diff --git a/efl/evas/efl.evas_object_textgrid.pxi b/efl/evas/efl.evas_object_textgrid.pxi
index 9b93cc4..68e579d 100644
--- a/efl/evas/efl.evas_object_textgrid.pxi
+++ b/efl/evas/efl.evas_object_textgrid.pxi
@@ -42,6 +42,14 @@ cdef class TextgridCell(object):
42 self.fg_extended, self.bg_extended, 42 self.fg_extended, self.bg_extended,
43 self.double_width) 43 self.double_width)
44 44
45 @staticmethod
46 cdef TextgridCell create(Evas_Textgrid_Cell *cell):
47 if cell == NULL:
48 raise ValueError("Invalid pointer for evas textgrid cell!")
49 cdef TextgridCell ret = TextgridCell.__new__(TextgridCell)
50 ret.cell = cell
51 return ret
52
45 property codepoint: 53 property codepoint:
46 """the UNICODE value of the character 54 """the UNICODE value of the character
47 55
@@ -167,6 +175,35 @@ cdef class TextgridCell(object):
167 def __get__(self): 175 def __get__(self):
168 return <bint>self.cell.double_width 176 return <bint>self.cell.double_width
169 177
178
179cdef class TextgridCellRow:
180
181 cdef:
182 Evas_Textgrid_Cell *row
183 unsigned int rowsize
184
185 @staticmethod
186 cdef TextgridCellRow create(Evas_Textgrid_Cell *row, unsigned int rowsize):
187 if row == NULL:
188 raise ValueError("Invalid pointer for evas textgrid cell row!")
189 cdef TextgridCellRow ret = TextgridCellRow.__new__(TextgridCellRow)
190 ret.row = row
191 ret.rowsize = rowsize
192 return ret
193
194 def __len__(self):
195 return self.rowsize
196
197 def __getitem__(self, x):
198 if x > self.rowsize - 1:
199 raise IndexError
200 if x < 0:
201 x = self.rowsize - x
202 if x < 0:
203 raise IndexError
204 return TextgridCell.create(&self.row[x])
205
206
170cdef class Textgrid(Object): 207cdef class Textgrid(Object):
171 """ 208 """
172 209
@@ -343,13 +380,13 @@ cdef class Textgrid(Object):
343 def __get__(self): 380 def __get__(self):
344 return evas_object_textgrid_supported_font_styles_get(self.obj) 381 return evas_object_textgrid_supported_font_styles_get(self.obj)
345 382
346 def cellrow_set(self, int y, list row not None): 383 def cellrow_set(self, int y, TextgridCellRow row not None):
347 """Set the string at the given row. 384 """Set the string at the given row.
348 385
349 :param y: The row index of the grid. 386 :param y: The row index of the grid.
350 :type y: int 387 :type y: int
351 :param row: The string as a sequence of :class:`TextgridCell`. 388 :param row: The string as a sequence of :class:`TextgridCell`.
352 :type row: list 389 :type row: :class:`TextgridCellRow`
353 390
354 This method allows returning cells to the textgrid, retrieved with 391 This method allows returning cells to the textgrid, retrieved with
355 :py:meth:`cellrow_get`. 392 :py:meth:`cellrow_get`.
@@ -361,26 +398,14 @@ cdef class Textgrid(Object):
361 :py:meth:`update_add` 398 :py:meth:`update_add`
362 399
363 """ 400 """
364 cdef: 401 evas_object_textgrid_cellrow_set(self.obj, y, row.row)
365 TextgridCell cell
366 Evas_Textgrid_Cell **crow
367 int rlen = len(row)
368 int i
369
370 crow = <Evas_Textgrid_Cell **>malloc(rlen * sizeof(Evas_Textgrid_Cell *))
371
372 for i in range(rlen):
373 cell = row[i]
374 crow[i] = cell.cell
375
376 evas_object_textgrid_cellrow_set(self.obj, y, crow[0])
377 402
378 def cellrow_get(self, int y): 403 def cellrow_get(self, int y):
379 """Get the string at the given row. 404 """Get the string at the given row.
380 405
381 :param int y: The row index of the grid. 406 :param int y: The row index of the grid.
382 :return: A list of :class:`TextgridCell` 407 :return: A list of :class:`TextgridCell`
383 :rtype: list 408 :rtype: :class:`TextgridCellRow`
384 409
385 This method returns a list of cells in the line **y** of 410 This method returns a list of cells in the line **y** of
386 the textgrid object. If **y** is not between 0 and the number 411 the textgrid object. If **y** is not between 0 and the number
@@ -393,21 +418,8 @@ cdef class Textgrid(Object):
393 :py:meth:`update_add` 418 :py:meth:`update_add`
394 419
395 """ 420 """
396 cdef: 421 return TextgridCellRow.create(
397 Evas_Textgrid_Cell *row = evas_object_textgrid_cellrow_get(self.obj, y) 422 evas_object_textgrid_cellrow_get(self.obj, y), self.size[0])
398 int i
399 list ret = []
400 TextgridCell cell
401
402 if row == NULL:
403 return None
404
405 for i in range(self.size[0]):
406 cell = TextgridCell.__new__(TextgridCell)
407 cell.cell = &row[i]
408 ret.append(cell)
409
410 return ret
411 423
412 def update_add(self, int x, int y, int w, int h): 424 def update_add(self, int x, int y, int w, int h):
413 """Indicate for evas that part of a textgrid region (cells) has been updated. 425 """Indicate for evas that part of a textgrid region (cells) has been updated.
diff --git a/examples/elementary/test_evas_textgrid.py b/examples/elementary/test_evas_textgrid.py
index 5fce834..8a281a8 100644
--- a/examples/elementary/test_evas_textgrid.py
+++ b/examples/elementary/test_evas_textgrid.py
@@ -5,34 +5,46 @@ from efl import evas
5from efl.evas import Textgrid, EVAS_TEXTGRID_PALETTE_STANDARD 5from efl.evas import Textgrid, EVAS_TEXTGRID_PALETTE_STANDARD
6from efl import elementary 6from efl import elementary
7from efl.elementary.window import StandardWindow 7from efl.elementary.window import StandardWindow
8from efl.elementary.background import Background 8
9if "unichr" not in dir(__builtins__):
10 unichr = chr
9 11
10 12
11def evas_textgrid_clicked(obj, item=None): 13def evas_textgrid_clicked(obj, item=None):
12 win = StandardWindow("evastextgrid", "Evas Textgrid Test", autodel=True, 14 win = StandardWindow(
13 size=(320, 320)) 15 "evastextgrid", "Evas Textgrid Test", autodel=True)
14 if obj is None: 16 if obj is None:
15 win.callback_delete_request_add(lambda o: elementary.exit()) 17 win.callback_delete_request_add(lambda o: elementary.exit())
16 18
17 tg = Textgrid(win.evas) 19 W = 80
18 tg.size = 15, 1 20 H = 26
19 tg.size_hint_weight_set(1.0, 1.0) 21
22 tg = Textgrid(
23 win.evas, size_hint_weight=(1.0, 1.0), size=(W, H),
24 font=("monospace", 14))
20 win.resize_object_add(tg) 25 win.resize_object_add(tg)
21 tg.font = "Courier", 20
22 tg.palette_set(EVAS_TEXTGRID_PALETTE_STANDARD, 0, 0, 0, 0, 255) 26 tg.palette_set(EVAS_TEXTGRID_PALETTE_STANDARD, 0, 0, 0, 0, 255)
23 tg.palette_set(EVAS_TEXTGRID_PALETTE_STANDARD, 1, 255, 255, 255, 255)
24 27
25 row = tg.cellrow_get(0) 28 win.size_step = tg.cell_size
26 for cell in row:
27 cell.codepoint="รถ"
28 cell.fg = 1
29 cell.bg = 0
30 tg.cellrow_set(0, row)
31 29
32 tg.show() 30 # XXX: Add 1 to size, else the last row/col won't fit. Unknown reason.
33 tg.update_add(0, 0, 10, 1) 31 win.size = (W * tg.cell_size[0] + 1, H * tg.cell_size[1] + 1)
34 32
35 rowback = tg.cellrow_get(0) 33 for i in range(H):
34 ci = i + 1
35 cv = ci * 9
36 tg.palette_set(
37 EVAS_TEXTGRID_PALETTE_STANDARD, ci, cv, cv, cv, 255)
38 row = tg.cellrow_get(i)
39 if row is not None:
40 for cell in row:
41 cell.codepoint = unichr(1000 + i)
42 cell.bg = 0
43 cell.fg = ci
44 tg.cellrow_set(i, row)
45
46 tg.show()
47 tg.update_add(0, 0, 80, 26)
36 48
37 win.show() 49 win.show()
38 50
@@ -46,4 +58,3 @@ if __name__ == "__main__":
46 elementary.run() 58 elementary.run()
47 elementary.shutdown() 59 elementary.shutdown()
48 evas.shutdown() 60 evas.shutdown()
49