Changeset 4802
- Timestamp:
- 01/13/12 21:17:01 (4 months ago)
- Location:
- libcaca/trunk/python
- Files:
-
- 19 edited
-
caca/__init__.py (modified) (2 diffs)
-
caca/canvas.py (modified) (23 diffs)
-
caca/common.py (modified) (8 diffs)
-
caca/display.py (modified) (7 diffs)
-
caca/dither.py (modified) (2 diffs)
-
caca/font.py (modified) (2 diffs)
-
examples/blit.py (modified) (2 diffs)
-
examples/colors.py (modified) (3 diffs)
-
examples/drawing.py (modified) (1 diff)
-
examples/driver.py (modified) (1 diff)
-
examples/event.py (modified) (2 diffs)
-
examples/figfont.py (modified) (4 diffs)
-
examples/font.py (modified) (3 diffs)
-
examples/frames.py (modified) (3 diffs)
-
examples/gol.py (modified) (6 diffs)
-
examples/text.py (modified) (3 diffs)
-
setup.py (modified) (2 diffs)
-
test/__init__.py (modified) (1 diff)
-
test/canvas.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/python/caca/__init__.py
r4398 r4802 15 15 """ Libcaca Python bindings """ 16 16 17 #standard modules 18 import locale 19 import sys 17 20 import ctypes 18 21 from ctypes.util import find_library … … 21 24 _lib = ctypes.cdll.LoadLibrary(find_library('caca')) 22 25 else: 23 raise ImportError , \24 "Can't find shared library, you need to install libcaca in your path !" 26 raise ImportError( 27 "Can't find shared library, you need to install libcaca in your path !") 25 28 26 from common import * 29 #functions to handle string/bytes in python3+ 30 if sys.version_info[0:2] >= (3, 0): 31 _PYTHON3 = True 32 else: 33 _PYTHON3 = False 27 34 35 def _str_to_bytes(the_string): 36 """ Translate string to bytes type for python 3. 37 """ 38 return bytes(the_string, locale.getlocale()[1]) 39 40 def _bytes_to_str(the_bytes): 41 """ Translate bytes to string type for python 3. 42 """ 43 return the_bytes.decode(locale.getlocale()[1]) 44 45 from .common import * 46 -
libcaca/trunk/python/caca/canvas.py
r4800 r4802 19 19 20 20 from caca import _lib, utf8_to_utf32, utf32_to_utf8 21 from caca import _PYTHON3, _str_to_bytes, _bytes_to_str 21 22 from caca.font import _Font 22 23 … … 48 49 49 50 return _lib.caca_free_canvas(self) 50 51 def get_width(self):52 raise CanvasError, "You can't use model canvas directly"53 54 def get_height(self):55 raise CanvasError, "You can't use model canvas directly"56 51 57 52 class Canvas(_Canvas): … … 71 66 try: 72 67 self._cv = _lib.caca_create_canvas(width, height) 73 except ctypes.ArgumentError , e:68 except ctypes.ArgumentError: 74 69 self._cv = 0 75 70 raise CanvasError("Specified width or height is invalid") … … 92 87 """ Not implemented. 93 88 """ 94 raise CanvasError , "Not implemented"89 raise CanvasError("Not implemented") 95 90 96 91 def unmanage(self, *args, **kw): 97 92 """ Not implemented. 98 93 """ 99 raise CanvasError , "Not implemented"94 raise CanvasError("Not implemented") 100 95 101 96 def set_size(self, width, height): … … 112 107 try: 113 108 ret = _lib.caca_set_canvas_size(self, width, height) 114 except ctypes.ArgumentError , e:109 except ctypes.ArgumentError: 115 110 raise CanvasError("Specified width or height is invalid") 116 111 else: … … 147 142 """ Not implemented. 148 143 """ 149 raise CanvasError , "Not implemented"144 raise CanvasError("Not implemented") 150 145 151 146 def get_attrs(self, *args, **kw): 152 147 """ Not implemented. 153 148 """ 154 raise CanvasError , "Not implemented"149 raise CanvasError("Not implemented") 155 150 156 151 def gotoxy(self, x, y): … … 166 161 try: 167 162 ret = _lib.caca_gotoxy(self, x, y) 168 except ctypes.ArgumentError , e:163 except ctypes.ArgumentError: 169 164 raise CanvasError("specified coordinate X or Y is invalid") 170 165 else: … … 210 205 try: 211 206 ret = _lib.caca_put_char(self, x, y, ch) 212 except ctypes.ArgumentError , e:207 except ctypes.ArgumentError: 213 208 raise CanvasError("specified coordinate X or Y is invalid") 214 209 else: … … 250 245 _lib.caca_put_str.restype = ctypes.c_int 251 246 252 if notisinstance(s, str):253 raise CanvasError("Specified string is invalid")254 else: 255 try:256 ret = _lib.caca_put_str(self, x, y, s)257 except ctypes.ArgumentError:258 raise CanvasError("Specified coordinate X or Y is invalid")259 else:260 return ret247 if _PYTHON3 and isinstance(s, str): 248 s = _str_to_bytes(s) 249 250 try: 251 ret = _lib.caca_put_str(self, x, y, s) 252 except ctypes.ArgumentError: 253 raise CanvasError("Invalid argument") 254 else: 255 return ret 261 256 262 257 def printf(self, x, y, fmt, *args): … … 273 268 _lib.caca_printf.restype = ctypes.c_int 274 269 275 if not isinstance(fmt, str): 276 raise CanvasError("Specified formated string is invalid") 277 else: 278 try: 279 ret = _lib.caca_printf(self, x, y, fmt, *args) 280 except ctypes.ArgumentError: 281 raise CanvasError("Specified coordinate X or Y is invalid") 282 else: 283 return ret 270 if _PYTHON3 and isinstance(fmt, str): 271 fmt = _str_to_bytes(fmt) 272 273 if _PYTHON3: 274 nargs = [] 275 for arg in args[:]: 276 if isinstance(arg, str): 277 nargs.append(_str_to_bytes(arg)) 278 else: 279 nargs.append(arg) 280 else: 281 nargs = args 282 283 try: 284 ret = _lib.caca_printf(self, x, y, fmt, *nargs) 285 except ctypes.ArgumentError: 286 raise CanvasError("Specified coordinate X or Y is invalid") 287 else: 288 return ret 284 289 285 290 def vprintf(self, *args, **kw): 286 291 """ Not implemented. 287 292 """ 288 raise CanvasError , "Not implemented"293 raise CanvasError("Not implemented") 289 294 290 295 def clear(self): … … 1231 1236 _lib.caca_get_frame_name.restype = ctypes.c_char_p 1232 1237 1233 return _lib.caca_get_frame_name(self) 1238 if _PYTHON3: 1239 return _bytes_to_str(_lib.caca_get_frame_name(self)) 1240 else: 1241 return _lib.caca_get_frame_name(self) 1234 1242 1235 1243 def set_frame_name(self, name): … … 1240 1248 _lib.caca_set_frame_name.argtypes = [_Canvas, ctypes.c_char_p] 1241 1249 _lib.caca_set_frame_name.restype = ctypes.c_int 1250 1251 if _PYTHON3 and isinstance(name, str): 1252 name = _str_to_bytes(name) 1242 1253 1243 1254 try: … … 1305 1316 - utf8: import UTF-8 files with ANSI colour codes. 1306 1317 """ 1307 length = ctypes.c_size_t(len(data))1308 1318 1309 1319 _lib.caca_import_canvas_from_memory.argtypes = [ … … 1313 1323 _lib.caca_import_canvas_from_memory.restype = ctypes.c_int 1314 1324 1315 if not isinstance(fmt, str): 1316 raise CanvasError("Invalid format requested") 1325 if _PYTHON3 and isinstance(data, str): 1326 data = _str_to_bytes(data) 1327 if _PYTHON3 and isinstance(fmt, str): 1328 fmt = _str_to_bytes(fmt) 1329 1330 length = ctypes.c_size_t(len(data)) 1317 1331 1318 1332 try: … … 1348 1362 _lib.caca_import_canvas_from_file.restype = ctypes.c_int 1349 1363 1350 if not isinstance(fmt, str): 1351 raise CanvasError("Invalid format requested") 1364 if _PYTHON3 and isinstance(filename, str): 1365 filename = _str_to_bytes(filename) 1366 if _PYTHON3 and isinstance(fmt, str): 1367 fmt = _str_to_bytes(fmt) 1352 1368 1353 1369 try: … … 1392 1408 _lib.caca_import_area_from_memory.restype = ctypes.c_int 1393 1409 1394 if not isinstance(fmt, str):1395 raise CanvasError("Invalid format requested")1396 elif not isinstance(data, str):1397 raise CanvasError("Given data are invalid")1410 if _PYTHON3 and isinstance(data, str): 1411 data = _str_to_bytes(data) 1412 if _PYTHON3 and isinstance(fmt, str): 1413 fmt = _str_to_bytes(fmt) 1398 1414 1399 1415 try: … … 1434 1450 _lib.caca_import_area_from_file.restype = ctypes.c_int 1435 1451 1436 if not isinstance(fmt, str):1437 raise CanvasError("Invalid format requested")1438 elif not isinstance(filename, str):1439 raise CanvasError("Invalid filename requested")1452 if _PYTHON3 and isinstance(filename, str): 1453 filename = _str_to_bytes(filename) 1454 if _PYTHON3 and isinstance(fmt, str): 1455 fmt = _str_to_bytes(fmt) 1440 1456 1441 1457 try: … … 1477 1493 _Canvas, ctypes.c_char_p, p_size_t 1478 1494 ] 1479 _lib.caca_export_canvas_to_memory.restype = ctypes.POINTER(ctypes.c_char_p) 1495 _lib.caca_export_canvas_to_memory.restype = ctypes.POINTER( 1496 ctypes.c_char_p) 1480 1497 1481 1498 p = ctypes.c_size_t() 1499 1500 if _PYTHON3 and isinstance(fmt, str): 1501 fmt = _str_to_bytes(fmt) 1482 1502 1483 1503 try: … … 1494 1514 " buffer") 1495 1515 else: 1496 return ctypes.string_at(ret, p.value) 1516 if _PYTHON3: 1517 return _bytes_to_str(ctypes.string_at(ret, p.value)) 1518 else: 1519 return ctypes.string_at(ret, p.value) 1497 1520 1498 1521 def export_area_to_memory(self, x, y, width, height, fmt): … … 1526 1549 p = ctypes.c_size_t() 1527 1550 1528 if notisinstance(fmt, str):1529 raise CanvasError("Invalid format requested")1551 if _PYTHON3 and isinstance(fmt, str): 1552 fmt = _str_to_bytes(fmt) 1530 1553 1531 1554 try: … … 1543 1566 " buffer") 1544 1567 else: 1545 return ctypes.string_at(ret, p.value) 1568 if _PYTHON3: 1569 return _bytes_to_str(ctypes.string_at(ret, p.value)) 1570 else: 1571 return ctypes.string_at(ret, p.value) 1546 1572 1547 1573 def set_figfont(self, filename): … … 1553 1579 _lib.caca_canvas_set_figfont.restype = ctypes.c_int 1554 1580 1555 if notisinstance(filename, str):1556 raise CanvasError("Invalid filename requested")1557 else: 1558 return _lib.caca_canvas_set_figfont(self, filename)1581 if _PYTHON3 and isinstance(filename, str): 1582 filename = _str_to_bytes(filename) 1583 1584 return _lib.caca_canvas_set_figfont(self, filename) 1559 1585 1560 1586 def put_figchar(self, ch): … … 1566 1592 _lib.caca_put_figchar.restype = ctypes.c_int 1567 1593 1568 if notisinstance(ch, str):1569 raise CanvasError("Specified character is invalid")1570 else: 1571 try:1572 ch = ord(ch)1573 except TypeError:1574 ch = utf8_to_utf32(ch)1594 if _PYTHON3 and isinstance(ch, str): 1595 ch = _str_to_bytes(ch) 1596 1597 try: 1598 ch = ord(ch) 1599 except TypeError: 1600 ch = utf8_to_utf32(ch) 1575 1601 1576 1602 return _lib.caca_put_figchar(self, ch) -
libcaca/trunk/python/caca/common.py
r4774 r4802 17 17 import ctypes 18 18 19 from caca import _lib 19 from caca import _lib, _PYTHON3, _bytes_to_str 20 20 21 21 #color constants … … 117 117 _lib.caca_get_version.restype = ctypes.c_char_p 118 118 119 return _lib.caca_get_version() 119 if _PYTHON3: 120 return _bytes_to_str(_lib.caca_get_version()) 121 else: 122 return _lib.caca_get_version() 120 123 121 124 def get_display_driver_list(): … … 129 132 for item in _lib.caca_get_display_driver_list(): 130 133 if item is not None and item != "": 131 tmplst.append(item) 134 if _PYTHON3: 135 tmplst.append(_bytes_to_str(item)) 136 else: 137 tmplst.append(item) 132 138 else: 133 139 #memory error occured otherwise 134 140 break 135 141 136 for i in xrange(0, len(tmplst)):142 for i in range(0, len(tmplst)): 137 143 if i % 2 == 0: 138 144 retlst.append((tmplst[i], tmplst[i+1])) … … 151 157 for item in _lib.caca_get_export_list(): 152 158 if item is not None and item != "": 153 tmplst.append(item) 159 if _PYTHON3: 160 tmplst.append(_bytes_to_str(item)) 161 else: 162 tmplst.append(item) 154 163 else: 155 164 #memory error occured otherwise 156 165 break 157 166 158 for i in xrange(0, len(tmplst)):167 for i in range(0, len(tmplst)): 159 168 if i % 2 == 0: 160 169 retlst.append((tmplst[i], tmplst[i+1])) … … 176 185 if item == "": 177 186 if not autodetect: 178 tmplst.append("\"\"") 187 if _PYTHON3: 188 tmplst.append(_bytes_to_str("\"\"")) 189 else: 190 tmplst.append("\"\"") 179 191 autodetect = True 180 192 else: … … 182 194 break 183 195 else: 184 tmplst.append(item) 196 if _PYTHON3: 197 tmplst.append(_bytes_to_str(item)) 198 else: 199 tmplst.append(item) 185 200 else: 186 201 #memory error occured otherwise 187 202 break 188 203 189 for i in xrange(0, len(tmplst)):204 for i in range(0, len(tmplst)): 190 205 if i % 2 == 0: 191 206 retlst.append((tmplst[i], tmplst[i+1])) … … 203 218 for item in _lib.caca_get_font_list(): 204 219 if item is not None and item != "": 205 fl.append(item) 220 if _PYTHON3: 221 fl.append(_bytes_to_str(item)) 222 else: 223 fl.append(item) 206 224 else: 207 225 #memory error occured otherwise … … 294 312 _lib.caca_utf32_to_utf8(buf, ch) 295 313 296 return buf.raw.rstrip('\x00') 314 if _PYTHON3: 315 return _bytes_to_str(buf.raw).replace('\x00', '') 316 else: 317 return buf.raw.replace('\x00', '') 297 318 298 319 def utf32_to_cp437(ch): -
libcaca/trunk/python/caca/display.py
r4769 r4802 17 17 import ctypes 18 18 19 from caca import _lib 19 from caca import _lib, _PYTHON3, _str_to_bytes 20 20 from caca.canvas import _Canvas, Canvas 21 21 … … 62 62 _Canvas, ctypes.c_char_p 63 63 ] 64 if _PYTHON3 and isinstance(driver, str): 65 driver = _str_to_bytes(driver) 66 64 67 self._dp = _lib.caca_create_display_with_driver(cv, driver) 65 68 66 69 if self._dp == 0: 67 raise DisplayError , "Failed to create display"70 raise DisplayError("Failed to create display") 68 71 69 72 def get_driver(self): … … 86 89 if not driver: 87 90 driver = ctypes.c_char_p(0) 91 else: 92 if _PYTHON3 and isinstance(driver, str): 93 driver = _str_to_bytes(driver) 88 94 89 95 return _lib.caca_set_display_driver(self, driver) … … 131 137 _lib.caca_set_display_title.restype = ctypes.c_int 132 138 139 if _PYTHON3 and isinstance(title, str): 140 title = _str_to_bytes(title) 141 133 142 return _lib.caca_set_display_title(self, title) 134 143 135 144 def set_mouse(self, flag): 136 """ Show or hide the mouse pointer. This function works with the ncurses, 137 S-Lang and X11 drivers. 138 139 flag -- 0 hides the pointer, 1 shows the system's default pointer (usually an arrow). 145 """ Show or hide the mouse pointer. This function works with the 146 ncurses, S-Lang and X11 drivers. 147 148 flag -- 0 hides the pointer, 1 shows the system's default pointer 149 (usually an arrow) 140 150 """ 141 151 _lib.caca_set_mouse.argtypes = [_Display, ctypes.c_int] … … 147 157 """ Show or hide the cursor, for devices that support such a feature. 148 158 149 flag -- 0 hides the cursor, 1 shows the system's default cursor (usually a white rectangle). 159 flag -- 0 hides the cursor, 1 shows the system's default cursor 160 (usually a white rectangle). 150 161 """ 151 162 … … 163 174 """ 164 175 165 _lib.caca_get_event.argtypes = [Display, ctypes.c_int, ctypes.POINTER(Event), ctypes.c_int] 166 167 return _lib.caca_get_event(self, event_mask, ctypes.byref(event), timeout) 176 _lib.caca_get_event.argtypes = [ 177 Display, ctypes.c_int, ctypes.POINTER(Event), ctypes.c_int 178 ] 179 180 return _lib.caca_get_event(self, event_mask, ctypes.byref(event), 181 timeout) 168 182 169 183 def get_mouse_x(self): … … 217 231 """ Not implemented. 218 232 """ 219 raise DisplayError , "Not implemented"233 raise DisplayError("Not implemented") 220 234 221 235 def get_key_utf8(self): -
libcaca/trunk/python/caca/dither.py
r4707 r4802 72 72 73 73 if self._dither == 0: 74 raise DitherError , "Failed to create dither object"74 raise DitherError("Failed to create dither object") 75 75 76 76 def set_palette(self, red, green, blue, alpha): … … 83 83 alpha -- array of 256 alpha values 84 84 """ 85 raise DitherError , "Not implemented"85 raise DitherError("Not implemented") 86 86 87 87 def set_brightness(self, brightness): -
libcaca/trunk/python/caca/font.py
r4770 r4802 18 18 import errno 19 19 20 from caca import _lib 20 from caca import _lib, _PYTHON3, _str_to_bytes 21 21 22 22 class _Font(object): … … 65 65 _lib.caca_load_font.restype = ctypes.c_int 66 66 67 if _PYTHON3: 68 font = _str_to_bytes(font) 69 67 70 self._font = _lib.caca_load_font(font, size) 68 71 if self._font == 0: -
libcaca/trunk/python/examples/blit.py
r4711 r4802 44 44 cv = Canvas(0, 0) 45 45 dp = Display(cv) 46 except (CanvasError, DisplayError) ,err:46 except (CanvasError, DisplayError) as err: 47 47 sys.stderr.write("%s\n" % err) 48 48 sys.exit(2) … … 51 51 sprite.set_color_ansi(caca.COLOR_LIGHTRED, caca.COLOR_BLACK) 52 52 sprite.import_from_memory(THE_PIG, "text") 53 sprite.set_handle(sprite.get_width()/ 2, sprite.get_height()/2)53 sprite.set_handle(sprite.get_width()//2, sprite.get_height()//2) 54 54 55 55 cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE) 56 56 cv.put_str(0, 0, "Centered sprite") 57 cv.blit(cv.get_width()/ 2, cv.get_height()/2, sprite, NullCanvas())57 cv.blit(cv.get_width()//2, cv.get_height()//2, sprite, NullCanvas()) 58 58 59 59 dp.refresh() -
libcaca/trunk/python/examples/colors.py
r4712 r4802 29 29 cv = Canvas(80, 24) 30 30 dp = Display(cv) 31 except (CanvasError, DisplayError) ,err:31 except (CanvasError, DisplayError) as err: 32 32 sys.stderr.write("%s\n" % err) 33 33 sys.exit(127) … … 36 36 cv.clear() 37 37 38 for i in xrange(0, 16):38 for i in range(0, 16): 39 39 if i >= 8: 40 40 y = i + 3 … … 45 45 cv.printf(3, y, "ANSI %i", i) 46 46 47 for j in xrange(0, 16):47 for j in range(0, 16): 48 48 if j >= 8: 49 49 x = 13 + (j * 4) -
libcaca/trunk/python/examples/drawing.py
r4398 r4802 52 52 array_x = ctypes.c_int * (len(x) + 1) 53 53 array_y = ctypes.c_int * (len(y) + 1) 54 ax = array_x(*x) 55 ay = array_y(*y) 54 array_xy = [ (x, y) for x, y in zip(array_x(*x), array_y(*y))] 56 55 if thin: 57 self.cv.draw_thin_polyline(a x, ay, len(x) + 1)56 self.cv.draw_thin_polyline(array_xy) 58 57 else: 59 self.cv.draw_polyline(a x, ay, len(x) + 1, '#')58 self.cv.draw_polyline(array_xy, '#') 60 59 61 60 def do_circle(self): 62 x = self.cv.get_width() / 263 y = self.cv.get_height() / 261 x = self.cv.get_width() // 2 62 y = self.cv.get_height() // 2 64 63 radius = 5 65 64 self.cv.draw_circle(x, y, radius, '@') 66 65 67 66 def do_ellipse(self, thin=False): 68 x = self.cv.get_width() / 269 y = self.cv.get_height() / 267 x = self.cv.get_width() // 2 68 y = self.cv.get_height() // 2 70 69 a = 7 71 70 b = 3 -
libcaca/trunk/python/examples/driver.py
r4712 r4802 32 32 cv = Canvas(0, 0) 33 33 dp = Display(cv) 34 except (CanvasError, DisplayError) ,err:34 except (CanvasError, DisplayError) as err: 35 35 sys.stderr.write("%s\n" % err) 36 36 sys.exit(127) -
libcaca/trunk/python/examples/event.py
r4712 r4802 71 71 cv = Canvas(80, 24) 72 72 dp = Display(cv) 73 except (CanvasError, DisplayError) ,err:73 except (CanvasError, DisplayError) as err: 74 74 sys.stderr.write("%s\n" % err) 75 75 sys.exit(127) … … 116 116 #print previous events 117 117 cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLACK) 118 counts = range(0, len(events) - 1)118 counts = list(range(0, len(events)-1)) 119 119 counts.reverse() 120 120 if len(events) > 1: -
libcaca/trunk/python/examples/figfont.py
r4772 r4802 17 17 # 18 18 19 import codecs 19 20 import os 20 21 import sys … … 26 27 """ Main function. """ 27 28 28 color = 029 29 30 30 if len(sys.argv) < 3: … … 35 35 try: 36 36 cv = Canvas(0, 0) 37 except CanvasError ,err:37 except CanvasError as err: 38 38 sys.stderr.write("%s\n" % err) 39 39 sys.exit(2) … … 43 43 sys.exit(2) 44 44 45 for c in sys.argv[2].decode('utf8'): 46 color += 4 47 cv.set_color_ansi(1+(color % 15), caca.COLOR_TRANSPARENT) 45 if sys.version_info[0:2] >= (3,0): 46 word = sys.argv[2] 47 else: 48 word = codecs.decode(sys.argv[2], "utf8") 49 for c in word: 48 50 cv.put_figchar(c) 49 51 -
libcaca/trunk/python/examples/font.py
r4770 r4802 31 31 try: 32 32 cv = Canvas(8, 2) 33 except CanvasError ,err:33 except CanvasError as err: 34 34 sys.stderr.write("%s\n" % err) 35 35 sys.exit(127) … … 49 49 try: 50 50 f = Font(fonts[0]) 51 except FontError ,err:51 except FontError as err: 52 52 sys.stderr.write("%s\n" % err) 53 53 sys.exit(127) … … 62 62 try: 63 63 dp = Display(cv) 64 except DisplayError ,err:64 except DisplayError as err: 65 65 sys.stderr.write("%s\n" % err) 66 66 sys.exit(127) 67 67 68 if sys.byteorder == 'big': 69 dit = Dither(32, w, h, 4 * w, 0xff0000, 0xff00, 0xff, 0xff000000) 68 try: 69 if sys.byteorder == 'big': 70 dit = Dither(32, w, h, 4 * w, 0xff0000, 0xff00, 0xff, 0xff000000) 71 else: 72 dit = Dither(32, w, h, 4 * w, 0xff00, 0xff0000, 0xff000000, 0xff) 73 74 dit.bitmap(cv, 0, 0, cv.get_width(), cv.get_height(), buf) 75 except DitherError as err: 76 sys.stderr.write("%s\n" % err) 77 sys.exit(127) 70 78 else: 71 dit = Dither(32, w, h, 4 * w, 0xff00, 0xff0000, 0xff000000, 0xff) 72 73 dit.bitmap(cv, 0, 0, cv.get_width(), cv.get_height(), buf) 74 dp.refresh() 79 dp.refresh() 75 80 76 81 dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1) -
libcaca/trunk/python/examples/frames.py
r4711 r4802 28 28 try: 29 29 cv = Canvas(0, 0) 30 except CanvasError ,err:30 except CanvasError as err: 31 31 sys.stderr.write("%s\n" % err) 32 32 sys.exit(2) … … 47 47 cv.fill_box(0, 0, 40, 15, ':') 48 48 cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE) 49 cv.put_str( idx * 5/ 2, idx, "カカ")49 cv.put_str((idx * 5) // 2, idx, "カカ") 50 50 cv.set_color_ansi(caca.COLOR_DEFAULT, caca.COLOR_TRANSPARENT) 51 51 … … 56 56 try: 57 57 dp = Display(cv) 58 except DisplayError ,err:58 except DisplayError as err: 59 59 sys.stderr.write("%s\n" % err) 60 60 sys.exit(2) -
libcaca/trunk/python/examples/gol.py
r4398 r4802 31 31 self.height = height 32 32 33 for i in xrange(0, self.height):33 for i in range(0, self.height): 34 34 self.array.append([]) 35 for j in xrange(0, self.width):35 for j in range(0, self.width): 36 36 self.array[i].append([]) 37 37 … … 69 69 n = 0 70 70 71 for i in xrange(0, self.height):72 for j in xrange(0, self.width):71 for i in range(0, self.height): 72 for j in range(0, self.width): 73 73 if self.get(i, j): 74 74 n += 1 … … 88 88 def nextCycle(self): 89 89 self.cycle += 1 90 for x in xrange(0, self.ca.height):91 for y in xrange(0, self.ca.width):90 for x in range(0, self.ca.height): 91 for y in range(0, self.ca.width): 92 92 if self.ca.get(x, y): 93 93 if self.ca.neighbors(x, y) >= 2 and self.ca.neighbors(x, y) <= 3: … … 102 102 else: 103 103 self.cbuf.set(x, y, 0) 104 for x in xrange(0, self.ca.height):105 for y in xrange(0, self.ca.width):104 for x in range(0, self.ca.height): 105 for y in range(0, self.ca.width): 106 106 self.ca.set(x, y, self.cbuf.get(x, y)) 107 107 … … 110 110 111 111 def randomCells(self): 112 for x in xrange(0, self.ca.height):113 for y in xrange(0, self.ca.width):112 for x in range(0, self.ca.height): 113 for y in range(0, self.ca.width): 114 114 self.ca.set(x, y, random.randint(0, 1)) 115 115 … … 122 122 cv.put_str(0, cv.get_height()-1, "generation: %d, population: %d" % (self.cycle, self.ca.population())) 123 123 cv.set_color_ansi(caca.COLOR_DEFAULT, caca.COLOR_BLACK) 124 posx = (cv.get_height() - self.height) / 2125 posy = (cv.get_width() - self.width) / 2126 for x in xrange(0, self.ca.height):127 for y in xrange(0, self.ca.width):124 posx = (cv.get_height() - self.height) // 2 125 posy = (cv.get_width() - self.width) // 2 126 for x in range(0, self.ca.height): 127 for y in range(0, self.ca.width): 128 128 if self.ca.get(x, y): 129 cv.put_str(posy+y, posx+x, '@')129 cv.put_str(posy+y, posx+x, "@") 130 130 131 131 def zeroCells(self): 132 for x in xrange(0, self.ca.height):133 for y in xrange(0, self.ca.width):132 for x in range(0, self.ca.height): 133 for y in range(0, self.ca.width): 134 134 self.ca.set(x, y, 0) 135 135 -
libcaca/trunk/python/examples/text.py
r4711 r4802 42 42 pig.import_from_memory(STRING, "text") 43 43 cv = Canvas(pig.get_width() * 2, pig.get_height() * 2) 44 except CanvasError ,err:44 except CanvasError as err: 45 45 sys.stderr.write("%s\n" % err) 46 46 sys.exit(2) … … 56 56 cv.blit(pig.get_width(), pig.get_height(), pig, NullCanvas()) 57 57 58 for j in xrange(0, cv.get_height()):59 for i in xrange(0, cv.get_width(), 2):58 for j in range(0, cv.get_height()): 59 for i in range(0, cv.get_width(), 2): 60 60 cv.set_color_ansi(caca.COLOR_LIGHTBLUE + (i + j) % 6, 61 61 caca.COLOR_DEFAULT) … … 65 65 cv.put_attr(i+1, j, a) 66 66 67 sys.stdout.write(cv.export_to_memory("utf8"))67 print("%s" % cv.export_to_memory('utf8')) 68 68 cv.rotate_left() 69 sys.stdout.write(cv.export_to_memory("utf8"))69 print("%s" % cv.export_to_memory('utf8')) 70 70 71 71 if __name__ == "__main__": -
libcaca/trunk/python/setup.py
r4801 r4802 4 4 # 5 5 6 import sys 6 7 from setuptools import setup 7 8 8 import caca 9 try: 10 import caca 11 except ImportError as err: 12 sys.stderr.write("FATAL: %s\n" % str(err)) 13 sys.exit(127) 14 15 version_string=caca.get_version() 9 16 10 17 setup( … … 12 19 author='Alex Foulon', 13 20 author_email='alxf@lavabit.com', 14 version= caca.get_version(),21 version=version_string, 15 22 packages=['caca'], 16 23 package_dir={ -
libcaca/trunk/python/test/__init__.py
r4801 r4802 19 19 20 20 #test modules 21 import canvas21 from . import canvas 22 22 23 23 #create modules test suite -
libcaca/trunk/python/test/canvas.py
r4801 r4802 75 75 self.assertEqual(10, cv.put_str(0, 0, "teststring")) 76 76 liststring = [] 77 for i in xrange(0, 10):77 for i in range(0, 10): 78 78 liststring.append(cv.get_char(i, 0)) 79 79 … … 89 89 self.assertEqual(10, cv.printf(0, 0, "%s%s", word1, word2)) 90 90 liststring = [] 91 for i in xrange(0, 10):91 for i in range(0, 10): 92 92 liststring.append(cv.get_char(i, 0)) 93 93 self.assertEqual("teststring", "".join(liststring))
Note: See TracChangeset
for help on using the changeset viewer.
