Added Options and OptionsDialog

This commit is contained in:
Arnar Flatberg 2007-01-04 13:53:03 +00:00
parent ebd4fdae7b
commit e08a8377ed

View File

@ -1,4 +1,4 @@
import gtk
import gtk, gobject
import sys
import os
import inspect
@ -213,3 +213,167 @@ class WorkflowView (gtk.VBox):
logger.log('debug', 'Function ended: %s' % function.name)
class Options(dict):
"""Options base class.
"""
def __init__(self, *args,**kw):
dict.__init__(self, *args, **kw)
self['out_plots'] = None
self['out_data'] = None
def _copy_from_list(self, key_list):
"""Returns suboptions (dictionary) from a list of keys.
"""
d = {}
for key in key_list:
d[key] = self.get(key, None)
return d
class OptionsDialog(gtk.Dialog):
"""The basic input/output dialog box.
This defines the first page of the function options-gui.
Any function that invokes a option-gui will inherit from this class.
"""
def __init__(self, data, options, input_names=['X','Y']):
gtk.Dialog.__init__(self, 'Input-Output dialog',
None,
gtk.DIALOG_DESTROY_WITH_PARENT,
(gtk.STOCK_OK, gtk.RESPONSE_OK,
gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
self._options = options
self._data = data
self._editable = True
self.set_size_request(300,400)
# create notebook
nb = gtk.Notebook()
# 1. page: input/output
#
#inputs
input_frame = gtk.Frame("Input")
hbox = gtk.HBox(True, 8)
align = gtk.Alignment(1, 1, 1, 1)
align.set_padding(8, 8, 8, 8)
align.add(hbox)
input_frame.add(align)
for i, name in enumerate(input_names):
frame = gtk.Frame(name)
frame.set_label_align(0.5, 0.5)
label = gtk.Label(data[i]._name + "\n" + str(data[i]._array.shape))
frame.add(label)
hbox.add(frame)
#outputs
output_frame = gtk.Frame("Output")
output_hbox = gtk.HBox(True,4)
output_align = gtk.Alignment(1, 1, 1, 1)
output_align.set_padding(8, 8, 8, 8) #left padding:8
output_align.add(output_hbox)
output_frame.add(output_align)
# plots
plot_list = gtk.ListStore(gobject.TYPE_STRING,
gobject.TYPE_BOOLEAN)
plot_treeview = gtk.TreeView(plot_list)
# Add plots
for plt, name, use in self._options['all_plots']:
plot_list.append((name, use))
# Renderer for active toggle.
active_renderer = gtk.CellRendererToggle()
active_renderer.set_property('mode', gtk.CELL_RENDERER_MODE_ACTIVATABLE)
active_renderer.connect('toggled', toggled, plot_list)
active_column = gtk.TreeViewColumn('Use', active_renderer, active=1)
# Renderer for plot title.
title_renderer = gtk.CellRendererText()
title_renderer.set_property('mode', gtk.CELL_RENDERER_MODE_EDITABLE)
title_column = gtk.TreeViewColumn('Plot', title_renderer, text=0)
# Add columns to tree view.
plot_treeview.append_column(active_column)
plot_treeview.append_column(title_column)
## datasets
dataset_list = gtk.ListStore(gobject.TYPE_STRING,
gobject.TYPE_BOOLEAN)
dataset_treeview = gtk.TreeView(dataset_list)
# Add datasets
for dat, name, use in self._options['all_data']:
dataset_list.append((name, use))
# Renderer for active toggle.
active_renderer = gtk.CellRendererToggle()
active_renderer.set_property('mode', gtk.CELL_RENDERER_MODE_ACTIVATABLE)
active_renderer.connect('toggled', toggled, dataset_list)
active_column = gtk.TreeViewColumn('Use', active_renderer, active=1)
# Renderer for plot title.
title_renderer = gtk.CellRendererText()
title_renderer.set_property('mode', gtk.CELL_RENDERER_MODE_EDITABLE)
title_column = gtk.TreeViewColumn('Dataset', title_renderer, text=0)
# Add columns to tree view.
dataset_treeview.append_column(active_column)
dataset_treeview.append_column(title_column)
# add treeviews to output frame
output_hbox.add(plot_treeview)
output_hbox.add(dataset_treeview)
# vbox for input/spacer/output
vbox1 = gtk.VBox()
vbox1.add(input_frame)
vbox1.add(gtk.HSeparator())
vbox1.add(output_frame)
# add vbox to notebook
nb.append_page(vbox1, gtk.Label("I/O"))
self.vbox.add(nb)
#keep ref to liststores
self.dataset_list = dataset_list
self.plot_list = plot_list
def run(self):
self.vbox.show_all()
return gtk.Dialog.run(self)
def set_options(self, options):
self._options = options
def update_options(self, options):
self._options.update(options)
def set_output(self):
# get marked output data
out_data = [item[0] for name, mark in self.dataset_list for item in self._options['all_data'] if mark==True and name==item[1]]
# get marked plots
out_plots = [item[0] for name, mark in self.plot_list for item in self._options['all_plots'] if mark==True and name==item[1]]
# update options
self._options['out_data'] = out_data
self._options['out_plots'] = out_plots
def set_editable(self, editable):
self._editable = True
def set_data(self, data):
self._data = data
def get_data(self):
return self._data
def get_options(self):
return self._options
def toggled(renderer, path, store):
it = store.get_iter(path)
old_value = store.get_value(it, 1)
store.set_value(it, 1, not old_value)