Skip to content
Permalink
Browse files

Merge pull request #7018 from 3nids/sipify_metaenum_helper

[sipify] write helpers in core.__init__.py for Q_ENUM
  • Loading branch information
3nids committed May 18, 2018
2 parents 610d99c + 7440220 commit 3e9a37cc1a808457e4a2f728b22a8faaaff21738
@@ -48,3 +48,29 @@
QgsProject.blockDirtying = ProjectDirtyBlocker
QgsReadWriteContext.enterCategory = ReadWriteContextEnterCategory
QgsTask.fromFunction = fromFunction

# -----------------
# DO NOT EDIT BELOW
# These are automatically added by calling sipify.pl script
QgsTolerance.UnitType.parentClass = lambda: QgsTolerance
QgsAuthManager.MessageLevel.parentClass = lambda: QgsAuthManager
QgsDataItem.Type.parentClass = lambda: QgsDataItem
QgsDataItem.State.parentClass = lambda: QgsDataItem
QgsLayerItem.LayerType.parentClass = lambda: QgsLayerItem
QgsDataProvider.DataCapability.parentClass = lambda: QgsDataProvider
QgsDataSourceUri.SslMode.parentClass = lambda: QgsDataSourceUri
QgsNetworkContentFetcherRegistry.FetchingMode.parentClass = lambda: QgsNetworkContentFetcherRegistry
QgsSnappingConfig.SnappingMode.parentClass = lambda: QgsSnappingConfig
QgsSnappingConfig.SnappingType.parentClass = lambda: QgsSnappingConfig
QgsUnitTypes.DistanceUnit.parentClass = lambda: QgsUnitTypes
QgsUnitTypes.AreaUnit.parentClass = lambda: QgsUnitTypes
QgsUnitTypes.AngleUnit.parentClass = lambda: QgsUnitTypes
QgsUnitTypes.RenderUnit.parentClass = lambda: QgsUnitTypes
QgsUnitTypes.LayoutUnit.parentClass = lambda: QgsUnitTypes
QgsVectorSimplifyMethod.SimplifyHint.parentClass = lambda: QgsVectorSimplifyMethod
QgsVectorSimplifyMethod.SimplifyAlgorithm.parentClass = lambda: QgsVectorSimplifyMethod
QgsRasterProjector.Precision.parentClass = lambda: QgsRasterProjector
QgsAbstractGeometry.SegmentationToleranceType.parentClass = lambda: QgsAbstractGeometry
QgsGeometry.BufferSide.parentClass = lambda: QgsGeometry
QgsGeometry.EndCapStyle.parentClass = lambda: QgsGeometry
QgsGeometry.JoinStyle.parentClass = lambda: QgsGeometry
@@ -25,3 +25,17 @@

from qgis.PyQt import QtCore
from qgis._gui import *

# -----------------
# DO NOT EDIT BELOW
# These are automatically added by calling sipify.pl script
QgsAuthSettingsWidget.WarningType.parentClass = lambda: QgsAuthSettingsWidget
QgsColorButton.Behavior.parentClass = lambda: QgsColorButton
QgsColorTextWidget.ColorTextFormat.parentClass = lambda: QgsColorTextWidget
QgsFilterLineEdit.ClearMode.parentClass = lambda: QgsFilterLineEdit
QgsFloatingWidget.AnchorPoint.parentClass = lambda: QgsFloatingWidget
QgsFontButton.Mode.parentClass = lambda: QgsFontButton
QgsMapToolIdentify.IdentifyMode.parentClass = lambda: QgsMapToolIdentify
QgsAttributeTableFilterModel.FilterMode.parentClass = lambda: QgsAttributeTableFilterModel
QgsAttributeTableFilterModel.ColumnType.parentClass = lambda: QgsAttributeTableFilterModel
QgsDualView.ViewMode.parentClass = lambda: QgsDualView
@@ -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 @@

# 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 @@ 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.*?$/){
@@ -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);
}
@@ -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 )
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
#set -e

DIR=$(git rev-parse --show-toplevel)

@@ -15,22 +15,30 @@ pushd ${DIR} > /dev/null
modules=(core gui analysis server)

code=0
while read -r sipfile; do
header=$(${GP}sed -E 's@(.*)\.sip@src/\1.h@; s@auto_generated/@@' <<< $sipfile)
if [ ! -f $header ]; then
echo "*** Missing header: $header for sipfile $sipfile"
else
outdiff=$(./scripts/sipify.pl $header | diff python/$sipfile.in -)
if [[ -n $outdiff ]]; then
echo " *** SIP file not up to date: $sipfile"
code=1
fi
fi
done < <(
for module in "${modules[@]}"; do
${GP}sed -n -r "s@^%Include auto_generated/(.*\.sip)@${module}/auto_generated/\1@p" python/${module}/${module}_auto.sip
done
module_init=${DIR}/python/${module}/__init__.py
cp ${module_init} ${DIR}/${module}.temp
while read -r sipfile; do
header=$(${GP}sed -E 's@(.*)\.sip@src/\1.h@; s@auto_generated/@@' <<< $sipfile)
if [ ! -f $header ]; then
echo "*** Missing header: $header for sipfile $sipfile"
else
outdiff=$(./scripts/sipify.pl -p ${DIR}/${module}.temp $header | diff python/$sipfile.in -)
if [[ -n "$outdiff" ]]; then
echo " *** SIP file not up to date: $sipfile"
code=1
fi
fi
done < <(
${GP}sed -n -r "s@^%Include auto_generated/(.*\.sip)@${module}/auto_generated/\1@p" python/${module}/${module}_auto.sip
)
outdiff=$(diff ${module_init} ${DIR}/${module}.temp)
if [[ -n "$outdiff" ]]; then
echo " *** Python ${module} (${module_init}) init not up to date: run sipify with -p argument"
code=1
fi
rm ${DIR}/${module}.temp
done


popd > /dev/null

0 comments on commit 3e9a37c

Please sign in to comment.
You can’t perform that action at this time.