67 Commits

Author SHA1 Message Date
Denis Rouzaud
b4ec9a3190
[pyqgis] add QgsSettings.enumValue and flagValue to the bindings (#7024)
* [pyqgis] add QgsSettings.enumValue and flagValue to the bindings

these are done in pure Python since no implementation is possible in SIP

there is a dirty hack for flags since QgsMapLayerProxyModel.Filters.__qualname__
returns 'Filters' and not 'QgsMapLayerProxyModel.Filters'

* fix typo
2018-05-18 09:25:12 -08:00
Denis Rouzaud
deccf205cf
[pyqgis] add method to retrieve metaEnum from an enum value or type (#7023) 2018-05-18 06:47:18 -08:00
Denis Rouzaud
f267adc37a run sipify 2018-05-17 22:54:39 -04:00
Denis Rouzaud
2abcfa23b8 do not add static QMetaObject to QgsDefaultValue
it has no Q_ENUM so no need for now
I do not understand while it doesn't compile though
2018-05-16 14:25:01 -04:00
Denis Rouzaud
95ecea897a move additions from top __init__ to core.__init__ 2018-05-16 11:29:28 -04:00
Denis Rouzaud
261e5f74ec bring back PyQt.QtCore.NULL in qgis.core 2018-05-14 19:53:02 -04:00
Denis Rouzaud
6e33bdcdc4 [pyqgis] move qgis.core tricks to their own python file in additions folder
this makes the code much easier to read
2018-05-14 18:00:39 -04:00
Denis Rouzaud
45e5b3fb79 [pyqgis] comment some core additions 2018-05-14 10:21:07 -04:00
Nyall Dawson
60afeadf44 Add QgsProjectDirtyBlocker and QgsProject.blockDirtying to prevent
project dirtying for the lifetime of an object

Python code can then call:

    project = QgsProject.instance()
    with QgsProject.blockDirtying(project):
      # do something

Use QgsProjectDirtyBlocker to prevent projects being marked as
dirty while creating a new project or while loading an existing
project -- avoids the titlebar temporarily showing the project
state as unsaved while it is being loaded.
2018-03-11 08:44:51 +11:00
Nyall Dawson
f2a6780973 Sipify and style 2018-03-05 19:15:06 +10:00
Denis Rouzaud
4e2eb0eb9c use a pointer otherwise Python is creating a copy 2018-02-28 13:43:11 -04:00
Denis Rouzaud
d171ca7ae4 offer enterCategory in Python bindings by adding a context manager 2018-02-28 13:43:11 -04:00
Denis Rouzaud
3dc3d9d1b2 unite QgsMessageLog::Level and QgsMessageBar::MessageLevel in Qgis::MessageLevel
make enum items lower case
remove unused QgsMessageLog::None and All
2018-02-06 08:56:40 -04:00
Matthias Kuhn
e025011799
Make Mr. Travis happy 2017-09-29 17:52:33 +02:00
Matthias Kuhn
900be9f57f
Properly report QgsDefaultValue.__bool__ in Python 2017-09-29 17:52:30 +02:00
Matthias Kuhn
ca5a0bb3de
Fix python expression functions 2017-09-29 17:01:33 +02:00
Etienne Trimaille
c606abc702 enable custom help in python expressions 2017-08-23 12:00:57 +02:00
Nyall Dawson
bc9b1b64f9 Astyle 2017-06-12 07:28:36 +10:00
Nyall Dawson
cb41ef1adc Output useful logging when running algorithms from toolbox
Now outputs the input parameters, execution time, and results
2017-06-12 07:26:02 +10:00
Matthias Kuhn
1e4c1595c0 Adapt “@qgsfunction" decorator to new expression structure 2017-05-19 07:13:11 +02:00
Matthias Kuhn
5f7a2912f6 Expose "context" to expression functions 2017-05-05 15:39:29 +02:00
Juergen E. Fischer
c77172ed3d fix more flake8 warnings 2017-03-05 10:21:24 +01:00
Denis Rouzaud
b119744773 replace cancelling, cancelled and cancellation by canceling, canceled and cancelation, respectively (#4000)
* replace cancelling and cancelled by canceling and canceled, respectively

see https://github.com/qgis/qgis3_UIX_discussion/issues/19

* replace cancellation by cancelation
2017-01-16 22:27:14 +01:00
Nyall Dawson
b5480633e4 Standardise names for static variables
All non-const variables are prefixed with "s", all const
statics are ALL_CAPS
2017-01-14 16:40:24 +10:00
Nyall Dawson
9d4adc1c70 Remove some singletons by moving instances to QgsApplication
- QgsColorSchemeRegistry
- QgsDataItemProviderRegistry
- QgsGPSConnectionRegistry
- QgsMessageLog
- QgsPaintEffectRegistry
- QgsPluginLayerRegistry
- QgsRasterRendererRegistry
- QgsRendererRegistry
- QgsSvgCache
- QgsSymbolLayerRegistry
2016-12-28 16:59:03 +10:00
Nyall Dawson
cc702c9c81 Remove (probably unnecessary) copy_func usage 2016-12-05 16:46:10 +10:00
Nyall Dawson
d03d0a5b47 Add some python docstrings to QgsTask.fromFunction 2016-12-05 14:08:12 +10:00
Nyall Dawson
e35420a8d9 Force QgsTask::run() to fully complete
Remove support for signal based completion/termination

Also unfortunately disable a lot of the test suite as a result,
since it's not easily translatable
2016-12-05 14:08:12 +10:00
Nyall Dawson
297b5724df QgsTask is no longer a QRunnable
Instead use a private wrapper class to make QgsTask compatible
with QThreadPool
2016-12-05 14:08:12 +10:00
Nyall Dawson
29f310c070 Convert QgsTask.fromFunction to a static method 2016-12-05 14:08:11 +10:00
Nyall Dawson
619381c0ad Call QgsTaskWrapper.on_finished with exception rather than result 2016-12-05 14:08:11 +10:00
Nyall Dawson
fded1a1f39 Don't explode returned values in QgsTaskWrapper
Breaks returning list values
2016-12-05 14:08:11 +10:00
Nyall Dawson
0dcff4491e Respect QgsTask::CanCancel flag in gui 2016-12-05 14:08:11 +10:00
Nyall Dawson
5216220872 Fix more racy conditions
Switch from QtConcurrent::run to QThreadPool::start

QtConcurrent doesn't give us anyway to cancel queued but not
started tasks. QThreadPool does (and also allows us to specify
task priority)
2016-12-05 14:08:11 +10:00
Nyall Dawson
14b6b3f6ee Harden everything up
And finally fix a racy condition which has been plaguing me for
ages
2016-12-05 14:08:11 +10:00
Nyall Dawson
6d4392a0f7 Allow QgsTask subclasses to defined a finished function, which is
called when the task has completed (successfully or otherwise).

This allows for simpler task design when the signal/slot
based approach is not required. Just implement run() with your
heavy lifting, and finished() to do whatever follow up stuff
should happen after the task is complete. finished is always
called from the main thread, so it's safe to do GUI operations
here.

Python based tasks using the simplified QgsTask.fromFunction
approach can now set a on_finished argument to a function
to call when the task is complete.

eg:

def calculate(task):
    # pretend this is some complex maths and stuff we want
    # to run in the background
    return 5*6

def calculation_finished(result, value=None):
    if result == QgsTask.ResultSuccess:
	iface.messageBar().pushMessage(
            'the magic number is {}'.format(value))
    elif result == QgsTask.ResultFail:
        iface.messageBar().pushMessage(
            'couldn\'t work it out, sorry')

task = QgsTask.fromFunction('my task', calculate,
		on_finished=calculation_finished)
QgsTaskManager.instance().addTask(task)

Multiple values can also be returned, eg:

def calculate(task):
    return (4, 8, 15)

def calculation_finished(result, count=None, max=None, sum=None):
    # here:
    # count = 4
    # max = 8
    # sum = 15

task = QgsTask.fromFunction('my task', calculate,
		on_finished=calculation_finished)
QgsTaskManager.instance().addTask(task)
2016-12-05 14:08:11 +10:00
Nyall Dawson
e01c306edb Simplify reporting completion of tasks
QgsTask subclasses can now return a result (success or fail)
directly from QgsTask::run. If they do so then there's no
need for them to manually call completed() or stopped()
to report their completion.

Alternatively, tasks can also return the ResultPending value
to indicate that the task is still operating and will
manually report its completion by calling completed() or
stopped(). This may be useful for tasks which rely on external
events for completion, eg downloading a file. In this case
Qt slots could be created which are connected to the download
completion or termination and which call completed() or
stopped() to indicate the task has finished operations.
2016-12-05 14:08:11 +10:00
Nyall Dawson
b64025df5c Add python test for task manager 2016-12-05 14:08:11 +10:00
Nyall Dawson
b065edeed7 Improvements to QgsTaskWrapper 2016-12-05 14:08:11 +10:00
Nyall Dawson
5d4689294d Add simple python method QgsTask.fromFunction for creation of tasks
from a function without having to create a QgsTask subclass
2016-12-05 14:08:10 +10:00
Matthias Kuhn
0b3646b252 Expression functions can dynamically report geometry and columns 2016-10-27 23:11:51 +02:00
Juergen E. Fischer
31df84aa6b run 2to3 on source 2016-09-21 23:30:04 +02:00
Nyall Dawson
7da8110536 Remove deprecated methods from QgsExpression
Now all evaluate/prepare/etc methods must be called using QgsExpressionContexts

Also remove most remaining traces of special variables. This brings some
user facing changes, such that existing expressions may need to be
updated if they used these old special variables (eg $scale,
$feature). These changes are noted in doc/qgis3_user_changes.dox
so that we can include them in the release notes.
2016-08-10 17:55:06 +10:00
Nyall Dawson
b7ca001c9c Add __nonzero__ and __bool__ methods to QgsGeometry 2016-08-02 08:39:58 +10:00
Nyall Dawson
1bc17e6c4f Default to requesting all attributes for python expression functions
Fix #14985
2016-06-10 10:03:34 +10:00
Matthias Kuhn
89b7a4aaa2 Introduce NULL QVariant to PyQt5 2016-05-13 22:23:03 +02:00
Denis Rouzaud
8071acd064 move PyQt compat folder to python/qgis 2016-04-29 14:10:26 +02:00
Juergen E. Fischer
271750fd53 switch bindings to pyqt wrappers 2016-03-21 17:00:26 +01:00
Juergen E. Fischer
fb3fcfa3a0 Python3/Qt5/2to3 updates:
* pyqtwrappers update (add QtNetwork, QtXml, QtSql, QtTest, uic)
* 2to3 updates
* move QPyNullVariant/NULL to PyQt.QtCore
* add global unicode/basestring/long for Python3
* expand QtGui, QtCore module and star exports
* Qscintilla2
* replace Set import with set builtin
2016-03-14 20:38:20 +01:00
Juergen E. Fischer
4e1cf3c081 add missing copyright headers 2016-01-08 21:32:11 +01:00