Exemplo n.º 1
0
    def __init__(self, category):
        gui3d.TaskView.__init__(self, category, 'Plugins')

        self.scroll = self.addTopWidget(gui.VScrollArea())
        self.pluginsBox = gui.GroupBox('Plugins')
        self.pluginsBox.setSizePolicy(gui.SizePolicy.MinimumExpanding,
                                      gui.SizePolicy.MinimumExpanding)
        self.scroll.setWidget(self.pluginsBox)

        for module in sorted(gui3d.app.modules):
            check = self.pluginsBox.addWidget(PluginCheckBox(module))
Exemplo n.º 2
0
    def __init__(self, category):

        info_msg = "Install new plugins by either copying to the user plugins folder or using the built in installer.\n"\
                   "The installer only handles Python script files and plugin packages in plain zip file format."\
                   "\n\nTo activate a plugin it must be checked in the list. Then click the \"Activate\"-Button or " \
                   "restart MakeHuman.\nTo deactivate a plugin uncheck it in the list and restart MakeHuman."

        gui3d.TaskView.__init__(self, category, 'User Plugins')

        self.userPlugins = getUserPlugins()
        activePlugins = gui3d.app.getSetting('activeUserPlugins')

        for plugin in activePlugins:
            if plugin not in [k for k, _ in self.userPlugins]:
                activePlugins.remove(plugin)

        gui3d.app.setSetting('activeUserPlugins', activePlugins)
        gui3d.app.saveSettings()

        self.home = getpath.getHomePath()

        scroll = self.addTopWidget(gui.VScrollArea())
        self.userPluginBox = gui.GroupBox('User Plugins')
        self.userPluginBox.setSizePolicy(gui.SizePolicy.MinimumExpanding,
                                         gui.SizePolicy.Preferred)
        scroll.setWidget(self.userPluginBox)

        self.updatePluginList()

        installWidget = gui.QtWidgets.QWidget()
        installWidgetLayout = gui.QtWidgets.QVBoxLayout()
        installWidget.setLayout(installWidgetLayout)
        self.addLeftWidget(installWidget)

        installBox = gui.GroupBox('')
        self.installPyButton = gui.Button('Install Plugin File')
        installBox.addWidget(self.installPyButton)
        self.installZipButton = gui.Button('Install Zipped Plugin')
        installBox.addWidget(self.installZipButton)
        installWidgetLayout.addWidget(installBox)

        actionsBox = gui.GroupBox('')
        self.reloadButton = gui.Button('Reload Plugins Folder')
        actionsBox.addWidget(self.reloadButton)
        self.activateButton = gui.Button('Activate Plugins')
        actionsBox.addWidget(self.activateButton)
        installWidgetLayout.addWidget(actionsBox)

        infoBox = gui.GroupBox('Info')
        infoText = gui.TextView(info_msg)
        infoText.setWordWrap(True)
        infoText.setSizePolicy(gui.SizePolicy.Ignored,
                               gui.SizePolicy.MinimumExpanding)
        infoBox.addWidget(infoText)
        installWidgetLayout.addWidget(infoBox)
        installWidgetLayout.addStretch(1)

        @self.installZipButton.mhEvent
        def onClicked(event):

            filename = getpath.pathToUnicode(
                gui.QtWidgets.QFileDialog.getOpenFileName(
                    gui3d.app.mainwin,
                    directory=self.home,
                    filter='Zip files ( *.zip );; All files ( *.* )')[0])

            dest_path = getpath.getPath('plugins')
            if os.path.isfile(filename):
                result = decompress(filename, dest_path)
                if result == 0:
                    self.updatePluginList()
                    gui3d.app.prompt(
                        'Info',
                        'The plugin copied successfully. To activate, check '
                        'the plugin in the list and press the "Activate"-Button or restart MakeHuman.',
                        'OK',
                        helpId='installPluginHelp')
                elif result == 3:
                    gui3d.app.prompt(
                        'Warning',
                        'Potentially dangerous zip file, containing files with unsuitable path. '
                        'Inspect/fix the zip file before usage!', 'OK')
                elif result == 4:
                    gui3d.app.prompt(
                        'Error',
                        'Zip file {0:s} contains exiting files.'.format(
                            filename), 'OK')
                elif result == 1:
                    gui3d.app.prompt('Error',
                                     'Not a zip file {0:s}'.format(filename),
                                     'OK')
            self.home = os.path.dirname(filename)

        @self.installPyButton.mhEvent
        def onClicked(event):
            filename = getpath.pathToUnicode(
                gui.QtWidgets.QFileDialog.getOpenFileName(
                    gui3d.app.mainwin,
                    directory=self.home,
                    filter='Python files ( *.py );; All files ( *.* )')[0])
            if os.path.isfile(filename) and os.path.splitext(
                    filename)[1] == '.py':
                try:
                    shutil.copy2(filename, getpath.getPath('plugins'))
                except OSError as e:
                    gui3d.app.prompt(
                        'Error',
                        'Failed to copy {0:s} to user plugins folder'.format(
                            filename), 'OK')
                self.updatePluginList()
                gui3d.app.prompt(
                    'Info',
                    'The plugin copied successfully. To activate, check '
                    'the plugin in the list and press the "Activate"-Button or restart MakeHuman.',
                    'OK',
                    helpId='installPluginHelp')
            self.home = os.path.dirname(filename)

        @self.reloadButton.mhEvent
        def onClicked(event):
            self.updatePluginList()

        @self.activateButton.mhEvent
        def onClicked(event):
            for child in self.userPluginBox.children:
                if child.selected:
                    if not child.module in gui3d.app.modules:
                        if not gui3d.app.loadPlugin(name=child.module,
                                                    location=child.path):
                            gui3d.app.prompt(
                                'Error',
                                'Cannot load module {0:s}\nCheck the log files'
                                .format(child.module), 'OK')
                    else:
                        log.message(
                            'Module %s already exists and will not be imported a second time.',
                            child.module)
Exemplo n.º 3
0
    def __init__(self, category):

        info_msg = "Install new plugins by either copying to the user plugins folder or using the built in installer.\n"\
                   "The installer only handles Python script files and plugin packages in plain zip file format."\
                   "\n\nTo (de-)activate a plugin it must be (un-)checked in the list. Changes only come into effect" \
                   " after MakeHuman is restarted."

        gui3d.TaskView.__init__(self, category, 'User Plugins')

        userPlugins = self.getUserPlugins()
        activePlugins = gui3d.app.getSetting('activeUserPlugins')

        for plugin in activePlugins:
            if plugin not in userPlugins:
                activePlugins.remove(plugin)

        gui3d.app.setSetting('activeUserPlugins', activePlugins)
        gui3d.app.saveSettings()

        self.home = os.path.expanduser('~')

        self.scroll = self.addTopWidget(gui.VScrollArea())
        self.userPluginBox = gui.GroupBox('User Plugins')
        self.userPluginBox.setSizePolicy(gui.SizePolicy.MinimumExpanding, gui.SizePolicy.Preferred)
        self.scroll.setWidget(self.userPluginBox)

        for i, plugin in enumerate(userPlugins):
            self.userPluginBox.addWidget(UserPluginCheckBox(plugin), row=i, alignment=gui.QtCore.Qt.AlignTop)

        self.installWidget = gui.QtWidgets.QWidget()
        installWidgetLayout = gui.QtWidgets.QVBoxLayout()
        self.installWidget.setLayout(installWidgetLayout)
        self.addLeftWidget(self.installWidget)

        self.installBox = gui.GroupBox('')
        self.installPyButton = gui.Button('Install Plugin File')
        self.installBox.addWidget(self.installPyButton)
        self.installZipButton = gui.Button('Install Zipped Plugin')
        self.installBox.addWidget(self.installZipButton)
        installWidgetLayout.addWidget(self.installBox)

        self.reloadBox = gui.GroupBox('')
        self.reloadButton = gui.Button('Reload Plugins Folder')
        self.reloadBox.addWidget(self.reloadButton)
        installWidgetLayout.addWidget(self.reloadBox)

        self.infoBox = gui.GroupBox('Info')
        self.infoText = gui.TextView(info_msg)
        self.infoText.setWordWrap(True)
        self.infoText.setSizePolicy(gui.SizePolicy.Ignored, gui.SizePolicy.MinimumExpanding)
        self.infoBox.addWidget(self.infoText)
        installWidgetLayout.addWidget(self.infoBox)
        installWidgetLayout.addStretch(1)

        @self.installZipButton.mhEvent
        def onClicked(event):

            filename = getpath.pathToUnicode(gui.QtWidgets.QFileDialog.getOpenFileName(gui3d.app.mainwin, directory=self.home,
                                             filter='Zip files ( *.zip );; All files ( *.* )')[0])

            dest_path = getpath.getPath('plugins')
            if os.path.isfile(filename):
                result = self.decompress(filename, dest_path)
                if result == 1:
                    gui3d.app.prompt('Error', 'Not a zip file {0:s}'.format(filename), 'OK')
                elif result == 3:
                    gui3d.app.prompt('Warning', 'Potentially dangerous zip file, containing files with unsuitable path. '
                                                'Inspect/fix the zip file before usage!', 'OK')
                elif result == -1:
                    gui3d.app.prompt('Error', 'Zip file {0:s} contains exiting files.'.format(filename), 'OK')
                elif result == 0:
                    gui3d.app.prompt('Info', 'The plugin copied successfully. To activate check '
                                     'the plugin in the list and restart MakeHuman.', 'OK', helpId='installPluginHelp' )
                    for child in self.userPluginBox.children:
                        self.userPluginBox.removeWidget(child)
                    updatePlugins = self.getUserPlugins()
                    for i, plugin in enumerate(updatePlugins):
                        self.userPluginBox.addWidget(UserPluginCheckBox(plugin), row = i, alignment=gui.QtCore.Qt.AlignTop)
            self.home = os.path.dirname(filename)

        @self.installPyButton.mhEvent
        def onClicked(event):
            filename = getpath.pathToUnicode(gui.QtWidgets.QFileDialog.getOpenFileName(gui3d.app.mainwin, directory=self.home,
                                             filter='Python files ( *.py );; All files ( *.* )')[0])
            if os.path.isfile(filename) and os.path.splitext(filename)[1] == '.py':
                try:
                    shutil.copy2(filename, getpath.getPath('plugins'))
                except OSError as e:
                    gui3d.app.prompt('Error', 'Failed to copy {0:s} to user plugins folder'.format(filename), 'OK')
                for child in self.userPluginBox.children:
                    self.userPluginBox.removeWidget(child)
                updatePlugins = self.getUserPlugins()
                for i, plugin in enumerate(updatePlugins):
                    self.userPluginBox.addWidget(UserPluginCheckBox(plugin), row=i, alignment=gui.QtCore.Qt.AlignTop)
                gui3d.app.prompt('Info', 'The plugin copied successfully. To activate check '
                                 'the plugin in the list and restart MakeHuman.', 'OK', helpId='installPluginHelp')
            self.home = os.path.dirname(filename)

        @self.reloadButton.mhEvent
        def onClicked(event):
            for child in self.userPluginBox.children:
                self.userPluginBox.removeWidget(child)
            updatePlugins = self.getUserPlugins()
            for i, plugin in enumerate(updatePlugins):
                self.userPluginBox.addWidget(UserPluginCheckBox(plugin), row=i, alignment=gui.QtCore.Qt.AlignTop)