Calendar

I’ve added a “calendar” control to my screen, where the operator can select a future production date for an order. But, I’m having a hard time using the mouse click event to write the date to a table. I had assumed that when I click on a date, there would be a mouse click event. What am I missing?

I have it working temporarily by moving the date to an invisible label and using a property change event to write the value to the table, but obviously that is a hack. And I’ve tried a variety of other ways to move the date to the table, and they all work. The only thing that doesn’t work is clicking on the calendar itself.

I’ll defer the Calendar Jython to Carl, Travis, or Bobby.

I recommend using the popup calendar instead of the calendar in pretty much every input case. It’s more space efficient and as all around a better component. See if that fixes your problem.

I looked at the popup calendar, but it takes three mouse clicks to set the date vs one with a static calendar. I have plenty of real estate, so space isn’t an issue in this case.

Step7,

I had a look at this and found that the mouseClicked, mousePressed and mouseReleased events only fire when you click on the calendar header, not on the date area - I assume this is a bug.

As a workaround, you could put your code in the propertyChange event. You will have to filter the code using the name of the property. The only problem here is that clicking on a date causes the date and formattedDate properties to change twice - another bug I think!

You could either write code to filter this second write (by checking if that date already existed in the table for example) or you could check for the user pressing the OK button, which works OK. Here is an example of detecting when the user clicks on the OK button and writing the formatted date to a textbox:

if event.propertyName == 'latchedDate': value = event.source.formattedLatchedDate event.source.parent.getComponent('Text1').text = value

I can’t help you in writing data to a table because I haven’t figured out how! In fact, if you could post code of how you did this it would be really helpful :slight_smile:

Thanks Al - good response and you pointed me in the right direction.

Step - don’t worry about mouse events, I’ll have our programmers check that out. I think you’re really interested in a property change event for date or latchedDate. Since you mentioned interest in a single click, you probably won’t use the latched options.

Try the following on a propertyChange event on the Calendar:

if event.propertyName == 'date': #your code here

If you wanted the user to have to click “ok”, then replace date with latchedDate. You may also be working with either the formattedDate or [i]formattedLatchedDate/i property.

[quote=“AlThePal”]I had a look at this and found that the mouseClicked, mousePressed and mouseReleased events only fire when you click on the calendar header, not on the date area - I assume this is a bug.

[/quote]

Mouse click wouldn’t be correct any how - property change events are exactly what you’re looking for (there are lots of parts of that component that the user could click on that wouldn’t change the date)

Did anyone try just binding the date or latched data birdirectionally to the database? You may not need any scripting at all here…

Hope this helps,

Point taken about property change events Carl. However, there still appears to be a problem when clicking on a date - this causes the date and formattedDate properties to change twice.

Also, I’m not aware how you can add a single line to a table with binding - in fact, I’m not clear on how to add a line to a table, programatically or otherwise. I remember looking at changing an Easy Chart’s dataset, where you showed me how to append an entry to the dataset indirectly as datasets are immutable. Is a similar approach required here?

Yeah, if you need to do an INSERT rather than an UPDATE, handling the propertyChange event is necessary. You could do that like this:

if event.propertyName == "formattedDate": query = "INSERT INTO mytable (thedate) VALUES ('%s')" % event.newValue fpmi.db.runUpdateQuery(query)

The problem that was causing the multiple property change updates has been fixed for 3.0.1

When I referred to a table, I was meaning an FPMI table. One job I carried out (in another package) allowed the user to enter 6 times and dates into a list - the system then used these times and dates to turn an item of plant on and off.

Any quick and easy way to implement this in FPMI? I imagine it might be easiest to write the data into a DB table and bind the list or table to the DB table.

[quote=“Carl.Gould”]Did anyone try just binding the date or latched data birdirectionally to the database? You may not need any scripting at all here…

Hope this helps,[/quote]

I just tried it, and it works perfectly. It’s the first time in my project I used bidirectional binding like that.

The only hiccup I ran into was that I also had to store the immediate date along with the formatted date (I only want the mm/dd/yyyy as a string) so I could read the value back from my table and set the calendar date to match the table when the window opens. It works great.

Also, sometime when you have nothing to do (just kidding), could you add a couple of new canned formats for my European friends? dd/mm/yyyy and dd.mm.yyyy would be fine. I can see it coming already.

You got it - that is the way to do it.

Indeed, that request has already been heard. It has made its way into the date range component (and the easy chart), but I guess the pre-canned formatting suggestions were forgotten. I’ll make a note if it.

Thanks,