Detect ctrl+click on button in pygtk - gtk

I want to detect if ctrl is held down when the user clicks a button. The 'clicked' signal doesn't seem to pass enough information to the callback to work this out.

If you can connect to either button-press-event or button-release-event instead of clicked, the event passed to the callback can be used to get the modifier state (using get_state) and check if control key is pressed. For ex.
def button_release_callback(widget, event, data=None):
if event.get_state() & gtk.gdk.CONTROL_MASK:
print "Ctrl held"
else:
print "Ctrl not held"
...
button.connect("button-release-event", button_release_callback)
Hope this helps!

Related

(MATLAB App Designer) Key Press Callback for Edit Field

I have an app that asks a user a question, has the user enter an answer in an edit field, and then has the user click a button to check the answer. It's very click intensive since you have to click the edit field, type your answer, click the check button, and then repeat since the cursor is removed from the edit field when the button is clicked.
I'm looking for a way to allow a user to hit the enter key while their cursor is WITHIN an edit field and have my check answer callback function triggered. I know about the KeyPressFcn callback, but it doesn't work if the cursor is within an edit field. Another possible solution would be to have the cursor placed back within the edit field automatically. The perfect solution would have both happen, completely removing clicking!
Does anyone know if it's possible to do this without using Java? Thanks!
In a standard edit field, the callback function for the edit field is executed when the user presses enter. So if you want to call a function when the user presses enter, for example a function to check the user input, just put that function in the callback function for the edit field.
function my_edit_field_Callback(hObject, eventdata, handles)
fprintf(1,'User entered %s\n',get(hObject,'String')); % this is for debugging
inputCheck = my_input_checking_function(get(hObject,'String'));
fprintf(1,'Input check result is: %s\n',inputCheck); % debugging

How can I disable the Close button of a waitbar in MATLAB?

I want to create a waitbar that should be processed without any interruption. How can I achieve this?
I have tried setting
h=waitbar(0,'please wait','CreateCancelBtn','setappdata(gcbf,''Cancel'',0)');
This disables the Close button on the waitbar, but it also shows me a Cancel button too. I don't want that button.
When you use the CreateCancelBtn option of waitbar, it creates a Cancel button, takes the string you supply, and then sets that string to be both the Callback of the Cancel button (i.e. the thing that happens when you press the button) and the CloseRequestFcn of the figure window (i.e. the thing that happens when you click the Close button on the window frame).
You can avoid this by just directly setting the CloseRequestFcn of the figure window yourself:
h = waitbar(0,'Please Wait...');
h.CloseRequestFcn = '';
The Close button is now disabled.
Bear in mind that the CloseRequestFcn is also what gets executed when you call close(h), so you now won't be able to close it with close(h). You can either call delete(h) instead, or you can make sure that before you call close(h) you reset the CloseRequestFcn back to the default, which is the buit-in function closereq (type edit closereq to see what this does, it basically just calls delete anyway).
Hope that helps!

How to use/link "esc" key to web pages?

A window/popup in web page can be provided with close (X) button at top-right corner to close that. How to make one closed with 'escape' key pressed?
Facebook chat boxes will be closed with the "esc" key pressed. How to do that?
Thanks.
It's totally depends on which window dialog/popup are you using. Because different dialog/popup can be handled by differently.
But you can use keyboard key press event(key code :27) to detect when use clicked ESC key.
Here is the example:
Suppose, you're using jquery dialog to show your content then you can handle ESC key event.
$(document).keydown(function(e) {
// ESCAPE key pressed
if (e.keyCode == 27) {
window.close();
}
});
Hope this helps!

Protractor : How to select an item from list when right-clicked

I am trying to Right click on an element and then select an option "Rename" from the list. I have got "right clicking" working but can't select option from the list. Referred links 1, 2
Note 1:
1: On right click the menu options that are visible are native context menus. So, they don't appear in my DOM that I can see.
2: The App runs only in Chrome browser(not sure if it is a browser issue)
I have tried the following code:
browser.actions().mouseMove(elementVar).perform();
browser.actions().click(protractor.Button.RIGHT).click(protractor.Button.ARROW_DOWN).click(protractor.Button.ARROW_DOWN).click(protractor.Button.ARROW_DOWN).perform();
Consider, "Rename" to be the third option in the list.
Note 2:
If I am just running the app and enter 'R' from my keyboard, it selects the "Rename" option. But when I tried to run it in my test, it doesn't select the "Rename" option. See below code I tried:
browser.actions().mouseMove(elementVar).perform();
browser.actions().click(protractor.Button.ARROW_RIGHT).sendKeys('R',protractor.Key.ENTER).perform();
None of the above code works. Let me know if more information is required.
EDIT:
I am guessing the following to be happening:
once I mouse over, the script "right clicks" and after that the "tooltip" is displayed. Since the "tooltip" is displayed after "right click" I think the menu list goes to the background(the list is still visible along with the tool-tip), which is why the arrow down keys aren't working. Is this possible? If yes, how can I wait for the tooltip to be invisible and then right click?
Input: I tried to wait for tool-tip to be invisible and then right click, but still the "Arrow_down" doesn't work.
Is there a way to bring the menu list in the front once we have right clicked?
IMPORTANT:
I took a screenshot after I right clicked on the element, and the screenshot doesn't show the "menu list". Below is the code for screenshot:
browser.actions().click(protractor.Button.RIGHT).perform()
.then(function() {
browser.takeScreenshot().then(function(screenShot) {
writeScreenShot(screenShot, "image.png");
});
});
//writeScreenShot takes two variables actual screenshot data and the file name. And the screenshot is saved as "image.png"
What needs to be done?
When you send ARROW keys to the browser, you have to send them as keys instead of passing them to click() function and the ARROW_DOWN key is part of Key object and not BUTTON. Here's how -
browser.actions().mouseMove(elementVar).perform();
browser.actions().click(protractor.Button.RIGHT).sendKeys(protractor.Key.ARROW_DOWN).sendKeys(protractor.Key.ARROW_DOWN).sendKeys(protractor.Key.ARROW_DOWN).perform();
For your second try, you should send RIGHT in the place of protractor.Button.ARROW_RIGHT to right click. When you send two actions/keys to sendKeys() function, you have to join them using chord object which combines the action of pressing two keys at a time(ex: CTRL+C for copy). But in your case i don't think its really necessary. Here's how to use it -
browser.actions().mouseMove(elementVar).perform();
browser.actions().click(protractor.Button.RIGHT).sendKeys(protractor.Key.chord("r", protractor.Key.ENTER).perform(); //Not necessary as you wont be pressing R+ENTER in your keyboard
OR
browser.actions().click(protractor.Button.RIGHT).sendKeys('R').sendKeys(protractor.Key.ENTER).perform();
Hope this helps.
use XPath to solve your problem
browser.actions().mouseMove(target).perform();
browser.actions().click(protractor.Button.RIGHT).perform();
element(by.xpath('//*[#id="context-menu"]/ul/li[1]')).click();
In your case it will be "//*[#id="context-menu"]/ul/li[3]" most probably.

GtkTreeView expand/collapse on keypress events

Is there an elegant way to expand/collapse the items in a GtkTreeView using the keyboard (say, the Enter key)?The view only seems to be responding to mouse clicks by default.I should perhaps connect the
"key_press_event"
signal to the view and in the handler, check
gtk_tree_view_row_expanded ()
and call
gtk_tree_view_expand_row ()
(with corresponding actions for collapse).
The row-activated signal was the better (right) callback choice instead of the key_press_event. Gave me all the parameters need to use gtk_tree_view_expand_row() and gtk_tree_view_collapse_row(). Works as expected.