Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 14
0
 def _on_add_applet_triggered(self):
     widget = AppletSelector()
     dialog = ModalDialog(widget)
     if dialog.exec_() == dialog.Accepted:
         self.add_applet(widget.currentAppletName())
Ejemplo n.º 15
0
 def open_preferences(self):
     preferences = PreferenceWidget()
     dialog = ModalDialog(preferences)
     if dialog.exec_():
         preferences.update_config(save=True)
Ejemplo n.º 16
0
 def new_project(self):
     project_creator = CreateProjectWidget()
     dialog = ModalDialog(project_creator)
     if dialog.exec_():
         project = project_creator.project()
         self.pm.cproject = project
Ejemplo n.º 17
0
 def new_project(self):
     project_creator = CreateProjectWidget()
     dialog = ModalDialog(project_creator)
     if dialog.exec_():
         project = project_creator.project()
         self.pm.cproject = project
Ejemplo n.º 18
0
 def open_preferences(self):
     preferences = PreferenceWidget()
     dialog = ModalDialog(preferences)
     if dialog.exec_():
         preferences.update_config(save=True)
Ejemplo n.º 19
0
 def _on_add_applet_triggered(self):
     widget = AppletSelector()
     dialog = ModalDialog(widget)
     if dialog.exec_() == dialog.Accepted:
         self.add_applet(widget.currentAppletName())