Exemplo n.º 1
0
    def onColorPicker(self):
        dlg = QtWidgets.QColorDialog(self)
        if self._color:
            dlg.setCurrentColor(QtGui.QColor(self._color))

        if dlg.exec_():
            self.setColor(dlg.currentColor().name())
Exemplo n.º 2
0
    def set_up_color_selector_toolbar_button(self, fig):
        # check if the action is already in the toolbar
        if self._actions.get('line_colour'):
            return

        a = self.addAction(get_icon('mdi.palette'), "Line Colour", lambda: None)
        self._actions['line_colour'] = a

        if figure_type(fig) == FigureType.Wireframe:
            a.setToolTip("Set the colour of the wireframe.")
        else:
            a.setToolTip("Set the colour of the contour lines.")

        line_collection = next(col for col in fig.get_axes()[0].collections if isinstance(col, LineCollection))
        initial_colour = convert_color_to_hex(line_collection.get_color()[0])

        colour_dialog = QtWidgets.QColorDialog(QtGui.QColor(initial_colour))
        colour_dialog.setOption(QtWidgets.QColorDialog.NoButtons)
        colour_dialog.setOption(QtWidgets.QColorDialog.DontUseNativeDialog)
        colour_dialog.currentColorChanged.connect(self.change_line_collection_colour)

        button = [child for child in self.children() if isinstance(child, QtWidgets.QToolButton)][-1]

        menu = QtWidgets.QMenu("Menu", parent=button)
        colour_selector_action = QtWidgets.QWidgetAction(menu)
        colour_selector_action.setDefaultWidget(colour_dialog)
        menu.addAction(colour_selector_action)

        button.setMenu(menu)
        button.setPopupMode(QtWidgets.QToolButton.InstantPopup)
Exemplo n.º 3
0
    def _on_clicked(self):
        dialog = QtWidgets.QColorDialog(self.color())

        if not dialog.exec_():
            return

        self.setColor(dialog.selectedColor())
        self.button.repaint()
Exemplo n.º 4
0
	def onColorPicker(self):
		'''
		Show color-picker dialog to select color.
		'''
		dlg = QtWidgets.QColorDialog(self)
		if self._color:
			dlg.setCurrentColor(QtGui.QColor(self._color))

		if dlg.exec_():
			self.setColor(dlg.currentColor().name())
Exemplo n.º 5
0
 def OpenDialog(self):
     """ open a color chooser dialog """
     # get new color from color picker
     self.current_color = QtGui.QColor(*tuple(mpl.colors.to_rgba_array(self.getColor())[0] * 255))
     self.dialog = QtWidgets.QColorDialog(self.current_color, self.parent())
     self.dialog.setOptions(QtWidgets.QColorDialog.ShowAlphaChannel)
     for index, color in enumerate(plt.rcParams['axes.prop_cycle'].by_key()['color']):
         self.dialog.setCustomColor(index, QtGui.QColor(color))
     self.dialog.open(self.dialog_finished)
     self.dialog.currentColorChanged.connect(self.dialog_changed)
     self.dialog.rejected.connect(self.dialog_rejected)
Exemplo n.º 6
0
    def select_color(self, idx: int) -> None:
        lay = self.table_model.layer(idx)
        if lay is None:
            return

        cur = numpy.array(lay.color) * 255
        initial = QtGui.QColor(*cur)
        c = QtWidgets.QColorDialog().getColor(initial)
        if c.isValid():
            r, g, b, _ = c.getRgb()
            lay.color = (r/255.0, g/255.0, b/255.0)
            self.table_model.headerDataChanged.emit(QtCore.Qt.Vertical, idx, idx)
Exemplo n.º 7
0
	def onClick(self):
		if self.dialog is None:
			self.dialog = QtWidgets.QColorDialog()
			self.dialog.setCurrentColor(QtGui.QColor(*self.colorValue))
			self.dialog.currentColorChanged.connect(self.onColorAdjusted)

		self.dialog.setOption(self.dialog.ColorDialogOption.ShowAlphaChannel, self.hasAlpha)

		preservedValue = self.colorValue
		self.dialog.exec_()

		if self.dialog.result() != QtWidgets.QDialog.Accepted:
			self.setValue(preservedValue)
			self.valueChanged.emit(preservedValue)
Exemplo n.º 8
0
 def __init__(self, window, pts):
     self.window = window  #: window.Window: Parent window that this ROI belongs to
     self.colorDialog = QtWidgets.QColorDialog()
     self.colorDialog.colorSelected.connect(self.colorSelected)
     self.window.closeSignal.connect(self.delete)
     self.window.currentROI = self
     self.traceWindow = None  #: tracefig.TraceFig: the Trace window that this ROI is plotted in. To test if roi is plotted, check 'roi.traceWindow is None'
     self.distWindow = None
     self.pts = np.array(
         pts)  #: list: Array of points that make up the boundary of the ROI
     self.linkedROIs = set()
     self.resetSignals()
     self.makeMenu()
     self.surroundROI = False
Exemplo n.º 9
0
 def changeColor(self):
     self.selectRow(self.rowFromWidget(self.sender()))
     existing_color = createQColor(self.selectedView().color)
     dialog = QtWidgets.QColorDialog()
     for index, color in enumerate(colors):
         dialog.setCustomColor(index, createQColor(color))
     color = dialog.getColor(existing_color)
     if not color.isValid():
         logging.warning(f'Non valid color {color.getRgb()[0:3]}')
         return
     r, g, b = color.getRgb()[0:3]
     self.selectedView().set_color((r, g, b))
     self.sender().setStyleSheet(f"background-color: rgb({r}, {g}, {b})")
     self.colorChanged.emit(self.selectedView())
Exemplo n.º 10
0
    def onColorPicker(self):
        '''
        Show color-picker dialog to select color.

        Qt will use the native dialog by default.

        '''
        dlg = QtWidgets.QColorDialog()
        dlg.setStyleSheet("")
        if self._color:
            dlg.setCurrentColor(self._color)

        if dlg.exec_():
            self.setColor(dlg.currentColor())
            self.colorChanged.emit()
Exemplo n.º 11
0
def main():
    """Execute QDarkStyle example."""
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument(
        '--palette',
        default='dark',
        type=str,
        choices=['dark', 'light', 'none'],
        help=
        "Palette to display. Using 'none' there is no style sheet applied, OS like."
    )
    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. Default is 'qtpy'"
    )
    parser.add_argument('--test',
                        action='store_true',
                        help="Auto close window after 2s.")
    parser.add_argument('--screenshots',
                        action='store_true',
                        help="Generate screenshots on images folder.")
    parser.add_argument(
        '--offscreen',
        action='store_true',
        help="Do not try to show the screen (running on server).")
    parser.add_argument('--reset',
                        action='store_true',
                        help="Reset GUI settings (position, size) then opens.")

    # Parsing arguments from command line
    args = parser.parse_args()

    # To avoid problems when testing without screen
    if args.test or args.offscreen:
        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, uic
    from qtpy import __version__ as QTPY_VERSION
    from qtpy import QtCore, QtGui, QtWidgets

    # 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'

    # create the application
    app = QtWidgets.QApplication(sys.argv)
    app.setOrganizationName('QDarkStyle')
    app.setApplicationName('QDarkStyle Example')

    style = ''

    if args.palette == 'dark':
        style = qdarkstyle.load_stylesheet(palette=DarkPalette)
    elif args.palette == 'light':
        style = qdarkstyle.load_stylesheet(palette=LightPalette)

    app.setStyleSheet(style)

    # create main window
    window = QtWidgets.QMainWindow()
    window.setObjectName('mainwindow')
    uic.loadUi(os.path.join(here, 'ui/mw_menus.ui'), window)

    title = (
        "QDarkStyle Example - (" + f"QDarkStyle=v{qdarkstyle.__version__}, " +
        f"QtPy=v{QTPY_VERSION}, " + f"{API_NAME}=v{API_VERSION}, " +
        f"Qt=v{QT_VERSION}, " + f"Python=v{platform.python_version()}, "
        # Operating system info are maybe too much,
        # but different OS add info in different places
        + f"System={platform.system()}, " + f"Release={platform.release()}, " +
        f"Version={platform.version()}, " + f"Platform={platform.platform()}" +
        ")")

    _logger.info(title)
    window.setWindowTitle(title)

    # Create docks for buttons
    dw_buttons = QtWidgets.QDockWidget()
    dw_buttons.setObjectName('buttons')
    uic.loadUi(os.path.join(here, 'ui/dw_buttons.ui'), dw_buttons)
    window.addDockWidget(QtCore.Qt.RightDockWidgetArea, dw_buttons)

    # Set state indeterminate (value=1)
    dw_buttons.checkBoxTristate.stateChanged.connect(
        dw_buttons.checkBoxTristateDis.setCheckState)
    dw_buttons.checkBoxTristate.setCheckState(1)

    # Add actions on popup toolbuttons
    menu = QtWidgets.QMenu()

    for action in ['Action A', 'Action B', 'Action C']:
        menu.addAction(action)

    # Add menu in special tool buttons
    dw_buttons.toolButtonDelayedPopup.setMenu(menu)
    dw_buttons.toolButtonInstantPopup.setMenu(menu)
    dw_buttons.toolButtonMenuButtonPopup.setMenu(menu)

    # Add menu in toolbar #251
    action_menu = QtWidgets.QAction(u'Menu action', window.toolBarMenus)
    action_menu.setMenu(menu)
    window.toolBarMenus.addAction(action_menu)

    # Add color to tab title text #212
    window.tabWidget.tabBar().setTabTextColor(3, QtGui.QColor('red'))

    # Connect dialogs to buttons
    window.toolButtonColorDialog.clicked.connect(
        lambda: QtWidgets.QColorDialog().exec())
    window.toolButtonFileDialog.clicked.connect(
        lambda: QtWidgets.QFileDialog().exec())
    window.toolButtonFileDialogStatic.clicked.connect(
        lambda: QtWidgets.QFileDialog.getOpenFileNames())
    window.toolButtonFontDialog.clicked.connect(
        lambda: QtWidgets.QFontDialog().exec())
    window.toolButtonInputDialog.clicked.connect(
        lambda: QtWidgets.QInputDialog().exec())
    window.toolButtonMessageBox.clicked.connect(
        lambda: QtWidgets.QMessageBox().exec())
    window.toolButtonMessageBoxStatic.clicked.connect(
        lambda: QtWidgets.QMessageBox.critical(window, "Critical title",
                                               "Critical message"))
    window.toolButtonProgressDialog.clicked.connect(
        lambda: QtWidgets.QProgressDialog().exec())

    # Create docks for buttons
    dw_displays = QtWidgets.QDockWidget()
    dw_displays.setObjectName('displays')
    uic.loadUi(os.path.join(here, 'ui/dw_displays.ui'), dw_displays)
    window.addDockWidget(QtCore.Qt.RightDockWidgetArea, dw_displays)

    # Create docks for inputs - no fields
    dw_inputs_no_fields = QtWidgets.QDockWidget()
    dw_inputs_no_fields.setObjectName('inputs_no_fields')
    uic.loadUi(os.path.join(here, 'ui/dw_inputs_no_fields.ui'),
               dw_inputs_no_fields)
    window.addDockWidget(QtCore.Qt.RightDockWidgetArea, dw_inputs_no_fields)

    # Create docks for inputs - fields
    dw_inputs_fields = QtWidgets.QDockWidget()
    dw_inputs_fields.setObjectName('inputs_fields')
    uic.loadUi(os.path.join(here, 'ui/dw_inputs_fields.ui'), dw_inputs_fields)
    window.addDockWidget(QtCore.Qt.RightDockWidgetArea, dw_inputs_fields)

    # Create docks for widgets
    dw_widgets = QtWidgets.QDockWidget()
    dw_widgets.setObjectName('widgets')
    uic.loadUi(os.path.join(here, 'ui/dw_widgets.ui'), dw_widgets)
    window.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dw_widgets)

    # Create docks for views
    dw_views = QtWidgets.QDockWidget()
    dw_views.setObjectName('views')
    uic.loadUi(os.path.join(here, 'ui/dw_views.ui'), dw_views)
    window.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dw_views)

    # Create docks for containers - no tabs
    dw_containers_no_tabs = QtWidgets.QDockWidget()
    dw_containers_no_tabs.setObjectName('containers_no_tabs')
    uic.loadUi(os.path.join(here, 'ui/dw_containers_no_tabs.ui'),
               dw_containers_no_tabs)
    window.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dw_containers_no_tabs)

    # Create docks for containters - tabs
    dw_containers_tabs = QtWidgets.QDockWidget()
    dw_containers_tabs.setObjectName('containers_tabs')
    uic.loadUi(os.path.join(here, 'ui/dw_containers_tabs.ui'),
               dw_containers_tabs)
    window.addDockWidget(QtCore.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 = QtWidgets.QStatusBar()
    qstatusbar.addWidget(
        QtWidgets.QLabel(
            'Issue Spyder #9120, #9121 - background not matching.'))
    qstatusbar.addWidget(QtWidgets.QPushButton('OK'))

    # Add info also in status bar for screenshots get it
    qstatusbar.addWidget(QtWidgets.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:
        QtCore.QTimer.singleShot(2000, app.exit)

    # Save screenshots for different displays and quit
    if args.screenshots:
        window.showFullScreen()
        create_screenshots(app, window, args)
    # Do not read settings when taking screenshots - like reset
    else:
        _read_settings(window, args.reset, QtCore.QSettings)
        window.showMaximized()

    app.exec_()
    _write_settings(window, QtCore.QSettings)