... ça devenait insoutenable. Alors j'ai implémenté des fonctions de sérialisation du style my_object_to_string() mais très vite ca deviens l'enfer dans ma console.
Aujourd'hui j'utilise gdb pour visualiser les données mais ce n'est pas toujours évident avec les GList, les GObject, GtkWidget, etc...
Ainsi, j'ai commencer a utiliser ce qu'on appel des
pretty-printer. Et j'en suis plutôt content.
Seulement voila. Hier, je suis tombé sur un nouveau bug avec les cairo_path_t j'ai donc créer le nécessaire pour visualiser ce que contenait CairoPath et ainsi détecter rapidement le bug.
Sans pretty-printer |
Avec pretty-printer |
Avec pretty-printer |
|
|
|
Le code nécessaire
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
class cairo__PathPrinter:
"Prints a cairo_path_t"
class _iterator:
"Iterator by cairo_path_data_t.header"
def __init__(self, path):
self.path = path
if path:
self.data = path["data"]
self.num_data = path["num_data"]
#self.status = path["status"]
self.pos = 0
self.command = ""
self.points = {}
self.attributes= []
def __iter__(self):
return self
def next(self):
if not self.path:
raise StopIteration
if self.pos >= self.num_data:
raise StopIteration
length = int(self.data[self.pos]["header"]["length"])
end = self.pos + length
self.command = self.data[self.pos]["header"]["type"]
self.points = {}
self.attributes= []
index = 1
suff = ""
if length>2:
suff = "1"
self.pos += 1
while self.pos < end:
self.points["x%s" % suff] = float(self.data[self.pos]["point"]["x"])
self.points["y%s" % suff] = float(self.data[self.pos]["point"]["y"])
self.attributes.append("x%s" % suff)
self.attributes.append("y%s" % suff)
self.pos += 1
index += 1
suff = "%d" % index
return (self.command, self.points, self.attributes)
__next__ = next # Python 3: def __next__(self)
def __init__ (self, val):
self.path = val
def segment(self):
return self._iterator(self.path)
def count(self):
size = 0
for seg in self.segment(): size += 1
return size |
Mais je dois bien me rendre a l'évidence que je ne suis pas un killer en Phython et je perd beaucoup de temps simplement pour pourvoir voir les données en mémoire.
Partager