當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。