Re: Conversion problems using Grace files

2002-02-18 Thread Herbert Voss

Angus Leeming wrote:

> string const getFormatFromContents(string const & filename)
> examines the file, and if it recognises the contents returns a string that is 
> the format name for those contents. You may think of those strings it returns 
> as extensions but really they aren't, they're format names.
> 
> If this function returns an empty string, because it doesn't recognise the 
> contents, then we fall back on the extension. If the extension is defined in 
> the list of Formats, then return the appropriate format name. If it isn't 
> defined, then return an empty string because there's absolutely nothing we 
> can do with this file.


I have in pref for example

\format "pcx" "pcx" "PCX" ""

\converter "pcx" "eps" "convert $$i eps:$$o" ""


and in my getExtFromContents a
"return extension if unknown contents"

than all works well with the present code when "pcx" is

returned!

Why do I need another method?

Herbert



-- 
http://www.lyx.org/help/




Re: Conversion problems using Grace files

2002-02-18 Thread Angus Leeming

On Monday 18 February 2002 11:07 am, Herbert Voss wrote:
> > Also, if you can't determine the format name from either
> > getFORMATfromContents or from the list of currently available formats and
> > their extensions, then you're screwed anyway. Best to just return string()
> > and enable the rest of the code to say "No format defined!"
> 
> no, than I have no way to handle this. A return type "user"
> includes the possibilty to handle it by the user.

?? But if "user" is defined in the list of Formats, then it'll be 
discovered. If it isn't then we fail anyway.

To explain that code snippet in words:

string const getFormatFromContents(string const & filename)
examines the file, and if it recognises the contents returns a string that is 
the format name for those contents. You may think of those strings it returns 
as extensions but really they aren't, they're format names.

If this function returns an empty string, because it doesn't recognise the 
contents, then we fall back on the extension. If the extension is defined in 
the list of Formats, then return the appropriate format name. If it isn't 
defined, then return an empty string because there's absolutely nothing we 
can do with this file.

See converter.h
extern Formats formats;

Angus



Re: Conversion problems using Grace files

2002-02-18 Thread Herbert Voss

On Mon, 18 Feb 2002, Angus Leeming wrote:

> > this should be much more easier:
> >
> > instead of "user", I will return the file-extension, if present.
> > Only when we can not detect a file type from the contents and
> > have no extension than I return "user"
>
> Also, if you can't determine the format name from either
> getFORMATfromContents or from the list of currently available formats and
> their extensions, then you're screwed anyway. Best to just return string()
> and enable the rest of the code to say "No format defined!"

no, than I have no way to handle this. A return type "user"
includes the possibilty to handle it by the user.

Herbert




Re: Conversion problems using Grace files

2002-02-18 Thread Herbert Voss

On Mon, 18 Feb 2002, Angus Leeming wrote:

> On Monday 18 February 2002 9:19 am, Herbert Voss wrote:
> > On Mon, 18 Feb 2002, Angus Leeming wrote:
> >
> > > On Saturday 16 February 2002 5:31 pm, Herbert Voss wrote:
> > > > I have no problem with
> > > >
> > > > \converter "user" "eps" "xmgrace -hardcopy -hdevice EPS $$i" ""
> > > >
> > > > Herbert
> > >
> > > Sure, Herbert, but it is still rather ugly, specifying user1, user2 etc.
> If
> > > Rob wants to define an agr format, then let's let him. I think that this
> > > would do it:
> >
> > [...]
> >
> > this should be much more easier:
> >
> > instead of "user", I will return the file-extension, if present.
> > Only when we can not detect a file type from the contents and
> > have no extension than I return "user"
> >
> > Herbert
>
> Herbert, don't think "file extension", think "file format name". That's what
> you're trying to determine.
>
> An example: files file.jpg, file.jpeg are both "jpg" files but have different
> extensions.
>
> I know what you mean, but I may not in 6 months time! Let's be pedantic about
> these things.

sure, but this was the reason for the contents! When I can not
detect it by contents I return the extension, so I don not
return the format.

Herbert




Re: Conversion problems using Grace files

2002-02-18 Thread Angus Leeming

On Monday 18 February 2002 9:19 am, Herbert Voss wrote:
> On Mon, 18 Feb 2002, Angus Leeming wrote:
> 
> > On Saturday 16 February 2002 5:31 pm, Herbert Voss wrote:
> > > I have no problem with
> > >
> > > \converter "user" "eps" "xmgrace -hardcopy -hdevice EPS $$i" ""
> > >
> > > Herbert
> >
> > Sure, Herbert, but it is still rather ugly, specifying user1, user2 etc. 
If
> > Rob wants to define an agr format, then let's let him. I think that this
> > would do it:
> 
> [...]
> 
> this should be much more easier:
> 
> instead of "user", I will return the file-extension, if present.
> Only when we can not detect a file type from the contents and
> have no extension than I return "user"

Also, if you can't determine the format name from either 
getFORMATfromContents or from the list of currently available formats and 
their extensions, then you're screwed anyway. Best to just return string() 
and enable the rest of the code to say "No format defined!"

Angus



Re: Conversion problems using Grace files

2002-02-18 Thread Angus Leeming

On Monday 18 February 2002 9:19 am, Herbert Voss wrote:
> On Mon, 18 Feb 2002, Angus Leeming wrote:
> 
> > On Saturday 16 February 2002 5:31 pm, Herbert Voss wrote:
> > > I have no problem with
> > >
> > > \converter "user" "eps" "xmgrace -hardcopy -hdevice EPS $$i" ""
> > >
> > > Herbert
> >
> > Sure, Herbert, but it is still rather ugly, specifying user1, user2 etc. 
If
> > Rob wants to define an agr format, then let's let him. I think that this
> > would do it:
> 
> [...]
> 
> this should be much more easier:
> 
> instead of "user", I will return the file-extension, if present.
> Only when we can not detect a file type from the contents and
> have no extension than I return "user"
> 
> Herbert

Herbert, don't think "file extension", think "file format name". That's what 
you're trying to determine.

An example: files file.jpg, file.jpeg are both "jpg" files but have different 
extensions.

I know what you mean, but I may not in 6 months time! Let's be pedantic about 
these things.

Angus



Re: Conversion problems using Grace files

2002-02-18 Thread Herbert Voss

On Mon, 18 Feb 2002, Angus Leeming wrote:

> On Saturday 16 February 2002 5:31 pm, Herbert Voss wrote:
> > I have no problem with
> >
> > \converter "user" "eps" "xmgrace -hardcopy -hdevice EPS $$i" ""
> >
> > Herbert
>
> Sure, Herbert, but it is still rather ugly, specifying user1, user2 etc. If
> Rob wants to define an agr format, then let's let him. I think that this
> would do it:

[...]

this should be much more easier:

instead of "user", I will return the file-extension, if present.
Only when we can not detect a file type from the contents and
have no extension than I return "user"

Herbert




Re: Conversion problems using Grace files

2002-02-18 Thread Angus Leeming

On Saturday 16 February 2002 5:31 pm, Herbert Voss wrote:
> I have no problem with
> 
> \converter "user" "eps" "xmgrace -hardcopy -hdevice EPS $$i" ""
> 
> Herbert

Sure, Herbert, but it is still rather ugly, specifying user1, user2 etc. If 
Rob wants to define an agr format, then let's let him. I think that this 
would do it:

In GraphicsCacheItem::convert, the code snippet

string const from = getExtFromContents(filename_);
string const to   = findTargetFormat(from);

should be 

string from = getFormatName(filename_);

if (from.empty() || from == "user") {
lyxerr << filename_
 << "\nDon't recognise the file format either from its 
contents\n"
 <<  "or from the extension (as a user-defined format)"
 << std::endl;
return false;
}

string const to   = findTargetFormat(from);

where

string getFormatName(string const & filename)
{
// Note: getExtFromContents should be renamed as 
// getFormatFromContents as that's what it does.
string const try1 = getExtFromContents(filename);
if (!try1.empty() && try1 != "user") {
// The format is recognised fromt the file's contents
return try1;
}

// Didn't recognise file from it's contents.
// Is the extension defined by the user? If so, asume that that is correct
formats::const_iterator it = 
std::find_if(formats.begin(), formats.end(),
   FindExt(GetExtension(filename_)));

if (it == formats.end()) {
// Unable to ascertain anything about this file!
return string();
}

return it->name();
}




Re: Conversion problems using Grace files

2002-02-17 Thread Herbert Voss

R. Lahaye wrote:

> Herbert Voss wrote:
> 
>>I have no problem with
>>
>>\converter "user" "eps" "xmgrace -hardcopy -hdevice EPS $$i" ""
>>
>>
> 
> Neither have I. Thanks!!
> Apparently I was not enough familiar with this type of conversion configuration.
> It works fine now.


it was a question of reading the docs of grace to get the
right options for the conversion and not a question of
using the converter stuff of lyx ...

Herbert






-- 
http://www.lyx.org/help/




Re: Conversion problems using Grace files

2002-02-17 Thread Kayvan A. Sylvan

On Mon, Feb 18, 2002 at 11:13:40AM +0900, R. Lahaye wrote:
> files. In other words, the following is not possible:
> 
>   \converter "user1" "eps" "xmgrace -hardcopy -hdevice EPS $$i" ""
>   \converter "user2" "eps" "gnuplot -what_ever_option_to_EPS $$i" ""
> 
> Regards,
> Rob.

I don't think that's right. There's nothing magic about "XPM" or "Noweb"
or "User" in the converters preferences tab.

As far as I understand it, your example should work.

---Kayvan
-- 
Kayvan A. Sylvan  | Proud husband of   | Father to my kids:
Sylvan Associates, Inc.   | Laura Isabella Sylvan  | Katherine Yelena (8/8/89)
http://sylvan.com/~kayvan | "crown of her husband" | Robin Gregory (2/28/92)



msg33118/pgp0.pgp
Description: PGP signature


Re: Conversion problems using Grace files

2002-02-17 Thread R. Lahaye

Herbert Voss wrote:
> 
> I have no problem with
> 
> \converter "user" "eps" "xmgrace -hardcopy -hdevice EPS $$i" ""
> 

Neither have I. Thanks!!
Apparently I was not enough familiar with this type of conversion configuration.
It works fine now.

Are my following conclusions correct (I can't find help on the conversion
mechanism):

1) I cannot enter my own format as a new LyX format; like Grace (.agr files)
cannot
be entered as a new Grace-format, only as "user" format.
Apparently getExtFromContents() does not 'learn' from the Conversion table about
new formats and new extensions of files?

2) Since "user" can only be one entry in the conversion list, I can only define
one single conversion as my own. If I have Grace files conversion defined as
"user", there is no way to also define, for example, another conversion for
GnuPlot
files. In other words, the following is not possible:

  \converter "user1" "eps" "xmgrace -hardcopy -hdevice EPS $$i" ""
  \converter "user2" "eps" "gnuplot -what_ever_option_to_EPS $$i" ""

Regards,
Rob.



Re: Conversion problems using Grace files

2002-02-16 Thread Herbert Voss

R. Lahaye wrote:

>>lyx gets the filetype from its contents, not from the
>>extension. If it's an unknown one, like your grace
>>than it returns "user". You can define a converter
>>
>>\converter "user" "eps" "gracebat -hdevice EPS $$i" ""
>>
> 
> Still doesn't work; but leave it at this point; will do
> the manual version instead since I'm running out of time :(.



I have no problem with

\converter "user" "eps" "xmgrace -hardcopy -hdevice EPS $$i" ""

Herbert



-- 
http://www.lyx.org/help/




Re: Conversion problems using Grace files

2002-02-15 Thread Allan Rae

On Fri, 15 Feb 2002, R. Lahaye wrote:
> Still doesn't work; but leave it at this point; will do
> the manual version instead since I'm running out of time :(.

Just take a look at the bitmap stuff for the external inst and use
that instead.  No converter support so you need to say explicitly in
the config what needs doing.

see lib/external_templates

Allan. (ARRae)




Re: Conversion problems using Grace files

2002-02-14 Thread R. Lahaye

Herbert Voss wrote:
> 
> lyx gets the filetype from its contents, not from the
> extension. If it's an unknown one, like your grace
> than it returns "user". You can define a converter
> 
> \converter "user" "eps" "gracebat -hdevice EPS $$i" ""

Still doesn't work; but leave it at this point; will do
the manual version instead since I'm running out of time :(.

Peculiar detail though: while playing with this, LyX was
crashing every now and then, especially after having tried
to load some grace files, I loaded an eps file; the
graphics dialog closed and LyX disappeared, whop, just like
that. It seems that the conversion and LyX got strangled
somewhere.
Sorry, can't provide more details at this point.

Regards,
Rob.



Re: Conversion problems using Grace files

2002-02-14 Thread Allan Rae

On Fri, 15 Feb 2002, Herbert Voss wrote:

> R. Lahaye wrote:
>
> > I was wondering whether the Preferences/Conversion can already be
> > used to load directly Grace-format files (a 2D graphics package),
> > and have these converted to EPS (from where LyX can take over).
> > I tried but failed.
>
>
> getExtFromContents() returns "user" as ext when it's not
> a gif/tgif/eps/ps/pdf/jpg/xpm.
> Try it with this "file-format" and it should work.
>
> can you send me an example grace-file?

It looks like we'll be needing to do that much needed
InsetExternal+InsetGraphics merge about 20 minutes after we release
1.2.0pre1 given the current rate of requests.

Allan. (ARRae)




Re: Conversion problems using Grace files

2002-02-14 Thread Herbert Voss

R. Lahaye wrote:

> I was wondering whether the Preferences/Conversion can already be
> used to load directly Grace-format files (a 2D graphics package),
> and have these converted to EPS (from where LyX can take over).
> I tried but failed.


getExtFromContents() returns "user" as ext when it's not
a gif/tgif/eps/ps/pdf/jpg/xpm.
Try it with this "file-format" and it should work.

can you send me an example grace-file?


Herbert




-- 
http://www.lyx.org/help/




Conversion problems using Grace files

2002-02-14 Thread R. Lahaye


Hi,

I'm running LyX CVS.

I was wondering whether the Preferences/Conversion can already be
used to load directly Grace-format files (a 2D graphics package),
and have these converted to EPS (from where LyX can take over).
I tried but failed.

I did following in Prefences/Conversion:

Add a new format in Formats-tab:
 Format   grace
 GUI name Grace
 Shortcut
 Extension agr
 Viewer

Add Grace->EPS in Converters-tab:
 From  Grace
 ToEPS
 Converter gracebat -hdevice EPS $$i
 Flags


For example

   gracebat -hdevice EPS myfig.agr

will produce

   myfig.eps


Nevertheless, I get an "Error converting" in the figure-square on
the canvas.

Is this feature not ready yet, or am I making a terrible mistake?

-
Something else:
The filebrowser in the graphics dialog seems to have a fixed
pattern of possible file extensions: "*.(ps|eps|png|jpeg|jpg|gif|gz)"

How about composing this pattern from the list of file extensions
in the converter list, since these are the loadable files?
This way I would get immediately "agr" added to the pattern list
when I add a Grace converter.

Regards,
Rob.