|
From: <zk...@us...> - 2010-06-17 18:05:24
|
Revision: 686
http://pyphant.svn.sourceforge.net/pyphant/?rev=686&view=rev
Author: zklaus
Date: 2010-06-17 18:05:17 +0000 (Thu, 17 Jun 2010)
Log Message:
-----------
Merge branch 'master' into svn-trunk
* master:
Enh: Added possible masking of lamp peak to Absorption calculator.
Enh: More parameters for FCSource and DCSource
Enh: New keywords for DataContainer search
Modified Paths:
--------------
trunk/src/pyphant/pyphant/core/KnowledgeManager.py
trunk/src/pyphant/pyphant/core/Param.py
trunk/src/pyphant/pyphant/core/SQLiteWrapper.py
trunk/src/pyphant/pyphant/tests/TestKnowledgeManager.py
trunk/src/pyphant/pyphant/tests/TestSQLiteWrapper.py
trunk/src/pyphant/pyphant/wxgui2/paramvisualization/ListSelect.py
trunk/src/workers/OSC/OSC/OscAbsorption.py
trunk/src/workers/tools/tools/FCSource.py
trunk/src/workers/tools/tools/SCSource.py
trunk/src/workers/tools/tools/__init__.py
Added Paths:
-----------
trunk/src/workers/tools/tools/DCSource.py
Modified: trunk/src/pyphant/pyphant/core/KnowledgeManager.py
===================================================================
--- trunk/src/pyphant/pyphant/core/KnowledgeManager.py 2010-06-17 16:17:44 UTC (rev 685)
+++ trunk/src/pyphant/pyphant/core/KnowledgeManager.py 2010-06-17 18:05:17 UTC (rev 686)
@@ -435,52 +435,7 @@
def search(self, result_keys, search_dict={}, order_by=None,
order_asc=True, limit=-1, offset=0, distinct=False):
"""
- returns a list of tuples filled with values of the result keys
- matching the constraints of search_dict.
- Arguments:
- - result_keys: List (of length >= 1) of keys to include in the
- result tuples.
- - search_dict: Dict mapping keys to constraint values.
- Use empty dict for no constraints at all
- possible keys: values (used relational operator[, type constraint]):
- 'longname': str types (==)
- 'shortname': str types (==)
- 'machine': str types (==)
- 'creator: str types (==)
- 'date_from:' str types:
- YYYY[-MM[-DD[_hh:[mm:[ss[.s[s[s[s[s[s]]]]]]]]]]] (>=)
- 'date_to:' str types:
- YYYY[-MM[-DD[_hh:[mm:[ss[.s[s[s[s[s[s]]]]]]]]]]] (<)
- 'hash': str types (==)
- 'id': str types: emd5 (==)
- 'type': 'field' or 'sample' (==)
- 'attributes': dict mapping attr. key to attr. value (==)
- use (SQLiteWrapper instance).any_value
- or (KM instance).any_value to skip value check
- 'storage': str types (==)
- 'unit': PhysicalUnit or number or Quantity (==, FC only)
- 'dimensions': list of FC search dicts
- (see above definitions, FC only)
- 'columns': list of FC search dicts (see above definitions, SC only)
- - order_by: element of result_keys to order the results by
- or None for no special ordering
- - order_asc: whether to order ascending
- - limit: maximum number of results to return,
- set to -1 for no limit, default: -1
- - offset: number of search results to skip, default: 0
- - distinct: flag that indicates whether the result list
- should only contain distinct tuples.
- Usage Examples:
- Get list of all longnames:
- get_andsearch_result(['longname'], distinct=True)
- --> [('name1', ), ('name2', ), ...]
- Get id and shortname of all FCs that are parametrized by
- a time dimension along the primary axis:
- tunit = Quantity(1, 's')
- get_andsearch_result(['id', 'shortname'],
- {'type':'field',
- 'dimensions':[{'unit':tunit}]})
- --> [('emd5_1', 'name_1'), ('emd5_2', 'name_2'), ...]
+ see SQLiteWrapper.get_andsearch_result
"""
with SQLiteWrapper(self.dbase) as wrapper:
return wrapper.get_andsearch_result(
Modified: trunk/src/pyphant/pyphant/core/Param.py
===================================================================
--- trunk/src/pyphant/pyphant/core/Param.py 2010-06-17 16:17:44 UTC (rev 685)
+++ trunk/src/pyphant/pyphant/core/Param.py 2010-06-17 18:05:17 UTC (rev 686)
@@ -54,10 +54,10 @@
class PossibleValuesChangeExpected(object):
- def __init__(self, param, expectedPVs, update=False):
+ def __init__(self, param, expectedPVs, autoSelect=False):
self.param = param
self.expectedPVs = expectedPVs
- self.update = update
+ self.autoSelect = autoSelect
class ParamChangeRequested(object):
Modified: trunk/src/pyphant/pyphant/core/SQLiteWrapper.py
===================================================================
--- trunk/src/pyphant/pyphant/core/SQLiteWrapper.py 2010-06-17 16:17:44 UTC (rev 685)
+++ trunk/src/pyphant/pyphant/core/SQLiteWrapper.py 2010-06-17 18:05:17 UTC (rev 686)
@@ -187,11 +187,11 @@
one_to_one_search_keys = ['longname', 'shortname', 'machine',
'creator', 'hash', 'storage']
one_to_one_result_keys = one_to_one_search_keys + ['date', 'id', 'type']
- common_search_keys = one_to_one_search_keys + ['id', 'attributes',
- 'date_from', 'date_to']
+ common_search_keys = one_to_one_search_keys + \
+ ['id', 'attributes', 'date_from', 'date_to', 'col_of']
fc_search_keys = common_search_keys + ['unit', 'dimensions',
- 'dim_of', 'col_of']
- sc_search_keys = common_search_keys + ['columns']
+ 'dim_of', 'has_dim']
+ sc_search_keys = common_search_keys + ['columns', 'has_col']
sortable_keys = common_keys + ['storage', 'type']
any_value = AnyValue()
@@ -506,6 +506,59 @@
expr += ' AND '
return (expr[:-5] + ')', new_value, True)
+ def translate_parent_search(self, key, dc_search_dict, type):
+ id_str = replace_type('%s_id', type)
+ if dc_search_dict.has_key('type'):
+ check = dc_search_dict.pop('type')
+ else:
+ check = None
+ if key == 'col_of':
+ assert check in [None, 'sample']
+ parent_type = 'sample'
+ parent_id_str = 'sc_id'
+ child_id_str = 'fc_id'
+ table = 'km_sc_columns'
+ elif key == 'dim_of':
+ assert check in [None, 'field']
+ parent_type = 'field'
+ parent_id_str = 'fc_id'
+ child_id_str = 'dim_id'
+ table = 'km_fc_dimensions'
+ dc_query, dc_values = self.get_andsearch_query(
+ parent_type, ['id'], dc_search_dict, False)
+ expr = "(%s IN (SELECT %s FROM %s WHERE %s IN (%s)))" \
+ % (id_str, child_id_str, table, parent_id_str, dc_query)
+ return (expr, dc_values, True)
+
+ def translate_child_search(self, key, child_search_dict):
+ if key == 'has_col':
+ if child_search_dict.has_key('type'):
+ child_type = child_search_dict.pop('type')
+ child_qry, child_values = self.get_andsearch_query(
+ child_type, ['id'], child_search_dict, False)
+ else:
+ fc_child_qry, fc_child_values = self.get_andsearch_query(
+ 'field', ['id'], child_search_dict, False)
+ sc_child_qry, sc_child_values = self.get_andsearch_query(
+ 'sample', ['id'], child_search_dict, False)
+ child_qry = "%s UNION ALL %s"
+ child_qry = child_qry % (fc_child_qry, sc_child_qry)
+ child_values = fc_child_values + sc_child_values
+ id_str = 'sc_id'
+ child_id_str = 'fc_id'
+ table = 'km_sc_columns'
+ elif key == 'has_dim':
+ if child_search_dict.has_key('type'):
+ assert child_search_dict.pop('type') == 'field'
+ child_qry, child_values = self.get_andsearch_query(
+ 'field', ['id'], child_search_dict, False)
+ id_str = 'fc_id'
+ child_id_str = 'dim_id'
+ table = 'km_fc_dimensions'
+ expr = "(%s IN (SELECT %s FROM %s WHERE %s IN (%s)))" \
+ % (id_str, id_str, table, child_id_str, child_qry)
+ return (expr, child_values, True)
+
def translate_search_dict(self, type, search_dict):
where = ''
values = []
@@ -528,19 +581,19 @@
elif key == 'columns' or key == 'dimensions':
expr, value, extend = self.translate_list_search(
key, value, type)
- elif key == 'dim_of':
- expr = '(fc_id IN (SELECT dim_id FROM km_fc_dimensions '\
- 'WHERE fc_id=?))'
- elif key == 'col_of':
- expr = '(fc_id IN (SELECT fc_id FROM km_sc_columns '\
- 'WHERE sc_id=?))'
+ elif key in ['dim_of', 'col_of']:
+ expr, value, extend = self.translate_parent_search(
+ key, value, type)
+ elif key in ['has_dim', 'has_col']:
+ expr, value, extend = self.translate_child_search(
+ key, value)
else:
raise NotImplementedError(key)
where += expr + " AND "
- if extend:
+ if not extend:
+ values.append(value)
+ elif value is not None:
values.extend(value)
- else:
- values.append(value)
return where[:-5], values
def get_andsearch_query(self, type, result_keys, search_dict, distinct):
@@ -595,9 +648,11 @@
'unit': PhysicalUnit or number or Quantity (==, FC only)
'dimensions': list of FC search dicts
(see above definitions, FC only)
- 'dim_of': str types: emd5 of parent FC (==, FC only)
- 'col_of': str types: emd5 of parent SC (==, FC only)
+ 'dim_of': FC search dict (see above definitions, FC only)
+ 'col_of': SC search dict (see above definitions)
'columns': list of FC search dicts (see above definitions, SC only)
+ 'has_col': DC search dict (see above defs, SC only)
+ 'had_dim': FC search dict (see above definitions, FC only)
- order_by: element of result_keys to order the results by
or None for no special ordering
- order_asc: whether to order ascending
@@ -623,11 +678,8 @@
else:
assert order_by in result_keys
assert order_by in self.sortable_keys
- order = ' ORDER BY %s' % order_by
- if order_asc:
- order += ' ASC'
- else:
- order += ' DESC'
+ order = ' ORDER BY %s %s' \
+ % (order_by, {True:'ASC', False:'DESC'}[order_asc])
assert isinstance(limit, int)
assert isinstance(offset, int)
if not search_dict.has_key('type'):
@@ -665,7 +717,7 @@
query, values = self.get_andsearch_query(
search_dict['type'], result_keys, mod_search_dict, distinct)
query = "%s%s LIMIT %d OFFSET %d" % (query, order, limit, offset)
- if mod_search_dict != {}:
+ if values is not None and len(values) > 0:
self.cursor.execute(query, values)
else:
self.cursor.execute(query)
Modified: trunk/src/pyphant/pyphant/tests/TestKnowledgeManager.py
===================================================================
--- trunk/src/pyphant/pyphant/tests/TestKnowledgeManager.py 2010-06-17 16:17:44 UTC (rev 685)
+++ trunk/src/pyphant/pyphant/tests/TestKnowledgeManager.py 2010-06-17 18:05:17 UTC (rev 686)
@@ -45,7 +45,7 @@
CACHE_MAX_SIZE,
CACHE_MAX_NUMBER)
import pyphant.core.PyTablesPersister as ptp
-from pyphant.core.DataContainer import FieldContainer
+from pyphant.core.DataContainer import (FieldContainer, SampleContainer)
import numpy as N
import tables
import urllib
@@ -104,6 +104,21 @@
km_fc = km.getDataContainer(self._fc.id)
self.assertEqual(self._fc, km_fc)
+ def testSCwithSCColumn(self):
+ fc_child1 = FieldContainer(longname='fc_child1', data=N.ones((10, 10)))
+ fc_child2 = FieldContainer(longname='fc_child2', data=N.ones((20, 20)))
+ sc_child = SampleContainer(longname='sc_child', columns=[fc_child1])
+ sc_parent = SampleContainer(longname='sc_parent', columns=[sc_child,
+ fc_child2])
+ sc_parent.seal()
+ km = KnowledgeManager.getInstance()
+ km.registerDataContainer(sc_parent, temporary=True)
+ lnlist = km.search(['longname'], {'col_of':{'longname':'sc_parent'}})
+ lnlist = [entry[0] for entry in lnlist]
+ assert len(lnlist) == 2
+ assert 'fc_child2' in lnlist
+ assert 'sc_child' in lnlist
+
def testExceptions(self):
km = KnowledgeManager.getInstance()
#TODO:
Modified: trunk/src/pyphant/pyphant/tests/TestSQLiteWrapper.py
===================================================================
--- trunk/src/pyphant/pyphant/tests/TestSQLiteWrapper.py 2010-06-17 16:17:44 UTC (rev 685)
+++ trunk/src/pyphant/pyphant/tests/TestSQLiteWrapper.py 2010-06-17 18:05:17 UTC (rev 686)
@@ -193,10 +193,11 @@
rowwrapper = self.wrapper[id]
assert rowwrapper['dimensions'] == self.summary['dimensions']
search_result = self.wrapper.get_andsearch_result(
- ['longname'], {'type':'field', 'dim_of':id})
+ ['longname'], {'type':'field', 'dim_of':{'id':id}})
assert search_result == [(im_summary['longname'], )]
search_result = self.wrapper.get_andsearch_result(
- ['shortname'], {'type':'field', 'col_of':self.sc_summary['id']})
+ ['shortname'], {'type':'field',
+ 'col_of':{'id':self.sc_summary['id']}})
assert search_result == [(self.summary['shortname'], )]
Modified: trunk/src/pyphant/pyphant/wxgui2/paramvisualization/ListSelect.py
===================================================================
--- trunk/src/pyphant/pyphant/wxgui2/paramvisualization/ListSelect.py 2010-06-17 16:17:44 UTC (rev 685)
+++ trunk/src/pyphant/pyphant/wxgui2/paramvisualization/ListSelect.py 2010-06-17 18:05:17 UTC (rev 686)
@@ -73,29 +73,27 @@
self.Bind(EVT_CHOICE, self.onChoice)
self.param = param
self.possibleValues = param.possibleValues
- self.selected = param.value
param._eventDispatcher.registerExclusiveListener(
self.onPVCE, PossibleValuesChangeExpected)
- def setSelected(self, value):
- self._selected = value
-
- def getSelected(self):
- return self._selected
- selected = property(getSelected, setSelected)
-
def onPVCE(self, event):
- value = self.selected
+ value = self.data[self.GetStringSelection()]
assert value in event.expectedPVs, "%s not in %s" % (value,
event.expectedPVs)
self.data = dict([(str(val), val) for val in event.expectedPVs])
self.possibleValues = event.expectedPVs
self.SetItems(map(str, event.expectedPVs))
- self.SetValue(value)
+ if event.autoSelect and len(event.expectedPVs) == 2:
+ self.SetSelection(1)
+ pce = ParamChangeExpected(
+ self.param, expectedValue=self.data[self.GetStringSelection()])
+ pce.norefresh = True
+ self.param._eventDispatcher.dispatchEvent(pce)
+ else:
+ self.SetValue(value)
def onChoice(self, event):
event.Skip()
- self.selected = self.data[self.GetStringSelection()]
self.param._eventDispatcher.dispatchEvent(
ParamChangeExpected(
self.param, expectedValue=self.data[self.GetStringSelection()]))
Modified: trunk/src/workers/OSC/OSC/OscAbsorption.py
===================================================================
--- trunk/src/workers/OSC/OSC/OscAbsorption.py 2010-06-17 16:17:44 UTC (rev 685)
+++ trunk/src/workers/OSC/OSC/OscAbsorption.py 2010-06-17 18:05:17 UTC (rev 686)
@@ -80,7 +80,8 @@
name = "Compute Absorption"
_sockets = [("osc", Connectors.TYPE_ARRAY)]
- _params = [("clipping", "Clipping", 1, None)]
+ _params = [("clipping", "Clipping", 1, None),
+ ("mask_lamp", "Mask lamp", 0, None)]
def inithook(self):
self._logger = logging.getLogger("pyphant")
@@ -98,6 +99,21 @@
longname=u'absorption',
shortname=ur'\tilde{A}')
Abso.dimensions[-1] = I.dimensions[-1]
+ if self.paramMask_lamp.value==1:
+ dim = Abso.dimensions[-1]
+ minVal = quantities.Quantity('654nm')/dim.unit
+ maxVal = quantities.Quantity('660nm')/dim.unit
+ lamp_interval = numpy.intersect1d(numpy.argwhere(minVal < dim.data), numpy.argwhere(dim.data<maxVal))
+ min_index = lamp_interval[0]
+ max_index = lamp_interval[-1]
+ steps = max_index-min_index
+ for row in Abso.data:
+ min_value = row[min_index]
+ max_value = row[max_index]
+ step_size = (max_value-min_value)/steps
+ print min_value, max_value, step_size, steps, min_index, max_index
+ print (lamp_interval-min_index)*step_size
+ row[lamp_interval] = min_value + (lamp_interval-min_index)*step_size
Abso.seal()
return Abso
Copied: trunk/src/workers/tools/tools/DCSource.py (from rev 685, trunk/src/workers/tools/tools/FCSource.py)
===================================================================
--- trunk/src/workers/tools/tools/DCSource.py (rev 0)
+++ trunk/src/workers/tools/tools/DCSource.py 2010-06-17 18:05:17 UTC (rev 686)
@@ -0,0 +1,115 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2008, Rectorate of the University of Freiburg
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of the Freiburg Materials Research Center,
+# University of Freiburg nor the names of its contributors may be used to
+# endorse or promote products derived from this software without specific
+# prior written permission.
+#
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""
+This module provides a base class for FCSource and SCSource
+"""
+
+__id__ = "$Id$"
+__author__ = "$Author$"
+__version__ = "$Revision$"
+# $Source$
+
+from pyphant.core.KnowledgeManager import KnowledgeManager
+from pyphant.core.Param import (
+ ParamChangeExpected, PossibleValuesChangeExpected, ParamOverridden)
+ANYSTR = u"-- any --"
+
+
+class DCSource(object):
+ """
+ This is the base class for SCSource and FCSource. It has to
+ be subclassed before use.
+ """
+ def __init__(self, dc_type):
+ self.dc_type = dc_type
+ self.expectedValues = {}
+ for name, param in self._params.iteritems():
+ if name in ["name"]:
+ continue
+ param.registerListener(self.onPCE, ParamChangeExpected)
+ param.registerListener(self.onPO, ParamOverridden)
+ self.expectedValues[name] = param.value
+
+ def onPCE(self, event):
+ if event.expectedValue != self.expectedValues[event.param.name]:
+ self.expectedValues[event.param.name] = event.expectedValue
+ if not hasattr(event, 'norefresh'):
+ self.refreshParams(update=False)
+
+ def onPO(self, event):
+ self.expectedValues[event.param.name] = event.newValue
+
+ def getKeyValue(self, key, value, name):
+ if key in ['col_of', 'dim_of', 'has_dim', 'has_col']:
+ value = {'longname':value}
+ return (key, value)
+
+ def getSearchDict(self, name):
+ search_dict = {'type':self.dc_type}
+ search_dict.update(dict(
+ [self.getKeyValue(key, val, name) \
+ for key, val in self.expectedValues.iteritems() \
+ if key not in ['name', name] and val != ANYSTR]))
+ if name == 'dim_of':
+ search_dict = {'type':'field', 'has_dim':search_dict}
+ elif name == 'col_of':
+ search_dict = {'type':'sample', 'has_col':search_dict}
+ elif name == 'has_dim':
+ search_dict = {'type':'field', 'dim_of':search_dict}
+ elif name == 'has_col':
+ search_dict = {'col_of':search_dict}
+ return search_dict
+
+ def getResKey(self, name):
+ if name in ['col_of', 'dim_of', 'has_col', 'has_dim']:
+ return 'longname'
+ else:
+ return name
+
+ def refreshParams(self, subscriber=None, update=True):
+ if update:
+ self.expectedValues = dict(
+ [(name, param.value) for name, param \
+ in self._params.iteritems() if name != 'name'])
+ kmanager = KnowledgeManager.getInstance()
+ for name, param in self._params.iteritems():
+ if name == 'name':
+ continue
+ search_dict = self.getSearchDict(name)
+ newEVs = [[ANYSTR]]
+ newEVs.extend(kmanager.search(
+ [self.getResKey(name)], search_dict=search_dict, distinct=True))
+ newEVs = [newEV[0] for newEV in newEVs]
+ param._eventDispatcher.dispatchEvent(
+ PossibleValuesChangeExpected(param, newEVs, autoSelect=True))
+ if update:
+ param.possibleValues = newEVs
Modified: trunk/src/workers/tools/tools/FCSource.py
===================================================================
--- trunk/src/workers/tools/tools/FCSource.py 2010-06-17 16:17:44 UTC (rev 685)
+++ trunk/src/workers/tools/tools/FCSource.py 2010-06-17 18:05:17 UTC (rev 686)
@@ -39,16 +39,12 @@
__version__ = "$Revision$"
# $Source$
-from pyphant.core import (Worker, Connectors,
- Param)
+from pyphant.core import (Worker, Connectors, Param)
+from DCSource import (ANYSTR, DCSource)
from pyphant.core.KnowledgeManager import KnowledgeManager
-from pyphant.core.Param import (
- ParamChangeExpected, PossibleValuesChangeExpected, ParamOverridden)
from pyphant.core.Connectors import SUBTYPE_INSTANT
-ANYSTR = u"-- any --"
-
-class FCSource(Worker.Worker):
+class FCSource(DCSource, Worker.Worker):
"""
This worker provides instantly updated dropdown lists for selecting
a FieldContainer from the KnowledgeManager.
@@ -57,55 +53,23 @@
VERSION = 1
REVISION = "$Revision$"[11:-1]
name = "FieldContainer"
- _params = [("machine", u"Machine", [ANYSTR], SUBTYPE_INSTANT),
- ("creator", u"Creator", [ANYSTR], SUBTYPE_INSTANT),
- ("longname", u"Longname", [ANYSTR], SUBTYPE_INSTANT),
- ("shortname", u"Shortname", [ANYSTR], SUBTYPE_INSTANT),
- ("id", u"emd5", [ANYSTR], SUBTYPE_INSTANT)]
+ _params = [("machine", u"machine ==", [ANYSTR], SUBTYPE_INSTANT),
+ ("creator", u"and creator ==", [ANYSTR], SUBTYPE_INSTANT),
+ ("longname", u"and longname ==", [ANYSTR], SUBTYPE_INSTANT),
+ ("shortname", u"and shortname ==", [ANYSTR], SUBTYPE_INSTANT),
+ ("unit", u"and unit is compatible to", [ANYSTR],
+ SUBTYPE_INSTANT),
+ ("has_dim", u"and has dimension", [ANYSTR], SUBTYPE_INSTANT),
+ ("col_of", u"and is column of", [ANYSTR], SUBTYPE_INSTANT),
+ ("dim_of", u"and is dimension of", [ANYSTR], SUBTYPE_INSTANT),
+ ("id", u"and emd5 ==", [ANYSTR], SUBTYPE_INSTANT)]
def __init__(self, *args, **kargs):
Worker.Worker.__init__(self, *args, **kargs)
- self.expectedValues = {}
- for name, param in self._params.iteritems():
- if name in ["name"]:
- continue
- param.registerListener(self.onPCE, ParamChangeExpected)
- param.registerListener(self.onPO, ParamOverridden)
- self.expectedValues[name] = param.value
+ DCSource.__init__(self, 'field')
- def onPCE(self, event):
- if event.expectedValue != self.expectedValues[event.param.name]:
- self.expectedValues[event.param.name] = event.expectedValue
- self.refreshParams(update=False)
-
- def onPO(self, event):
- self.expectedValues[event.param.name] = event.newValue
-
- def refreshParams(self, subscriber=None, update=True):
- if update:
- self.expectedValues = dict(
- [(name, param.value) for name, param \
- in self._params.iteritems() if name != 'name'])
- kmanager = KnowledgeManager.getInstance()
- for name, param in self._params.iteritems():
- if name == 'name':
- continue
- search_dict = {'type':'field'}
- update_dict = dict(
- [(key, val) for key, val in self.expectedValues.iteritems() \
- if key not in ['name', name] and val != ANYSTR])
- search_dict.update(update_dict)
- newEVs = [[ANYSTR]]
- newEVs.extend(kmanager.search([name], search_dict=search_dict,
- distinct=True))
- newEVs = [newEV[0] for newEV in newEVs]
- param._eventDispatcher.dispatchEvent(
- PossibleValuesChangeExpected(param, newEVs))
- if update:
- param.possibleValues = newEVs
-
@Worker.plug(Connectors.TYPE_IMAGE)
- def getDataContainer(self, subscriber = 0):
+ def getFieldContainer(self, subscriber = 0):
emd5 = self.paramId.value
kmanager = KnowledgeManager.getInstance()
return kmanager.getDataContainer(emd5)
Modified: trunk/src/workers/tools/tools/SCSource.py
===================================================================
--- trunk/src/workers/tools/tools/SCSource.py 2010-06-17 16:17:44 UTC (rev 685)
+++ trunk/src/workers/tools/tools/SCSource.py 2010-06-17 18:05:17 UTC (rev 686)
@@ -39,16 +39,12 @@
__version__ = "$Revision$"
# $Source$
-from pyphant.core import (Worker, Connectors,
- Param)
+from pyphant.core import (Worker, Connectors, Param)
+from DCSource import (ANYSTR, DCSource)
from pyphant.core.KnowledgeManager import KnowledgeManager
-from pyphant.core.Param import (
- ParamChangeExpected, PossibleValuesChangeExpected, ParamOverridden)
from pyphant.core.Connectors import SUBTYPE_INSTANT
-ANYSTR = u"-- any --"
-
-class SCSource(Worker.Worker):
+class SCSource(DCSource, Worker.Worker):
"""
This worker provides instantly updated dropdown lists for selecting
a SampleContainer from the KnowledgeManager.
@@ -57,55 +53,20 @@
VERSION = 1
REVISION = "$Revision$"[11:-1]
name = "SampleContainer"
- _params = [("machine", u"Machine", [ANYSTR], SUBTYPE_INSTANT),
- ("creator", u"Creator", [ANYSTR], SUBTYPE_INSTANT),
- ("longname", u"Longname", [ANYSTR], SUBTYPE_INSTANT),
- ("shortname", u"Shortname", [ANYSTR], SUBTYPE_INSTANT),
- ("id", u"emd5", [ANYSTR], SUBTYPE_INSTANT)]
+ _params = [("machine", u"machine ==", [ANYSTR], SUBTYPE_INSTANT),
+ ("creator", u"and creator ==", [ANYSTR], SUBTYPE_INSTANT),
+ ("longname", u"and longname ==", [ANYSTR], SUBTYPE_INSTANT),
+ ("shortname", u"and shortname ==", [ANYSTR], SUBTYPE_INSTANT),
+ ("has_col", u"and has column", [ANYSTR], SUBTYPE_INSTANT),
+ ("col_of", u"and is column of", [ANYSTR], SUBTYPE_INSTANT),
+ ("id", u"and emd5 ==", [ANYSTR], SUBTYPE_INSTANT)]
def __init__(self, *args, **kargs):
Worker.Worker.__init__(self, *args, **kargs)
- self.expectedValues = {}
- for name, param in self._params.iteritems():
- if name in ["name"]:
- continue
- param.registerListener(self.onPCE, ParamChangeExpected)
- param.registerListener(self.onPO, ParamOverridden)
- self.expectedValues[name] = param.value
+ DCSource.__init__(self, 'sample')
- def onPCE(self, event):
- if event.expectedValue != self.expectedValues[event.param.name]:
- self.expectedValues[event.param.name] = event.expectedValue
- self.refreshParams(update=False)
-
- def onPO(self, event):
- self.expectedValues[event.param.name] = event.newValue
-
- def refreshParams(self, subscriber=None, update=True):
- if update:
- self.expectedValues = dict(
- [(name, param.value) for name, param \
- in self._params.iteritems() if name != 'name'])
- kmanager = KnowledgeManager.getInstance()
- for name, param in self._params.iteritems():
- if name == 'name':
- continue
- search_dict = {'type':'sample'}
- update_dict = dict(
- [(key, val) for key, val in self.expectedValues.iteritems() \
- if key not in ['name', name] and val != ANYSTR])
- search_dict.update(update_dict)
- newEVs = [[ANYSTR]]
- newEVs.extend(kmanager.search([name], search_dict=search_dict,
- distinct=True))
- newEVs = [newEV[0] for newEV in newEVs]
- param._eventDispatcher.dispatchEvent(
- PossibleValuesChangeExpected(param, newEVs))
- if update:
- param.possibleValues = newEVs
-
@Worker.plug(Connectors.TYPE_ARRAY)
- def getDataContainer(self, subscriber = 0):
+ def getSampleContainer(self, subscriber = 0):
emd5 = self.paramId.value
kmanager = KnowledgeManager.getInstance()
return kmanager.getDataContainer(emd5)
Modified: trunk/src/workers/tools/tools/__init__.py
===================================================================
--- trunk/src/workers/tools/tools/__init__.py 2010-06-17 16:17:44 UTC (rev 685)
+++ trunk/src/workers/tools/tools/__init__.py 2010-06-17 18:05:17 UTC (rev 686)
@@ -40,7 +40,7 @@
# $Source$
workers=[
- "Emd5Src",
+ #"Emd5Src",
"FCSource",
"SCSource"
]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|