gtk.fixed layout laid out events? - gtk

I have a gtk.Fixed. I move components inside it around using:
myFixed.move( myEventBox, new_x, new_y )
What event do I listen for to know when myEventBox has been rendered at its new position?
Do I connect to the fixed or the eventbox?
MORE INFO:
I need this information so I know when it is safe to queue a video under the eventbox... if I do it too soon (e.g. right after calling myFixed.move) I can see the glitch. Currently getting around this with a gobject.idle_add.

To be honest, I am not aware of any such event. The object should move immediately and redraw the screen, but I don't think any signal is emitted when that happens.
The PyGTK documentation is very comprehensive, and it will list all of the functions and events of every object in the library. In searching (through both the gtk.Container (for fixed) and gtk.Widget (for fixed and eventbox) signal lists, I can't find any such event. The closest thing is an "add" signal in gtk.Container, but I don't think that's what you're looking for.
If the object is not moving, please post your code, because there is probably a subtle error.
If the object is moving just fine and you just want the event/signal, you may have to simulate it yourself. Write the function you want to be called as soon as the object is moved in a function (def) inside "__ init __", and then call that function in code in the line right after "myFixed.move".

Related

Are there any ways to loop in a button press callback method until the button is released?

So im using gtkmm specifically here.
What I'm working on:
I'm implementing a feature in which when I press in a certain window a parameter is increased/decreased depending on if the mouse moves left/right.
What needs to be done:
To be able to somehow loop in the button press callback method -(doing so as each iteration would store the new value of the cursor position and compare it to the inital position to determine wheter increase value or decrease)- until the button is released.However the event which is sent remains the same so I cant just for example check to see if the events type becomes GTK_BUTTON_RELEASE. I have also tried to use a flag which is set to false in the button release call back, however the release callback isnt even called as the execution is stuck in the now infinite loop.
Thoughts
Im thinking maybe the solution could be a certain something to do with signals.
Update:
Gtk has two functions for doing what I was saying here exactly which are , gtk_events_pending(), and gtk_main_iteration(). Hever turns out having a limitless loop inside an event is considered a bad practise and its better to use other methods like here for example using GdkEventMotion, or other types.

Unity New Input System and Animations

I am creating a basic 2D fighter game and am trying to replace what was the old input system with the new input system. Because of this the old systems update would wait for buttons and then call appropriate functions when they were pressed. Movement was actually the easiest part, simply rigging a 1D Vector and then grabbing the float to use with movement, awesome. However the difficulty is in pressing keys to change things in the game. For example, I have an input 's' which should lead to the method Crouch(). This method changes the animation running and alters the hitbox to be shorter and tell the attack to use a smaller hitbox as well. A Stand() method is called on release of 's' to return everything to the way it is. I have my Player Input object set to 'Invoke Unity Events' which leads to the corresponding method needed. The problem is that even though these events are set to be push and release they are read as a toggle effect instead of press and release triggers(respectively). This does the same thing with my attack function because it forces the animation to play twice, one for pressing and one for releasing. Is there a fix for this or is this currently a bug? Edit: Here are some images to clarify and the code used to reflect everything happening associated with the Attack functionality. Let me know if anything else should be needed
public void Attack(){
anim.SetTrigger("attack");
StartCoroutine(wait());
}
IEnumerator wait(){
if(!isCrouched){
yield return new WaitForSeconds(1.3f);
SHitBox.enabled = true;
yield return new WaitForSeconds(.5f);
SHitBox.enabled = false;
}
if(isCrouched){
yield return new WaitForSeconds(1.3f);
CHitBox.enabled = true;
yield return new WaitForSeconds(.5f);
CHitBox.enabled = false;
}
}
Binding
Action
Think I figured it out. At least for the purposes of this specific thread. The answer was it was not my code. There is what I am going to call a bug in the new Unity Input System. Specifically there were three lines of code all simultaneously being hooked which caused three calls on my method. The fix was commenting out two lines of code. Here's the thread where this is solved, coincidentally found on GitHub help pages, heres the link:
https://github.com/Unity-Technologies/InputSystem/issues/959
the issue is listed as close but its still a problem for me, lol...
The only issue left is that the behavior of selecting the type of button press that I want to use is still acting funky. Mainly the inputs are still simply firing without listening to the type of input I want. I am basically just going to start searching through unity code to find where these choices have impact. If there are no comments/answers in 8 hours I'll accept my own answer because this has technically been answered, it just leads to another question.

Understanding Chrome Dev Tools timeline

I'm trying to understand why I have several Long Frames reported by Chrome Dev Tools.
The first row (top of the call stack) in the flame chart are mostly Timer Fired events, triggered by jQuery.Deferred()s executing a bunch of $(function(){ }); ready funcs.
If I dig into the jQuery source and replace their use of setTimeout with requestAnimationFrame the flame chart doesn't change much, I still get many of the rAFs firing within a single frame (as reported by dev tools) making long frames. I'd have expected doing the below pseudocode:
window.requestAnimationFrame(function() {
// do stuff
});
window.requestAnimationFrame(function() {
// do more stuff
});
to be executed on two difference animation frames. Is this not the case?
All of the JS that is executing is necessary, but what should I do to execute it as "micro tasks" (as hinted at, but not explained here https://developers.google.com/web/fundamentals/performance/rendering/optimize-javascript-execution) when setTimeout and rAF don't seem to achieve this.
Update
Here's a zoomed in shot of one of the long frames that doesn't seem to have any reflows (forced or otherwise) in it. Why are all the rAF callbacks here being executed in one frame?
Long frames are usually caused by forced synchronous layouts, which is when you (unintentionally) force a layout operation to happen early.
When you write to the DOM, the layout needs to be reflowed because it has been invalidated by the write operation. This usually happens at the next frame. However, if you try to read from the DOM, the layout happens early, in the current frame, in order to make sure that the correct value gets returned. When forced layout occurs, it causes long frames, leading to jank.
To prevent this from happening, you should only perform the write operations inside your requestAnimationFrame function. The read operations should be done outside of this, so as to avoid the browser doing an early layout.
Diagnose Forced Synchronous Layouts is a nicely explained article, and has a simple example demo for detecting forced reflow in DevTools, and how to resolve it.
It might also be worth checking out FastDom, which is a library for batching your read and write. It is basically a queuing system, and is more scalable.
Additional Source:
What forces layout / reflow, by Paul Irish, contains a comprehensive list of properties and methods that will force layout/reflow.
Update: As for the assumption that multiple requestAnimationFrame calls will execute callbacks on separate frames, this is not the case. When you have consecutive calls, the browser adds the callbacks to a document list of animation callbacks. When the browser goes to run the next frame, it traverses the document list and executes each of the callbacks, in the order they were added.
See Animation Frames from the HTML spec for more of the implementation details.
This means that you should avoid using the consecutive calls, especially where the callback function execution times combined exceed your frame budget. I think this would explain the long frames that aren't caused by reflow.

gwt HorizontalSplitPanel: catch split position event

I use a HorizonSplitPanel in gwt and wonder if there is no possibility to get an event, if the split position is changed. I need the event to later manually change the positions of some absolute positioned elements.
Is there a possibility to get an event for the change of the split position? Or does somebody know a work-around?
Best,
Michael
You may sink mouseup/mousedown event on the splitPanel, and check split position at each mouse release. If it has changed since last time, then fire a custom event.
You also may override newer SplitLayoutPanel with your own Splitter implementation which sends a custom event on resize, since event handing is implemented in abstract Splitter class.

Interacting with events and listeners in MATLAB

I want to write GUI code that is orthogonal. Lets say I have a circle class and a square class and they need to interact. Right now, to get the circle and square talking to each other - say the circle object sends a message to the square object, I would use something like square_obj.listen_for_circle(circle_obj) where listen_for_circle is a method that implements an addlistener.
This is a problem for me since now the two objects are linked - and removing one object from my code would break it. What I am looking to do is for the circle_obj to be able to broadcast a global message say 'CIRCLE_EVENT'. Additionally square_obj would be listening for global message broadcasts of type 'CIRCLE_EVENT', and upon hearing the event - does some action.(Ahhh, now the objects have no links to each other in the code base!)
Is this possible or even reasonable in MATLAB? (or maybe i'm just going crazy).
As always, advice much appreciated.
I'm not really sure why addlistener is problematic for you. It basically just adds an event listener that doesn't do anything if the event-origin object (the circle) is deleted.
Alternately you can use event.listener or handle.listener. They are undocumented but work well, and are widely used within the Matlab codebase (m-files). See explanation here: http://UndocumentedMatlab.com/blog/continuous-slider-callback/#Event_Listener