Exemple #1
0
    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 = self.widget()
        self.preferred_size = QtCore.QSize(200, 70)
        inner.setAutoFillBackground(True)
        layout = self.vlayout
        hlayout = box_row(layout)

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

        self.toggle_options = PanelButton(pixmap=qt_prefs.settings_pixmap,
                                          action='toggle_panel',
                                          parent=inner,
                                          size=20).to_layout(hlayout, align=QtCore.Qt.AlignRight)
        self.toggle_options.setFixedSize(26, 26)
        self.toggle_options.setCheckable(True)
        self.toggle_options.data = 'VisualizationOptionsPanel'

        ctrl.main.visualisation_changed.connect(self.update_visualisation)
        self.finish_init()
Exemple #2
0
 def update_visualisation(self):
     if not (ctrl.document and ctrl.forest):
         return
     data = ctrl.forest.vis_data
     if data and 'name' in data:
         index = list(VISUALIZATIONS.keys()).index(data['name'])
         self.selector.setCurrentIndex(index)
Exemple #3
0
    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)
Exemple #4
0
    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)
Exemple #5
0
 def build_visualizations(key, d, widget):
     choices = list(VISUALIZATIONS.keys())
     return Selector(key, widget, choices), False
Exemple #6
0
 def build_visualizations(self, key, d):
     choices = list(VISUALIZATIONS.keys())
     return Selector(key, self, choices), False
Exemple #7
0
    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()
Exemple #8
0
    def __init__(self, parent, ui):
        QtWidgets.QFrame.__init__(self, parent=parent)
        layout = QtWidgets.QHBoxLayout()
        self.show()

        # Left side
        self.edit_mode_button = ModeLabel(['Free drawing', 'Visualisation'],
                                          ui_key='edit_mode_label',
                                          parent=self)
        layout.addWidget(self.edit_mode_button)
        ui.add_ui(self.edit_mode_button)
        ui.connect_element_to_action(self.edit_mode_button, 'switch_edit_mode')

        layout.addStretch(0)

        # Center side

        self.view_mode_button = ModeLabel(['All objects', 'Syntactic only'],
                                          ui_key='view_mode_label',
                                          parent=self, icon=qt_prefs.eye_icon)
        layout.addWidget(self.view_mode_button)
        ui.add_ui(self.view_mode_button)
        ui.connect_element_to_action(self.view_mode_button, 'switch_view_mode')

        layout.addStretch(0)

        view_label = QtWidgets.QLabel("Visualisation:")
        layout.addWidget(view_label)

        #self.vis_mode_buttons = []
        for vkey, vis in VISUALIZATIONS.items():
            shortcut = vis.shortcut
            if shortcut:
                vis_button = VisButton(f'vis_button_{shortcut}', parent=self, text=shortcut,
                                       size=(16, 24))
                ui.add_button(vis_button, action=action_key(vkey))
                vis_button.setCheckable(True)
                layout.addWidget(vis_button)
        layout.addStretch(0)

        # Right side

        self.camera = TopRowButton('print_button', parent=self, tooltip='Print to file',
                              pixmap=qt_prefs.camera_icon, size=(24, 24))
        ui.add_button(self.camera, action='print_pdf')
        layout.addWidget(self.camera)

        undo = TopRowButton('undo_button', parent=self, tooltip='Undo last action',
                            pixmap=qt_prefs.undo_icon)
        ui.add_button(undo, action='undo')
        layout.addWidget(undo)

        redo = TopRowButton('redo_button', parent=self, tooltip='Redo action',
                            pixmap=qt_prefs.redo_icon)
        ui.add_button(redo, action='redo')
        layout.addWidget(redo)

        pan_mode = TopRowButton('pan_mode', parent=self, tooltip='Move mode', size=(24, 24),
                                pixmap=qt_prefs.pan_icon)  # draw_method=drawn_icons.pan_around
        ui.add_button(pan_mode, action='toggle_pan_mode')
        pan_mode.setCheckable(True)
        layout.addWidget(pan_mode)

        select_mode = TopRowButton('select_mode', parent=self, tooltip='Move mode',
                                   pixmap=qt_prefs.cursor_icon,
                                   size=(24, 24))  # draw_method=drawn_icons.select_mode
        select_mode.setCheckable(True)
        ui.add_button(select_mode, action='toggle_select_mode')
        layout.addWidget(select_mode)

        fit_to_screen = TopRowButton('fit_to_screen', parent=self,
                                     tooltip='Fit to view', size=(24, 24),
                                     pixmap=qt_prefs.center_focus_icon)
        # draw_method=drawn_icons.fit_to_screen)
        ui.add_button(fit_to_screen, action='zoom_to_fit')
        layout.addWidget(fit_to_screen)

        full_screen = TopRowButton('full_screen', parent=self,
                                     tooltip='Toggle full screen mode', size=(24, 24),
                                     pixmap=qt_prefs.full_icon)
        # draw_method=drawn_icons.fit_to_screen)
        ui.add_button(full_screen, action='fullscreen_mode')
        layout.addWidget(full_screen)


        layout.setContentsMargins(2, 0, 2, 0)
        self.setLayout(layout)
        self.setMinimumHeight(28)
        self.update_position()
Exemple #9
0
    def __init__(self, parent, ui):
        QtWidgets.QFrame.__init__(self, parent=parent)
        layout = QtWidgets.QHBoxLayout()
        self.show()

        # Left side
        self.play_button = TwoStateIconButton(ui_key='play_button',
                                              parent=self,
                                              pixmap0=qt_prefs.pause_pixmap,
                                              pixmap1=qt_prefs.play_pixmap,
                                              size=36,
                                              action='play_animations').to_layout(layout)

        self.record_button = TwoStateIconButton(ui_key='record_button',
                                                parent=self,
                                                pixmap0=qt_prefs.record_pixmap,
                                                pixmap1=qt_prefs.stop_pixmap,
                                                color0=ctrl.cm.red,
                                                color1=ctrl.cm.red,
                                                size=24,
                                                action='toggle_recording').to_layout(layout)

        layout.addStretch(0)

        view_label = QtWidgets.QLabel("Visualisation:")
        layout.addWidget(view_label)

        default_vis = prefs.visualization
        self.vis_buttons = KatajaButtonGroup(parent=self)
        for vkey, vis in VISUALIZATIONS.items():
            shortcut = vis.shortcut
            if shortcut:
                vis_button = VisButton(ui_key=f'vis_button_{shortcut}', parent=self, text=shortcut,
                                       size=(16, 24), subtype=vkey, shortcut=shortcut,
                                       tooltip=vis.name).to_layout(layout)
                self.vis_buttons.addButton(vis_button)
                vis_button.setChecked(vkey == default_vis)
        ui.connect_element_to_action(self.vis_buttons, 'set_visualization')
        layout.addStretch(0)

        # Right side

        self.camera = TopRowButton(ui_key='print_button', parent=self, pixmap=qt_prefs.camera_icon,
                                   size=(24, 24), action='print_pdf').to_layout(layout)

        undo = TopRowButton(ui_key='undo_button', parent=self, pixmap=qt_prefs.undo_icon,
                            action='undo').to_layout(layout)

        redo = TopRowButton(ui_key='redo_button', parent=self, pixmap=qt_prefs.redo_icon,
                            action='redo').to_layout(layout)

        pan_mode = TopRowButton(ui_key='pan_mode', parent=self, size=(24, 24),
                                pixmap=qt_prefs.pan_icon, action='toggle_pan_mode').to_layout(
            layout)
        pan_mode.setCheckable(True)

        select_mode = TopRowButton(ui_key='select_mode', parent=self, pixmap=qt_prefs.cursor_icon,
                                   size=(24, 24), action='toggle_select_mode').to_layout(layout)
        select_mode.setCheckable(True)

        full_screen = TopRowButton(ui_key='full_screen', parent=self, size=(24, 24),
                                   pixmap=qt_prefs.full_icon, action='fullscreen_mode',
                                   ).to_layout(layout)

        automatic_zoom = TopRowButton(ui_key='auto_zoom', parent=self, size=(24, 24),
                                      pixmap=qt_prefs.autozoom_icon,
                                      action='auto_zoom', ).to_layout(layout)

        fit_to_screen = TopRowButton(ui_key='fit_to_screen', parent=self, size=(24, 24),
                                     pixmap=qt_prefs.center_focus_icon,
                                     action='zoom_to_fit', ).to_layout(layout)

        layout.setContentsMargins(2, 0, 2, 0)
        self.setLayout(layout)
        self.setMinimumHeight(36)
        self.update_position()
Exemple #10
0
 def build_visualizations(key, d, widget):
     choices = list(VISUALIZATIONS.keys())
     return Selector(key, widget, choices), False
Exemple #11
0
    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()