Re: PyGObject: cell_data_func or own Renderer for date column?
- From: infirit <infirit gmail com>
- To: c buhtz posteo jp, "gtk-app-devel-list gnome org" <gtk-app-devel-list gnome org>
- Subject: Re: PyGObject: cell_data_func or own Renderer for date column?
- Date: Fri, 11 May 2018 12:13:41 +0200
Op 10-05-18 om 00:06 schreef c buhtz posteo jp:
I want to have a date column in a Gtk.ListView. The field in the model
is a real "datetime.date". Based on that the content of the column
could display this:
"2018-05-07"
"2 days ago"
"this week"
"7th May"
"7. Mai '18"
Store this string in the Gtk.List/TreeStore, keep the datetime.date
somewhere and update the string when the user changes the date format.
I never used it but you may want to experiment with storing a GLib.Date
object.
This is all based on the same "datetime.date" instance. The user decide
how to display. So I need maximum flexibility.
A cell_data_function is an option here to implement this. Is it a good
choice?
You can of-course do all sorts of things and manipulate to your hearts
content but I think you are making it too complicated. You could have
two strings, one for the display and another that stores a version that
is easily parsed by the datetime module.
What is about deriving from Gtk.CellRendererText?
But I don't see how to do this. May I only overload the render()
function? But how can I read from datetime.date object and convert it
to a string?
You subclass and override the virtual methods [1] with your own. For
example something like below.
class MyRenderer(Gtk.CellRendereText):
def __init__(self, datetime):
super().__init__()
self._datetime = datetime
do_render(self, cr, widget, bg_area, cell_area, flags):
# implement your own rendering here
~infirit
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]