def __init__(self, src): self.src = src self.display = '' self.icon = Qt.QIcon() self.ok = True self._dbCache = taurus.Authority() self.setSrc(src)
def get_readwrite_models(expressions, limit=1000): ''' All devices matching expressions must be obtained. For each device only the good attributes are read. ''' # self.debug( 'In TaurusGrid.get_all_models(%s:"%s") ...' % (type(expressions),expressions)) if isinstance(expressions, string_types): if any(re.match(s, expressions) for s in ('\{.*\}', '\(.*\)', '\[.*\]')): # self.trace( 'evaluating expressions ....') expressions = list(eval(expressions)) else: # self.trace( 'expressions as string separated by commas ...') expressions = expressions.split(',') elif isinstance(expressions, (list, tuple, dict)): expressions = list(str(e) for e in expressions) taurus_db = taurus.Authority() # WHAAAT???? At least check instances... if 'SimulationAuthority' in str(type(taurus_db)): models = expressions else: all_devs = taurus_db.get_device_exported('*') models = [] for exp in expressions: exp = str(exp) devs = [] targets = [] if exp.count('/') == 3: device, attribute = exp.rsplit('/', 1) else: device, attribute = exp, 'State' if any(c in device for c in '.*[]()+?'): if '*' in device and '.*' not in device: device = device.replace('*', '.*') devs = [s for s in all_devs if re_match_low(device, s)] else: devs = [device] for dev in devs: if any(c in attribute for c in '.*[]()+?'): if '*' in attribute and '.*' not in attribute: attribute = attribute.replace('*', '.*') try: taurus_dp = taurus.core.taurusmanager.TaurusManager().getFactory()().getDevice( dev) attrs = [att.name for att in taurus_dp.attribute_list_query( ) if re_match_low(attribute, att.name) and att.isReadOnly()] targets.extend(dev + '/' + att for att in attrs) except Exception as e: pass else: targets.append(dev + '/' + attribute) models.extend(targets) models = models[:limit] return models
def TaurusPanelMain(): '''A launcher for TaurusPanel.''' # NOTE: DON'T PUT TEST CODE HERE. # THIS IS CALLED FROM THE LAUNCHER SCRIPT (<taurus>/scripts/tauruspanel) from taurus.qt.qtgui.application import TaurusApplication from taurus.core.util import argparse import sys parser = argparse.get_taurus_parser() parser.set_usage("%prog [options] [devname]") parser.set_description("Taurus Application inspired in Jive and Atk Panel") app = TaurusApplication(cmd_line_parser=parser, app_name="tauruspanel", app_version=taurus.Release.version) args = app.get_command_line_args() options = app.get_command_line_options() w = TaurusDevPanel() if options.tango_host is None: options.tango_host = taurus.Authority().getNormalName() w.setTangoHost(options.tango_host) if len(args) == 1: w.setDevice(args[0]) w.show() sys.exit(app.exec_())
def TaurusPanelMain(): """A launcher for TaurusPanel.""" from taurus.qt.qtgui.panel import TaurusDevPanel parser = argparse.get_taurus_parser() parser.set_usage("%prog [options] [devname]") parser.set_description("Taurus Application inspired in Jive and Atk Panel") app = TaurusApplication(cmd_line_parser=parser, app_name="tauruspanel", app_version=Release.version) args = app.get_command_line_args() options = app.get_command_line_options() w = TaurusDevPanel() if options.tango_host is None: options.tango_host = taurus.Authority().getNormalName() w.setTangoHost(options.tango_host) if len(args) == 1: w.setDevice(args[0]) w.show() sys.exit(app.exec_())
def demo(): """Table panels""" import taurus db = taurus.Authority() host = db.getNormalName() w = main_TaurusDbTableWidget(host, TaurusElementType.Device) return w
def get_device_for_alias(alias): db = taurus.Authority() try: return db.get_device_alias(alias) except Exception, e: if 'no device found' in str(e).lower(): return None return None # raise e
def __init__(self, src): self.src = src self.display = '' self.icon = Qt.QIcon() self.ok = True self._attrnamevalidator = ATTRNAMEVALIDATOR self._dbCache = taurus.Authority() self.setSrc(src)
def get_device_for_alias(alias): # TODO: Use validators instead db = taurus.Authority() try: return db.get_device_alias(alias) except Exception as e: if 'no device found' in str(e).lower(): return None return None # raise e
def get_alias_for_device(dev): db = taurus.Authority() try: # .get_database_device().DbGetDeviceAlias(dev) result = db.get_alias(dev) return result except Exception, e: if 'no alias found' in str(e).lower(): return None return None # raise e
def __init__(self, parent=None, curves=None, showXcol=True): super(CurveItemConfDlg, self).__init__(parent) self.loadUi() self._showXcol = showXcol if curves is None: curves = [CurveItemConf()] # add the NeXusWidget if extra_nexus is available try: from taurus.qt.qtgui.extra_nexus import TaurusNeXusBrowser nexusWidget = TaurusNeXusBrowser() self.ui.tabWidget.addTab(nexusWidget, 'NeXus') except: import taurus.core.util.log _logger = taurus.core.util.log.Logger('CurveItemConfDlg') _logger.warning('TaurusNeXusBrowser not available') self.traceback() self.ui.tangoTree.setButtonsPos(Qt.Qt.RightToolBarArea) # @todo: The action for this button is not yet implemented self.ui.reloadBT.setEnabled(False) self.model = TaurusCurveItemTableModel(curves) table = self.ui.curvesTable table.setModel(self.model) table.setColumnHidden(X, not self._showXcol) # #adjust the column widths # table.resizeColumnsToContents() # availableSpace = table.viewport().width() # for col in xrange(self.model.columnCount()): # availableSpace -= table.columnWidth(col) # if availableSpace > 0: # extraSpace = availableSpace / self.model.columnCount() # for col in xrange(self.model.columnCount()): # table.setColumnWidth(col, table.columnWidth(col)+extraSpace) # host import taurus # @todo: I get "UnboundLocalError: local variable 'taurus' referenced before assignment" if I don't import taurus again here ???? host = taurus.Authority().getNormalName() self.ui.tangoTree.setModel(host) # Connections self.connect(self.ui.applyBT, Qt.SIGNAL("clicked()"), self.onApply) self.connect(self.ui.reloadBT, Qt.SIGNAL("clicked()"), self.onReload) self.connect(self.ui.cancelBT, Qt.SIGNAL("clicked()"), self.close) self.connect(self.ui.tangoTree, Qt.SIGNAL("addModels"), self.onModelsAdded) self.connect(self.ui.curvesTable, Qt.SIGNAL("customContextMenuRequested(QPoint)"), self.onTableContextMenu)
def getAuthority(self, resources, uri, expected_attr_uri): """ Helper for test the getAuthority method :param resources: list of tuple (map, priority) :param uri: res scheme uri. :param expected_attr_uri: a scheme uri """ self._load(resources) expected_auth = taurus.Authority(expected_attr_uri) res_auth = self.resfactory.getAuthority(uri) msg = 'Authorities are different, expected %s, got %s' % ( expected_auth, res_auth) self.assertIs(expected_auth, res_auth, msg)
def get_object(self, name=None, klass=None): '''check if Authority returns the expected type''' if klass is None: klass = TaurusAuthority manager = taurus.Manager() scheme = manager.getScheme(name) supportedSchemes = manager.getPlugins().keys() if scheme not in supportedSchemes: self.skipTest('"%s" scheme not supported' % scheme) a = taurus.Authority(name) msg = ('%s("%s") is not an instance of %s (it is %s)' % (taurus.Authority.__name__, name, klass.__name__, a.__class__.__name__)) self.assertTrue(isinstance(a, klass), msg)
def setModel(self, model): '''reimplemented from :class:`TaurusBaseWidget`''' TaurusBaseWidget.setModel(self, model) self._reloadConf(force=True) # set the model of some child widgets door = self.getModelObj() if door is None: return # @todo: get the tghost from the door model instead tghost = taurus.Authority().getNormalName() msname = door.macro_server.getFullName() self.ui.taurusModelTree.setModel(tghost) self.ui.sardanaElementTree.setModel(msname) door.experimentConfigurationChanged.connect( self._experimentConfigurationChanged)
def __retriveMacroServersFromDB(self): ms_stateIcons = [] db = taurus.Authority() macroServerList = db.getTangoDB().get_device_name('*', 'MacroServer') for macroServer in macroServerList: #state = Device(macroServer).getState() state = None try: ms_name = "{0}/{1}".format(db.getNormalName(), macroServer) state = PyTango.DeviceProxy(ms_name).state() except: pass icon = None if state == PyTango.DevState.ON: icon = Qt.QIcon("leds_images24:ledgreen.png") elif state == PyTango.DevState.FAULT: icon = Qt.QIcon("leds_images24:ledred.png") elif state is None: icon = Qt.QIcon("leds_images24:ledredoff.png") ms_stateIcons.append((macroServer, icon)) return ms_stateIcons
def get_matching_devices(expressions, limit=0, exported=False): """ Searches for devices matching expressions, if exported is True only running devices are returned """ db = taurus.Authority() all_devs = [s.lower() for s in db.get_device_name('*', '*')] # This code is used to get data from multiples hosts #if any(not fun.matchCl(rehost,expr) for expr in expressions): all_devs.extend(get_all_devices(exported)) # for expr in expressions: #m = fun.matchCl(rehost,expr) # if m: #host = m.groups()[0] # print 'get_matching_devices(%s): getting %s devices ...'%(expr,host) #odb = PyTango.Database(*host.split(':')) #all_devs.extend('%s/%s'%(host,d) for d in odb.get_device_name('*','*')) result = [e for e in expressions if e.lower() in all_devs] expressions = [extend_regexp(e) for e in expressions if e not in result] result.extend( filter( lambda d: any(matchCl(extend_regexp(e), d) for e in expressions), all_devs)) return result
def get_all_models(expressions, limit=1000): ''' All devices matching expressions must be obtained. For each device only the good attributes are read. It practically equals to fandango.get_matching_attributes; check which is better! Move this method to taurus.core.tango.search ''' # print( 'In TaurusGrid.get_all_models(%s:"%s") ...' % (type(expressions),expressions)) if isinstance(expressions, string_types): # if any(re.match(s,expressions) for s in ('\{.*\}','\(.*\)','\[.*\]')): ##self.debug( 'evaluating expressions ....') # expressions = list(eval(expressions)) # else: ##self.debug( 'expressions as string separated by commas ...') expressions = expressions.split(',') elif isinstance(expressions, (list, tuple, dict)): # self.debug( 'expressions converted from list ...') expressions = list(str(e) for e in expressions) # self.debug( 'In TaurusGrid.get_all_models(%s:"%s") ...' % (type(expressions),expressions)) taurus_db = taurus.Authority() # taurus_db = taurus.Authority(os.environ['TANGO_HOST']) # WHAAAAAAT????? Someone should get beaten for this line if 'SimulationAuthority' in str(type(taurus_db)): # self.trace( 'Using a simulated database ...') models = expressions else: all_devs = taurus_db.get_device_exported('*') models = [] for exp in expressions: # self.trace( 'evaluating exp = "%s"' % exp) exp = str(exp) devs = [] targets = [] if exp.count('/') == 3: device, attribute = exp.rsplit('/', 1) else: device, attribute = exp, 'State' if any(c in device for c in '.*[]()+?'): if '*' in device and '.*' not in device: device = device.replace('*', '.*') devs = [s for s in all_devs if re_match_low(device, s)] else: devs = [device] # self.trace( 'TaurusGrid.get_all_models(): devices matched by %s / %s are %d:' % (device,attribute,len(devs))) # self.debug( '%s' % (devs)) for dev in devs: if any(c in attribute for c in '.*[]()+?'): if '*' in attribute and '.*' not in attribute: attribute = attribute.replace('*', '.*') try: # taurus_dp = taurus.core.taurusdevice.TaurusDevice(dev) taurus_dp = taurus.core.taurusmanager.TaurusManager( ).getFactory()().getDevice(dev) # self.debug( "taurus_dp = %s"%taurus_dp.getFullName()) attrs = [ att.name for att in taurus_dp.attribute_list_query() if re_match_low(attribute, att.name) ] targets.extend(dev + '/' + att for att in attrs) except Exception as e: # self.warning( 'ERROR! TaurusGrid.get_all_models(): Unable to get attributes for device %s: %s' % (dev,str(e))) pass else: targets.append(dev + '/' + attribute) # print 'TaurusGrid.get_all_models(): targets added by %s are: %s' # % (exp,targets) models.extend(targets) models = models[:limit] # print( 'Out of TaurusGrid.get_all_models(...)') return models
def setModel(self, model): TaurusModelSelectorItem.setModel(self, model) self._arch_auth = taurus.Authority(model) # Fill schemes schemas = self._arch_auth.getSchemas() self.ui.schema_comboBox.addItems(schemas)
def get_alias_dict(exp='*'): tango = taurus.Authority() return dict((k, tango.get_device_alias(k)) for k in tango.get_device_alias_list(exp))