Get Rid of a QAction.trigger.connect in pyside2 - python-3.x

I have the following function to bind my dynamically generated Actions in the ToolBar with a name passing function:
def bind_action(self, action, name):
'''bind an Action to the ToolBar'''
action.triggered.connect(lambda: self._fct.get_name(name))
Now the user may change the name at runtime. And I call the function a second time to bind the new name. If the QAction is triggered now, I have the problem that both triggers are sent. Is it possible to delete the first connect again? I found a workaround (I check if the name is in a list), but I want to have it neater.
As private feedback I got this question recommended: stackoverflow.com/questions/45090982/… It is the exactly opposite problem. There, a user want to know how he can add a second parameter, my Question is: How can I get rid of the first triggered.connect()?

Related

how to read the state when starting the software?(UseState and UseEffect)

** when I start the software for the first time the "items" state property is not set. Not even in setItems.
If I try to reload a second time instead it is valued. How can I change the following code to make the status value also on first opening?**
(https://i.stack.imgur.com/8bgSP.png)](https://i.stack.imgur.com/8bgSP.png)
How can I change the following code to make the status value also on first opening?
enter code hereI am still learning React Hooks, but I think I see the issue. In your useEffect function, you populate items by calling the _getItemButton function, but then you immediately setItems back to an empty array. Remove the setItems([]); statement in the useEffect function and see if that fixes the issue.
By including the empty array, the useEffect function only runs the first time. Clicking the button runs the _getItemButton function again directly, not using the useEffect function, so that is why it works the second time.
Hope this helps!

How to use Tkcalendar virtual events?

Still I’m confused on that tkcalendar virtual events usage to bind user actions on the calendar days selections. Making something like follow,
calendar.bind("<<CalendarSelected>>", print(calendar.get_date())
That print the default date once the I run the script but when I select on the displayed calendar nothing is printed. Normally any selection on any day on the calendar should be printed if was really bound. I did something wrong right ?
You need to use a lambda function instead
calendar.bind("<<CalendarSelected>>", lambda: print(calendar.get_date())
You code will currently bind the result of the print function as the callback for the bind. Since print returns None, no function will be called.
A lambda creates an anonymous function.
If your code gets more complex than a single line, put this code in to a function of its own and use the name of that function in the bind method, for example
calendar.bind("<<CalendarSelected>>", showDateToUser)

Resetting or overwriting the lifespan of a context in DialogFlow

I'm trying to manage the context of my Google Assistant agent (in DialogFlow), using the ApiAi class in the npm package actions-on-google.
The problem is this:
How can I reset the lifespan / delete a context using the npm package?
I can easily set the lifespan of a new context, and it works.
However:
How do I delete a context?
Setting the context to a different number does not seem to work. That is, if I set app.setContext('myContext',10) and then, 2 intents later, when the lifespan in 8, I call app.setContext('myContext',10) again, in the next intent, the lifespan is still 7. If I could answer (1) and delete a context, I'd just delete it and set it again.
I don't think there is a way to delete or overwrite the duration of a context. Instead, if you know that a certain context must not be active at a certain point, set a context that lasts for 1 or 2 turns and do this after each turn. This will also give you more control over the conversation, so you won't have contexts that last for 10 turns that you suddenly don't need anymore.
To delete a lifespan of context you just set it to ZERO or 0 like app.setContext('your_context',0)
Make sure you do this before calling the app.ask or app.tell
or
if not using client you could write a function that simply sets
this.contexts_[your_context] = {}
The first option is definitely working for me. I have not tried the second option. Try and see if you are not setting it in the Dialogflow. Also, you can remove context setting in webhook and put lifespan as 0 in Dialogflow. That will put a line (like deprecated method) over your context.
I know this question is old, at least old enough so that we now have a v2 API and library overhaul, so I'll answer anyway with today's solution :) .
1 - To delete a context, you can use conv.contexts.delete('context1'); as specified on the Node.js library reference docs.
2- If conv.contexts.set('context1', 1); doesn't change the context's lifespan then you can easily delete it and recreate it with these two calls.
My experience is that you cannot overwrite context data.
You can create a new context though:
agent.setContext({
name: contextName,
lifespan: newLifeSpan,
// Note: Parameters are not visible until the context is passed
// console.log() won't show them now.
parameters: {
// Previously saved using getContext()
param_name : paramValue,
}
});

nightwatch - check for popup window, after each click event

Is there a way in nightwatch to check whether a popup window appears after each click event?
I have a problem that randomly an error message appear and I don't want to write for each click event the same callback function.
I have already tried out the after and afterEach commands in the Global.js but then the commands will only run after the whole test suite.
I also have tried it local within a test file, although it also does not cover all single click events, even though the official website writes "... while beforeEach and afterEach are ran before and after each testcase (test step)"?
Solution I'm looking for:
.waitForElementVisible('selector')
.click('selector')
.click('selector')
Solution I have come up with so far:
.waitForElementVisible('selector')
.click('selector', isPresent)
.click('selector', isPresent)
isPresent as a callback function, which does the checking and close the popup window if it appears.
Is there another way to write a function (with or without after and/or forEach), so that it will be called after each click event or after each command. Thus, I don't have to write the isPresent repetitive code?
You can insert something like this in your page object file:
var popupCommand = {
popupCheck:function(){
return this.waitForElementVisible('selector', 5000)
.click('selector', isPresent)
.click('selector', isPresent)
},
module.exports = {
commands:[popupCommand],
elements:{
firstElement: {selector: 'xpath',locateStrategy: 'xpath'},
secondElement: {selector: 'css'},
}
}
Where 'popupCommand' will be the name of your page object file, for example 'Popup'. And also you will have to insert your isPresent callback function here so you can use it.
I did my best to explain you as much as possible what and how to do that :)
you should yse .switchWindow() method.
Why don't you write your own custom command specific for that case, so that way you will avoid repetitive code?

Terminating each() block in Protractor

I was automating the an application (using Protractor) and I have come across situation where I wanted to select the an option from the type ahead using the DOWN arrow button from the Keyboard. Here is how I am approaching to this action.
After typing part into the text field I am getting the reference of each option that appear in the type ahead.
Now, I am using .each() method of protractor to iterate through each of the option to look for the required option.
I'm making the script to hit DOWN arrow button to iterate through each option in the type ahead.
Suppose there are 10 options displayed in the type ahead and the option that I need to select is at 5th position. Now when I reach the 5th position I am selecting the option but each() function still continues.
I want the loop to terminate when required option is selected. Something like BREAK statement in FOR loops.
BTW I have tried the above scenario with FOR loop but unable to use BREAK statement within then() handler.
Please let me know how to cope up with this situation.
You could throw an exception to terminate the loop. Put the loop inside try and use catch to wrangle your results. You can also just use a boolean variable to indicate that you have found a match and ignore everything after that point. I would just use a for loop though.
Edit:
You could add a variable to hold an action before the allBenchmarks.each
var action
Then inside the test
if(dataValue == optionToSelect){
action = function() {benchmark.click(); ...}
}
After the loop exits call the action
if (action) action()

Resources