Friday 29 June 2012

Baby, did a bad, bad thing

Yesterday I wasted a little bit of time searching to find a bug: I had to delete a selected element from the list of registered stocks in the main screen, and also from the internal db.
Everytime I searched to delete one element from the list, the deletion of that element from internal db doesn't work... instead it was deleting another element.
The code was something like that:
  1. get the iterator and model , for the selected element of the treeview.
  2. remove the element from the model giving the iterator.
  3. the iterator became invalid...(yes it is deleted!) so I did the same thing of step 1.
  4. remove the element form the db getting the key from the iterator.
The bug was simple but it takes some time.. at point 4, the selection to the treeview changed to the previous element in the list!
So the code changed like this:
  1. get the iterator and model , for the selected element of the treeview.
  2. remove the element form the db getting the key from the iterator.
  3. remove the element from the model giving the iterator.

Now add and delete of stocks works.

The other problem is with pygtk and thread.. As I mentioned before.. everytime the application try to connect to the web the interface freeze until this operation is complete.
This happened because retrieving data from the net, it is a blocking operation, and block the main thread where the GTK engine runs.. so the application freeze.

I read so many pages about which is the best way to implements a Thread.. and I hope to be near to a solution.. but not yet!

No comments:

Post a Comment