def __init__(self, func, name=None, annotations=None, hide_params=None, parent=None): # Function information self.func = func self.signature = inspect.signature(func) self.name = name or self.func.__name__ # Initialize parent super().__init__('{} Parameters'.format(clean_attr(self.name)), parent=parent) # Ignore certain parameters, args and kwargs by default self.hide_params = ['self', 'args', 'kwargs'] if hide_params: self.hide_params.extend(hide_params) # Create basic layout self._layout = QVBoxLayout() self._layout.setSpacing(2) self.setLayout(self._layout) # Create an empty list to fill later with parameter widgets self.param_controls = list() # Add our button to execute the function self.execute_button = QPushButton() self.execute_button.setText(clean_attr(self.name)) self.execute_button.clicked.connect(self.execute) self._layout.addWidget(self.execute_button) # Add a panel for the optional parameters self.optional = TogglePanel("Optional Parameters") self.optional.contents = QWidget() self.optional.contents.setLayout(QVBoxLayout()) self.optional.contents.layout().setSpacing(2) self.optional.layout().addWidget(self.optional.contents) self.optional.show_contents(False) self._layout.addWidget(self.optional) self._layout.addItem(QSpacerItem(10, 5, vPolicy=QSizePolicy.Expanding)) # Create parameters from function signature annotations = annotations or dict() for param in [param for param in self.signature.parameters.values() if param.name not in self.hide_params]: logger.debug("Adding parameter %s ", param.name) # See if we received a manual annotation for this parameter if param.name in annotations: _type = annotations[param.name] logger.debug("Found manually specified type %r", _type.__name__) # Try and get the type from the function annotation elif param.annotation != inspect._empty: _type = param.annotation logger.debug("Found annotated type %r ", _type.__name__) # Try and get the type from the default value elif param.default != inspect._empty: _type = type(param.default) logger.debug("Gathered type %r from parameter default ", _type.__name__) # If we don't have a default value or an annotation, # we can not make a widget for this parameter. Since # this is a required variable (no default), the function # will not work without it. Raise an Exception else: raise TypeError("Parameter {} has an unspecified " "type".format(param.name)) # Add our parameter self.add_parameter(param.name, _type, default=param.default) # Hide optional parameter widget if there are no such parameters if not self.optional_params: self.optional.hide()
def __init__(self, plugin, id_, history_filename, config_options, additional_options, interpreter_versions, connection_file=None, hostname=None, menu_actions=None, slave=False, external_kernel=False, given_name=None, options_button=None, show_elapsed_time=False, reset_warning=True, ask_before_restart=True, css_path=None): super(ClientWidget, self).__init__(plugin) SaveHistoryMixin.__init__(self, history_filename) # --- Init attrs self.plugin = plugin self.id_ = id_ self.connection_file = connection_file self.hostname = hostname self.menu_actions = menu_actions self.slave = slave self.external_kernel = external_kernel self.given_name = given_name self.show_elapsed_time = show_elapsed_time self.reset_warning = reset_warning self.ask_before_restart = ask_before_restart # --- Other attrs self.options_button = options_button self.stop_button = None self.reset_button = None self.stop_icon = ima.icon('stop') self.history = [] self.allow_rename = True self.stderr_dir = None self.is_error_shown = False self.restart_thread = None if css_path is None: self.css_path = CSS_PATH else: self.css_path = css_path # --- Widgets self.shellwidget = ShellWidget(config=config_options, ipyclient=self, additional_options=additional_options, interpreter_versions=interpreter_versions, external_kernel=external_kernel, local_kernel=True) self.infowidget = plugin.infowidget self.blank_page = self._create_blank_page() self.loading_page = self._create_loading_page() # To keep a reference to the page to be displayed # in infowidget self.info_page = None self._before_prompt_is_ready() # Elapsed time self.time_label = None self.t0 = time.monotonic() self.timer = QTimer(self) self.show_time_action = create_action(self, _("Show elapsed time"), toggled=self.set_elapsed_time_visible) # --- Layout self.layout = QVBoxLayout() toolbar_buttons = self.get_toolbar_buttons() hlayout = QHBoxLayout() hlayout.addWidget(self.create_time_label()) hlayout.addStretch(0) for button in toolbar_buttons: hlayout.addWidget(button) self.layout.addLayout(hlayout) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.addWidget(self.shellwidget) self.layout.addWidget(self.infowidget) self.setLayout(self.layout) # --- Exit function self.exit_callback = lambda: plugin.close_client(client=self) # --- Dialog manager self.dialog_manager = DialogManager() # Show timer self.update_time_label_visibility()
def __init__(self, parent, max_entries=100, options_button=None, text_color=None): QWidget.__init__(self, parent) self.setWindowTitle("Profiler") self.output = None self.error_output = None self.text_color = text_color self._last_wdir = None self._last_args = None self._last_pythonpath = None self.filecombo = PythonModulesComboBox(self) self.start_button = create_toolbutton(self, icon=ima.icon('run'), text=_("Profile"), tip=_("Run profiler"), triggered=lambda: self.start(), text_beside_icon=True) self.stop_button = create_toolbutton(self, icon=ima.icon('stop'), text=_("Stop"), tip=_("Stop current profiling"), text_beside_icon=True) self.filecombo.valid.connect(self.start_button.setEnabled) #self.connect(self.filecombo, SIGNAL('valid(bool)'), self.show_data) # FIXME: The combobox emits this signal on almost any event # triggering show_data() too early, too often. browse_button = create_toolbutton(self, icon=ima.icon('fileopen'), tip=_('Select Python script'), triggered=self.select_file) self.datelabel = QLabel() self.log_button = create_toolbutton(self, icon=ima.icon('log'), text=_("Output"), text_beside_icon=True, tip=_("Show program's output"), triggered=self.show_log) self.datatree = ProfilerDataTree(self) self.collapse_button = create_toolbutton( self, icon=ima.icon('collapse'), triggered=lambda dD: self.datatree.change_view(-1), tip=_('Collapse one level up')) self.expand_button = create_toolbutton( self, icon=ima.icon('expand'), triggered=lambda dD: self.datatree.change_view(1), tip=_('Expand one level down')) self.save_button = create_toolbutton(self, text_beside_icon=True, text=_("Save data"), icon=ima.icon('filesave'), triggered=self.save_data, tip=_('Save profiling data')) self.load_button = create_toolbutton( self, text_beside_icon=True, text=_("Load data"), icon=ima.icon('fileimport'), triggered=self.compare, tip=_('Load profiling data for comparison')) self.clear_button = create_toolbutton(self, text_beside_icon=True, text=_("Clear comparison"), icon=ima.icon('editdelete'), triggered=self.clear) hlayout1 = QHBoxLayout() hlayout1.addWidget(self.filecombo) hlayout1.addWidget(browse_button) hlayout1.addWidget(self.start_button) hlayout1.addWidget(self.stop_button) if options_button: hlayout1.addWidget(options_button) hlayout2 = QHBoxLayout() hlayout2.addWidget(self.collapse_button) hlayout2.addWidget(self.expand_button) hlayout2.addStretch() hlayout2.addWidget(self.datelabel) hlayout2.addStretch() hlayout2.addWidget(self.log_button) hlayout2.addWidget(self.save_button) hlayout2.addWidget(self.load_button) hlayout2.addWidget(self.clear_button) layout = QVBoxLayout() layout.addLayout(hlayout1) layout.addLayout(hlayout2) layout.addWidget(self.datatree) self.setLayout(layout) self.process = None self.set_running_state(False) self.start_button.setEnabled(False) self.clear_button.setEnabled(False) if not is_profiler_installed(): # This should happen only on certain GNU/Linux distributions # or when this a home-made Python build because the Python # profilers are included in the Python standard library for widget in (self.datatree, self.filecombo, self.start_button, self.stop_button): widget.setDisabled(True) url = 'https://docs.python.org/3/library/profile.html' text = '%s <a href=%s>%s</a>' % (_('Please install'), url, _("the Python profiler modules")) self.datelabel.setText(text) else: pass # self.show_data()
def __init__( self, parent: QWidget = None, description: str = None, preview_text: str = None, value: int = None, min_value: int = 1, max_value: int = 50, unit: str = "px", ): super().__init__(parent) description = description or "" preview_text = preview_text or "" self._value = value if value else self.fontMetrics().height() self._min_value = min_value self._max_value = max_value # Widget self._lineedit = QLineEdit() self._description_label = QLabel(self) self._unit_label = QLabel(self) self._slider = QSlider(Qt.Horizontal, self) self._slider_min_label = QLabel(self) self._slider_max_label = QLabel(self) self._preview = QtFontSizePreview(self) self._preview_label = QLabel(self) self._validator = None # Widgets setup self._description_label.setText(description) self._description_label.setWordWrap(True) self._unit_label.setText(unit) self._lineedit.setAlignment(Qt.AlignRight) self._slider_min_label.setText(str(min_value)) self._slider_max_label.setText(str(max_value)) self._slider.setMinimum(min_value) self._slider.setMaximum(max_value) self._preview.setText(preview_text) self._preview_label.setText(trans._("preview")) self._preview_label.setAlignment(Qt.AlignHCenter) self.setFocusProxy(self._lineedit) # Layout left_bottom_layout = QHBoxLayout() left_bottom_layout.addWidget(self._lineedit) left_bottom_layout.addWidget(self._unit_label) left_bottom_layout.addWidget(self._slider_min_label) left_bottom_layout.addWidget(self._slider) left_bottom_layout.addWidget(self._slider_max_label) left_layout = QVBoxLayout() left_layout.addWidget(self._description_label) left_layout.addLayout(left_bottom_layout) right_layout = QVBoxLayout() right_layout.addWidget(self._preview) right_layout.addWidget(self._preview_label) layout = QHBoxLayout() layout.addLayout(left_layout, 2) layout.addLayout(right_layout, 1) self.setLayout(layout) # Signals self._slider.valueChanged.connect(self._update_value) self._lineedit.textChanged.connect(self._update_value) self._update_line_width() self._update_validator() self._update_value(self._value)
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.multiple_files_chk.setChecked( self._settings.get("multiple_files_widget", False)) 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) 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 = EnumComboBox(Units) self.units.set_value(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)
def __init__(self, parent, opacity, duration, easing_curve, tour=None, color_top=None, color_back=None, combobox_background=None): super(FadingTipBox, self).__init__(parent, opacity, duration, easing_curve) self.holder = self.anim # needed for qt to work self.parent = parent self.tour = tour self.frames = None self.offset_shadow = 0 self.fixed_width = 300 self.key_pressed = None self.setAttribute(Qt.WA_TranslucentBackground) self.setWindowFlags(Qt.Dialog | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) self.setModal(False) # Widgets def toolbutton(icon): bt = QToolButton() bt.setAutoRaise(True) bt.setIcon(icon) return bt self.button_close = toolbutton(ima.icon("tour.close")) self.button_home = toolbutton(ima.icon("tour.home")) self.button_previous = toolbutton(ima.icon("tour.previous")) self.button_end = toolbutton(ima.icon("tour.end")) self.button_next = toolbutton(ima.icon("tour.next")) self.button_run = QPushButton(_('Run code')) self.button_disable = None self.button_current = QToolButton() self.label_image = QLabel() self.label_title = QLabel() self.combo_title = QComboBox() self.label_current = QLabel() self.label_content = QLabel() self.label_content.setMinimumWidth(self.fixed_width) self.label_content.setMaximumWidth(self.fixed_width) self.label_current.setAlignment(Qt.AlignCenter) self.label_content.setWordWrap(True) self.widgets = [self.label_content, self.label_title, self.label_current, self.combo_title, self.button_close, self.button_run, self.button_next, self.button_previous, self.button_end, self.button_home, self.button_current] arrow = get_image_path('hide.png') self.color_top = color_top self.color_back = color_back self.combobox_background = combobox_background self.stylesheet = '''QComboBox {{ padding-left: 5px; background-color: {} border-width: 0px; border-radius: 0px; min-height:20px; max-height:20px; }} QComboBox::drop-down {{ subcontrol-origin: padding; subcontrol-position: top left; border-width: 0px; }} QComboBox::down-arrow {{ image: url({}); }} '''.format(self.combobox_background.name(), arrow) # Windows fix, slashes should be always in unix-style self.stylesheet = self.stylesheet.replace('\\', '/') self.setFocusPolicy(Qt.StrongFocus) for widget in self.widgets: widget.setFocusPolicy(Qt.NoFocus) widget.setStyleSheet(self.stylesheet) layout_top = QHBoxLayout() layout_top.addWidget(self.combo_title) layout_top.addStretch() layout_top.addWidget(self.button_close) layout_top.addSpacerItem(QSpacerItem(self.offset_shadow, self.offset_shadow)) layout_content = QHBoxLayout() layout_content.addWidget(self.label_content) layout_content.addWidget(self.label_image) layout_content.addSpacerItem(QSpacerItem(5, 5)) layout_run = QHBoxLayout() layout_run.addStretch() layout_run.addWidget(self.button_run) layout_run.addStretch() layout_run.addSpacerItem(QSpacerItem(self.offset_shadow, self.offset_shadow)) layout_navigation = QHBoxLayout() layout_navigation.addWidget(self.button_home) layout_navigation.addWidget(self.button_previous) layout_navigation.addStretch() layout_navigation.addWidget(self.label_current) layout_navigation.addStretch() layout_navigation.addWidget(self.button_next) layout_navigation.addWidget(self.button_end) layout_navigation.addSpacerItem(QSpacerItem(self.offset_shadow, self.offset_shadow)) layout = QVBoxLayout() layout.addLayout(layout_top) layout.addStretch() layout.addSpacerItem(QSpacerItem(15, 15)) layout.addLayout(layout_content) layout.addLayout(layout_run) layout.addStretch() layout.addSpacerItem(QSpacerItem(15, 15)) layout.addLayout(layout_navigation) layout.addSpacerItem(QSpacerItem(self.offset_shadow, self.offset_shadow)) layout.setSizeConstraint(QLayout.SetFixedSize) self.setLayout(layout) self.set_funcs_before_fade_in([self._disable_widgets]) self.set_funcs_after_fade_in([self._enable_widgets, self.setFocus]) self.set_funcs_before_fade_out([self._disable_widgets]) self.setContextMenuPolicy(Qt.CustomContextMenu)
def __init__(self, parent=None, is_report=False): QDialog.__init__(self, parent) self.is_report = is_report self.setWindowTitle(_("Issue reporter")) self._github_org = 'spyder-ide' self._github_repo = 'spyder' # To save the traceback sent to the internal console self.error_traceback = "" # Dialog main label if self.is_report: title = _("Please fill the following information") else: title = _("Spyder has encountered an internal problem!") self.main_label = QLabel( _("<h3>{title}</h3>" "Before reporting this problem, <i>please</i> consult our " "comprehensive " "<b><a href=\"{trouble_url}\">Troubleshooting Guide</a></b> " "which should help solve most issues, and search for " "<b><a href=\"{project_url}\">known bugs</a></b> " "matching your error message or problem description for a " "quicker solution.").format(title=title, trouble_url=__trouble_url__, project_url=__project_url__)) self.main_label.setOpenExternalLinks(True) self.main_label.setWordWrap(True) self.main_label.setAlignment(Qt.AlignJustify) self.main_label.setStyleSheet('font-size: 12px;') # Issue title self.title = QLineEdit() self.title.textChanged.connect(self._contents_changed) self.title_chars_label = QLabel( _("{} more characters " "to go...").format(TITLE_MIN_CHARS)) form_layout = QFormLayout() form_layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow) red_asterisk = '<font color="Red">*</font>' title_label = QLabel(_("<b>Title</b>: {}").format(red_asterisk)) form_layout.setWidget(0, QFormLayout.LabelRole, title_label) form_layout.setWidget(0, QFormLayout.FieldRole, self.title) # Description steps_header = QLabel( _("<b>Steps to reproduce:</b> {}").format(red_asterisk)) self.steps_text = QLabel( _("Please enter a detailed step-by-step " "description (in English) of what led up to " "the problem below. Issue reports without a " "clear way to reproduce them will be closed.")) self.steps_text.setWordWrap(True) self.steps_text.setAlignment(Qt.AlignJustify) self.steps_text.setStyleSheet('font-size: 12px;') # Field to input the description of the problem self.input_description = DescriptionWidget(self) # Only allow to submit to Github if we have a long enough description self.input_description.textChanged.connect(self._contents_changed) # Widget to show errors self.details = ShowErrorWidget(self) self.details.set_pythonshell_font(get_font()) self.details.hide() self.description_minimum_length = DESC_MIN_CHARS self.require_minimum_length = True # Label to show missing chars self.initial_chars = len(self.input_description.toPlainText()) self.desc_chars_label = QLabel( _("{} more characters " "to go...").format(self.description_minimum_length)) # Checkbox to dismiss future errors self.dismiss_box = QCheckBox( _("Hide all future errors during this " "session")) if self.is_report: self.dismiss_box.hide() # Dialog buttons gh_icon = ima.icon('github') self.submit_btn = QPushButton(gh_icon, _('Submit to Github')) self.submit_btn.setEnabled(False) self.submit_btn.clicked.connect(self._submit_to_github) self.details_btn = QPushButton(_('Show details')) self.details_btn.clicked.connect(self._show_details) if self.is_report: self.details_btn.hide() self.close_btn = QPushButton(_('Close')) if self.is_report: self.close_btn.clicked.connect(self.reject) # Buttons layout buttons_layout = QHBoxLayout() buttons_layout.addWidget(self.submit_btn) buttons_layout.addWidget(self.details_btn) buttons_layout.addWidget(self.close_btn) # Main layout layout = QVBoxLayout() layout.addWidget(self.main_label) layout.addSpacing(20) layout.addLayout(form_layout) layout.addWidget(self.title_chars_label) layout.addSpacing(12) layout.addWidget(steps_header) layout.addSpacing(-1) layout.addWidget(self.steps_text) layout.addSpacing(1) layout.addWidget(self.input_description) layout.addWidget(self.details) layout.addWidget(self.desc_chars_label) layout.addSpacing(15) layout.addWidget(self.dismiss_box) layout.addSpacing(15) layout.addLayout(buttons_layout) layout.setContentsMargins(25, 20, 25, 10) self.setLayout(layout) self.resize(570, 600) self.title.setFocus() # Set Tab key focus order self.setTabOrder(self.title, self.input_description)
def __init__(self, layer): super().__init__() self.layer = layer layer.events.select.connect(lambda v: self.setSelected(True)) layer.events.deselect.connect(lambda v: self.setSelected(False)) layer.events.name.connect(self._on_layer_name_change) layer.events.blending.connect(self._on_blending_change) layer.events.opacity.connect(self._on_opacity_change) layer.events.visible.connect(self._on_visible_change) layer.events.thumbnail.connect(self._on_thumbnail_change) self.setObjectName('layer') self.vbox_layout = QVBoxLayout() self.top = QFrame() self.top_layout = QHBoxLayout() self.grid = QFrame() self.grid_layout = QGridLayout() self.vbox_layout.addWidget(self.top) self.vbox_layout.addWidget(self.grid) self.vbox_layout.setSpacing(0) self.top.setFixedHeight(38) self.top_layout.setContentsMargins(0, 0, 0, 0) self.grid_layout.setContentsMargins(0, 0, 0, 0) self.top_layout.setAlignment(Qt.AlignCenter) self.top.setLayout(self.top_layout) self.grid.setLayout(self.grid_layout) self.setLayout(self.vbox_layout) self.name_column = 0 self.property_column = 1 cb = QCheckBox(self) cb.setObjectName('visibility') cb.setToolTip('Layer visibility') cb.setChecked(self.layer.visible) cb.setProperty('mode', 'visibility') cb.stateChanged.connect(lambda state=cb: self.changeVisible(state)) self.visibleCheckBox = cb self.top_layout.addWidget(cb) tb = QLabel(self) tb.setObjectName('thumbmnail') tb.setToolTip('Layer thumbmnail') self.thumbnail_label = tb self._on_thumbnail_change(None) self.top_layout.addWidget(tb) textbox = QLineEdit(self) textbox.setText(layer.name) textbox.home(False) textbox.setToolTip('Layer name') textbox.setAcceptDrops(False) textbox.setEnabled(True) textbox.editingFinished.connect(self.changeText) self.nameTextBox = textbox self.top_layout.addWidget(textbox) pb = QPushButton(self) pb.setToolTip('Expand properties') pb.clicked.connect(self.changeExpanded) pb.setObjectName('expand') self.expand_button = pb self.top_layout.addWidget(pb) row = self.grid_layout.rowCount() sld = QSlider(Qt.Horizontal, self) sld.setFocusPolicy(Qt.NoFocus) sld.setMinimum(0) sld.setMaximum(100) sld.setSingleStep(1) sld.setValue(self.layer.opacity * 100) sld.valueChanged[int].connect( lambda value=sld: self.changeOpacity(value)) self.opacitySilder = sld row = self.grid_layout.rowCount() self.grid_layout.addWidget(QLabel('opacity:'), row, self.name_column) self.grid_layout.addWidget(sld, row, self.property_column) row = self.grid_layout.rowCount() blend_comboBox = QComboBox() for blend in Blending: blend_comboBox.addItem(str(blend)) index = blend_comboBox.findText(self.layer.blending, Qt.MatchFixedString) blend_comboBox.setCurrentIndex(index) blend_comboBox.activated[str].connect( lambda text=blend_comboBox: self.changeBlending(text)) self.blendComboBox = blend_comboBox self.grid_layout.addWidget(QLabel('blending:'), row, self.name_column) self.grid_layout.addWidget(blend_comboBox, row, self.property_column) msg = 'Click to select\nDrag to rearrange\nDouble click to expand' self.setToolTip(msg) self.setExpanded(False) self.setFixedWidth(250) self.grid_layout.setColumnMinimumWidth(0, 100) self.grid_layout.setColumnMinimumWidth(1, 100) self.setSelected(self.layer.selected)
def __init__(self, parent, search_text, search_text_regexp, search_path, exclude, exclude_idx, exclude_regexp, supported_encodings, in_python_path, more_options, case_sensitive, external_path_history, options_button=None): QWidget.__init__(self, parent) if search_path is None: search_path = getcwd_or_home() if not isinstance(search_text, (list, tuple)): search_text = [search_text] if not isinstance(search_path, (list, tuple)): search_path = [search_path] if not isinstance(exclude, (list, tuple)): exclude = [exclude] if not isinstance(external_path_history, (list, tuple)): external_path_history = [external_path_history] self.supported_encodings = supported_encodings # Layout 1 hlayout1 = QHBoxLayout() self.search_text = PatternComboBox(self, search_text, _("Search pattern")) self.edit_regexp = create_toolbutton(self, icon=ima.icon('advanced'), tip=_('Regular expression')) self.case_button = create_toolbutton(self, icon=get_icon("upper_lower.png"), tip=_("Case Sensitive")) self.case_button.setCheckable(True) self.case_button.setChecked(case_sensitive) self.edit_regexp.setCheckable(True) self.edit_regexp.setChecked(search_text_regexp) self.more_widgets = () self.more_options = create_toolbutton(self, toggled=self.toggle_more_options) self.more_options.setCheckable(True) self.more_options.setChecked(more_options) self.ok_button = create_toolbutton(self, text=_("Search"), icon=ima.icon('find'), triggered=lambda: self.find.emit(), tip=_("Start search"), text_beside_icon=True) self.ok_button.clicked.connect(self.update_combos) self.stop_button = create_toolbutton( self, text=_("Stop"), icon=ima.icon('editclear'), triggered=lambda: self.stop.emit(), tip=_("Stop search"), text_beside_icon=True) self.stop_button.setEnabled(False) for widget in [ self.search_text, self.edit_regexp, self.case_button, self.ok_button, self.stop_button, self.more_options ]: hlayout1.addWidget(widget) if options_button: hlayout1.addWidget(options_button) # Layout 2 hlayout2 = QHBoxLayout() self.exclude_pattern = PatternComboBox(self, exclude, _("Excluded filenames pattern")) if exclude_idx is not None and exclude_idx >= 0 \ and exclude_idx < self.exclude_pattern.count(): self.exclude_pattern.setCurrentIndex(exclude_idx) self.exclude_regexp = create_toolbutton(self, icon=ima.icon('advanced'), tip=_('Regular expression')) self.exclude_regexp.setCheckable(True) self.exclude_regexp.setChecked(exclude_regexp) exclude_label = QLabel(_("Exclude:")) exclude_label.setBuddy(self.exclude_pattern) for widget in [ exclude_label, self.exclude_pattern, self.exclude_regexp ]: hlayout2.addWidget(widget) # Layout 3 hlayout3 = QHBoxLayout() search_on_label = QLabel(_("Search in:")) self.path_selection_combo = SearchInComboBox(external_path_history, parent) hlayout3.addWidget(search_on_label) hlayout3.addWidget(self.path_selection_combo) self.search_text.valid.connect(lambda valid: self.find.emit()) self.exclude_pattern.valid.connect(lambda valid: self.find.emit()) vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) vlayout.addLayout(hlayout1) vlayout.addLayout(hlayout2) vlayout.addLayout(hlayout3) self.more_widgets = (hlayout2, ) self.toggle_more_options(more_options) self.setLayout(vlayout) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)
def create_layout(self): cancel_box = QHBoxLayout() cancel_box.addWidget(self.close_button) grid1 = QGridLayout() grid2 = QGridLayout() #----------------------------------------- # setup self.radio_rectangular = QRadioButton('Rectangular') self.radio_cylindrical = QRadioButton('Cylindrical') self.radio_spherical = QRadioButton('Spherical') coord_type_layout = QHBoxLayout() coord_type_layout.addWidget(self.radio_rectangular) coord_type_layout.addWidget(self.radio_cylindrical) coord_type_layout.addWidget(self.radio_spherical) checkboxs = QButtonGroup(self) checkboxs.addButton(self.checkbox_region_all) checkboxs.addButton(self.checkbox_region_ids) vbox1 = QVBoxLayout() vbox1.addWidget(self.checkbox_region_all) vbox1.addWidget(self.checkbox_region_ids) #vbox1.addLayout(checkboxs) #----------------------------------------- irow = 0 grid2.addWidget(self.name, irow, 0) grid2.addWidget(self.name_edit, irow, 1) irow += 1 #grid2.addWidget(self.name, irow, 0) grid2.addWidget(self.description_edit, irow, 1) irow += 1 grid2.addWidget(self.location_x, irow, 0) grid2.addWidget(self.location_x_edit, irow, 1) irow += 1 grid2.addWidget(self.location_y, irow, 0) grid2.addWidget(self.location_y_edit, irow, 1) irow += 1 grid2.addWidget(self.location_z, irow, 0) grid2.addWidget(self.location_z_edit, irow, 1) irow += 1 #| Name EngineInlet | #| RegionMode * RegionID | #| * All | #| | #| AllowedRegions: | #| Region ID 3 | #| | #| PickMode * All | #| Pick Mode x On/Off | #| Pick Angle 20 deg | #| | #| Revert | #| RenumberRegions | #| Close | grid2.addWidget(self.region_id, irow, 0) grid2.addWidget(self.region_id_edit, irow, 1) irow += 1 #grid2.addWidget(self.pick_mode, irow, 0) grid2.addWidget(self.checkbox_pick_mode, irow, 0) irow += 1 grid2.addWidget(self.pick_angle, irow, 0) grid2.addWidget(self.pick_angle_edit, irow, 1) irow += 1 #grid2.addWidget(self.pi, irow, 0) #grid2.addLayout(coord_type_layout, irow, 1) #irow += 1 #grid2.addWidget(self.location, irow, 0) #grid2.addLayout(location_layout, irow, 1) #irow += 1 #------------------------------------ vbox = QVBoxLayout() vbox.addLayout(grid1) #vbox.addLayout(vbox1) #vbox.addStretch() vbox.addWidget(self.table) vbox.addLayout(grid2) vbox.addStretch() #vbox.addWidget(self.check_apply) vbox.addLayout(cancel_box) self.setLayout(vbox)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.dir = None self.runconf = RunConfiguration() firstrun_o = CONF.get('run', ALWAYS_OPEN_FIRST_RUN_OPTION, False) # --- Interpreter --- interpreter_group = QGroupBox(_("Console")) interpreter_layout = QVBoxLayout(interpreter_group) self.current_radio = QRadioButton(CURRENT_INTERPRETER) interpreter_layout.addWidget(self.current_radio) self.dedicated_radio = QRadioButton(DEDICATED_INTERPRETER) interpreter_layout.addWidget(self.dedicated_radio) self.systerm_radio = QRadioButton(SYSTERM_INTERPRETER) interpreter_layout.addWidget(self.systerm_radio) # --- General settings ---- common_group = QGroupBox(_("General settings")) common_layout = QGridLayout(common_group) self.clear_var_cb = QCheckBox(CLEAR_ALL_VARIABLES) common_layout.addWidget(self.clear_var_cb, 0, 0) self.console_ns_cb = QCheckBox(CONSOLE_NAMESPACE) common_layout.addWidget(self.console_ns_cb, 1, 0) self.post_mortem_cb = QCheckBox(POST_MORTEM) common_layout.addWidget(self.post_mortem_cb, 2, 0) self.clo_cb = QCheckBox(_("Command line options:")) common_layout.addWidget(self.clo_cb, 3, 0) self.clo_edit = QLineEdit() self.clo_cb.toggled.connect(self.clo_edit.setEnabled) self.clo_edit.setEnabled(False) common_layout.addWidget(self.clo_edit, 3, 1) # --- Working directory --- wdir_group = QGroupBox(_("Working directory settings")) wdir_layout = QVBoxLayout(wdir_group) self.file_dir_radio = QRadioButton(FILE_DIR) wdir_layout.addWidget(self.file_dir_radio) self.cwd_radio = QRadioButton(CW_DIR) wdir_layout.addWidget(self.cwd_radio) fixed_dir_layout = QHBoxLayout() self.fixed_dir_radio = QRadioButton(FIXED_DIR) fixed_dir_layout.addWidget(self.fixed_dir_radio) self.wd_edit = QLineEdit() self.fixed_dir_radio.toggled.connect(self.wd_edit.setEnabled) self.wd_edit.setEnabled(False) fixed_dir_layout.addWidget(self.wd_edit) browse_btn = create_toolbutton(self, triggered=self.select_directory, icon=ima.icon('DirOpenIcon'), tip=_("Select directory")) fixed_dir_layout.addWidget(browse_btn) wdir_layout.addLayout(fixed_dir_layout) # --- System terminal --- external_group = QGroupBox(_("External system terminal")) external_group.setDisabled(True) self.systerm_radio.toggled.connect(external_group.setEnabled) external_layout = QGridLayout() external_group.setLayout(external_layout) self.interact_cb = QCheckBox(INTERACT) external_layout.addWidget(self.interact_cb, 1, 0, 1, -1) self.pclo_cb = QCheckBox(_("Command line options:")) external_layout.addWidget(self.pclo_cb, 3, 0) self.pclo_edit = QLineEdit() self.pclo_cb.toggled.connect(self.pclo_edit.setEnabled) self.pclo_edit.setEnabled(False) self.pclo_edit.setToolTip( _("<b>-u</b> is added to the " "other options you set here")) external_layout.addWidget(self.pclo_edit, 3, 1) # Checkbox to preserve the old behavior, i.e. always open the dialog # on first run self.firstrun_cb = QCheckBox(ALWAYS_OPEN_FIRST_RUN % _("this dialog")) self.firstrun_cb.clicked.connect(self.set_firstrun_o) self.firstrun_cb.setChecked(firstrun_o) layout = QVBoxLayout(self) layout.addWidget(interpreter_group) layout.addWidget(common_group) layout.addWidget(wdir_group) layout.addWidget(external_group) layout.addWidget(self.firstrun_cb) layout.addStretch(100)
def __init__(self, viewer: Viewer, welcome=False): # Avoid circular import. from .layer_controls import QtLayerControlsContainer super().__init__() self.setAttribute(Qt.WA_DeleteOnClose) QCoreApplication.setAttribute( Qt.AA_UseStyleSheetPropagationInWidgetStyles, True) self.viewer = viewer self.dims = QtDims(self.viewer.dims) self.controls = QtLayerControlsContainer(self.viewer) self.layers = QtLayerList(self.viewer.layers) self.layerButtons = QtLayerButtons(self.viewer) self.viewerButtons = QtViewerButtons(self.viewer) self._key_map_handler = KeymapHandler() self._key_map_handler.keymap_providers = [self.viewer] self._key_bindings_dialog = None self._console = None layerList = QWidget() layerList.setObjectName('layerList') layerListLayout = QVBoxLayout() layerListLayout.addWidget(self.layerButtons) layerListLayout.addWidget(self.layers) layerListLayout.addWidget(self.viewerButtons) layerListLayout.setContentsMargins(8, 4, 8, 6) layerList.setLayout(layerListLayout) self.dockLayerList = QtViewerDockWidget( self, layerList, name=trans._('layer list'), area='left', allowed_areas=['left', 'right'], object_name='layer list', ) self.dockLayerControls = QtViewerDockWidget( self, self.controls, name=trans._('layer controls'), area='left', allowed_areas=['left', 'right'], object_name='layer controls', ) self.dockConsole = QtViewerDockWidget( self, QWidget(), name=trans._('console'), area='bottom', allowed_areas=['top', 'bottom'], shortcut='Ctrl+Shift+C', object_name='console', ) self.dockConsole.setVisible(False) # because the console is loaded lazily in the @getter, this line just # gets (or creates) the console when the dock console is made visible. self.dockConsole.visibilityChanged.connect(lambda visible: self.console if visible else None) self.dockLayerControls.visibilityChanged.connect(self._constrain_width) self.dockLayerList.setMaximumWidth(258) self.dockLayerList.setMinimumWidth(258) # Only created if using perfmon. self.dockPerformance = self._create_performance_dock_widget() # This dictionary holds the corresponding vispy visual for each layer self.layer_to_visual = {} self.viewerButtons.consoleButton.clicked.connect( self.toggle_console_visibility) self._create_canvas() main_widget = QWidget() main_layout = QVBoxLayout() main_layout.setContentsMargins(10, 22, 10, 2) main_layout.addWidget(self.canvas.native) main_layout.addWidget(self.dims) main_layout.setSpacing(10) main_widget.setLayout(main_layout) self.setOrientation(Qt.Vertical) self.addWidget(main_widget) self._last_visited_dir = str(Path.home()) self._cursors = { 'cross': Qt.CrossCursor, 'forbidden': Qt.ForbiddenCursor, 'pointing': Qt.PointingHandCursor, 'standard': QCursor(), } self._on_active_change() viewer.layers.selection.events.active.connect(self._on_active_change) self.viewer.camera.events.interactive.connect(self._on_interactive) self.viewer.cursor.events.style.connect(self._on_cursor) self.viewer.cursor.events.size.connect(self._on_cursor) self.viewer.layers.events.reordered.connect(self._reorder_layers) self.viewer.layers.events.inserted.connect(self._on_add_layer_change) self.viewer.layers.events.removed.connect(self._remove_layer) # stop any animations whenever the layers change self.viewer.events.layers_change.connect(lambda x: self.dims.stop()) self.setAcceptDrops(True) for layer in self.viewer.layers: self._add_layer(layer) self.view = self.canvas.central_widget.add_view() self.camera = VispyCamera(self.view, self.viewer.camera, self.viewer.dims) self.canvas.connect(self.camera.on_draw) # Add axes, scale bar and welcome visuals. self._add_visuals(welcome) # Create the experimental QtPool for octree and/or monitor. self._qt_poll = _create_qt_poll(self, self.viewer.camera) # Create the experimental RemoteManager for the monitor. self._remote_manager = _create_remote_manager(self.viewer.layers, self._qt_poll)
def __init__(self, parent, search_text, search_text_regexp, search_path, include, include_idx, include_regexp, exclude, exclude_idx, exclude_regexp, supported_encodings, in_python_path, more_options): QWidget.__init__(self, parent) if search_path is None: search_path = getcwd() if not isinstance(search_text, (list, tuple)): search_text = [search_text] if not isinstance(search_path, (list, tuple)): search_path = [search_path] if not isinstance(include, (list, tuple)): include = [include] if not isinstance(exclude, (list, tuple)): exclude = [exclude] self.supported_encodings = supported_encodings # Layout 1 hlayout1 = QHBoxLayout() self.search_text = PatternComboBox(self, search_text, _("Search pattern")) self.edit_regexp = create_toolbutton(self, icon=ima.icon('advanced'), tip=_('Regular expression')) self.edit_regexp.setCheckable(True) self.edit_regexp.setChecked(search_text_regexp) self.more_widgets = () self.more_options = create_toolbutton(self, toggled=self.toggle_more_options) self.more_options.setCheckable(True) self.more_options.setChecked(more_options) self.ok_button = create_toolbutton(self, text=_("Search"), icon=ima.icon('DialogApplyButton'), triggered=lambda: self.find.emit(), tip=_("Start search"), text_beside_icon=True) self.ok_button.clicked.connect(self.update_combos) self.stop_button = create_toolbutton(self, text=_("Stop"), icon=ima.icon('stop'), triggered=lambda: self.stop.emit(), tip=_("Stop search"), text_beside_icon=True) self.stop_button.setEnabled(False) for widget in [self.search_text, self.edit_regexp, self.ok_button, self.stop_button, self.more_options]: hlayout1.addWidget(widget) # Layout 2 hlayout2 = QHBoxLayout() self.include_pattern = PatternComboBox(self, include, _("Included filenames pattern")) if include_idx is not None and include_idx >= 0 \ and include_idx < self.include_pattern.count(): self.include_pattern.setCurrentIndex(include_idx) self.include_regexp = create_toolbutton(self, icon=ima.icon('advanced'), tip=_('Regular expression')) self.include_regexp.setCheckable(True) self.include_regexp.setChecked(include_regexp) include_label = QLabel(_("Include:")) include_label.setBuddy(self.include_pattern) self.exclude_pattern = PatternComboBox(self, exclude, _("Excluded filenames pattern")) if exclude_idx is not None and exclude_idx >= 0 \ and exclude_idx < self.exclude_pattern.count(): self.exclude_pattern.setCurrentIndex(exclude_idx) self.exclude_regexp = create_toolbutton(self, icon=ima.icon('advanced'), tip=_('Regular expression')) self.exclude_regexp.setCheckable(True) self.exclude_regexp.setChecked(exclude_regexp) exclude_label = QLabel(_("Exclude:")) exclude_label.setBuddy(self.exclude_pattern) for widget in [include_label, self.include_pattern, self.include_regexp, exclude_label, self.exclude_pattern, self.exclude_regexp]: hlayout2.addWidget(widget) # Layout 3 hlayout3 = QHBoxLayout() self.python_path = QRadioButton(_("PYTHONPATH"), self) self.python_path.setChecked(in_python_path) self.python_path.setToolTip(_( "Search in all directories listed in sys.path which" " are outside the Python installation directory")) self.hg_manifest = QRadioButton(_("Hg repository"), self) self.detect_hg_repository() self.hg_manifest.setToolTip( _("Search in current directory hg repository")) self.custom_dir = QRadioButton(_("Here:"), self) self.custom_dir.setChecked(not in_python_path) self.dir_combo = PathComboBox(self) self.dir_combo.addItems(search_path) self.dir_combo.setToolTip(_("Search recursively in this directory")) self.dir_combo.open_dir.connect(self.set_directory) self.python_path.toggled.connect(self.dir_combo.setDisabled) self.hg_manifest.toggled.connect(self.dir_combo.setDisabled) browse = create_toolbutton(self, icon=ima.icon('DirOpenIcon'), tip=_('Browse a search directory'), triggered=self.select_directory) for widget in [self.python_path, self.hg_manifest, self.custom_dir, self.dir_combo, browse]: hlayout3.addWidget(widget) self.search_text.valid.connect(lambda valid: self.find.emit()) self.include_pattern.valid.connect(lambda valid: self.find.emit()) self.exclude_pattern.valid.connect(lambda valid: self.find.emit()) self.dir_combo.valid.connect(lambda valid: self.find.emit()) vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) vlayout.addLayout(hlayout1) vlayout.addLayout(hlayout2) vlayout.addLayout(hlayout3) self.more_widgets = (hlayout2, hlayout3) self.toggle_more_options(more_options) self.setLayout(vlayout) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)
def setup(self): """Setup the ShortcutEditor with the provided arguments.""" # Widgets icon_info = HelperToolButton() icon_info.setIcon(ima.get_std_icon('MessageBoxInformation')) layout_icon_info = QVBoxLayout() layout_icon_info.setContentsMargins(0, 0, 0, 0) layout_icon_info.setSpacing(0) layout_icon_info.addWidget(icon_info) layout_icon_info.addStretch(100) self.label_info = QLabel() self.label_info.setText( _("Press the new shortcut and select 'Ok' to confirm, " "click 'Cancel' to revert to the previous state, " "or use 'Clear' to unbind the command from a shortcut.")) self.label_info.setAlignment(Qt.AlignTop | Qt.AlignLeft) self.label_info.setWordWrap(True) layout_info = QHBoxLayout() layout_info.setContentsMargins(0, 0, 0, 0) layout_info.addLayout(layout_icon_info) layout_info.addWidget(self.label_info) layout_info.setStretch(1, 100) self.label_current_sequence = QLabel(_("Current shortcut:")) self.text_current_sequence = QLabel(self.current_sequence) self.label_new_sequence = QLabel(_("New shortcut:")) self.text_new_sequence = ShortcutLineEdit(self) self.text_new_sequence.setPlaceholderText(_("Press shortcut.")) self.helper_button = HelperToolButton() self.helper_button.setIcon(QIcon()) self.label_warning = QLabel() self.label_warning.setWordWrap(True) self.label_warning.setAlignment(Qt.AlignTop | Qt.AlignLeft) self.button_default = QPushButton(_('Default')) self.button_ok = QPushButton(_('Ok')) self.button_ok.setEnabled(False) self.button_clear = QPushButton(_('Clear')) self.button_cancel = QPushButton(_('Cancel')) button_box = QHBoxLayout() button_box.addWidget(self.button_default) button_box.addStretch(100) button_box.addWidget(self.button_ok) button_box.addWidget(self.button_clear) button_box.addWidget(self.button_cancel) # New Sequence button box self.btn_clear_sequence = create_toolbutton( self, icon=ima.icon('editclear'), tip=_("Clear all entered key sequences"), triggered=self.clear_new_sequence) self.button_back_sequence = create_toolbutton( self, icon=ima.icon('ArrowBack'), tip=_("Remove last key sequence entered"), triggered=self.back_new_sequence) newseq_btnbar = QHBoxLayout() newseq_btnbar.setSpacing(0) newseq_btnbar.setContentsMargins(0, 0, 0, 0) newseq_btnbar.addWidget(self.button_back_sequence) newseq_btnbar.addWidget(self.btn_clear_sequence) # Setup widgets self.setWindowTitle(_('Shortcut: {0}').format(self.name)) self.helper_button.setToolTip('') style = """ QToolButton { margin:1px; border: 0px solid grey; padding:0px; border-radius: 0px; }""" self.helper_button.setStyleSheet(style) icon_info.setToolTip('') icon_info.setStyleSheet(style) # Layout layout_sequence = QGridLayout() layout_sequence.setContentsMargins(0, 0, 0, 0) layout_sequence.addLayout(layout_info, 0, 0, 1, 4) layout_sequence.addItem(QSpacerItem(15, 15), 1, 0, 1, 4) layout_sequence.addWidget(self.label_current_sequence, 2, 0) layout_sequence.addWidget(self.text_current_sequence, 2, 2) layout_sequence.addWidget(self.label_new_sequence, 3, 0) layout_sequence.addWidget(self.helper_button, 3, 1) layout_sequence.addWidget(self.text_new_sequence, 3, 2) layout_sequence.addLayout(newseq_btnbar, 3, 3) layout_sequence.addWidget(self.label_warning, 4, 2, 1, 2) layout_sequence.setColumnStretch(2, 100) layout_sequence.setRowStretch(4, 100) layout = QVBoxLayout(self) layout.addLayout(layout_sequence) layout.addSpacing(10) layout.addLayout(button_box) layout.setSizeConstraint(layout.SetFixedSize) # Signals self.button_ok.clicked.connect(self.accept_override) self.button_clear.clicked.connect(self.unbind_shortcut) self.button_cancel.clicked.connect(self.reject) self.button_default.clicked.connect(self.set_sequence_to_default) # Set all widget to no focus so that we can register <Tab> key # press event. widgets = (self.label_warning, self.helper_button, self.text_new_sequence, self.button_clear, self.button_default, self.button_cancel, self.button_ok, self.btn_clear_sequence, self.button_back_sequence) for w in widgets: w.setFocusPolicy(Qt.NoFocus) w.clearFocus()
def createUI(self): """ Create the popup box with the calculation input area and buttons. :return: """ boldFont = QtGui.QFont() boldFont.setBold(True) # Create calculation label and input box self.calculation_label = QLabel("Calculation:") self.calculation_label.setFixedWidth(100) self.calculation_label.setAlignment((Qt.AlignRight | Qt.AlignTop)) self.calculation_label.setFont(boldFont) self.calculation_text = QLineEdit() self.calculation_text.setMinimumWidth(200) self.calculation_text.setAlignment((Qt.AlignLeft | Qt.AlignTop)) hbl1 = QHBoxLayout() hbl1.addWidget(self.calculation_label) hbl1.addWidget(self.calculation_text) # Create calculation label and input box self.error_label = QLabel("") self.error_label.setFixedWidth(100) self.error_label_text = QLabel("") self.error_label_text.setMinimumWidth(200) self.error_label_text.setAlignment((Qt.AlignLeft | Qt.AlignTop)) hbl_error = QHBoxLayout() hbl_error.addWidget(self.error_label) hbl_error.addWidget(self.error_label_text) # Show the available data self.data_available_text_label = QLabel("Data available: ") self.data_available_text_label.setFixedWidth(100) self.data_available_text_label.setAlignment( (Qt.AlignRight | Qt.AlignTop)) self.data_available_text_label.setFont(boldFont) self.data_available_label = QLabel(', '.join(self.data_components)) self.data_available_label.setMinimumWidth(200) self.data_available_label.setAlignment((Qt.AlignLeft | Qt.AlignTop)) hbl2 = QHBoxLayout() hbl2.addWidget(self.data_available_text_label) hbl2.addWidget(self.data_available_label) # Show the examples self.example_text_label = QLabel("Examples: ") self.example_text_label.setFixedWidth(100) self.example_text_label.setAlignment((Qt.AlignRight | Qt.AlignTop)) self.example_text_label.setFont(boldFont) examples = """Assuming we have data available called FLUX and ERROR: - Subtract 1000 from {0}: {0}new = {0} - 1000 - Double the FLUX: {0}new = {0} * 2 - Scale FLUX between 0 and 1: {0}norm = ({0} - min({0})) - (max({0})-min({0})) - Signal to noise: SNR = {0} / {1} - Masking: {0}new = {0} * ({1} < 0.1*mean({1})) """.format(self.data_components[0], self.data_components[1]) self.examples_label = QLabel(examples) self.examples_label.setMinimumWidth(200) self.examples_label.setAlignment((Qt.AlignLeft | Qt.AlignTop)) hbl_examples = QHBoxLayout() hbl_examples.addWidget(self.example_text_label) hbl_examples.addWidget(self.examples_label) # Create Calculate and Cancel buttons self.calculateButton = QPushButton("Calculate") self.calculateButton.clicked.connect(self.calculate_callback) self.calculateButton.setDefault(True) self.cancelButton = QPushButton("Cancel") self.cancelButton.clicked.connect(self.cancel_callback) hbl5 = QHBoxLayout() hbl5.addStretch(1) hbl5.addWidget(self.cancelButton) hbl5.addWidget(self.calculateButton) # Add calculation and buttons to popup box vbl = QVBoxLayout() vbl.addLayout(hbl1) vbl.addLayout(hbl_error) vbl.addLayout(hbl2) vbl.addLayout(hbl_examples) vbl.addLayout(hbl5) self.wid = QWidget(self) self.setCentralWidget(self.wid) self.wid.setLayout(vbl) self.setMaximumWidth(700) self.show()
def __init__(self, parent, max_entries=100, options_button=None, text_color=None, prevrate_color=None, top_max_entries=100): super().__init__(parent) self.setWindowTitle("Pylint") self.parent = parent self.output = None self.error_output = None self.filename = None self.text_color = text_color self.prevrate_color = prevrate_color self.max_entries = max_entries self.top_max_entries = top_max_entries self.rdata = [] if osp.isfile(self.DATAPATH): try: data = pickle.loads(open(self.DATAPATH, 'rb').read()) if data[0] == self.VERSION: self.rdata = data[1:] except (EOFError, ImportError): pass self.filecombo = PythonModulesComboBox(self) self.filecombo.setInsertPolicy(self.filecombo.InsertAtTop) self.start_button = create_toolbutton( self, icon=ima.icon('run'), text=_("Analyze"), tip=_("Run analysis"), triggered=self.analyze_button_handler, text_beside_icon=True) self.stop_button = create_toolbutton(self, icon=ima.icon('stop'), text=_("Stop"), tip=_("Stop current analysis"), text_beside_icon=True) self.filecombo.valid.connect(self.start_button.setEnabled) self.filecombo.valid.connect(self.check_new_file) browse_button = create_toolbutton(self, icon=ima.icon('fileopen'), tip=_('Select Python file'), triggered=self.select_file) self.ratelabel = QLabel() self.datelabel = QLabel() self.log_button = create_toolbutton(self, icon=ima.icon('log'), text=_("Output"), text_beside_icon=True, tip=_("Complete output"), triggered=self.show_log) self.treewidget = ResultsTree(self) hlayout1 = QHBoxLayout() hlayout1.addWidget(self.filecombo) hlayout1.addWidget(browse_button) hlayout1.addWidget(self.start_button) hlayout1.addWidget(self.stop_button) if options_button: hlayout1.addWidget(options_button) hlayout2 = QHBoxLayout() hlayout2.addWidget(self.ratelabel) hlayout2.addStretch() hlayout2.addWidget(self.datelabel) hlayout2.addStretch() hlayout2.addWidget(self.log_button) layout = QVBoxLayout() layout.addLayout(hlayout1) layout.addLayout(hlayout2) layout.addWidget(self.treewidget) self.setLayout(layout) self.process = None self.set_running_state(False) self.show_data() if self.rdata: self.remove_obsolete_items() self.filecombo.insertItems(0, self.get_filenames()) self.start_button.setEnabled(self.filecombo.is_valid()) else: self.start_button.setEnabled(False) if self.parent: self.curr_filenames = self.parent.get_option( 'history_filenames', []) else: self.curr_filenames = [] for f in self.curr_filenames[::-1]: self.set_filename(f)
def __init__( self, settings: BaseSettings, channel_property: ChannelProperty, name: str, parent: Optional[QWidget] = None, ndisplay=2, ): super().__init__(parent=parent) self.settings = settings self.channel_property = channel_property self.name = name self.image_info: Dict[str, ImageInfo] = {} self.current_image = "" self._current_order = "xy" self.components = None self.worker_list = [] self.points_layer = None self.roi_alternative_selection = "ROI" self._search_type = SearchType.Highlight self._last_component = 1 self.viewer = Viewer(ndisplay=ndisplay) self.viewer.theme = self.settings.theme_name self.viewer_widget = NapariQtViewer(self.viewer) if hasattr(self.viewer_widget.canvas, "background_color_override"): self.viewer_widget.canvas.background_color_override = "black" self.channel_control = ColorComboBoxGroup(settings, name, channel_property, height=30) self.ndim_btn = QtNDisplayButton(self.viewer) self.reset_view_button = QtViewerPushButton(self.viewer, "home", "Reset view", self._reset_view) self.points_view_button = QtViewerPushButton( self.viewer, "new_points", "Show points", self.toggle_points_visibility) self.points_view_button.setVisible(False) self.search_roi_btn = SearchROIButton(self.settings) self.search_roi_btn.clicked.connect(self._search_component) self.search_roi_btn.setDisabled(True) self.roll_dim_button = QtViewerPushButton(self.viewer, "roll", "Roll dimension", self._rotate_dim) self.roll_dim_button.setContextMenuPolicy(Qt.CustomContextMenu) self.roll_dim_button.customContextMenuRequested.connect( self._dim_order_menu) self.mask_chk = QCheckBox() self.mask_chk.setVisible(False) self.mask_label = QLabel("Mask:") self.mask_label.setVisible(False) self.btn_layout = QHBoxLayout() self.btn_layout.addWidget(self.reset_view_button) self.btn_layout.addWidget(self.ndim_btn) self.btn_layout.addWidget(self.roll_dim_button) self.btn_layout.addWidget(self.points_view_button) self.btn_layout.addWidget(self.search_roi_btn) self.btn_layout.addWidget(self.channel_control, 1) self.btn_layout.addWidget(self.mask_label) self.btn_layout.addWidget(self.mask_chk) self.btn_layout2 = QHBoxLayout() layout = QVBoxLayout() layout.addLayout(self.btn_layout) layout.addLayout(self.btn_layout2) layout.addWidget(self.viewer_widget) self.setLayout(layout) self.channel_control.change_channel.connect(self.change_visibility) self.viewer.events.status.connect(self.print_info) settings.mask_changed.connect(self.set_mask) settings.roi_changed.connect(self.set_roi) settings.roi_clean.connect(self.set_roi) settings.image_changed.connect(self.set_image) settings.image_spacing_changed.connect(self.update_spacing_info) settings.points_changed.connect(self.update_points) settings.connect_to_profile(RENDERING_MODE_NAME, self.update_rendering) settings.labels_changed.connect(self.update_roi_coloring) settings.connect_to_profile(f"{name}.image_state.opacity", self.update_roi_coloring) settings.connect_to_profile(f"{name}.image_state.only_border", self.update_roi_border) settings.connect_to_profile(f"{name}.image_state.border_thick", self.update_roi_border) settings.connect_to_profile(f"{name}.image_state.show_label", self.update_roi_labeling) settings.connect_to_profile("mask_presentation_opacity", self.update_mask_parameters) settings.connect_to_profile("mask_presentation_color", self.update_mask_parameters) # settings.labels_changed.connect(self.paint_layer) self.old_scene: BaseCamera = self.viewer_widget.view.scene self.mask_chk.stateChanged.connect(self.change_mask_visibility) self.viewer_widget.view.scene.transform.changed.connect( self._view_changed, position="last") self.viewer.dims.events.current_step.connect(self._view_changed, position="last") self.viewer.dims.events.ndisplay.connect(self._view_changed, position="last") self.viewer.dims.events.ndisplay.connect(self._view_changed, position="last") self.viewer.dims.events.ndisplay.connect(self.camera_change, position="last") self.viewer.events.reset_view.connect(self._view_changed, position="last")
def run(loop_times): for i in range(loop_times): print(i) time.sleep(1) return 'finished!!', 'aaaaaa', ['finished', 123] def single_shoot(): global oneshot, textedit if oneshot is not None: if oneshot.is_running(): return oneshot = PMGOneShotThreadRunner(run, args=(3, )) oneshot.signal_finished.connect( lambda x: textedit.append('任务完成,函数返回值:' + repr(x))) oneshot = None app = QApplication(sys.argv) basewidget = QWidget() basewidget.setLayout(QVBoxLayout()) textedit = QTextEdit() pushbutton = QPushButton('run') pushbutton.clicked.connect(single_shoot) basewidget.layout().addWidget(textedit) basewidget.layout().addWidget(pushbutton) basewidget.show() sys.exit(app.exec_())
def setupUI(self): from functools import partial from qtpy.QtCore import Qt from qtpy.QtWidgets import QHBoxLayout, QFormLayout, QSlider, QPushButton, QPlainTextEdit, QCheckBox, QComboBox from qtpy.QtWidgets import QRadioButton, QWidget, QVBoxLayout, QListView, QSpacerItem, QSizePolicy layout = QHBoxLayout() layout1 = QFormLayout() self.fontsizeslider = QSlider(Qt.Horizontal) self.fontsizeslider.setMinimum(1) self.fontsizeslider.setMaximum(12) self.fontsizeslider.setTickInterval(2) self.fontsizeslider.setSingleStep(2) self.fontsizeslider.setValue(config.presentationFontSize / 0.5) self.fontsizeslider.setToolTip(str(config.presentationFontSize)) self.fontsizeslider.valueChanged.connect(self.presentationFontSizeChanged) layout1.addRow("Font Size", self.fontsizeslider) self.changecolorbutton = QPushButton() buttonStyle = "QPushButton {0}background-color: {2}; color: {3};{1}".format("{", "}", config.presentationColorOnDarkTheme if config.theme in ("dark", "night") else config.presentationColorOnLightTheme, "white" if config.theme in ("dark", "night") else "black") self.changecolorbutton.setStyleSheet(buttonStyle) self.changecolorbutton.setToolTip("Change Color") self.changecolorbutton.clicked.connect(self.changeColor) layout1.addRow("Font Color", self.changecolorbutton) self.marginslider = QSlider(Qt.Horizontal) self.marginslider.setMinimum(0) self.marginslider.setMaximum(200) self.marginslider.setTickInterval(50) self.marginslider.setSingleStep(50) self.marginslider.setValue(config.presentationMargin) self.marginslider.setToolTip(str(config.presentationMargin)) self.marginslider.valueChanged.connect(self.presentationMarginChanged) layout1.addRow("Margin", self.marginslider) self.verticalpositionslider = QSlider(Qt.Horizontal) self.verticalpositionslider.setMinimum(10) self.verticalpositionslider.setMaximum(90) self.verticalpositionslider.setTickInterval(10) self.verticalpositionslider.setSingleStep(10) self.verticalpositionslider.setValue(config.presentationVerticalPosition) self.verticalpositionslider.setToolTip(str(config.presentationVerticalPosition)) self.verticalpositionslider.valueChanged.connect(self.presentationVerticalPositionChanged) layout1.addRow("Vertical Position", self.verticalpositionslider) self.horizontalpositionslider = QSlider(Qt.Horizontal) self.horizontalpositionslider.setMinimum(10) self.horizontalpositionslider.setMaximum(90) self.horizontalpositionslider.setTickInterval(10) self.horizontalpositionslider.setSingleStep(10) self.horizontalpositionslider.setValue(config.presentationHorizontalPosition) self.horizontalpositionslider.setToolTip(str(config.presentationHorizontalPosition)) self.horizontalpositionslider.valueChanged.connect(self.presentationHorizontalPositionChanged) layout1.addRow("Horizontal Position", self.horizontalpositionslider) self.showBibleSelection = QRadioButton() self.showBibleSelection.setChecked(True) self.showBibleSelection.clicked.connect(lambda: self.selectRadio("bible")) layout1.addRow("Bible", self.showBibleSelection) if len(self.books) > 0: self.showHymnsSelection = QRadioButton() self.showHymnsSelection.setChecked(False) self.showHymnsSelection.clicked.connect(lambda: self.selectRadio("hymns")) layout1.addRow("Songs", self.showHymnsSelection) # Second column layout2 = QVBoxLayout() self.bibleWidget = QWidget() self.bibleLayout = QFormLayout() checkbox = QCheckBox() checkbox.setText("") checkbox.setChecked(config.presentationParser) checkbox.stateChanged.connect(self.presentationParserChanged) checkbox.setToolTip("Parse bible verse reference in the entered text") self.bibleLayout.addRow("Bible Reference", checkbox) versionCombo = QComboBox() self.bibleVersions = self.parent.textList versionCombo.addItems(self.bibleVersions) initialIndex = 0 if config.mainText in self.bibleVersions: initialIndex = self.bibleVersions.index(config.mainText) versionCombo.setCurrentIndex(initialIndex) versionCombo.currentIndexChanged.connect(self.changeBibleVersion) self.bibleLayout.addRow("Bible Version", versionCombo) defaultVerse = "{0} {1}:{2}".format(BibleBooks.eng[str(config.mainB)][0], config.mainC, config.mainV) self.textEntry = QPlainTextEdit(defaultVerse) self.bibleLayout.addRow(self.textEntry) button = QPushButton("Presentation") button.setToolTip("Go to Presentation") button.clicked.connect(self.goToPresentation) self.bibleLayout.addWidget(button) self.bibleLayout.addItem(QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)) self.bibleWidget.setLayout(self.bibleLayout) self.hymnWidget = QWidget() self.hymnLayout = QFormLayout() selected = 0 book = "Hymn Lyrics - English" if book in self.books: selected = self.books.index(book) self.bookList = QComboBox() self.bookList.addItems(self.books) self.bookList.setCurrentIndex(selected) self.bookList.currentIndexChanged.connect(self.selectHymnBook) self.hymnLayout.addWidget(self.bookList) self.chapterlist = QListView() self.chapterlist.clicked.connect(self.selectHymn) # self.chapterlist.selectionModel().selectionChanged.connect(self.selectHymn) self.hymnLayout.addWidget(self.chapterlist) self.buttons = [] for count in range(0, 10): hymnButton = QPushButton() hymnButton.setText(" ") hymnButton.setEnabled(False) hymnButton.clicked.connect(partial(self.selectParagraph, count)) self.hymnLayout.addWidget(hymnButton) self.buttons.append(hymnButton) self.selectHymnBook(selected) self.hymnWidget.setLayout(self.hymnLayout) self.hymnWidget.hide() layout2.addWidget(self.bibleWidget) if len(self.books) > 0: layout2.addWidget(self.hymnWidget) layout.addLayout(layout1) layout.addLayout(layout2) self.setLayout(layout)
def __init__(self, model, ctrl, parent=None): self._model = model self._model.propertyUpdated.connect(self.updatePropertyFromModel) self._model.failureMsg.connect(self.show_failure_msg) self._ctrl = ctrl super().__init__(parent) self.setWindowTitle("PyRS Strain-Stress Viewer") mainMenu = self.menuBar() fileMenu = mainMenu.addMenu('File') self.saveAction = QAction('&Save state', self) self.saveAction.setShortcut('Ctrl+S') self.saveAction.setStatusTip('Save application state') self.saveAction.triggered.connect(self.save) self.saveAction.setEnabled(False) fileMenu.addAction(self.saveAction) self.loadAction = QAction('&Load state', self) self.loadAction.setStatusTip('Load application state') self.loadAction.triggered.connect(self.load) fileMenu.addAction(self.loadAction) fileMenu.addSeparator() exitAction = QAction('&Exit', self) exitAction.setShortcut('Ctrl+Q') exitAction.setStatusTip('Exit application') exitAction.triggered.connect(self.close) fileMenu.addAction(exitAction) self.splitter = QSplitter() self.splitter.setHandleWidth(10) self.setCentralWidget(self.splitter) left = QWidget() left_layout = QVBoxLayout() self.stressCase = StressCase(self) self.stressCase.dimChanged.connect(self.dimChanged) left_layout.addWidget(self.stressCase) self.fileLoading = FileLoading(self) left_layout.addWidget(self.fileLoading) self.peak_selection = PeakSelection(self) self.peak_selection.peak_select.currentTextChanged.connect( self.controller.peakSelected) left_layout.addWidget(self.peak_selection) self.d0 = D0(self) left_layout.addWidget(self.d0) self.mechanicalConstants = MechanicalConstants(self) self.mechanicalConstants.youngModulus.editingFinished.connect( self.update_plot) self.mechanicalConstants.poissonsRatio.editingFinished.connect( self.update_plot) left_layout.addWidget(self.mechanicalConstants) self.csvExport = CSVExport(self) left_layout.addWidget(self.csvExport) left_layout.addStretch(0) left.setLayout(left_layout) self.splitter.addWidget(left) right = QWidget() right_layout = QVBoxLayout() self.plot_select = PlotSelect(self) self.plot_select.measure_dir.currentTextChanged.connect( self.update_plot) self.plot_select.plot_param.currentTextChanged.connect( self.update_plot) right_layout.addWidget(self.plot_select) self.viz_tab = VizTabs(self) right_layout.addWidget(self.viz_tab) right.setLayout(right_layout) self.splitter.addWidget(right) self.splitter.setStretchFactor(0, 1) self.splitter.setStretchFactor(1, 5)
def setup_gui(self): """Setup the main layout of the widget.""" layout = QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addWidget(self.setup_scrollarea())
def __init__(self, type_, error='', title='', text='', learn_more=None): """Base message box dialog.""" super(MessageBox, self).__init__() from anaconda_navigator.utils.analytics import GATracker self.tracker = GATracker() self.label_text = QLabel(to_text_string(text)) self.textbox_error = QTextEdit() self.button_ok = ButtonPrimary('Ok') self.button_yes = ButtonPrimary('Yes') self.button_no = ButtonNormal('No') self.button_copy = ButtonNormal('Copy text') self.button_learn = ButtonNormal('Learn more') self.button_remove = ButtonDanger('Remove') self.button_cancel = ButtonNormal('Cancel') self.button_send = ButtonNormal('Report Issue', parent=self) self.label_text.setOpenExternalLinks(False) self.label_text.setWordWrap(True) self.label_text.linkActivated.connect(self.url_clicked) self.textbox_error.setReadOnly(True) self.textbox_error.setFrameStyle(QTextEdit.Plain) self.textbox_error.setFrameShape(QTextEdit.NoFrame) self.setMinimumWidth(260) self.textbox_error.verticalScrollBar().show() self.setWindowTitle(to_text_string(title)) error = to_text_string(error).split('\n') error = '<br>'.join(error) self.textbox_error.setText(error) # Layouts layout = QVBoxLayout() layout.addWidget(self.label_text) layout.addWidget(SpacerVertical()) if error: layout.addWidget(self.textbox_error) layout.addWidget(SpacerVertical()) layout.addWidget(self.button_copy) layout.addWidget(SpacerVertical()) layout.addWidget(SpacerVertical()) layout_buttons = QHBoxLayout() layout_buttons.addStretch() layout.addLayout(layout_buttons) self.layout = layout self.setLayout(layout) # Signals self.button_copy.clicked.connect(self.copy_text) self.button_ok.clicked.connect(self.accept) self.button_yes.clicked.connect(self.accept) self.button_no.clicked.connect(self.reject) self.button_remove.clicked.connect(self.accept) self.button_cancel.clicked.connect(self.reject) self.button_send.clicked.connect(self.send) # Setup self.button_learn.setVisible(bool(learn_more)) if bool(learn_more): layout_buttons.addWidget(self.button_learn) layout_buttons.addWidget(SpacerHorizontal()) self.button_learn.clicked.connect( lambda: self.show_url(learn_more)) if type_ == self.ERROR_BOX: layout_buttons.addWidget(self.button_send) layout_buttons.addWidget(SpacerHorizontal()) layout_buttons.addWidget(self.button_ok) self.button_yes.setVisible(False) self.button_no.setVisible(False) self.button_remove.setVisible(False) self.button_cancel.setVisible(False) elif type_ == self.INFORMATION_BOX: layout_buttons.addWidget(self.button_ok) self.button_yes.setVisible(False) self.button_no.setVisible(False) self.textbox_error.setVisible(False) self.button_copy.setVisible(False) self.button_remove.setVisible(False) self.button_cancel.setVisible(False) elif type_ == self.QUESTION_BOX: layout_buttons.addStretch() layout_buttons.addWidget(self.button_no) layout_buttons.addWidget(SpacerHorizontal()) layout_buttons.addWidget(self.button_yes) layout_buttons.addWidget(SpacerHorizontal()) self.textbox_error.setVisible(False) self.button_ok.setVisible(False) self.button_copy.setVisible(False) self.button_remove.setVisible(False) self.button_cancel.setVisible(False) elif type_ == self.REMOVE_BOX: layout_buttons.addStretch() layout_buttons.addWidget(self.button_cancel) layout_buttons.addWidget(SpacerHorizontal()) layout_buttons.addWidget(self.button_remove) layout_buttons.addWidget(SpacerHorizontal()) self.textbox_error.setVisible(False) self.button_ok.setVisible(False) self.button_copy.setVisible(False) self.button_yes.setVisible(False) self.button_no.setVisible(False) self.button_send.setVisible(False) self.layout_buttons = layout_buttons
def __init__(self, settings: PartSettings, parent=None): super().__init__(parent) self.chosen_element: Optional[MeasurementListWidgetItem] = None self.chosen_element_area: Optional[Tuple[AreaType, float]] = None self.settings = settings self.profile_list = QListWidget(self) self.profile_description = QTextEdit(self) self.profile_description.setReadOnly(True) self.profile_options = QListWidget() self.profile_options_chosen = QListWidget() self.measurement_area_choose = EnumComboBox(AreaType) self.per_component = EnumComboBox(PerComponent) self.power_num = QDoubleSpinBox() self.power_num.setDecimals(3) self.power_num.setRange(-100, 100) self.power_num.setValue(1) self.choose_butt = QPushButton("→", self) self.discard_butt = QPushButton("←", self) self.proportion_butt = QPushButton("Ratio", self) self.proportion_butt.setToolTip("Create proportion from two parameter") self.move_up = QPushButton("↑", self) self.move_down = QPushButton("↓", self) self.remove_button = QPushButton("Remove") self.save_butt = QPushButton("Save") self.save_butt.setToolTip( "Set name for set and choose at least one parameter") self.save_butt_with_name = QPushButton( "Save with custom parameters designation") self.save_butt_with_name.setToolTip( "Set name for set and choose at least one parameter") self.reset_butt = QPushButton("Clear") self.soft_reset_butt = QPushButton("Remove user parameters") self.profile_name = QLineEdit(self) self.delete_profile_butt = QPushButton("Delete ") self.export_profiles_butt = QPushButton("Export") self.import_profiles_butt = QPushButton("Import") self.edit_profile_butt = QPushButton("Edit") self.choose_butt.setDisabled(True) self.choose_butt.clicked.connect(self.choose_option) self.discard_butt.setDisabled(True) self.discard_butt.clicked.connect(self.discard_option) self.proportion_butt.setDisabled(True) self.proportion_butt.clicked.connect(self.proportion_action) self.save_butt.setDisabled(True) self.save_butt.clicked.connect(self.save_action) self.save_butt_with_name.setDisabled(True) self.save_butt_with_name.clicked.connect(self.named_save_action) self.profile_name.textChanged.connect(self.name_changed) self.move_down.setDisabled(True) self.move_down.clicked.connect(self.move_down_fun) self.move_up.setDisabled(True) self.move_up.clicked.connect(self.move_up_fun) self.remove_button.setDisabled(True) self.remove_button.clicked.connect(self.remove_element) self.reset_butt.clicked.connect(self.reset_action) self.soft_reset_butt.clicked.connect(self.soft_reset) self.delete_profile_butt.setDisabled(True) self.delete_profile_butt.clicked.connect(self.delete_profile) self.export_profiles_butt.clicked.connect( self.export_measurement_profiles) self.import_profiles_butt.clicked.connect( self.import_measurement_profiles) self.edit_profile_butt.clicked.connect(self.edit_profile) self.profile_list.itemSelectionChanged.connect(self.profile_chosen) self.profile_options.itemSelectionChanged.connect( self.create_selection_changed) self.profile_options_chosen.itemSelectionChanged.connect( self.create_selection_chosen_changed) layout = QVBoxLayout() layout.addWidget(QLabel("Measurement set:")) profile_layout = QHBoxLayout() profile_layout.addWidget(self.profile_list) profile_layout.addWidget(self.profile_description) profile_buttons_layout = QHBoxLayout() profile_buttons_layout.addWidget(self.delete_profile_butt) profile_buttons_layout.addWidget(self.export_profiles_butt) profile_buttons_layout.addWidget(self.import_profiles_butt) profile_buttons_layout.addWidget(self.edit_profile_butt) profile_buttons_layout.addStretch() layout.addLayout(profile_layout) layout.addLayout(profile_buttons_layout) heading_layout = QHBoxLayout() # heading_layout.addWidget(QLabel("Create profile"), 1) heading_layout.addWidget(h_line(), 6) layout.addLayout(heading_layout) name_layout = QHBoxLayout() name_layout.addWidget(QLabel("Set name:")) name_layout.addWidget(self.profile_name) name_layout.addStretch() name_layout.addWidget(QLabel("Per component:")) name_layout.addWidget(self.per_component) name_layout.addWidget(QLabel("Area:")) name_layout.addWidget(self.measurement_area_choose) name_layout.addWidget(QLabel("to power:")) name_layout.addWidget(self.power_num) layout.addLayout(name_layout) create_layout = QHBoxLayout() create_layout.addWidget(self.profile_options) butt_op_layout = QVBoxLayout() butt_op_layout.addStretch() butt_op_layout.addWidget(self.choose_butt) butt_op_layout.addWidget(self.discard_butt) butt_op_layout.addWidget(self.proportion_butt) butt_op_layout.addWidget(self.reset_butt) butt_op_layout.addStretch() create_layout.addLayout(butt_op_layout) create_layout.addWidget(self.profile_options_chosen) butt_move_layout = QVBoxLayout() butt_move_layout.addStretch() butt_move_layout.addWidget(self.move_up) butt_move_layout.addWidget(self.move_down) butt_move_layout.addWidget(self.remove_button) butt_move_layout.addStretch() create_layout.addLayout(butt_move_layout) layout.addLayout(create_layout) save_butt_layout = QHBoxLayout() save_butt_layout.addWidget(self.soft_reset_butt) save_butt_layout.addStretch() save_butt_layout.addWidget(self.save_butt) save_butt_layout.addWidget(self.save_butt_with_name) layout.addLayout(save_butt_layout) self.setLayout(layout) for profile in MEASUREMENT_DICT.values(): help_text = profile.get_description() lw = MeasurementListWidgetItem(profile.get_starting_leaf()) lw.setToolTip(help_text) self.profile_options.addItem(lw) self.profile_list.addItems( list(sorted(self.settings.measurement_profiles.keys()))) if self.profile_list.count() == 0: self.export_profiles_butt.setDisabled(True)
def __init__(self, presenter, parent=None, name='', isMD=False, noExp=0): super(SampleLogsView, self).__init__(parent) self.presenter = presenter self.setWindowTitle("{} sample logs".format(name)) self.setWindowFlags(Qt.Window) self.setAttribute(Qt.WA_DeleteOnClose, True) # Create sample log table self.table = QTableView() self.table.setSelectionBehavior(QAbstractItemView.SelectRows) self.table.clicked.connect(self.presenter.clicked) self.table.doubleClicked.connect(self.presenter.doubleClicked) self.table.contextMenuEvent = self.tableMenu self.addWidget(self.table) frame_right = QFrame() layout_right = QVBoxLayout() #Add full_time and experimentinfo options layout_options = QHBoxLayout() if isMD: layout_options.addWidget(QLabel("Experiment Info #")) self.experimentInfo = QSpinBox() self.experimentInfo.setMaximum(noExp - 1) self.experimentInfo.valueChanged.connect( self.presenter.changeExpInfo) layout_options.addWidget(self.experimentInfo) self.full_time = QCheckBox("Relative Time") self.full_time.setChecked(True) self.full_time.stateChanged.connect(self.presenter.plot_logs) layout_options.addWidget(self.full_time) layout_right.addLayout(layout_options) # Sample log plot self.fig = Figure() self.canvas = FigureCanvas(self.fig) self.canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.canvas.mpl_connect('button_press_event', self.presenter.plot_clicked) self.ax = self.fig.add_subplot(111, projection='mantid') layout_right.addWidget(self.canvas) # Sample stats self.create_stats_widgets() layout_stats = QFormLayout() layout_stats.addRow('', QLabel("Log Statistics")) layout_stats.addRow('Min:', self.stats_widgets["minimum"]) layout_stats.addRow('Max:', self.stats_widgets["maximum"]) layout_stats.addRow('Time Avg:', self.stats_widgets["time_mean"]) layout_stats.addRow('Time Std Dev:', self.stats_widgets["time_standard_deviation"]) layout_stats.addRow('Mean (unweighted):', self.stats_widgets["mean"]) layout_stats.addRow('Median (unweighted):', self.stats_widgets["median"]) layout_stats.addRow('Std Dev:', self.stats_widgets["standard_deviation"]) layout_stats.addRow('Duration:', self.stats_widgets["duration"]) layout_right.addLayout(layout_stats) frame_right.setLayout(layout_right) self.addWidget(frame_right) self.setStretchFactor(0, 1) self.resize(1200, 800) self.show()
def __init__(self, text, help_text, objects_list=None): if objects_list is None: objects_list = help_text help_text = "" def create_input_float(obj, ob2=None): if ob2 is not None: val = obj obj = ob2 else: val = 0 res = QDoubleSpinBox(obj) res.setRange(-1000000, 1000000) res.setValue(val) return res def create_input_int(obj, ob2=None): if ob2 is not None: val = obj obj = ob2 else: val = 0 res = QSpinBox(obj) res.setRange(-1000000, 1000000) res.setValue(val) return res field_dict = { str: QLineEdit, float: create_input_float, int: create_input_int } QDialog.__init__(self) ok_butt = QPushButton("Ok", self) cancel_butt = QPushButton("Cancel", self) self.object_dict = {} self.result = None ok_butt.clicked.connect(self.accept_response) cancel_butt.clicked.connect(self.close) layout = QGridLayout() layout.setAlignment(Qt.AlignVCenter) for i, info in enumerate(objects_list): name = info[0] type_of = info[1] name_label = QLabel(name) name_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter) layout.addWidget(name_label, i, 0) if len(info) == 3: item = field_dict[type_of](type_of(info[2]), self) else: item = field_dict[type_of](self) self.object_dict[name] = (type_of, item) layout.addWidget(item, i, 1) main_layout = QVBoxLayout() main_text = QLabel(text) main_text.setWordWrap(True) font = QApplication.font() font.setBold(True) main_text.setFont(font) main_layout.addWidget(main_text) if help_text != "": help_label = QLabel(help_text) help_label.setWordWrap(True) main_layout.addWidget(help_label) main_layout.addLayout(layout) button_layout = QHBoxLayout() button_layout.addWidget(cancel_butt) button_layout.addStretch() button_layout.addWidget(ok_butt) main_layout.addLayout(button_layout) self.setLayout(main_layout)
def __init__(self, presenter, dims_info, can_normalise, parent=None, conf=None): super().__init__(parent) self.presenter = presenter self.image = None self.line_plots_active = False self.can_normalise = can_normalise self.nonortho_transform = None self.ws_type = dims_info[0]['type'] self.conf = conf self._line_plots = None self._image_info_tracker = None # Dimension widget self.dimensions_layout = QGridLayout() self.dimensions = DimensionWidget(dims_info, parent=self) self.dimensions.dimensionsChanged.connect( self.presenter.dimensions_changed) self.dimensions.valueChanged.connect(self.presenter.slicepoint_changed) self.dimensions_layout.addWidget(self.dimensions, 1, 0, 1, 1) self.colorbar_layout = QVBoxLayout() self.colorbar_layout.setContentsMargins(0, 0, 0, 0) self.colorbar_layout.setSpacing(0) self.image_info_widget = ImageInfoWidget(self) self.track_cursor = QCheckBox("Track Cursor", self) self.track_cursor.setToolTip( "Update the image readout table when the cursor is over the plot. " "If unticked the table will update only when the plot is clicked") if self.ws_type == 'MDE': self.colorbar_layout.addWidget(self.image_info_widget, alignment=Qt.AlignCenter) self.colorbar_layout.addWidget(self.track_cursor) else: self.dimensions_layout.setHorizontalSpacing(10) self.dimensions_layout.addWidget(self.track_cursor, 0, 1, Qt.AlignRight) self.dimensions_layout.addWidget(self.image_info_widget, 1, 1) self.track_cursor.setChecked(True) self.track_cursor.stateChanged.connect( self.on_track_cursor_state_change) # normalization options if can_normalise: self.norm_label = QLabel("Normalization") self.colorbar_layout.addWidget(self.norm_label) self.norm_opts = QComboBox() self.norm_opts.addItems(["None", "By bin width"]) self.norm_opts.setToolTip("Normalization options") self.colorbar_layout.addWidget(self.norm_opts) # MPL figure + colorbar self.fig = Figure() self.ax = None self.image = None self._grid_on = False self.fig.set_facecolor(self.palette().window().color().getRgbF()) self.canvas = SliceViewerCanvas(self.fig) self.canvas.mpl_connect('button_release_event', self.mouse_release) self.colorbar_label = QLabel("Colormap") self.colorbar_layout.addWidget(self.colorbar_label) norm_scale = self.get_default_scale_norm() self.colorbar = ColorbarWidget(self, norm_scale) self.colorbar_layout.addWidget(self.colorbar) self.colorbar.colorbarChanged.connect(self.update_data_clim) self.colorbar.scaleNormChanged.connect(self.scale_norm_changed) # make width larger to fit image readout table if self.ws_type == 'MDE': self.colorbar.setMaximumWidth(155) # MPL toolbar self.toolbar_layout = QHBoxLayout() self.mpl_toolbar = SliceViewerNavigationToolbar( self.canvas, self, False) self.mpl_toolbar.gridClicked.connect(self.toggle_grid) self.mpl_toolbar.linePlotsClicked.connect(self.on_line_plots_toggle) self.mpl_toolbar.regionSelectionClicked.connect( self.on_region_selection_toggle) self.mpl_toolbar.homeClicked.connect(self.on_home_clicked) self.mpl_toolbar.nonOrthogonalClicked.connect( self.on_non_orthogonal_axes_toggle) self.mpl_toolbar.zoomPanFinished.connect(self.on_data_limits_changed) self.toolbar_layout.addWidget(self.mpl_toolbar) # Status bar self.status_bar = QStatusBar(parent=self) self.status_bar_label = QLabel() self.status_bar.addWidget(self.status_bar_label) # layout layout = QGridLayout(self) layout.setSpacing(1) layout.addLayout(self.dimensions_layout, 0, 0, 1, 2) layout.addLayout(self.toolbar_layout, 1, 0, 1, 1) layout.addLayout(self.colorbar_layout, 1, 1, 3, 1) layout.addWidget(self.canvas, 2, 0, 1, 1) layout.addWidget(self.status_bar, 3, 0, 1, 1) layout.setRowStretch(2, 1)
def __init__(self, parent): """Project creation dialog.""" super(ProjectDialog, self).__init__(parent=parent) # Variables current_python_version = '.'.join([ to_text_string(sys.version_info[0]), to_text_string(sys.version_info[1]) ]) python_versions = ['2.7', '3.4', '3.5'] if current_python_version not in python_versions: python_versions.append(current_python_version) python_versions = sorted(python_versions) self.project_name = None self.location = get_home_dir() # Widgets self.groupbox = QGroupBox() self.radio_new_dir = QRadioButton(_("New directory")) self.radio_from_dir = QRadioButton(_("Existing directory")) self.label_project_name = QLabel(_('Project name')) self.label_location = QLabel(_('Location')) self.label_project_type = QLabel(_('Project type')) self.label_python_version = QLabel(_('Python version')) self.text_project_name = QLineEdit() self.text_location = QLineEdit(get_home_dir()) self.combo_project_type = QComboBox() self.combo_python_version = QComboBox() self.button_select_location = QToolButton() self.button_cancel = QPushButton(_('Cancel')) self.button_create = QPushButton(_('Create')) self.bbox = QDialogButtonBox(Qt.Horizontal) self.bbox.addButton(self.button_cancel, QDialogButtonBox.ActionRole) self.bbox.addButton(self.button_create, QDialogButtonBox.ActionRole) # Widget setup self.combo_python_version.addItems(python_versions) self.radio_new_dir.setChecked(True) self.text_location.setEnabled(True) self.text_location.setReadOnly(True) self.button_select_location.setIcon(get_std_icon('DirOpenIcon')) self.button_cancel.setDefault(True) self.button_cancel.setAutoDefault(True) self.button_create.setEnabled(False) self.combo_project_type.addItems(self._get_project_types()) self.combo_python_version.setCurrentIndex( python_versions.index(current_python_version)) self.setWindowTitle(_('Create new project')) self.setFixedWidth(500) self.label_python_version.setVisible(False) self.combo_python_version.setVisible(False) # Layouts layout_top = QHBoxLayout() layout_top.addWidget(self.radio_new_dir) layout_top.addWidget(self.radio_from_dir) layout_top.addStretch(1) self.groupbox.setLayout(layout_top) layout_grid = QGridLayout() layout_grid.addWidget(self.label_project_name, 0, 0) layout_grid.addWidget(self.text_project_name, 0, 1, 1, 2) layout_grid.addWidget(self.label_location, 1, 0) layout_grid.addWidget(self.text_location, 1, 1) layout_grid.addWidget(self.button_select_location, 1, 2) layout_grid.addWidget(self.label_project_type, 2, 0) layout_grid.addWidget(self.combo_project_type, 2, 1, 1, 2) layout_grid.addWidget(self.label_python_version, 3, 0) layout_grid.addWidget(self.combo_python_version, 3, 1, 1, 2) layout = QVBoxLayout() layout.addWidget(self.groupbox) layout.addSpacing(10) layout.addLayout(layout_grid) layout.addStretch() layout.addSpacing(20) layout.addWidget(self.bbox) self.setLayout(layout) # Signals and slots self.button_select_location.clicked.connect(self.select_location) self.button_create.clicked.connect(self.create_project) self.button_cancel.clicked.connect(self.close) self.radio_from_dir.clicked.connect(self.update_location) self.radio_new_dir.clicked.connect(self.update_location) self.text_project_name.textChanged.connect(self.update_location)
def setup_page(self): newcb = self.create_checkbox # --- Display tab --- showtabbar_box = newcb(_("Show tab bar"), 'show_tab_bar') showclassfuncdropdown_box = newcb( _("Show selector for classes and functions"), 'show_class_func_dropdown') showindentguides_box = newcb(_("Show indent guides"), 'indent_guides') linenumbers_box = newcb(_("Show line numbers"), 'line_numbers') blanks_box = newcb(_("Show blank spaces"), 'blank_spaces') underline_errors_box = newcb(_("Underline errors and warnings"), 'underline_errors') currentline_box = newcb(_("Highlight current line"), 'highlight_current_line') currentcell_box = newcb(_("Highlight current cell"), 'highlight_current_cell') wrap_mode_box = newcb(_("Wrap lines"), 'wrap') scroll_past_end_box = newcb(_("Scroll past the end"), 'scroll_past_end') edgeline_box = newcb(_("Show vertical lines at"), 'edge_line') edgeline_edit = self.create_lineedit( "", 'edge_line_columns', tip=("Enter values separated by commas"), alignment=Qt.Horizontal, regex="[0-9]+(,[0-9]+)*") edgeline_edit_label = QLabel(_("characters")) edgeline_box.toggled.connect(edgeline_edit.setEnabled) edgeline_box.toggled.connect(edgeline_edit_label.setEnabled) edgeline_edit.setEnabled(self.get_option('edge_line')) edgeline_edit_label.setEnabled(self.get_option('edge_line')) occurrence_box = newcb(_("Highlight occurrences after"), 'occurrence_highlighting') occurrence_spin = self.create_spinbox( "", _(" ms"), 'occurrence_highlighting/timeout', min_=100, max_=1000000, step=100) occurrence_box.toggled.connect(occurrence_spin.spinbox.setEnabled) occurrence_box.toggled.connect(occurrence_spin.slabel.setEnabled) occurrence_spin.spinbox.setEnabled( self.get_option('occurrence_highlighting')) occurrence_spin.slabel.setEnabled( self.get_option('occurrence_highlighting')) display_g_layout = QGridLayout() display_g_layout.addWidget(edgeline_box, 0, 0) display_g_layout.addWidget(edgeline_edit.textbox, 0, 1) display_g_layout.addWidget(edgeline_edit_label, 0, 2) display_g_layout.addWidget(occurrence_box, 1, 0) display_g_layout.addWidget(occurrence_spin.spinbox, 1, 1) display_g_layout.addWidget(occurrence_spin.slabel, 1, 2) display_h_layout = QHBoxLayout() display_h_layout.addLayout(display_g_layout) display_h_layout.addStretch(1) display_layout = QVBoxLayout() display_layout.addWidget(showtabbar_box) display_layout.addWidget(showclassfuncdropdown_box) display_layout.addWidget(showindentguides_box) display_layout.addWidget(linenumbers_box) display_layout.addWidget(blanks_box) display_layout.addWidget(underline_errors_box) display_layout.addWidget(currentline_box) display_layout.addWidget(currentcell_box) display_layout.addWidget(wrap_mode_box) display_layout.addWidget(scroll_past_end_box) display_layout.addLayout(display_h_layout) display_widget = QWidget() display_widget.setLayout(display_layout) # --- Source code tab --- closepar_box = newcb( _("Automatic insertion of parentheses, braces and brackets"), 'close_parentheses') close_quotes_box = newcb(_("Automatic insertion of closing quotes"), 'close_quotes') add_colons_box = newcb( _("Automatic insertion of colons after 'for', 'if', 'def', etc"), 'add_colons') autounindent_box = newcb( _("Automatic indentation after 'else', 'elif', etc."), 'auto_unindent') tab_mode_box = newcb( _("Tab always indent"), 'tab_always_indent', default=False, tip=_("If enabled, pressing Tab will always indent,\n" "even when the cursor is not at the beginning\n" "of a line (when this option is enabled, code\n" "completion may be triggered using the alternate\n" "shortcut: Ctrl+Space)")) strip_mode_box = newcb( _("Automatically strip trailing spaces on changed lines"), 'strip_trailing_spaces_on_modify', default=True, tip= _("If enabled, modified lines of code (excluding strings)\n" "will have their trailing whitespace stripped when leaving them.\n" "If disabled, only whitespace added by Spyder will be stripped." )) ibackspace_box = newcb(_("Intelligent backspace"), 'intelligent_backspace', default=True) removetrail_box = newcb( _("Automatically remove trailing spaces when saving files"), 'always_remove_trailing_spaces', default=False) indent_chars_box = self.create_combobox( _("Indentation characters: "), ((_("2 spaces"), '* *'), (_("3 spaces"), '* *'), (_("4 spaces"), '* *'), (_("5 spaces"), '* *'), (_("6 spaces"), '* *'), (_("7 spaces"), '* *'), (_("8 spaces"), '* *'), (_("Tabulations"), '*\t*')), 'indent_chars') tabwidth_spin = self.create_spinbox(_("Tab stop width:"), _("spaces"), 'tab_stop_width_spaces', 4, 1, 8, 1) def enable_tabwidth_spin(index): if index == 7: # Tabulations tabwidth_spin.plabel.setEnabled(True) tabwidth_spin.spinbox.setEnabled(True) else: tabwidth_spin.plabel.setEnabled(False) tabwidth_spin.spinbox.setEnabled(False) indent_chars_box.combobox.currentIndexChanged.connect( enable_tabwidth_spin) indent_tab_grid_layout = QGridLayout() indent_tab_grid_layout.addWidget(indent_chars_box.label, 0, 0) indent_tab_grid_layout.addWidget(indent_chars_box.combobox, 0, 1) indent_tab_grid_layout.addWidget(tabwidth_spin.plabel, 1, 0) indent_tab_grid_layout.addWidget(tabwidth_spin.spinbox, 1, 1) indent_tab_grid_layout.addWidget(tabwidth_spin.slabel, 1, 2) indent_tab_layout = QHBoxLayout() indent_tab_layout.addLayout(indent_tab_grid_layout) indent_tab_layout.addStretch(1) sourcecode_layout = QVBoxLayout() sourcecode_layout.addWidget(closepar_box) sourcecode_layout.addWidget(autounindent_box) sourcecode_layout.addWidget(add_colons_box) sourcecode_layout.addWidget(close_quotes_box) sourcecode_layout.addWidget(tab_mode_box) sourcecode_layout.addWidget(ibackspace_box) sourcecode_layout.addWidget(removetrail_box) sourcecode_layout.addWidget(strip_mode_box) sourcecode_layout.addLayout(indent_tab_layout) sourcecode_widget = QWidget() sourcecode_widget.setLayout(sourcecode_layout) # --- Run code tab --- saveall_box = newcb(_("Save all files before running script"), 'save_all_before_run') focus_box = newcb( _("Maintain focus in the Editor after running cells " "or selections"), 'focus_to_editor') run_cell_box = newcb( _("Copy full cell contents to the console when " "running code cells"), 'run_cell_copy') run_layout = QVBoxLayout() run_layout.addWidget(saveall_box) run_layout.addWidget(focus_box) run_layout.addWidget(run_cell_box) run_widget = QWidget() run_widget.setLayout(run_layout) # --- Advanced tab --- # -- Templates template_btn = self.create_button(_("Edit template for new files"), self.plugin.edit_template) # -- Autosave autosave_group = QGroupBox(_('Autosave')) autosave_checkbox = newcb( _('Automatically save a copy of files with unsaved changes'), 'autosave_enabled') autosave_spinbox = self.create_spinbox(_('Autosave interval: '), _('seconds'), 'autosave_interval', min_=1, max_=3600) autosave_checkbox.toggled.connect(autosave_spinbox.setEnabled) autosave_layout = QVBoxLayout() autosave_layout.addWidget(autosave_checkbox) autosave_layout.addWidget(autosave_spinbox) autosave_group.setLayout(autosave_layout) # -- Docstring docstring_group = QGroupBox(_('Docstring type')) numpy_url = "<a href='{}'>Numpy</a>".format(NUMPYDOC) googledoc_url = "<a href='{}'>Google</a>".format(GOOGLEDOC) docstring_label = QLabel( _("Here you can select the type of docstrings ({} or {}) you " "want the editor to automatically introduce when pressing " "<tt>{}</tt> after a function/method/class " "declaration.").format(numpy_url, googledoc_url, DOCSTRING_SHORTCUT)) docstring_label.setOpenExternalLinks(True) docstring_label.setWordWrap(True) docstring_combo_choices = ( (_("Numpy"), 'Numpydoc'), (_("Google"), 'Googledoc'), ) docstring_combo = self.create_combobox("Type:", docstring_combo_choices, 'docstring_type') docstring_layout = QVBoxLayout() docstring_layout.addWidget(docstring_label) docstring_layout.addWidget(docstring_combo) docstring_group.setLayout(docstring_layout) # -- Annotations annotations_group = QGroupBox(_("Annotations")) annotations_label = QLabel( _("Display a marker to the left of line numbers when the " "following annotations appear at the beginning of a comment: " "<tt>TODO, FIXME, XXX, HINT, TIP, @todo, HACK, BUG, OPTIMIZE, " "!!!, ???</tt>")) annotations_label.setWordWrap(True) todolist_box = newcb(_("Display code annotations"), 'todo_list') annotations_layout = QVBoxLayout() annotations_layout.addWidget(annotations_label) annotations_layout.addWidget(todolist_box) annotations_group.setLayout(annotations_layout) # -- EOL eol_group = QGroupBox(_("End-of-line characters")) eol_label = QLabel( _("When opening a text file containing " "mixed end-of-line characters (this may " "raise syntax errors in the consoles " "on Windows platforms), Spyder may fix the " "file automatically.")) eol_label.setWordWrap(True) check_eol_box = newcb(_("Fix automatically and show warning " "message box"), 'check_eol_chars', default=True) convert_eol_on_save_box = newcb(_("On Save: convert EOL characters" " to"), 'convert_eol_on_save', default=False) eol_combo_choices = ( (_("LF (UNIX)"), 'LF'), (_("CRLF (Windows)"), 'CRLF'), (_("CR (Mac)"), 'CR'), ) convert_eol_on_save_combo = self.create_combobox( "", eol_combo_choices, ('convert_eol_on_' 'save_to'), ) convert_eol_on_save_box.toggled.connect( convert_eol_on_save_combo.setEnabled) convert_eol_on_save_combo.setEnabled( self.get_option('convert_eol_on_save')) eol_on_save_layout = QHBoxLayout() eol_on_save_layout.addWidget(convert_eol_on_save_box) eol_on_save_layout.addWidget(convert_eol_on_save_combo) eol_layout = QVBoxLayout() eol_layout.addWidget(eol_label) eol_layout.addWidget(check_eol_box) eol_layout.addLayout(eol_on_save_layout) eol_group.setLayout(eol_layout) # --- Tabs --- tabs = QTabWidget() tabs.addTab(self.create_tab(display_widget), _("Display")) tabs.addTab(self.create_tab(sourcecode_widget), _("Source code")) tabs.addTab(self.create_tab(run_widget), _('Run Code')) tabs.addTab( self.create_tab(template_btn, autosave_group, docstring_group, annotations_group, eol_group), _("Advanced settings")) vlayout = QVBoxLayout() vlayout.addWidget(tabs) self.setLayout(vlayout)
def __init__(self, parent, opacity, duration, easing_curve): super(FadingTipBox, self).__init__(parent, opacity, duration, easing_curve) self.holder = self.anim # needed for qt to work self.parent = parent self.frames = None self.color_top = QColor.fromRgb(230, 230, 230) self.color_back = QColor.fromRgb(255, 255, 255) self.offset_shadow = 0 self.fixed_width = 300 self.key_pressed = None self.setAttribute(Qt.WA_TranslucentBackground) self.setWindowFlags(Qt.Dialog | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) self.setModal(False) # Widgets self.button_home = QPushButton("<<") self.button_close = QPushButton("X") self.button_previous = QPushButton(" < ") self.button_end = QPushButton(">>") self.button_next = QPushButton(" > ") self.button_run = QPushButton(_('Run code')) self.button_disable = None self.button_current = QToolButton() self.label_image = QLabel() self.label_title = QLabel() self.combo_title = QComboBox() self.label_current = QLabel() self.label_content = QLabel() self.label_content.setMinimumWidth(self.fixed_width) self.label_content.setMaximumWidth(self.fixed_width) self.label_current.setAlignment(Qt.AlignCenter) self.label_content.setWordWrap(True) self.widgets = [ self.label_content, self.label_title, self.label_current, self.combo_title, self.button_close, self.button_run, self.button_next, self.button_previous, self.button_end, self.button_home, self.button_current ] arrow = get_image_path('hide.png') self.stylesheet = '''QPushButton { background-color: rgbs(200,200,200,100%); color: rgbs(0,0,0,100%); border-style: outset; border-width: 1px; border-radius: 3px; border-color: rgbs(100,100,100,100%); padding: 2px; } QPushButton:hover { background-color: rgbs(150, 150, 150, 100%); } QPushButton:disabled { background-color: rgbs(230,230,230,100%); color: rgbs(200,200,200,100%); border-color: rgbs(200,200,200,100%); } QComboBox { padding-left: 5px; background-color: rgbs(230,230,230,100%); border-width: 0px; border-radius: 0px; min-height:20px; max-height:20px; } QComboBox::drop-down { subcontrol-origin: padding; subcontrol-position: top left; border-width: 0px; } QComboBox::down-arrow { image: url(''' + arrow + '''); } ''' # Windows fix, slashes should be always in unix-style self.stylesheet = self.stylesheet.replace('\\', '/') for widget in self.widgets: widget.setFocusPolicy(Qt.NoFocus) widget.setStyleSheet(self.stylesheet) layout_top = QHBoxLayout() layout_top.addWidget(self.combo_title) layout_top.addStretch() layout_top.addWidget(self.button_close) layout_top.addSpacerItem( QSpacerItem(self.offset_shadow, self.offset_shadow)) layout_content = QHBoxLayout() layout_content.addWidget(self.label_content) layout_content.addWidget(self.label_image) layout_content.addSpacerItem(QSpacerItem(5, 5)) layout_run = QHBoxLayout() layout_run.addStretch() layout_run.addWidget(self.button_run) layout_run.addStretch() layout_run.addSpacerItem( QSpacerItem(self.offset_shadow, self.offset_shadow)) layout_navigation = QHBoxLayout() layout_navigation.addWidget(self.button_home) layout_navigation.addWidget(self.button_previous) layout_navigation.addStretch() layout_navigation.addWidget(self.label_current) layout_navigation.addStretch() layout_navigation.addWidget(self.button_next) layout_navigation.addWidget(self.button_end) layout_navigation.addSpacerItem( QSpacerItem(self.offset_shadow, self.offset_shadow)) layout = QVBoxLayout() layout.addLayout(layout_top) layout.addStretch() layout.addSpacerItem(QSpacerItem(15, 15)) layout.addLayout(layout_content) layout.addLayout(layout_run) layout.addStretch() layout.addSpacerItem(QSpacerItem(15, 15)) layout.addLayout(layout_navigation) layout.addSpacerItem( QSpacerItem(self.offset_shadow, self.offset_shadow)) layout.setSizeConstraint(QLayout.SetFixedSize) self.setLayout(layout) self.set_funcs_before_fade_in([self._disable_widgets]) self.set_funcs_after_fade_in([self._enable_widgets]) self.set_funcs_before_fade_out([self._disable_widgets]) self.setContextMenuPolicy(Qt.CustomContextMenu)
def __init__(self, parent): super(MultiFileEditor, self).__init__(parent) # layout self.editors = MultiPythonFileInterpreter( default_content=DEFAULT_CONTENT, parent=self) layout = QVBoxLayout() layout.addWidget(self.editors) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) self.setAcceptDrops(True) # attributes self.tabs_open_on_closing = None self.run_action = create_action( self, "Run", on_triggered=self.editors.execute_current, shortcut=("Ctrl+Return", "Ctrl+Enter"), shortcut_context=Qt.ApplicationShortcut) self.abort_action = create_action( self, "Abort", on_triggered=self.editors.abort_current) # menu action to toggle the find/replace dialog self.toggle_find_replace = create_action( self, 'Find/Replace...', on_triggered=self.editors.toggle_find_replace_dialog, shortcut='Ctrl+F') self.toggle_comment_action = create_action( self.editors.current_editor(), "Comment/Uncomment", on_triggered=self.editors.toggle_comment_current, shortcut="Ctrl+/", shortcut_context=Qt.ApplicationShortcut) self.tabs_to_spaces_action = create_action( self, 'Tabs to Spaces', on_triggered=self.editors.tabs_to_spaces_current) self.spaces_to_tabs_action = create_action( self, 'Spaces to Tabs', on_triggered=self.editors.spaces_to_tabs_current) self.toggle_whitespace_action = create_action( self, 'Toggle Whitespace Visible', on_triggered=self.editors.toggle_whitespace_visible_all) # Store actions for adding to menu bar; None will add a separator self.editor_actions = [ self.run_action, self.abort_action, None, self.toggle_find_replace, None, self.toggle_comment_action, self.toggle_whitespace_action, None, self.tabs_to_spaces_action, self.spaces_to_tabs_action, None ]