Ejemplo n.º 1
0
class SyntaxPanel(Panel):
    """ Switch between trees or derivation steps """
    def __init__(self,
                 name,
                 default_position='bottom',
                 parent=None,
                 folded=False):
        """
        All of the panel constructors follow the same format so that the construction can be automated.
        :param name: Title of the panel and the key for accessing it
        :param default_position: 'bottom', 'right'...
        :param parent: self.main
        :param ui_manager: pass a dictionary where buttons from this panel will be added
        """
        Panel.__init__(self, name, default_position, parent, folded)
        inner = QtWidgets.QWidget()
        inner.setMinimumHeight(40)
        inner.setMaximumHeight(50)
        inner.preferred_size = QtCore.QSize(220, 40)
        inner.sizeHint = self.sizeHint

        layout = QtWidgets.QVBoxLayout()
        hlayout = QtWidgets.QHBoxLayout()
        hlayout.setContentsMargins(0, 0, 0, 0)

        selector = SelectionBox(self)
        self.selector = selector
        for key, item in []:
            selector.addItem('%s (%s)' % (key, item.shortcut), key)

        self.ui_manager.connect_element_to_action(selector,
                                                  'set_visualization')
        hlayout.addWidget(selector)
        self.toggle_options = PanelButton(pixmap=qt_prefs.settings_pixmap,
                                          tooltip='Visualization settings',
                                          parent=self,
                                          size=20)
        self.toggle_options.setFixedSize(26, 26)
        self.toggle_options.setCheckable(True)
        ctrl.ui.connect_element_to_action(self.toggle_options,
                                          'toggle_panel_%s' % g.VIS_OPTIONS)
        hlayout.addWidget(self.toggle_options, 1, QtCore.Qt.AlignRight)

        layout.addLayout(hlayout)
        inner.setLayout(layout)
        self.watchlist = ['forest_changed']
        self.preferred_size = inner.preferred_size
        self.setWidget(inner)
        self.widget().setAutoFillBackground(True)
        self.finish_init()

    def watch_alerted(self, obj, signal, field_name, value):
        """ Receives alerts from signals that this object has chosen to listen. These signals
         are declared in 'self.watchlist'.

         This method will try to sort out the received signals and act accordingly.

        :param obj: the object causing the alarm
        :param signal: identifier for type of the alarm
        :param field_name: name of the field of the object causing the alarm
        :param value: value given to the field
        :return:
        """
        if signal == 'forest_changed':
            keeper = ctrl.main.forest_keeper
            if keeper is not None:
                display_index = keeper.current_index + 1
                max_index = len(keeper.forests)
                self.treeset_counter.setText('%s/%s' %
                                             (display_index, max_index))
Ejemplo n.º 2
0
class SyntaxPanel(Panel):
    """ Switch between trees or derivation steps """

    def __init__(self, name, default_position="bottom", parent=None, folded=False):
        """
        All of the panel constructors follow the same format so that the construction can be automated.
        :param name: Title of the panel and the key for accessing it
        :param default_position: 'bottom', 'right'...
        :param parent: self.main
        :param ui_manager: pass a dictionary where buttons from this panel will be added
        """
        Panel.__init__(self, name, default_position, parent, folded)
        inner = QtWidgets.QWidget()
        inner.setMinimumHeight(40)
        inner.setMaximumHeight(50)
        inner.preferred_size = QtCore.QSize(220, 40)
        inner.sizeHint = self.sizeHint

        layout = QtWidgets.QVBoxLayout()
        hlayout = QtWidgets.QHBoxLayout()
        hlayout.setContentsMargins(0, 0, 0, 0)

        selector = SelectionBox(self)
        self.selector = selector
        for key, item in []:
            selector.addItem("%s (%s)" % (key, item.shortcut), key)

        self.ui_manager.connect_element_to_action(selector, "set_visualization")
        hlayout.addWidget(selector)
        self.toggle_options = PanelButton(
            pixmap=qt_prefs.settings_pixmap, tooltip="Visualization settings", parent=self, size=20
        )
        self.toggle_options.setFixedSize(26, 26)
        self.toggle_options.setCheckable(True)
        ctrl.ui.connect_element_to_action(self.toggle_options, "toggle_panel_%s" % g.VIS_OPTIONS)
        hlayout.addWidget(self.toggle_options, 1, QtCore.Qt.AlignRight)

        layout.addLayout(hlayout)
        inner.setLayout(layout)
        self.watchlist = ["forest_changed"]
        self.preferred_size = inner.preferred_size
        self.setWidget(inner)
        self.widget().setAutoFillBackground(True)
        self.finish_init()

    def watch_alerted(self, obj, signal, field_name, value):
        """ Receives alerts from signals that this object has chosen to listen. These signals
         are declared in 'self.watchlist'.

         This method will try to sort out the received signals and act accordingly.

        :param obj: the object causing the alarm
        :param signal: identifier for type of the alarm
        :param field_name: name of the field of the object causing the alarm
        :param value: value given to the field
        :return:
        """
        if signal == "forest_changed":
            keeper = ctrl.main.forest_keeper
            if keeper is not None:
                display_index = keeper.current_index + 1
                max_index = len(keeper.forests)
                self.treeset_counter.setText("%s/%s" % (display_index, max_index))
Ejemplo n.º 3
0
class VisualizationPanel(Panel):
    """ Switch visualizations and adjust their settings """


    def __init__(self, name, default_position='right', parent=None, folded=False):
        """
        All of the panel constructors follow the same format so that the construction can be automated.
        :param name: Title of the panel and the key for accessing it
        :param default_position: 'bottom', 'right'...
        :param parent: self.main
        """
        Panel.__init__(self, name, default_position, parent, folded)
        inner = QtWidgets.QWidget()
        inner.preferred_size = QtCore.QSize(200, 70)
        inner.setMaximumWidth(220)
        inner.setMaximumHeight(80)
        inner.sizeHint = self.sizeHint

        layout = QtWidgets.QVBoxLayout()
        hlayout = QtWidgets.QHBoxLayout()

        self.selector = SelectionBox(self)
        self.selector.add_items([('%s (%s)' % (key, item.shortcut), key) for key, item in
                                 VISUALIZATIONS.items()])

        self.ui_manager.connect_element_to_action(self.selector, 'set_visualization')
        hlayout.addWidget(self.selector)
        self.toggle_options = PanelButton(pixmap=qt_prefs.settings_pixmap,
                                          parent=self, size=20)
        self.toggle_options.setFixedSize(26, 26)
        self.toggle_options.setCheckable(True)
        ctrl.ui.connect_element_to_action(self.toggle_options,
                                          'toggle_panel_VisualizationOptionsPanel')
        hlayout.addWidget(self.toggle_options, 1, QtCore.Qt.AlignRight)

        layout.addLayout(hlayout)

        hlayout = QtWidgets.QHBoxLayout()
        w = 36
        b1 = PanelButton(pixmap=qt_prefs.shape_icon_plain, parent=self, size=24)
        b1.setFixedWidth(w)
        b1.setCheckable(True)
        ctrl.ui.connect_element_to_action(b1, 'set_no_frame_node_shape')
        hlayout.addWidget(b1)
        b2 = PanelButton(pixmap=qt_prefs.shape_icon_scope, parent=self, size=24)
        b2.setFixedWidth(w)
        b2.setCheckable(True)
        ctrl.ui.connect_element_to_action(b2, 'set_scopebox_node_shape')
        hlayout.addWidget(b2)
        b3 = PanelButton(pixmap=qt_prefs.shape_icon_brackets, parent=self, size=24)
        b3.setFixedWidth(w)
        b3.setCheckable(True)
        ctrl.ui.connect_element_to_action(b3, 'set_bracketed_node_shape')
        hlayout.addWidget(b3)
        b4 = PanelButton(pixmap=qt_prefs.shape_icon_box, parent=self, size=24)
        b4.setFixedWidth(w)
        b4.setCheckable(True)
        ctrl.ui.connect_element_to_action(b4, 'set_box_node_shape')
        hlayout.addWidget(b4)
        b5 = PanelButton(pixmap=qt_prefs.shape_icon_card, parent=self, size=24)
        b5.setFixedWidth(w)
        b5.setCheckable(True)
        ctrl.ui.connect_element_to_action(b5, 'set_card_node_shape')
        hlayout.addWidget(b5)
        layout.addLayout(hlayout)
        #layout.setContentsMargins(0, 0, 0, 0)
        inner.setLayout(layout)
        self.watchlist = ['visualization']
        self.preferred_size = inner.preferred_size
        self.setWidget(inner)
        inner.setAutoFillBackground(True)
        self.finish_init()

    def showEvent(self, event):
        """ Panel may have missed signals to update its contents when it was hidden: update all
        that signals would update.
        :param event:
        :return:
        """
        # ??
        super().showEvent(event)

    def watch_alerted(self, obj, signal, field_name, value):
        """ Receives alerts from signals that this object has chosen to listen. These signals
         are declared in 'self.watchlist'.

         This method will try to sort out the received signals and act accordingly.

        :param obj: the object causing the alarm
        :param signal: identifier for type of the alarm
        :param field_name: name of the field of the object causing the alarm
        :param value: value given to the field
        :return:
        """
        if signal == 'visualization':
            if value and 'name' in value:
                index = list(VISUALIZATIONS.keys()).index(value['name'])
                self.selector.setCurrentIndex(index)

    def sizeHint(self):
        #print("VisualizationPanel asking for sizeHint, ", self.preferred_size)
        return self.preferred_size
Ejemplo n.º 4
0
class VisualizationPanel(Panel):
    """ Switch visualizations and adjust their settings """
    def __init__(self,
                 name,
                 default_position='right',
                 parent=None,
                 folded=False):
        """
        All of the panel constructors follow the same format so that the construction can be automated.
        :param name: Title of the panel and the key for accessing it
        :param default_position: 'bottom', 'right'...
        :param parent: self.main
        """
        Panel.__init__(self, name, default_position, parent, folded)
        inner = QtWidgets.QWidget()
        inner.preferred_size = QtCore.QSize(200, 70)
        inner.setMaximumWidth(220)
        inner.setMaximumHeight(80)
        inner.sizeHint = self.sizeHint

        layout = QtWidgets.QVBoxLayout()
        hlayout = QtWidgets.QHBoxLayout()

        self.selector = SelectionBox(self)
        self.selector.add_items([('%s (%s)' % (key, item.shortcut), key)
                                 for key, item in VISUALIZATIONS.items()])

        self.ui_manager.connect_element_to_action(self.selector,
                                                  'set_visualization')
        hlayout.addWidget(self.selector)
        self.toggle_options = PanelButton(pixmap=qt_prefs.settings_pixmap,
                                          parent=self,
                                          size=20)
        self.toggle_options.setFixedSize(26, 26)
        self.toggle_options.setCheckable(True)
        ctrl.ui.connect_element_to_action(
            self.toggle_options, 'toggle_panel_VisualizationOptionsPanel')
        hlayout.addWidget(self.toggle_options, 1, QtCore.Qt.AlignRight)

        layout.addLayout(hlayout)

        hlayout = QtWidgets.QHBoxLayout()
        w = 36
        b1 = PanelButton(pixmap=qt_prefs.shape_icon_plain,
                         parent=self,
                         size=24)
        b1.setFixedWidth(w)
        b1.setCheckable(True)
        ctrl.ui.connect_element_to_action(b1, 'set_no_frame_node_shape')
        hlayout.addWidget(b1)
        b2 = PanelButton(pixmap=qt_prefs.shape_icon_scope,
                         parent=self,
                         size=24)
        b2.setFixedWidth(w)
        b2.setCheckable(True)
        ctrl.ui.connect_element_to_action(b2, 'set_scopebox_node_shape')
        hlayout.addWidget(b2)
        b3 = PanelButton(pixmap=qt_prefs.shape_icon_brackets,
                         parent=self,
                         size=24)
        b3.setFixedWidth(w)
        b3.setCheckable(True)
        ctrl.ui.connect_element_to_action(b3, 'set_bracketed_node_shape')
        hlayout.addWidget(b3)
        b4 = PanelButton(pixmap=qt_prefs.shape_icon_box, parent=self, size=24)
        b4.setFixedWidth(w)
        b4.setCheckable(True)
        ctrl.ui.connect_element_to_action(b4, 'set_box_node_shape')
        hlayout.addWidget(b4)
        b5 = PanelButton(pixmap=qt_prefs.shape_icon_card, parent=self, size=24)
        b5.setFixedWidth(w)
        b5.setCheckable(True)
        ctrl.ui.connect_element_to_action(b5, 'set_card_node_shape')
        hlayout.addWidget(b5)
        layout.addLayout(hlayout)
        #layout.setContentsMargins(0, 0, 0, 0)
        inner.setLayout(layout)
        self.watchlist = ['visualization']
        self.preferred_size = inner.preferred_size
        self.setWidget(inner)
        inner.setAutoFillBackground(True)
        self.finish_init()

    def showEvent(self, event):
        """ Panel may have missed signals to update its contents when it was hidden: update all
        that signals would update.
        :param event:
        :return:
        """
        # ??
        super().showEvent(event)

    def watch_alerted(self, obj, signal, field_name, value):
        """ Receives alerts from signals that this object has chosen to listen. These signals
         are declared in 'self.watchlist'.

         This method will try to sort out the received signals and act accordingly.

        :param obj: the object causing the alarm
        :param signal: identifier for type of the alarm
        :param field_name: name of the field of the object causing the alarm
        :param value: value given to the field
        :return:
        """
        if signal == 'visualization':
            if value and 'name' in value:
                index = list(VISUALIZATIONS.keys()).index(value['name'])
                self.selector.setCurrentIndex(index)

    def sizeHint(self):
        #print("VisualizationPanel asking for sizeHint, ", self.preferred_size)
        return self.preferred_size