예제 #1
0
 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
예제 #2
0
 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()
         self.pluginLoaded.emit(action)
예제 #4
0
파일: labeltool.py 프로젝트: iluxave/sloth
 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)
예제 #5
0
    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))
예제 #6
0
파일: container.py 프로젝트: mlilien/sloth
    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))
예제 #7
0
    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
예제 #8
0
파일: factory.py 프로젝트: MacTop/sloth
    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
예제 #9
0
    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)
예제 #10
0
    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)