How to run a process in the background in Flex? - apache-flex

I have a normal flex app that allows you to enter a code. When you enter this code, it pops the code into a queue. I the have a process in the background that hits this queue and takes each code, sends it to a webservice and then responds with a result. Based on the result, the screen is then also updated. The problem is, I want the user to be able to keep entering codes without having the annoying clock show up stopping him from doing anything until the process is done.
So...
Is there a way to run a background process on Flex?
How do you do it, what's it called?

Close the native window but let the Application run in the background
NativeApplication.nativeApplication.autoExit = false;
NativeWindow(this.stage.nativeWindow).close();

Related

How to show exteranal window in qml-based application

I have an application that gui is made up with QML. The task is to start an external program (LibreOffice) "inside" my application. It means that when you press the button on the app's face, external program must be shown in the same window as the main program is. And also it can be closed by app's button that is drown under the external window.
The only thing that I could do for the moment is to start lowriter with QProcess using this article. But it is still shown in separate window and I don't know how to make a button that will close lowriter.
If somebody have any thoughts about how to do this, it would be great if you share it.. Thanks!

Eventloop is not updating the GUI widget opacity value

I have a button widget I'd like to fade out (self.button1)
def button_slot(self):
fade_effect = QtGui.QGraphicsOpacityEffect()
self.button1.setGraphicsEffect(fade_effect)
hideAnimation = QtCore.QPropertyAnimation(fade_effect, "opacity")
hideAnimation.setDuration(5000)
hideAnimation.setStartValue(1.0)
hideAnimation.setEndValue(0.0)
hideAnimation.start(QtCore.QPropertyAnimation.DeleteWhenStopped)
self.hideAnimation = hideAnimation
The code is in PyQt, but is the same as the original Qt.
For a reason, the when I try the code separately in a test file, it works well.
However, when trying to integrate it in my code, it seems like the fading out animation is running in the background, but not updated in the GUI itself:
The button is stuck at the "clicked" state.
If I minimize and enlarge the window, The button's opacity is right where it's supposed to be (for example, if the duration is 5000ms from 1.0 to 0.0, enlarging the window after 2500ms will show 0.5 opacity).
The button is clickable even though it looks "stuck".
Why could this be happening? How can I force the GUI to update itself at every event iteration?
The only possible explanation I have is that you're blocking the event loop somewhere else in your code. The animation will definitely run, as your test case shows, but it's invoked from the event loop. If your code blocks -- if there's any place in your code where you wait for things, sleep, etc., then that's your problem.
GUI code in Qt and many other frameworks must be written in run-to-completion fashion. Every slot and event handler must execute as quickly as it can, and then return. When you add a breakpoint in a slot, and look at the stack trace when the code stops, you'll see that QEventLoop::exec() is somewhere there. Ultimately, all GUI code is called from the event loop.
Try reducing your code piecewise until the problem vanishes. That's how you'll know where the blocking part is. Qt provides, unfortunately, many methods named waitxxx(), and they tend to be used without understanding that they block the event loop. A blocked event loop means that the application does not respond to user interaction, and eventually the OS will detect it and issue a spinning beachball (OS X), a spinning circle (Vista/Win7) or perhaps a message about a stuck application. A spinning beachball/circle means that the application's main event loop is blocked.

QMessageBox blocks QDialog

I don't really know how to formulate my question this time...
I have my application with a QDialog as a main window.
The application is getting different values like temperature, humidity and so on from a remote machine.
For development I added a group box with different widgets to simulate these values. I have different limits for throwing warnings and alarms to the user.
For example if temperature rises over 30°C then I open a QMessageBox with the request time (the application does polling at the remote machine) and the current temperature. So this is updated each request cycle.
I use the show() method to bring up the message box which keeps my application running in background. The problem now is: the focus is at the message box and nothing in my main window/ QDialog can be clicked until the message box is not accepted/ has finished.
And that's my problem: in simulation mode I want to play around with different temperature values which I can adjust by slider in the main window. How can I access these widgets/ make the message box somehow "not-blocking"?
Best regards,
Matthias
What you're experiencing is called "modality" of a window. By default, a QMessageBox is "application modal". This means that input to all other application windows is blocked.
To change the modality, use setWindowModality() with a value from Qt::WindowModality just before you call show(). In your case:
box->setWindowModality(Qt::NonModal);
box->show();
Indeed you have a modal message box which is the way QMessageBox is intended to work - ie the user is to be alerted and the ui is protected from further interaction until the user has registered the message, closed the message box and (if necessary) taken any action required in response to the message.
Now if you set the message box modality to Qt::NonModal, (remember to assign it to a variable that won't go out of scope when your application continues after popping up the messagebox) you'll be able to interact with the ui even while the message box is displayed., which I have to say is 'unusual'. If I understand your requirement you will already have the message box up - then while this is still up, you'll then want to play around with different temp values in the main window - to what effect? Until another message dialog box is produced? The message box is going to have to be discarded at some point.
Not only that, but if you show a non modal message box and then interact with the main window, you're quite likely to just have the message box disappear behind the main window, out of sight anyway.
I'd suggest that message boxes are generally treated as intended - transient, temporary modal alert boxes only and that perhaps you require a clearly visible live report/status area in your main window rather than utilizing a non-modal QMessageBox.
Hope this helps
Regards
Roger

WebAii - problem facing while entering text in input box in web page

Steps performed
1. Open a web page where data needs to be entered programmatically
2. Retrieved Element instance by passing element Id.
3. Call SetText function in Actions instance in ArtOfTest.WebAii.TestTemplates.BaseTest class by passing element and textToSet
Expected solution
Text need to be entered in the text box always.
Actual Output
Text is not always entered in the text box. Some times entering correctly and sometimes skipping it without entering the value. When debugging, observed that, the element instance is retrieved properly and SetText function is called and no exceptions are thrown. When the value is not entered, setting the control again at the top of the function and running it again will set the value in the text box.
Can any one tell me the reason for this weird behaviour?
Please let me know if more details are required.
Your description sounds like a timing problem. Since test scripts usually run very quickly it is easy for them to outrun your web application. If your test runs while debugging it (i.e. running slowly or single stepping) but intermittently fails when run at full speed, you are almost certainly running into a timing problem. Your web application may not be ready to accept text input at the time your test script is trying to feed the data into it, which is a very common problem if your web application is doing an AJAX postback. The easiest method to overcome such a problem is to add a fixed delay just before the SetText call. A more advanced technique is to monitor some property or element contained within your web application to detect when it's ready for input and wait for that to be set. Once that property is correctly set then call the SetText function.
Cody
Telerik Technical Support Team

How to create a "Please Wait" spinner while data is being imported

I am creating an Flex AIR app which imports data from a zip file into a sqlite db. I need to show a progress bar / "Please Wait" spinner animation so that the user waits till the operation completes.
I have tried to put a pop-up spinner animation but the problem is that the spinner stops spinning as soon as the database import queries start executing.
I need to run both the spinner code and the import code simultaneously rather than sequentially.
Thanks
The problem you are facing here is because Flex is a single threaded application. When you run large amounts of as processing, the thread does not update the UI, so your spinner stops spinning.
I think you can work around this by creating a Green Thread to handle your processing code if it can be sliced down. You can check here for an as3 implementation of the Green Thread.
I can provide some more info on implementing it if you need.
Your issue could be caused by the fact that Flash is single-threaded. Try replacing the import with at timer, to remove the cpu-intesive operation.
It that proves not to be the issue, a bit of code could speed up debugging :)
So - if you want just a spinner, you do not need any more data. If you want a progress bar, though, you will just have to know how much data is there (most likely the size of the zip will be precise enough). Then - have some Event.ENTER_FRAME listener in which you will take a part of the data, insert into table... And stop there. It will then show the animation of stuff. Try to see what amount of data is optimal... Most likely by adding a FPS meter there too, and if it goes too low, make the amount lower.
If you want the progress bar, just increment a variable with how many bytes were already parsed, and divide that by the total bytes - a ratio for progress bar. Rest same as spinner.

Resources