瀏覽代碼

Get plugin options in PluginBase

To reduce the boilerplate code needed for each plugin, the PluginBase
class now pulls out the plugin's options from the configuration object.
They get stored under the reasonably obvious name of ``options``.
Clara Hobbs 8 年之前
父節點
當前提交
c9e02f7e02
共有 2 個檔案被更改,包括 2 行新增2 行删除
  1. 1
    0
      kayleevc/plugins/pluginbase.py
  2. 1
    2
      kayleevc/plugins/shell.py

+ 1
- 0
kayleevc/plugins/pluginbase.py 查看文件

@@ -29,6 +29,7 @@ class PluginBase(GObject.Object):
29 29
         super().__init__()
30 30
         self.config = config
31 31
         self.name = name
32
+        self.options = config.options.plugins[name]
32 33
         self.corpus_strings = set()
33 34
 
34 35
     def recognizer_finished(self, recognizer, text):

+ 1
- 2
kayleevc/plugins/shell.py 查看文件

@@ -13,9 +13,8 @@ class Plugin(PluginBase):
13 13
 
14 14
     def __init__(self, config, name):
15 15
         super().__init__(config, name)
16
-        self.options = vars(self.config.options)
17 16
         self.number_parser = NumberParser()
18
-        self.commands = self.options['plugins'][name]
17
+        self.commands = self.options
19 18
 
20 19
         for voice_cmd in self.commands.keys():
21 20
             self.corpus_strings.add(voice_cmd.strip().replace('%d', ''))

Loading…
取消
儲存