Esempio n. 1
0
    def add_tool_bar_actions(self, icon_path, name="", category=None,
                             description="", priority=0, enabled=True,
                             callback=None, menu=None):
        icon = QIcon(icon_path)

        if menu is not None:
            tool_button = QToolButton()
            tool_button.setPopupMode(QToolButton.MenuButtonPopup)

            menu_widget = self._dict_to_menu(menu)

            tool_button.setMenu(menu_widget)
            tool_button.setIcon(icon)
            tool_button.setText(name)
            tool_button.setStatusTip(description)
            tool_button.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)

            item = QWidgetAction(self)
            item.setDefaultWidget(tool_button)
            item.setEnabled(enabled)
        else:
            item = QAction(self)
            item.triggered.connect(callback if callback is not None else
                                     lambda: None)
            item.setIcon(icon)
            item.setStatusTip(description)
            item.setEnabled(enabled)
            item.setText(name)

        self._actions.append(dict(action=item,
                                  category=(category, 0) if not isinstance(
                                      category, tuple) else category,
                                  priority=priority))

        return item
Esempio n. 2
0
    def __init__(self):
        QWidget.__init__(self)
        self._line_edit = ClearableLineEdit()

        self._calendar_button = QToolButton()
        self._calendar_button.setPopupMode(QToolButton.InstantPopup)
        self._calendar_button.setFixedSize(26, 26)
        self._calendar_button.setAutoRaise(True)
        self._calendar_button.setIcon(resourceIcon("calendar_date_range.svg"))
        self._calendar_button.setStyleSheet(
            "QToolButton::menu-indicator { image: none; }")

        tool_menu = QMenu(self._calendar_button)
        self._calendar_widget = QCalendarWidget(tool_menu)
        action = QWidgetAction(tool_menu)
        action.setDefaultWidget(self._calendar_widget)
        tool_menu.addAction(action)
        self._calendar_button.setMenu(tool_menu)

        layout = QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self._line_edit)
        layout.addWidget(self._calendar_button)
        self.setLayout(layout)

        self._calendar_widget.activated.connect(self.setDate)
Esempio n. 3
0
    def __init__(self, parent: Optional[QWidget] = None):
        super(ColorPicker, self).__init__(parent)
        self.events = ColorPicker.Events()
        self.setAutoFillBackground(True)

        self._color_dialog = QColorDialog(self)
        self._color_dialog.setWindowFlags(Qt.Widget)
        self._color_dialog.setOptions(QColorDialog.DontUseNativeDialog
                                      | QColorDialog.NoButtons)

        self._menu = QMenu(self)
        action = QWidgetAction(self)
        action.setDefaultWidget(self._color_dialog)
        self._menu.addAction(action)
        self.setMenu(self._menu)

        # noinspection PyUnresolvedReferences
        self._menu.aboutToShow.connect(lambda: self._color_dialog.show())
        # noinspection PyUnresolvedReferences
        self._color_dialog.currentColorChanged.connect(
            self.events.color_changed)
        # noinspection PyUnresolvedReferences
        self._color_dialog.currentColorChanged.connect(
            lambda color: self.update())

        self.update()
Esempio n. 4
0
    def __init__(self, *args, **kwargs):
        super(MOSViewerToolbar, self).__init__(*args, **kwargs)
        self.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)

        # Define the toolbar actions
        self.cycle_previous_action = QAction(
            QIcon(os.path.join(ICON_DIR, "Previous-96.png")), "Previous", self)
        self.cycle_next_action = QAction(
            QIcon(os.path.join(ICON_DIR, "Next-96.png")), "Next", self)

        # Include the dropdown widget
        self.source_select = QComboBox()

        # Add the items to the toolbar
        self.addAction(self.cycle_previous_action)
        self.addAction(self.cycle_next_action)
        self.addWidget(self.source_select)

        # Include a button to open spectrum in specviz
        self.open_specviz = QAction(
            QIcon(os.path.join(ICON_DIR, "External-96.png")),
            "Open in SpecViz", self)

        # Create a tool button to hold the lock axes menu object
        tool_button = QToolButton(self)
        tool_button.setText("Axes Settings")
        tool_button.setIcon(QIcon(os.path.join(ICON_DIR, "Settings-96.png")))
        tool_button.setPopupMode(QToolButton.MenuButtonPopup)
        tool_button.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)

        # Create a menu for the axes settings drop down
        self.settings_menu = QMenu(self)

        # Add lock x axis action
        self.lock_x_action = QAction("Lock spectral axis", self.settings_menu)
        self.lock_x_action.setCheckable(True)

        # Add lock y axis action
        self.lock_y_action = QAction("Lock vertical displacement axis",
                                     self.settings_menu)
        self.lock_y_action.setCheckable(True)

        # Add the actions to the menu
        self.settings_menu.addAction(self.lock_x_action)
        self.settings_menu.addAction(self.lock_y_action)

        # Set the menu object on the tool button
        tool_button.setMenu(self.settings_menu)

        # Create a widget action object to hold the tool button, this way the
        # toolbar behaves the way it's expected to
        tool_button_action = QWidgetAction(self)
        tool_button_action.setDefaultWidget(tool_button)

        self.addAction(tool_button_action)
        self.addSeparator()
        self.addAction(self.open_specviz)
Esempio n. 5
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self.que = []
        self.algorithms = [
            FCFS, SSTF, SCAN, C_SCAN, C_LOOK, SSTF_EDF, SSTF_FDF_SCAN
        ]

        self.menu = QMenu(self)
        self.style_picker_action = QWidgetAction(self.menu)
        self.style_picker = StylePickerHorizontal(self)
        self.style_picker_action.setDefaultWidget(self.style_picker)
        self.menu.addAction(self.style_picker_action)
        self.menu.setTitle("Simulation")
        self.addMenu(self.menu)

        self.main_widget = MainWidget(self)
        self.addContentWidget(self.main_widget)
Esempio n. 6
0
    def create_actions(self):
        '''
        Creates the toolbar actions
        '''
        self.tool_bar.addAction(self.action_save_state)
        self.action_save_state.setIcon(self.style().standardIcon(QStyle.SP_DialogSaveButton))
        self.tool_bar.addAction(self.action_restore_state)
        self.action_restore_state.setIcon(self.style().standardIcon(QStyle.SP_DialogOpenButton))
        self.save_perspective_action = QAction("Save Perspective", self)
        self.save_perspective_action.triggered.connect(self.save_perspective)

        self.perspective_list_action = QWidgetAction(self)
        self.perspective_combo_box = QComboBox(self)
        self.perspective_combo_box.setSizeAdjustPolicy(QComboBox.AdjustToContents)
        self.perspective_combo_box.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        self.perspective_list_action.setDefaultWidget(self.perspective_combo_box)
        self.tool_bar.addSeparator()
        self.tool_bar.addAction(self.perspective_list_action)
        self.tool_bar.addAction(self.save_perspective_action)
Esempio n. 7
0
    def __init__(self, parent):
        super(MainWindowMenu, self).__init__(parent)
        self.setTitle("QtPyBotnet")

        self.console_action = QAction('Show console', self)
        self.console_action.setObjectName("show_console")
        self.addAction(self.console_action)

        self.stay_top_action = QAction("Stay on top", self)
        self.stay_top_action.setObjectName("stay_top_action")
        self.stay_top_action.setCheckable(True)
        self.stay_top_action.setChecked(
            bool(self.window().windowFlags() & Qt.WindowStaysOnTopHint))
        self.addAction(self.stay_top_action)

        self.style_picker_action = QWidgetAction(self)
        self.style_picker = StylePickerHorizontal(self)
        self.style_picker_action.setDefaultWidget(self.style_picker)
        self.addAction(self.style_picker_action)
Esempio n. 8
0
    def generate_context_menu(self, pos: QPoint):
        """
        Generate a context menu for contextMenuEvent

        Parameters
        ----------
        pos : QPoint
            The point where the context menu was requested
        """
        model_menu = QMenu()
        skip_text = "skip me"

        # Add filterbox to the context menu
        txt_box = QLineEdit(model_menu)
        txt_box.setPlaceholderText("Filter")
        txt_box.setClearButtonEnabled(True)
        txt_box_action = QWidgetAction(model_menu)
        txt_box_action.setDefaultWidget(txt_box)
        model_menu.addAction(txt_box_action)

        # Add result treeview to the context menu
        tree_view = QTreeWidget(model_menu)
        tree_view.header().close()
        tree_view_action = QWidgetAction(model_menu)
        tree_view_action.setDefaultWidget(tree_view)
        model_menu.addAction(tree_view_action)

        top_level_items = {}
        for cat in self._scene.registry.categories():
            item = QTreeWidgetItem(tree_view)
            item.setText(0, cat)
            item.setData(0, Qt.UserRole, skip_text)
            top_level_items[cat] = item

        registry = self._scene.registry
        for model, category in registry.registered_models_category_association(
        ).items():
            self.parent = top_level_items[category]
            item = QTreeWidgetItem(self.parent)
            item.setText(0, model)
            item.setData(0, Qt.UserRole, model)

        tree_view.expandAll()

        def click_handler(item):
            model_name = item.data(0, Qt.UserRole)
            if model_name == skip_text:
                return

            type_ = self._scene.registry.create(model_name)
            if type_:
                node = self._scene.create_node(type_)
                pos_view = self.mapToScene(pos)
                node.graphics_object.setPos(pos_view)
                self._scene.node_placed.emit(node)
            else:
                logger.debug("Model not found")

            model_menu.close()

        tree_view.itemClicked.connect(click_handler)

        # Setup filtering
        def filter_handler(text):
            for name, top_lvl_item in top_level_items.items():
                for i in range(top_lvl_item.childCount()):
                    child = top_lvl_item.child(i)
                    model_name = child.data(0, Qt.UserRole)
                    child.setHidden(text not in model_name)

        txt_box.textChanged.connect(filter_handler)

        # make sure the text box gets focus so the user doesn't have to click on it
        txt_box.setFocus()
        return model_menu
Esempio n. 9
0
    def __init__(self, title, parent=None, key=''):
        QDialog.__init__(self, parent)
        self.setWindowTitle(title)

        self._ert = ERT.ert
        """:type: res.enkf.enkf_main.EnKFMain"""

        self.key_manager = self._ert.getKeyManager()
        """:type: res.enkf.key_manager.KeyManager """

        self.current_key = key

        self.setWindowFlags(self.windowFlags()
                            & ~Qt.WindowContextHelpButtonHint)
        self.setWindowFlags(self.windowFlags() & ~Qt.WindowCloseButtonHint)

        self._tab_map = {}
        self._tab_order = []

        layout = QVBoxLayout()

        self._tabs = QTabWidget()
        layout.addWidget(self._tabs)
        layout.setSizeConstraint(QLayout.SetFixedSize)  # not resizable!!!

        self._button_layout = QHBoxLayout()

        self._reset_button = QToolButton()
        self._reset_button.setIcon(resourceIcon("update.png"))
        self._reset_button.setToolTip("Reset all settings back to default")
        self._reset_button.clicked.connect(self.resetSettings)

        self._undo_button = QToolButton()
        self._undo_button.setIcon(resourceIcon("undo.png"))
        self._undo_button.setToolTip("Undo")
        self._undo_button.clicked.connect(self.undoSettings)

        self._redo_button = QToolButton()
        self._redo_button.setIcon(resourceIcon("redo.png"))
        self._redo_button.setToolTip("Redo")
        self._redo_button.clicked.connect(self.redoSettings)
        self._redo_button.setEnabled(False)

        self._copy_from_button = QToolButton()
        self._copy_from_button.setIcon(resourceIcon("copy_from.png"))
        self._copy_from_button.setToolTip("Copy settings from another key")
        self._copy_from_button.setPopupMode(QToolButton.InstantPopup)
        self._copy_from_button.setEnabled(False)

        self._copy_to_button = QToolButton()
        self._copy_to_button.setIcon(resourceIcon("copy_to.png"))
        self._copy_to_button.setToolTip(
            "Copy current plot settings to other keys")
        self._copy_to_button.setPopupMode(QToolButton.InstantPopup)
        self._copy_to_button.clicked.connect(self.initiateCopyStyleToDialog)
        self._copy_to_button.setEnabled(True)

        tool_menu = QMenu(self._copy_from_button)
        self._popup_list = QListWidget(tool_menu)
        self._popup_list.setSortingEnabled(True)
        self._popup_list.itemClicked.connect(self.keySelected)
        action = QWidgetAction(tool_menu)
        action.setDefaultWidget(self._popup_list)
        tool_menu.addAction(action)
        self._copy_from_button.setMenu(tool_menu)

        self._apply_button = QPushButton("Apply")
        self._apply_button.setToolTip("Apply the new settings")
        self._apply_button.clicked.connect(self.applySettings)
        self._apply_button.setDefault(True)

        self._close_button = QPushButton("Close")
        self._close_button.setToolTip("Hide this dialog")
        self._close_button.clicked.connect(self.hide)

        self._button_layout.addWidget(self._reset_button)
        self._button_layout.addStretch()
        self._button_layout.addWidget(self._undo_button)
        self._button_layout.addWidget(self._redo_button)
        self._button_layout.addWidget(self._copy_from_button)
        self._button_layout.addWidget(self._copy_to_button)
        self._button_layout.addStretch()
        self._button_layout.addWidget(self._apply_button)
        self._button_layout.addWidget(self._close_button)

        layout.addStretch()
        layout.addLayout(self._button_layout)

        self.setLayout(layout)