Submitting batch UI update actions - swing

I'm writing a minesweeper clone using Seesaw. For the minefield, I'm using a simple grid-panel of buttons. I've gotten to the point where when you click on a button, it will flood fill the grid to uncover all the empty tiles surrounding where you clicked. To "uncover the tile", I'm just disabling the button associated with the tile.
The problem is, it's uncovering incrementally, even though the task being executed isn't that expensive. It will update a few spotty buttons around the grid randomly over time, and it looks really bad. I would rather have a second of lag than for it to disable the buttons procedurally.
This is basically the button click handler:
(doseq [b buttons] ; Buttons are the grid cells
(let [[tx ty] (sc/user-data b) ; The cell position is stored in the user data
tile (b/get-tile-at board tx ty)] ; O(1) lookup
(when (:uncovered? tile)
(sc/invoke-later ; Because this chunk is actually being executed in a pool
(sc/config! b :enabled? false)))))
Since there's nothing expensive going on here, it seems like each config! call makes a change to a button, and the button's appearances are updated as the changes happen.
Is there a way to have every call to config!/button update happen all at once, even if it creates a small amount of perceived lag?

I'm not familiar with seesaw or its internals, but you want to find a way to use double buffering in Swing.
See also:
https://docs.oracle.com/javase/tutorial/extra/fullscreen/doublebuf.html

Related

How can I subscribe only once to the app-db in re-frame?

I need to subscribe to the app-db for a value that I want to check only once when the parent component is rendered. For example, when I click a button "Click me", and there's a certain on-click event being processed, whose status I have saved on the app-db with the list of processes that are being done, I just want to check against that value once, and display two different components based on that value.
If the value is empty, I want to proceed with the normal event. If not, I'd like to show something else to the user, a popup for example.
Now the thing is that, because it's actively listening to the app-db, and the value is changing almost every second (or in a matter of milliseconds), the said popup appears, disappears, reappears, and disappears again super fast with each change to the app-db, which isn't helpful at all.
I would like to just subscribe once, get the value, and do the checks based on the value when the parent was first rendered. And then I'll do something to make that go away.
If I click the "Click me" button once again, that's only when I'd like for it to re-render.
I haven't quite been able to achieve this. I tried numerous methods such as introducing a delay during the dispatch of popup as well as after introducing processing states to the app-db in the first place hoping that since the data will already be in a steady state, it might not change as much, but now that I realize it's actively listening to it, it's expected that the values would change.
I did try using the subscription without the deref, but that only introduced an error to my frontend, so I'm not sure which way to go now.
My error with the component diappearing/reappearing turned out to be triggered by something else. A conflict/mismatch with popup-ids and a dispatch to clear one popup leading to destroying all of them.
But to answer the question, it works when you introduce a (fn []) block after the let binding where you actually do the subscription, and calling the components from inside the fn.

How to find same logos, UI elements using sikulix

I am new to sikuli.
I am using it for functional test automation of my java spring standalone application. I am having the same set of images(logos) at multiple locations on the screen. and they are generated dynamically as per the application data. In that case how can I find and click on certain buttons/elements in the UI.
Example: like, share, comment text/image will be there several times in facebook page. in that how to we click on particular buttons out of all.(facebook is just an example) i want the similar solution for my application.
I think what you're asking is- given a case where the same image or UI element is present multiple times on the same page, how can I specify one of these elements in one location versus the same element in another?
The quick and easy way to do this would be to capture a larger picture, like as much of the window as you can, and click the image in parentheses after the click action; this opens a window reading file, matching preview, and target offset. Click target offset, use the mouse wheel to zoom in, and click on the exact point of the picture that you'd like to click.
It's possible to click in multiple places on a captured image, provided you use different click() commands, and you can set the target offset for each click() command without needing a new picture.
With just this one image, you can potentially click every square on the board provided you take the time to set the offset for each of the 64 click() commands it'd take to do so. http://files.chesscomfiles.com/images_users/tiny_mce/cigoL/Chessboard.png
The more difficult solution would be setting up regions, and searching those regions for the matching pictures, but for what you're looking for this should- for more about regions and setting it up check links below. Cheers!
http://sikulix-2014.readthedocs.io/en/latest/index.html
Based on your FB example you could use setROI() to focus on the top post on the page (imagine a rectangle that covers a complete post on the news feed) from there I would loop:
if exists(profile pic):
click(like button)
elif exists(profile pic 2): # If you are testing more than one user
click(like button)
else : type(Key.DOWN) #repeat as needed
Getting the next post into the ROI may be tricky but using WHEEL_DOWN may help if you can adjust your lines traveled with each wheel click on your system.

Can't update textview instantly

I've a text view and a method has a while loop does things among them appending to text view
But The text only changes when the method ends.. (but the console shows changes instantly
How to update it instantly??
You have to give the UI, i.e., the gtk code, the chance to update the pixels on the screen. The update happens when your method exits because that is when gtk gets back in charge and can do the changes. If you want to do a lot of work and still update the UI just execute the work in a separate thread and update the UI by calling Gtk.Application.Invoke() from time to time.

SpinnerList control and monitor wheel movement

Does anyone know how programatically:
1- Stop the SpinnerList from spinning;
2- Check in which item the spinner currently is while spinning;
The SpinnerList I am using comes from the mobile.swc components. It is a Spark component (using Flex 4.6). What I could take from the documentation is basically that I could control the SpinnerList and stop it when the user triggers a mouseDown event by manipulating the scoller used in the SpinnerList. That leads to another question how do I control the scroller. Do I need to set the scrollPolicy on/off? Isn't there a better way?
Second point I still have no idea how to do it. Even reading carefully the documentation. My dataProvider is sorted alphabetically and I would like to smoothly pop a letter showing in which letter group the Spinner entered while spinning. Sort of a first letter displayer that dynamically changes while scrolling. Something like the caret_index would be cool but it only updates once the Caret is selected.
Thanks!

flex validation invalidation (component life cycle)

I am still confused with Validation and Invalidation of the component in Flex. Could anybody please give me simple comparison about what Validation can do which invalidation cant and vice versa.
I really appreciate your any help.
Thanks.
Although I do agree with the comments, this is pretty well documented I think your just missing the overall relationship between "invalidation" and "validation" methods. Basically whenever you're making a call to invalidate somethings, whether it's the display list, the size, or the properties then all your doing is telling it to set a boolean flag for one of those (any time you modify a property that will modify any of these three it will call the appropriate invalidate method such as invalidateProperties when set width is called). When the next enter frame/render happens, it will check the flags and if any of them are set to invalid it calls the corresponding validation method (updateDisplayList, commitProperties, measure).
To see the code for yourself in FB/Eclipse hit Ctrl+Shift+T and pull up UIComponent, hit Ctrl+O once UIComponent.as is opened and type in validateNow you can see the method body is 1 line and there's a nice ASDoc comment there explaining what it does. Better yet you'll see it calls validateClient on a ILayoutManager, pop open LayoutManager (Ctrl+Shift+T again) look at validateClient, it explains basically what I do here.
I think this is where you're coming from because I was in that boat once too, not understanding the relationship between updating a property and it affecting it's siblings/parent/children but it's really key to reducing processing load since a property can be modified multiple times between frame refreshes and it doesn't need to re-calculate everything around it until it will actual be redrawn.
The problem being that sometimes you want to modify a property and immediately (that is on the next lines execution) be able to see how it's side affects have modified other parts of the layout, in this case you can call validateNow() after modifying a property forcing it to immediately update all of that even if it may happen multiple times before a redraw occurs. This is generally not a great practice since it usually means undesired cpu time is wasted, but sometimes it's the easiest option.