Is it possible to access engine root context in dynamically created QQuickPaintedItem, without a global reference ?
class LiveStream(QQuickPaintedItem):
def __init__(self):
QQuickPaintedItem.__init__(self)
self.backend = root_ctx.contextProperty("backend") # <- I want to remove/change this global reference
# self.getRootContext() <- Is there such a function, I cant find such a function on documentaion
...
if __name__ == "__main__":
app = QApplication()
engine = QQmlApplicationEngine()
url = QUrl.fromLocalFile(MAIN_QML)
root_ctx = engine.rootContext()
main = MainWindow(root_ctx, engine)
root_ctx.setContextProperty("backend", main)
qmlRegisterType(LiveStream, "video", 1, 0, "LiveStream")
engine.load(url)
On QML side i do this
function add_stream(camera, pane, pane_id) {
Qt.createQmlObject(`
import video 1.0
LiveStream {
width: ${pane.width}
height: ${pane.height}
stream_id: '${camera.id}'
stream_name: '${camera.name}'
anchors.fill: parent
}`, pane);
}
I am very new to pyside or qt/qml so any help would be very nice.
Thanks
Add a Qt property to Livestream and reference this on qml side.
Related
I created a button that looks up the coordinates of the device. There is no errors in the code but for some reason which is eluding me, the event is not being triggered.
Here is my code:
protected function lblCheckIn_clickHandler(event:MouseEvent):void
{
if (Geolocation.isSupported)
{
lblLat.text = "Finding Location...";
geo.addEventListener(GeolocationEvent.UPDATE, onUpdate);
}
else
{
lblLat.text = "Geolocation is not supported on this device.";
}
}
Later on I have the event code:
protected function onUpdate(event:GeolocationEvent):void
{
if (event.horizontalAccuracy <= 10)
{
Lat = event.latitude.toString();
Long = event.longitude.toString();
lblLat.text = Lat;
lblLong.text = Long;
geo.removeEventListener(GeolocationEvent.UPDATE, onUpdate);
navigator.pushView(PersonSelect);
}
else
{
lblLat.text = "Updating";
}
}
Oh, and I also did the usual imports
import flash.filesystem.File;
import flash.sensors.Geolocation;
import flash.events.GeolocationEvent
import spark.events.ViewNavigatorEvent
import flash.utils.ByteArray;
Any clues as to why my event isnt calling?
Have you instantiated an instance of geo?
if (Geolocation.isSupported)
{
lblLat.text = "Finding Location...";
geo = new Geolocation();
geo.addEventListener(GeolocationEvent.UPDATE, Update);
}
I worked out the ultimate cause of this specific problem. It stems from Flash Builder not installing the complete Android SDK or the IOS SDK. Once I manually installed these by copying the SDK folders to their correct paths in Adobe Flash Builder, my GPS events were called successfully.
To sum up, if you get this trouble where the code and everything looks alright but it wont call up your events, then check to make sure that your latest SDKs for Flex are installed correctly for Android and or iOS
I'm new to Flex and am trying to port a pure Flash/AS3 card game to Flex 4.5.
It works mostly well, but I'm missing few puzzle parts there:
I've created a custom component based on UIComponent representing a deck of cards (which are an array of Sprites or MovieClips):
In the original pure Flash/AS3 game I was using Tween for the 3 cards at the table - to show the game user, who has put which card (by sliding them towards playing table middle):
import fl.transitions.*;
import fl.transitions.easing.*;
public class Deck extends UIComponent {
private var _card:Array = new Array(3);
private var _tween:Array = new Array(3);
....
override protected function createChildren():void {
_tween[YOU] = new Tween(_card[0], 'y', Regular.easeOut, _card[0].y + 40, _card[0].y, .5, true);
_tween[LEFT] = new Tween(_card[1], 'x', Regular.easeOut, _card[1].x - 40, _card[1].x, .5, true);
_tween[RIGHT] = new Tween(_card[2], 'x', Regular.easeOut, _card[2].x + 40, _card[2].x, .5, true);
....
However Flash Builder 4.5 doesn't seem to know fl.transitions.* packages at all?
Does anybody please have an advice on how to use Tween here?
Like I've written the rest (my custom Flex component, moving card-Sprites around, etc.) works well. Only the Tween lines had to be commented.
Thank you!
Alex
Take a look at the Tweener class on Google Code. With it you can specify and object, and a map of its properties and their desired values, along with time, and it will 'tween' those properties from their current to their desired values.
Tweener.addTween(yourCard, {y:50, time:1});//for a 1 second tween
My first knee-jerk reaction has been to add flash.swc (delivered by Flash CS Pro) to the Flex build path and then:
import fl.transitions.*;
import fl.transitions.easing.*;
can be used again.
But in the long-term I will probably write my own function to move the playing cards and run it on Event.ENTER_FRAME. Because I don't want to include Tweener or Tweenlite libraries for mere card sliding.
_tween[0] = _card[0].y;
_tween[1] = _card[1].x;
_tween[2] = _card[2].x;
....
_card[0].y = _tween[0] + 20;
addEventListener(Event.ENTER_FRAME, slideCardYou);
_card[1].x = _tween[1] - 20;
addEventListener(Event.ENTER_FRAME, slideCardLeft);
_card[2].x = _tween[2] + 20;
addEventListener(Event.ENTER_FRAME, slideCardRight);
....
private function slideCardYou(event:Event):void {
if (_card[0].y-- < _tween[0])
removeEventListener(Event.ENTER_FRAME, slideCardYou);
}
private function slideCardLeft(event:Event):void {
if (_card[1].x++ > _tween[1])
removeEventListener(Event.ENTER_FRAME, slideCardLeft);
}
private function slideCardRight(event:Event):void {
if (_card[2].x-- < _tween[2])
removeEventListener(Event.ENTER_FRAME, slideCardRight);
}
Also I've looked at mx.effects.Tween and spark.effects.Animate but they seem to be more appropriate for UIComponents and not Sprites as in my case.
Hy!
I need to upload a group of images using flex with robotlegs.
I need a progress bar to work when image is uploading.
It might upload 1 image or more at the time.
I want to know if uploading byteArray to server and then save the image is too heavy for the server.
In the server side I have a method that is made by pyamf, and looks like this:
.
def upload_image(input):
# here does stuff. I need to be able to get parametters like this
input.list_key
# and here I need some help on how to save the file
Thanks ;)
I had to tackle a similar problem (uploading single photo from Flex to Django) while working on captionmash.com, maybe it can help you. I was using PyAMF for normal messaging but FileReference class had a built in upload method, so I chose the easy way.
Basically system allows you to upload a single file from Flex to Google App Engine, then it uses App Engine's Image API to create thumbnail and also convert image to JPEG, then upload it to S3 bucket. boto library is used for Amazon S3 connection, you can view the whole code of the project here on github.
This code is for single file upload only, but you should be able to do multi-file uploads by creating an array of FileReference objects and calling upload method on all of them.
The code I'm posting here is a bit cleaned up, if you still have problems you should check the repo out.
Client Side (Flex):
private function upload(fileReference:FileReference,
album_id:int,
user_id:int):void{
try {
//500 kb image size
if(fileReference.size > ApplicationConstants.IMAGE_SIZE_LIMIT){
trace("File too big"+fileReference.size);
return;
}
fileReference.addEventListener(Event.COMPLETE,onComplete);
var data:URLVariables = new URLVariables();
var request:URLRequest = new URLRequest(ApplicationConstants.DJANGO_UPLOAD_URL);
request.method = URLRequestMethod.POST;
request.data = data;
fileReference.upload(request,"file");
//Popup indefinite progress bar
} catch (err:Error) {
trace("ERROR: zero-byte file");
}
}
//When upload complete
private function onComplete(evt:Event):void{
fileReference.removeEventListener(Event.COMPLETE,onComplete);
//Do other stuff (remove progress bar etc)
}
Server side (Django on App Engine):
Urls:
urlpatterns = patterns('',
...
(r'^upload/$', receive_file),
...
Views:
def receive_file(request):
uploadService = UploadService()
file = request.FILES['file']
uploadService.receive_single_file(file)
return HttpResponse()
UploadService class
import uuid
from google.appengine.api import images
from boto.s3.connection import S3Connection
from boto.s3.key import Key
import mimetypes
import settings
def receive_single_file(self,file):
uuid_name = str(uuid.uuid4())
content = file.read()
image_jpeg = self.create_jpeg(content)
self.store_in_s3(uuid_name, image_jpeg)
thumbnail = self.create_thumbnail(content)
self.store_in_s3('tn_'+uuid_name, thumbnail)
#Convert image to JPEG (also reduce size)
def create_jpeg(self,content):
img = images.Image(content)
img_jpeg = images.resize(content,img.width,img.height,images.JPEG)
return img_jpeg
#Create thumbnail image using file
def create_thumbnail(self,content):
image = images.resize(content,THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT,images.JPEG)
return image
def store_in_s3(self,filename,content):
conn = S3Connection(settings.ACCESS_KEY, settings.PASS_KEY)
b = conn.get_bucket(BUCKET_NAME)
mime = mimetypes.guess_type(filename)[0]
k = Key(b)
k.key = filename
k.set_metadata("Content-Type", mime)
k.set_contents_from_string(content)
k.set_acl("public-read")
I'm having a problem with labels disappearing on Flex's datavisualization.swc charts that are built on our build server via ANT and the Flex 3.3 SDK. I've made sure that our license is applied properly on the build server (hence no water marks), and I've made sure the exact same datavisualization.swc was copied from my dev machine into the Flex3.3SDK/frameworks/libs directory.
Any ideas? Could it be a font problem? (Though we're really only using default fonts.)
Here's the problem, missing axis labels on the build server
alt text http://img687.imageshack.us/img687/5038/chartwithmissingaxislab.png
Here's how it's supposed to look with labels (taken on my local development machine)
alt text http://img683.imageshack.us/img683/1504/chartwithaxislabels.png
I got it working using the helpful information I found at the Flex Coders archive.
Basically, in an initalize event handler, I added the following code:
var ccClassFactory:ContextualClassFactory = new ContextualClassFactory(ChartAxisTextLabel);
ccClassFactory.moduleFactory=this.moduleFactory;
var hAxisRenderer:AxisRenderer = new AxisRenderer();
hAxisRenderer.axis = hAxis;
hAxisRenderer.labelRenderer=ccClassFactory;
var vAxisRenderer:AxisRenderer = new AxisRenderer();
vAxisRenderer.axis = vertAxis;
vAxisRenderer.labelRenderer=ccClassFactory;
lineChart.horizontalAxis=hAxis;
lineChart.verticalAxis=vertAxis;
lineChart.horizontalAxisRenderers = [ hAxisRenderer ];
lineChart.verticalAxisRenderers = [ vAxisRenderer ];
Also, I had to create the class:
public class ChartAxisTextLabel extends Label
{
public function ChartAxisTextLabel()
{
super();
}
override public function set data(value:Object):void
{
super.data = value;
text = value.text;
}
}
I've got a Scala program that downloads and parses html. I got the links to the image files form the html, Now I need to transfer those images to my hard drive. I'm wondering what the best Scala method I should use.
my connection code:
import java.net._
import java.io._
import _root_.java.io.Reader
import org.xml.sax.InputSource
import scala.xml._
def parse(sUrl:String) = {
var url = new URL(sUrl)
var connect = url.openConnection
var sorce:InputSource = new InputSource
var neo = new TagSoupFactoryAdapter //load sUrl
var input = connect.getInputStream
sorce.setByteStream(input)
xml = neo.loadXML(sorce)
input.close
}
My blog
Then you may want to take a look at java2s. Although the solution is in plain Java but you can still modify to Scala syntax to "just use it"
An alternative option is to use the system commands which is much cleaner
import sys.process._
import java.net.URL
import java.io.File
object Downloader {
def start(location: String) : Unit = {
val url = new URL(location)
var path = url match {
case UrlyBurd(protocol, host, port, path) => (if (path == "") "/" else path)
}
path = path.substring(path.lastIndexOf("/") + 1)
url #> new File(path) !!
}
}
object UrlyBurd {
def unapply(in: java.net.URL) = Some((
in.getProtocol,
in.getHost,
in.getPort,
in.getPath
))
}
One way to achieve that is: collect the URLs of the images and ask for them to the server (open a new connection with the image url and store the bytestream in the hard drive)