def _build_left_dock(self): # QTreeView for the project view w_project_tree = QDockWidget("Project tree", self) w_project_tree.setFloating(False) self._docks['project tree'] = w_project_tree self.addDockWidget(Qt.LeftDockWidgetArea, w_project_tree) # Add the treeview treeview = QTreeView(w_project_tree) treedelegate = TreeDelegate() treeview.setItemDelegate(treedelegate) pm = ProjectModel() self._models["project"] = pm treeview.setModel(pm) treeview.expandAll() treeview.resizeColumnToContents(0) treeview.resizeColumnToContents(1) w_project_tree.setWidget(treeview) treeview.clicked.connect(self.treeItemClicked) # Formatting Editor w_properties = QDockWidget("Properties editor", self) w_properties.setFloating(False) self._docks['properties'] = w_properties self.addDockWidget(Qt.LeftDockWidgetArea, w_properties) # Create Container widget container = QWidget(w_properties) # Create a verticallayout in which we put a treeview and a tableview v_layout = QVBoxLayout(w_properties) # Positions Properties to start with # the treeview will contain the widgets for the properties of the selected item in the tree treeview = QTreeView(w_properties) v_layout.addWidget(treeview) v_layout.setStretchFactor(treeview, 2) treedelegate = PropertiesTreeDelegate() treeview.setItemDelegate(treedelegate) pm = PropertiesTreeModel() self._models['properties'] = pm treeview.setModel(pm) treeview.expandAll() # The tableview will only contain editable x,y shown as rows tableview = QTableView(w_properties) v_layout.addWidget(tableview) v_layout.setStretchFactor(tableview, 1) container.setLayout(v_layout) w_properties.setWidget(container) # Formatting Editor w_formatting = QDockWidget("Formatting editor", self) w_formatting.setFloating(False) self._docks['formatting'] = w_formatting self.addDockWidget(Qt.LeftDockWidgetArea, w_formatting)
def build_layout(self): # TODO: Allow save/restore https://stackoverflow.com/questions/14288635/any-easy-way-to-store-dock-widows-layout-and-sizes-in-settings-with-qt # Clear out docks for dockwidget in self.findChildren(QDockWidget): if dockwidget.parent() == self: self.removeDockWidget(dockwidget) # Make new docks self.topwidget = QDockWidget(parent=self) self.leftwidget = QDockWidget(parent=self) self.rightwidget = QDockWidget(parent=self) self.bottomwidget = QDockWidget(parent=self) self.lefttopwidget = QDockWidget(parent=self) self.righttopwidget = QDockWidget(parent=self) self.leftbottomwidget = QDockWidget(parent=self) self.rightbottomwidget = QDockWidget(parent=self) # Place the docks self.addDockWidget(Qt.LeftDockWidgetArea, self.lefttopwidget) self.addDockWidget(Qt.RightDockWidgetArea, self.righttopwidget) self.addDockWidget(Qt.TopDockWidgetArea, self.topwidget) self.addDockWidget(Qt.LeftDockWidgetArea, self.leftwidget) self.addDockWidget(Qt.RightDockWidgetArea, self.rightwidget) self.addDockWidget(Qt.BottomDockWidgetArea, self.bottomwidget) self.addDockWidget(Qt.LeftDockWidgetArea, self.leftbottomwidget) self.addDockWidget(Qt.RightDockWidgetArea, self.rightbottomwidget) # Adjust spanning self.setCorner(Qt.TopLeftCorner, Qt.LeftDockWidgetArea) self.setCorner(Qt.TopRightCorner, Qt.RightDockWidgetArea) self.setCorner(Qt.BottomLeftCorner, Qt.LeftDockWidgetArea) self.setCorner(Qt.BottomRightCorner, Qt.RightDockWidgetArea)
def __init__(self, fileName, parent=None): QObject.__init__(self) sweepCollection = IvSweepCollection(str(fileName)) self.sweepCollection = sweepCollection tableModel = SweepTableModel(sweepCollection) tableView = QTableView() tableView.setModel(tableModel) tableView.setItemDelegateForColumn(0, CheckBoxDelegate(parent=tableView)) tableView.setItemDelegateForColumn(1, CheckBoxDelegate(parent=tableView)) self.tableModel = tableModel tableView.resizeColumnsToContents() tableView.setSelectionMode(QAbstractItemView.SingleSelection) tableView.setSelectionBehavior(QAbstractItemView.SelectRows) sm = tableView.selectionModel() sm.currentRowChanged.connect(self.selectedRowChanged) self.tableView = tableView dockWidget = QDockWidget('Sweeps') dockWidget.setWidget(tableView) self.sweepTableDock = dockWidget hkDock = HkDockWidget(sweepCollection.hk) hkDock.setWindowTitle('HK - %s' % str(fileName)) self.hkDock = hkDock ivGraphWidget = IvGraphWidget(sweepCollection) tableModel.plotToggled.connect(ivGraphWidget.showSweep) #tableModel.badToggled.connect(self.toggleBad) self.ivGraphWidget = ivGraphWidget
def test_main_window_raise(main_window, qtbot, start_floating, close, finish_floating): # Add our docks dock1 = QDockWidget() qtbot.addWidget(dock1) dock2 = QDockWidget() qtbot.addWidget(dock2) main_window.addDockWidget(Qt.RightDockWidgetArea, dock1) main_window.addDockWidget(Qt.RightDockWidgetArea, dock2) # Setup dock dock1.setFloating(start_floating) if close: dock1.close() # Re-raise # main_window.raise_dock(dock1) assert dock1.isFloating() == finish_floating
def test_main_window_find_window(main_window, qtbot): widget = QWidget() qtbot.addWidget(widget) dock = QDockWidget() qtbot.addWidget(dock) dock.setWidget(widget) main_window.addDockWidget(Qt.RightDockWidgetArea, dock) assert LucidMainWindow.find_window(widget) == main_window
def __init__( self, config_folder: Union[str, Path, None] = None, title="PartSeg", settings: Optional[BaseSettings] = None, load_dict: Optional[Register] = None, signal_fun=None, ): if settings is None: if config_folder is None: raise ValueError("wrong config folder") if not os.path.exists(config_folder): import_config() settings: BaseSettings = self.get_setting_class()(config_folder) errors = settings.load() if errors: errors_message = QMessageBox() errors_message.setText("There are errors during start") errors_message.setInformativeText( "During load saved state some of data could not be load properly\n" "The files has prepared backup copies in " " state directory (Help > State directory)") errors_message.setStandardButtons(QMessageBox.Ok) text = "\n".join("File: " + x[0] + "\n" + str(x[1]) for x in errors) errors_message.setDetailedText(text) errors_message.exec_() super().__init__() if signal_fun is not None: self.show_signal.connect(signal_fun) self.settings = settings self._load_dict = load_dict self.viewer_list: List[Viewer] = [] self.files_num = 1 self.setAcceptDrops(True) self.setWindowTitle(title) self.title_base = title app = QApplication.instance() if app is not None: app.setStyleSheet(settings.style_sheet) self.settings.theme_changed.connect(self.change_theme) self.channel_info = "" self.multiple_files = None self.settings.request_load_files.connect(self.read_drop) self.recent_file_menu = QMenu("Open recent") self._refresh_recent() self.settings.connect_(FILE_HISTORY, self._refresh_recent) self.settings.napari_settings.appearance.events.theme.connect( self.change_theme) self.settings.set_parent(self) self.console = None self.console_dock = QDockWidget("console", self) self.console_dock.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.BottomDockWidgetArea) # self.console_dock.setWidget(self.console) self.console_dock.hide() self.addDockWidget(Qt.BottomDockWidgetArea, self.console_dock)
def addDock(self, name, widget, area=Qt.LeftDockWidgetArea, allowed_areas=Qt.AllDockWidgetAreas): dock_widget = QDockWidget(name) dock_widget.setObjectName("%sDock" % name) dock_widget.setWidget(widget) dock_widget.setAllowedAreas(allowed_areas) dock_widget.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable) self.addDockWidget(area, dock_widget) return dock_widget
def create_dockwidget(self): """Creates a QDockWidget suitable for wrapping this plugin""" dock = QDockWidget(self.get_plugin_title(), self.main) dock.setObjectName(self.__class__.__name__ + "_dockwidget") dock.setAllowedAreas(self.ALLOWED_AREAS) dock.setFeatures(self.FEATURES) dock.setWidget(self) self.dockwidget = dock return dock, self.LOCATION
def create_dockwidget(self, title): """Add to parent QMainWindow as a dock widget""" dock = QDockWidget(title, self.parent_widget) dock.setObjectName(self.__class__.__name__ + "_dw") dock.setAllowedAreas(self._allowed_areas) dock.setFeatures(self._features) dock.setWidget(self) dock.visibilityChanged.connect(self.visibility_changed) self.dockwidget = dock return (dock, self._location)
def createDockWidget(self, widget, area, title, key=None): dock = QDockWidget() dock.setWidget(widget) dock.setWindowTitle(title) dock.setObjectName(title) self.addDockWidget(area, dock) if not hasattr(self, "dockWidgets"): self.dockWidgets = {} if key is None: key = title self.dockWidgets[key] = dock
def addDock(self, name, widget, area=Qt.RightDockWidgetArea, allowed_areas=Qt.AllDockWidgetAreas): dock_widget = QDockWidget(name) dock_widget.setObjectName("%sDock" % name) dock_widget.setWidget(widget) dock_widget.setAllowedAreas(allowed_areas) self.addDockWidget(area, dock_widget) self.__view_menu.addAction(dock_widget.toggleViewAction()) return dock_widget
def event_startup(self): dm = DataMatrix(length=0) dm.initializing = -1 self._qdm = WorkspaceMatrix(dm, read_only=True) self._qdm.cell_double_clicked.connect(self._inspect_variable) self._dock_widget = QDockWidget(self.main_window) self._dock_widget.setWidget(self._qdm) self._dock_widget.closeEvent = self._on_close_event self._dock_widget.setWindowTitle(_(u'Workspace')) self._dock_widget.setObjectName('WorkspaceExplorer') self._dock_widget.visibilityChanged.connect( self._on_visibility_changed) self.main_window.addDockWidget(Qt.RightDockWidgetArea, self._dock_widget) self._set_visible(cfg.workspace_visible)
def setup_figure(self): self.figure = Figure() self.figure.canvas = FigureCanvas(self.figure) self.figure.canvas.mpl_connect('button_press_event', self.mouse_click) self.figure.add_subplot(111, projection="mantid") self.toolbar = FittingPlotToolbar(self.figure.canvas, self, False) self.toolbar.setMovable(False) self.dock_window = QMainWindow(self.group_plot) self.dock_window.setWindowFlags(Qt.Widget) self.dock_window.setDockOptions(QMainWindow.AnimatedDocks) self.dock_window.setCentralWidget(self.toolbar) self.plot_dock = QDockWidget() self.plot_dock.setWidget(self.figure.canvas) self.plot_dock.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable) self.plot_dock.setAllowedAreas(Qt.BottomDockWidgetArea) self.plot_dock.setWindowTitle("Fit Plot") self.plot_dock.topLevelChanged.connect(self.make_undocked_plot_larger) self.initial_chart_width, self.initial_chart_height = self.plot_dock.width( ), self.plot_dock.height() self.plot_dock.setSizePolicy( QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)) self.dock_window.addDockWidget(Qt.BottomDockWidgetArea, self.plot_dock) self.vLayout_plot.addWidget(self.dock_window) self.fit_browser = EngDiffFitPropertyBrowser( self.figure.canvas, ToolbarStateManager(self.toolbar)) # remove SequentialFit from fit menu (implemented a different way) qmenu = self.fit_browser.getFitMenu() qmenu.removeAction([ qact for qact in qmenu.actions() if qact.text() == "Sequential Fit" ][0]) # hide unnecessary properties of browser hide_props = [ 'Minimizer', 'Cost function', 'Max Iterations', 'Output', 'Ignore invalid data', 'Peak Radius', 'Plot Composite Members', 'Convolve Composite Members', 'Show Parameter Errors', 'Evaluate Function As' ] self.fit_browser.removePropertiesFromSettingsBrowser(hide_props) self.fit_browser.toggleWsListVisible() self.fit_browser.closing.connect(self.toolbar.handle_fit_browser_close) self.vLayout_fitprop.addWidget(self.fit_browser) self.fit_browser.hide()
def event_startup(self): from jupyter_tabwidget import ConsoleTabWidget self.set_busy(True) self._jupyter_console = ConsoleTabWidget(self.main_window) self._dock_widget = QDockWidget(u'Console', self.main_window) self._dock_widget.setObjectName(u'JupyterConsole') self._dock_widget.setWidget(self._jupyter_console) self._dock_widget.closeEvent = self._on_close_event self.main_window.addDockWidget(Qt.BottomDockWidgetArea, self._dock_widget) self._set_visible(cfg.jupyter_visible) self._shortcut_focus = QShortcut(QKeySequence( cfg.jupyter_focus_shortcut), self.main_window, self._focus, context=Qt.ApplicationShortcut) self.set_busy(False)
def add_dock_widget(self, area: str = 'bottom', widget: QWidget = None, allowed_areas=None): """Convenience method to add a QDockWidget to the main window Parameters ---------- area : str Side of the main window to which the new dock widget will be added. Must be in {'left', 'right', 'top', 'bottom'} widget : QWidget, optional If provided, `widget` will be added as QDockWidget's main widget allowed_areas : Qt.DockWidgetArea, optional Areas, relative to main window, that the new dock is allowed to go. """ areas = { 'left': Qt.LeftDockWidgetArea, 'right': Qt.RightDockWidgetArea, 'top': Qt.TopDockWidgetArea, 'bottom': Qt.BottomDockWidgetArea, } if area not in areas: raise ValueError(f'side argument must be in {list(areas.keys())}') dock_widget = QDockWidget(self._qt_window) dock_widget.setAllowedAreas(allowed_areas or (Qt.LeftDockWidgetArea | Qt.BottomDockWidgetArea | Qt.RightDockWidgetArea | Qt.TopDockWidgetArea)) dock_widget.setMinimumHeight(50) dock_widget.setMinimumWidth(50) if isinstance(widget, QWidget): dock_widget.setWidget(widget) widget.setParent(dock_widget) self._qt_window.addDockWidget(areas[area], dock_widget) return dock_widget
def add_new_viewer_selected(self, checked): if self.top_controls_add_new_selector.count() == 0: return selected = self.top_controls_add_new_selector.currentIndex() if selected < 0: return workflow = self.top_controls_add_new_selector.currentData(Qt.UserRole) print("WORKFLOW", workflow, workflow.name) dock_widget = QDockWidget() viewer = CatalogView() dock_widget.setWidget(viewer) dock_widget.setWindowTitle(workflow.name) if len(self.active_workflows) == 0: self._main_view.addDockWidget(Qt.RightDockWidgetArea, dock_widget) else: self._main_view.tabifyDockWidget(self.active_workflows[-1][0], dock_widget) self.active_workflows.append((dock_widget, workflow))
def event_startup(self): dm = DataMatrix(length=0) dm.initializing = -1 self._workspace_cache = {} self._label_kernel_not_supported = QLabel('<b>' + _('Kernel not supported') + '</b>') self._label_kernel_not_supported.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self._qdm = WorkspaceMatrix(dm, read_only=True) self._qdm.setFont(QFont(cfg.pyqode_font_name, cfg.pyqode_font_size)) self._qdm.cell_double_clicked.connect(self._inspect_variable) self._dock_widget = QDockWidget(self.main_window) self._dock_widget.setWidget(self._qdm) self._dock_widget.closeEvent = self._on_close_event self._dock_widget.setWindowTitle(_(u'Workspace')) self._dock_widget.setObjectName('WorkspaceExplorer') self._dock_widget.visibilityChanged.connect( self._on_visibility_changed) self.main_window.addDockWidget(Qt.RightDockWidgetArea, self._dock_widget) self._set_visible(cfg.workspace_visible)
def appendHeader(self, header, **kwargs): filename = header._documents["start"][0]["filename"] self.active_filename = filename self.status_bar.setText("Loading Filename:" + filename) dataset, bkgs, drks = read_als_hdf5(filename) slice_widget = MyCatalogView() dw = QDockWidget() dw.setWidget(slice_widget) dw.setWindowTitle(filename) slice_widget.setImage(dataset) dock_children = self._main_view.findChildren(QDockWidget) print(dock_children) #if len(dock_children) == 0: # self._main_view.addDockWidget(Qt.LeftDockWidgetArea, dw) #else: # self._main_view.tabifyDockWidget(dock_children[0], dw) self._main_view.addDockWidget(Qt.LeftDockWidgetArea, dw) self.status_bar.setText("Done Loading Filename:" + filename)
def _create_dock_widget(window, name, area, *, max_width=None): # create dock widget dock = QDockWidget(name) # add scroll area scroll = QScrollArea(dock) dock.setWidget(scroll) # give the scroll area a child widget widget = QWidget(scroll) scroll.setWidget(widget) scroll.setWidgetResizable(True) dock.setAllowedAreas(area) dock.setTitleBarWidget(QLabel(name)) window.addDockWidget(area, dock) dock_layout = QVBoxLayout() widget.setLayout(dock_layout) # Fix resize grip size # https://stackoverflow.com/a/65050468/2175965 styles = ['margin: 4px;'] if max_width is not None: styles.append(f'max-width: {max_width};') style_sheet = 'QDockWidget { ' + ' \n'.join(styles) + '\n}' dock.setStyleSheet(style_sheet) return dock, dock_layout
def _main(args): # To avoid problems when testing without screen if args.test or args.screenshots: os.environ['QT_QPA_PLATFORM'] = 'offscreen' # Set QT_API variable before importing QtPy if args.qt_from in ['pyqt', 'pyqt5', 'pyside', 'pyside2']: os.environ['QT_API'] = args.qt_from elif args.qt_from == 'pyqtgraph': os.environ['QT_API'] = os.environ['PYQTGRAPH_QT_LIB'] elif args.qt_from in ['qt.py', 'qt']: try: import Qt except ImportError: print('Could not import Qt (Qt.Py)') else: os.environ['QT_API'] = Qt.__binding__ # QtPy imports from qtpy import API_NAME, QT_VERSION, PYQT_VERSION, PYSIDE_VERSION from qtpy import __version__ as QTPY_VERSION from qtpy.QtWidgets import (QApplication, QMainWindow, QDockWidget, QStatusBar, QLabel, QMenu) from qtpy.QtCore import QTimer, Qt, QSettings # Set API_VERSION variable API_VERSION = '' if PYQT_VERSION: API_VERSION = PYQT_VERSION elif PYSIDE_VERSION: API_VERSION = PYSIDE_VERSION else: API_VERSION = 'Not found' # Import examples UI from mw_menus_ui import Ui_MainWindow as ui_main from dw_buttons_ui import Ui_DockWidget as ui_buttons from dw_displays_ui import Ui_DockWidget as ui_displays from dw_inputs_fields_ui import Ui_DockWidget as ui_inputs_fields from dw_inputs_no_fields_ui import Ui_DockWidget as ui_inputs_no_fields from dw_widgets_ui import Ui_DockWidget as ui_widgets from dw_views_ui import Ui_DockWidget as ui_views from dw_containers_tabs_ui import Ui_DockWidget as ui_containers_tabs from dw_containers_no_tabs_ui import Ui_DockWidget as ui_containers_no_tabs # qrainbowstyle.useDarwinButtons() QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) # create the application if not QApplication.instance(): app = QApplication(sys.argv) else: app = QApplication.instance() app.setOrganizationName('QRainbowStyle') app.setApplicationName('QRainbowStyle Example') styles = qrainbowstyle.getAvailableStyles() style = args.style if not args.style: style = styles[random.randint(0, len(styles)) - 1] app.setStyleSheet(qrainbowstyle.load_stylesheet(style=str(style))) # create main window window = qrainbowstyle.windows.FramelessWindow() window.setTitlebarHeight(30) widget = QMainWindow(window) widget.setWindowFlags(Qt.Widget) widget.setObjectName('mainwindow') ui = ui_main() ui.setupUi(widget) window.addContentWidget(widget) title = ("QRainbowStyle Example - " + "(QRainbowStyle=v" + qrainbowstyle.__version__ + ", QtPy=v" + QTPY_VERSION + ", " + API_NAME + "=v" + API_VERSION + ", Qt=v" + QT_VERSION + ", Python=v" + platform.python_version() + ")") _logger.info(title) window.setWindowTitle(title) # Create docks for buttons dw_buttons = QDockWidget() dw_buttons.setObjectName('buttons') ui_buttons = ui_buttons() ui_buttons.setupUi(dw_buttons) widget.addDockWidget(Qt.RightDockWidgetArea, dw_buttons) # Add actions on popup toolbuttons menu = QMenu() for action in ['Action A', 'Action B', 'Action C']: menu.addAction(action) ui_buttons.toolButtonDelayedPopup.setMenu(menu) ui_buttons.toolButtonInstantPopup.setMenu(menu) ui_buttons.toolButtonMenuButtonPopup.setMenu(menu) # Create docks for buttons dw_displays = QDockWidget() dw_displays.setObjectName('displays') ui_displays = ui_displays() ui_displays.setupUi(dw_displays) widget.addDockWidget(Qt.RightDockWidgetArea, dw_displays) # Create docks for inputs - no fields dw_inputs_no_fields = QDockWidget() dw_inputs_no_fields.setObjectName('inputs_no_fields') ui_inputs_no_fields = ui_inputs_no_fields() ui_inputs_no_fields.setupUi(dw_inputs_no_fields) widget.addDockWidget(Qt.RightDockWidgetArea, dw_inputs_no_fields) # Create docks for inputs - fields dw_inputs_fields = QDockWidget() dw_inputs_fields.setObjectName('inputs_fields') ui_inputs_fields = ui_inputs_fields() ui_inputs_fields.setupUi(dw_inputs_fields) widget.addDockWidget(Qt.RightDockWidgetArea, dw_inputs_fields) # Create docks for widgets dw_widgets = QDockWidget() dw_widgets.setObjectName('widgets') ui_widgets = ui_widgets() ui_widgets.setupUi(dw_widgets) widget.addDockWidget(Qt.LeftDockWidgetArea, dw_widgets) # Create docks for views dw_views = QDockWidget() dw_views.setObjectName('views') ui_views = ui_views() ui_views.setupUi(dw_views) widget.addDockWidget(Qt.LeftDockWidgetArea, dw_views) # Create docks for containers - no tabs dw_containers_no_tabs = QDockWidget() dw_containers_no_tabs.setObjectName('containers_no_tabs') ui_containers_no_tabs = ui_containers_no_tabs() ui_containers_no_tabs.setupUi(dw_containers_no_tabs) widget.addDockWidget(Qt.LeftDockWidgetArea, dw_containers_no_tabs) # Create docks for containters - tabs dw_containers_tabs = QDockWidget() dw_containers_tabs.setObjectName('containers_tabs') ui_containers_tabs = ui_containers_tabs() ui_containers_tabs.setupUi(dw_containers_tabs) widget.addDockWidget(Qt.LeftDockWidgetArea, dw_containers_tabs) # Tabify right docks widget.tabifyDockWidget(dw_buttons, dw_displays) widget.tabifyDockWidget(dw_displays, dw_inputs_fields) widget.tabifyDockWidget(dw_inputs_fields, dw_inputs_no_fields) # Tabify left docks widget.tabifyDockWidget(dw_containers_no_tabs, dw_containers_tabs) widget.tabifyDockWidget(dw_containers_tabs, dw_widgets) widget.tabifyDockWidget(dw_widgets, dw_views) # Issues #9120, #9121 on Spyder qstatusbar = QStatusBar() qstatusbar.addWidget(QLabel('Style')) qstatusbarbutton = qrainbowstyle.widgets.StylePickerHorizontal() qstatusbar.addWidget(qstatusbarbutton) qstatusbar.setSizeGripEnabled(False) # Add info also in status bar for screenshots get it qstatusbar.addWidget(QLabel('INFO: ' + title)) widget.setStatusBar(qstatusbar) # Todo: add report info and other info in HELP graphical # Auto quit after 2s when in test mode if args.test: QTimer.singleShot(2000, app.exit) _read_settings(widget, args.reset, QSettings) window.show() # window.showMaximized() app.exec_() _write_settings(widget, QSettings)
def _build_right_dock(self): w_data = QDockWidget("Data inspector", self) w_data.setFloating(False) self._docks['data'] = w_data self.addDockWidget(Qt.RightDockWidgetArea, w_data)
def __init__(self, parent=None): super().__init__(parent) # Create viewer widget self._viewer = micro_view.MicroViewWidget() self._viewer.setObjectName("viewer") self._viewer.showLocalizationsChanged.connect(self.setShowPreview) # Create dock widgets fileChooser = file_chooser.FileChooser() fileChooser.selected.connect(self.open) self._fileModel = fileChooser.model() self._fileModel.rowsRemoved.connect(self._checkFileList) self._fileDock = QDockWidget(self.tr("File selection"), self) self._fileDock.setObjectName("fileDock") self._fileDock.setWidget(fileChooser) self._locOptionsWidget = locate_options.Container() self._locOptionsWidget.setObjectName("locOptionsWidget") self._locOptionsDock = QDockWidget(self.tr("Localization options"), self) self._locOptionsDock.setObjectName("locOptionsDock") self._locOptionsDock.setWidget(self._locOptionsWidget) self._locFilterWidget = locate_filter.FilterWidget() self._locFilterWidget.filterChanged.connect(self._filterLocalizations) self._locFilterDock = QDockWidget(self.tr("Localization filter"), self) self._locFilterDock.setObjectName("locFilterDock") self._locFilterDock.setWidget(self._locFilterWidget) locSaveWidget = locate_saver.SaveWidget() self._locSaveDock = QDockWidget(self.tr("Save localizations"), self) self._locSaveDock.setObjectName("locSaveDock") self._locSaveDock.setWidget(locSaveWidget) for d in (self._fileDock, self._locOptionsDock, self._locFilterDock, self._locSaveDock): d.setFeatures(d.features() & ~QDockWidget.DockWidgetClosable) self.addDockWidget(Qt.LeftDockWidgetArea, d) self.setDockOptions(self.dockOptions() | QMainWindow.VerticalTabs) self.setCentralWidget(self._viewer) # set up the preview worker self._previewWorker = workers.PreviewWorker(self) self._locOptionsWidget.optionsChanged.connect( self._makePreviewWorkerWork) self._viewer.currentFrameChanged.connect(self._makePreviewWorkerWork) self._previewWorker.finished.connect(self._previewFinished) self._previewWorker.error.connect(self._previewError) self._previewWorker.enabled = True self._previewWorker.busyChanged.connect(self._setBusyCursor) # set up the batch worker self._batchWorker = workers.BatchWorker(self) self._batchWorker.fileFinished.connect(self._locateRunnerFinished) self._batchWorker.fileError.connect(self._locateRunnerError) # batch progress dialog self._progressDialog = batch_progress.BatchProgressDialog(self) self._batchWorker.fileFinished.connect( self._progressDialog.increaseValue) self._batchWorker.fileError.connect(self._progressDialog.increaseValue) self._progressDialog.canceled.connect(self._batchWorker.stop) # Some things to keep track of self._currentFile = QPersistentModelIndex() self._currentLocData = pd.DataFrame(columns=["x", "y"]) self._roiPolygon = QPolygonF() # load settings and restore window geometry settings = QSettings("sdt", "locator") v = settings.value("MainWindow/geometry") if v is not None: self.restoreGeometry(v) v = settings.value("MainWindow/state") if v is not None: self.restoreState(v) # restore enable/disable preview show = settings.value("Viewer/showPreview", True, type=bool) self._viewer.showLocalizations = show QMetaObject.connectSlotsByName(self)
def _build_bottom_dock(self): w_assets = QDockWidget("Assets", self) w_assets.setFloating(False) self._docks['assets'] = w_assets self.addDockWidget(Qt.BottomDockWidgetArea, w_assets)
def main(): """Execute QDarkStyle example.""" parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument( '--qt_from', default='qtpy', type=str, choices=[ 'pyqt5', 'pyqt', 'pyside2', 'pyside', 'qtpy', 'pyqtgraph', 'qt.py' ], help= "Choose which binding and/or abstraction is to be used to run the example." ) parser.add_argument( '--no_dark', action='store_true', help="Exihibts the original window (without jam_darkstyle).") parser.add_argument('--test', action='store_true', help="Auto close window after 2s.") parser.add_argument('--reset', action='store_true', help="Reset GUI settings (position, size) then opens.") parser.add_argument('--screenshots', action='store_true', help="Generate screenshots on images folder.") # Parsing arguments from command line args = parser.parse_args() # To avoid problems when testing without screen if args.test or args.screenshots: os.environ['QT_QPA_PLATFORM'] = 'offscreen' # Set QT_API variable before importing QtPy if args.qt_from in ['pyqt', 'pyqt5', 'pyside', 'pyside2']: os.environ['QT_API'] = args.qt_from elif args.qt_from == 'pyqtgraph': os.environ['QT_API'] = os.environ['PYQTGRAPH_QT_LIB'] elif args.qt_from in ['qt.py', 'qt']: try: import Qt except ImportError: print('Could not import Qt (Qt.Py)') else: os.environ['QT_API'] = Qt.__binding__ # QtPy imports from qtpy import API_NAME, QT_VERSION, PYQT_VERSION, PYSIDE_VERSION from qtpy import __version__ as QTPY_VERSION from qtpy.QtWidgets import (QApplication, QMainWindow, QDockWidget, QStatusBar, QLabel, QPushButton, QMenu) from qtpy.QtCore import QTimer, Qt, QSettings # Set API_VERSION variable API_VERSION = '' if PYQT_VERSION: API_VERSION = PYQT_VERSION elif PYSIDE_VERSION: API_VERSION = PYSIDE_VERSION else: API_VERSION = 'Not found' # Import examples UI from mw_menus_ui import Ui_MainWindow as ui_main from dw_buttons_ui import Ui_DockWidget as ui_buttons from dw_displays_ui import Ui_DockWidget as ui_displays from dw_inputs_fields_ui import Ui_DockWidget as ui_inputs_fields from dw_inputs_no_fields_ui import Ui_DockWidget as ui_inputs_no_fields from dw_widgets_ui import Ui_DockWidget as ui_widgets from dw_views_ui import Ui_DockWidget as ui_views from dw_containers_tabs_ui import Ui_DockWidget as ui_containers_tabs from dw_containers_no_tabs_ui import Ui_DockWidget as ui_containers_no_tabs # create the application app = QApplication(sys.argv) app.setOrganizationName('QDarkStyle') app.setApplicationName('QDarkStyle Example') style = '' if not args.no_dark: style = jam_darkstyle.load_stylesheet() app.setStyleSheet(style) # create main window window = QMainWindow() window.setObjectName('mainwindow') ui = ui_main() ui.setupUi(window) title = ("QDarkStyle Example - " + "(QDarkStyle=v" + jam_darkstyle.__version__ + ", QtPy=v" + QTPY_VERSION + ", " + API_NAME + "=v" + API_VERSION + ", Qt=v" + QT_VERSION + ", Python=v" + platform.python_version() + ")") _logger.info(title) window.setWindowTitle(title) # Create docks for buttons dw_buttons = QDockWidget() dw_buttons.setObjectName('buttons') ui_buttons = ui_buttons() ui_buttons.setupUi(dw_buttons) window.addDockWidget(Qt.RightDockWidgetArea, dw_buttons) # Add actions on popup toolbuttons menu = QMenu() for action in ['Action A', 'Action B', 'Action C']: menu.addAction(action) ui_buttons.toolButtonDelayedPopup.setMenu(menu) ui_buttons.toolButtonInstantPopup.setMenu(menu) ui_buttons.toolButtonMenuButtonPopup.setMenu(menu) # Create docks for buttons dw_displays = QDockWidget() dw_displays.setObjectName('displays') ui_displays = ui_displays() ui_displays.setupUi(dw_displays) window.addDockWidget(Qt.RightDockWidgetArea, dw_displays) # Create docks for inputs - no fields dw_inputs_no_fields = QDockWidget() dw_inputs_no_fields.setObjectName('inputs_no_fields') ui_inputs_no_fields = ui_inputs_no_fields() ui_inputs_no_fields.setupUi(dw_inputs_no_fields) window.addDockWidget(Qt.RightDockWidgetArea, dw_inputs_no_fields) # Create docks for inputs - fields dw_inputs_fields = QDockWidget() dw_inputs_fields.setObjectName('inputs_fields') ui_inputs_fields = ui_inputs_fields() ui_inputs_fields.setupUi(dw_inputs_fields) window.addDockWidget(Qt.RightDockWidgetArea, dw_inputs_fields) # Create docks for widgets dw_widgets = QDockWidget() dw_widgets.setObjectName('widgets') ui_widgets = ui_widgets() ui_widgets.setupUi(dw_widgets) window.addDockWidget(Qt.LeftDockWidgetArea, dw_widgets) # Create docks for views dw_views = QDockWidget() dw_views.setObjectName('views') ui_views = ui_views() ui_views.setupUi(dw_views) window.addDockWidget(Qt.LeftDockWidgetArea, dw_views) # Create docks for containers - no tabs dw_containers_no_tabs = QDockWidget() dw_containers_no_tabs.setObjectName('containers_no_tabs') ui_containers_no_tabs = ui_containers_no_tabs() ui_containers_no_tabs.setupUi(dw_containers_no_tabs) window.addDockWidget(Qt.LeftDockWidgetArea, dw_containers_no_tabs) # Create docks for containters - tabs dw_containers_tabs = QDockWidget() dw_containers_tabs.setObjectName('containers_tabs') ui_containers_tabs = ui_containers_tabs() ui_containers_tabs.setupUi(dw_containers_tabs) window.addDockWidget(Qt.LeftDockWidgetArea, dw_containers_tabs) # Tabify right docks window.tabifyDockWidget(dw_buttons, dw_displays) window.tabifyDockWidget(dw_displays, dw_inputs_fields) window.tabifyDockWidget(dw_inputs_fields, dw_inputs_no_fields) # Tabify left docks window.tabifyDockWidget(dw_containers_no_tabs, dw_containers_tabs) window.tabifyDockWidget(dw_containers_tabs, dw_widgets) window.tabifyDockWidget(dw_widgets, dw_views) # Issues #9120, #9121 on Spyder qstatusbar = QStatusBar() qstatusbar.addWidget( QLabel('Issue Spyder #9120, #9121 - background not matching.')) qstatusbar.addWidget(QPushButton('OK')) # Add info also in status bar for screenshots get it qstatusbar.addWidget(QLabel('INFO: ' + title)) window.setStatusBar(qstatusbar) # Todo: add report info and other info in HELP graphical # Auto quit after 2s when in test mode if args.test: QTimer.singleShot(2000, app.exit) # Save screenshots for different displays and quit if args.screenshots: window.showFullScreen() create_screenshots(app, window, args.no_dark) # Do not read settings when taking screenshots - like reset else: _read_settings(window, args.reset, QSettings) window.showMaximized() app.exec_() _write_settings(window, QSettings) return window
def init_ui(self): # Define standard icon. standard_icon = self.style().standardIcon # Central widget. self.main_widget = SpectrumWidget(self.spectra) self.main_widget.setFocus() self.setCentralWidget(self.main_widget) # Open spectrum action open_spectrum_action = QAction(standard_icon(QStyle.SP_DialogOpenButton), 'Open spectrum', self) open_spectrum_action.setShortcut('Ctrl+O') open_spectrum_action.setStatusTip('Open spectrum') open_spectrum_action.triggered.connect(self.open_spectrum) # Exit action exit_action = QAction(standard_icon(QStyle.SP_TitleBarCloseButton), 'Exit', self) exit_action.setShortcut('Ctrl+Q') exit_action.setStatusTip('Exit application') exit_action.triggered.connect(self.close) # Status bar. self.statusBar() # Menu bar. menubar = self.menuBar() file_menu = menubar.addMenu('&File') file_menu.addAction(open_spectrum_action) file_menu.addAction(exit_action) view_menu = menubar.addMenu('&View') analysis_menu = menubar.addMenu('&Analysis') # Toolbar file_toolbar = self.addToolBar('File') file_toolbar.addAction(open_spectrum_action) file_toolbar.addAction(exit_action) view_menu.addAction(file_toolbar.toggleViewAction()) analysis_toolbar = self.addToolBar('Analysis') view_menu.addAction(analysis_toolbar.toggleViewAction()) view_menu.addSeparator() # Dock widget. self.graphic_settings_dock = QDockWidget("Graphic settings", self) self.graphic_settings_dock.setObjectName("graphic_settings_dock") self.graphic_settings_dock.setAllowedAreas(Qt.AllDockWidgetAreas) label_test = QLabel("Test label") self.graphic_settings_dock.setWidget(label_test) view_menu.addAction(self.graphic_settings_dock.toggleViewAction()) self.addDockWidget(Qt.AllDockWidgetAreas, self.graphic_settings_dock) print(self.graphic_settings_dock.objectName()) self.zero_loss_peak_dock = ZeroLossPeakWidget(self, self.spectra) analysis_menu.addAction(self.zero_loss_peak_dock.toggleViewAction()) self.addDockWidget(Qt.AllDockWidgetAreas, self.zero_loss_peak_dock) self.projects_dock = ProjectWidget(self) view_menu.addAction(self.projects_dock.toggleViewAction()) self.addDockWidget(Qt.AllDockWidgetAreas, self.projects_dock) # Final options. self.setWindowTitle('pySEM-EELS') self.show()
def init_ui(self): # Define standard icon. standard_icon = self.style().standardIcon # Central widget. self.main_widget = SpectrumWidget() self.main_widget.setFocus() self.setCentralWidget(self.main_widget) # Project action new_project_action = QAction(QIcon(':/oi/svg/document.svg'), 'New project', self) new_project_action.setShortcut('Ctrl+N') new_project_action.setStatusTip('New project') new_project_action.triggered.connect(self.new_project) open_project_action = QAction(QIcon(':/oi/svg/envelope-open.svg'), 'Open project', self) open_project_action.setShortcut('Ctrl+O') open_project_action.setStatusTip('Open project') open_project_action.triggered.connect(self.open_project) close_project_action = QAction(QIcon(':/oi/svg/envelope-closed.svg'), 'Close project', self) close_project_action.setShortcut('Ctrl+C') close_project_action.setStatusTip('Close project') close_project_action.triggered.connect(self.close_project) save_project_action = QAction(QIcon(':/oi/svg/hard-drive.svg'), 'Save project', self) save_project_action.setShortcut('Ctrl+S') save_project_action.setStatusTip('Save project') save_project_action.triggered.connect(self.save_project) saveas_project_action = QAction(QIcon(':/oi/svg/hard-drive.svg'), 'Save project as ...', self) # saveas_project_action.setShortcut('Ctrl+S') saveas_project_action.setStatusTip('Save project as ...') saveas_project_action.triggered.connect(self.saveas_project) # Spectrum action import_spectrum_action = QAction(QIcon(':/oi/svg/account-login.svg'), 'Import spectrum', self) import_spectrum_action.setShortcut('Ctrl+I') import_spectrum_action.setStatusTip('Import spectrum') import_spectrum_action.triggered.connect(self.import_spectrum) export_spectrum_action = QAction(QIcon(':/oi/svg/account-logout.svg'), 'Export spectrum', self) # export_spectrum_action.setShortcut('Ctrl+I') export_spectrum_action.setStatusTip('Export spectrum') export_spectrum_action.triggered.connect(self.export_spectrum) # Exit action exit_action = QAction(QIcon(':/oi/svg/x.svg'), 'Exit', self) exit_action.setShortcut('Ctrl+Q') exit_action.setStatusTip('Exit application') exit_action.triggered.connect(self.close) # Status bar. self.statusBar() # Menu bar. menubar = self.menuBar() file_menu = menubar.addMenu('&File') file_menu.addAction(new_project_action) file_menu.addAction(open_project_action) file_menu.addAction(save_project_action) file_menu.addAction(saveas_project_action) file_menu.addAction(close_project_action) file_menu.addSeparator() file_menu.addAction(exit_action) view_menu = menubar.addMenu('&View') spectrum_menu = menubar.addMenu('&Spectrum') spectrum_menu.addAction(import_spectrum_action) analysis_menu = menubar.addMenu('&Analysis') # Toolbar file_toolbar = self.addToolBar('File') file_toolbar.addAction(new_project_action) file_toolbar.addAction(open_project_action) file_toolbar.addAction(save_project_action) file_toolbar.addAction(saveas_project_action) file_toolbar.addAction(close_project_action) file_toolbar.addAction(exit_action) view_menu.addAction(file_toolbar.toggleViewAction()) spectrum_toolbar = self.addToolBar('Spectrum') spectrum_toolbar.addAction(import_spectrum_action) view_menu.addAction(spectrum_toolbar.toggleViewAction()) analysis_toolbar = self.addToolBar('Analysis') view_menu.addAction(analysis_toolbar.toggleViewAction()) view_menu.addSeparator() # Dock widget. self.graphic_settings_dock = QDockWidget("Graphic settings", self) self.graphic_settings_dock.setObjectName("graphic_settings_dock") self.graphic_settings_dock.setAllowedAreas(Qt.AllDockWidgetAreas) label_test = QLabel("Test label") self.graphic_settings_dock.setWidget(label_test) view_menu.addAction(self.graphic_settings_dock.toggleViewAction()) self.addDockWidget(Qt.AllDockWidgetAreas, self.graphic_settings_dock) print(self.graphic_settings_dock.objectName()) # Final options. self.setWindowTitle('X-ray spectrum analyzer') self.show()
def __init__(self, label_file=None): super(MainWindow, self).__init__() self.showMaximized() self.setWindowTitle("VTCC.Labelling") self.file_dirs = [] self.file_id = -1 self.labels = [] with open(label_file, 'r') as f: lines = f.read().splitlines() for label in lines: self.labels.append(label) # RIGHT DOCK self.label_dock = QDockWidget("Label List", self) self.label_list_widget = QListWidget(self) self.load_labels(label_file) self.label_dock.setWidget(self.label_list_widget) self.object_dock = QDockWidget("Object List", self) self.object_list_widget = QListWidget(self) self.object_list_widget.currentRowChanged.connect(self.change_object) self.object_dock.setWidget(self.object_list_widget) self.file_dock = QDockWidget("File List", self) self.file_list_widget = QListWidget(self) self.file_list_widget.currentRowChanged.connect(self.change_file) self.file_dock.setWidget(self.file_list_widget) self.addDockWidget(Qt.RightDockWidgetArea, self.label_dock) self.addDockWidget(Qt.RightDockWidgetArea, self.object_dock) self.addDockWidget(Qt.RightDockWidgetArea, self.file_dock) # MAIN CANVAS self.canvas = Canvas(self) self.canvas_area = QScrollArea() self.canvas_area.setWidget(self.canvas) self.canvas_area.setWidgetResizable(True) self.scrollBars = { Qt.Vertical: self.canvas_area.verticalScrollBar(), Qt.Horizontal: self.canvas_area.horizontalScrollBar(), } self.setCentralWidget(self.canvas_area) # LEFT DOCK self.open_action = QAction(QIcon('icons/open.png'), 'Open File', self) self.open_action.triggered.connect(self.open_file) self.open_action.setShortcut(QKeySequence("Ctrl+O")) self.open_dir_action = QAction(QIcon('icons/open.png'), 'Open Dir', self) self.open_dir_action.triggered.connect(self.open_dir) self.next_img_action = QAction(QIcon('icons/next.png'), 'Next Image', self) self.next_img_action.triggered.connect(self.next_img) self.next_img_action.setShortcut(QKeySequence("Right")) self.prev_img_action = QAction(QIcon('icons/prev.png'), 'Prev Image', self) self.prev_img_action.triggered.connect(self.prev_img) self.prev_img_action.setShortcut(QKeySequence("Left")) self.zoom_in_action = QAction(QIcon('icons/zoom-in.png'), 'Zoom In', self) self.zoom_in_action.triggered.connect(self.zoom_in) self.zoom_out_action = QAction(QIcon('icons/zoom-out.png'), 'Zoom Out', self) self.zoom_out_action.triggered.connect(self.zoom_out) self.zoom_org_action = QAction(QIcon('icons/fit-window.png'), 'Fit Window', self) self.zoom_org_action.triggered.connect(self.zoom_org) self.rectangle_action = QAction(QIcon('icons/objects.png'), 'New Rectangle', self) self.rectangle_action.triggered.connect(self.new_rectangle) self.auto_polygon_action = QAction(QIcon('icons/objects.png'), 'New Auto-Polygon', self) self.auto_polygon_action.triggered.connect(self.new_auto_polygon) self.polygon_action = QAction(QIcon('icons/objects.png'), 'New Polygon', self) self.polygon_action.triggered.connect(self.new_polygon) self.next_obj_action = QAction(QIcon('icons/next.png'), 'Next Object', self) self.next_obj_action.triggered.connect(self.canvas.next_obj) self.next_obj_action.setShortcut(QKeySequence("Down")) self.prev_obj_action = QAction(QIcon('icons/prev.png'), 'Prev Object', self) self.prev_obj_action.triggered.connect(self.canvas.prev_obj) self.prev_obj_action.setShortcut(QKeySequence("Up")) self.del_obj_action = QAction(QIcon('icons/delete.png'), 'Delete Object', self) self.del_obj_action.triggered.connect(self.canvas.del_obj) self.del_obj_action.setShortcut(QKeySequence("Del")) self.toolbar = QToolBar(self) self.toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) self.toolbar.addAction(self.open_action) self.toolbar.addAction(self.open_dir_action) self.toolbar.addAction(self.next_img_action) self.toolbar.addAction(self.prev_img_action) # self.toolbar.addAction(self.zoom_in_action) # self.toolbar.addAction(self.zoom_out_action) # self.toolbar.addAction(self.zoom_org_action) self.toolbar.addAction(self.rectangle_action) self.toolbar.addAction(self.auto_polygon_action) self.toolbar.addAction(self.polygon_action) self.toolbar.addAction(self.next_obj_action) self.toolbar.addAction(self.prev_obj_action) self.toolbar.addAction(self.del_obj_action) self.addToolBar(Qt.LeftToolBarArea, self.toolbar) self.scalers = { self.FIT_WINDOW: self.scaleFitWindow, self.FIT_WIDTH: self.scaleFitWidth, # Set to one to scale to 100% when loading files. self.MANUAL_ZOOM: lambda: 1, }