Saturday, January 23, 2010

Tonight's Photobomb Feature(s): Push and Hold Buttons, Simpler Web Tab


Yesterday afternoon I started to implement "Press and Hold" for certain buttons. Like the the "bigger/smaller" buttons, the "less/more opacity" buttons, and the rotation buttons. What I wanted (and now have) is that you can just press down on the button and hold it down. While it is held down the button keeps working, like the selected item keeps getting bigger the longer the hold it down.

Unfortunately, it turns out that gtk.ToolButton don't send pressed and released signals, just "clicked". So I went ahead and reimplemented the buttons for photobomb using regular buttons. Thus it took me a few hours instead of a few minutes to implement that features.

I actually added a Quidget for the press and hold buttons, and is it seemed like useful functionality that I could make a simple API for. To create a PressAndHoldButton, you just create a button as normal, but you pass it an action to perform while depressed. Here's how I created PressAndHoldButtons with an image. "action" is a function passed in to fire repeatedly as the button is held down:
     button = PressAndHoldButton(action)
image_path = getdatapath() + "/media/" + icon
img = gtk.Image()
img.set_from_file(image_path)
button.set_image(img)
button.show()
I suppose that I should really change the API so that you connect a function to a signal that the button fires, for example "tick". This would be more consistent with other PyGtk widgets. It would also developers to tie multiple functions to the button. In any case, the PressAndHoldButton manages a gobject timer internally, as the developer, all you need to do is give it a function.

Anyway, there's one more Quidget, and also while I was at it, I cleaned up the interaction of the clip tool and the pen somewhat, especially in terms of the most cursors they set. I also added buttons for saving a file and micro-blogging. I sniped the Gwibber svg file and sized it down to 20 x 20.

I also modified the web tab somewhat. Now instead of three separate buttons that each bring up a different prompt, there is a single text edit field. The way it works is to first check if the entered text starts with "http:". If it doesn't, the page assumes it's a search, and searches for images matching the keywords. If it does start with "http:" then does it end with the suffix of an image type? If so, it tries to just download that image. Otherwise, it assumes it's a web page, and tries to scrape the page.

No comments:

Post a Comment