How to raise an event from a dialog with a string parameter - nao-robot

I want Pepper to play a video if I told him to do so (in a dialog). Currently I have implemented an behavior that plays videos. This video player is activated by an event named "Video/PlayVideo" and it plays the video provided by this event (the name of the video as a string parameter).
So how can I do it in my dialog? Below I have added an example how I am expecting this event to be called but I am not sure it could be done and how exactly the syntax is:
Edited:
u:(Start video) OK, I will start the video ^raisePlayVideoEvent("my_video.mp4")
This ^raisePlayVideoEvent is supposed to be an event from ALMemory.
Also it could be 'LeftBumperPressed("my_video.mp4")' - event when left bumper pressed raised with the parameter "my_video.mp4".

To raise an event in dialog use $Video/PlayVideo=value (see qiChat documentation).
By storing a value in an ALMemory key you are effectively also raising the event of the same name.

Related

When does each event occur in WinForms

As I am trying to make my own custom "WinForms", I am left confused on when does each mouse event occurs. I have made my own custom classes, but now the events are something I have to rework, as they won't work right.
I have a custom class for controls. Objects from that class can contain other controls, which can contain other controls and so on. There is a main control, which gets input from a picture box. That input is what is where the mouse is and what even has been activated in the picture box.
So far I have figured, that MouseMove, MouseHover and MouseDown events are the simplest to write, as they occur in simple conditions. But the rest require additional data about the mouse's location, state and past. MouseDoubleClick seems to activate after a specific sequence of events (strictly down-up-down-up, down-up-down-move-up and down-up-down-move-leave-enter-move-up, with the movement events not activating). With that in mind, I am even more confused.
In what conditions and sequences does each mouse event occur?
EDIT
Further testing made things even more confusing. For one, now I want to know at what rate is the MouseMove being registered, and testing it shows that between each event there is a different time (or so does my use of a StopWatch say). This is important, because then that raises the question when is Hover being triggered.
Click is down-up, where moving is allowed between the two.
DoubleClick proved to be simple enough - down-up-down-up, where moving is allowed explicitly only between the second down-up.
Hover activates only once after each Enter, when the mouse remains stationary; if you want to trigger Hover again, the mouse has to leave and then re-enter.
So the question now is how the system tracks the mouse's activity - how does it detect the mouse moving, being held down and being released. Hopefully that would help me get the full answer.

C# "Textchanged" event and infinite loop?

I'm currently creating an application that has three textboxes. Typing into one box will result in the other two having "converted" versions of the text displayed. All three boxes can be typed into and serve the same purpose (though provide different outputs for the conversion).
The "TextChanged" event is called whenever the text value of the box is changed, that is fairly self-explanatory. But will this event also trigger if I change the value through code.
Say if I changed the first box, it would create text in the second. Would the second box trigger the event as well? And would this result in an infinite loop?
No, it wouldn't. Text taken from the MSDN page on the event:
The TextChanged event is raised when the content of the text box changes between posts to the server. The event is only raised if the text is changed by the user; the event is not raised if the text is changed programmatically.
MSDN page
Yes, or no.
this behavior differs from Winform and ASP.Net (each corresponding to System.Windows.Forms.TextBox and System.Web.UI.WebControls.TextBox), means that if you are to create ASP.Net application then the answer is no, but if you are working on Winform application then the answer is yes.
Please refer to the following different saying from the MSDN:
System.Windows.Forms.Control.TextChanged Event
Remarks
This event is raised if the Text property is changed by either a
programmatic modification or user interaction.
For more information about handling events, see Handling and Raising
Events.
System.Web.UI.WebControls.TextBox.TextChanged Event
The TextChanged event is raised when the content of the text box
changes between posts to the server. The event is only raised if the
text is changed by the user; the event is not raised if the text is
changed programmatically.

How to use AddHandler to add event handler for a click event on a button in WPF

Hey collective brain,
So I need to add some additional click behavior to an existing button of a control whose click event, i assume, is handled somewhere in its encapsulated code. So I am using AddHandler() on the button, which is a CalendarDayButton, I can't seem to find a handler for click event. For the first argument of the AddHandler, I used ButtonBase.ClickEvent, and for the second I just used new EventHandler(button_click), and the third is "true". And then I get the "Handler type is mismatched." exception. Any input on this would be highly appreciated.
The problem is that, in WPF, ButtonBase.Click is a RoutedEventHandler. You need to add an appropriate delegate (not EventHandler, but one that implements RoutedEventHandler).

Change mediaelement Source Based on Actions

I have a WPF 4 and VB.net 2010 project. I am playing videos in a single mediaelement. This is what I need to do:
When the window first opens, I have the first video play just fine. However, it is after this video plays that I run into trouble figuring out how to do the following.
I need the video source to change immediately following a single play through of any video, and I need this video (henceforth referred to as an "ambient" video) to loop forever.
When a certain event happens, I need to change the video source again, have it play once through, and then go back to looping ambient video in step 1.
Here is the rub, however. Many of the video triggers are inside of If-Then or Select Case statements in code behind, so I'm not exclusively using simple WPF events such as "MouseUp" or "MouseEnter".
Also, all videos must play in the same mediaelement, for performance reasons.
Thank you in advance!
How do I do this?
The Source of the media element is a DependencyProperty, as such any changes to it will be immediately reflected in the UI.
If you combine this with the MediaEnded event that is fired, you can set the Source and your problem is solved.
When you hit the triggers in code, you can either call a method or fire an event. You will have to use some semblance of a State Pattern to deal with the other logic. As an aside, check out Programming Without Ifs, it's an awesome intro on how to avoid insane conditional logic.
I set the mediaelement's LoadedBehavior to "Play" and Unloadedbehavior to "Stop", then I was able to just change the source of the mediaelement itself in code, and put the video I needed played after every video into the MediaEnded event.
It turns out that MediaEnded does not fire automatically when the LoadedBehavior is set to "Manual", unless "Stop" is explicitly called in code.
I hate accepting my own answers, so Nate Noonen gets the bounty (he was going down the right alley originally)! TY!

What would be the expected behavior for a window that hides itself upon keystroke

This is a subjective question, but I need opinions.
I have a WinForms C# application whose window hides itself after a specific keystroke (Enter or Escape), with possible modifiers (e.g. Ctrl-Enter). When hiding on KeyDown or KeyPress, the other application that becomes active after my window hides itself receives the KeyUp event for that keystroke. Normally, it shouldn't affect that other application, but some of them out there react on KeyUp. For example, TweetDeck sends the message currently being edited on "Enter" KeyUp, even if it did not receive KeyDown/KeyPress.
So I thought, fine, I'll be a good citizen, I'll hide on KeyUp. But this doesn't feel right. If I only look for keys up, I'm doing what I blame others of doing! If I try to create an history of matching KeyDown/KeyUp, I'm over-complicating my code (modifiers generate their own key up).
What should I do? What should a well-implemented application do?
This is a hack, but you can set the state of your program to "pending hide" when receive the key down. And then when you get the key up for that sequence, reset the "pending state" and then hide.
Alternatively, can you just "eat" the key up off the message queue after you receive the key down?
I would not worry too much about applications handling key up rather than key down - like you point out - the only reason this is an issue is because your app changes active windows in the middle of a key down key up sequence. It is your responsibility (IMO) to also "eat" the key up messages. You can probably just handle the key up instead of key down with no adverse side effects.
EDIT
Thinking about this further - when doing alt-tab to go to a new window - the action does not happen until the key up. In the meantime it shows a window of possible apps to change to. You can do similar action and the behavior has a precedent.
So:
On key down: Display window that indicates app will hide.
on key up: hide window
This is "stateful" - you can only go into hiding if you received the key down and the key up - at least that is what I would do. 99.9999% (guess) not handling key down would be ok.
I can't think of any program that implements keyboard shortcuts on the KeyUp event. That standard was set a long time ago, with the Windows TranslateAccelerator() API function. It translates WM_KEYDOWN. Windows Forms implements the same behavior with ProcessCmdKey().
Sounds like you found a doozy. Does it handle Alt+F4 correctly?
Well, I'd say "Don't worry about it, until it becomes a problem", but I guess it is a problem now....
In that case, I would hide on KeyPress (the expected user experience), but grab the focus until you get a KeyUp (or until a short timeout).

Resources