I use this script to batch process all opened files (it simply calls
another function I wrote in another script, which is also included below)

#################################################
# process_all.py
# This calls another script I wrote so I need to import it.
import process_afm

import gwy
import os

plugin_menu = "/Process All Opened Files"
plugin_type = "PROCESS"
plugin_desc = "Process all opened files"

def run():
    cons = gwy.gwy_app_data_browser_get_containers()
    for c in cons:
        process_afm.process_container(c)

#################################################

Below is the other script that gets called. This one works perfectly when I
run it from the menu, but not when called from process_all.py above:

#################################################
# process_afm.py
import gwy
import os
import sys

plugin_menu = "/Process AFM Image"
plugin_type = "PROCESS"
plugin_desc = "Process currently active file"

def run():
    c = gwy.gwy_app_data_browser_get_current(gwy.APP_CONTAINER)
    process_container(c)

# I make this a separate function so I can call it from other scripts
def process_container(c):
    gwy.gwy_process_func_run("line_correct_median", c, gwy.RUN_IMMEDIATE)
    gwy.gwy_process_func_run("scars_remove", c, gwy.RUN_IMMEDIATE)
    dfields = get_data_fields_dir(c)
    d = dfields['/0/data']
    d.fit_lines(0,0,512,512,3,False,gwy.ORIENTATION_VERTICAL)
    d.data_changed()

def get_data_fields_dir(container):
    """
    Get list of available datafield stored in given container as directory
    where key is key name and value is DataField object.

    @param container: gwy.Container with datafields

    @return: a directory of datafields
    """
    d = {}
    for key in container.keys_by_name():
        x = container.get_value_by_name(key)
        if type(x) is gwy.DataField:
            d[key] = x
    return d
#################################################


(I took the source code for get_data_fields_dir from gwyutils.py because I
cannot include gwyutils for some reason.)

What appears to happen is that the Datafield method fit_lines is called
properly on all opened windows. However, the two invocations to
gwy.gwy_process_func_run do not work on any open window, except the one
that is active when I start the batch processing.

How can I get gwy.gwy_process_func_run to process containers other than the
currently active one? If this is not possible, how can I achieve the same
functionality for batch processing (for instance, are there Datafield
methods equivalent to the functions available through
gwy.gwy_process_func_run?)

Thank you in advance for your help,
Dave
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
Gwyddion-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gwyddion-users

Reply via email to