def register(self, _type, item, replace=False): _type = str(_type) if _type in self._items and not replace: raise Exception("Type already has an item") else: if type(item) == str: item = import_callable(item) self._items[_type] = item
def loadPlugins(self, plugins): self._plugins = [] for plugin in plugins: if type(plugin) == str: plugin = import_callable(plugin) p = plugin(self) self._plugins.append(p) action = p.action() self.pluginLoaded.emit(action)
def loadPlugins(self, plugins): self._plugins = [] for plugin in plugins: if type(plugin) == str: plugin = import_callable(plugin) p = plugin(self) self._plugins.append(p) action = p.action() if isinstance(action, (list, tuple)): for a in action: self.pluginLoaded.emit(a) else: self.pluginLoaded.emit(action)
def __init__(self, containers): """ Initialize the factory with the mappings between file pattern and the container. Parameters ========== containers: tuple of tuples (str, str/class) The mapping between file pattern and container class responsible for loading/saving. """ self._containers = [] for pattern, item in containers: if type(item) == str: item = import_callable(item) self._containers.append((pattern, item))
def register(self, _type, item, replace=False): """ Register a new type-item mapping. Parameters ========== _type: string Type of the item. item: python callable or string Reference to the callable which creates the new object. """ _type = str(_type) if _type in self._items and not replace: raise Exception("Type %s already has an item: %s" % \ (_type, str(self._items[_type]))) else: if type(item) == str: item = import_callable(item) self._items[_type] = item
def initShortcuts(self, HOTKEYS): self.shortcuts = [] for hotkey in HOTKEYS: assert len(hotkey) >= 2 key = hotkey[0] fun = hotkey[1] desc = "" if len(hotkey) > 2: desc = hotkey[2] if type(fun) == str: fun = import_callable(fun) hk = QAction(desc, self) hk.setShortcut(QKeySequence(key)) hk.setEnabled(True) if hasattr(fun, '__call__'): hk.triggered.connect(bind(fun, self.labeltool)) else: hk.triggered.connect(compose_noargs([bind(f, self.labeltool) for f in fun])) self.ui.menuShortcuts.addAction(hk) self.shortcuts.append(hk)