How to prevent user interaction before opening complex Qt dialogs - lazy-initialization

I have complex dialog (it has a lot of widgets that take some time to be created) which at the end of its constructor calls QDialog::exec(). And I want to disallow the user to open it several times by double-clicking on some action a few times.
E.g. When a user trigger some action to open the dialog, he has some time to click it again before QDialog::exec() be called and block user interaction, which will lead to creating some "dialog opening events" that will be triggered after the first opened dialog will be closed.
I am sure that there is some proper solution for that kind of problem. Something like block user interaction immediately and lazy dialog widgets loading.

Related

Cannot complete download from popup when prompting location with saveAs

I've been working on a browser extension allowing users to generate epub files from any webpage.
To use the extension, a user has to click on a toolbar button which opens a popup. On the latter, after specifying a config, the user clicks on "Generate". Here is my issue though:
When I use the download API directly, and specify saveAs to false (i.e the user is NOT prompted where to save the file), then the download is completed as expected and the file saved in some location.
However, when I do set saveAs to true --- which is what I want in the final version --- then once the user has selected the location under which to save the file, the download fails. My intuition is that as soon as the file location window pops up, the popup looses focus and dies, which makes the download impossible to resume.
Is that the explanation? And is there a way to prevent such a problem? I do not find my use case to be much of a stretch, and do not get why popups associated with browser actions are not allowed to loose focus for file selection.
Another weird thing is that I'm pretty confident this problem only appeared recently in firefox, since when I started developing the extension, I had no issue.
My intuition is that as soon as the file location window pops up, the
popup looses focus and dies, which makes the download impossible to
resume.
That's right...
Browser Action Popup is page and once page is closed, async operations will lose their reference. It is best to pass async operations to the background script.
You can use
runtime.sendMessage()
to pass a message to the background script to run the download.
You can also use the async
runtime.getBackgroundPage() to run a function in the background script but the first option works
easier as you dont need to wait for the async response as in runtime.getBackgroundPage()

Extract Path From File Dialog

My app uses a 3rd party DLL for image processing, which opens a file dialog to choose an image file. For continuity and usability reasons, I use a separate thread to change the dialog after it appears (change the icon and title, and remove the system menu and context help button). I also introduce my own WNDPROC to capture the button clicks, which I can re-route to my app if I choose.
I want to do some specific processing of certain image types, but I need to know when one of these has been picked. Is there a way to get hold of the full file path and pass it back to my app? (The third party file dialog is not the default Windows dialog, but seems to be based on it).
In my WNDPROC, after catching the IDOK WM_COMMAND message, I used SendMessage and CDM_GETFILEPATH to get what I'm after!
Edit:
Actually, it seems I'm better off catching the WM_DESTROY message - in case the user double-clicks or presses enter instead of the 'OK' button.

Have one application execute an action when another application is given a command using AppleScript?

I know nothing about AppleScript, but I wonder if it could make my life easier: is there a way to write an AppleScript that tells Safari / Firefox / Chrome to refresh the current tab when I save a document in another application, say TextWrangler? Essentially, I want to map the Command+S keyboard shortcut to do two things at once in two separate applications.
If that’s not possible, can you script one application so that saving one file executes a command in another window in that same application?
There are different possible approaches to implement this, but the most straightforward would probably be to create a script that executes all steps you need (i.e. save the document and refresh the window) and bind that to the Cmd+S keyboard combo in the triggering application.
What you need for this approach to work, is, in order:
a method to bind a key combo to a script effective only in a specific application. OS X’ Automator Services fit that bill: their scope can be restricted to a single application (select it in the “only in” drop down at the top of the workflow actions), and they can be assigned a shortcut in the Keyboard preference pane of System Preferences.
a way to relay your commands to the applications they target. AppleScript can help you in two different ways, depending on the fact if your applications are scriptable, i.e. if they have a scripting dictionary you can inspect in the AppleScript editor:
if they do, and their terminology includes the saving action for the editor on one side (most scriptable document based apps do so in the form save <document>), the page refreshing for the browser(s) on the other (Chrome has reload <tab>, Safari gets the same result via a JavaScript detour, i.e. do JavaScript "window.location.reload()" in <document> – I don’t use Firefox), you are set.
if they do not, GUI Scripting might help, i.e. simulating a click on the right UI element (menu or toolbar) via tell application "System Events" to tell process <your process> to click item x of menu y.
That script can then be embedded into the Automator workflow (in an “Run AppleScript” action, to be precise).
As you can see, a lot depends on the exact software you are using. if you are new to AppleScript and the above baffles you, I’d suggest spending a bit of time on the AppleScript pages of Mac OS X Automation (where you’ll also find example scripts which will kick start you into things like GUI Scripting).
One final note: as of this writing, sandboxed applications do not honor key combos assigned to them in the Keyboard Preference pane (they do honor global key combos set there – just not those specifically targeting them). This means you cannot, for instance, currently override TextEdit’s Cmd+S shortcut for saving in Lion. As long as your editor is not sandboxed (easily checked in Activity Monitor), you should have no issue with this.
One solution would be to create a folder action to refresh the current tab when a new file is saved in the folder.
on adding folder items to theFolder after receiving theFiles
tell application "Google Chrome"
activate
tell window 1 to tell active tab
set URL to (get URL)
end tell
end tell
end adding folder items to

Call event in Excel VBA when switching to another app

I'm looking for an event which gets called when the user switches to another app (without closing Excel) and when he switches back to Excel again. I need to know this to stop a timer triggered event which isn't necessary when app isn't active or nothing is changed.
I would use it to implement an autosave-method which shouldn't save the file if its in the background and therefore not been changed.
There's an excellent article on how to find what events are available here
http://www.cpearson.com/excel/Events.aspx
"Open the Object Browser in the VBA Editor (press F2 or choose Object Browser from the View menu. In the Classes list, scroll down and select Worksheet. Right-click anywhere in the primary window and choose Group Members on the pop up menu. Then scroll down in the Members Of "Worksheet" list until you see items with yellow lightening bolts next to them. These are the events for the Worksheet objects. Do the same for the Workbook and Application objects."
I am not sure whether you will be able to find EXCEL events that capture your needs, as jumping to another application is not an EXCEL mechanism, but a general Windows mechanism. In fact you try to capture a kind of "LostFocus" event of the Excel application itself. Excel however gives you only event triggers for events that are "local to the Excel application".
What about calling your external program by pressing an Excel Button which contains code to
set a global status variable to "I JUMPED OFF"
stop the timer
start the external application (Shell or similar), minimize the window or whatever
plus a global Selection_Change trigger that
examines the status variable, and if it was set to "I JUMPED OFF"
set it back to "I AM HERE"
restart the timer
Of course this is a bit weak and the user can trick you out by simply manoevering with the mouse or Alt-TAB, but if you maximize the window on Startup you can motivate the user to use the Buttons.

When are modal dialogs truly necessary?

Modal dialogs are evil, but I keep reading "You should remove modal dialogs when possible"
When isn't it possible to remove modal dialogs? I mean, what are some truly modal tasks that force us to use evil modal dialogs?
The most common given example is the "Do you want to Save?" I think this is the problem of the concept of having the user hit Save instead of remembering that user input is sacred. If you just saved automatically with the ability to "undo" or have revisions, then you don't ever need ask the user if they want to save.
"Are you sure you want to delete?" Undelete
"Are you sure you want to quit?" Why would you ask that? Are you that vain?
Why do we ever need modal dialogs?
EDIT
Webs app don't count in my books, unless they write their own UI windowing system within the browser. Web apps don't have the same tools set as desktop apps.
EDIT 2
My question is slightly different than the one labeled as duplicate. I feel that there is no case that modal dialogs are the best solution. The referred question assumes there is such a case.
Duplicate of: When Is Modal UI acceptable?
Use Cases for Modal Dialogs
blocking the application flow until information required to continue is entered, as for example a password in a login process.
collecting application configuration options in a centralized dialog. In such cases, typically the changes are applied upon closing the dialog, and access to the application is disabled while the edits are being made.
warning that the effects of the current action are not reversible. This is a frequent interaction pattern for modal dialogs, but it is also criticised by usability experts as being ineffective for its intended use (protection against errors in destructive actions) and for which better alternatives exist.
(Source: Wikipedia)
When I use them
In instances where stopping them from doing something stupid is absolutely mandatory. My company has a web app where Users sometimes leave the page before finishing their work. We prompt them with a Modal (the standard onbeforeunload JavaScript function) if they haven't saved their work.
Otherwise, I don't use Modals if I can help it, I hate it when an app steals focus from what I'm doing.
Edit: We don't save their work automatically for them when they leave the page. We do at other times, but not when they leave the page, hence the Modal. I did write could that could go in and save their work when they left the page, but it wouldn't be a 'great' idea to implement it, especially if they accidentally deleted their work and didn't want it to automatically save.
The only thing more sacred than user input is any file I known about. You should never modify any file that an implementation detail unless I have told you to. Thus boxes like "do you want to save?" at exit are a must because I may want to not save.
Imagine an application which needs to open a dialog for some actions. Now imagine that these would be non-modal dialogs: while one dialog is open, you could change the selection or even worse - invoke a different command which itself opens another dialog. Now imagine the these dialogs would be modal: then you would have to close the dialog to proceed - you can't get in the state where the selection changes under a dialog or where two commands are waiting for input.

Resources