Re: using xml to save/open project data



tonytraductor wrote:
Hi,

This is my first post to this list, so, I hope I am within the bounds
of the group. I'm a newbie to programming, and enjoying
tcl very much, but likely to ask stupid questions.

There are no stupid questions, only stupid answers :-)
Now, I've made a program, a translation project management tool,
and, I've got it doing almost everything I want.
(I just started learning tcl in January, when I started
to write this program).
http://www.TransProCalc.org - Free translation project mgmt software
Really, it's a very simple program, a gui interface that collects
specific data regarding a project (how many documents, how many
words, how much to charge per word, to whom documents have been
assigned,
etc., etc.) and spits out reports. It helps me manage this data
and does a little math. Simple.
But, there are a few, more or less essential, functions that
I still want to add.
1) rounding financial figures.
This is proving quite troublesome.
I can only find information for rounding to integers, and I need to
round to hundredths/cents.
The first thing that comes to my mind here is to multiply your number by 100, round to int and divide again:

% set myVal 3078.34763456
3078.34763456
% expr {round($myVal * 100) / 100.0}
3078.35
%

2)giving the user the ability to add/remove fields for
items like no. of document, languages, vendors, expenses, etc.
I think that's going to be complicated, so, I haven't quite
looked into that yet, although, I'm certain it's possible
and will get around to that eventually.
At the moment it serves my purposes, I just want this function to make
it more useful to others.
I would need to take a look to your app to give you hints about this. I'm feeling too lazy right now for doing that...
and

3) saving/re-opening of project. (It makes these reports,
will print and save them, but,
if I want to manipulate this same data later,
I have to re-input all of the data.)

It is this last for which I am seeking a bit of assistance at the
moment.

I tried just having the program write a script
puts "/usr/bin/wish\n
set var value\n
set var1 value1\n
etc.\n"

Then did
set filename tk_getOpenfile
exec $filename

Exec'ing the script you run it as a separate process, your script won't be able to access its vars (as you noticed). The right way would be:

source $filename

this command reads a file and evaluates its content in the current script.
to run the script to reset the variables to reopen the project.
Didn't work. The script would run, but the values weren't
imported to my program. The script would run and exit,
and, I'm assuming, somewhere those vars were set, but,
not in tpcalc. So, I lumped that.
Besides, I had to chmod the script by hand, because I couldn't
get my program to effect that little necessary change,
and that's not going to be too useful to other users, is it?
For such things, there's the [file] command, but since exec'ing the file is not what you need, in this case it isn't necessary to change the permissions of the file.

I've been told that generating an xml file is the best way to go about
this,
and, generating the xml file is easy enough. I can just have
transprocalc
write that file like it does the reports it currently writes.
No problem.

But reading the file to set the variables to re-open a save project is
proving
troublesome.

If I understand this (from http://tclxml.sourceforge.net/tclxml/3.1/tclxml.html):

I can write a proc that will do something like:

package require xml

ttk::button .btn -text Open -command open


proc open {target, data} {

set parser [xml::parser -processinginstructioncommand setvars]

setvars {set filename tk_getOpenfile
{
for each i in $filename do
set target data
}
}
}


I don't know xml, so I can't give you any useful help here. I'll leave that question to other, more experienced people on this newsgroup...

Or something akin to that.
Where filename is the name of the xml file,
target is the element and data the value, like
[target] data [/target]
[target1] data1 [/target1]
in the xml file ($filename).

Am I way off here?
I'm figuring a lot of stuff out by trial/error and whatnot, but,
confess,
that some of these tutorials are starting over my head with language
I don't understand. (It's like man pages...8 years of using linux, and
still,
most man pages might as well be in Chinese, as far as I'm concerned...
and I don't speak Chinese, just English, French, Spanish and
Portuguese...)
This xml documentation would be among those.

If this is not the appropriate place for a newbie to ask
stupid questions, I apologize, and would be grateful for
any direction regarding where I may ask said stupid questions.

Thanks,
Tony

--
http://www.LinguasOS.org - Linux for Translators
http://www.BaldwinLinguas.com - translating & interpreting
http://www.TransProCalc.org - Free translation project mgmt software


--
The orthography of this message is a product of the phantasy of the autor.
Coincidence with existing rules is purely incidental and not intended.
.