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)
Related
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()?
I have a program that has multiple windows in pyglet, and I want to make one window unclosable, rather to set its visibility to false. Is there a way I can access the event handle for close, to make it instead of closing the window, possibly return a bool or a string like "should close."?
Found the answer to my own question, first define a custom event loop with window_event_loop = pyglet.app.EventLoop(), then create a handler for .event for the event loop
#window_event_loop.event
def on_window_close(window):
# Extra code here
return pyglet.event.EVENT_HANDLED
I am putting up a web server in node.js,
in particular I am developing a module for orders management.
the module is wrapped inside an anonymous function
(function(){})();
if the "insertOrder" function I declare the variable order like this:
var order = {
user_id: '',
address_id: '',
payed: false,
accepted: false,
shipped: false
};
Then it gets populated with the values "returned" from the asynchronous functions i am calling that interact with the database.
This application is going to be used simultaneously by multiple clients.
Now, assuming that two users want to make an order, is the variable going to be re-initialized to the starting object every time the function get's called, overwriting the changes made during the first execution? Or is a context going to be spawned every time a client makes a call to the server?
I know this is not the case for node.js but still can't figure this one
out.
I.E.
is the variable value of the previous iteration gonna be kept somehow and used until the end of the first function call or lost as soon as the function gets called again?
Thank you very much.
EDIT: further explaination of the problem.
The user_id is is going to be used to retrieve the address that the order is going to be shipped to. A wrong user_id is going to result in the item shipped to the wrong address
If var order = { ... } is inside the insertOrder function, then every time the insertOrder function is called order will be reinitialized. The scope is isolated, so there should not be any mingling of local variables even in an asynchronous situation.
jsFiddle
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()
How can I save some text to clipboard by pressing button? clipboard.setText("gg") works by itself
widget.connect(button, QtCore.SIGNAL('clicked()'), clipboard.setText("text") )
throw error, you can only use instance.methodName
widget.connect(button, QtCore.SIGNAL('clicked()'), clipboard, QtCore.SLOT('setText("text")') )
do nothing.
What is wrong?
First, there's a much better way to connect signals to slots on PyQt:
button.clicked.connect(self.method)
You can use lambda functions to pass extra arguments to methods.
Then you call
button1.clicked.connect(lambda : clipboard.setText('btn one'))
button2.clicked.connect(lambda : clipboard.setText('btn two'))
When you pass a function call, in fact the interpreter is evaluating the call and trying to pass the result to the SIGNAL/SLOT connection. That's why your first example doesn't work.
I've written something similar here: https://stackoverflow.com/questions/...from-other-functions