DateTime Format in wxGrid

Hi all,

is there any helper to format date in wxGrid ?

for float values, I return wx.grid.GRID_VALUE_FLOAT + ':10,2' in GetType.

I'd like to be able to do something like this : wx.grid.GRID_VALUE_DATETIME + ':D/M/Y'

Thanks for any clue.

François

Francois Girault wrote:

Hi all,

is there any helper to format date in wxGrid ?

for float values, I return wx.grid.GRID_VALUE_FLOAT + ':10,2' in GetType.

I'd like to be able to do something like this : wx.grid.GRID_VALUE_DATETIME + ':D/M/Y'

Yes. It uses wxDateTime::Format so you can specify a format string for the cell the same as you can for that function, which is nearly the same as the strftime C function, or the time.strftime python function.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks for help, but :

wx.grid.GRID_VALUE_DATETIME + ':%d/%m/%Y'

still doesn't work... Am I missing something or is this feature not
avalaible in stable ?

I forgot to tell about my conf :

python 2.3.2
wxPython 2.4.2

···

On Wed, 17 Dec 2003 10:43:33 -0800 Robin Dunn wrote:

Francois Girault wrote:
> Hi all,
>
> is there any helper to format date in wxGrid ?
>
> for float values, I return wx.grid.GRID_VALUE_FLOAT + ':10,2' in
> GetType.
>
> I'd like to be able to do something like this :
> wx.grid.GRID_VALUE_DATETIME + ':D/M/Y'

Yes. It uses wxDateTime::Format so you can specify a format string
for the cell the same as you can for that function, which is nearly
the same as the strftime C function, or the time.strftime python
function.

Francois Girault wrote:

Francois Girault wrote:

Hi all,

is there any helper to format date in wxGrid ?

for float values, I return wx.grid.GRID_VALUE_FLOAT + ':10,2' in
GetType.

I'd like to be able to do something like this :
wx.grid.GRID_VALUE_DATETIME + ':D/M/Y'

Yes. It uses wxDateTime::Format so you can specify a format string
for the cell the same as you can for that function, which is nearly
the same as the strftime C function, or the time.strftime python
function.

Thanks for help, but :

wx.grid.GRID_VALUE_DATETIME + ':%d/%m/%Y'

still doesn't work... Am I missing something or is this feature not
avalaible in stable ?

Looks like it shoudl be but the code is rather complex so I may be overlooking something.

Perhaps another approach to do the same thing will work for you. You can register your own datatypes with the grid and specify the renderer and editor that you want to use. So if you precreate the datatime editor and renderer yourself, specifying the options you want, and then call

  grid.RegisterDataType("MyTypeName", renderer, editor)

then use that typename from your table then it should use the editor and renderer you gave it. (Don't forget to IncRef them)

···

On Wed, 17 Dec 2003 10:43:33 -0800 > Robin Dunn wrote:
  
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Howdy Robin:

I'm struggeling through the datetime issues w/gridtablebase and beating an old horse w/a keyboard shaped stick.
This issue is preplexing me, but it may perhaps shed some light on issues with datetime in the grids.

I'm feeding a column in in wxGridTableBase from a Postgres database. Since the

In my "class DBTable(grid.wxPyGridTableBase)" I substantiate a wxDateTime variable to hold the value for date columns.

class DBTable(grid.wxPyGridTableBase)
    def GetValue(self, row, col):
        if self.debug: print "%s.GetValue(row=%s, col=%s)" % (self.tableName, row, col)
        if self.__rows[row][col] is None:
            return ''
        if self._colTypes[col] is grid.wxGRID_VALUE_DATETIME:
            date = self.__rows[row][col]
            wxdate = wxDateTime_Now()
            wxdate.Set(date.day, date.month, date.year)
            return wxdate
        return self.__rows[row][col]

Traceback (most recent call last):
  File "dbTable.py", line 62, in GetValue
    wxdate = wxDateTimeFromDMY(date.day, date.month, date.year)
  File "P:\Python23\lib\site-packages\wxPython\utils.py", line 609, in wxDateTimeFromDMY
    val = wxDateTimePtr(utilsc.new_wxDateTimeFromDMY(*_args,**_kwargs))
wxPython.wxc.wxPyAssertionError: C++ assertion "wxAssertFailure" failed in e:\Projects\wx2.4\src\generic\grid.cpp(9111): Unknown data type name

This error "Unknown data type name" confounds me. Where is "name" coming from? do you think it's the name for wx.grid.wxGRID_VALUE_DATETIME it's referring to? I haven't declared anything called "name"

It's probably a bad idea to perform the conversion in the GetData function, but thought it would work... Going to explore the suggestion below...

Ciao,

-Joe

Robin Dunn wrote:

···

Francois Girault wrote:

On Wed, 17 Dec 2003 10:43:33 -0800 >> Robin Dunn wrote:

Francois Girault wrote:

Hi all,

is there any helper to format date in wxGrid ?

for float values, I return wx.grid.GRID_VALUE_FLOAT + ':10,2' in
GetType.

I'd like to be able to do something like this :
wx.grid.GRID_VALUE_DATETIME + ':D/M/Y'

Yes. It uses wxDateTime::Format so you can specify a format string
for the cell the same as you can for that function, which is nearly
the same as the strftime C function, or the time.strftime python
function.

Thanks for help, but :

wx.grid.GRID_VALUE_DATETIME + ':%d/%m/%Y'

still doesn't work... Am I missing something or is this feature not
avalaible in stable ?

Looks like it shoudl be but the code is rather complex so I may be overlooking something.

Perhaps another approach to do the same thing will work for you. You can register your own datatypes with the grid and specify the renderer and editor that you want to use. So if you precreate the datatime editor and renderer yourself, specifying the options you want, and then call

    grid.RegisterDataType("MyTypeName", renderer, editor)

then use that typename from your table then it should use the editor and renderer you gave it. (Don't forget to IncRef them)

Joe Brown wrote:

Howdy Robin:

I'm struggeling through the datetime issues w/gridtablebase and beating an old horse w/a keyboard shaped stick.
This issue is preplexing me, but it may perhaps shed some light on issues with datetime in the grids.

I'm feeding a column in in wxGridTableBase from a Postgres database. Since the

In my "class DBTable(grid.wxPyGridTableBase)" I substantiate a wxDateTime variable to hold the value for date columns.

class DBTable(grid.wxPyGridTableBase)
   def GetValue(self, row, col):
       if self.debug: print "%s.GetValue(row=%s, col=%s)" % (self.tableName, row, col)
       if self.__rows[row][col] is None:
           return ''
       if self._colTypes[col] is grid.wxGRID_VALUE_DATETIME:
           date = self.__rows[row][col]
           wxdate = wxDateTime_Now()
           wxdate.Set(date.day, date.month, date.year)
           return wxdate
       return self.__rows[row][col]

GetValue should always return a string.

Traceback (most recent call last):
File "dbTable.py", line 62, in GetValue
   wxdate = wxDateTimeFromDMY(date.day, date.month, date.year)
File "P:\Python23\lib\site-packages\wxPython\utils.py", line 609, in wxDateTimeFromDMY
   val = wxDateTimePtr(utilsc.new_wxDateTimeFromDMY(*_args,**_kwargs))
wxPython.wxc.wxPyAssertionError: C++ assertion "wxAssertFailure" failed in e:\Projects\wx2.4\src\generic\grid.cpp(9111): Unknown data type name

This error "Unknown data type name" confounds me. Where is "name" coming from? do you think it's the name for wx.grid.wxGRID_VALUE_DATETIME it's referring to?

Yes. Message is talking about the data-type-name, not the data-type called "name".

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!