From 6df26ddbf7eb563e66bee2313e71d1c0241b351a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 26 Feb 2010 14:09:43 +0000 Subject: [PATCH] Add pretty-printers for wxPoint, wxSize and wxRect. Also replace an if checking for the supported types with an array-based approach to make it easier to add pretty printers for more types in the future. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63559 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- misc/gdb/print.py | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/misc/gdb/print.py b/misc/gdb/print.py index 9df3beb66c..449edba1ea 100755 --- a/misc/gdb/print.py +++ b/misc/gdb/print.py @@ -10,6 +10,11 @@ # License: wxWindows licence ############################################################################### +# 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. + + # shamelessly stolen from std::string example class wxStringPrinter: def __init__(self, val): @@ -21,9 +26,41 @@ class wxStringPrinter: def display_hint(self): return 'string' +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. def wxLookupFunction(val): - if val.type.tag == 'wxString': - return wxStringPrinter(val) + # 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. + types = ['wxString', 'wxPoint', 'wxSize', 'wxRect'] + + 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) + return None gdb.pretty_printers.append(wxLookupFunction) -- 2.45.2