Edit an item in Panel embedded table

Hallo eveyone,

The top line is to call up a graph macro or function and using a selected date-time from a 20k wave from a table to set the bottom axis range.  The date time format used is, for example 20240812 02:57:42.608.    To select the data requires the date time wave and many other paarmeters to be scrolled and the date time point from the table to be copied  by selection with mouse.

What I have arrived at is to use a single point wave in a panel embedded table and pasting the item into it. 

    // Insert table for edit/pasting date time for plot control 
    string editTable1 ="root:PlotControl:editDateTime"
    Edit/W=(360,510,490,530)/HOST=Panel_loadUtility $editTable1
    ModifyTable frameStyle=0,format(Point)=1, width(point)=500
    modifyTable size=11,alignment($editTable1)=0, width($editTable1)=200
    modifyTable showparts=0, rgb= (0,0,63000), entrymode = 1, format =8
    modifyTable showFracSeconds=1, viewSelection

 With showparts = 0 as above the embedded table shows the date-time value at point 0 and values can be pasted and copied as expected.  The date-time can be usd by a graph macro with just a few clicks in the panel.  The layout is shown in the first panel snippet below.

    // Insert table for edit/pasting date time for plot control 
    string editTable1 ="root:PlotControl:editDateTime"
    Edit/W=(340,510,500,530)/HOST=Panel_loadUtility $editTable1
    ModifyTable frameStyle=0,format(Point)=1, width(point)=500
    modifyTable size=11,alignment($editTable1)=0, width($editTable1)=200
    modifyTable showparts=1, rgb= (0,0,63000), entrymode = 1, format =8
    modifyTable showFracSeconds=1, viewSelection

With showparts = 1  above the embedded table shows the edit cell of the table. See second snippet.

How is the table edit cell controlled and formatted to look like the showparts = 0.  i.e. font size and single box?

 

With showparts = 0 With showparts = 1

Not answering you question at all, but I wonder why you don't just have a normal (SetVariable) control in your panel to work on the table data if your goal is to edit a single cell anyway. But maybe I don't get what you are trying to do ...

The problem I found was setting the variable to the Date-time format I needed.  I know it is an awkward way, but I do not know/cannot find a way of pasting a date time copied with that format into a normal SetVariable.  

If you're willing to write conversion/parsing code, you could use a string-based SetVariable.

But I'm afraid I don't understand what your goal is- what is the purpose of the single-cell table? To edit a time/date value?

I realized that SetVariable / printf offer no direct date/time conversion, so my suggestion was not very helpful. You could write your own parsing code, as John suggested to transfer from/to the (string) SetVariable control every time there is a change. Here are two conversion functions for this purpose (I use the format "2025/06/03 05:27:13.064" here):

function/S timeToString(variable tVal)
    return Secs2Date(tVal,-2,"/") + " " + Secs2Time(tVal,3,3)
end
 
function stringToTime(string str)
    string year, month, day, hour, minute, second, frac; variable tVal = 0
    string parse = "([0-9]{4})\/([0-9]{2})\/([0-9]{2})\s([0-9]{2}):([0-9]{2}):([0-9]{2}).?([0-9]*)"
    SplitString/E=(parse) str, year, month, day, hour, minute, second, frac
    frac = SelectString(strlen(frac),"0",frac)
    tVal += date2secs(str2num(year), str2num(month), str2num(day))
    tVal += str2num(hour)*3600 + str2num(minute)*60 + str2num(second) + str2num(frac)/1000
    return tVal 
end

 

It was a cludge to cut and paste a cell in table somewhere so that I could then use the value to set the bottom axes of a graph.  I used a space on a panel to have another table into which I paste it.  It would have been neater if something could be done on  the control bar of the graph.   

However, from the above comments (thanks to all) I now realise something about dates in tables that I had never thought of before: i.e. a date-time wave is stored as double precision variable but when a cell is shown in a table in the form I use  (YYYYMMDD hh:mm:ss.sss) it is of course a string. So copy and paste takes the string representation of the date-time not the DP value.  When pasting into another table it is recognised that it is a DP in the format copied and is transferred correctly. 

When I had tried pasting into a setvariable and again realise why I could not get it to function. 

The way is as nicely shown by chozo - to do a conversion.  And it will fit on the control bar of the graph.

.... a very useful training exercise for the never-to-old-to-learn from the guys-who-know-their-stuff.  

 

chozo

I am not familiar with the parsing using SplitString.  I can see the structure in the parse string representing the elements of the date time string  and it seems OK but I  the print below returns NaN 

print stringToTime("20240801 00:00:30.793")

 

Mike- SplitString uses regular expressions to break up a string into components. I have heard it said, "I had a problem and solved it with regular expressions. Now I have two problems."

But they are very seductive because they are very powerful. I know that a few of our Igor power users (like chozo) use them a lot. But it's possible that you fed SplitString with a string that chozo didn't expect. With chozo helping you, you are getting the very best advice!

Yes, regex is great at solving an issue like this while creating two news ones. :-) But SplitString is great for parsing strings you exactly know the format of.

If you don't use the '/' separator in the date, you could simply remove it from SplitString (here, represented by a preceding \ ,i.e., '\/' because this character needs to be escaped). BUT, I don't think you can teach timeToString() to output something like "20240801 00:00:30.793", because you (as far as I know) cannot have no separator in the date. This would make your back and forth conversion quite complicated (and a bit hard to read as I would think). How about using the default dashes instead, i.e., "2024-08-01 00:00:30.793"?

function stringToTime(string str)
    string year, month, day, hour, minute, second, frac; variable tVal = 0
    string parse = "([0-9]{4})-([0-9]{2})-([0-9]{2})\s([0-9]{2}):([0-9]{2}):([0-9]{2}).?([0-9]*)"
    SplitString/E=(parse) str, year, month, day, hour, minute, second, frac
    frac = SelectString(strlen(frac),"0",frac)
    tVal += date2secs(str2num(year), str2num(month), str2num(day))
    tVal += str2num(hour)*3600 + str2num(minute)*60 + str2num(second) + str2num(frac)/1000
    return tVal 
end
 
function/S timeToString(variable tVal)
    return Secs2Date(tVal,-2) + " " + Secs2Time(tVal,3,3)
end
print/D stringToTime("2024-08-01 00:00:30.793")
print timetoString(stringToTime("2024-08-01 00:00:30.793"))

 

In reply to by chozo

chozo wrote:

I don't think you can teach timeToString() to output something like "20240801 00:00:30.793", because you (as far as I know) cannot have no separator in the date.

ReplaceString("-", Secs2Date(tval, -2), "")

It's not so very ugly?

The community and databases I interact with use the "YYYYMMDD hh:mm:ss.sss" format.  As it is fixed here's my way to skin the cat

Function /D DateTimeStr2Var(string DTstr)
    // DTstr fixed format "20240802 04:35:57.532"
     variable DTvar
     DTvar = date2secs(str2num(DTstr[0,3]),str2num(DTstr[4,5]),str2num(DTstr[6,7])) 
     DTvar +=  str2num(DTstr[9,10])*3600 + str2num(DTstr[12,13])*60 + str2num(DTstr[15,20]) 
    return DTvar
end

I can use it with setvariable and remove my table cludge.  Thanks for solution.

@Tony: Yeah, that is a solution. Sometimes I fail to see the obvious, I guess.