Friday, May 01, 2009

Code quiz

run this code:

see that the close icon has a padding on the left and the bottom?


import gtk

class TinyButton(gtk.Button):
'''a simple and tiny button'''

def __init__(self, stock):
'''constructor'''
gtk.Button.__init__(self)

self.image = gtk.image_new_from_stock(stock, gtk.ICON_SIZE_MENU)
self.set_image(self.image)
width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)
self.set_size_request(width + 2, height + 2)
self.image.show()

self.set_focus_on_click(False)
self.set_relief(gtk.RELIEF_NONE)

if __name__ == '__main__':
w = gtk.Window()
w.add(TinyButton(gtk.STOCK_CLOSE))
w.show_all()
gtk.main()


ok, if you can remove that extra padding your name will be on this post :D

EDIT: what I need is a really small button with no margins or paddings, that's why it's called TinyButton ;)

HINT: I borrowed the code from here: http://git.gnome.org./cgit/gnome-terminal/tree/src/terminal-tab-label.c?h=gnome-2-26 but something is missing and I can't see what.

An the winner is:

Faith_Nahn

he posted the code to solve the problem that involved setting a gtk style for the button. Thanks to him and all the ones that submited code!

If you find it fun I can make more code quizes in the future.

as an extra bonus you where added to the dummy user list of the dummy protocol, now you can make girls fall inlove with you by showing them that you are on emesene code (?)*

btw, you are on the commit log too: http://emesene.svn.sourceforge.net/viewvc/emesene?view=rev&revision=1610

* to make this, login with any user and password selecting the dummy session on login preferences.

10 comments:

Fitoria said...

the only way I got it to work is this one http://gist.github.com/104873 I don't know what you want.. so please explain a bit more :P

Anonymous said...

Hi

add to code
self.connect("clicked", self.destroy)in constructor, and create metod destroy.

Code:
http://pastie.org/465347

Sorry for my bad english i'm Chilean.
=P

brutalchrist@gmail.com

blacknight said...

@brutalchrist

That's not what he's after :P

When you run the code he provides, you'll notice that the red X is offset to the right, i.e. it's padded. He wants to eliminate that padding, so that the X appears central.

What he wants is that padding to be removed so that he can have a really small close button. Hope this clears things up :)

If I knew more about python, I'd help, but I've hardly touched the language!

Anonymous said...

May be changing window size fix the problem. When I resize the window manually the button shows properly.

Daniele said...

there you are mariano :)

http://rafb.net/p/rXiCqm66.html

The problem is: width can't be lower than 24 pixel for gtk to exactly align the image ( don't ask me why :/ )

height can be lower than 24 but it will stretch the image.

Gabriel Mazetto said...

this way worked:

http://gist.github.com/107508

Faith_Nahn said...
This comment has been removed by the author.
Faith_Nahn said...

Here it is.
The solution was to create a new style for the widget, to force the size and padding changings.

http://gist.github.com/107992


I borrowed the idea from this site.
http://coding.debuntu.org/python-gtk-how-customize-size-button-notebook-tab-label

Hope to see the new emesene soon. ;)

Anonymous said...

i like your proyect, i miss i cant help because i programing in C/C++. But if you can, maybe you can add webcam Support, or when you do this can add record webcam please xD

If you can do this, i sure used allways

luismarianoguerra said...

we have a winner!, read the bottom of the article.