Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python expressions support #203

Open
ThomasG77 opened this issue May 20, 2021 · 3 comments · May be fixed by #267
Open

Add Python expressions support #203

ThomasG77 opened this issue May 20, 2021 · 3 comments · May be fixed by #267

Comments

@ThomasG77
Copy link

When people use expressions, they sometimes do not find specific functions. You have to make some of them using Python expressions.

Although expressions can be already published, is there any way to also push Python expressions? I missed the functionality or not available?

Triggered by recurring questions on the QGIS users mailing list like https://lists.osgeo.org/pipermail/qgis-user/2021-May/048919.html

Should be possible using the following Python function

@qgsfunction(args='auto', group='Layout')
def get_page_format(layoutname, pagenumber, feature, parent, context):
    layout = QgsProject.instance().layoutManager().layoutByName(layoutname)
    page = layout.pageCollection().page(pagenumber - 1)
    return QgsApplication.pageSizeRegistry().find(page.pageSize())
@Guts
Copy link
Contributor

Guts commented Sep 21, 2021

Thanks for you interest and taking time to report.

According to the documentation, expressions can actually be shared: https://qgis-contribution.github.io/QGIS-ResourceSharing/authoring/what-to-share.html

But I've never tried out this feature. Maybe I'm wrong. Could you confirm please?

@ThomasG77
Copy link
Author

ThomasG77 commented Sep 21, 2021

I can confirm my initial statement or I'm also wrong?! You can easily add new expressions using a JSON file like https://github.com/QGIS-Contribution/QGIS_Test-Resources/blob/master/collections/qgis_test/expressions/testexpressions.json in an expressions directory but it only act more or less as a shortcut for complex expressions you often need and does not always remember.

You can't add them to load magically some Python functions that will act as new expressions. I know I can set Python expressions within profile dedicated directory from

import os
from qgis.core import QgsApplication
os.join.path(QgsApplication.qgisSettingsDirPath(), 'python', 'expressions')

bit I'm not aware you can do it through QGIS-ResourceSharing

@JanCaha
Copy link

JanCaha commented Mar 22, 2022

Can this be reconsidered? It seems like very reasonable idea and clear way to do that would be very desirable.

@Guts Guts linked a pull request Sep 5, 2022 that will close this issue
@Guts Guts linked a pull request Sep 5, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants