Skip to content

Commit 6301f9b

Browse files
committed
[sipify] write helpers in core.__init__.py for Q_ENUM
whenever reading a Q_ENUM macro, sipify will create a helper in the core module: BaseClass.EnumType.parentClass = lamda: BaseClass this will allow to use the meta object to access the QMetaEnum of the object
1 parent 83ccff2 commit 6301f9b

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

‎scripts/prepare-commit.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ for f in $MODIFIED; do
121121
m=python/$sip_file.$REV.prepare
122122
touch python/$sip_file
123123
cp python/$sip_file $m
124-
${TOPLEVEL}/scripts/sipify.pl $f > python/$sip_file
124+
${TOPLEVEL}/scripts/sipify.pl -s python/$sip_file -p python/${module}/__init__.py $f
125125
if ! diff -u $m python/$sip_file >>$SIPIFYDIFF; then
126126
echo "python/$sip_file is not up to date"
127127
fi

‎scripts/sipify.pl‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323

2424
# read arguments
2525
my $debug = 0;
26+
my $sip_output = '';
27+
my $python_output = '';
2628
#my $SUPPORT_TEMPLATE_DOCSTRING = 0;
2729
#die("usage: $0 [-debug] [-template-doc] headerfile\n") unless GetOptions ("debug" => \$debug, "template-doc" => \$SUPPORT_TEMPLATE_DOCSTRING) && @ARGV == 1;
28-
die("usage: $0 [-debug] headerfile\n") unless GetOptions ("debug" => \$debug) && @ARGV == 1;
30+
die("usage: $0 [-debug] [-sip_output FILE] [-python_output FILE] headerfile\n")
31+
unless GetOptions ("debug" => \$debug, "sip_output=s" => \$sip_output, "python_output=s" => \$python_output) && @ARGV == 1;
2932
my $headerfile = $ARGV[0];
3033

3134
# read file
@@ -603,11 +606,33 @@ sub detect_non_method_member{
603606
# insert metaoject for Q_GADGET
604607
if ($LINE =~ m/^\s*Q_GADGET\b.*?$/){
605608
if ($LINE !~ m/SIP_SKIP/){
609+
dbg_info('Q_GADGET');
606610
write_output("HCE", " public:\n");
607611
write_output("HCE", " static const QMetaObject staticMetaObject;\n\n");
608612
}
609613
next;
610614
}
615+
if ($LINE =~ m/Q_ENUM\(\s*(\w+)\s*\)/ ){
616+
if ($LINE !~ m/SIP_SKIP/){
617+
my $enum_helper = "$ACTUAL_CLASS.$1.parentClass = lambda: $ACTUAL_CLASS";
618+
dbg_info("Q_ENUM $enum_helper");
619+
if ($python_output ne ''){
620+
my $pl;
621+
open(FH, '+<', $python_output) or die $!;
622+
foreach $pl (<FH>) {
623+
if ($pl =~ m/$enum_helper/){
624+
$enum_helper = '';
625+
last;
626+
}
627+
}
628+
if ($enum_helper ne ''){
629+
print FH "$enum_helper\n";
630+
}
631+
close(FH);
632+
}
633+
}
634+
next;
635+
}
611636

612637
# Skip Q_OBJECT, Q_PROPERTY, Q_ENUM etc.
613638
if ($LINE =~ m/^\s*Q_(OBJECT|ENUMS|ENUM|FLAG|PROPERTY|DECLARE_METATYPE|DECLARE_TYPEINFO|NOWARN_DEPRECATED_(PUSH|POP))\b.*?$/){
@@ -1102,4 +1127,10 @@ sub detect_non_method_member{
11021127
}
11031128
write_header_footer();
11041129

1105-
print join('',@OUTPUT);
1130+
if ( $sip_output ne ''){
1131+
open(FH, '>', $sip_output) or die $!;
1132+
print FH join('',@OUTPUT);
1133+
close(FH);
1134+
} else {
1135+
print join('',@OUTPUT);
1136+
}

‎scripts/sipify_all.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ for module in "${modules[@]}"; do
4747
else
4848
path=$(${GP}sed -r 's@/[^/]+$@@' <<< $sipfile)
4949
mkdir -p python/$path
50-
./scripts/sipify.pl $header > python/$sipfile.in &
50+
./scripts/sipify.pl -s python/$sipfile.in -p python/${module}/__init__.py $header &
5151
fi
5252
count=$((count+1))
5353
done < <( ${GP}sed -n -r "s@^%Include auto_generated/(.*\.sip)@${module}/auto_generated/\1@p" python/${module}/${module}_auto.sip )

0 commit comments

Comments
 (0)