Source code for openalea.oalab.control.editor
import weakref
from openalea.vpltk.qt import QtGui, QtCore
from openalea.core.service.interface import interface_label
from openalea.oalab.service.qt_control import qt_widget_plugins
from openalea.core.control import Control
from openalea.deploy.shared_data import shared_data
import openalea.oalab
class QtControlEditor(QtGui.QWidget):
[docs]
def __init__(self, control=None):
QtGui.QWidget.__init__(self)
self.set_control(control)
self._layout = QtGui.QVBoxLayout(self)
self._qt_editor = None
def set_control(self, control=None):
[docs] self._control = control
def widget_label(widget):
generate_pyfile_from_uifile(__name__)
from openalea.oalab.control.designer._editor import Ui_ControlEditor
class ControlEditor(QtGui.QWidget, Ui_ControlEditor):
[docs] counters = {}
def __init__(self, name='default'):
QtGui.QWidget.__init__(self)
Ui_ControlEditor.__init__(self)
self.setupUi(self)
self._interfaces = []
self._constraints = None
self.cb_preview.setChecked(False)
self.box_preview.setVisible(False)
self.e_name.setText(name)
self._autoname = True
self.e_name.textEdited.connect(self.on_user_edit)
self.tooltips = {}
self.label_to_iname = {}
self.label_to_wname = {}
self.widget_to_label = {}
plugins = qt_widget_plugins()
for iname in plugins:
label = interface_label(iname)
self.label_to_iname[label] = iname
self.tooltips[iname] = '<b>%s</b><br />Interface name:%s' % (label, iname)
for label in sorted(self.label_to_iname):
iname = self.label_to_iname[label]
self._interfaces.append(iname)
tooltip = self.tooltips[iname]
item = QtGui.QListWidgetItem(label)
item.setToolTip(tooltip)
item.setStatusTip(tooltip)
self.cb_interface.addItem(label)
self.cb_interface.currentIndexChanged.connect(self.refresh)
self.cb_widget.currentIndexChanged.connect(self.on_widget_changed)
self.refresh()
def on_user_edit(self):
[docs] self._autoname = False
def on_widget_changed(self):
[docs] iname = self._interfaces[self.cb_interface.currentIndex()]
if self._autoname:
i = self.__class__.counters.setdefault(iname, 0)
self.e_name.setText('%s_%d' % (iname[1:].lower(), i))
self.l_type.setToolTip(self.tooltips[iname])
self.cb_widget.clear()
self.widget_plugins = []
self.label_to_wname = {}
editors = qt_widget_plugins(iname)
for widget in editors:
self.widget_plugins.append(widget)
label = widget_label(widget)
self.label_to_wname[label] = widget.name
self.cb_widget.addItem(label)
def control(self):
[docs] iname = self._interfaces[self.cb_interface.currentIndex()]
control = Control(self.e_name.text(), iname,
widget=self.label_to_wname[self.cb_widget.currentText()],
constraints=self.constraints())
self.__class__.counters[iname] = self.__class__.counters.setdefault(iname, 0) + 1
return control
def constraints(self):
[docs] if self._constraints:
return self._constraints().constraints()
else:
return {}