BHO: getting a notification when onload finishes executing - atl

I'm writing a BHO that should make a slight modification to a specific page. I'd be using DISPID_DOCUMENTCOMPLETE, but the problem is that the page loads more contents using AJAX on it's onload function.
I think the perfect solution for me would be to run my code after onload has returned. Is there any way to get notified when this happens?
Edit: Actually, its not onload, it's jQuery's ready. I'm afraid there's no clean way to achieve what I want. I guess I'll have to implement a timer and check the page periodically, although I hoped to avoid that.

You could try to use DISPID_HTMLDOCUMENTEVENTS2_ONREADYSTATECHANGE (you must advise for DIID_HTMLDocumentEvents2) and then use get_readyState from IHTMLDocument2.
You are lucky that your page is a specific one, you may see a specific sequence of events you can rely on. The general case indeed involves periodic poll (imho)

Related

Synchronous single file download - is it the right approach in a GUI Qt application?

I'm developing an updater for my application in Qt, primarily to get to know the framework (I realize there are multiple ready-made solutions available, that's not relevant here). It is a basic GUI application using a QMainWindow subclass for its main window and an MyAppUpdater class to perform the actual program logic.
The update information (version, changelog, files to be downloaded) is stored on my server as an XML file. The first thing the updater should do after it sets up the UI is query that server, get the XML file, parse it and display info to the user. Here's where I have a problem though; coming from a procedural/C background, I'd initiate a synchronous download, set a timeout of maybe 3 seconds, then see what happens - if I manage to download the file correctly, I'll parse it and carry on, otherwise display an error.
However, seeing how inconvenient something like that is to implement in Qt, I've come to believe that its network classes are designed in a different way, with a different approach in mind.
I was thinking about initiating an asynchronous download in, say, InitVersionInfoDownload, and then connecting QNetworkReply's finished signal to a slot called VersionInfoDownloadComplete, or something along these lines. I'd also need a timer somewhere to implement timeout checks - if the slot is not invoked after say 3 seconds, the update should be aborted. However, this approach seems overly complicated and in general inadequate to the situation; I cannot proceed without retrieving this file from the server, or indeed do anything while waiting for it to be downloaded, so an asynchronous approach seems inappropriate in general.
Am I mistaken about that, or is there a better way?
TL;DR: It's the wrong approach in any GUI application.
how inconvenient something like that is to implement in Qt
It's not meant to be convenient, since whenever I see a shipping product that behaves that way, I have an urge to have a stern talk with the developers. Blocking the GUI is a usability nightmare. You never want to code that way.
coming from a procedural/C background, I'd initiate a synchronous download, set a timeout of maybe 3 seconds, then see what happens
If you write any sort of machine or interface control code in C, you probably don't want it to be synchronous either. You'd set up a state machine and process everything asynchronously. When coding embedded C applications, state machines make hard things downright trivial. There are several solutions out there, QP/C would be a first class example.
was thinking about initiating an asynchronous download in, say, InitVersionInfoDownload, and then connecting QNetworkReply's finished signal to a slot called VersionInfoDownloadComplete, or something along these lines. I'd also need a timer somewhere to implement timeout checks - if the slot is not invoked after say 3 seconds, the update should be aborted. However, this approach seems overly complicated
It is trivial. You can't discuss such things without showing your code: perhaps you've implemented it in some horribly verbose manner. When done correctly, it's supposed to look lean and sweet. For some inspiration, see this answer.
I cannot proceed without retrieving this file from the server, or indeed do anything while waiting for it to be downloaded
That's patently false. Your user might wish to cancel the update and exit your application, or resize its window, or minimize/maximize it, or check the existing version, or the OS might require a window repaint, or ...
Remember: Your user and the environment are in control. An application unresponsive by design is not only horrible user experience, but also makes your code harder to comprehend and test. Pseudo-synchronous spaghetti gets out of hand real quick. With async design, it's trivial to use signal spy or other products to introspect what the application is doing, where it's stuck, etc.

ARAnimation rendering stop working without any code change

Could there be any reason why sendARAnimationObject should stop working without any change in the code? Does rendering of bitmaps in a timer depend on any external state like battery level or sensor state etc?
Another issue is that if I use sendARAnimationObjectWithCallback the callback method in the listener onResultSendAnimationObject is never called as stated in the documentation. Could there be any other dependency causing this callback method not called at all?
It works much better with the official SDK v1.0
Now I belive I found the main reason behind. I was not calling disableARAnimationRequest anywhere in my app. Now I am calling it in onPause and it works much better next time I start the app and call enableARAnimationRequest. But I would need someone at sony to confirm this kind of behaviour. Maybe the disable method should be called in some SDK method without putting that burden on the developer. Or some kind of cleanup in SDK when you start your app and enable animation request.

Ember.js Observer on computed property, not working. Example from guides

I am learning Ember.js and going through some of the guides. I was reading about observers here:
http://emberjs.com/guides/object-model/observers/
I wanted to play around with the example so I copied and pasted it into my js file. After adding an alert statement to the observer callback, I was surprised to find it was not invoked.
http://jsbin.com/UWEseSo/2/edit?js,output
I was able to find that if you add:
person.get('fullName');
Before the call to set the firstName, the observer callback will be invoked. If I set the first name again immediately after the callback would again not be invoked.
Can anyone explain what is going on here?
Thank you.
EDIT-------
I've traced through the code a little more and I now I have an idea on why this behavior may be like this. Although the example seems like there is a bug it may just be an optimization. I observed earlier that if I called "get" the observer would work. If I did not call "get" the observer would not work. I believe Ember.js may just being smart about this and intentionally not bothering to invoke the observer if no "get" was called. They may be doing this because if there was no "get" there is no reason to invoke the observer because the application can not possibly be showing out of date information.
Once "get" is called an internal flag is set to ensure the observer will be invoked on the next "set".
It looks like you got the explanation right for this behaviour all by yourself, and to confirm your assumptions there is indeed a change that was introduced in rc8 for performance reason mainly.
You can read here the full article on that, under UNCONSUMED COMPUTED PROPERTIES DO NOT TRIGGER OBSERVERS
This means basically that if you need to observe a computed property but aren't currently retrieving it, just get it in your init method.
Hope it helps.

Calling a function after another function is called

I'm programming a controller for use with Ableton Live 8 using the Python-based API. In my code I use a method provided in the API to watch for changes in a property's value, and call a function whenever the value changes. My goal is to change the color of the clip when the value change is noticed.
I have my code completed, and it compiles without error. From Ableton's log:
742234 ms. RemoteScriptError: RuntimeError
742234 ms. RemoteScriptError: :
742234 ms. RemoteScriptError: Changes cannot be triggered by notifications
742234 ms. RemoteScriptError:
It appears this is the result of using the built-in notification system to make a change to the live set during notification. Triggering the actual change AFTER the listening function has finished executing should work. Is this possible using Python?
Edit for clarification:
currently we have
value change noticed, function called
function attempts to change the clips color (results in error)
we need
listener notices value change, function called
function finds the new color value
function execution ends
another function is called outside the listener's scope, and changes the clips color
I did a lot in M4L and know this error by heart :)
I'm afraid you can't do anything about that - to my noob eyes it looks like a built-in security mechanism so you can't loop (Something changed? Change it! Something changed...).
In M4L i used Javascript Tasks to separate the steps (Tasks forget nearly everything),
something like
Observer -> Something changed
Create a Task that reacts
task.execute() or task.schedule(time)
Maybe the python threading module can achieve something similar?
BTW, if you happen to understand anything about the _Framework-Tasks, let me know.
I was having the same issue trying to delete a track from a clip stop listener, then I found this thread and followed #user2323980 suggestion.
There seems to be a "_tasks" object on every Framework class (I found it throught log_message inside ClipSlotComponent and ControlSurface) that handles concurrency between tasks. And it's really simple to use it:
self._tasks.add(Task.run(func, args))
I found some uses of it on Push and MK2 scripts, those are good references.

Block alt+shift event or disable changing language in programming way

I need to block alt+shift keys event using C++, or some way to block changing language.
Thanks in advance.
I would go about it a bit differently. I would catch current langauge settings at startup than change it for desired one.
At the even of alt+shift i would just set it back to the desired type again.
It should be fairy easy to do with net framework.
Here is a short article about manipulating languages: How to change input language programmatically
And main class on msdna: InputLanguage documentation
To actually prevent alt+shift from moving into windows system you would have to play with hooks.
Here is an article about blocking keystrokes before windows process them.
Just an idea. You can catch WM_KEYDOWN message and call ActivateKeyboardLayout to switch language.
Using C++ you can install a keyboard hook procedure like the one suggested here and filter (swallow/don't propagate) the key(s) you want to forbid.
My understanding of MSDN is that you can pretend to process WM_INPUTLANGCHANGEREQUEST and then do nothing, so that Windows will not do anything further and the language will not actually change. But some users say that doesn't work any more.
http://msdn.microsoft.com/en-us/library/ms632630(VS.85).aspx
Maybe you can implement ITfInputProcessorProfileActivationSink::OnActivated, and when you get called you can change back to the previous language by calling ITfInputProcessorProfiles::ActivateLanguageProfile. At the beginning of your app you would call ITfInputProcessorProfiles::GetActiveLanguageProfile.
Maybe you can implement ITfLanguageProfileNotifySink::OnLanguageChange, set *pfAccept
to FALSE and return S_OK.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms628770(v=vs.85).aspx
All of the above have a problem. If the user intentionally changes languages on the client, for example by clicking on the client's task bar instead of pressing Alt+Shift, the above methods will prevent their change anyway.
I wonder if RegisterHotKey would let you register Alt+Shift for your own window even though the system already had it defined.
The thing you are trying to implement is keyboard hook. The detailed explanation with source code in C/C++ can be found here:
http://www.codeproject.com/Articles/67091/Mouse-and-KeyBoard-Hooking-utility-with-VC
Also other helpful examples can be found here:
http://www.codeproject.com/Articles/1264/KeyBoard-Hooks
http://www.codeproject.com/Articles/9513/Disable-keyboard-and-show-images-for-the-children
Hope this helps.
Kind regards,
Bo