if you are using Python and MySQLdb you may find that using special chars like ñ or ó break the program raising an DecodeError because character xxx is not in the range...
MySQLdb has a way to set the charset for the connection but it is useless if you are using MySQL prior to 4.1. If you are having problems with this, then try doing this:
(py)Gtk provides a quick way to get a cairo context using the gtk.DrawingArea widget, this widget let you draw everythin you want into your application using the widget.window drawable area.
It help you to create custom widgets (you can also use this with buttons or any other widget), the problem with the usage of this context is that everything you ask it to draw it will draw it as soon as it can.
If you draw several lines or you draw the same thing very often (an animation for example) your draw may flick, making your application looks ugly.
There is an easy way to avoid this, using a surface to draw and when you are done put your draw into the context using the set_source_surface method.
In the next example you have a windows, with a custom "progressbar" using gtk.DrawingArea and a slide that is supposed to change the value of the progressbar but I'm so lazy to move a slide that let the computer do the work :-).
We create a surface using cairo.ImageSurface and then create a cairo context from it, draw on that context and at the end use the widget.window.cairo_create to create a context for the drawing_area and use set_source_surface to get all the stuff
we drew into the DrawingArea context. At the en just paint it.
This time I'm going to talk about putting an image as the application background in Gtk. In Gtk we are used to leave the colors of the application to the theme, but sometimes we will need to use an image as background. I already wrote how to draw a pixbuf in a gtk.DrawingArea (Esp), we could use that, but we will "draw" directly on the widget window instead.
Yes, I said the widget's window instead the widget itself. You should know that every widget that has been packed in a container has a gtk.gdk.window object and is the responsible for containing your widget. Well, we can draw on that object.
What we need is to create a simple gtk.gdk.Pixbuf and call the gtk.gdk.window.draw_pixbuf method using your widget.window object on the expose-event.
It is just a window with an HBoxButton as container and a Button in the middle. The button draws normal, but the HButtonBox is drawing its gtk.gdk.window with a pixbuf.
In ICT Consulting I did a small program that help the support team to create new tickets in the tracking system and keep them updated. In the "update" screen, I put a TreeView to show the comments history.
For Gtk TreeViews are just a "viewer" of the data stored in the "model", but it depends in the way the cell renderer will do its job. The render for text is called.. yes, you guessed: CellRendererText. This item will render the text as it is in the model.
If you are using text with markup (with the pango markup) it will be displayed with bold, italic and many other properties you define in your markup. But this render have a small problem, if you have a long line because the input method was a text box and the user didn't use the return key then you will end with a very very long line in the treeview.
If the line is not too big then the use of the scrollbar may help you, but, if that's not the case, and you or your user have to check more and more lines like that, using the scrollbar is tedious.
The fix: make the column usually big to wrap the text.
The trick is know the size of the window, and compute the space left by other columns then, set the
wrap_width property of the cell renderer according to the space left. That's what the "resize_wrap" function do.
You can achieve this behavior in gvim, just edit your vimrc, typically located in /home/$user/.vimrc and add the next lines:
if has("gui_running") " If the current buffer has never been saved, it will have no name,
" call the file browser to save it, otherwise just save it.
:map <silent><C-S> :if expand("%") == ""<CR>:browse confirm w<CR>:else<CR>:confirm w<CR>:endif<CR>
endif
Then add this imap to save any time you are typing, with this, you just save as in any other text editor, just Ctrl+s and keep going.
Recent Comments On Blog
Marco Antonio Islas Cruz on
Marco Antonio Islas Cruz on
Marco Antonio Islas Cruz on
Getting ready
Marco Antonio Islas Cruz on
Python: Create win32 services using Python and py2exe
jopython@gmail.com on
Python: Create win32 services using Python and py2exe
yodenuevo on
Holy Shit!
markuz on
Holy Shit!
yo on
Holy Shit!
Gustavo on
Things that happen last week
Marco Antonio Islas Cruz on
Christine: rola_christine.py