GUIS basicΒΆ

# -*-Python-*-
# Created by bgrierson at 20 Dec 2016  12:38

# This is a basic OMFIT GUI demo
# All data associated with this demo will go in the TUTORIAL module ['INPUTS']['GUIS_basic']

# Set default OMFIT trees for I/O
root['INPUTS'].setdefault('GUIS_basic', OMFITtree())

# Create the main GUI
OMFITx.TitleGUI('Basic GUI Demo')

# The ShotTimeDevice GUI
OMFITx.Label("The ShotTimeDevice GUI")
OMFITx.ShotTimeDevice(multiTimes=True, showSingleTime=True)
OMFITx.ShotTimeDevice()

# A label
OMFITx.Label('A Label Followed by Separator')
OMFITx.Separator()

# A label with an image
OMFITx.Label('A label with an image', image=OMFITsrc + '/../samples/test_image.png')

# Create a text entry
OMFITx.Entry("root['INPUTS']['GUIS_basic']['entry']", 'OMFITx.Entry', default=1.0, help='A live text entry')

# Create a text entry with a post-command execution such that
# when the user presses [return] a function is executed.
def post(location=''):
    printi('Recieved varable location {}'.format(location))
    printi('With value {}'.format(eval(location)))


OMFITx.Entry("root['INPUTS']['GUIS_basic']['entry_post']", 'OMFITx.Entry with postcommand', default=1.0, postcommand=post)

# Create a text entry and enforce the entry to be a string
OMFITx.Entry("root['INPUTS']['GUIS_basic']['entry_check']", 'OMFITx.Entry must be string', default='foo', check=is_string)

# Create a checkbox
OMFITx.CheckBox("root['INPUTS']['GUIS_basic']['checkbox']", 'OMFITx.CheckBox', default=True, url='https://omfit.io')
OMFITx.CheckBox(
    "root['INPUTS']['GUIS_basic']['checkbox_mapped']",
    'OMFITx.CheckBox mapped',
    mapFalseTrue=['disabled', 'enabled'],
    default='some_other_value',
)

# Create a combobox with options that map to variables
opts = SortedDict(list(zip(['one', 'two'], [1.0, 2.0])))
OMFITx.ComboBox("root['INPUTS']['GUIS_basic']['combobox']", opts, 'OMFITx.Combobox', default=1.0)

# Create a slider
OMFITx.Slider("root['INPUTS']['GUIS_basic']['slider_float']", [-4.33, 10.9, 4], 'OMFITx.Slider', digits=2, default=1)

# A list Editor
OMFITx.ListEditor(
    "root['INPUTS']['a list']", ['apple', 'pear', 'banana', 'cherries'], lbl='Two Fruits', default=None, unique=True, ordered=True, max=2
)

# Create a button that executes a function
def button_function():
    printi('Button pressed executes function')


OMFITx.Button('OMFITx.Button runs function', button_function)

# Create a button that executes a script
root['GUIS']['basic_script'] = OMFITpythonTask(
    "basic_script.py",
    fromString='''
printi('Button pressed executes script')
''',
)

OMFITx.Button('OMFITx.Button runs script', root['GUIS']['basic_script'])

# Create a button that executes a script with arguments
root['GUIS']['basic_script2'] = OMFITpythonTask(
    "basic_script2.py",
    fromString='''
defaultVars(yesno = False)
printi('Button pressed executes script with argument {}'.format(yesno))
''',
)

OMFITx.Button('OMFITx.Button runs script with argument', lambda: root['GUIS']['basic_script2'].run(yesno=True))

# GUI elements on the same row
with OMFITx.same_row():
    for k in range(3):
        OMFITx.Button(f'Button {k+1}', lambda x=k + 1: print(x))

# Create a labeled separator
OMFITx.Separator('A Labeled Separator')

# Create an unlabeled ObjectPicker
OMFITx.ObjectPicker("root['INPUTS']['geqdsk']", objectType=OMFITgeqdsk)

# Create a labeled ObjectPicker
root['SETTINGS']['SETUP']['geqdsk2_dir'] = OMFITsrc + '/../samples/'
root['SETTINGS']['SETUP']['geqdsk2_patt'] = 'g*'
OMFITx.ObjectPicker(
    "root['INPUTS']['geqdsk2']",
    objectType=OMFITgeqdsk,
    lbl='geqdsk file',
    init_directory_location="root['SETTINGS']['SETUP']['geqdsk2_dir']",
    init_pattern_location="root['SETTINGS']['SETUP']['geqdsk2_patt']",
)

# Add a filepicker object, which just holds a string path, not an object
OMFITx.FilePicker("root['INPUTS']['geqdsk3']", default='')
OMFITx.FilePicker("root['INPUTS']['local_path']", default='', directory=True, transferRemoteFile=True)
root['INPUTS']['remote_path'] = ('/home/smithsp/bin/', 'smithsp@saturn.gat.com:22', 'smithsp@cybele.gat.com:2039')
OMFITx.FilePicker("root['INPUTS']['remote_path']", default='', directory=True, transferRemoteFile=None)

OMFITx.Separator()
OMFITx.Label('Demonstrating proper use of a lambda function within a loop')
for i in map(str, range(2)):
    OMFITx.Tab(i)
    OMFITx.Button('Press number %s' % i, lambda i=i: print('{}'.format(i)))