I've just started playing with Nokia S60v5. I'm currently using Python to develop some learning stuff. Remember, Symbian is now Open Source, a little bit late, but Open Source at the end.
3:20 in the morning and I'm working, I need to finish a program that I wrote almost a year ago, that was a Demo program and in 4 days (right now just 2) should be production ready!... I'm gonna need a double Monster dosis.
(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.
Tonight I have been working on Christine, in the GUI, IMO a media player that work fine should also look good and sometimes GTK just don't fit on that, why? it is because GTK is a general purpose graphical toolkit and everything is general, I wish GTK has some more widget options (like more buttons that fit a specific function, like those small rounded with a simple question sign help buttons)
Fortunately, you can write your own widgets and make them look as you want. Tonight I have been working on Christine's new buttons, just for the Previous, Play/Pause, Next. Creating custom buttons is not a complicated task, just subclass gtk.Button and connect your button "expose-event" signal to a custom function, remember at the end of this function return "True" in order to stop the signal emition. If you don't do this the gtk.Button will do its task and will redraw the button.
As usual, you can check out the source code from the svn
This time I'm about to talk about lazy object, I called like that because they are more or less similar to what we use in lazy treeviews (In Gtk) where the Tree shows expanders but didn't load the child nodes until you expand the node). What I want to do is create objects and count them, but don't load any data until I need it.
Why would I need this?. Well. I'm currently writing a program for my employer, this program load a list of customers and shows how many accounts it has. As this accounts are kind of complex I create an object for them. This object is responsible for load/save the data for it, and any data you need is accessed via properties.
In my first approach, the object was loading the data as soon as the constructor was called, but sometimes I never access to any info in that object, remember, a customer may have many (and I mean really many) accounts, then why load all the data if there is a chance that I'll never use it?. Well, that is because there is a chance that I have to use that data.
Then how could I create the object and then load the data when somebody require it?. That may be easy, may not. :-). One approach is making use of python properties. Just create the object and when someone want to use a "value" from the object use the property to retrieve the data, process it and then return a value. A simple property may be defined like this:
class demo(object): def get_some_property(self): #Here you can make use of whatever you want to retrieve the data pass def set_some_property(self, value): #Here you get a value and save it. pass
some_property = property(get_some_property, set_some_property, None, 'Doc')
I just create a class "demo" and the property "some_property", everytime you use this:
d = demo()
d.some_property
Python will call the method get_some_property allowing you to do your trick. But if you have an object with more and more properties is better to get all data at one time and then just use properties to return a piece of it. You could call a method on every property if the data container is empty but for me it is not the best.
What you could do, is get the data the first time you need it. But, how could I know when a property/variable is requested on my object?
Well, Python classes have several reserved methods, and one of them is __getattribute__. This method let you handle every request to any property/class variable in your object.
With this you can digg in your object to know if the container is empty, and if it is empty fill it with data before returning the property value :-).
Lets say that the demo object have a __data dictionary containing the data. and propeties look into it for the right value, it also have a reference to the storage layer called storage.
class demo(object): def__init__(self): self.__data = {} self.storage = storage() def__getattribute__(self, name):
obj = object.__getattribute__(self,name) #Check if the requested property is __data if name in("__data", '_account__data'): #Get the reference of __data
d = object.__getattribute__(self,'_account__data') ifnot d: #Get in only if __data is empty. #Get your
s = object.__getattribute__(self,'storage') #We can assign without using object.__getattribute__ self.__data = s.get_data() #Get the value again
obj = object.__getattribute__(self,name) return obj
Pay attention that I used object.__getattribute__ instead self.property, if I use self.property will call self.__getattribute__ and will cause a recursion exception.
With this, we can create a great number of objects quickly and reducing the memory footprint.
This night I have been working on the Win32 build of christine. It seems to be working fine. This version is just a test, for those that wanted to use christine on Microsoft Windows.
Altough that I have made some tests on a clean Windows XP installation cannot guarantee that the Win32 will work on your computer.
Anyway, if you are brave enough, download the win32 binary and report any bug you found on it.
If you want to compile it, you will need this:
Python 2.6 (I built Christine with it, but python >= 2.5 should work too)
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.
Finally!!!, Christine, my beloved media player is running on Windows, this is something that I really wanted to do for the next release. I had spend the last nights trying to compile it, first I tried to compile GStreamer, then I realized that there are binaries in the GStreamer WinBuilds project, with a little less work, I tried to compile Christine using cygwin, but it didn't worked. Then using the Python's distutils I compiled the C modules and I created a binary with Py2exe
There it is, running. I still have a lot of work to do, because Christine is written for UNIX and several technologies like Dbus are not in win32, although it seems to be in progress.
I'm running it on a virtual machine and I haven't tested if it really plays something, I'll give a try tomorrow.
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