def __init__(self, *args, **kwargs): """Lineedit search widget with clear button.""" super(PasswordEdit, self).__init__(*args, **kwargs) self._empty = True self._show_icons = True self.button_icon = ButtonShow() # Setup self.button_icon.setDefault(False) self.button_icon.setFocusPolicy(Qt.NoFocus) self.button_icon.setCheckable(False) self.setAttribute(Qt.WA_MacShowFocusRect, False) self.setEchoMode(QLineEdit.Password) # Layouts layout = QHBoxLayout() layout.addWidget(self.button_icon, 0, Qt.AlignRight) layout.setSpacing(0) layout.addSpacing(2) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) # Signals self.button_icon.sig_entered.connect(self._show_password) self.button_icon.sig_left.connect(self._hide_password) self.textEdited.connect(self.update_box) self.update_box(None) self.set_icon_size(16, 16) self.setTabOrder(self, self.button_icon)
def create_scedit(self, text, option, default=NoDefault, tip=None, without_layout=False): label = QLabel(text) clayout = ColorLayout(QColor(Qt.black), self) clayout.lineedit.setMaximumWidth(80) if tip is not None: clayout.setToolTip(tip) cb_bold = QCheckBox() cb_bold.setIcon(ima.icon('bold')) cb_bold.setToolTip(_("Bold")) cb_italic = QCheckBox() cb_italic.setIcon(ima.icon('italic')) cb_italic.setToolTip(_("Italic")) self.scedits[(clayout, cb_bold, cb_italic)] = (option, default) if without_layout: return label, clayout, cb_bold, cb_italic layout = QHBoxLayout() layout.addWidget(label) layout.addLayout(clayout) layout.addSpacing(10) layout.addWidget(cb_bold) layout.addWidget(cb_italic) layout.addStretch(1) layout.setContentsMargins(0, 0, 0, 0) widget = QWidget(self) widget.setLayout(layout) return widget
def __init__(self, *args, **kwargs): super(ClosePackageManagerDialog, self).__init__(*args, **kwargs) self.label_icon = QLabel() self.label_about = QLabel('Conda is still busy.\n\n' 'Do you want to cancel the process?') self.button_ok = QPushButton('Yes') self.button_cancel = QPushButton('No') self.buttonbox = QDialogButtonBox(Qt.Horizontal) # Widget setup self.buttonbox.addButton(self.button_ok, QDialogButtonBox.ActionRole) self.buttonbox.addButton(self.button_cancel, QDialogButtonBox.ActionRole) # self.label_icon.setPixmap(QPixmap(images.ANACONDA_ICON_64_PATH)) self.setWindowTitle("Cancel Process") # Layouts h_layout = QHBoxLayout() h_layout.addWidget(self.label_icon, 0, Qt.AlignTop) h_layout.addSpacing(10) h_layout.addWidget(self.label_about) main_layout = QVBoxLayout() main_layout.addLayout(h_layout) main_layout.addSpacing(20) main_layout.addWidget(self.buttonbox) self.setLayout(main_layout) # Signals self.button_ok.clicked.connect(self.accept) self.button_cancel.clicked.connect(self.reject)
def __init__(self, ert: EnKFMain, notifier: ErtNotifier, config_file: str): self.notifier = notifier QWidget.__init__(self) self.ert = ert self.facade = LibresFacade(ert) self._config_file = config_file self.setObjectName("Simulation_panel") layout = QVBoxLayout() self._simulation_mode_combo = QComboBox() self._simulation_mode_combo.setObjectName("Simulation_mode") addHelpToWidget(self._simulation_mode_combo, "run/simulation_mode") self._simulation_mode_combo.currentIndexChanged.connect( self.toggleSimulationMode) simulation_mode_layout = QHBoxLayout() simulation_mode_layout.addSpacing(10) simulation_mode_layout.addWidget(QLabel("Simulation mode:"), 0, Qt.AlignVCenter) simulation_mode_layout.addWidget(self._simulation_mode_combo, 0, Qt.AlignVCenter) simulation_mode_layout.addSpacing(20) self.run_button = QToolButton() self.run_button.setObjectName("start_simulation") self.run_button.setText("Start simulation") self.run_button.setIcon(resourceIcon("play_circle.svg")) self.run_button.setIconSize(QSize(32, 32)) self.run_button.clicked.connect(self.runSimulation) self.run_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) addHelpToWidget(self.run_button, "run/start_simulation") simulation_mode_layout.addWidget(self.run_button) simulation_mode_layout.addStretch(1) layout.addSpacing(5) layout.addLayout(simulation_mode_layout) layout.addSpacing(10) self._simulation_stack = QStackedWidget() self._simulation_stack.setLineWidth(1) self._simulation_stack.setFrameStyle(QFrame.StyledPanel) layout.addWidget(self._simulation_stack) self._simulation_widgets = OrderedDict() """ :type: OrderedDict[BaseRunModel,SimulationConfigPanel]""" self.addSimulationConfigPanel(SingleTestRunPanel(ert, notifier)) self.addSimulationConfigPanel(EnsembleExperimentPanel(ert, notifier)) if self.facade.have_observations: self.addSimulationConfigPanel(EnsembleSmootherPanel(ert, notifier)) self.addSimulationConfigPanel( MultipleDataAssimilationPanel(self.facade, notifier)) self.addSimulationConfigPanel( IteratedEnsembleSmootherPanel(self.facade, notifier)) self.setLayout(layout)
def __init__(self, *args, **kwargs): """Lineedit search widget with clear button.""" super(LineEditSearch, self).__init__(*args, **kwargs) self._empty = True self._show_icons = False self.button_icon = ButtonSearch() # Setup self.button_icon.setDefault(True) self.button_icon.setFocusPolicy(Qt.NoFocus) self.setAttribute(Qt.WA_MacShowFocusRect, False) # Layouts layout = QHBoxLayout() layout.addWidget(self.button_icon, 0, Qt.AlignRight) layout.setSpacing(0) layout.addSpacing(2) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) # Signals self.textEdited.connect(self.update_box) self.button_icon.clicked.connect(self.clear_text) self.update_box(None) self.set_icon_size(16, 16) self.setTabOrder(self, self.button_icon)
def __init__(self, parent, statusbar, icon=None): """Status bar widget base.""" super(StatusBarWidget, self).__init__(parent) # Variables self.value = None # Widget self._status_bar = statusbar self._icon = None self._pixmap = None self._icon_size = QSize(16, 16) # Should this be adjustable? self.label_icon = QLabel() self.label_value = QLabel() # Layout setup layout = QHBoxLayout(self) layout.setSpacing(0) # Reduce space between icon and label layout.addWidget(self.label_icon) layout.addWidget(self.label_value) layout.addSpacing(20) layout.setContentsMargins(0, 0, 0, 0) # Widget setup self.set_icon(icon) # See spyder-ide/spyder#9044. self.text_font = QFont(QFont().defaultFamily(), weight=QFont.Normal) self.label_value.setAlignment(Qt.AlignRight) self.label_value.setFont(self.text_font) # Setup statusbar.addPermanentWidget(self) self.set_value('') self.update_tooltip()
def set_corner_widgets(self, corner_widgets): """ Set tabs corner widgets corner_widgets: dictionary of (corner, widgets) corner: Qt.TopLeftCorner or Qt.TopRightCorner widgets: list of widgets (may contains integers to add spacings) """ assert isinstance(corner_widgets, dict) assert all(key in (Qt.TopLeftCorner, Qt.TopRightCorner) for key in corner_widgets) self.corner_widgets.update(corner_widgets) for corner, widgets in list(self.corner_widgets.items()): cwidget = QWidget() cwidget.hide() # This removes some white dots in our tabs (not all but most). # See spyder-ide/spyder#15081 cwidget.setObjectName('corner-widget') cwidget.setStyleSheet( "QWidget#corner-widget {border-radius: '0px'}") prev_widget = self.cornerWidget(corner) if prev_widget: prev_widget.close() self.setCornerWidget(cwidget, corner) clayout = QHBoxLayout() clayout.setContentsMargins(0, 0, 0, 0) for widget in widgets: if isinstance(widget, int): clayout.addSpacing(widget) else: clayout.addWidget(widget) cwidget.setLayout(clayout) cwidget.show()
def set_corner_widgets(self, corner_widgets): """ Set tabs corner widgets corner_widgets: dictionary of (corner, widgets) corner: Qt.TopLeftCorner or Qt.TopRightCorner widgets: list of widgets (may contains integers to add spacings) """ assert isinstance(corner_widgets, dict) assert all(key in (Qt.TopLeftCorner, Qt.TopRightCorner) for key in corner_widgets) self.corner_widgets.update(corner_widgets) for corner, widgets in list(self.corner_widgets.items()): cwidget = QWidget() cwidget.hide() prev_widget = self.cornerWidget(corner) if prev_widget: prev_widget.close() self.setCornerWidget(cwidget, corner) clayout = QHBoxLayout() clayout.setContentsMargins(0, 0, 0, 0) for widget in widgets: if isinstance(widget, int): clayout.addSpacing(widget) else: clayout.addWidget(widget) cwidget.setLayout(clayout) cwidget.show()
def create_widget(self, widget=None, label=None, option=None, hint=None, check=None): if hint: widget.setPlaceholderText(hint) config_value = self.get_option(option) widget.label = QLabel(label) widget.option = option widget.set_value(config_value) widget.label_information = QLabel() widget.label_information.setMinimumWidth(20) widget.label_information.setMaximumWidth(20) form_widget = QWidget() h_layout = QHBoxLayout() h_layout.addSpacing(4) h_layout.addWidget(widget.label_information, 0, Qt.AlignRight) h_layout.addWidget(widget, 0, Qt.AlignLeft) form_widget.setLayout(h_layout) if check: widget.check_value = lambda value: check(value) else: widget.check_value = lambda value: (True, '') self.widgets.append(widget) self.grid_layout.addWidget(widget.label, self.row, 0, Qt.AlignRight | Qt.AlignCenter) self.grid_layout.addWidget(form_widget, self.row, 1, Qt.AlignLeft | Qt.AlignCenter) self.row += 1
def create_scedit(self, text, option, default=NoDefault, tip=None, without_layout=False, section=None): label = QLabel(text) clayout = ColorLayout(QColor(Qt.black), self) clayout.lineedit.setMaximumWidth(80) if tip is not None: clayout.setToolTip(tip) cb_bold = QCheckBox() cb_bold.setIcon(ima.icon('bold')) cb_bold.setToolTip(_("Bold")) cb_italic = QCheckBox() cb_italic.setIcon(ima.icon('italic')) cb_italic.setToolTip(_("Italic")) self.scedits[(clayout, cb_bold, cb_italic)] = (section, option, default) if without_layout: return label, clayout, cb_bold, cb_italic layout = QHBoxLayout() layout.addWidget(label) layout.addLayout(clayout) layout.addSpacing(10) layout.addWidget(cb_bold) layout.addWidget(cb_italic) layout.addStretch(1) layout.setContentsMargins(0, 0, 0, 0) widget = QWidget(self) widget.setLayout(layout) return widget
def __init__(self, config_file): QWidget.__init__(self) self._config_file = config_file self._ee_config = None if FeatureToggling.is_enabled("ensemble-evaluator"): self._ee_config = EvaluatorServerConfig() self.setObjectName("Simulation_panel") layout = QVBoxLayout() self._simulation_mode_combo = QComboBox() self._simulation_mode_combo.setObjectName("Simulation_mode") addHelpToWidget(self._simulation_mode_combo, "run/simulation_mode") self._simulation_mode_combo.currentIndexChanged.connect( self.toggleSimulationMode) simulation_mode_layout = QHBoxLayout() simulation_mode_layout.addSpacing(10) simulation_mode_layout.addWidget(QLabel("Simulation mode:"), 0, Qt.AlignVCenter) simulation_mode_layout.addWidget(self._simulation_mode_combo, 0, Qt.AlignVCenter) simulation_mode_layout.addSpacing(20) self.run_button = QToolButton() self.run_button.setObjectName("start_simulation") self.run_button.setIconSize(QSize(32, 32)) self.run_button.setText("Start Simulation") self.run_button.setIcon(resourceIcon("ide/gear_in_play")) self.run_button.clicked.connect(self.runSimulation) self.run_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) addHelpToWidget(self.run_button, "run/start_simulation") simulation_mode_layout.addWidget(self.run_button) simulation_mode_layout.addStretch(1) layout.addSpacing(5) layout.addLayout(simulation_mode_layout) layout.addSpacing(10) self._simulation_stack = QStackedWidget() self._simulation_stack.setLineWidth(1) self._simulation_stack.setFrameStyle(QFrame.StyledPanel) layout.addWidget(self._simulation_stack) self._simulation_widgets = OrderedDict() """ :type: OrderedDict[BaseRunModel,SimulationConfigPanel]""" self.addSimulationConfigPanel(SingleTestRunPanel()) self.addSimulationConfigPanel(EnsembleExperimentPanel()) if ERT.ert.have_observations(): self.addSimulationConfigPanel(EnsembleSmootherPanel()) self.addSimulationConfigPanel(MultipleDataAssimilationPanel()) self.addSimulationConfigPanel(IteratedEnsembleSmootherPanel()) self.setLayout(layout)
def set_layout(self): """Set layout for default widgets.""" # Icon if self.show_icon: self._icon = self.get_icon() self._pixmap = None self._icon_size = QSize(16, 16) # Should this be adjustable? self.label_icon = QLabel() self.set_icon() # Label if self.show_label: self.label_value = QLabel() self.set_value('') # See spyder-ide/spyder#9044. self.text_font = QFont(QFont().defaultFamily(), weight=QFont.Normal) self.label_value.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.label_value.setFont(self.text_font) # Custom widget if self.CUSTOM_WIDGET_CLASS: if not issubclass(self.CUSTOM_WIDGET_CLASS, QWidget): raise SpyderAPIError( 'Any custom status widget must subclass QWidget!') self.custom_widget = self.CUSTOM_WIDGET_CLASS(self._parent) # Spinner if self.show_spinner: self.spinner = create_waitspinner(size=14, parent=self) self.spinner.hide() # Layout setup layout = QHBoxLayout(self) layout.setSpacing(0) # Reduce space between icon and label if self.show_icon: layout.addWidget(self.label_icon) if self.show_label: layout.addWidget(self.label_value) if self.custom_widget: layout.addWidget(self.custom_widget) if self.show_spinner: layout.addWidget(self.spinner) if is_dark_interface(): layout.addSpacing(0) else: layout.addSpacing(10) layout.setContentsMargins(0, 0, 0, 0) layout.setAlignment(Qt.AlignVCenter) # Setup self.update_tooltip()
def __init__(self, *args, **kwargs): super(AboutDialog, self).__init__(*args, **kwargs) self.tracker = GATracker() text = """<b>Anaconda Navigator {version}</b><br> <br>Copyright © 2016 Continuum Analytics <p>Created by Continuum Analytics <br> <p>For bug reports and feature requests, please visit our """.format(version=__version__) self.label_icon = QLabel() self.label_about = QLabel(text) self.button_link = ButtonLink('Issue Tracker') self.button_label = ButtonLabel('on GitHub.') self.button_ok = QPushButton('Ok') # Widget setup self.button_ok.setMinimumWidth(70) self.label_about.setOpenExternalLinks(True) self.label_icon.setPixmap(QPixmap(images.ANACONDA_ICON_64_PATH)) self.setWindowTitle("About Anaconda Navigator") # Layouts h_layout = QHBoxLayout() h_layout.addWidget(self.label_icon, 0, Qt.AlignTop) h_layout.addSpacing(10) content_layout = QVBoxLayout() content_layout.addWidget(self.label_about, 0, Qt.AlignBottom) content_layout.setContentsMargins(0, 0, 0, 0) h_content_layout = QHBoxLayout() h_content_layout.addWidget(self.button_link, 0, Qt.AlignLeft) h_content_layout.addWidget(self.button_label, 0, Qt.AlignLeft) h_content_layout.addStretch(0) h_content_layout.setContentsMargins(0, 0, 0, 0) content_layout.addLayout(h_content_layout) h_layout.addLayout(content_layout) buttons_layout = QHBoxLayout() buttons_layout.addStretch() buttons_layout.addWidget(self.button_ok) main_layout = QVBoxLayout() main_layout.addLayout(h_layout) main_layout.addSpacing(24) main_layout.addLayout(buttons_layout) self.setLayout(main_layout) # Signals self.button_ok.clicked.connect(self.accept) self.button_link.clicked.connect( lambda: self.open_url(self.GITHUB_URL))
def _setup_settings_group(self): self.group_settings = QGroupBox("Settings for Fitting Algorithm") self.pb_fit_param_general = QPushButton("General ...") self.pb_fit_param_general.clicked.connect( self.pb_fit_param_general_clicked) self.pb_fit_param_shared = QPushButton("Shared ...") self.pb_fit_param_shared.clicked.connect( self.pb_fit_param_shared_clicked) self.pb_fit_param_lines = QPushButton("Lines ...") self.pb_fit_param_lines.clicked.connect( self.pb_fit_param_lines_clicked) fit_strategy_list = self.gpc.get_fit_strategy_list() combo_items = [fitting_preset_names[_] for _ in fit_strategy_list] combo_items = ["None"] + combo_items self.cb_step1 = QComboBox() self.cb_step1.setMinimumWidth(150) self.cb_step1.addItems(combo_items) self.cb_step1.setCurrentIndex(1) # Should also be set based on data self.cb_step2 = QComboBox() self.cb_step2.setMinimumWidth(150) self.cb_step2.addItems(combo_items) vbox = QVBoxLayout() hbox = QHBoxLayout() hbox.addWidget(self.pb_fit_param_general) hbox.addWidget(self.pb_fit_param_shared) hbox.addWidget(self.pb_fit_param_lines) vbox.addLayout(hbox) hbox = QHBoxLayout() hbox.addWidget(QLabel("Fitting step 1:")) hbox.addSpacing(20) hbox.addWidget(self.cb_step1) hbox.addStretch(1) vbox.addLayout(hbox) hbox = QHBoxLayout() hbox.addWidget(QLabel("Fitting step 2:")) hbox.addSpacing(20) hbox.addWidget(self.cb_step2) hbox.addStretch(1) vbox.addLayout(hbox) self.group_settings.setLayout(vbox)
def setupui(self): """.""" hbl = QHBoxLayout(self) self.spectx = MultiTurnSumWidget(self, device=self.device, prefix=self.prefix, orbtype='X', csorb=self._csorb) self.specty = MultiTurnSumWidget(self, device=self.device, prefix=self.prefix, orbtype='Y', csorb=self._csorb) hbl.addWidget(self.spectx) hbl.addSpacing(50) hbl.addWidget(self.specty)
def create_widget( self, widget=None, label=None, option=None, hint=None, check=None, info=None, ): """Create preference option widget and add to layout.""" config_value = self.get_option(option) widget._text = label widget.label = QLabel(label) widget.option = option widget.set_value(config_value) widget.label_information = QLabel() widget.label_information.setMinimumWidth(16) widget.label_information.setMaximumWidth(16) form_widget = QWidget() h_layout = QHBoxLayout() h_layout.addSpacing(4) h_layout.addWidget(widget.label_information, 0, Qt.AlignRight) h_layout.addWidget(widget, 0, Qt.AlignLeft) h_layout.addWidget(QLabel(hint or ''), 0, Qt.AlignLeft) form_widget.setLayout(h_layout) if check: widget.check_value = lambda value: check(value) else: widget.check_value = lambda value: (True, '') if info: label = widget.label_information label = PreferencesDialog.update_icon(label, INFO_ICON) label.setToolTip(info) self.widgets.append(widget) self.widgets_dic[option] = widget self.grid_layout.addWidget( widget.label, self.row, 0, Qt.AlignRight | Qt.AlignCenter ) self.grid_layout.addWidget( form_widget, self.row, 1, Qt.AlignLeft | Qt.AlignCenter ) self.row += 1
def __init__(self, parent=None, spinner=False): """Status bar widget base.""" super().__init__(parent) # Variables self.value = None self._parent = parent # Widget self._icon = self.get_icon() self._pixmap = None self._icon_size = QSize(16, 16) # Should this be adjustable? self.label_icon = QLabel() self.label_value = QLabel() self.spinner = None if spinner: self.spinner = create_waitspinner(size=14, parent=self) # Layout setup layout = QHBoxLayout(self) layout.setSpacing(0) # Reduce space between icon and label layout.addWidget(self.label_icon) layout.addWidget(self.label_value) if spinner: layout.addWidget(self.spinner) self.spinner.hide() if is_dark_interface(): layout.addSpacing(0) else: layout.addSpacing(10) layout.setContentsMargins(0, 0, 0, 0) # Widget setup self.set_icon() # See spyder-ide/spyder#9044. self.text_font = QFont(QFont().defaultFamily(), weight=QFont.Normal) self.label_value.setAlignment(Qt.AlignRight) self.label_value.setFont(self.text_font) # Setup self.set_value('') self.update_tooltip()
def initLayout(self): sequenceLayout = QHBoxLayout() sequenceLayout.setSpacing(0) sequenceLayout.setContentsMargins(0, 0, 0, 0) for i, label in enumerate(self.labels): indexWidget = IndexWidget(text=label, index=(i + 1)) self.indexWidgets.append(indexWidget) sequenceLayout.addWidget(indexWidget, stretch=0) isLast = i == (len(self.labels) - 1) if not isLast: chevronWidget = ChevronWidget() self.chevronWidgets.append(chevronWidget) sequenceLayout.addWidget(chevronWidget, stretch=0) # navigation buttons backButton = QPushButton() backButton.setText("Back") backButton.setObjectName("backButton") self.backButton = backButton nextButton = QPushButton() nextButton.setText("Next") nextButton.setObjectName("nextButton") self.nextButton = nextButton buttonsLayout = QHBoxLayout() buttonsLayout.addWidget(backButton) buttonsLayout.addWidget(nextButton) buttonsLayout.setContentsMargins(0, 0, 0, 0) layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addStretch(1) layout.addLayout(sequenceLayout) layout.addSpacing(30) layout.addLayout(buttonsLayout) layout.addSpacing(20) self.setLayout(layout)
def __init__(self, *args, **kwargs): super(QuitApplicationDialog, self).__init__(*args, **kwargs) self.label_icon = QLabel() self.label_about = QLabel('Quit Anaconda Navigator?') self.button_ok = QPushButton('Yes') self.button_cancel = ButtonCancel('No') self.buttonbox = QDialogButtonBox(Qt.Horizontal) self.checkbox = QCheckBox("Don't show again") # Widget setup if CONF.get('main', 'hide_quit_dialog'): hide_dialog = Qt.Checked else: hide_dialog = Qt.Unchecked self.checkbox.setChecked(hide_dialog) self.buttonbox.addButton(self.button_ok, QDialogButtonBox.ActionRole) self.buttonbox.addButton(self.button_cancel, QDialogButtonBox.ActionRole) self.label_icon.setPixmap(QPixmap(images.ANACONDA_ICON_64_PATH)) self.setWindowTitle("Quit application") # Layouts h_layout = QHBoxLayout() h_layout.addWidget(self.label_icon, 0, Qt.AlignTop) h_layout.addSpacing(10) h_layout.addWidget(self.label_about) main_layout = QVBoxLayout() main_layout.addLayout(h_layout) main_layout.addWidget(self.checkbox, 0, Qt.AlignRight) main_layout.addSpacing(24) main_layout.addWidget(self.buttonbox) self.setLayout(main_layout) # Signals self.button_ok.clicked.connect(self.accept) self.button_cancel.clicked.connect(self.reject) # Setup self.update_style_sheet()
def __init__(self, *args): QMainWindow.__init__(self, *args) self.plot = BodePlot(self) self.plot.setContentsMargins(5, 5, 5, 0) self.setContextMenuPolicy(Qt.NoContextMenu) self.setCentralWidget(self.plot) toolBar = QToolBar(self) self.addToolBar(toolBar) btnPrint = QToolButton(toolBar) btnPrint.setText("Print") btnPrint.setIcon(QIcon(QPixmap(print_xpm))) btnPrint.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnPrint) btnPrint.clicked.connect(self.print_) btnExport = QToolButton(toolBar) btnExport.setText("Export") btnExport.setIcon(QIcon(QPixmap(print_xpm))) btnExport.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) toolBar.addWidget(btnExport) btnExport.clicked.connect(self.exportDocument) toolBar.addSeparator() dampBox = QWidget(toolBar) dampLayout = QHBoxLayout(dampBox) dampLayout.setSpacing(0) dampLayout.addWidget(QWidget(dampBox), 10) # spacer dampLayout.addWidget(QLabel("Damping Factor", dampBox), 0) dampLayout.addSpacing(10) toolBar.addWidget(dampBox) self.statusBar() self.showInfo()
def __init__(self, parent, statusbar, icon=None): """Status bar widget base.""" super(StatusBarWidget, self).__init__(parent) # Variables self.value = None # Widget self._status_bar = statusbar self._icon = None self._pixmap = None self._icon_size = QSize(16, 16) # Should this be adjustable? self.label_icon = QLabel() if icon is not None else None self.label_value = QLabel() # Widget setup self.set_icon(icon) # See spyder-ide/spyder#9044. self.text_font = QFont(get_font(option='font')) self.text_font.setPointSize(self.font().pointSize()) self.text_font.setBold(True) self.label_value.setAlignment(Qt.AlignRight) self.label_value.setFont(self.text_font) # Layout layout = QHBoxLayout() if icon is not None: layout.addWidget(self.label_icon) layout.addWidget(self.label_value) layout.addSpacing(20) # Layout setup layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) # Setup statusbar.addPermanentWidget(self) self.set_value('') self.update_tooltip()
def __init__(self, parent, statusbar, icon=None): """Status bar widget base.""" super(StatusBarWidget, self).__init__(parent) # Variables self.value = None # Widget self._icon = icon self._pixmap = icon.pixmap(QSize(16, 16)) if icon is not None else None self.label_icon = QLabel() if icon is not None else None self.label_value = QLabel() # Widget setup if icon is not None: self.label_icon.setPixmap(self._pixmap) # See spyder-ide/spyder#9044. self.text_font = QFont(get_font(option='font')) self.text_font.setPointSize(self.font().pointSize()) self.text_font.setBold(True) self.label_value.setAlignment(Qt.AlignRight) self.label_value.setFont(self.text_font) if self.TIP: self.setToolTip(self.TIP) self.label_value.setToolTip(self.TIP) # Layout layout = QHBoxLayout() if icon is not None: layout.addWidget(self.label_icon) layout.addWidget(self.label_value) layout.addSpacing(20) # Layout setup layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) # Setup statusbar.addPermanentWidget(self)
def __init__(self, ert): self.ert = ert QWidget.__init__(self) layout = QHBoxLayout() layout.addSpacing(10) self._workflow_combo = QComboBox() addHelpToWidget(self._workflow_combo, "run/workflow") self._workflow_combo.addItems( sorted(ert.getWorkflowList().getWorkflowNames(), key=str.lower)) layout.addWidget(QLabel("Select Workflow:"), 0, Qt.AlignVCenter) layout.addWidget(self._workflow_combo, 0, Qt.AlignVCenter) # simulation_mode_layout.addStretch() layout.addSpacing(20) self.run_button = QToolButton() self.run_button.setIconSize(QSize(32, 32)) self.run_button.setText("Start Workflow") self.run_button.setIcon(resourceIcon("play_circle.svg")) self.run_button.clicked.connect(self.startWorkflow) self.run_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) layout.addWidget(self.run_button) layout.addStretch(1) self.setLayout(layout) self._running_workflow_dialog = None self.workflowSucceeded.connect(self.workflowFinished) self.workflowFailed.connect(self.workflowFinishedWithFail) self.workflowKilled.connect(self.workflowStoppedByUser) self._workflow_runner = None """:type: WorkflowRunner"""
def __init__(self, parent, statusbar, icon=None): """Status bar widget base.""" super(StatusBarWidget, self).__init__(parent) # Variables self.value = None # Widget self._icon = icon self._pixmap = icon.pixmap(QSize(16, 16)) if icon is not None else None self.label_icon = QLabel() if icon is not None else None self.label_value = QLabel() # Widget setup if icon is not None: self.label_icon.setPixmap(self._pixmap) self.text_font = QFont(get_font(option='font')) # See Issue #9044 self.text_font.setPointSize(self.font().pointSize()) self.text_font.setBold(True) self.label_value.setAlignment(Qt.AlignRight) self.label_value.setFont(self.text_font) if self.TIP: self.setToolTip(self.TIP) self.label_value.setToolTip(self.TIP) # Layout layout = QHBoxLayout() if icon is not None: layout.addWidget(self.label_icon) layout.addWidget(self.label_value) layout.addSpacing(20) # Layout setup layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) # Setup statusbar.addPermanentWidget(self)
def __init__(self, *args, **kwargs): super(LineEditSearch, self).__init__(*args, **kwargs) self._empty = True self._show_icons = False self.button_icon = ButtonSearch() self.button_icon.setDefault(True) self.button_icon.setFocusPolicy(Qt.NoFocus) layout = QHBoxLayout() layout.addWidget(self.button_icon, 0, Qt.AlignRight) layout.setSpacing(0) layout.addSpacing(2) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) # Signals self.textEdited.connect(self.update_box) self.button_icon.clicked.connect(self.clear_text) self.update_box(None) self.set_icon_size(16, 16) self.setTabOrder(self, self.button_icon)
def __init__(self, parent, msg_label, status_label, cmd_line): """Status bar widget base.""" super(StatusBarVimWidget, self).__init__(parent) width_msg = msg_label.width() width_status = status_label.width() width_cmd = cmd_line.width() spacing_post = 32 spacing = 5 width_total = width_msg + width_status + width_cmd layout = QHBoxLayout() layout.setSpacing(spacing) layout.addWidget(msg_label, int(width_msg / width_total * 100)) layout.addWidget(status_label, int(width_status / width_total * 100)) layout.addWidget(cmd_line, int(width_cmd / width_total * 100)) layout.addSpacing(spacing_post) layout.setContentsMargins(0, 0, 0, 0) width_total += 2 * spacing + spacing_post self.setLayout(layout) self.setFixedWidth(width_total)
def __init__(self, parent, adjacency): QWidget.__init__(self, parent) # self.main = parent # Spyder3 # Create main widget self.model = MxAnalyzerModel(adjacency=adjacency, root=None, parent=self) # from .modeltest import ModelTest # self.modeltest = ModelTest(self.model, self) self.tree = MxAnalyzerTree(self, self.model) self.shellwidget = None # Set by parent # Layout of the top area in the plugin widget layout_top = QHBoxLayout() layout_top.setContentsMargins(0, 0, 0, 0) # Add Object textbox layout_top.addSpacing(10) txt = _("Object") if sys.platform == 'darwin': obj_label = QLabel(" " + txt) else: obj_label = QLabel(txt) layout_top.addWidget(obj_label) if spyder.version_info < (4, ): font = parent.plugin.get_plugin_font() else: font = parent.plugin.get_font() self.objbox = MxPyExprLineEdit(self, font=font) layout_top.addWidget(self.objbox) layout_top.addSpacing(10) # Add Object textbox txt = _("Args") if sys.platform == 'darwin': arg_label = QLabel(" " + txt) else: arg_label = QLabel(txt) layout_top.addWidget(arg_label) self.argbox = MxPyExprLineEdit(self, font=font) layout_top.addWidget(self.argbox) layout_top.addSpacing(10) # Main layout of this widget layout = create_plugin_layout(layout_top, self.tree) self.setLayout(layout)
def __init__(self, parent): if PYQT5: SpyderPluginWidget.__init__(self, parent, main = parent) else: SpyderPluginWidget.__init__(self, parent) self.internal_shell = None # Initialize plugin self.initialize_plugin() self.no_doc_string = _("No further documentation available") self._last_console_cb = None self._last_editor_cb = None self.plain_text = PlainText(self) self.rich_text = RichText(self) color_scheme = self.get_color_scheme() self.set_plain_text_font(self.get_plugin_font(), color_scheme) self.plain_text.editor.toggle_wrap_mode(self.get_option('wrap')) # Add entries to read-only editor context-menu self.wrap_action = create_action(self, _("Wrap lines"), toggled=self.toggle_wrap_mode) self.wrap_action.setChecked(self.get_option('wrap')) self.plain_text.editor.readonly_menu.addSeparator() add_actions(self.plain_text.editor.readonly_menu, (self.wrap_action,)) self.set_rich_text_font(self.get_plugin_font('rich_text')) self.shell = None self.external_console = None # locked = disable link with Console self.locked = False self._last_texts = [None, None] self._last_editor_doc = None # Object name layout_edit = QHBoxLayout() layout_edit.setContentsMargins(0, 0, 0, 0) txt = _("Source") if sys.platform == 'darwin': source_label = QLabel(" " + txt) else: source_label = QLabel(txt) layout_edit.addWidget(source_label) self.source_combo = QComboBox(self) self.source_combo.addItems([_("Console"), _("Editor")]) self.source_combo.currentIndexChanged.connect(self.source_changed) if (not programs.is_module_installed('rope') and not programs.is_module_installed('jedi', '>=0.8.1')): self.source_combo.hide() source_label.hide() layout_edit.addWidget(self.source_combo) layout_edit.addSpacing(10) layout_edit.addWidget(QLabel(_("Object"))) self.combo = ObjectComboBox(self) layout_edit.addWidget(self.combo) self.object_edit = QLineEdit(self) self.object_edit.setReadOnly(True) layout_edit.addWidget(self.object_edit) self.combo.setMaxCount(self.get_option('max_history_entries')) self.combo.addItems( self.load_history() ) self.combo.setItemText(0, '') self.combo.valid.connect(lambda valid: self.force_refresh()) # Plain text docstring option self.docstring = True self.rich_help = self.get_option('rich_mode', True) self.plain_text_action = create_action(self, _("Plain Text"), toggled=self.toggle_plain_text) # Source code option self.show_source_action = create_action(self, _("Show Source"), toggled=self.toggle_show_source) # Rich text option self.rich_text_action = create_action(self, _("Rich Text"), toggled=self.toggle_rich_text) # Add the help actions to an exclusive QActionGroup help_actions = QActionGroup(self) help_actions.setExclusive(True) help_actions.addAction(self.plain_text_action) help_actions.addAction(self.rich_text_action) # Automatic import option self.auto_import_action = create_action(self, _("Automatic import"), toggled=self.toggle_auto_import) auto_import_state = self.get_option('automatic_import') self.auto_import_action.setChecked(auto_import_state) # Lock checkbox self.locked_button = create_toolbutton(self, triggered=self.toggle_locked) layout_edit.addWidget(self.locked_button) self._update_lock_icon() # Option menu options_button = create_toolbutton(self, text=_('Options'), icon=ima.icon('tooloptions')) options_button.setPopupMode(QToolButton.InstantPopup) menu = QMenu(self) add_actions(menu, [self.rich_text_action, self.plain_text_action, self.show_source_action, None, self.auto_import_action]) options_button.setMenu(menu) layout_edit.addWidget(options_button) if self.rich_help: self.switch_to_rich_text() else: self.switch_to_plain_text() self.plain_text_action.setChecked(not self.rich_help) self.rich_text_action.setChecked(self.rich_help) self.source_changed() # Main layout layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addLayout(layout_edit) layout.addWidget(self.plain_text) layout.addWidget(self.rich_text) self.setLayout(layout) # Add worker thread for handling rich text rendering self._sphinx_thread = SphinxThread( html_text_no_doc=warning(self.no_doc_string)) self._sphinx_thread.html_ready.connect( self._on_sphinx_thread_html_ready) self._sphinx_thread.error_msg.connect(self._on_sphinx_thread_error_msg) # Handle internal and external links view = self.rich_text.webview if not WEBENGINE: view.page().setLinkDelegationPolicy(QWebEnginePage.DelegateAllLinks) view.linkClicked.connect(self.handle_link_clicks) self._starting_up = True
def __init__(self, settings: PartSettings): super().__init__() self._settings = settings self.export_btn = QPushButton("Export profile") self.export_btn.clicked.connect(self.export_profile) self.import_btn = QPushButton("Import profile") self.import_btn.clicked.connect(self.import_profiles) self.export_pipeline_btn = QPushButton("Export pipeline") self.export_pipeline_btn.clicked.connect(self.export_pipeline) self.import_pipeline_btn = QPushButton("Import pipeline") self.import_pipeline_btn.clicked.connect(self.import_pipeline) self.delete_btn = QPushButton("Delete profile") self.delete_btn.setDisabled(True) self.delete_btn.clicked.connect(self.delete_profile) self.multiple_files_chk = QCheckBox("Show multiple files panel") self._update_measurement_chk() self.multiple_files_chk.stateChanged.connect( self.multiple_files_visibility) self.rename_btn = QPushButton("Rename profile") self.rename_btn.clicked.connect(self.rename_profile) self.rename_btn.setDisabled(True) self.voxel_size_label = QLabel() self.info_label = QPlainTextEdit() self.info_label.setReadOnly(True) self.profile_list = SearchableListWidget() self.profile_list.currentTextChanged.connect(self.profile_chosen) self.pipeline_list = SearchableListWidget() self.pipeline_list.currentTextChanged.connect(self.profile_chosen) self.spacing = [QDoubleSpinBox() for _ in range(3)] self.lock_spacing = LockCheckBox() self.lock_spacing.stateChanged.connect(self.spacing[1].setDisabled) self.lock_spacing.stateChanged.connect(self.synchronize_spacing) # noinspection PyUnresolvedReferences self.spacing[2].valueChanged.connect(self.synchronize_spacing) self._settings.roi_profiles_changed.connect(self.update_profile_list) self._settings.roi_pipelines_changed.connect(self.update_profile_list) self._settings.connect_("multiple_files_widget", self._update_measurement_chk) units_value = self._settings.get("units_value", Units.nm) for el in self.spacing: el.setAlignment(Qt.AlignRight) el.setButtonSymbols(QAbstractSpinBox.NoButtons) el.setRange(0, 1000000) # noinspection PyUnresolvedReferences el.valueChanged.connect(self.image_spacing_change) self.units = QEnumComboBox(enum_class=Units) self.units.setCurrentEnum(units_value) # noinspection PyUnresolvedReferences self.units.currentIndexChanged.connect(self.update_spacing) spacing_layout = QHBoxLayout() spacing_layout.addWidget(self.lock_spacing) for txt, el in zip(["x", "y", "z"], self.spacing[::-1]): spacing_layout.addWidget(QLabel(txt + ":")) spacing_layout.addWidget(el) spacing_layout.addWidget(self.units) spacing_layout.addStretch(1) voxel_size_layout = QHBoxLayout() voxel_size_layout.addWidget(self.voxel_size_label) voxel_size_layout.addSpacing(30) profile_layout = QGridLayout() profile_layout.setSpacing(0) profile_layout.addWidget(QLabel("Profiles:"), 0, 0) profile_layout.addWidget(self.profile_list, 1, 0) profile_layout.addWidget(QLabel("Pipelines:"), 2, 0) profile_layout.addWidget(self.pipeline_list, 3, 0, 4, 1) profile_layout.addWidget(self.info_label, 1, 1, 3, 2) profile_layout.addWidget(self.export_btn, 4, 1) profile_layout.addWidget(self.import_btn, 4, 2) profile_layout.addWidget(self.export_pipeline_btn, 5, 1) profile_layout.addWidget(self.import_pipeline_btn, 5, 2) profile_layout.addWidget(self.delete_btn, 6, 1) profile_layout.addWidget(self.rename_btn, 6, 2) layout = QVBoxLayout() layout.addLayout(spacing_layout) layout.addLayout(voxel_size_layout) layout.addWidget(self.multiple_files_chk) layout.addLayout(profile_layout, 1) self.setLayout(layout) self.update_profile_list()
def setup_ui(self): self.resize(1080, 640) vlay_1 = QVBoxLayout(self) self.h_splitter = QSplitter(self) vlay_1.addWidget(self.h_splitter) self.h_splitter.setOrientation(Qt.Horizontal) self.v_splitter = QSplitter(self.h_splitter) self.v_splitter.setOrientation(Qt.Vertical) self.v_splitter.setMinimumWidth(500) installed = QWidget(self.v_splitter) lay = QVBoxLayout(installed) lay.setContentsMargins(0, 2, 0, 2) self.installed_label = QLabel(trans._("Installed Plugins")) self.packages_filter = QLineEdit() self.packages_filter.setPlaceholderText(trans._("filter...")) self.packages_filter.setMaximumWidth(350) self.packages_filter.setClearButtonEnabled(True) mid_layout = QVBoxLayout() mid_layout.addWidget(self.packages_filter) mid_layout.addWidget(self.installed_label) lay.addLayout(mid_layout) self.installed_list = QPluginList(installed, self.installer) self.packages_filter.textChanged.connect(self.installed_list.filter) lay.addWidget(self.installed_list) uninstalled = QWidget(self.v_splitter) lay = QVBoxLayout(uninstalled) lay.setContentsMargins(0, 2, 0, 2) self.avail_label = QLabel(trans._("Available Plugins")) mid_layout = QHBoxLayout() mid_layout.addWidget(self.avail_label) mid_layout.addStretch() lay.addLayout(mid_layout) self.available_list = QPluginList(uninstalled, self.installer) self.packages_filter.textChanged.connect(self.available_list.filter) lay.addWidget(self.available_list) self.stdout_text = QTextEdit(self.v_splitter) self.stdout_text.setReadOnly(True) self.stdout_text.setObjectName("pip_install_status") self.stdout_text.hide() buttonBox = QHBoxLayout() self.working_indicator = QLabel(trans._("loading ..."), self) sp = self.working_indicator.sizePolicy() sp.setRetainSizeWhenHidden(True) self.working_indicator.setSizePolicy(sp) self.process_error_indicator = QLabel(self) self.process_error_indicator.setObjectName("error_label") self.process_error_indicator.hide() load_gif = str(Path(napari.resources.__file__).parent / "loading.gif") mov = QMovie(load_gif) mov.setScaledSize(QSize(18, 18)) self.working_indicator.setMovie(mov) mov.start() visibility_direct_entry = not running_as_constructor_app() self.direct_entry_edit = QLineEdit(self) self.direct_entry_edit.installEventFilter(self) self.direct_entry_edit.setPlaceholderText( trans._('install by name/url, or drop file...')) self.direct_entry_edit.setVisible(visibility_direct_entry) self.direct_entry_btn = QPushButton(trans._("Install"), self) self.direct_entry_btn.setVisible(visibility_direct_entry) self.direct_entry_btn.clicked.connect(self._install_packages) self.show_status_btn = QPushButton(trans._("Show Status"), self) self.show_status_btn.setFixedWidth(100) self.cancel_all_btn = QPushButton(trans._("cancel all actions"), self) self.cancel_all_btn.setObjectName("remove_button") self.cancel_all_btn.setVisible(False) self.cancel_all_btn.clicked.connect(lambda: self.installer.cancel()) self.close_btn = QPushButton(trans._("Close"), self) self.close_btn.clicked.connect(self.accept) self.close_btn.setObjectName("close_button") buttonBox.addWidget(self.show_status_btn) buttonBox.addWidget(self.working_indicator) buttonBox.addWidget(self.direct_entry_edit) buttonBox.addWidget(self.direct_entry_btn) if not visibility_direct_entry: buttonBox.addStretch() buttonBox.addWidget(self.process_error_indicator) buttonBox.addSpacing(20) buttonBox.addWidget(self.cancel_all_btn) buttonBox.addSpacing(20) buttonBox.addWidget(self.close_btn) buttonBox.setContentsMargins(0, 0, 4, 0) vlay_1.addLayout(buttonBox) self.show_status_btn.setCheckable(True) self.show_status_btn.setChecked(False) self.show_status_btn.toggled.connect(self._toggle_status) self.v_splitter.setStretchFactor(1, 2) self.h_splitter.setStretchFactor(0, 2) self.packages_filter.setFocus()
def __init__(self, parent=None, css_path=CSS_PATH): SpyderPluginWidget.__init__(self, parent) self.internal_shell = None self.console = None self.css_path = css_path self.no_doc_string = _("No documentation available") self._last_console_cb = None self._last_editor_cb = None self.plain_text = PlainText(self) self.rich_text = RichText(self) color_scheme = self.get_color_scheme() self.set_plain_text_font(self.get_font(), color_scheme) self.plain_text.editor.toggle_wrap_mode(self.get_option('wrap')) # Add entries to read-only editor context-menu self.wrap_action = create_action(self, _("Wrap lines"), toggled=self.toggle_wrap_mode) self.wrap_action.setChecked(self.get_option('wrap')) self.plain_text.editor.readonly_menu.addSeparator() add_actions(self.plain_text.editor.readonly_menu, (self.wrap_action,)) self.set_rich_text_font(self.get_font(rich_text=True)) self.shell = None # locked = disable link with Console self.locked = False self._last_texts = [None, None] self._last_editor_doc = None # Object name layout_edit = QHBoxLayout() layout_edit.setContentsMargins(0, 0, 0, 0) txt = _("Source") if sys.platform == 'darwin': source_label = QLabel(" " + txt) else: source_label = QLabel(txt) layout_edit.addWidget(source_label) self.source_combo = QComboBox(self) self.source_combo.addItems([_("Console"), _("Editor")]) self.source_combo.currentIndexChanged.connect(self.source_changed) if (not programs.is_module_installed('rope') and not programs.is_module_installed('jedi', '>=0.11.0')): self.source_combo.hide() source_label.hide() layout_edit.addWidget(self.source_combo) layout_edit.addSpacing(10) layout_edit.addWidget(QLabel(_("Object"))) self.combo = ObjectComboBox(self) layout_edit.addWidget(self.combo) self.object_edit = QLineEdit(self) self.object_edit.setReadOnly(True) layout_edit.addWidget(self.object_edit) self.combo.setMaxCount(self.get_option('max_history_entries')) self.combo.addItems( self.load_history() ) self.combo.setItemText(0, '') self.combo.valid.connect(self.force_refresh) # Plain text docstring option self.docstring = True self.rich_help = self.get_option('rich_mode', True) self.plain_text_action = create_action(self, _("Plain Text"), toggled=self.toggle_plain_text) # Source code option self.show_source_action = create_action(self, _("Show Source"), toggled=self.toggle_show_source) # Rich text option self.rich_text_action = create_action(self, _("Rich Text"), toggled=self.toggle_rich_text) # Add the help actions to an exclusive QActionGroup help_actions = QActionGroup(self) help_actions.setExclusive(True) help_actions.addAction(self.plain_text_action) help_actions.addAction(self.rich_text_action) # Automatic import option self.auto_import_action = create_action(self, _("Automatic import"), toggled=self.toggle_auto_import) auto_import_state = self.get_option('automatic_import') self.auto_import_action.setChecked(auto_import_state) # Lock checkbox self.locked_button = create_toolbutton(self, triggered=self.toggle_locked) layout_edit.addWidget(self.locked_button) self._update_lock_icon() # Option menu layout_edit.addWidget(self.options_button) if self.rich_help: self.switch_to_rich_text() else: self.switch_to_plain_text() self.plain_text_action.setChecked(not self.rich_help) self.rich_text_action.setChecked(self.rich_help) self.source_changed() # Main layout layout = create_plugin_layout(layout_edit) # we have two main widgets, but only one of them is shown at a time layout.addWidget(self.plain_text) layout.addWidget(self.rich_text) self.setLayout(layout) # Add worker thread for handling rich text rendering self._sphinx_thread = SphinxThread( html_text_no_doc=warning(self.no_doc_string, css_path=self.css_path), css_path=self.css_path) self._sphinx_thread.html_ready.connect( self._on_sphinx_thread_html_ready) self._sphinx_thread.error_msg.connect(self._on_sphinx_thread_error_msg) # Handle internal and external links view = self.rich_text.webview if not WEBENGINE: view.page().setLinkDelegationPolicy(QWebEnginePage.DelegateAllLinks) view.linkClicked.connect(self.handle_link_clicks) self._starting_up = True
class ObjectExplorer(BaseDialog, SpyderConfigurationAccessor): """Object explorer main widget window.""" CONF_SECTION = 'variable_explorer' def __init__(self, obj, name='', expanded=False, resize_to_contents=True, parent=None, attribute_columns=DEFAULT_ATTR_COLS, attribute_details=DEFAULT_ATTR_DETAILS, readonly=None, reset=False): """ Constructor :param name: name of the object as it will appear in the root node :param expanded: show the first visible root element expanded :param resize_to_contents: resize columns to contents ignoring width of the attributes :param obj: any Python object or variable :param attribute_columns: list of AttributeColumn objects that define which columns are present in the table and their defaults :param attribute_details: list of AttributeDetails objects that define which attributes can be selected in the details pane. :param reset: If true the persistent settings, such as column widths, are reset. """ QDialog.__init__(self, parent=parent) self.setAttribute(Qt.WA_DeleteOnClose) # Options show_callable_attributes = self.get_conf('show_callable_attributes') show_special_attributes = self.get_conf('show_special_attributes') # Model self._attr_cols = attribute_columns self._attr_details = attribute_details self.readonly = readonly self.btn_save_and_close = None self.btn_close = None self._tree_model = TreeModel(obj, obj_name=name, attr_cols=self._attr_cols) self._proxy_tree_model = TreeProxyModel( show_callable_attributes=show_callable_attributes, show_special_attributes=show_special_attributes ) self._proxy_tree_model.setSourceModel(self._tree_model) # self._proxy_tree_model.setSortRole(RegistryTableModel.SORT_ROLE) self._proxy_tree_model.setDynamicSortFilter(True) # self._proxy_tree_model.setSortCaseSensitivity(Qt.CaseInsensitive) # Tree widget self.obj_tree = ToggleColumnTreeView() self.obj_tree.setAlternatingRowColors(True) self.obj_tree.setModel(self._proxy_tree_model) self.obj_tree.setSelectionBehavior(QAbstractItemView.SelectRows) self.obj_tree.setUniformRowHeights(True) self.obj_tree.add_header_context_menu() # Views self._setup_actions() self._setup_menu(show_callable_attributes=show_callable_attributes, show_special_attributes=show_special_attributes) self._setup_views() if name: name = "{} -".format(name) self.setWindowTitle("{} {}".format(name, EDITOR_NAME)) self.setWindowFlags(Qt.Window) self._resize_to_contents = resize_to_contents self._readViewSettings(reset=reset) # Update views with model self.toggle_show_special_attribute_action.setChecked( show_special_attributes) self.toggle_show_callable_action.setChecked(show_callable_attributes) # Select first row so that a hidden root node will not be selected. first_row_index = self._proxy_tree_model.firstItemIndex() self.obj_tree.setCurrentIndex(first_row_index) if self._tree_model.inspectedNodeIsVisible or expanded: self.obj_tree.expand(first_row_index) def get_value(self): """Get editor current object state.""" return self._tree_model.inspectedItem.obj def _make_show_column_function(self, column_idx): """Creates a function that shows or hides a column.""" show_column = lambda checked: self.obj_tree.setColumnHidden( column_idx, not checked) return show_column def _setup_actions(self): """Creates the main window actions.""" # Show/hide callable objects self.toggle_show_callable_action = QAction( _("Show callable attributes"), self, checkable=True, shortcut=QKeySequence("Alt+C"), statusTip=_("Shows/hides attributes that are callable " "(functions, methods, etc)") ) self.toggle_show_callable_action.toggled.connect( self._proxy_tree_model.setShowCallables) self.toggle_show_callable_action.toggled.connect( self.obj_tree.resize_columns_to_contents) # Show/hide special attributes self.toggle_show_special_attribute_action = QAction( _("Show __special__ attributes"), self, checkable=True, shortcut=QKeySequence("Alt+S"), statusTip=_("Shows or hides __special__ attributes") ) self.toggle_show_special_attribute_action.toggled.connect( self._proxy_tree_model.setShowSpecialAttributes) self.toggle_show_special_attribute_action.toggled.connect( self.obj_tree.resize_columns_to_contents) def _setup_menu(self, show_callable_attributes=False, show_special_attributes=False): """Sets up the main menu.""" self.tools_layout = QHBoxLayout() callable_attributes = create_toolbutton( self, text=_("Show callable attributes"), icon=ima.icon("class"), toggled=self._toggle_show_callable_attributes_action) callable_attributes.setCheckable(True) callable_attributes.setChecked(show_callable_attributes) callable_attributes.setStyleSheet(str(PANES_TOOLBAR_STYLESHEET)) self.tools_layout.addWidget(callable_attributes) special_attributes = create_toolbutton( self, text=_("Show __special__ attributes"), icon=ima.icon("private2"), toggled=self._toggle_show_special_attributes_action) special_attributes.setCheckable(True) special_attributes.setChecked(show_special_attributes) special_attributes.setStyleSheet(str(PANES_TOOLBAR_STYLESHEET)) self.tools_layout.addSpacing(5) self.tools_layout.addWidget(special_attributes) self.tools_layout.addStretch() self.options_button = create_toolbutton( self, text=_('Options'), icon=ima.icon('tooloptions')) self.options_button.setStyleSheet(str(PANES_TOOLBAR_STYLESHEET)) self.options_button.setPopupMode(QToolButton.InstantPopup) self.show_cols_submenu = QMenu(self) self.show_cols_submenu.setObjectName('checkbox-padding') self.options_button.setMenu(self.show_cols_submenu) self.show_cols_submenu.setStyleSheet(str(PANES_TOOLBAR_STYLESHEET)) self.tools_layout.addWidget(self.options_button) @Slot() def _toggle_show_callable_attributes_action(self): """Toggle show callable atributes action.""" action_checked = not self.toggle_show_callable_action.isChecked() self.toggle_show_callable_action.setChecked(action_checked) self.set_conf('show_callable_attributes', action_checked) @Slot() def _toggle_show_special_attributes_action(self): """Toggle show special attributes action.""" action_checked = ( not self.toggle_show_special_attribute_action.isChecked()) self.toggle_show_special_attribute_action.setChecked(action_checked) self.set_conf('show_special_attributes', action_checked) def _setup_views(self): """Creates the UI widgets.""" layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addLayout(self.tools_layout) self.central_splitter = QSplitter(self, orientation=Qt.Vertical) layout.addWidget(self.central_splitter) self.setLayout(layout) # Stretch last column? # It doesn't play nice when columns are hidden and then shown again. obj_tree_header = self.obj_tree.header() obj_tree_header.setSectionsMovable(True) obj_tree_header.setStretchLastSection(False) add_actions(self.show_cols_submenu, self.obj_tree.toggle_column_actions_group.actions()) self.central_splitter.addWidget(self.obj_tree) # Bottom pane bottom_pane_widget = QWidget() bottom_layout = QHBoxLayout() bottom_layout.setSpacing(0) bottom_layout.setContentsMargins(5, 5, 5, 5) # left top right bottom bottom_pane_widget.setLayout(bottom_layout) self.central_splitter.addWidget(bottom_pane_widget) group_box = QGroupBox(_("Details")) bottom_layout.addWidget(group_box) v_group_layout = QVBoxLayout() h_group_layout = QHBoxLayout() h_group_layout.setContentsMargins(2, 2, 2, 2) # left top right bottom group_box.setLayout(v_group_layout) v_group_layout.addLayout(h_group_layout) # Radio buttons radio_widget = QWidget() radio_layout = QVBoxLayout() radio_layout.setContentsMargins(0, 0, 0, 0) # left top right bottom radio_widget.setLayout(radio_layout) self.button_group = QButtonGroup(self) for button_id, attr_detail in enumerate(self._attr_details): radio_button = QRadioButton(attr_detail.name) radio_layout.addWidget(radio_button) self.button_group.addButton(radio_button, button_id) self.button_group.buttonClicked[int].connect( self._change_details_field) self.button_group.button(0).setChecked(True) radio_layout.addStretch(1) h_group_layout.addWidget(radio_widget) # Editor widget self.editor = SimpleCodeEditor(self) self.editor.setReadOnly(True) h_group_layout.addWidget(self.editor) # Save and close buttons btn_layout = QHBoxLayout() btn_layout.addStretch() if not self.readonly: self.btn_save_and_close = QPushButton(_('Save and Close')) self.btn_save_and_close.setDisabled(True) self.btn_save_and_close.clicked.connect(self.accept) btn_layout.addWidget(self.btn_save_and_close) self.btn_close = QPushButton(_('Close')) self.btn_close.setAutoDefault(True) self.btn_close.setDefault(True) self.btn_close.clicked.connect(self.reject) btn_layout.addWidget(self.btn_close) v_group_layout.addLayout(btn_layout) # Splitter parameters self.central_splitter.setCollapsible(0, False) self.central_splitter.setCollapsible(1, True) self.central_splitter.setSizes([500, 320]) # Connect signals # Keep a temporary reference of the selection_model to prevent # segfault in PySide. # See http://permalink.gmane.org/gmane.comp.lib.qt.pyside.devel/222 selection_model = self.obj_tree.selectionModel() selection_model.currentChanged.connect(self._update_details) # Check if the values of the model have been changed self._proxy_tree_model.sig_setting_data.connect( self.save_and_close_enable) self._proxy_tree_model.sig_update_details.connect( self._update_details_for_item) # End of setup_methods def _readViewSettings(self, reset=False): """ Reads the persistent program settings. :param reset: If True, the program resets to its default settings. """ pos = QPoint(20, 20) window_size = QSize(825, 650) details_button_idx = 0 header = self.obj_tree.header() header_restored = False if reset: logger.debug("Resetting persistent view settings") else: pos = pos window_size = window_size details_button_idx = details_button_idx # splitter_state = settings.value("central_splitter/state") splitter_state = None if splitter_state: self.central_splitter.restoreState(splitter_state) # header_restored = self.obj_tree.read_view_settings( # 'table/header_state', # settings, reset) header_restored = False if not header_restored: column_sizes = [col.width for col in self._attr_cols] column_visible = [col.col_visible for col in self._attr_cols] for idx, size in enumerate(column_sizes): if not self._resize_to_contents and size > 0: # Just in case header.resizeSection(idx, size) else: header.resizeSections(QHeaderView.ResizeToContents) break for idx, visible in enumerate(column_visible): elem = self.obj_tree.toggle_column_actions_group.actions()[idx] elem.setChecked(visible) self.resize(window_size) button = self.button_group.button(details_button_idx) if button is not None: button.setChecked(True) @Slot() def save_and_close_enable(self): """Handle the data change event to enable the save and close button.""" if self.btn_save_and_close: self.btn_save_and_close.setEnabled(True) self.btn_save_and_close.setAutoDefault(True) self.btn_save_and_close.setDefault(True) @Slot(QModelIndex, QModelIndex) def _update_details(self, current_index, _previous_index): """Shows the object details in the editor given an index.""" tree_item = self._proxy_tree_model.treeItem(current_index) self._update_details_for_item(tree_item) def _change_details_field(self, _button_id=None): """Changes the field that is displayed in the details pane.""" # logger.debug("_change_details_field: {}".format(_button_id)) current_index = self.obj_tree.selectionModel().currentIndex() tree_item = self._proxy_tree_model.treeItem(current_index) self._update_details_for_item(tree_item) @Slot(TreeItem) def _update_details_for_item(self, tree_item): """Shows the object details in the editor given an tree_item.""" try: # obj = tree_item.obj button_id = self.button_group.checkedId() assert button_id >= 0, ("No radio button selected. " "Please report this bug.") attr_details = self._attr_details[button_id] data = attr_details.data_fn(tree_item) self.editor.setPlainText(data) self.editor.setWordWrapMode(attr_details.line_wrap) self.editor.setup_editor( font=get_font(font_size_delta=DEFAULT_SMALL_DELTA), show_blanks=False, color_scheme=CONF.get('appearance', 'selected'), scroll_past_end=False, ) self.editor.set_text(data) if attr_details.name == 'Source code': self.editor.set_language('Python') else: self.editor.set_language('Rst') except Exception as ex: self.editor.setStyleSheet("color: red;") stack_trace = traceback.format_exc() self.editor.setPlainText("{}\n\n{}".format(ex, stack_trace)) self.editor.setWordWrapMode( QTextOption.WrapAtWordBoundaryOrAnywhere) @classmethod def create_explorer(cls, *args, **kwargs): """ Creates and shows and ObjectExplorer window. The *args and **kwargs will be passed to the ObjectExplorer constructor A (class attribute) reference to the browser window is kept to prevent it from being garbage-collected. """ object_explorer = cls(*args, **kwargs) object_explorer.exec_() return object_explorer
def __init__(self, splash=None): super(MainWindow, self).__init__() self.tracker = None self.splash = splash # Anaconda API self.api = AnacondaAPI() self.busy = False self.logged = False self.username = '' self._login_text = 'Sign in to Anaconda Cloud' self.first_run = CONF.get('main', 'first_run') self.application_update_version = None # Widgets self.frame_header = FrameHeader(self) self.frame_body = FrameBody(self) self.label_logo = LabelHeaderLogo('ANACONDA NAVIGATOR') self.button_logged_text = ButtonLabelLogin('') self.button_logged_username = ButtonLinkLogin('') self.label_update_available = LabelHeaderUpdate('Update available!') self.button_update_available = ButtonHeaderUpdate('Update') self.button_login = ButtonLogin(self._login_text) self.central_widget = QWidget() self.statusbar = self.statusBar() self.progressbar = QProgressBar() self.stack = TabWidgetBody(self) self.home_tab = HomeTab(parent=self) self.environments_tab = EnvironmentsTab(parent=self) self.learning_tab = CommunityTab( parent=self, tags=['webinar', 'documentation', 'video', 'training'], content_urls=[self.VIDEOS_URL, self.WEBINARS_URL]) self.community_tab = CommunityTab(parent=self, tags=['event', 'forum', 'social'], content_urls=[self.EVENTS_URL]) # self.projects_tab = ProjectsTab(parent=self) # Note: Icons are set in CSS self.stack.addTab(self.home_tab, text='Home') self.stack.addTab(self.environments_tab, text='Environments') self.stack.addTab(self.learning_tab, text='Learning') self.stack.addTab(self.community_tab, text='Community') # self.stack.addTab(self.projects_tab, 'Projects') # Widget setup self.button_login.setDefault(True) self.label_logo.setPixmap(QPixmap(images.ANACONDA_NAVIGATOR_LOGO)) self.setWindowTitle("Anaconda Navigator") self.statusbar.addPermanentWidget(self.progressbar) self.progressbar.setVisible(False) # Layout header_layout = QHBoxLayout() header_layout.addWidget(self.label_logo) header_layout.addSpacing(18) header_layout.addWidget(self.label_update_available, 0, Qt.AlignCenter) header_layout.addWidget(self.button_update_available, 0, Qt.AlignCenter) header_layout.addStretch() header_layout.addWidget(self.button_logged_text, 0, Qt.AlignTrailing) header_layout.addWidget(self.button_logged_username, 0, Qt.AlignTrailing) header_layout.addWidget(self.button_login, 0, Qt.AlignTrailing) header_layout.setContentsMargins(0, 0, 0, 0) self.frame_header.setLayout(header_layout) body_layout = QHBoxLayout() body_layout.addWidget(self.stack) body_layout.setContentsMargins(0, 0, 0, 0) self.frame_body.setLayout(body_layout) main_layout = QVBoxLayout() main_layout.addWidget(self.frame_header) main_layout.addWidget(self.frame_body) main_layout.setContentsMargins(0, 0, 0, 0) main_layout.setSpacing(0) self.central_widget.setLayout(main_layout) self.setContentsMargins(0, 0, 0, 0) self.setCentralWidget(self.central_widget) # Signals self.button_login.clicked.connect(self.login) self.button_logged_username.clicked.connect(self.open_login_page) self.button_update_available.clicked.connect(self.update_application) self.stack.currentChanged.connect(self._track_tab) # This needs to be reworked! # self.projects_tab.sig_apps_updated.connect( # self.home_tab.set_applications) # self.projects_tab.sig_apps_changed.connect( # self.home_tab.set_applications) # self.projects_tab.sig_project_updated.connect( # self.home_tab.set_applications) # self.projects_tab.sig_status_updated.connect(self.update_status_bar) # Setup self.api.set_data_directory(CHANNELS_PATH) self.update_style_sheet()
def setup_ui(self): self.resize(1080, 640) vlay_1 = QVBoxLayout(self) self.h_splitter = QSplitter(self) vlay_1.addWidget(self.h_splitter) self.h_splitter.setOrientation(Qt.Horizontal) self.v_splitter = QSplitter(self.h_splitter) self.v_splitter.setOrientation(Qt.Vertical) self.v_splitter.setMinimumWidth(500) self.plugin_sorter = QtPluginSorter(parent=self.h_splitter) self.plugin_sorter.layout().setContentsMargins(2, 0, 0, 0) self.plugin_sorter.hide() installed = QWidget(self.v_splitter) lay = QVBoxLayout(installed) lay.setContentsMargins(0, 2, 0, 2) lay.addWidget(QLabel(trans._("Installed Plugins"))) self.installed_list = QPluginList(installed, self.installer) lay.addWidget(self.installed_list) uninstalled = QWidget(self.v_splitter) lay = QVBoxLayout(uninstalled) lay.setContentsMargins(0, 2, 0, 2) self.avail_label = QLabel(trans._("Available Plugins")) lay.addWidget(self.avail_label) self.available_list = QPluginList(uninstalled, self.installer) lay.addWidget(self.available_list) self.stdout_text = QTextEdit(self.v_splitter) self.stdout_text.setReadOnly(True) self.stdout_text.setObjectName("pip_install_status") self.stdout_text.hide() buttonBox = QHBoxLayout() self.working_indicator = QLabel(trans._("loading ..."), self) sp = self.working_indicator.sizePolicy() sp.setRetainSizeWhenHidden(True) self.working_indicator.setSizePolicy(sp) self.process_error_indicator = QLabel(self) self.process_error_indicator.setObjectName("error_label") self.process_error_indicator.hide() load_gif = str(Path(napari.resources.__file__).parent / "loading.gif") mov = QMovie(load_gif) mov.setScaledSize(QSize(18, 18)) self.working_indicator.setMovie(mov) mov.start() self.direct_entry_edit = QLineEdit(self) self.direct_entry_edit.installEventFilter(self) self.direct_entry_edit.setPlaceholderText( trans._('install by name/url, or drop file...')) self.direct_entry_btn = QPushButton(trans._("Install"), self) self.direct_entry_btn.clicked.connect(self._install_packages) self.show_status_btn = QPushButton(trans._("Show Status"), self) self.show_status_btn.setFixedWidth(100) self.show_sorter_btn = QPushButton(trans._("<< Show Sorter"), self) self.close_btn = QPushButton(trans._("Close"), self) self.close_btn.clicked.connect(self.reject) buttonBox.addWidget(self.show_status_btn) buttonBox.addWidget(self.working_indicator) buttonBox.addWidget(self.direct_entry_edit) buttonBox.addWidget(self.direct_entry_btn) buttonBox.addWidget(self.process_error_indicator) buttonBox.addSpacing(60) buttonBox.addWidget(self.show_sorter_btn) buttonBox.addWidget(self.close_btn) buttonBox.setContentsMargins(0, 0, 4, 0) vlay_1.addLayout(buttonBox) self.show_status_btn.setCheckable(True) self.show_status_btn.setChecked(False) self.show_status_btn.toggled.connect(self._toggle_status) self.show_sorter_btn.setCheckable(True) self.show_sorter_btn.setChecked(False) self.show_sorter_btn.toggled.connect(self._toggle_sorter) self.v_splitter.setStretchFactor(1, 2) self.h_splitter.setStretchFactor(0, 2)