lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: frescobaldi clipboard file name


From: David Wright
Subject: Re: frescobaldi clipboard file name
Date: Tue, 24 Apr 2018 09:30:02 -0500
User-agent: Mutt/1.5.21 (2010-09-15)

On Tue 24 Apr 2018 at 08:53:01 (+0200), Gianmaria Lari wrote:
> On 23 April 2018 at 15:48, David Wright <address@hidden> wrote:
> 
> > On Mon 23 Apr 2018 at 09:43:01 (+0200), Gianmaria Lari wrote:
> > > The following frescobaldi snippet call the "more.com" program with the
> > > parameter "\\readme"
> > >
> > > -*- python;
> > > from subprocess import call
> > > call(["more.com", "\\readme"])
> > >
> > > This other one-line snippet pastes, in the frescobaldi editor window at
> > the
> > > cursor position, the lilypond file name (including path) of the current
> > > document
> > >
> > > $FILE_NAME
> > >
> > > Now I would like to merge the two worlds:) I would like a snippet that
> > > calls an external application passing as parameter $FILE_NAME.
> > > Any suggestion?
> >
> > import os # likely to have been imported already
> > call(["more.com", os.environ['FILE_NAME']])
> >
> 
> I have not been able to make it working.
> Let's make a step back and simplify things.
> Let's use FRESCOBALDI_VERSION that should always be defined (FILE_NAME is
> not defined when the file has not been explicitly saved).
> And let's use a simple assignement instead of an external call.
> 
> The following code paste in the editor window the text "ciccio" at the
> cursor position.....
> 
> -*- python;
> 
> text = "ciccio"
> 
> 
> 
> 
> Now if I try....
> 
> -*- python;
> import os
> text = os.environ['FRESCOBALDI_VERSION']
> 
> 
> I expect to see pasted the frescobaldi version. But this does not work and
> I get the errror.... KeyError: FRESCOBALDI_VERSION.
> Maybe the variables are not part of os.environ?

I think we're falling foul of this:

    This mapping is captured the first time the os module is imported,
    typically during Python startup as part of processing
    site.py. Changes to the environment made after this time are not
    reflected in os.environ, except for changes made by modifying
    os.environ directly.

So if Fresco is running a child process, that child could interrogate
the environment set by the parent. As it is, I don't know where your
FRESCOBALDI_VERSION and FILE_NAME come from. If they're being set in
a Fresco parent process, then they would have to be inserted into
the environment for you to use them:

$ pyth
Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ["SHELL"]
'/bin/bash'
>>> os.environ["SPQR"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/os.py", line 725, in __getitem__
    raise KeyError(key) from None
KeyError: 'SPQR'
>>> os.environ["SPQR"]="Senatus Populusque Romanus"
>>> os.environ["SHELL"],os.environ["SPQR"]
('/bin/bash', 'Senatus Populusque Romanus')
>>> 

Cheers,
David.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]