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()
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)
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)
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)
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)
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)
class MainWindow(FramelessWindow): 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) def createRequests(self) -> None: """Fills queue with disk access requests.""" for x in range(REQUESTS_COUNT - REAL_TIME_COUNT): self.que.append( Request(random.randint(MIN_ARRIVE_TIME, MAX_ARRIVE_TIME), random.randint(0, DISK_SIZE))) for x in range(REAL_TIME_COUNT): self.que.append( Request(random.randint(MIN_ARRIVE_TIME, MAX_ARRIVE_TIME), random.randint(0, DISK_SIZE), real_time=True, deadline=random.randint(MIN_DEADLINE, MAX_DEADLINE))) self.que.sort(key=lambda req: req.arrive_time) for index, request in enumerate(self.que): request.set_id(index + 1) def saveProcessesToFile(self) -> None: """Saves requests to file using pickle.""" with open(PICKLED_FILENAME, "wb") as file: pickle.dump(self.que, file) def loadProcessesFromFile(self) -> None: """Load requests from files using pickle.""" with open(PICKLED_FILENAME, "rb") as file: self.que = pickle.load(file) def setupAlgorithms(self): self.table = AlgorithmsTable(self.main_widget) self.tableModel = AlgorithmsTableModel(self.table) self.tableModel.setDiskSize(DISK_SIZE) self.table.setModel(self.tableModel) self.main_widget.addWidget(self.table) for algorithm in self.algorithms: algorithm_instance = algorithm(self.que, START_POS, DISK_SIZE) self.tableModel.addAlgorithm(algorithm_instance) self.start_button = QPushButton("Start", self) self.start_button.clicked.connect(self.tableModel.start) self.main_widget.addWidget(self.start_button)
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
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)
class MainWindow(QtWidgets.QMainWindow): save_perspective_action: QAction perspective_list_action: QWidgetAction perspective_combo_box: QComboBox dock_manager: DockManager def __init__(self, parent=None): super().__init__(parent) self.save_perspective_action = None self.perspective_list_action = None self.perspective_combo_box = None self.dock_manager = None self.setup_ui() self.dock_manager = DockManager(self) self.perspective_combo_box.activated.connect(self.dock_manager.open_perspective) self.create_content() self.resize(800, 600) self.restore_state() self.restore_perspectives() def setup_ui(self): self.setObjectName("MainWindow") self.resize(400, 300) self.setDockOptions(QtWidgets.QMainWindow.AllowTabbedDocks) self.centralWidget = QtWidgets.QWidget(self) self.centralWidget.setObjectName("centralWidget") self.setCentralWidget(self.centralWidget) self.status_bar = QtWidgets.QStatusBar(self) self.status_bar.setObjectName("statusBar") self.setStatusBar(self.status_bar) self.menu_bar = QtWidgets.QMenuBar(self) self.menu_bar.setGeometry(QRect(0, 0, 400, 21)) self.menu_bar.setObjectName("menuBar") self.menu_file = QtWidgets.QMenu(self.menu_bar) self.menu_file.setObjectName("menuFile") self.menu_view = QtWidgets.QMenu(self.menu_bar) self.menu_view.setObjectName("menuView") self.menu_about = QtWidgets.QMenu(self.menu_bar) self.menu_about.setObjectName("menuAbout") self.setMenuBar(self.menu_bar) self.tool_bar = QtWidgets.QToolBar(self) self.tool_bar.setObjectName("toolBar") self.addToolBar(Qt.TopToolBarArea, self.tool_bar) self.action_exit = QtWidgets.QAction(self) self.action_exit.setObjectName("actionExit") self.action_save_state = QtWidgets.QAction(self) self.action_save_state.setObjectName("actionSaveState") self.action_save_state.triggered.connect(self.save_state) self.action_restore_state = QtWidgets.QAction(self) self.action_restore_state.setObjectName("actionRestoreState") self.action_restore_state.triggered.connect(self.restore_state) self.menu_file.addAction(self.action_exit) self.menu_file.addAction(self.action_save_state) self.menu_file.addAction(self.action_restore_state) self.menu_bar.addAction(self.menu_file.menuAction()) self.menu_bar.addAction(self.menu_view.menuAction()) self.menu_bar.addAction(self.menu_about.menuAction()) self.setWindowTitle("MainWindow") self.menu_file.setTitle("File") self.menu_view.setTitle("View") self.menu_about.setTitle("About") self.tool_bar.setWindowTitle("toolBar") self.action_exit.setText("Exit") self.action_save_state.setText("Save State") self.action_restore_state.setText("Restore State") self.create_actions() 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) def create_content(self): ''' Fill the dock manager with dock widgets ''' # Test container docking view_menu = self.menu_view dock_widget = create_calendar_dock_widget(view_menu) dock_widget.set_icon(self.style().standardIcon(QStyle.SP_DialogOpenButton)) dock_widget.set_feature(DockWidgetFeature.closable, False) self.dock_manager.add_dock_widget(DockWidgetArea.left, dock_widget) self.dock_manager.add_dock_widget(DockWidgetArea.left, create_long_text_label_dock_widget(view_menu)) file_system_widget = create_file_system_tree_dock_widget(view_menu) tool_bar = file_system_widget.create_default_tool_bar() tool_bar.addAction(self.action_save_state) tool_bar.addAction(self.action_restore_state) self.dock_manager.add_dock_widget(DockWidgetArea.bottom, file_system_widget) file_system_widget = create_file_system_tree_dock_widget(view_menu) tool_bar = file_system_widget.create_default_tool_bar() tool_bar.addAction(self.action_save_state) tool_bar.addAction(self.action_restore_state) file_system_widget.set_feature(DockWidgetFeature.movable, False) top_dock_area = self.dock_manager.add_dock_widget(DockWidgetArea.top, file_system_widget) dock_widget = create_calendar_dock_widget(view_menu) dock_widget.set_feature(DockWidgetFeature.closable, False) dock_widget.set_tab_tool_tip("Tab ToolTip\nHodie est dies magna") self.dock_manager.add_dock_widget(DockWidgetArea.center, dock_widget, top_dock_area) # Test dock area docking right_dock_area = self.dock_manager.add_dock_widget( DockWidgetArea.right, create_long_text_label_dock_widget(view_menu), top_dock_area) self.dock_manager.add_dock_widget( DockWidgetArea.top, create_long_text_label_dock_widget(view_menu), right_dock_area) bottom_dock_area = self.dock_manager.add_dock_widget( DockWidgetArea.bottom, create_long_text_label_dock_widget(view_menu), right_dock_area) self.dock_manager.add_dock_widget( DockWidgetArea.right, create_long_text_label_dock_widget(view_menu), right_dock_area) self.dock_manager.add_dock_widget( DockWidgetArea.center, create_long_text_label_dock_widget(view_menu), bottom_dock_area) def save_state(self): ''' Saves the dock manager state and the main window geometry ''' settings = QSettings("Settings.ini", QSettings.IniFormat) settings.setValue("mainWindow/Geometry", self.saveGeometry()) settings.setValue("mainWindow/State", self.saveState()) settings.setValue("mainWindow/DockingState", self.dock_manager.save_state()) def save_perspectives(self): ''' Save the list of perspectives ''' settings = QSettings("Settings.ini", QSettings.IniFormat) self.dock_manager.save_perspectives(settings) def restore_state(self): ''' Restores the dock manager state ''' settings = QSettings("Settings.ini", QSettings.IniFormat) geom = settings.value("mainWindow/Geometry") if geom is not None: self.restoreGeometry(geom) state = settings.value("mainWindow/State") if state is not None: self.restoreState(state) state = settings.value("mainWindow/DockingState") if state is not None: self.dock_manager.restore_state(state) def restore_perspectives(self): ''' Restore the perspective listo of the dock manager ''' settings = QSettings("Settings.ini", QSettings.IniFormat) self.dock_manager.load_perspectives(settings) self.perspective_combo_box.clear() self.perspective_combo_box.addItems(self.dock_manager.perspective_names()) def save_perspective(self): perspective_name = QInputDialog.getText(self, 'Save perspective', 'Enter unique name:') if perspective_name: self.dock_manager.add_perspective(perspective_name) _ = QSignalBlocker(self.perspective_combo_box) self.perspective_combo_box.clear() self.perspective_combo_box.addItems(self.dock_manager.perspective_names()) self.perspective_combo_box.setCurrentIndex(perspective_name) self.save_perspectives()
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
def __init__(self, *args, **kwargs): super(MOSViewerToolbar, self).__init__(*args, **kwargs) # self.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) # Define icon path icon_path = os.path.join(os.path.dirname(__file__), 'ui', 'icons') # Define the toolbar actions self.cycle_previous_action = QAction( QIcon(os.path.join(icon_path, "Previous-96.png")), "Previous", self) self.cycle_next_action = QAction( QIcon(os.path.join(icon_path, "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_path, "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_path, "Settings-96.png"))) tool_button.setPopupMode(QToolButton.MenuButtonPopup) # 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 X Axis", self.settings_menu) self.lock_x_action.setCheckable(True) # Add lock y axis action self.lock_y_action = QAction("Lock Y 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)