当前位置: 首页>>代码示例>>Python>>正文


Python Backend.set_cfg方法代码示例

本文整理汇总了Python中backend.Backend.set_cfg方法的典型用法代码示例。如果您正苦于以下问题:Python Backend.set_cfg方法的具体用法?Python Backend.set_cfg怎么用?Python Backend.set_cfg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在backend.Backend的用法示例。


在下文中一共展示了Backend.set_cfg方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SysAlertsPlugin

# 需要导入模块: from backend import Backend [as 别名]
# 或者: from backend.Backend import set_cfg [as 别名]

#.........这里部分代码省略.........
                ),
            ))

        if self._settings:
            ui.append('main', self.get_ui_settings())

        if self._configuring:
            ui.append('main', getattr(self, 'get_ui_cfg_%s'%self._configuring.type)(self._configuring))

        return ui

    def get_ui_settings(self):
        ui = self.app.inflate('sysalerts:settings')

        for m in self.backend.list_meters():
            for v in self.backend.list_variated(m):
                ui.append('list', UI.DTR(
                    UI.DTD(
                        UI.Label(text=v.name, bold=True),
                        UI.Label(text=v.text),
                    ),
                    UI.DTD(
                        UI.TipIcon(
                            iconfont="gen-pencil-2",
                            id='config/%s/%s'%(m.plugin_id,self.enc_file(v.variant)),
                            text='Configure',
                        ),
                        UI.TipIcon(
                            iconfont="gen-cancel-circle",
                            id='disable/%s/%s'%(m.plugin_id,self.enc_file(v.variant)),
                            text='Disable',
                        ) if self.backend.has_cfg(m.plugin_id,v.variant) else None,
                    ),
                ))
        return ui

    def enc_file(self, path):
        path = path.replace('//','/')
        return base64.b64encode(path, altchars='+-').replace('=', '*')

    def dec_file(self, b64):
        return base64.b64decode(b64.replace('*', '='), altchars='+-')

    @event('button/click')
    def on_click(self, event, params, vars=None):
        if params[0] == 'btnRefresh':
            self.mon.refresh()
        if params[0] == 'btnSettings':
            self._settings = True
        if params[0] == 'config':
            self._configuring = self.backend.get_meter(params[1], self.dec_file(params[2]))
        if params[0] == 'disable':
            self.backend.del_cfg(params[1], self.dec_file(params[2]))
            self.mon.refresh()

    @event('dialog/submit')
    def on_submit(self, event, params, vars=None):
        if params[0] == 'dlgSettings':
            self._settings = False
        if params[0] == 'dlgConfigure':
            if vars.getvalue('action', None) == 'OK':
                try:
                    getattr(self, 'apply_cfg_%s'%(self._configuring.type))(self._configuring, vars)
                except:
                    self.app.log.error('Invalid meter configuration')
                self.mon.refresh()
            self._configuring = None

    def get_ui_cfg_binary(self, cls):
        ui = self.app.inflate('sysalerts:cfg-binary')
        t = self.backend.get_cfg(cls.plugin_id, cls.variant).setdefault('good_state', True)
        ui.find('r-true').set('checked', t)
        ui.find('r-false').set('checked', not t)
        return ui

    def get_ui_cfg_decimal(self, cls):
        ui = self.app.inflate('sysalerts:cfg-decimal')
        c = self.backend.get_cfg(cls.plugin_id, cls.variant)
        ui.find('limit_susp').set('value', str(c.setdefault('limit_susp', 33.0)))
        ui.find('limit_dang').set('value', str(c.setdefault('limit_dang', 66.0)))
        return ui

    def get_ui_cfg_linear(self, cls):
        ui = self.app.inflate('sysalerts:cfg-linear')
        c = self.backend.get_cfg(cls.plugin_id, cls.variant)
        ui.find('limit_susp').set('value', str(c.setdefault('limit_susp', 33.0)))
        ui.find('limit_dang').set('value', str(c.setdefault('limit_dang', 66.0)))
        ui.find('max').set('text', 'Min: %.2f, max: %.2f'%(cls.get_min(), cls.get_max()))
        return ui

    def apply_cfg_binary(self, cls, vars):
        self.backend.set_cfg(cls.plugin_id, cls.variant, {'good_state': eval(vars.getvalue('val', 'True'))})

    def apply_cfg_decimal(self, cls, vars):
        self.backend.set_cfg(cls.plugin_id, cls.variant, {
            'limit_susp': float(vars.getvalue('lim_susp', True)),
            'limit_dang': float(vars.getvalue('lim_dang', True)),
        })

    apply_cfg_linear = apply_cfg_decimal
开发者ID:Bugsbane,项目名称:genesis,代码行数:104,代码来源:main.py

示例2: HealthPlugin

# 需要导入模块: from backend import Backend [as 别名]
# 或者: from backend.Backend import set_cfg [as 别名]

#.........这里部分代码省略.........
                ),
                UI.DTD(
                    UI.TipIcon(
                        icon='/dl/core/ui/stock/edit.png',
                        id='config/%s/%s'%(m.plugin_id,m.variant),
                        text='Configurar',
                    ),
                ),
            ))

        if self._settings:
            ui.append('main', self.get_ui_settings())

        if self._configuring:
            ui.append('main', getattr(self, 'get_ui_cfg_%s'%self._configuring.type)(self._configuring))

        return ui

    def get_ui_settings(self):
        ui = self.app.inflate('health:settings')

        for m in self.backend.list_meters():
            for v in self.backend.list_variated(m):
                ui.append('list', UI.DTR(
                    UI.DTD(
                        UI.Label(text=v.name, bold=True),
                        UI.Label(text=v.text),
                    ),
                    UI.DTD(
                        UI.TipIcon(
                            icon='/dl/core/ui/stock/edit.png',
                            id='config/%s/%s'%(m.plugin_id,v.variant),
                            text='Configure',
                        ),
                        UI.TipIcon(
                            icon='/dl/core/ui/stock/delete.png',
                            id='disable/%s/%s'%(m.plugin_id,v.variant),
                            text='Disable',
                        ) if self.backend.has_cfg(m.plugin_id,v.variant) else None,
                    ),
                ))
        return ui

    @event('button/click')
    def on_click(self, event, params, vars=None):
        if params[0] == 'btnRefresh':
            self.mon.refresh()
        if params[0] == 'btnSettings':
            self._settings = True
        if params[0] == 'config':
            self._configuring = self.backend.get_meter(*params[1:])
        if params[0] == 'disable':
            self.backend.del_cfg(*params[1:])
            self.mon.refresh()

    @event('dialog/submit')
    def on_submit(self, event, params, vars=None):
        if params[0] == 'dlgSettings':
            self._settings = False
        if params[0] == 'dlgConfigure':
            if vars.getvalue('action', None) == 'OK':
                try:
                    getattr(self, 'apply_cfg_%s'%(self._configuring.type))(self._configuring, vars)
                except:
                    self.app.log.error('Invalid meter configuration')
                self.mon.refresh()
            self._configuring = None

    def get_ui_cfg_binary(self, cls):
        ui = self.app.inflate('health:cfg-binary')
        t = self.backend.get_cfg(cls.plugin_id, cls.variant).setdefault('good_state', True)
        ui.find('r-true').set('checked', t)
        ui.find('r-false').set('checked', not t)
        return ui

    def get_ui_cfg_decimal(self, cls):
        ui = self.app.inflate('health:cfg-decimal')
        c = self.backend.get_cfg(cls.plugin_id, cls.variant)
        ui.find('limit_susp').set('value', str(c.setdefault('limit_susp', 33.0)))
        ui.find('limit_dang').set('value', str(c.setdefault('limit_dang', 66.0)))
        return ui

    def get_ui_cfg_linear(self, cls):
        ui = self.app.inflate('health:cfg-linear')
        c = self.backend.get_cfg(cls.plugin_id, cls.variant)
        ui.find('limit_susp').set('value', str(c.setdefault('limit_susp', 33.0)))
        ui.find('limit_dang').set('value', str(c.setdefault('limit_dang', 66.0)))
        ui.find('max').set('text', 'Min: %.2f, max: %.2f'%(cls.get_min(), cls.get_max()))
        return ui

    def apply_cfg_binary(self, cls, vars):
        self.backend.set_cfg(cls.plugin_id, cls.variant, {'good_state': eval(vars.getvalue('val', 'True'))})

    def apply_cfg_decimal(self, cls, vars):
        self.backend.set_cfg(cls.plugin_id, cls.variant, {
            'limit_susp': float(vars.getvalue('lim_susp', True)),
            'limit_dang': float(vars.getvalue('lim_dang', True)),
        })

    apply_cfg_linear = apply_cfg_decimal
开发者ID:GabrielDiniz,项目名称:FluxNetControl,代码行数:104,代码来源:main.py

示例3: HealthPlugin

# 需要导入模块: from backend import Backend [as 别名]
# 或者: from backend.Backend import set_cfg [as 别名]

#.........这里部分代码省略.........
                    ),
                ),
            )

        if self._settings:
            ui.append("main", self.get_ui_settings())

        if self._configuring:
            ui.append("main", getattr(self, "get_ui_cfg_%s" % self._configuring.type)(self._configuring))

        return ui

    def get_ui_settings(self):
        ui = self.app.inflate("health:settings")

        for m in self.backend.list_meters():
            for v in self.backend.list_variated(m):
                ui.append(
                    "list",
                    UI.DTR(
                        UI.DTD(UI.Label(text=v.name, bold=True), UI.Label(text=v.text)),
                        UI.DTD(
                            UI.TipIcon(
                                icon="/dl/core/ui/stock/edit.png",
                                id="config/%s/%s" % (m.plugin_id, v.variant),
                                text="Configure",
                            ),
                            UI.TipIcon(
                                icon="/dl/core/ui/stock/delete.png",
                                id="disable/%s/%s" % (m.plugin_id, v.variant),
                                text="Disable",
                            )
                            if self.backend.has_cfg(m.plugin_id, v.variant)
                            else None,
                        ),
                    ),
                )
        return ui

    @event("button/click")
    def on_click(self, event, params, vars=None):
        if params[0] == "btnRefresh":
            self.mon.refresh()
        if params[0] == "btnSettings":
            self._settings = True
        if params[0] == "config":
            self._configuring = self.backend.get_meter(*params[1:])
        if params[0] == "disable":
            self.backend.del_cfg(*params[1:])
            self.mon.refresh()

    @event("dialog/submit")
    def on_submit(self, event, params, vars=None):
        if params[0] == "dlgSettings":
            self._settings = False
        if params[0] == "dlgConfigure":
            if vars.getvalue("action", None) == "OK":
                try:
                    getattr(self, "apply_cfg_%s" % (self._configuring.type))(self._configuring, vars)
                except:
                    self.app.log.error("Invalid meter configuration")
                self.mon.refresh()
            self._configuring = None

    def get_ui_cfg_binary(self, cls):
        ui = self.app.inflate("health:cfg-binary")
        t = self.backend.get_cfg(cls.plugin_id, cls.variant).setdefault("good_state", True)
        ui.find("r-true").set("checked", t)
        ui.find("r-false").set("checked", not t)
        return ui

    def get_ui_cfg_decimal(self, cls):
        ui = self.app.inflate("health:cfg-decimal")
        c = self.backend.get_cfg(cls.plugin_id, cls.variant)
        ui.find("limit_susp").set("value", str(c.setdefault("limit_susp", 33.0)))
        ui.find("limit_dang").set("value", str(c.setdefault("limit_dang", 66.0)))
        return ui

    def get_ui_cfg_linear(self, cls):
        ui = self.app.inflate("health:cfg-linear")
        c = self.backend.get_cfg(cls.plugin_id, cls.variant)
        ui.find("limit_susp").set("value", str(c.setdefault("limit_susp", 33.0)))
        ui.find("limit_dang").set("value", str(c.setdefault("limit_dang", 66.0)))
        ui.find("max").set("text", "Min: %.2f, max: %.2f" % (cls.get_min(), cls.get_max()))
        return ui

    def apply_cfg_binary(self, cls, vars):
        self.backend.set_cfg(cls.plugin_id, cls.variant, {"good_state": eval(vars.getvalue("val", "True"))})

    def apply_cfg_decimal(self, cls, vars):
        self.backend.set_cfg(
            cls.plugin_id,
            cls.variant,
            {
                "limit_susp": float(vars.getvalue("lim_susp", True)),
                "limit_dang": float(vars.getvalue("lim_dang", True)),
            },
        )

    apply_cfg_linear = apply_cfg_decimal
开发者ID:bneg,项目名称:genesis,代码行数:104,代码来源:main.py


注:本文中的backend.Backend.set_cfg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。