Ejemplo n.º 1
0
    def __init__(self, parent, adjacency):

        QWidget.__init__(self, parent)
        # self.main = parent # Spyder3

        # Create main widget
        self.model = MxAnalyzerModel(adjacency=adjacency,
                                     root=None,
                                     parent=self)
        # from .modeltest import ModelTest
        # self.modeltest = ModelTest(self.model, self)
        self.tree = MxAnalyzerTree(self, self.model)
        self.shellwidget = None  # Set by parent

        # Layout of the top area in the plugin widget
        layout_top = QHBoxLayout()
        layout_top.setContentsMargins(0, 0, 0, 0)

        # Add Object textbox
        layout_top.addSpacing(10)
        txt = _("Object")
        if sys.platform == 'darwin':
            obj_label = QLabel("  " + txt)
        else:
            obj_label = QLabel(txt)
        layout_top.addWidget(obj_label)

        if spyder.version_info < (4, ):
            font = parent.plugin.get_plugin_font()
        else:
            font = parent.plugin.get_font()

        self.objbox = MxPyExprLineEdit(self, font=font)
        layout_top.addWidget(self.objbox)
        layout_top.addSpacing(10)

        # Add Object textbox
        txt = _("Args")
        if sys.platform == 'darwin':
            arg_label = QLabel("  " + txt)
        else:
            arg_label = QLabel(txt)
        layout_top.addWidget(arg_label)

        self.argbox = MxPyExprLineEdit(self, font=font)
        layout_top.addWidget(self.argbox)
        layout_top.addSpacing(10)

        # Main layout of this widget
        layout = create_plugin_layout(layout_top, self.tree)
        self.setLayout(layout)
Ejemplo n.º 2
0
    def setup_toolbar(self):

        txt = _("Expression")
        if sys.platform == 'darwin':
            expr_label = QLabel("  " + txt)
        else:
            expr_label = QLabel(txt)

        if spyder.version_info < (4, ):
            font = self.plugin.get_plugin_font()
        else:
            font = self.plugin.get_font()

        self.exprbox = MxPyExprLineEdit(self, font=font)

        return [expr_label, self.exprbox]
Ejemplo n.º 3
0
    def __init__(self, parent, adjacency):

        QSplitter.__init__(self, parent, orientation=Qt.Vertical)

        self.plugin = parent.plugin
        self.adjacency = adjacency

        treepane = QWidget(parent=self)

        # Create main widget
        self.model = MxAnalyzerModel(
            adjacency=adjacency,
            root=None,
            parent=self     # parent must be self,
                            # because self.model access self.tab
        )
        # from .modeltest import ModelTest
        # self.modeltest = ModelTest(self.model, self)
        self.tree = MxAnalyzerTree(treepane, self.model)
        self.shellwidget = None # Set by parent

        button_group = QButtonGroup(parent=self)
        self.object_radio = object_radio = QRadioButton("Object")
        self.expr_radio = expr_radio = QRadioButton("Expression")
        button_group.addButton(object_radio)
        button_group.addButton(expr_radio)
        object_radio.setChecked(True)

        object_radio.toggled.connect(self.toggleObject)

        # Layout of the top area in the plugin widget
        expr_layout = QHBoxLayout()
        expr_layout.setContentsMargins(0, 0, 0, 0)

        # Add Object textbox
        expr_layout.addSpacing(10)
        txt = _("Object")
        if sys.platform == 'darwin':
            obj_label = QLabel("  " + txt)
        else:
            obj_label = QLabel(txt)
        expr_layout.addWidget(obj_label)

        if spyder.version_info < (4,):
            font = parent.plugin.get_plugin_font()
        else:
            font = parent.plugin.get_font()

        self.objbox = QLabel(parent=self)
        self.argbox = MxPyExprLineEdit(self, font=font)
        self.attrdict = None

        objbox_layout = QHBoxLayout()
        objbox_layout.addWidget(self.objbox)
        objbox_layout.addWidget(self.argbox)
        objbox_layout.setStretch(0, 3)  # 3:1
        objbox_layout.setStretch(1, 1)

        self.exprobjbox = MxPyExprLineEdit(treepane, font=font)
        expr_layout.addWidget(self.exprobjbox)
        expr_layout.addSpacing(10)

        # Add Object textbox
        txt = _("Args")
        if sys.platform == 'darwin':
            arg_label = QLabel("  " + txt)
        else:
            arg_label = QLabel(txt)
        expr_layout.addWidget(arg_label)

        self.exprargbox = MxPyExprLineEdit(treepane, font=font)
        expr_layout.addWidget(self.exprargbox)
        # expr_layout.addSpacing(5)

        top_layout = QGridLayout()
        top_layout.addWidget(object_radio, 0, 0)
        top_layout.addWidget(expr_radio, 1, 0)
        top_layout.addLayout(objbox_layout, 0, 1)
        objbox_layout.setContentsMargins(0, 0, 0, 5)
        top_layout.addLayout(expr_layout, 1, 1)
        top_layout.setContentsMargins(5, 5, 5, 5)

        # Main layout of this widget
        layout = create_plugin_layout(top_layout, self.tree)
        treepane.setLayout(layout)

        self.status = QLabel()
        layout.addWidget(self.status)

        self.codepane = AnalyzerCodePane(parent=self)
Ejemplo n.º 4
0
        def __init__(self, parent, **kwargs):
            QWidget.__init__(self, parent)

            self.plugin = parent.get_plugin()
            # self.plugin_actions = []

            #         outer_layout
            #        +----------------------------------------------|-----------+
            #        |   inner_layout                               |           |
            #        |  +---------|-----------------------------+   |           |
            #  upper |  |         | +----------------------+    |   |           |
            # layout |  |obj_radio| |objbox_layout         |    |   |           |
            #        |  |         | +----------------------+    |   |  update   |
            #        |  -----------------------------------------   |  button   |
            #        |  |   expr  |                             |   |           |
            #        |  |   radio |  exprbox                    |   |           |
            #        |  +---------|-----------------------------+   |           |
            #        |                                              |           |
            #        -----------------------------------------------|------------
            #        |                                                          |
            #        |   msgbox                                                 |
            #        |                                                          |
            #        +----------------------------------------------------------+
            #

            button_group = QButtonGroup(parent=self)
            self.object_radio = object_radio = QRadioButton("Object")
            self.expr_radio = expr_radio = QRadioButton("Expression")
            button_group.addButton(object_radio)
            button_group.addButton(expr_radio)

            object_radio.toggled.connect(self.activateObject)
            expr_radio.toggled.connect(self.activateExpression)

            update_button = QPushButton(text="Update", parent=self)
            update_button.clicked.connect(self.update_data)

            # txt = _("Expression")
            # if sys.platform == 'darwin':
            #     expr_label = QLabel("  " + txt)
            # else:
            #     expr_label = QLabel(txt)

            font = self.plugin.get_font()

            self.exprbox = MxPyExprLineEdit(self, font=font)
            self.objbox = QLabel(parent=self)
            self.argbox = MxPyExprLineEdit(self, font=font)
            self.msgbox = QLabel(parent=self)
            self.msgbox.setText("")
            self.msgbox.setWordWrap(True)

            outer_layout = QVBoxLayout()
            upper_layout = QHBoxLayout()
            outer_layout.addLayout(upper_layout)
            outer_layout.addWidget(self.msgbox)

            inner_layout = QGridLayout()
            inner_layout.addWidget(object_radio, 0, 0)
            inner_layout.addWidget(expr_radio, 1, 0)
            inner_layout.addWidget(self.exprbox, 1, 1)
            objbox_layout = QHBoxLayout()
            objbox_layout.addWidget(self.objbox)
            objbox_layout.addWidget(self.argbox)
            objbox_layout.setStretch(0, 3)  # 3:1
            objbox_layout.setStretch(1, 1)
            inner_layout.addLayout(objbox_layout, 0, 1)

            upper_layout.addLayout(inner_layout)
            upper_layout.addWidget(update_button)

            # widget = QWidget(parent=self)
            # widget.setLayout(outer_layout)

            # Create main widget
            self.widget = QWidget(parent=self)  # MxDataFrameViewer(self)

            self.main_layout = main_layout = QVBoxLayout()
            main_layout.addLayout(outer_layout)
            main_layout.addWidget(self.widget)
            main_layout.setStretch(1, 1)

            # Main layout of this widget
            # layout = create_plugin_layout(self.tools_layout)
            # layout.addLayout(main_layout)

            margins = (0, 0, 0, 0)

            for lo in [outer_layout, upper_layout, inner_layout, self.msgbox]:
                lo.setContentsMargins(*margins)

            objbox_layout.setContentsMargins(0, 0, 0, 0)

            self.setLayout(main_layout)

            self.attrdict = None
            object_radio.setChecked(True)
Ejemplo n.º 5
0
    class MxDataViewWidget(QWidget):
        def __init__(self, parent, **kwargs):
            QWidget.__init__(self, parent)

            self.plugin = parent.get_plugin()
            # self.plugin_actions = []

            #         outer_layout
            #        +----------------------------------------------|-----------+
            #        |   inner_layout                               |           |
            #        |  +---------|-----------------------------+   |           |
            #  upper |  |         | +----------------------+    |   |           |
            # layout |  |obj_radio| |objbox_layout         |    |   |           |
            #        |  |         | +----------------------+    |   |  update   |
            #        |  -----------------------------------------   |  button   |
            #        |  |   expr  |                             |   |           |
            #        |  |   radio |  exprbox                    |   |           |
            #        |  +---------|-----------------------------+   |           |
            #        |                                              |           |
            #        -----------------------------------------------|------------
            #        |                                                          |
            #        |   msgbox                                                 |
            #        |                                                          |
            #        +----------------------------------------------------------+
            #

            button_group = QButtonGroup(parent=self)
            self.object_radio = object_radio = QRadioButton("Object")
            self.expr_radio = expr_radio = QRadioButton("Expression")
            button_group.addButton(object_radio)
            button_group.addButton(expr_radio)

            object_radio.toggled.connect(self.activateObject)
            expr_radio.toggled.connect(self.activateExpression)

            update_button = QPushButton(text="Update", parent=self)
            update_button.clicked.connect(self.update_data)

            # txt = _("Expression")
            # if sys.platform == 'darwin':
            #     expr_label = QLabel("  " + txt)
            # else:
            #     expr_label = QLabel(txt)

            font = self.plugin.get_font()

            self.exprbox = MxPyExprLineEdit(self, font=font)
            self.objbox = QLabel(parent=self)
            self.argbox = MxPyExprLineEdit(self, font=font)
            self.msgbox = QLabel(parent=self)
            self.msgbox.setText("")
            self.msgbox.setWordWrap(True)

            outer_layout = QVBoxLayout()
            upper_layout = QHBoxLayout()
            outer_layout.addLayout(upper_layout)
            outer_layout.addWidget(self.msgbox)

            inner_layout = QGridLayout()
            inner_layout.addWidget(object_radio, 0, 0)
            inner_layout.addWidget(expr_radio, 1, 0)
            inner_layout.addWidget(self.exprbox, 1, 1)
            objbox_layout = QHBoxLayout()
            objbox_layout.addWidget(self.objbox)
            objbox_layout.addWidget(self.argbox)
            objbox_layout.setStretch(0, 3)  # 3:1
            objbox_layout.setStretch(1, 1)
            inner_layout.addLayout(objbox_layout, 0, 1)

            upper_layout.addLayout(inner_layout)
            upper_layout.addWidget(update_button)

            # widget = QWidget(parent=self)
            # widget.setLayout(outer_layout)

            # Create main widget
            self.widget = QWidget(parent=self)  # MxDataFrameViewer(self)

            self.main_layout = main_layout = QVBoxLayout()
            main_layout.addLayout(outer_layout)
            main_layout.addWidget(self.widget)
            main_layout.setStretch(1, 1)

            # Main layout of this widget
            # layout = create_plugin_layout(self.tools_layout)
            # layout.addLayout(main_layout)

            margins = (0, 0, 0, 0)

            for lo in [outer_layout, upper_layout, inner_layout, self.msgbox]:
                lo.setContentsMargins(*margins)

            objbox_layout.setContentsMargins(0, 0, 0, 0)

            self.setLayout(main_layout)

            self.attrdict = None
            object_radio.setChecked(True)

            # self.calc_on_update = create_action(self,
            #     _("Calculate upon update"),
            #     tip=_("Calculate the selected cells if not yet calculated"))
            # self.calc_on_update.setChecked(True)
            #
            # self.actions = [self.calc_on_update]

        def set_shellwidget(self, shellwidget):
            """Bind shellwidget instance to namespace browser"""
            self.shellwidget = shellwidget
            self.shellwidget.set_mxdataview(self)

        def activateObject(self, checked):
            self.argbox.setEnabled(checked)
            self.exprbox.setEnabled(not checked)

        def activateExpression(self, checked):
            self.argbox.setEnabled(not checked)
            self.exprbox.setEnabled(checked)

        def update_object(self, data):
            if data is None:
                return

            self.attrdict = data
            if data["type"] == 'Reference' or (data["type"] == "Cells"
                                               and not data["parameters"]):
                self.argbox.setText("")
                self.argbox.setEnabled(False)
            else:
                self.argbox.setEnabled(True)

            self.objbox.setText(data['_evalrepr'])

        def update_data(self):
            if self.object_radio.isChecked():

                argtxt = self.argbox.get_expr()
                args = "(" + argtxt + ("," if argtxt else "") + ")"
                # assert
                ast.literal_eval(args)

                calc = self.plugin.get_container(
                ).calc_on_update_action.isChecked()

                val, is_calculated = self.shellwidget.update_mxdataview(
                    is_obj=True,
                    obj=self.attrdict["fullname"],
                    args=args,
                    calc=calc)
                self.update_value(val)
                if is_calculated:
                    self.shellwidget.refresh_namespacebrowser()

            elif self.expr_radio.isChecked():
                self.shellwidget.update_mxdataview(
                    is_obj=False, expr=self.exprbox.get_expr())
                self.shellwidget.refresh_namespacebrowser()
            else:
                raise RuntimeError("MxDataViewer: must not happen")

        def update_value(self, data):

            import pandas as pd
            import numpy as np
            import numpy.ma

            if isinstance(data, (pd.DataFrame, pd.Index, pd.Series)):
                self.widget.deleteLater()
                self.widget = MxDataFrameViewer(self)
                self.widget.setup_and_check(data)
                self.msgbox.setText(data.__class__.__name__)
            elif isinstance(data, (np.ndarray, np.ma.MaskedArray)):
                self.widget.deleteLater()
                self.widget = MxArrayViewer(self)
                self.widget.setup_and_check(data, title='', readonly=True)
                self.msgbox.setText(data.__class__.__name__)
            elif isinstance(data, (list, set, tuple, dict)):
                self.widget.deleteLater()
                self.widget = MxCollectionsViewer(self)
                self.widget.setup(data, title='', readonly=True)
                self.msgbox.setText(data.__class__.__name__)
            else:
                txt = data.__class__.__name__ + ": " + repr(data)
                self.widget.deleteLater()
                self.widget = QWidget(parent=self)
                self.msgbox.setText(txt)

            self.main_layout.addWidget(self.widget)
            self.main_layout.setStretchFactor(self.widget, 1)