File indexing completed on 2024-05-12 04:39:56

0001 # -*- coding: utf-8 -*-
0002 # Pretty-printers for KDE4.
0003 
0004 # SPDX-FileCopyrightText: 2009 Milian Wolff <mail@milianw.de>
0005 # SPDX-FileCopyrightText: 2014 Kevin Funk <kfunk@kde.org>
0006 #
0007 # SPDX-License-Identifier: GPL-2.0-or-later
0008 
0009 import gdb
0010 import itertools
0011 import re
0012 
0013 import qt
0014 
0015 from helper import *
0016 
0017 class KDevelop_Path:
0018     def __init__(self, val):
0019         self.val = val
0020 
0021     def to_string(self):
0022         iterator = qt.QVectorPrinter(self.val['m_data'], 'QVector').children()
0023         pathSegments = [str(it[1]) for it in iterator]
0024         return "(" + ", ".join(pathSegments) + ")" if pathSegments else None
0025 
0026 class KTextEditor_CursorPrinter:
0027     "Pretty Printer for KTextEditor::Cursor"
0028 
0029     def __init__(self, val):
0030         self.val = val
0031 
0032     def to_string(self):
0033         return "[%d, %d]" % (self.val['m_line'], self.val['m_column'])
0034 
0035 class KTextEditor_RangePrinter:
0036     "Pretty Printer for KTextEditor::Range"
0037 
0038     def __init__(self, val):
0039         self.val = val
0040 
0041     def to_string(self):
0042         return "[(%d, %d) -> (%d, %d)]" % (self.val['m_start']['m_line'], self.val['m_start']['m_column'],
0043                                            self.val['m_end']['m_line'], self.val['m_end']['m_column'])
0044 
0045 pretty_printers_dict = {}
0046 
0047 def register_kde_printers (obj):
0048     if obj == None:
0049         obj = gdb
0050 
0051     obj.pretty_printers.append(FunctionLookup(gdb, pretty_printers_dict))
0052 
0053 def build_dictionary ():
0054     pretty_printers_dict[re.compile('^KDevelop::Path$')] = lambda val: KDevelop_Path(val)
0055 
0056     pretty_printers_dict[re.compile('^KTextEditor::Cursor$')] = lambda val: KTextEditor_CursorPrinter(val)
0057     pretty_printers_dict[re.compile('^KTextEditor::Range$')] = lambda val: KTextEditor_RangePrinter(val)
0058 
0059 build_dictionary ()