예제 #1
0
def connect_line(line, master, value):
    update_value = gui.ValueCallback(master, value)  # save the value
    update_control = LineCallFront(line)  # update control
    update_value.opposite = update_control
    update_control(getdeepattr(master, value))  # set the first value
    master.connect_control(value, update_control)
    line.sigMoved.connect(lambda: update_value(line.rounded_value()))
예제 #2
0
    def settings_to_widget(self, widget):
        """
        Restore the saved `context` to `widget`.
        """
        super().settings_to_widget(widget)
        context = widget.current_context

        if context is None:
            return

        if self.inputListField and self.inputListFieldName in context.values:
            # find the permutation of the current input list so it matches
            # the stored one
            inputs = widgetutils.getdeepattr(widget, self.inputListFieldName)
            _, encoded = self.encode(widget, inputs)
            _, stored = context.encoded

            def uuids(seq):
                return [uuid for _, _, uuid in seq]

            # NOTE: Match on widget uuids only.
            # LTTL.Input.Input can change it's 'label' in place on user
            # interaction
            try:
                permutation = self._permutation(uuids(encoded), uuids(stored))
            except ValueError:
                permutation = range(len(inputs))

            permuted = [inputs[p] for p in permutation]

            # Restore the stored order in the widget.
            setattr(widget, self.inputListFieldName, permuted)
예제 #3
0
def connect_line(line, master, value):
    update_value = gui.ValueCallback(master, value)  # save the value
    update_control = LineCallFront(line)  # update control
    update_value.opposite = update_control
    update_control(getdeepattr(master, value))  # set the first value
    master.connect_control(value, update_control)
    line.sigMoved.connect(lambda: update_value(line.rounded_value()))
예제 #4
0
def connect_line_edit_finished(lineedit, master, value, valueToStr=str, valueType=str, callback=None):
    # callback is only for compatibility with the old code
    update_value = gui.ValueCallback(master, value, valueType)  # save the value
    update_control = CallFrontLineEditCustomConversion(lineedit, valueToStr)  # update control
    update_value.opposite = update_control
    update_control(getdeepattr(master, value))  # set the first value
    master.connect_control(value, update_control)
    lineedit.newInput.connect(lambda x: (update_value(x),
                                         callback() if callback is not None else None))
예제 #5
0
파일: widget.py 프로젝트: Ameobea/orange3
    def save_graph(self):
        """Save the graph with the name given in class attribute `graph_name`.

        The method is called by the *Save graph* button, which is created
        automatically if the `graph_name` is defined.
        """
        graph_obj = getdeepattr(self, self.graph_name, None)
        if graph_obj is None:
            return
        saveplot.save_plot(graph_obj, self.graph_writers)
예제 #6
0
    def save_graph(self):
        """Save the graph with the name given in class attribute `graph_name`.

        The method is called by the *Save graph* button, which is created
        automatically if the `graph_name` is defined.
        """
        graph_obj = getdeepattr(self, self.graph_name, None)
        if graph_obj is None:
            return
        saveplot.save_plot(graph_obj, self.graph_writers)
예제 #7
0
def lineEditFloatOrNone(widget, master, value, **kwargs):
    kwargs["validator"] = FloatOrEmptyValidator(master)
    kwargs["valueType"] = floatornone
    le = gui.lineEdit(widget, master, value, **kwargs)
    if value:
        val = getdeepattr(master, value)
        if val is None:
            le.setText("")
        else:
            le.setText(str(val))
    return le
예제 #8
0
파일: gui.py 프로젝트: RobC1957/orange3
 def __call__(self, *_):  # triggered by selectionChange()
     if not self.disabled and self.control.ogValue is not None:
         clist = getdeepattr(self.widget, self.control.ogValue)
         control = self.control
         selection = [i for i in range(control.count())
                      if control.item(i).isSelected()]
         if isinstance(clist, int):
             self.widget.__setattr__(
                 self.control.ogValue, selection[0] if selection else None)
         else:
             list.__setitem__(clist, slice(0, len(clist)), selection)
             self.widget.__setattr__(self.control.ogValue, clist)
예제 #9
0
    def settings_from_widget(self, widget):
        """
        Get the settings from a widget.
        """
        super().settings_from_widget(widget)
        context = widget.current_context

        if context is None:
            return

        if self.inputListField:
            encoded = self.encode(
                widget, widgetutils.getdeepattr(widget,
                                                self.inputListFieldName))
            context.encoded = encoded
            context.values[self.inputListFieldName] = encoded[1]
예제 #10
0
    def report_plot(self, name=None, plot=None):
        """
        Add a plot to the report.

        Both arguments can be omitted.

        - `report_plot("graph name", self.plotView)` reports plot
            `self.plotView` with name `"graph name"`
        - `report_plot(self.plotView) reports plot without name
        - `report_plot()` reports plot stored in attribute whose name is
            taken from `self.graph_name`
        - `report_plot("graph name")` reports plot stored in attribute
            whose name is taken from `self.graph_name`

        :param name: report section name (can be omitted)
        :type name: str or tuple or OrderedDict
        :param plot: plot widget
        :type plot:
            QGraphicsScene or pyqtgraph.PlotItem or pyqtgraph.PlotWidget
            or pyqtgraph.GraphicsWidget. If omitted, the name of the
            attribute storing the graph is taken from `self.graph_name`
        """
        if not (isinstance(name, str) and plot is None):
            name, plot = self._fix_args(name, plot)

        from pyqtgraph import PlotWidget, PlotItem, GraphicsWidget, GraphicsView
        from Orange.widgets.utils.webview import WebviewWidget

        self.report_name(name)
        if plot is None:
            plot = getdeepattr(self, self.graph_name)
        if isinstance(plot, (QGraphicsScene, PlotItem)):
            self.report_html += get_html_img(plot)
        elif isinstance(plot, PlotWidget):
            self.report_html += get_html_img(plot.plotItem)
        elif isinstance(plot, GraphicsWidget):
            self.report_html += get_html_img(plot.scene())
        elif isinstance(plot, GraphicsView):
            self.report_html += get_html_img(plot)
        elif isinstance(plot, WebviewWidget):
            try:
                svg = plot.svg()
            except (IndexError, ValueError):
                svg = plot.html()
            self.report_html += svg
예제 #11
0
    def report_plot(self, name=None, plot=None):
        """
        Add a plot to the report.

        Both arguments can be omitted.

        - `report_plot("graph name", self.plotView)` reports plot
            `self.plotView` with name `"graph name"`
        - `report_plot(self.plotView) reports plot without name
        - `report_plot()` reports plot stored in attribute whose name is
            taken from `self.graph_name`
        - `report_plot("graph name")` reports plot stored in attribute
            whose name is taken from `self.graph_name`

        :param name: report section name (can be omitted)
        :type name: str or tuple or OrderedDict
        :param plot: plot widget
        :type plot:
            QGraphicsScene or pyqtgraph.PlotItem or pyqtgraph.PlotWidget
            or pyqtgraph.GraphicsWidget. If omitted, the name of the
            attribute storing the graph is taken from `self.graph_name`
        """
        if not (isinstance(name, str) and plot is None):
            name, plot = self._fix_args(name, plot)

        from pyqtgraph import PlotWidget, PlotItem, GraphicsWidget, GraphicsView
        from Orange.widgets.utils.webview import WebviewWidget

        self.report_name(name)
        if plot is None:
            plot = getdeepattr(self, self.graph_name)
        if isinstance(plot, (QGraphicsScene, PlotItem)):
            self.report_html += get_html_img(plot)
        elif isinstance(plot, PlotWidget):
            self.report_html += get_html_img(plot.plotItem)
        elif isinstance(plot, GraphicsWidget):
            self.report_html += get_html_img(plot.scene())
        elif isinstance(plot, GraphicsView):
            self.report_html += get_html_img(plot)
        elif isinstance(plot, WebviewWidget):
            try:
                svg = plot.svg()
            except IndexError:
                svg = plot.html()
            self.report_html += svg
예제 #12
0
def connect_settings(master, value, value2, transform=None):
    """
    Connect two Orange settings, so that both will be mutually updated. One value
    can be a function of the other. This sets value of the value2 as a function of value.

    :param master: a settings controller
    :param value: name of the first value
    :param value2: name of the second value
    :param transform: a transform from value to value2 (an instance of ValueTransform)
    """
    update_value = ValueCallbackTransform(master, value,
                                          f=transform.inverse if transform is not None else None)
    update_value2 = ValueCallbackTransform(master, value2,
                                           f=transform.transform if transform is not None else None)
    update_value.opposite = update_value2
    update_value2.opposite = update_value
    update_value2(getdeepattr(master, value))
    master.connect_control(value, update_value2)
    master.connect_control(value2, update_value)
예제 #13
0
 def addSetting(self, owner, name, label=None, updateCallback=None):
     """
     :param owner: setting owner
     :type owner: OWWidget or OWComponent
     :param name: setting name
     :type name: str
     :param label: setting label
     :type label: str or None
     """
     # Label
     if label is None:
         label = '{}:'.format(name)
     # Field
     value = getdeepattr(owner, name)
     if isinstance(value, str):
         field = QtWidgets.QLineEdit()
         field.setText(value)
         if updateCallback:
             field.textChanged.connect(updateCallback)
     elif isinstance(value, numbers.Number):
         if isinstance(value, numbers.Integral):
             field = QtWidgets.QSpinBox()
             ma = sys.maxsize
             field.setRange(-ma - 1, ma)
         else:
             field = QtWidgets.QDoubleSpinBox()
         field.setValue(value)
         if updateCallback:
             field.valueChanged.connect(updateCallback)
     else:
         raise ValueError('{} does not have a Qt widget'.format(
             repr(type(value).__qualname__)))
     # Append
     policy = QtWidgets.QSizePolicy.Expanding
     field.setSizePolicy(policy, policy)
     self.layout().addRow(label, field)
     return field
예제 #14
0
 def copy_to_clipboard(self):
     if self.graph_name:
         graph_obj = getdeepattr(self, self.graph_name, None)
         if graph_obj is None:
             return
         ClipboardFormat.write_image(None, graph_obj)
예제 #15
0
파일: gui.py 프로젝트: qeryq/SFECOMLA
def comboBox(widget,
             master,
             value,
             box=None,
             label=None,
             labelWidth=None,
             orientation=Qt.Vertical,
             items=(),
             callback=None,
             sendSelectedValue=False,
             valueType=str,
             emptyString=None,
             editable=False,
             contentsLength=None,
             maximumContentsLength=25,
             **misc):
    """
    Construct a combo box.

    The `value` attribute of the `master` contains either the index of the
    selected row (if `sendSelected` is left at default, `False`) or a value
    converted to `valueType` (`str` by default).

    :param widget: the widget into which the box is inserted
    :type widget: QWidget or None
    :param master: master widget
    :type master: OWWidget or OWComponent
    :param value: the master's attribute with which the value is synchronized
    :type value:  str
    :param box: tells whether the widget has a border, and its label
    :type box: int or str or None
    :param orientation: tells whether to put the label above or to the left
    :type orientation: `Qt.Horizontal` (default), `Qt.Vertical` or
        instance of `QLayout`
    :param label: a label that is inserted into the box
    :type label: str
    :param labelWidth: the width of the label
    :type labelWidth: int
    :param callback: a function that is called when the value is changed
    :type callback: function
    :param items: items (optionally with data) that are put into the box
    :type items: tuple of str or tuples
    :param sendSelectedValue: flag telling whether to store/retrieve indices
        or string values from `value`
    :type sendSelectedValue: bool
    :param valueType: the type into which the selected value is converted
        if sentSelectedValue is `False`
    :type valueType: type
    :param emptyString: the string value in the combo box that gets stored as
        an empty string in `value`
    :type emptyString: str
    :param editable: a flag telling whether the combo is editable
    :type editable: bool
    :param int contentsLength: Contents character length to use as a
        fixed size hint. When not None, equivalent to::

            combo.setSizeAdjustPolicy(
                QComboBox.AdjustToMinimumContentsLengthWithIcon)
            combo.setMinimumContentsLength(contentsLength)
    :param int maximumContentsLength: Specifies the upper bound on the
        `sizeHint` and `minimumSizeHint` width specified in character
        length (default: 25, use 0 to disable)
    :rtype: QComboBox
    """

    # Local import to avoid circular imports
    from Orange.widgets.utils.itemmodels import VariableListModel

    if box or label:
        hb = widgetBox(widget, box, orientation, addToLayout=False)
        if label is not None:
            label = widgetLabel(hb, label, labelWidth)
    else:
        hb = widget

    combo = OrangeComboBox(hb,
                           maximumContentsLength=maximumContentsLength,
                           editable=editable)

    if contentsLength is not None:
        combo.setSizeAdjustPolicy(
            QtWidgets.QComboBox.AdjustToMinimumContentsLengthWithIcon)
        combo.setMinimumContentsLength(contentsLength)

    combo.box = hb
    combo.label = label
    for item in items:
        if isinstance(item, (tuple, list)):
            combo.addItem(*item)
        else:
            combo.addItem(str(item))

    if value:
        cindex = getdeepattr(master, value)
        model = misc.pop("model", None)
        if model is not None:
            combo.setModel(model)
        if isinstance(model, VariableListModel):
            callfront = CallFrontComboBoxModel(combo, model)
            callfront.action(cindex)
        else:
            if isinstance(cindex, str):
                if items and cindex in items:
                    cindex = items.index(cindex)
                else:
                    cindex = 0
            if cindex > combo.count() - 1:
                cindex = 0
            combo.setCurrentIndex(cindex)

        if isinstance(model, VariableListModel):
            connectControl(master, value, callback, combo.activated[int],
                           callfront,
                           ValueCallbackComboModel(master, value, model))
        elif sendSelectedValue:
            connectControl(
                master, value, callback, combo.activated[str],
                CallFrontComboBox(combo, valueType, emptyString),
                ValueCallbackCombo(master, value, valueType, emptyString))
        else:
            connectControl(master, value, callback, combo.activated[int],
                           CallFrontComboBox(combo, None, emptyString))
    miscellanea(combo, hb, widget, **misc)
    combo.emptyString = emptyString
    return combo
예제 #16
0
파일: widget.py 프로젝트: Ameobea/orange3
 def copy_to_clipboard(self):
     graph_obj = getdeepattr(self, self.graph_name, None)
     if graph_obj is None:
         return
     ClipboardFormat.write_image(None, graph_obj)
예제 #17
0
def listBox(widget,
            master,
            value=None,
            labels=None,
            box=None,
            callback=None,
            selectionMode=QtWidgets.QListWidget.SingleSelection,
            enableDragDrop=False,
            dragDropCallback=None,
            dataValidityCallback=None,
            sizeHint=None,
            **misc):
    """
    Insert a list box.

    The value with which the box's value synchronizes (`master.<value>`)
    is a list of indices of selected items.

    :param widget: the widget into which the box is inserted
    :type widget: QWidget or None
    :param master: master widget
    :type master: OWWidget or OWComponent
    :param value: the name of the master's attribute with which the value is
        synchronized (list of ints - indices of selected items)
    :type value: str
    :param labels: the name of the master's attribute with the list of items
        (as strings or tuples with icon and string)
    :type labels: str
    :param box: tells whether the widget has a border, and its label
    :type box: int or str or None
    :param callback: a function that is called when the selection state is
        changed
    :type callback: function
    :param selectionMode: selection mode - single, multiple etc
    :type selectionMode: QAbstractItemView.SelectionMode
    :param enableDragDrop: flag telling whether drag and drop is available
    :type enableDragDrop: bool
    :param dragDropCallback: callback function on drop event
    :type dragDropCallback: function
    :param dataValidityCallback: function that check the validity on enter
        and move event; it should return either `ev.accept()` or `ev.ignore()`.
    :type dataValidityCallback: function
    :param sizeHint: size hint
    :type sizeHint: QSize
    :rtype: OrangeListBox
    """
    if box:
        bg = hBox(widget, box, addToLayout=False)
    else:
        bg = widget
    lb = OrangeListBox(master, enableDragDrop, dragDropCallback,
                       dataValidityCallback, sizeHint, bg)
    lb.setSelectionMode(selectionMode)
    lb.ogValue = value
    lb.ogLabels = labels
    lb.ogMaster = master

    if labels is not None:
        setattr(master, labels, getdeepattr(master, labels))
        master.connect_control(labels, CallFrontListBoxLabels(lb))
    if value is not None:
        clist = getdeepattr(master, value)
        if not isinstance(clist, (int, ControlledList)):
            clist = ControlledList(clist, lb)
            master.__setattr__(value, clist)
        setattr(master, value, clist)
        connectControl(master, value, callback, lb.itemSelectionChanged,
                       CallFrontListBox(lb), CallBackListBox(lb, master))

    misc.setdefault('addSpace', True)
    miscellanea(lb, bg, widget, **misc)
    return lb
예제 #18
0
 def settings_from_widget(self, widget, *args):
     super().settings_from_widget(widget, *args)
     context = widget.current_context
     context.targetClass = getdeepattr(widget, self.targetAttr)
     context.selectedClassifiers = list(getdeepattr(self.selectedAttr))
예제 #19
0
 def save_graph(self):
     graph_obj = getdeepattr(self, self.graph_name, None)
     if graph_obj is None:
         return
     saveplot.save_plot(graph_obj, self.graph_writers)
예제 #20
0
 def settings_from_widget(self, widget):
     super().settings_from_widget(widget)
     context = widget.current_context
     context.targetClass = getdeepattr(widget, self.targetAttr)
     context.selectedClassifiers = list(getdeepattr(self.selectedAttr))