Subject: Re: [nmr_sparky] show peaks in all spectra with one click
From: Tom Goddard
Date: Apr 20, 2010

Previous: 672 Next: 683

Attachment: README

Sparky does not add $SPARKYHOME/Python to the Python path so it isnt going to find your my.py file. You could insert the path in the Python sys.path variable. But probably more useful to you is that Sparky will import the file

$SPARKYHOME/Python/sparky_init.py

when it starts and run the routine named initialize_session(). So if in the sparky_init.py file you put

def initialize_session(session):

print hello world

Then you will see hello world in the Sparky Python shell (menu Extensions / Python Shell, shortcut py). The session argument is the Sparky session object and is described in the README file included with Sparky

sparky/python/README

or on Mac

Sparky.app/Contents/Resources/python/README

Ive attached that file for your amusement.

As for modifications to peak table mouse behavior you are looking in the right place in peaktable.py, and the bind routine is setting the mouse binding which currently calls goto_assignment_cb() which calls clicked_assignment() to find the spectrum you clicked on. With some Python knowledge and studying the above code it is not hard to modify it as you desire.

Tom



I just got hold of sparky and loved it immediately! While playing with it, I met a situation I think one can probably improve the efficiency dramatically. In the Peak Table window, we can double-left- click or single-middle- click at the left side of a peak in particular spectrum to center the spectrum with that peak. If there are more than one spectrum, one need to click individual peaks to center them in different spectra window. Im wondering whether one can set a different mouse event to center all the peaks in their spectrum, respectively, for example, set single-middle- click or single-right- click for this purpose. I believe people would benefit a lot from this small modification.

I tried to understand the peaktable.py but it is quite complicated for a python newbie. By the way, how exactly I can add my own python script in sparky? Here is what I tried:
1. create a file my.py with following lines
def hello ():
print (hello the world)
2. save this file in /home/Sparky/ Python and my SPARKYHOME is /home/Sparky
3. open sparky and python shell, type import my and get error message:
Traceback (most recent call last):
File /usr/local/ src/sparky/ platforms/ linux-2.6. 9/sparky- install/python/ sparky/pythonshe ll.py, line 150, in execute_command
File stdin, line 1, in ?
ImportError: No module named my

Thanks in advance