]>
git.saurik.com Git - wxWidgets.git/blob - misc/gdb/print.py
1 ###############################################################################
2 # Name: misc/gdb/print.py
3 # Purpose: pretty-printers for wx data structures: this file is meant to
4 # be sourced from gdb using "source -p" (or, better, autoloaded
6 # Author: Vadim Zeitlin
9 # Copyright: (c) 2009 Vadim Zeitlin
10 # Licence: wxWindows licence
11 ###############################################################################
13 # Define wxFooPrinter class implementing (at least) to_string() method for each
14 # wxFoo class we want to pretty print. Then just add wxFoo to the types array
15 # in wxLookupFunction at the bottom of this file.
18 # shamelessly stolen from std::string example
19 class wxStringPrinter
:
20 def __init__(self
, val
):
24 return self
.val
['m_impl']['_M_dataplus']['_M_p'].string()
26 def display_hint(self
):
29 class wxXYPrinterBase
:
30 def __init__(self
, val
):
34 class wxPointPrinter(wxXYPrinterBase
):
36 return '(%d, %d)' % (self
.x
, self
.y
)
38 class wxSizePrinter(wxXYPrinterBase
):
40 return '%d*%d' % (self
.x
, self
.y
)
42 class wxRectPrinter(wxXYPrinterBase
):
43 def __init__(self
, val
):
44 wxXYPrinterBase
.__init
__(self
, val
)
45 self
.width
= val
['width']
46 self
.height
= val
['height']
49 return '(%d, %d) %d*%d' % (self
.x
, self
.y
, self
.width
, self
.height
)
52 # The function looking up the pretty-printer to use for the given value.
53 def wxLookupFunction(val
):
54 # Using a list is probably ok for so few items but consider switching to a
55 # set (or a dict and cache class types as the keys in it?) if needed later.
56 types
= ['wxString', 'wxPoint', 'wxSize', 'wxRect']
60 # Not sure if this is the best name to create the object of a class
61 # by name but at least it beats eval()
62 return globals()[t
+ 'Printer'](val
)
66 gdb
.pretty_printers
.append(wxLookupFunction
)