]> git.saurik.com Git - wxWidgets.git/blame - misc/gdb/print.py
Don't handle branches specially when sorting items in wxDataViewCtrl.
[wxWidgets.git] / misc / gdb / print.py
CommitLineData
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
14f38667 17import datetime
6df26ddb 18
3b9aa4e8
VZ
19# shamelessly stolen from std::string example
20class wxStringPrinter:
21 def __init__(self, val):
22 self.val = val
23
24 def to_string(self):
9513aa80 25 return self.val['m_impl']['_M_dataplus']['_M_p'].string()
3b9aa4e8 26
753dc0f7
VZ
27 def display_hint(self):
28 return 'string'
29
14f38667
VZ
30class wxDateTimePrinter:
31 def __init__(self, val):
32 self.val = val
33
34 def to_string(self):
35 # A value of type wxLongLong can't be used in Python arithmetic
36 # expressions directly so we need to convert it to long long first and
37 # then cast to int explicitly to be able to use it as a timestamp.
38 msec = self.val['m_time'].cast(gdb.lookup_type('long long'))
d4bc7a16
VZ
39 if msec == 0x8000000000000000:
40 return 'NONE'
14f38667
VZ
41 sec = int(msec / 1000)
42 return datetime.datetime.fromtimestamp(sec).isoformat(' ')
43
a6a181a3
VZ
44class wxFileNamePrinter:
45 def __init__(self, val):
46 self.val = val
47
48 def to_string(self):
49 # It is simpler to just call the internal function here than to iterate
50 # over m_dirs array ourselves. The disadvantage of this approach is
51 # that it requires a live inferior process and so doesn't work when
52 # debugging using only a core file. If this ever becomes a serious
53 # problem, this should be rewritten to use m_dirs and m_name and m_ext.
54 return gdb.parse_and_eval('((wxFileName*)%s)->GetFullPath(0)' %
55 self.val.address)
56
6df26ddb
VZ
57class wxXYPrinterBase:
58 def __init__(self, val):
59 self.x = val['x']
60 self.y = val['y']
61
62class wxPointPrinter(wxXYPrinterBase):
63 def to_string(self):
64 return '(%d, %d)' % (self.x, self.y)
65
66class wxSizePrinter(wxXYPrinterBase):
67 def to_string(self):
68 return '%d*%d' % (self.x, self.y)
69
70class wxRectPrinter(wxXYPrinterBase):
71 def __init__(self, val):
72 wxXYPrinterBase.__init__(self, val)
73 self.width = val['width']
74 self.height = val['height']
75
76 def to_string(self):
77 return '(%d, %d) %d*%d' % (self.x, self.y, self.width, self.height)
78
79
80# The function looking up the pretty-printer to use for the given value.
753dc0f7 81def wxLookupFunction(val):
6df26ddb
VZ
82 # Using a list is probably ok for so few items but consider switching to a
83 # set (or a dict and cache class types as the keys in it?) if needed later.
a6a181a3
VZ
84 types = ['wxString',
85 'wxDateTime',
86 'wxFileName',
87 'wxPoint',
88 'wxSize',
89 'wxRect']
6df26ddb
VZ
90
91 for t in types:
92 if val.type.tag == t:
93 # Not sure if this is the best name to create the object of a class
94 # by name but at least it beats eval()
95 return globals()[t + 'Printer'](val)
96
753dc0f7
VZ
97 return None
98
99gdb.pretty_printers.append(wxLookupFunction)