wxGrid - RefreshBlock Undocumented Member Function - wxwidgets

In order to refresh a part of the grid, i.e., when font or alignment changes, I was using the following approach:
wxRect rect1=CellToRect(TopLeft);
wxRect rect2=CellToRect(BottomRight);
wxRect r(rect1.GetTopLeft(), rect2.GetBottomRight());
RefreshRect(r);
This was refreshing only a part of the intended block and was not working correctly.
From the suggestions of intellisense I came across RefreshBlock function and it works correctly. I searched the docs and have not found any information on it. I wonder if it is not recommended to use RefreshBlock for some reason? What does RefreshBlock do, does it refresh a block (as the name suggests) or is it equivalent to Refresh?
I am using wxWidgets 3.2 on Win10.
Thanks in advance.

The function RefreshBlock() is indeed the best way to do what you want and it was only undocumented by mistake, i.e. we simply forgot to do it. I've added documentation for it only now, so it will only get included in 3.2.1, but you can still use it in your code, the function itself is available since 3.1.3.

It seems from the source code that, depending on the location of its parameters, RefreshBlock refreshes any of the following:
corner grid
frozen cols grid
frozen rows grid
main grid
Since the area I wanted to refresh was on the main grid the following approach works (the idea is similar to RefreshBlock's approach):
auto GridWnd = CellToGridWindow(TL);
wxRect rect = BlockToDeviceRect(TL, BR, GridWnd);
GetGridWindow()->RefreshRect(rect);
Now everything is refreshed correctly.
Notes:
If only RefreshRect(rect) is called, things will NOT work as expected.
Little experiment showed that BlockToDeviceRect(TL, BR) also works, therefore eliminating the need for auto GridWnd = CellToGridWindow(TL);

Related

Gridster add_widget is slow

I want use Gridster for my web site, but i need to add lot of widgets with "add_widget" command. I do a test and i think there is a problem with "add_widget" function : grid is more and more slow and there are memory leak.
You can see that in this video : grister problem video
However, as you can see on the video, if i add widget at beginning (not with add_widget function) there is no problem. Can you help me ? Something wrong with my code ?
Thanks in advance !
In my own experience, the main culprit was using the autogenerate_stylesheet setting. The problem is that it regenerates the css on every call to add_widget(), and this just absolutely kills browsers. Additionally, gridster has/had a bug where stylesheets get duplicated, filling the <head> with tons of duplicate style rules, making it tough on the browser(this bug was supposedly fixed, but my experience was that the fix only worked in specific scenarios, definitely not in mine).
When I used gridster, my widgets were always the same size. So, in my case, I was able to generate the stylesheet once, never needing to regenerate it.
I don't think its part of the public api, but you can just call generate_stylesheet() method once manually.
var gridster = $(".gridster ul").gridster({
autogenerate_stylesheet: false,
widget_base_dimensions: [140, 140],
//other options...
}).data('gridster');
gridster.generate_stylesheet({rows: 30; cols: 8});
//freely call gridster.add_widget(...); as many times as you like
Since you're only going to generate the stylesheet once, you need to make sure gridster will generate style rules for enough rows and columns to accommodate all your widgets, otherwise once you exceed the range, you'll experience broken layouts. Just supply an upper bound on rows and cols when calling generate_stylesheet(opts). If you don't, it seems like it defaults to whatever value your gridster instance is using for max_rows and max_cols.
The nice thing is by manually generating the stylesheet, is that you completely avoid the duplicate style bug too.
The exponential slowdown will be gone. Happy gridstering.
I know I'm a bit late on this but I had the same problem and none of the above solutions worked.
However, I found that I was generating the size and coordinates of the widgets as a string rather than an integer on the back-end.
By making sure they were integers I managed to speed things up loads.
The best way to fix it, is not to disable the autogenerated stylesheet, but to edit the fn.generate_stylesheet function in jquery.gridster.js
At the end of the function, just before these lines:
return this.add_style_tag(styles);
};
add this line:
this.remove_style_tags();
The final result would look like this:
this.remove_style_tags();
return this.add_style_tag(styles);
};
With this, each time a stylesheet is generated, the previous one is removed, so there no duplication problem!

dojo.dnd.move node rendering issue

Dojo has a basic issue, amongst other things... with its dojo.dnd.move class. The issue which you can see here:
http://archive.dojotoolkit.org/nightly/dojotoolkit/dojo/tests/dnd/test_parent_constraints.html
Is that when you click on a node, and start dragging, the node itself jumps. It actually moves its position. This is extremely problematic and I was wondering if anyone has seen this happen before.
I am creating an application that requires the moving of nodes but it needs to be precise and thus can't have the initial jump.
Any help would be greatly appreciated.
This is caused by the following highlighted code in Mover.js:
https://github.com/dojo/dojo/blob/master/dnd/Mover.js#L91-92
The odd thing is, based on the comments, it seems like this code is causing the very problem it aims to prevent.
That said, if your body has padding: 0 applied to its style, this code shouldn't affect you. (You can test it on that test page by running document.body.style.padding = "0" in the console before dragging.)
You might want to enter a ticket on the Dojo bug tracker at http://bugs.dojotoolkit.org (or maybe search and see if one has already been entered for it).

PyGtk: change image after window's main() method?

I'm using a gtk.Image widget to display a picture in a gtk window. I can set the image to be displayed before I call window.main(), but after I've done that the image won't change any more. Basically:
import pygtk
pygtk.require('2.0')
import gtk
(...)
window= Window()
window.canvas= gtk.Image()
window.window.add(sprite.window.canvas)
window.canvas.show()
window.canvas.set_from_file("pic1.gif")
window.main()
window.canvas.set_from_file("pic2.gif")
pic1.gif will be displayed. Is there a proper way of changing the image (I don't care if I have to use a widget other than gtk.Image)? All I can think of is destroying the window and creating a new one.
Edit:
I realized my mistake... I called window.main() for every window and any window's destroy event called gtk.main_quit(). Had to make slight adjustments, but it works now. Even after calling window.main() :)
As Rawing hasn't yet accepted his own answer, I'll post it to get this off the top of the unanswered questions page, and to help out anyone skimming this from a search engine clickthrough by providing a comprehensive answer. (Rawing, feel free to post your answer yourself, all the same.)
In your code, you're declaring window as Window(), as opposed to gtk.Window. If you're building in one window, you should not need to do this every time. Create the window once, add what you need to it. If you need additional windows, declare them separately in this module, and call them from code (instead of from main).
Furthermore, don't name your objects with a "window." at the beginning...that just gets overly confusing. Give it a simple name, add it where you need it. Python will do the rest.
A cleaned up version of your code above would probably look like this:
window = gtk.Window()
#You may need additional arguments above, such as to make it top level.
canvas = gtk.Image()
window.add(canvas)
canvas.show()
canvas.set_from_file("pic1.gif")
Now, just change the image in an event or another "def", like this:
def ChangePicture():
canvas.set_from_file("pic2.gif")
Canvas should update the picture automatically.

Dojo - Some of my form.dijit's seem to be dead/inactive on one page

I was started to work on my first sample of the dijit.Tree control.
When it didn't work, I added a couple of dijit.form.Textbox'es to the screen, and they didn't work either, even though I have them working fine on a similar form.
Interesting enough, when I killed FireFox and restarted it, I was got a clear message in FireBug console on what was wrong with my tree control, and got it fixed.
But now I'm rather puzzled while the simple dijits like NumberTextBox that I added are not working.
My Samples:
1) http://3wcloud-com-provisioning-qa.appspot.com/testDijitDate - this works great
(except the initial date value not showing - I have a separate question open on that)
2) http://3wcloud-com-provisioning-qa.appspot.com/testDijitTree
I've done several "diff"s on the two files, and I kind find the difference that would cause one to work and one not to work.
Thanks,
Neal
You should put your dojo.require statements immediately in a script block, not wrapped in the onload callback. Also, your input tags should be HTML style without the XHTML style slash (you didn't declare XHTML in your document) though I doubt that's the problem. See if either of those things help.

Problem with QSqlTableModel -- no automatic updates

After setting up a table model in Qt 4.4 like this:
QSqlTableModel *sqlmodel = new QSqlTableModel();
sqlmodel->setTable("Names");
sqlmodel->setEditStrategy(QSqlTableModel::OnFieldChange);
sqlmodel->select();
sqlmodel->removeColumn(0);
tableView->setModel(sqlmodel);
tableView->show();
the content is displayed properly, but editing is not possible, error:
QSqlQuery::value: not positioned on a valid record
I can confirm that the bug exists exactly as you report it, in Qt 4.5.1, AND that the documentation, e.g. here, still gives a wrong example (i.e. one including the removeColumn call).
As a work-around I've tried to write a slot connected to the beforeUpdate signal, with the idea of checking what's wrong with the QSqlRecord that's about to be updated in the DB and possibly fixing it, but I can't get that to work -- any calls to methods of that record parameter are crashing my toy-app with a BusError.
So I've given up on that idea and switched to what's no doubt the right way to do it (visibility should be determined by the view, not by the model, right?-): lose the removeColumn and in lieu of it call tableView->setColumnHidden(0, true) instead. This way the IDs are hidden and everything works.
So I think we can confirm there's a documentation error and open an issue about it in the Qt tracker, so it can be fixed in the next round of docs, right?
It seems that the cause of this was in line
sqlmodel->removeColumn(0);
After commenting it out, everything work perfectly.
Thus, I'll have to find another way not to show ID's in the table ;-)
EDIT
I've said "it seems", because in the example from "Foundations of Qt development" Johan Thelin also removed the first column. So, it would be nice if someone else also tries this and reports results.
I use Qt 4.6.1 in PyQt and the problem is still here. Removing "removeColumn(0)" solves the issue.