mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[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
This commit is contained in:
parent
83ccff2aad
commit
6301f9b6f3
@ -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
|
||||
|
@ -23,9 +23,12 @@ use constant CODE_SNIPPET_CPP => 31;
|
||||
|
||||
# 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
|
||||
@ -603,11 +606,33 @@ while ($LINE_IDX < $LINE_COUNT){
|
||||
# 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.*?$/){
|
||||
@ -1102,4 +1127,10 @@ while ($LINE_IDX < $LINE_COUNT){
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
@ -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 )
|
||||
|
Loading…
x
Reference in New Issue
Block a user