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


Python PackageManager.get_user_packages方法代码示例

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


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

示例1: FactorySelector

# 需要导入模块: from openalea.core.pkgmanager import PackageManager [as 别名]
# 或者: from openalea.core.pkgmanager.PackageManager import get_user_packages [as 别名]
class FactorySelector(qt.QtGui.QDialog, ui_tofactory.Ui_FactorySelector):
    """ Dialog to select a particular CompositeNode factory """

    def __init__(self, default_factory=None, parent=None):
        """
        Construtor
        @param default_factory : default selected factory
        """

        qt.QtGui.QDialog.__init__(self, parent)
        ui_tofactory.Ui_FactorySelector.__init__(self)
        self.setupUi(self)

        self.pkgmanager = PackageManager()
        self.factorymap = {}
        self.default_factory = default_factory

        cfactories = []
        # Get all composite node factories in writable packages
        for pkg in self.pkgmanager.get_user_packages():
            pname = pkg.name

            for f in pkg.itervalues():
                if isinstance(f, CompositeNodeFactory):
                    name = "%s.%s" % (pname, f.name)
                    cfactories.append(name)
                    self.factorymap[name] = f

        cfactories.sort()
        self.comboBox.addItems(cfactories)

        i = -1
        if default_factory and default_factory.package:
            name = "%s.%s" % (default_factory.package.name, default_factory.name)
            i = self.comboBox.findText(name)

        self.comboBox.setCurrentIndex(i)

        self.connect(self.newFactoryButton, qt.QtCore.SIGNAL("clicked()"), self.new_factory)

    def accept(self):
        """ Accept dialog result """
        # Test if name is correct
        text = self.comboBox.currentText()
        if not text:
            mess = qt.QtGui.QMessageBox.warning(self, "Error", "Invalid Choice.")
            return

        qt.QtGui.QDialog.accept(self)

    def new_factory(self):
        """ Create a new composite node """

        if self.default_factory and self.default_factory.package:
            pkg_id = self.default_factory.package.name
        else:
            pkg_id = None
        dialog = NewGraph("New Composite Node", self.pkgmanager, self, io=False, pkg_id=pkg_id)
        ret = dialog.exec_()

        if ret > 0:
            newfactory = dialog.create_cnfactory(self.pkgmanager)
            name = "%s.%s" % (newfactory.package.name, newfactory.name)
            self.comboBox.addItem(name)
            self.factorymap[name] = newfactory
            i = self.comboBox.findText(name)
            self.comboBox.setCurrentIndex(i)
            self.accept()

    def get_factory(self):
        """ Return the selected factory """

        text = unicode(self.comboBox.currentText()).encode("latin1")
        return self.factorymap[str(text)]
开发者ID:shiva16,项目名称:openalea,代码行数:76,代码来源:dialogs.py


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