def Widget(option_name, value): """ :return: create a widget which permit to edit the value with a label """ # TODO: Currently an evaluation is used to guess value type. # This approach may fails for complex data # We need to improve option type management, for example by providing an associated map "option_name -> type". # We should also add constraints on values try: eval_value = ast.literal_eval(value) except (ValueError, SyntaxError): eval_value = value inames = guess_interface(eval_value) if len(inames): iname = inames[0] else: iname = 'IStr' # Dirty hack to handle int constraints on font size. if 'font' in option_name and iname == 'IInt': iname = new_interface(iname, min=5, max=200) control = Control(option_name, iname, eval_value) editor = qt_editor(control) return control, editor
def createEditor(self, parent, option, index): model = index.model() control = model.control(index) widget = qt_editor(control, shape='hline', preferred=control.widget) if widget is None: self.external_edition(index) else: widget.setParent(parent) widget.set(control, True, True) return widget
def add_control(self, control, pos=None): widget = qt_editor(control, 'large') if widget: if pos is None: pos = QtCore.QPointF(0, 0) item = WidgetItem(widget, pos, control.name) item.set_mode(self._mode) self.witems.append(item) self.addItem(item)
def add_control(self, control, pos=None): widget = qt_editor(control, "large") if widget: if pos is None: pos = QtCore.QPointF(0, 0) item = WidgetItem(widget, pos, control.name) item.set_mode(self._mode) self.witems.append(item) self.addItem(item)
def on_controls_selected(self, controls): if self._widget_edit: widget = self._widget_edit() widget.close() self._widget_edit = None del widget if not controls: return widget = QtGui.QWidget() widget.setAttribute(QtCore.Qt.WA_DeleteOnClose) layout = QtGui.QVBoxLayout(widget) for control in controls: subwidget = qt_editor(control, shape='large', preferred=control.widget) layout.addWidget(subwidget) self.addWidget(widget) self._widget_edit = weakref.ref(widget)
from openalea.vpltk.qt import QtGui from openalea.core.service.control import create_control from openalea.oalab.service.qt_control import qt_editor instance = QtGui.QApplication.instance() if instance is None: app = QtGui.QApplication([]) control = create_control('i', 'IInt', 250, dict(min=200, max=300)) widget = qt_editor(control) # widget.show() assert control.value == 250 assert widget.value() == 250 #if instance is None: # app.exec_()