Skip to content

Commit

Permalink
[sipify] write helpers in core.__init__.py for Q_ENUM
Browse files Browse the repository at this point in the history
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
  • Loading branch information
3nids committed May 18, 2018
1 parent 83ccff2 commit 6301f9b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scripts/prepare-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ for f in $MODIFIED; do
m=python/$sip_file.$REV.prepare
touch python/$sip_file
cp python/$sip_file $m
${TOPLEVEL}/scripts/sipify.pl $f > python/$sip_file
${TOPLEVEL}/scripts/sipify.pl -s python/$sip_file -p python/${module}/__init__.py $f
if ! diff -u $m python/$sip_file >>$SIPIFYDIFF; then
echo "python/$sip_file is not up to date"
fi
Expand Down
35 changes: 33 additions & 2 deletions scripts/sipify.pl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@

# read arguments
my $debug = 0;
my $sip_output = '';
my $python_output = '';
#my $SUPPORT_TEMPLATE_DOCSTRING = 0;
#die("usage: $0 [-debug] [-template-doc] headerfile\n") unless GetOptions ("debug" => \$debug, "template-doc" => \$SUPPORT_TEMPLATE_DOCSTRING) && @ARGV == 1;
die("usage: $0 [-debug] headerfile\n") unless GetOptions ("debug" => \$debug) && @ARGV == 1;
die("usage: $0 [-debug] [-sip_output FILE] [-python_output FILE] headerfile\n")
unless GetOptions ("debug" => \$debug, "sip_output=s" => \$sip_output, "python_output=s" => \$python_output) && @ARGV == 1;
my $headerfile = $ARGV[0];

# read file
Expand Down Expand Up @@ -603,11 +606,33 @@ sub detect_non_method_member{
# insert metaoject for Q_GADGET
if ($LINE =~ m/^\s*Q_GADGET\b.*?$/){
if ($LINE !~ m/SIP_SKIP/){
dbg_info('Q_GADGET');
write_output("HCE", " public:\n");
write_output("HCE", " static const QMetaObject staticMetaObject;\n\n");
}
next;
}
if ($LINE =~ m/Q_ENUM\(\s*(\w+)\s*\)/ ){
if ($LINE !~ m/SIP_SKIP/){
my $enum_helper = "$ACTUAL_CLASS.$1.parentClass = lambda: $ACTUAL_CLASS";
dbg_info("Q_ENUM $enum_helper");
if ($python_output ne ''){
my $pl;
open(FH, '+<', $python_output) or die $!;
foreach $pl (<FH>) {
if ($pl =~ m/$enum_helper/){
$enum_helper = '';
last;
}
}
if ($enum_helper ne ''){
print FH "$enum_helper\n";
}
close(FH);
}
}
next;
}

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

print join('',@OUTPUT);
if ( $sip_output ne ''){
open(FH, '>', $sip_output) or die $!;
print FH join('',@OUTPUT);
close(FH);
} else {
print join('',@OUTPUT);
}
2 changes: 1 addition & 1 deletion scripts/sipify_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ for module in "${modules[@]}"; do
else
path=$(${GP}sed -r 's@/[^/]+$@@' <<< $sipfile)
mkdir -p python/$path
./scripts/sipify.pl $header > python/$sipfile.in &
./scripts/sipify.pl -s python/$sipfile.in -p python/${module}/__init__.py $header &
fi
count=$((count+1))
done < <( ${GP}sed -n -r "s@^%Include auto_generated/(.*\.sip)@${module}/auto_generated/\1@p" python/${module}/${module}_auto.sip )
Expand Down

0 comments on commit 6301f9b

Please sign in to comment.