示例#1
0
    def add(self, project, name, code, dtype=None, category=None):
        if dtype is None:

            dtypes = [ModelClass.default_name for ModelClass in plugins('oalab.modelclass')]
        else:
            dtypes = [dtype]

        if category:
            categories = [category]
        else:
            categories = Project.DEFAULT_CATEGORIES.keys()
        selector = SelectCategory(filename=name, categories=categories, dtypes=dtypes)
        dialog = ModalDialog(selector)
        if dialog.exec_():
            category = selector.category()
            filename = selector.name()
            dtype = selector.dtype()
            path = project.path / category / filename
            if path.exists():
                box = QtGui.QMessageBox.information(self, 'Data yet exists',
                                                    'Data with name %s already exists in this project, just add it' % filename)
                code = None
            data = project.add(category=category, filename=filename, content=code, dtype=dtype)
            if data:
                return category, data
        return None, None
示例#2
0
 def new_control(self):
     editor = ControlEditor('control')
     dialog = ModalDialog(editor)
     if dialog.exec_():
         control = editor.control()
         if self.model()._manager.control(control.name):
             QtGui.QMessageBox.information(self, 'Error on adding control',
                                           'A control with name %s already exists' % control.name)
         else:
             self.model().add_control(control)
示例#3
0
def select_plugin(category, parent=None, **kwargs):
    """
    kwargs:
        - size: tuple (width, height) [default: (640,480)]
        - title: unicode [default: "Select plugin"]
    """
    size = kwargs.pop('size', (640, 480))
    title = kwargs.pop('title', 'Select plugin')
    selector = PluginSelector(category)
    selector.setAttribute(QtCore.Qt.WA_DeleteOnClose)
    selector.resize(*size)
    dialog = ModalDialog(selector,
                         parent=parent,
                         buttons=QtGui.QDialogButtonBox.Cancel)
    dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose)
    dialog.resize(*size)
    dialog.setWindowTitle(title)
    selector.pluginSelected.connect(dialog.accept)
    if dialog.exec_():
        plugin_class = selector.plugin_class
    else:
        plugin_class = None
    del dialog
    del selector
    return plugin_class
示例#4
0
 def _rename(self, project, category, name):
     if category in project.DEFAULT_CATEGORIES:
         filelist = getattr(project, category).keys()
         renamer = RenameModel(filelist, name)
         dialog = ModalDialog(renamer)
         if dialog.exec_():
             old_name = renamer.old_name()
             new_name = renamer.new_name()
             project.rename_item(category, old_name, new_name)
     elif category == 'project':
         self.edit_metadata()
示例#5
0
 def edit_metadata(self):
     project = self.project()
     if project:
         project_creator = CreateProjectWidget(project)
         dialog = ModalDialog(project_creator)
         if dialog.exec_():
             _proj = project_creator.project()
             if _proj.name != project.name or _proj.projectdir != project.projectdir:
                 project.move(_proj.path)
             project.metadata = project_creator.metadata()
             project.save()
示例#6
0
 def _rename(self, project, category, name):
     if category in project.DEFAULT_CATEGORIES:
         filelist = getattr(project, category).keys()
         renamer = RenameModel(filelist, name)
         dialog = ModalDialog(renamer)
         if dialog.exec_():
             old_name = renamer.old_name()
             new_name = renamer.new_name()
             project.rename_item(category, old_name, new_name)
     elif category == 'project':
         self.edit_metadata()
示例#7
0
 def edit_metadata(self):
     project = self.project()
     if project:
         project_creator = CreateProjectWidget(project)
         dialog = ModalDialog(project_creator)
         if dialog.exec_():
             _proj = project_creator.project()
             if _proj.name != project.name or _proj.projectdir != project.projectdir:
                 project.move(_proj.path)
             project.metadata = project_creator.metadata()
             project.save()
示例#8
0
    def delete(self):
        project, category, name = self.selected_data()
        if project:
            if category in project.DEFAULT_CATEGORIES:
                data = project.get(category, name)

                confirm = QtGui.QLabel('Remove %s ?' % data.path)
                dialog = ModalDialog(confirm)
                if dialog.exec_():
                    project.remove(category, data)
                    data.path.remove()
                    if self.paradigm_container:
                        self.paradigm_container.close_data(data)
示例#9
0
    def delete(self):
        project, category, name = self.selected_data()
        if project:
            if category in project.DEFAULT_CATEGORIES:
                data = project.get(category, name)

                confirm = QtGui.QLabel('Remove %s ?' % data.path)
                dialog = ModalDialog(confirm)
                if dialog.exec_():
                    project.remove(category, data)
                    data.path.remove()
                    if self.paradigm_container:
                        self.paradigm_container.close_data(data)
示例#10
0
def qt_dialog(control=None, **kwds):
    """
    You can pass control factory arguments:
        - name: Control name
        - interface: Control interface
        - value: Control value

    You can also pass qt_editor factory arguments
        - shape: widget shape
        - preferred: preferred widget
    """
    autoapply = kwds.get('autoapply', False)
    if control is None:
        control = Control(**kwds)
    widget = qt_editor(control, **kwds)
    widget.autoapply(control, autoapply)
    dialog = ModalDialog(widget)
    if dialog.exec_() == QtGui.QDialog.Accepted:
        return widget.value()
    else:
        return None
示例#11
0
def qt_dialog(control=None, **kwds):
    """
    You can pass control factory arguments:
        - name: Control name
        - interface: Control interface
        - value: Control value

    You can also pass qt_editor factory arguments
        - shape: widget shape
        - preferred: preferred widget
    """
    autoapply = kwds.get('autoapply', False)
    if control is None:
        control = Control(**kwds)
    widget = qt_editor(control, **kwds)
    widget.autoapply(control, autoapply)
    dialog = ModalDialog(widget)
    if dialog.exec_() == QtGui.QDialog.Accepted:
        return widget.value()
    else:
        return None
示例#12
0
    def add(self, project, name, code, dtype=None, category=None):
        if dtype is None:

            dtypes = [
                ModelClass.default_name
                for ModelClass in plugins('oalab.modelclass')
            ]
        else:
            dtypes = [dtype]

        if category:
            categories = [category]
        else:
            categories = Project.DEFAULT_CATEGORIES.keys()
        selector = SelectCategory(filename=name,
                                  categories=categories,
                                  dtypes=dtypes)
        dialog = ModalDialog(selector)
        if dialog.exec_():
            category = selector.category()
            filename = selector.name()
            dtype = selector.dtype()
            path = project.path / category / filename
            if path.exists():
                box = QtGui.QMessageBox.information(
                    self, 'Data yet exists',
                    'Data with name %s already exists in this project, just add it'
                    % filename)
                code = None
            data = project.add(category=category,
                               filename=filename,
                               content=code,
                               dtype=dtype)
            if data:
                return category, data
        return None, None
示例#13
0
def select_plugin(category, parent=None, **kwargs):
    """
    kwargs:
        - size: tuple (width, height) [default: (640,480)]
        - title: unicode [default: "Select plugin"]
    """
    size = kwargs.pop('size', (640, 480))
    title = kwargs.pop('title', 'Select plugin')
    selector = PluginSelector(category)
    selector.setAttribute(QtCore.Qt.WA_DeleteOnClose)
    selector.resize(*size)
    dialog = ModalDialog(selector, parent=parent, buttons=QtGui.QDialogButtonBox.Cancel)
    dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose)
    dialog.resize(*size)
    dialog.setWindowTitle(title)
    selector.pluginSelected.connect(dialog.accept)
    if dialog.exec_():
        plugin_class = selector.plugin_class
    else:
        plugin_class = None
    del dialog
    del selector
    return plugin_class
示例#14
0
 def _on_add_applet_triggered(self):
     widget = AppletSelector()
     dialog = ModalDialog(widget)
     if dialog.exec_() == dialog.Accepted:
         self.add_applet(widget.currentAppletName())
示例#15
0
文件: help.py 项目: shiva16/openalea
 def open_preferences(self):
     preferences = PreferenceWidget()
     dialog = ModalDialog(preferences)
     if dialog.exec_():
         preferences.update_config(save=True)
示例#16
0
 def new_project(self):
     project_creator = CreateProjectWidget()
     dialog = ModalDialog(project_creator)
     if dialog.exec_():
         project = project_creator.project()
         self.pm.cproject = project
示例#17
0
 def new_project(self):
     project_creator = CreateProjectWidget()
     dialog = ModalDialog(project_creator)
     if dialog.exec_():
         project = project_creator.project()
         self.pm.cproject = project
示例#18
0
 def open_preferences(self):
     preferences = PreferenceWidget()
     dialog = ModalDialog(preferences)
     if dialog.exec_():
         preferences.update_config(save=True)
示例#19
0
 def _on_add_applet_triggered(self):
     widget = AppletSelector()
     dialog = ModalDialog(widget)
     if dialog.exec_() == dialog.Accepted:
         self.add_applet(widget.currentAppletName())