Re: [gnome-db] Formatting numbers in Form/Grid

On 1/31/07, Armin Burgmeier <armin arbur net> wrote:
Does libgda and/or libgnomedb somehow already support showing numbers or
dates in a different format? By looking at the docs and the code, I
could not find a way to do it. It seems that such a feature would have
to be added to GdaDataHandlerNumeric and/or a custom DataHandler.

Then, a way would be required to assign that data handler to a cell
renderer of a GnomeDbGrid. The GnomeDbDataCellRendererTextual does not
allow to change the DataHandler at runtime though. Is there a particular
reason for this or would it be possible to make a property out of the
data handler that can be changed later on? Finally, the grid and form
widgets would have to expose the cell renderers respectively entry
widgets (perhaps this is already the case via GtkTreeView API, but
adding explicit API seems cleaner).

I am however not sure how to specify other formats. The first thing that
came to my mind was a printf-like format string that could be given to
the data handler, but as one data handler handles multiple native types
(ints of different size, floats, etc.), we would have to make sure that
the format string is compatible. Perhaps it would be better to add two
or three separate data handlers for the most common types (say int, uint
and double) that allow formatting. Any suggestions?

If we agree on an API, I would come up with a patch for this.

The GdaDataHandler is created by each provider, and cannot be changed
(as each provider knows better how to render values as SQL and the
other wayaround).

Anyway, what you need to change is not the data handler, but the way
the data is rendered visually, which is the responsability of the
GnomeDbDataEntry widgets and GtkCellRenderer objects for respectively
the form and grid views. Libgnomedb allows you to define your own
"data entry widgets" (GnomeDbDataEntry of GtkCellRenderer) and use
them as plugins instead of the default ones.

For some examples of implementation, look at the
gnome-db-entry-pict.[ch], gnome-db-data-cell-renderer-pict.|ch] and
libmain.c files in the data-entries/plugins directory which display
binary data (or string BASE64 encoded) as pictures.

For some code about how to actually use a plugin, look in the
extra/demos/form-pict.c or extra/demos/grid-pict.c files.

So for your specific problem, I suggest you write a GnomeDbDataEntry
and a GtkCellRenderer which display dates in the way you want. Also if
you want and if the plugin you write could be usefull to others, we
could include it into the libgnomedb's sources.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]