Image as background in a Gtk Application.

(Reposted from the old blog)

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.

The code should look like this:


#!/usr/bin/env python
import gtk
 
def draw_pixbuf(widget, event):
        path = '/home/markuz/wallpapers/WMwall1024x768.gif'
        pixbuf = gtk.gdk.pixbuf_new_from_file(path)
        widget.window.draw_pixbuf(widget.style.bg_gc[gtk.STATE_NORMAL], pixbuf, 0, 0, 0,0)
 
window = gtk.Window()
window.set_title('Drawing Test')
window.set_size_request(640,480)
window.connect('destroy',gtk.main_quit)
hbbox = gtk.HButtonBox()
window.add(hbbox)
hbbox.connect('expose-event', draw_pixbuf)
button = gtk.Button('Press Me!')
hbbox.pack_start(button, True, False, 10)
window.show_all()
 
gtk.main()

And the result should be like this:

4113718671_d310f973d0

Putting an image as background in Gtk

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.

Loading

Trying the new wordpress desktop app

Basically looks like the wordpress.com site in a frame. And there is one thing that needs to improve, something that needs to change also in the mobile app (iPhone, iPad and possibly in Android too): Integration.

Screenshot 2015-12-18 00.06.23

Yes, wordpress needs to integrate with the system, WordPress is by many people used as a CMS more than a blogging system. Many “news” sites use wordpress, maybe they do need to enter to the desktop/web app to write all that stuff, but others use wordpress as a simple blog system.

In a simple blog system not always things are big posts, maybe you just want to share some pictures.

Screenshot 2015-12-18 00.12.19

Maybe you want to share just one picture. Maybe you just want to do a quick share.
Screenshot 2015-12-18 00.12.54

I mean, is good and other apps like blogo might be wondering what to do with this new official app, what would be the added value that a user will make it use blogo instead of wordpress desktop app, but still, to me a killer feature would be: Integration with the system.

Have you been in tumblr?, I bet you did. There are lots blogs to share (pr0n) gifs, they do the “reblog” feature that I like a lot, in wordpress it is called “press it” and that is nice, having an integration with the system would be awesome, that would really make it a “desktop” app.

There is a way to post by sending an email, and that’s also great, but not having to rely on your email to share an image is great, something like this can make the trick.

Screenshot 2015-12-18 00.19.28.png

I hope this feature to be added soon in both, the desktop and mobile apps.

Loading

no sugar

Just to let a note on my blog, I’m starting a new challenge, no sugar week, if I can do it for one week then I’ll try to make it for another week and so on. that’s why I’m drinking coffee with no sugar.

I’m also trying to get rid of meat, so, this is also my no meat week challenge, I tried to do it last week but I failed on Thursday I think, kids wanted pizza, I wanted pizza, but they didn’t wanted the veggie one :-(. I hope I can do it this week.

I’m also doing some workout, I hope the workout + no sugar + no meat help me to get rid of this ~20 extra kilograms I have.

Loading

How to move some files but preserve the directory tree?

So, I have a bunch of ogg files that I moved to mp3 (I don’t want to start a format/encoder war, I just did it), I wanted to move the old ogg files, I didn’t delete them because probably I need them in the future. To move the files apart the easiest way could be using find and xargs:


find . -iname "*ogg" -print0 |xargs -0 -I {} mv {} /dest/folder/

The problem with this is that all those ogg files would be in /dest/folder/ all together, and I want to have them each in the corresponding subfolder, I was looking and found that some uses “cp –parents” unfortunately it seems that the cp in OS X does not include that.

What I ended up doing.

If you create a package file (.tar for example), the directories are preserved, so, for me the trick was using tar for that purpose.


find . -name "*ogg" -print0 | xargs -0 tar cvf - |(cd /dest/folder/ ; tar xfp -)

You’ll see all those ogg files in the screen as they are “copied” to the destination folder. later you can remove the files with find again.


find . -iname "*ogg" -delete

 

I assume there is a way to remove the files as soon as they have been added to the tar file.

Loading

High price on a system with a built-in “compress” feature?, who the hell runs WinZip?

 

Screen Shot 2015-11-16 at 3.38.48 PM

I was looking for rar applications on the App Store, and I saw that WinZip was there, although the price was scaring knowing that OS X have a built in compress/decompress feature, no need to use WinZip, still, knowing that maybe some Windows nostalgic user wants to the WinZip app it would be better to have a lower price (even a free version). Why bother in paying a $99USD developer license if your app will probably sell 0 licenses.

Which remind me this:

5713890_700b_v2

Loading

TripMode

Screen Shot 2015-11-15 at 5.00.23 PM

Just a small post about TripMode a small app (and kernel extension) that helps a lot to control which program is having access to internet, not only incoming connections but more importantly outgoing when you are on a limited connection.

Since a little more than a month I’ve moved to a place where the internet connection was not that good. I used do have 20Mb/s connection and was working perfectly fine, but when I moved here.. well.. the internet was pretty unstable and the bandwidth was like with dial-up modems.

TripMode help me a lot to let some applications use internet, example, Chrome, iTerm, SSH, and some other command line programs, but forbid others like App Store, Updates, the Photos Agent, Dropbox, etc.. of course I can allow any of them whenever I want/need. This to allow all the important apps to have internet, the most possible bandwidth. 

That was in the small town where I was a week ago, then one week I didn’t have a landline and I had to use my cellphone internet, which is fast but is expensive, and TripMode helped to limit the internet usage, so I didn’t finish my cellphone’s credit. This was awesome

Note this is not a paid post, I just like this app and deserves my recommendation.

Loading

I’m getting used to this

2015-10-22 21.27.55

I know I said 3D touch is not the thing, but is handy. Of course, I’m used to the usual way to do things (entering to the app and then hit the action button) and I expect the apps really make use of this technology, I hope.

Ceiba #notouch #nofilter #morning

Ceiba

And talking about the device, It’s great, as you can see in my flickr photostream I’ve been using it for a couple of weeks now, pictures are great although with the bandwidth I have here (near to Guatemala) is hard to upload several pictures, not to mention videos. But pictures are fine, about 2MB in size and look definitively great (I still want my DSLR camera). In terms of performance, you can watch several videos about the 6S performance in youtube. Its also great, reloading apps happens not to often, sometimes it’s barely noticeable, sometimes it is but almost all time you won’t notice.

Continue reading

Loading

Apple, Why U NO Let me use your extension in Chrome?

Screen Shot 2015-10-26 at 4.37.04 PM

Apple have this chrome extension so you can sync your Safari favourites with Chrome, but it is designed to run on Windows 7/8, bad luck for those that use OS X and prefer to use Chrome.

I also use Safari, but for my day to day I use chrome because of the extensions. If Safari could add good extensions that would be great!

Continue reading

Loading

Python trick: How to make lazy objects?

Reposting from the old blog.

Hay una versión de este post en español, si lo prefieres puedes léerla aquí: Truco de Python, como crear objetos “flojos” (Lazy objects)

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:

I just create a class “demo” and the property “some_property”, every time you use this:

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 dig 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.

Pay attention that I used object.__getattribute__ instead self.property, if I use self.property it 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. The downside is that getting the data will be a lot expensive if we require the data of all (or several) objects at once.

How would you do it?, let me know in the comments.

Loading