Example #1
0
class ComputeWidget(QWidget):
    def __init__(self, parent):
        super(ComputeWidget, self).__init__(parent)

        self.input = QueryInput(self)
        self.exec = QPushButton(self)
        self.grid = QGridLayout(self)
        self.target = QLineEdit(self)
        self.ui()
        self.properties()

        self.exec.clicked.connect(self.execute)

    def execute(self):
        query = Query(select=self.input.toPlainText())
        query.execute()
        if query.error == Query.NoError:
            var_name = self.target.text().strip()
            column = None
            new_column = False
            if var_name:
                logger.debug("var_name={}".format(var_name))
                column = Column.get_by_name(var_name)

            if not column:
                column = Column(Column.count(), name=var_name)
                new_column = True

            logger.debug("new_column={}".format(new_column))

            for row, data in query.result.items():
                if new_column:
                    Cell(row, column.id, data=data)
                else:
                    cell = Cell.get(row, column.id)
                    cell.data = data

    def properties(self):
        self.input.setPlaceholderText("Query")
        self.exec.setText("Execute")
        self.target.setPlaceholderText("Target Variable")

    def ui(self):
        self.grid.addWidget(self.input, 1, 0, 1, 10)
        self.grid.addWidget(self.exec, 2, 5, 1, 5)
        self.grid.addWidget(self.target, 0, 0, 1, 10)

    def events(self):
        self.exec.clicked.connect(self.execute)
Example #2
0
class QueryWidget(QWidget):
    def __init__(self, parent):
        super(QueryWidget, self).__init__(parent)

        self.input = QueryInput(self)

        self.lbl_color = QLabel(self)
        self.color = ColorWidget(self, Query.DefaultColor)
        self.exec = QPushButton(self)
        # self.history = QueryHistoryWidget(self)
        self.grid = QGridLayout(self)

        self.ui()
        self.properties()

        self.exec.clicked.connect(self.execute)

    def execute(self):
        # color = self.color.color.name(QtGui.QColor.HexRgb)
        query = Query(self.input.toPlainText())
        query.execute()
        if query.error == Query.NoError:
            selection = Selection()
            selection.query = query
            DataView.Model.headerDataChanged.emit(Qt.Vertical, 0, Row.count())

    def properties(self):
        self.input.setPlaceholderText("Query")
        self.lbl_color.setText("Color:")
        self.exec.setText("Execute")

    def ui(self):
        self.grid.addWidget(self.input, 0, 0, 1, 10)
        self.grid.addWidget(self.lbl_color, 1, 0, 1, 1, Qt.AlignRight)
        self.grid.addWidget(self.color, 1, 1, 0, 4)
        self.grid.addWidget(self.exec, 1, 5, 1, 5)