Management and IT there might well be clueless but I am new there and don't want to say that yet.That is the smartest thing I have read all week. :)
Quote of the Week!
Why I will never use Epiphany
Grabbing URL:s with style
urlgrabber is a fairly nice Python package for grabbing URL:s. The documentation is kind of sparse, but reading the source is easy enough.
Here is a simple example:
from urlgrabber.grabber import URLGrabber from urlgrabber.progress import TextMeter grabber = URLGrabber(progress_obj = TextMeter()) grabber.urlgrab('http://www.python.org/ftp/python/2.5.1/Python-2.5.1.tar.bz2')
Snåla SAS
Ibland skickar jag in insändare till tidningar. De blir aldrig publicerade, men det är kul att försöka. Den här handlade om SAS strejken.
Alla som har flugit vet hur stressande det kan vara att sitta på ett kvalmigt fullpackat försenat charterplan. Det är inget mot att ha det som sin ständiga arbetsplats. Kabinpersonalen förtjänar pauser och lunchpauser och att SAS nekar dem detta är dåligt. SAS gick med över en miljard i vinst förra året så de har råd att ge sina anställda drägliga anställningsvillkor. Att de har ratat kabinpersonalens bud är inget annat än ren och skär snålhet.
Tools for GtkImageView
I have decided that I want to extend the GtkImageView widget to make it extensible. Right now, it handles showing images that you can zoom in on and drag around. It will be extended so that you can do the following things:
- Drag a selection on the widget. Very similar to how gThumbs Image->Crop dialog works.
- Various kinds of drawing operations.
I thought about implementing this as "tools":
+------------+
| | 1 1 +-------------+
|GtkImageView| ------> |GtkIImageTool|
| | +-------------+
+------------+ |_____________________
/ |
+-------------------+ +--------------------+
|GtkImageToolDragger| |GtkImageToolSelector|
+-------------------+ +--------------------+
In this diagram, GtkImageView has a reference to a GtkIImageTool which is an interface that abstracts out certain behaviour of GtkImageView. GtkImageToolDragger and GtkImageToolSelector are two concrete implementations of the GtkIImageTool interface. When GtkImageView references a GtkImageToolDragger, it behaves like normal. You have a hand cursor and can drag the image. When GtkImageView references a GtkImageToolSelector, it instead displays a selection cursor and you can make a rectangular selection on the image.
Using this arrangement, it is now possible to dynamically alter the behaviour of GtkImageView.
It should be possible to achieve this, but the interface that GtkIImageTool will specify, might become to fat.
Tired of DocBook
Spent some time trying to find out how to write definition lists in DocBook. DocBook is the markup language used by gtk-doc and consequently the tool I am using for writing documentation for GtkImageView.
... And I am very, VERY sick of it. It turns out it was fairly simple (heh), all you have to do to create a list of directories and paragraphs is this:
The result is almost exactly what you could have accomplised using this HTML:
And of course, even less markup is needed if you use reStructuredText.
My search for a decent documentation writing system continues.
It is official!
It is official! GtkImageView is now released!
Here is the whole release announcement reprinted in full, just for fun:
I'm pleased to finally announce GtkImageView 1.0.0:
Description
GtkImageView is a simple image viewer widget for GTK. Similar to the image viewer panes in gThumb or Eye of Gnome. It makes writing image viewing and editing applications easy. Among its features are:
- Mouse and keyboard zooming.
- Scrolling and dragging.
- Adjustable interpolation.
- Fullscreen mode.
Download
Check it out from Subversion:
svn co http://publicsvn.bjourne.webfactional.com/gtkimageview
Or download the latest release tarball:
http://trac.bjourne.webfactional.com/attachment/wiki/WikiStart/gtkimageview-1.0.0.tar.gz
API documentation can be found by browsing to the ./docs/reference/html/index.html file.
Project website: http://trac.bjourne.webfactiona.com
Examples
Here is the canonical example for using the widget:
#include <gtkimageview/gtkimagescrollwin.h>
#include <gtkimageview/gtkimageview.h>
...
GtkWidget *view = gtk_image_view_new ();
GtkWidget *scroll = gtk_image_scroll_win_new (GTK_IMAGE_VIEW (view));
/* Where "box" is a GtkBox already part of your layout. */
gtk_box_pack_start (GTK_BOX (box), scroll, TRUE, TRUE, 0);
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file ("someimage.png", NULL);
gtk_image_view_set_pixbuf (GTK_IMAGE_VIEW (view), pixbuf);
Future
- Python bindings.
- Perl bindings.
- Gtk# bindings.
gtk-doc problems
My first reaction was that gtk-doc really sucks. For example, it requires you to write docstrings like this:
You have to repeat my_function_name in the comment even though it should be extremely simple for the documentation generator to find out the name of the function the docstring is documenting.
There is apparently no way to group multiple source code definitions to one docstring. You can't write something like this and expect it to work:
And despite writing docstrings using the weird format that gtk-doc imposes, you will still have to write separate API documentation using SGML. Yay! For each c-file gtk-doc documents, it generates a file called /tmpl/someclass.sgml which contains place holders for each symbol. Here is an except of one such file:
Because gtk-doc likes to write to this file, you will have a hard time keeping it version controlled and you will have to periodically merge it with the real source code. gtk-doc therefore negates the main advantage of using a documentation generator tool which is to keep the documentation close to the source code.
I am sorry for all the complaining. gtk-doc is a decent tool and using it is better than writing all documentation is Latex, for example. But gtk-doc is not the only API documentation tool available. There is doxygen, JavaDoc, Epydoc and a whole host of other documentation generators. gtk-doc just manages to be worse then all of them.
Red wine
The three classes in GtkImageView
The whole API for GtkImageView is not completed yet, but it is slowly getting there. Much of the design is borrowed (or almost stolen) from gThumb. Here is a birds eye view of the three main classes along with their counterparts in gThumb:
- GtkImageView (gtkimageview.c, gtkimageview.h)
This is the main class of the package. It provides a draggable and zoomable pane on which images can be displayed. The user of the class can customize how images are displayed and whether high or low quality scaling should be used. It also implements a number of useful keybindings for manipulating the image view.
Much code and ideas was borrowed from the ImageViewer widget in gThumb in the files /libgthumb/image-viewer.{c,h}.
- GtkImageScrollWin (gtkimagescrollwin.c, gtkimagescrollwin.h)
This class implements a kind of GtkScrolledWindow which is more suitable to use in conjuction with GtkImageView. A GtkImageView embedded inside a GtkImageScrollWin will have auto-hiding horizontal and vertical scrollbars. Additionally, in the bottom right corner it has a button which brings up a GtkImageNavigor for the image.
This class corresponds to the GthNavWindow class in /libgthumb/gth-nav-window.{c,h}.
- GtkImageNavigator (gtkimagenavigator.c, gtkimagenavigator.h)
The GtkImageNavigator provides a small popup window showing a preview of the GdkPixbuf it references. It contains a rectangle which the user can drag which causes the GtkImageNavigator to emit a certain signal, signalling to possibly a GtkImageView that it should change its scroll.
It is fairly similar to the NavWindow class in /libgthumb/nav-window.{c,h}.
And here follows a small example showing how the library is supposed to be used:
Others mistakes
Seems like I am not the only one who has had problems with Python's evalution of default arguments :
This particular example was found in comp.lang.python .
GtkImageView is now online
The code for GtkImageView is now publicly released. You can check it out using Subversion:
svn co http://publicsvn.bjourne.webfactional.com/gtkimageview gtkimageview
You can also browse to the project site at trac.bjourne.webfactional.com where you can view the code online. It is still very basic.
The GtkImageView widget
The project I have been working on lately is to create a general purpose image viewer widget for GTK . For my personal project, which will be a commercial product to be sold, I needed such a widget.
After searching around a bit, I concluded that there was no such widget [ 1 ] .
So, what I have created is such a general purpouse widget named GtkImageView. I think that there is a great use for such a widget in GNOME and that it will be just as useful as the GtkSourceView widget has been.
There are quite a few programs in GNOME that display an image inside a pane which you can zoom and drag around. Atleast both gThumb , Eye of GNOME and GIMP has such widgets. But the image display widget in these three programs is implemented independently and are incompatible to each other. Each behave slightly differently from the other. Different keybindings, different zoom factor levels and different graphic adornments.
This is where GtkImageView comes into the picture. It is an attempt to unify these three different widget implementations into one that they all can use. The gains are obvious:
- less code duplication
- Less code for each project to maintain means less bugs.
- Uniform UI
- The same set of keybindings in all programs means that a user does not have to relearn each program.
- Usable by third parties
- If you today want to create an application that has a widget that can pane and zoom on an image you have to create it from scratch. You would probably look at, for example, gThumb's source and then cut and paste that. Then you would have to spend some time integrating their widget in your own programs. Time that would be better spent doing something else.
Right now, GtkImageView is almost fully coded. What remains is to upload it to bjourne.webfactional.com and make it world-readable. The following tasks are not yet done:
- API documentation needs to be written.
- There needs to be example programs.
- Patches must be written for EOG and gThumb.
- Must announce intention to the GNOME community and get buy-in from EOG and gThumb's maintainers.
- Need to upload code and publish documentation online.
| [ 1 ] | Which was wrong, as I found out later. |