PropertySheet dateProperty

After resolving my issues with the ArrayStringProperties, I now have run into issues with the DateProperty.
Looking at the demo example for property sheets I expected to see a similar view once I created such a property, but instead of the Date picker ctrl drop down, I just get a spin control which allow me to increment/decrement on of the date values.
See the attched screenshot.


The code to add the property is:

dt = wx.DateTime() # Uninitialized datetime
                        if  dt.ParseFormat(sDate[0], "%Y:%m:%d %H:%M:%S" ):
                            print(v, dt)
                            sp = wx.propgrid.DateProperty(cleanName, value=dt)

and the print statement gives me:

['2011:01:13 15:44:42', '08:00']
2011:01:13 15:44:42-08:00 Thu Jan 13 15:44:42 2011

What am I missing or doing wrong

One thing to note: the ParseFormat() method returns -1 if it fails and -1 evaluates to True. Therefore your if-statement will be executed even when the conversion fails. What is sDate[0] actually set to?

The code below works for me using wxPython 4.2.2 gtk3 (phoenix) wxWidgets 3.2.6 + Python 3.12.3 + Linux Mint 22.

import wx
import wx.propgrid

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        super(MyFrame, self).__init__(*args, **kwds)
        self.SetSize((400, 220))
        self.SetTitle("Test DateProperty")
        self.main_panel = wx.Panel(self, wx.ID_ANY)
        main_sizer = wx.BoxSizer(wx.VERTICAL)
        self.pg = wx.propgrid.PropertyGridManager(self.main_panel, wx.ID_ANY)
        main_sizer.Add(self.pg, 1, wx.EXPAND, 0)
        self.main_panel.SetSizer(main_sizer)
        self.Layout()

        self.page = wx.propgrid.PropertyGridPage()

        dt_str = '2011:01:13 15:44:42'
        dt = wx.DateTime()
        if dt.ParseFormat(dt_str, "%Y:%m:%d %H:%M:%S") != -1:
            sp = wx.propgrid.DateProperty("CreateDate", value=dt)
            self.page.Append(sp)
        else:
            print(f"Invalid date {dt_str}")

        self.pg.AddPage("Page_1", wx.BitmapBundle(), self.page)

if __name__ == "__main__":
    app = wx.App()
    frame = MyFrame(None, wx.ID_ANY, "")
    frame.Show()
    app.MainLoop()

Screenshot at 2024-10-18 08-56-17

I haven’t used exiftool before, so I installed it and wrote a script to check one of my own image files.

The script showed that the value for the “EXIF:CreateDate” tag in that file is set to a single date time string.

When that string is passed to the ParseFormat() method, it successfully sets the wx.DateTime object to the correct date-time.

import exiftool
import wx

image_pathname = "../images/IMG_4632.CR2"

with exiftool.ExifToolHelper() as et:
    for d in et.get_metadata(image_pathname):
        for k, v in d.items():
            if k == "EXIF:CreateDate":
                print(f"Metadata value = {v} - {type(v)}")
                dt = wx.DateTime()
                if dt.ParseFormat(v, "%Y:%m:%d %H:%M:%S") != -1:
                    print(f"Converted value = {dt} - {type(dt)}")
                else:
                    print(f"Invalid date: {v}")

Output:

Metadata value = 2016:09:24 17:36:31 - <class 'str'>
Converted value = Sat Sep 24 17:36:31 2016 - <class 'wx._core.DateTime'>

Thank you for your help, especially for the Mint example.

As I am trying to move my app from Windows to Mint, I still do a lot of development work on my Win PC and then move it to Mint via Git.

Initially, I simply stuck with the string representation. But in order to make it easier to edit/adjust some of the times & dates. and since the DateTime property was available, I wanted to use it in place of a plain string to avoid potential issues with poor editing.

The images I posted were from my Win version and, when I followed your example code, I still got the same display issue shown in my image.
When I port & run the code under Mint, I can get your Date/Time picker, but it seem next to impossible to actually click on the down ‘arrow’ to have it pop up. The scroll bar overlaps the ‘down’ button so much, that it is very tricky to be able to get the proper control to pop up.

As for Exiftool, my unfamiliarity with Python caused me much trouble trying to decide where the problem lay.
In my Windows setup, the date/time string has some extra details, which I tried to strip off.

My date/time string: 2011:01:13 15:44:42-08:00
                                        ======

I modified my example to add 10 entries to the page so that a scrollbar would appear. I was then able to easily click on any of the down arrows and get the DateTime picker to appear. Perhaps your layout is constraining the property grid from adjusting its size?

import wx
import wx.propgrid

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        super(MyFrame, self).__init__(*args, **kwds)
        self.SetSize((400, 220))
        self.SetTitle("Test DateProperty")
        self.main_panel = wx.Panel(self, wx.ID_ANY)
        main_sizer = wx.BoxSizer(wx.VERTICAL)
        self.pg = wx.propgrid.PropertyGridManager(self.main_panel, wx.ID_ANY)
        main_sizer.Add(self.pg, 1, wx.EXPAND, 0)
        self.main_panel.SetSizer(main_sizer)
        self.Layout()

        self.page = wx.propgrid.PropertyGridPage()

        dt_str = '2011:01:13 15:44:42'
        for i in range(10):
            dt = wx.DateTime()
            if dt.ParseFormat(dt_str, "%Y:%m:%d %H:%M:%S") != -1:
                sp = wx.propgrid.DateProperty(f"CreateDate{i}", value=dt)
                self.page.Append(sp)
            else:
                print(f"Invalid date {dt_str}")

        self.pg.AddPage("Page_1", wx.BitmapBundle(), self.page)

if __name__ == "__main__":
    app = wx.App()
    frame = MyFrame(None, wx.ID_ANY, "")
    frame.Show()
    app.MainLoop()

Frame-00147_2

The “-08:00” part of your date/time string looks like a timezone offset from GMT. As I’m in the UK I don’t get any offset. If you add a “%z” to the format string, the ParseFormat() should parse the whole string. However, that causes the wx.DateTime object to be set 8 hours later than input date/time (which, if late enough in the day, will also affect the date):

import wx

dt_strs = ("2011:01:13 15:44:42-08:00",
           "2011:01:13 18:44:42-08:00")
for dt_str in dt_strs:
    print(dt_str)
    dt = wx.DateTime()
    if dt.ParseFormat(dt_str, "%Y:%m:%d %H:%M:%S%z") != -1:
        print(dt)
    else:
        print("Invalid date-time")
    print()

Output:

2011:01:13 15:44:42-08:00
Thu Jan 13 23:44:42 2011

2011:01:13 18:44:42-08:00
Fri Jan 14 02:44:42 2011

So the question is: was the actual date/time that the picture was taken the uncorrected exif value, or the corrected value?

Regarding the GUI, from your example it is clear to me that problem lies with my GUI generation.
Unfortunately I am the ‘lazy’ type and have been using wxFormBuilder to build the basic GUI, hence there is where I need to look for a solution for my problem.
As for the Time Zone appendix, I have no definite information. All of my tests use images I obtained from various sources from the 'net, mainly with the main goal of getting images with a wide enough variety of metadata to serve as test targets.

This means, that to properly handle the test case, I will have to add the code mods you suggested and accept any changes that implies … but by now I have come to the reluctant conclusion, that my Python version is so far behind my C++ version for Windows and my grasp of the Python conventions so tenuous and week, that, if I really want to move ahead with what motivated me to try for the (wx)Python version, I should really concentrate on getting some ‘work’ done and then, if time permits and the need and motivation gets strong enough, to revisit the wxPython version.
Still, I am very grateful for your help. :slight_smile:
FWIW, another ‘nail in this coffin’ was a number of crashes somewhere deep inside my code, with nary a hint from VSCode about where to look or how to even proceed to debug these issues :frowning:

I’m even lazier and use Raw Therapee if I ever be interested in metadata, Exif or IPTC :sunglasses:

Good one :slight_smile:
For me the issue is that I have looked at a number of apps which can display both images and data, but, at least in the past, found them not meeting my needs. Most are intended to display the graphics, but few - even Gimp - seem all that up-to-date for metadata.
Another issue, for me, is that some of the files I need/want to work with will be PDF’s. though I have not yet explored their full capabilities of PDF metadata.
A third issue, not all of the info I want/need to write to the images would likely be supported by whatever app I might choose.

did you try Exif Pilot :cowboy_hat_face:

Not sure, but certainly not recently.
My attempts at this go back quite a few years (~20+ sidecar files and all of that non-sense) and what I found in those days, in a very general sense is that the apps I did find at at the time did not give me what I needed.
Part of that was due to my relatively limited understanding of both my needs and the various options for genealogical work.
Most of the developers for free or share ware had their own priorities and needs, if one could find a way to contact them and they responded. Some did, and one, XnViewMP in particular, did implement a number of suggestions, IIRC.
Hence, a major part of the motivation to try and build my own app was to understand the options and learn about the world of metadata in more detail. And I am not there yet :slight_smile: