File: owProduct.py

package info (click to toggle)
orange3 3.40.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,908 kB
  • sloc: python: 162,745; ansic: 622; makefile: 322; sh: 93; cpp: 77
file content (47 lines) | stat: -rw-r--r-- 1,233 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from Orange.widgets import widget, gui
from Orange.widgets.settings import Setting


class OWProduct(widget.OWWidget):
    name = "Product"
    id = "orange.widgets.data.multiplier"
    description = ""
    icon = "icons/Unknown.svg"
    priority = 10
    category = ""
    keywords = ["list", "of", "keywords"]
    outputs = [("Product", int)]
    inputs = [("First factor", int, "get_first"), ("Second factor", int, "get_second")]

    want_main_area = False

    def __init__(self):
        super().__init__()

        self.first = self.second = None
        self.product = None

        self.result = gui.label(
            self.controlArea,
            self,
            "%(first)s times %(second)s is %(product)s",
            box="Result",
        )
        self.result.hide()

    def get_first(self, n):
        self.first = n
        self.do_multiply()

    def get_second(self, n):
        self.second = n
        self.do_multiply()

    def do_multiply(self):
        if self.first and self.second is None:
            self.result.hide()
            self.send("Product", None)
        else:
            self.result.show()
            self.product = self.first * self.second
            self.send("Product", self.product)