With Robot Framework I automatizate a connexion to a website.
To do this, I used Dialogs Library to ask for a username and a password with the command "Get Value From User". The thing is, the library let the user enter only one by one value (a first popup where robot ask Username then a second where it ask the password). Dialogs Library do not support to ask several values in the same popup or window. But is there a way to do it ? (I do not find anything, and I almost never learn python to creat my own library (it is in my plan to do it asap)). Thank you for help !
Possible, yes. If you need to ask, not easy.
Dialogs uses tkinter toolkit, when you call a keyword from dialogs keyword library, library will create a temporary gui element and runs the event loop until its either dismissed or value is provided.
You can make similar keyword that creates tkinter dialog with multiple ui elements, process the event loop until user has indicated that all is fine, exit the event loop and return the field values to the caller.
Related
in my application, I override QMainWindow::closeEvent in order to do some logic before closing the app.
The only argument this function gets is of type QCloseEvent, and it's called whenever the user tries to close the app.
It happens when we click the X button, of course, but depending on platform we also have things like alt+f4, rightclick->close and possibly more.
My goal here is to distinguish between these. More specifically, I need to know if just the X button was pressed or not.
From to the docs, which can be found here: https://doc.qt.io/qt-5/qcloseevent-members.html
I can't see anything that would help me get this information.
There is a function spontaneous(), which allows me to check if the event was triggered programmatically or by the environment/user, but in the case I'm presenting, every event has this value as true.
Unfortunately, I don't even know if this is possible.
I expect that it could work in a way that X11 or some other component in the system would just send the same signal for every case, but I don't really know where to look for this information.
Other questions that I've found on stack cover the spontaneous vs non-spontaneous cases, thus the didn't help me.
closeEvent() is called after the window is closed, not necessarily when the application is closed. Therefore, it's not called until after all the logic for the key is processed.
Override keyEvent() and use that function to run your key press logic.
Documentation here
I'm trying to build a GUI wrapper over an external command line application. Everything is fine until this application wants to get an input from user. How to know if the process is asking for an input? For example, so I could show the GUI input dialog for the end user.
Also, the fact is I don't need this input functionality at all, so it would also be fine to simply omit / suppress the input.
How to create/launch integration test in QT? For example, I want to test my application on receiving events and check signals with QSignalSpy, but it looks like there is no option to execute your application and test after that.
Update:
I'm familiar with QTest and using it - I'm actually looking how to launch custom application, not base one with QTEST_MAIN macro
have a look at QTest. It is designed for unit testing but you can use it to launch your application, perform mouse clicks and key presses on objects. It does present a bit of a headache whenever you get a modal window, but there are workarounds on SO.
In my app, I have a project features but it needs a chain of dialogs to work.
At start, the user must either open an existing project or create a new one and when creating a new project, the user must specify a folder.
So there is a first dialog for the choice between new or existing project and another one opens to select a folder in the case of a new project.
Right now, I call the exec_() method on the first one, and do everything inside (creating the second dialog, using it, ect). the direct consequence : it is messy as it uses side effects.
So the question is : It is possible to cleanly chain dialogs in QT ?
Take a look at QWizard clas:
A wizard (also called an assistant on Mac OS X) is a special type of
input dialog that consists of a sequence of pages. A wizard's purpose
is to guide the user through a process step by step. Wizards are
useful for complex or infrequent tasks that users may find difficult
to learn.
Sounds to me like "state machine" is your friend.
http://www.drdobbs.com/cpp/state-machine-design-in-c/184401236
https://en.wikipedia.org/wiki/Automata-based_programming
In your case, you'd start your state machine from an initial state that runs dialog 1.
You run dialog 1, and when it returns from exec(), determine and
update your machine to a new state.
Then run the appropriate dialog for the new state. And so on, until you get to a state that is the end of your dialog chain.
This allows you to have the flexibility in your dialog chain where the next dialog is conditional to what the user selects in the previous dialog, while keeping the logic of the states outside of the dialogs and in a central location.
It's basically a switch statement in a while loop, but a very useful one for managing non-linear / conditional flow in your program.
Hope this helps.
I'm a newcomer to Qt, but I'm trying to implement what basically amounts to a video-game-esque input loop in a Qt application (crazy, I know, but see if you can help). I need accurate, one-to-one event handling for key presses and key releases, for all keys, including modifiers, no matter how weirdly you chord-up the keyboard.
Of course, your main access to key events is through QKeyEvent. But let's say the following happens:
user presses and holds Ctrl
user presses and holds Up
user releases Ctrl and Up simultaneously
As far as I can tell, what I get from Qt is:
QKeyEvent for the pressing of Ctrl, by itself (Qt::Key_Ctrl)
QKeyEvent for the pressing of Up, by itself (Qt::Key_Up)
QKeyEvent for the releasing of Ctrl+Up, with key() == Qt::Key_Up and the Ctrl bit reflected in a modifier change.
This may be not exactly accurate, but it's my best guess as to what's going on from way too much debugging of the issue. In any event, the key release events when modifiers are involved are incredibly unreliable.
The Ctrl+Up sequence there at the end is the problem. Now, I know I'm getting modifier state in e->modifiers(), and I'm getting the key press in e->key(). I could do some complicated hacks, trying to remember the modifier state internally, to detect when the user's released the modifier. But then, the Qt docs inform me, speaking of e->modifiers(), that:
This function cannot always be trusted. The user can confuse it by pressing both Shift keys simultaneously and releasing one of them, for example.
This is exactly the case I'm trying to avoid.
Is there any reliable way to keep track of one-to-one key presses and releases, for both normal and modifier keys, in Qt? If not, what's the closest you can get?
EDIT: I can refine this a little bit. It seems that if you hold down Cmd on a Mac, press a few keys (letter keys, say), release them, then release Cmd, you don't get release events for the letter key releases. I'm going to try to isolate a small example and see if this is actually a Qt bug.
I think if you are getting very specific with the keyboard, you are going to have leave Qt and get something that is OS specific, or you need to handle the Qt events before any filtering happens.
Handle Qt Events Before Filtering
Accelerators in Qt look for and wait on Alt+__ combos and you can set up Ctrl+__ combos to be listened to by QAction.
Both of these types of Objects built into QApplication and the general GUI environment, might be interrupting the messages you are getting, and giving you less than what you are expecting.
Qt Documentation: The Event System ... this part has a link to this...
QCoreApplication::notify() ... which tells the highest level that a Qt Application can be written to handle input using the Qt API:
Installing an event filter on QCoreApplication::instance(). Such an event filter is able to process all events for all widgets, so it's just as powerful as reimplementing notify(); furthermore, it's possible to have more than one application-global event filter. Global event filters even see mouse events for disabled widgets. Note that application event filters are only called for objects that live in the main thread.
OS Specific Keyboard Handling Alternative
If looking at debug statements from a Qt event filter installed at the level mentioned above yields the same results as what you mentioned in your question, then you will need to go to the OS specific keyboard input stuff. For example in Windows you would need to scan the keyboard and or look at the VK state of the whole keyboard and do something with it (with something like GetKeyboardState() ).
I know it's a bit late to answer this question. Still... I have the same problem with Mac key release events and there is an open bug QTBUG-36839.
On Windows you may implement keyboard hook to catch every key presses/releases. But even that is not reliable in some cases. E.g. if you will type lock screen shortcut after unlocking you will NOT see any key release. I guess there must be something similar to hook on Mac. If it is important to you to remember what exactly physical key user pressed - I think this is one of the best ways. At the same time, from my experience, doing something low-level takes a lot of time and may bring a weird bugs in cases you never could imagine. So the question is: are you sure you cannot make what you need with something like QAction?
Or maybe you could just use Control instead of Command in your shortcuts :)