File: sip_tools.py

package info (click to toggle)
wxwidgets3.2 3.2.8%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 179,460 kB
  • sloc: cpp: 992,335; ansic: 102,143; makefile: 51,623; sh: 11,572; python: 5,590; perl: 1,563; php: 326; xml: 200; javascript: 181
file content (84 lines) | stat: -rw-r--r-- 3,039 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os

from common import *

class SIPBuilder:
    def __init__(self, doxyparse, outputdir):
        self.doxyparser = doxyparse
        self.output_dir = outputdir

    def make_bindings(self):
        output_dir = os.path.abspath(os.path.join(self.output_dir, "sip"))
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        for aclass in self.doxyparser.classes:
            if aclass.name in excluded_classes:
                print "Skipping %s" % aclass.name
                continue

            header_name = aclass.name[2:].lower()
            filename = os.path.join(output_dir, "_" + header_name + ".sip")
            enums_text = make_enums(aclass)
            method_text = self.make_sip_methods(aclass)
            base_class = get_first_value(aclass.bases)
            if base_class != "":
                base_class = ": %s" % base_class

            text = """
%s
class %s %s
{
%%TypeHeaderCode
#include <%s>
%%End

public:
%s
};
""" % (enums_text, aclass.name, base_class, get_first_value(aclass.includes), method_text)

            afile = open(filename, "wb")
            afile.write(text)
            afile.close()


    def make_sip_methods(self, aclass):
        retval = ""

        for amethod in aclass.constructors + aclass.methods:
            transfer = ""

            # FIXME: we need to come up with a way of filtering the methods out by various criteria
            # including parameters and method name, and how to deal with overloads
            if aclass.name in ignored_methods:
                should_ignore = False
                for method in ignored_methods[aclass.name]:
                    print "method = %s" % method
                    if method == amethod.name:
                        params = ignored_methods[aclass.name][method]
                        should_ignore = True
                        for i in xrange(len(params)):
                            if i >= len(amethod.params):
                                should_ignore = False
                                break
                            elif amethod.params[i]["type"] != params[i]:
                                print "param type = %s, amethod.param type = %s" % (params[i], amethod.params[i]["type"])
                                should_ignore = False
                                break

                if should_ignore:
                    continue

            # We need to let SIP know when wx is responsible for deleting the object.
            # We do this if the class is derived from wxWindow, since wxTLW manages child windows
            # and wxApp deletes all wxTLWs on shutdown
            if amethod in aclass.constructors and self.doxyparser.is_derived_from_base(aclass, "wxWindow"):
                transfer = "/Transfer/"

            if amethod.name.startswith("operator"):
                continue

            retval += "    %s %s%s%s;\n\n" % (amethod.return_type.replace("virtual ", ""), amethod.name, amethod.argsstring, transfer)

        return retval