Beruflich Dokumente
Kultur Dokumente
+hat is PySide
basically a L-PL alternative to the older PyQt pro,ect PySide recently became part o' the Qt Pro,ect
there is an "no''icial port 'or 3ndroid and o' co"rse it also wor)s on des)top :1
3dvantages
Python is easy to "se :1 no need to .cross41compile code can be easily twea)ed on the go in combination with 5sync ma)es 'or very rapid change-test cycles big standard library and boatloads o' third4party mod"les
6isadvantages
bindings don7t cover all available libraries no Qt 8reator s"pport no Qt 9 s"pport yet
on a P8
install PySide :1 install Qt 8omponents 'rom the &or"m /o)ia PP3 /000% /090 and /0 are s"pported by PySide out of the box ,"st install the python-pyside metapac)age and yo" are ready to go :1 on the /000 yo" might need the qt-components-10 pac)age
on a mobile device
2. add '"nctions yo" want to e!port to this class H. annotate them #. instantiate the class an set it as a conte!t property o' the declarative view
the property name ins e!ported to the global QML namespace% so watch o"t 'or collisions
instantiated QML @lements can be directly manip"lated 'rom Python the easiest way is probably thro"gh the root ob,ect
the root ob,ect is created 'rom the 'ile that was set as the declarative view so"rce at start"p% in o"r e!ample this is the main.qml 'ile
b"t be care'"l M this ties Python very closely to the ."s"ally ever4changing1 QML code
def noti'y.sel'% te!t1: %%% trigger a notification using the Qt Quick 'omponents (nfo)anner %%% root=b,ect = view.root=b,ect.1 root=b,ect.noti'y.te!t1
/oti'ications
noti'ications can be easily implemented "sing the QML InfoBanner element the InfoBanner element is instantiated in the main.qml 'ile there is also a notify(text) '"nction this '"nction can be called both 'rom QML and 'rom Python code /0 handling more notifications at once
Loading images
QML s"pports loading images 'rom 'iles or networ) b"t what i' we want to load an image 'rom raw data in memory or do c"stom image processing P Q6eclarative(mageProvider
provides an inter'ace 'or loading images to QML ret"rns Q(mage or QPi!map does not "pdate the (mage.progress property
Loading images
image provider e!ample
class (mages&romPython.Q6eclarative(mageProvider1: def __init__.sel'1: # this image provider supports Q(mage1 # as specified by the (mage-ype Qdeclarative(mageProvider.__init__.sel'% Qdeclarative(mageProvider.(mage?ype.(mage1 def reC"est(mage.sel'% path(d% siDe% reC"estedSiDe1: # we draw the text provided from Q#$ on the image te!t = path(d # for an example image1 "y2ide logo in 234 is used image = Q(mage.Apyside.svgA1 image.scaled.reC"estedSiDe.width.1%reC"estedSiDe.height.11 painter = Qt-"i.QPainter.image1 painter.setPen.AwhiteA1 painter.draw?e!t.20% 20% te!t1 return image
Loading images
registering the image provider
provider = (mages&romPython.1 view.engine.1.add(mageProvider.A'rom>pythonA% provider1 # NOTE view.engine56.add(mage"rovider5%from7python%1 # (mages8rom"ython566 # doesn9t work for some reason
Loading images
"sing the image provider 'rom QML
(mage . anchors.horiDontal8enter: parent.horiDontal8enter width : 200 height : 200 smooth : true :: NOTE the image provider name in the (mage.source :: ;<$ is automatically lower-cased == so"rce : Aimage://'rom>python/A L entry&ield.te!t G
Persistent con'ig"ration
can be easily achieved on the Python side ,"st e!port a property with properly annotated get/set methods on the Python side% it can be as simple as dictionary that is loaded 'rom 'ile with Marshal on start"p and saved bac) on sh"tdown or other Qbac)endsR li)e con'igparser% con'ig=b,% csv% sClite% etc. can be "sed
Python has a big advantage 4 yo" don7t have to compile the so"rce code the same so"rce can be "sed to r"n an application both on yo"r des)top comp"ter or yo"r mobile device this can be "sed 'or a very rapid on4device testing develo any!"ere <
the only thing yo" need is (P connectivity between yo"r des)top/laptop and yo"r mobile device
basically any wireless 3P will do also wor)s with the b"ilt4in mobile hotspot < :1
reC"irements
rsync on yo"r mobile device scp might be "sed as a less4e''ective alternative SS24P$S a"thentication .so that yo" don7t have to enter the password on every sync1 the (P address o' yo"r comp"ter and yo"r mobile device
installation
place the scripts to a convenient 'older on yo"r mobile device log4in to yo"r mobile device set yo"r P8 (P in the main script .optional1 r"n the the scripts as appropriate
"sage
+hy H scripts P
sync & start the application ,"st sync ,"st start the application
Pac)aging
"nless yo" are developing 'or 2armattan and need 3egis to)ens
programs "sing PySide can be accepted to the /o)ia store .'ormerly >vi 2tore1
with my pac)aging script that "ses modi'ied sdist>maemo and =:S to create /o)ia Store4 compatible pac)ages
PySide applications
-podder
gotoBienna
3-?L
Q"estions P :1
1ant to contact me - #) Martin Kolman email# martin&%olman2'mail&com ,abber# m3rtin%24a++im&c, gith"b# "tt s#$$'it"u+&com$M3rtinK