]>
Commit | Line | Data |
---|---|---|
3b9aa4e8 VZ |
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 | |
5 | # in the future...) | |
6 | # Author: Vadim Zeitlin | |
7 | # Created: 2009-01-04 | |
526954c5 | 8 | # RCS-Id: $Id$ |
3b9aa4e8 | 9 | # Copyright: (c) 2009 Vadim Zeitlin |
526954c5 | 10 | # Licence: wxWindows licence |
3b9aa4e8 VZ |
11 | ############################################################################### |
12 | ||
6df26ddb VZ |
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. | |
16 | ||
17 | ||
3b9aa4e8 VZ |
18 | # shamelessly stolen from std::string example |
19 | class wxStringPrinter: | |
20 | def __init__(self, val): | |
21 | self.val = val | |
22 | ||
23 | def to_string(self): | |
24 | return '"' + self.val['m_impl']['_M_dataplus']['_M_p'].string() + '"' | |
25 | ||
753dc0f7 VZ |
26 | def display_hint(self): |
27 | return 'string' | |
28 | ||
6df26ddb VZ |
29 | class wxXYPrinterBase: |
30 | def __init__(self, val): | |
31 | self.x = val['x'] | |
32 | self.y = val['y'] | |
33 | ||
34 | class wxPointPrinter(wxXYPrinterBase): | |
35 | def to_string(self): | |
36 | return '(%d, %d)' % (self.x, self.y) | |
37 | ||
38 | class wxSizePrinter(wxXYPrinterBase): | |
39 | def to_string(self): | |
40 | return '%d*%d' % (self.x, self.y) | |
41 | ||
42 | class wxRectPrinter(wxXYPrinterBase): | |
43 | def __init__(self, val): | |
44 | wxXYPrinterBase.__init__(self, val) | |
45 | self.width = val['width'] | |
46 | self.height = val['height'] | |
47 | ||
48 | def to_string(self): | |
49 | return '(%d, %d) %d*%d' % (self.x, self.y, self.width, self.height) | |
50 | ||
51 | ||
52 | # The function looking up the pretty-printer to use for the given value. | |
753dc0f7 | 53 | def wxLookupFunction(val): |
6df26ddb VZ |
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'] | |
57 | ||
58 | for t in types: | |
59 | if val.type.tag == t: | |
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) | |
63 | ||
753dc0f7 VZ |
64 | return None |
65 | ||
66 | gdb.pretty_printers.append(wxLookupFunction) |