5. Settings, Dialogs, Printing - Spinmob/spinmob GitHub Wiki

As usual, this tutorial relies on the following import command:

In []: import spinmob as s

Settings

Spinmob can remember information between sessions, e.g., the last data directory where you loaded and saved files (see below). This is accomplished by using the s.settings object, which behaves roughly like a persistent python dictionary. If you want to remember something from one session to the next, use a command like

In []: s.settings['thing_to_remember'] = 'that thing I wanted to remember.'

Next time you load spinmob, this will still exist.

In []: s.settings['thing_to_remember']
Out[]: 'that thing I wanted to remember.'

Good times.

Dialogs

Spinmob is equipped with a set of basic dialog windows for loading / saving file(s) and creating / selecting directories. These can be found in

In []: s.dialogs

The functions in s.dialogs all use s.settings to remember the last path between calls and sessions. If you want to remember more than one "type" of directory, set the default_directory keyword when calling a dialog function, e.g.

In []: s.dialogs.open_multiple(default_directory='particular_apparatus')

This will automatically create (and manage) s.settings['particular_apparatus'] so that every time you run a file dialog with this specification, it will remember the path from the previous call of the same specification.

Insta™ Brand Figure Printing

This may seem trivial, but another key feature of spinmob is the ability to immediately print the plot(s) you just made without any clicking or hassle. Just type

In []: s.instaprint()

and the current figure will immediately stream out of your default (or specified) printer so you can start scribbling on it and thinking about science. You can also specify a list of figures, e.g. [0,2,5], or 'all' to print all of them.

This command requires some initial setup, but is totally worth the effort because it will save you an infinite amount of time. Think of what you can do with infinite time.

Windows

On Windows, we have mostly started to use greenshot to instantly print whatever we're looking at on the screen. It's pretty great.

To use instaprint, we first download and install Ghostscript and gsview. Then, use the following command in spinmob:

In []: s.settings['instaprint'] = r'C:\"Program Files (x86)\Ghostgum\gsview\gsprint.exe" -color'

but with your correct path to gsprint.exe. Note the 'r' before the string (disables the back-slashes). This will print to your default printer, but gsprint.exe does have the ability to choose a printer as well.

OSX

This used to work, but hasn't been tested in awhile. Set a default mac printer using System Preferences.

Then

In []: s.settings['instaprint']='lpr'
Linux?

If you're running linux, you can presumably pwn this. I also recommend 'lpr'. Let us know if you find a simpler / more elegant methods! It would be amazing to not have to install anything, for example.

Up next: 6. Easy GUI Generator