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
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)
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
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()
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()
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)
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
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
def _on_add_applet_triggered(self): widget = AppletSelector() dialog = ModalDialog(widget) if dialog.exec_() == dialog.Accepted: self.add_applet(widget.currentAppletName())
def open_preferences(self): preferences = PreferenceWidget() dialog = ModalDialog(preferences) if dialog.exec_(): preferences.update_config(save=True)
def new_project(self): project_creator = CreateProjectWidget() dialog = ModalDialog(project_creator) if dialog.exec_(): project = project_creator.project() self.pm.cproject = project