コード例 #1
0
ファイル: taurusdevicepanel.py プロジェクト: tcsgmrt/taurus
 def get_comms_form(self, device, form=None, parent=None):
     self.trace('In TaurusDevicePanel.get_comms_form(%s)' % device)
     params = get_regexp_dict(TaurusDevicePanel._command_filter, device, [])
     # If filters are defined only listed devices will show commands
     if TaurusDevicePanel._command_filter and not params:
         self.debug(
             'TaurusDevicePanel.get_comms_form(%s): By default an unknown device type will display no commands'
             % device)
         return None
     if not form:
         form = TaurusCommandsForm(parent)
     elif hasattr(form, 'setModel'):
         form.setModel('')
     try:
         form.setModel(device)
         if params:
             form.setSortKey(lambda x, vals=[s[0].lower() for s in params]:
                             vals.index(x.cmd_name.lower())
                             if str(x.cmd_name).lower() in vals else 100)
             form.setViewFilters([
                 lambda c: str(c.cmd_name).lower() not in
                 ('state', 'status') and any(
                     searchCl(s[0], str(c.cmd_name)) for s in params)
             ])
             form.setDefaultParameters(
                 dict((k, v)
                      for k, v in (params if not hasattr(params, 'items')
                                   else params.items()) if v))
         for wid in form._cmdWidgets:
             if not hasattr(wid, 'getCommand') or not hasattr(
                     wid, 'setDangerMessage'):
                 continue
             if re.match('.*(on|off|init|open|close).*',
                         str(wid.getCommand().lower())):
                 wid.setDangerMessage(
                     'This action may affect other systems!')
         # form._splitter.setStretchFactor(1,70)
         # form._splitter.setStretchFactor(0,30)
         form._splitter.setSizes([80, 20])
     except Exception:
         self.warning(
             'Unable to setModel for TaurusDevicePanel.comms_form!!: %s' %
             traceback.format_exc())
     return form
コード例 #2
0
ファイル: taurusdevicepanel.py プロジェクト: cmft/taurus
 def get_comms_form(self, device, form=None, parent=None):
     self.trace('In TaurusDevicePanel.get_comms_form(%s)' % device)
     params = get_regexp_dict(TaurusDevicePanel._command_filter, device, [])
     # If filters are defined only listed devices will show commands
     if TaurusDevicePanel._command_filter and not params:
         self.debug(
             'TaurusDevicePanel.get_comms_form(%s): By default an unknown device type will display no commands' % device)
         return None
     if not form:
         form = TaurusCommandsForm(parent)
     elif hasattr(form, 'setModel'):
         form.setModel('')
     try:
         form.setModel(device)
         if params:
             form.setSortKey(lambda x, vals=[s[0].lower() for s in params]: vals.index(
                 x.cmd_name.lower()) if str(x.cmd_name).lower() in vals else 100)
             form.setViewFilters([lambda c: str(c.cmd_name).lower() not in (
                 'state', 'status') and any(searchCl(s[0], str(c.cmd_name)) for s in params)])
             form.setDefaultParameters(dict((k, v) for k, v in (
                 params if not hasattr(params, 'items') else params.items()) if v))
         for wid in form._cmdWidgets:
             if not hasattr(wid, 'getCommand') or not hasattr(wid, 'setDangerMessage'):
                 continue
             if re.match('.*(on|off|init|open|close).*', str(wid.getCommand().lower())):
                 wid.setDangerMessage(
                     'This action may affect other systems!')
         # form._splitter.setStretchFactor(1,70)
         # form._splitter.setStretchFactor(0,30)
         form._splitter.setSizes([80, 20])
     except Exception:
         self.warning(
             'Unable to setModel for TaurusDevicePanel.comms_form!!: %s' % traceback.format_exc())
     return form