2009-01-04 16:15:19 -05:00
|
|
|
###############################################################################
|
|
|
|
# Name: misc/gdb/print.py
|
|
|
|
# Purpose: pretty-printers for wx data structures: this file is meant to
|
|
|
|
# be sourced from gdb using "source -p" (or, better, autoloaded
|
|
|
|
# in the future...)
|
|
|
|
# Author: Vadim Zeitlin
|
|
|
|
# Created: 2009-01-04
|
2010-07-13 09:29:13 -04:00
|
|
|
# RCS-Id: $Id$
|
2009-01-04 16:15:19 -05:00
|
|
|
# Copyright: (c) 2009 Vadim Zeitlin
|
2010-07-13 09:29:13 -04:00
|
|
|
# Licence: wxWindows licence
|
2009-01-04 16:15:19 -05:00
|
|
|
###############################################################################
|
|
|
|
|
2010-02-26 09:09:43 -05:00
|
|
|
# Define wxFooPrinter class implementing (at least) to_string() method for each
|
|
|
|
# wxFoo class we want to pretty print. Then just add wxFoo to the types array
|
|
|
|
# in wxLookupFunction at the bottom of this file.
|
|
|
|
|
2012-03-24 20:31:38 -04:00
|
|
|
import datetime
|
2010-02-26 09:09:43 -05:00
|
|
|
|
2009-01-04 16:15:19 -05:00
|
|
|
# shamelessly stolen from std::string example
|
|
|
|
class wxStringPrinter:
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
2010-10-22 10:17:22 -04:00
|
|
|
return self.val['m_impl']['_M_dataplus']['_M_p'].string()
|
2009-01-04 16:15:19 -05:00
|
|
|
|
2009-11-11 18:08:41 -05:00
|
|
|
def display_hint(self):
|
|
|
|
return 'string'
|
|
|
|
|
2012-03-24 20:31:38 -04:00
|
|
|
class wxDateTimePrinter:
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
# A value of type wxLongLong can't be used in Python arithmetic
|
|
|
|
# expressions directly so we need to convert it to long long first and
|
|
|
|
# then cast to int explicitly to be able to use it as a timestamp.
|
|
|
|
msec = self.val['m_time'].cast(gdb.lookup_type('long long'))
|
|
|
|
sec = int(msec / 1000)
|
|
|
|
return datetime.datetime.fromtimestamp(sec).isoformat(' ')
|
|
|
|
|
2010-02-26 09:09:43 -05:00
|
|
|
class wxXYPrinterBase:
|
|
|
|
def __init__(self, val):
|
|
|
|
self.x = val['x']
|
|
|
|
self.y = val['y']
|
|
|
|
|
|
|
|
class wxPointPrinter(wxXYPrinterBase):
|
|
|
|
def to_string(self):
|
|
|
|
return '(%d, %d)' % (self.x, self.y)
|
|
|
|
|
|
|
|
class wxSizePrinter(wxXYPrinterBase):
|
|
|
|
def to_string(self):
|
|
|
|
return '%d*%d' % (self.x, self.y)
|
|
|
|
|
|
|
|
class wxRectPrinter(wxXYPrinterBase):
|
|
|
|
def __init__(self, val):
|
|
|
|
wxXYPrinterBase.__init__(self, val)
|
|
|
|
self.width = val['width']
|
|
|
|
self.height = val['height']
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
return '(%d, %d) %d*%d' % (self.x, self.y, self.width, self.height)
|
|
|
|
|
|
|
|
|
|
|
|
# The function looking up the pretty-printer to use for the given value.
|
2009-11-11 18:08:41 -05:00
|
|
|
def wxLookupFunction(val):
|
2010-02-26 09:09:43 -05:00
|
|
|
# Using a list is probably ok for so few items but consider switching to a
|
|
|
|
# set (or a dict and cache class types as the keys in it?) if needed later.
|
2012-03-24 20:31:38 -04:00
|
|
|
types = ['wxString', 'wxDateTime', 'wxPoint', 'wxSize', 'wxRect']
|
2010-02-26 09:09:43 -05:00
|
|
|
|
|
|
|
for t in types:
|
|
|
|
if val.type.tag == t:
|
|
|
|
# Not sure if this is the best name to create the object of a class
|
|
|
|
# by name but at least it beats eval()
|
|
|
|
return globals()[t + 'Printer'](val)
|
|
|
|
|
2009-11-11 18:08:41 -05:00
|
|
|
return None
|
|
|
|
|
|
|
|
gdb.pretty_printers.append(wxLookupFunction)
|