Exemple #1
0
    def __init__(self, parent, module, pos):
        super().__init__(parent)
        self.module = module
        self.parent = parent

        self.move(pos)

        raw_json = module.to_json()
        stripped_json = module.to_stripped_dict()
        input_dict = self.module.get_input_names()
        output_dict = self.module.get_output_names()

        panel_layout = QGridLayout(self)
        panel_layout.cellRect(max(len(input_dict), len(stripped_json)) + 1, 6)

        lbl = QLabel(raw_json['type'].replace('Module', ''))
        panel_layout.addWidget(lbl, 0, 0, 1, 4)

        self.input_lbls = {}
        self.output_lbls = {}

        for index, inp in enumerate(input_dict):
            lbl = QArgPushButton(input_dict[inp], inp)
            p = lbl.palette()
            p.setColor(lbl.backgroundRole(), QtGui.QColor(63, 82, 255))
            lbl.setPalette(p)
            lbl.setAutoFillBackground(True)
            panel_layout.addWidget(lbl, index + 1, 0, 1, 1)
            self.input_lbls[inp] = lbl

            def on_click(btn):
                self.parent.select(btn)

            lbl.callback = on_click

        for index, prop in enumerate(stripped_json):
            sl = property_widgets[stripped_json[prop]['type']](self,
                                                               getattr(
                                                                   self.module,
                                                                   prop), prop)
            if len(input_dict) > 0:
                panel_layout.addWidget(sl, index + 1, 1, 1, 5)
            elif len(input_dict) == 0:
                panel_layout.addWidget(sl, index + 1, 0, 1, 6)

        for index, out in enumerate(output_dict):
            lbl = QArgPushButton(output_dict[out], out)
            p = lbl.palette()
            p.setColor(lbl.backgroundRole(), QtGui.QColor(255, 104, 112))
            lbl.setPalette(p)
            lbl.setAutoFillBackground(True)
            panel_layout.addWidget(lbl, index, 5, 1, 1)
            self.output_lbls[out] = lbl

            def on_click(btn):
                self.parent.select(btn)

            lbl.callback = on_click

        width = 0
        if len(input_dict) > 0:
            width += 60 * 2
        if len(stripped_json) > 0:
            width += 300

        height = (max(len(input_dict), len(stripped_json)) + 1) * 45
        self.setGeometry(pos.x(), pos.y(), width, height)

        self.show()