def __init__(self, master: Union[QWidget, None], settings: Dict[str, Dict[str, SettingsType]]): super().__init__(master, windowTitle="Visual Settings") self.__controls: Dict[KeyType, Tuple[QWidget, ValueType]] = {} self.__changed_settings: Dict[KeyType, ValueType] = {} self.setting_changed.connect(self.__on_setting_changed) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) self.main_box = gui.vBox(self, box=None) # type: QWidget buttons = QDialogButtonBox( orientation=Qt.Horizontal, standardButtons=QDialogButtonBox.Close | QDialogButtonBox.Reset, ) closeButton = buttons.button(QDialogButtonBox.Close) closeButton.clicked.connect(self.close) resetButton = buttons.button(QDialogButtonBox.Reset) resetButton.clicked.connect(self.__reset) resetButton.setAutoDefault(False) layout.addWidget(buttons) self.__initialize(settings)
def __setupUi(self): layout = QVBoxLayout() # Scene with the link editor. self.scene = LinksEditScene() self.view = QGraphicsView(self.scene) self.view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.view.setRenderHint(QPainter.Antialiasing) self.scene.editWidget.geometryChanged.connect(self.__onGeometryChanged) # Ok/Cancel/Clear All buttons. buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel | QDialogButtonBox.Reset, Qt.Horizontal) clear_button = buttons.button(QDialogButtonBox.Reset) clear_button.setText(self.tr("Clear All")) buttons.accepted.connect(self.accept) buttons.rejected.connect(self.reject) clear_button.clicked.connect(self.scene.editWidget.clearLinks) layout.addWidget(self.view) layout.addWidget(buttons) self.setLayout(layout) layout.setSizeConstraint(QVBoxLayout.SetFixedSize) self.setSizeGripEnabled(False)
def __init__(self, *args, headingText="", **kwargs): super().__init__(*args, **kwargs) self.setLayout(QVBoxLayout()) self.__top_label = QLabel(headingText, visible=bool(headingText), objectName="-top-heading-text") self.__top_label.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) self.__model = model = encodings_model() self.__model.setParent(self) self.__view = view = EncodingsView( self, uniformItemSizes=True, editTriggers=QListView.NoEditTriggers) self.__view.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred) view.setModel(model) self.layout().addWidget(self.__top_label) self.layout().addWidget(view) buttons = QDialogButtonBox( standardButtons=QDialogButtonBox.RestoreDefaults) b = buttons.addButton("Select all", QDialogButtonBox.ActionRole) b.clicked.connect(self.selectAll) b = buttons.button(QDialogButtonBox.RestoreDefaults) b.clicked.connect(self.reset) self.layout().addWidget(buttons) self.setAttribute(Qt.WA_MacSmallSize)
def __run_add_package_dialog(self): self.__add_package_by_name_dialog = dlg = QDialog( self, windowTitle="Add add-on by name", ) dlg.setAttribute(Qt.WA_DeleteOnClose) vlayout = QVBoxLayout() form = QFormLayout() form.setContentsMargins(0, 0, 0, 0) nameentry = QLineEdit(placeholderText="Package name", toolTip="Enter a package name as displayed on " "PyPI (capitalization is not important)") nameentry.setMinimumWidth(250) form.addRow("Name:", nameentry) vlayout.addLayout(form) buttons = QDialogButtonBox(standardButtons=QDialogButtonBox.Ok | QDialogButtonBox.Cancel) okb = buttons.button(QDialogButtonBox.Ok) okb.setEnabled(False) okb.setText("Add") def changed(name): okb.setEnabled(bool(name)) nameentry.textChanged.connect(changed) vlayout.addWidget(buttons) vlayout.setSizeConstraint(QVBoxLayout.SetFixedSize) dlg.setLayout(vlayout) f = None def query(): nonlocal f name = nameentry.text() def query_pypi(name): # type: (str) -> _QueryResult res, = pypi_json_query_project_meta([name]) inst = None # type: Optional[Installable] if res is not None: inst = installable_from_json_response(res) else: inst = None return _QueryResult(queryname=name, installable=inst) f = self.__executor.submit(query_pypi, name) okb.setDisabled(True) f.add_done_callback( method_queued(self.__on_add_single_query_finish, (object, ))) buttons.accepted.connect(query) buttons.rejected.connect(dlg.reject) dlg.exec_()
def __run_add_package_dialog(self): self.__add_package_by_name_dialog = dlg = QDialog( self, windowTitle="Add add-on by name", ) dlg.setAttribute(Qt.WA_DeleteOnClose) vlayout = QVBoxLayout() form = QFormLayout() form.setContentsMargins(0, 0, 0, 0) nameentry = QLineEdit( placeholderText="Package name", toolTip="Enter a package name as displayed on " "PyPI (capitalization is not important)") nameentry.setMinimumWidth(250) form.addRow("Name:", nameentry) vlayout.addLayout(form) buttons = QDialogButtonBox( standardButtons=QDialogButtonBox.Ok | QDialogButtonBox.Cancel ) okb = buttons.button(QDialogButtonBox.Ok) okb.setEnabled(False) okb.setText("Add") def changed(name): okb.setEnabled(bool(name)) nameentry.textChanged.connect(changed) vlayout.addWidget(buttons) vlayout.setSizeConstraint(QVBoxLayout.SetFixedSize) dlg.setLayout(vlayout) f = None def query(): nonlocal f name = nameentry.text() def query_pypi(name): # type: (str) -> _QueryResult res = pypi_json_query_project_meta([name]) assert len(res) == 1 r = res[0] if r is not None: r = installable_from_json_response(r) return _QueryResult(queryname=name, installable=r) f = self.__executor.submit(query_pypi, name) okb.setDisabled(True) f.add_done_callback( method_queued(self.__on_add_single_query_finish, (object,)) ) buttons.accepted.connect(query) buttons.rejected.connect(dlg.reject) dlg.exec_()
def __setupUi(self): layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.setContentsMargins(0, 0, 0, 0) heading = self.tr("预览") heading = "<h3>{0}</h3>".format(heading) self.__heading = QLabel(heading, self, objectName="heading") self.__heading.setContentsMargins(12, 12, 12, 0) self.__browser = previewbrowser.PreviewBrowser(self) self.__buttons = QDialogButtonBox(QDialogButtonBox.Open | \ QDialogButtonBox.Cancel, Qt.Horizontal,) self.__buttons.button(QDialogButtonBox.Open).setAutoDefault(True) # Set the Open dialog as disabled until the current index changes self.__buttons.button(QDialogButtonBox.Open).setEnabled(False) self.__buttons.button(QDialogButtonBox.Open).setText("打开") self.__buttons.button(QDialogButtonBox.Cancel).setText("取消") # The QDialogButtonsWidget messes with the layout if it is # contained directly in the QDialog. So we create an extra # layer of indirection. buttons = QWidget(objectName="button-container") buttons_l = QVBoxLayout() buttons_l.setContentsMargins(12, 0, 12, 12) buttons.setLayout(buttons_l) buttons_l.addWidget(self.__buttons) layout.addWidget(self.__heading) layout.addWidget(self.__browser) layout.addWidget(buttons) self.__buttons.accepted.connect(self.accept) self.__buttons.rejected.connect(self.reject) self.__browser.currentIndexChanged.connect( self.__on_currentIndexChanged ) self.__browser.activated.connect(self.__on_activated) layout.setSizeConstraint(QVBoxLayout.SetFixedSize) self.setLayout(layout) self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
def __init__(self, parent=None, acceptDrops=True, **kwargs): super().__init__(parent, acceptDrops=acceptDrops, **kwargs) self.setLayout(QVBoxLayout()) self.addonwidget = AddonManagerWidget() self.addonwidget.layout().setContentsMargins(0, 0, 0, 0) self.layout().addWidget(self.addonwidget) buttons = QDialogButtonBox( orientation=Qt.Horizontal, standardButtons=QDialogButtonBox.Ok | QDialogButtonBox.Cancel, ) addmore = QPushButton( "Add more...", toolTip="Add an add-on not listed below", autoDefault=False ) self.addonwidget.tophlayout.addWidget(addmore) addmore.clicked.connect(self.__run_add_package_dialog) buttons.accepted.connect(self.__accepted) buttons.rejected.connect(self.reject) self.layout().addWidget(buttons) self.__progress = None # type: Optional[QProgressDialog] self.__executor = ThreadPoolExecutor(max_workers=1) # The installer thread self.__thread = None # The installer object self.__installer = None self.__add_package_by_name_dialog = None # type: Optional[QDialog]
def __init__(self, rgbColors, parent=None, windowTitle="Palette Editor", **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(4, 4, 4, 4) hbox = gui.hBox(self, "Information") gui.widgetLabel( hbox, '<p align="center">You can reorder colors in the list using the' "<br/>buttons on the right or by dragging and dropping the items." "<br/>To change a specific color double click the item in the " "list.</p>", ) hbox = gui.hBox(self, box=True) self.discListbox = gui.listBox(hbox, self, enableDragDrop=1) vbox = gui.vBox(hbox) buttonUPAttr = gui.button(vbox, self, "", callback=self.moveAttrUP, tooltip="Move selected colors up") buttonDOWNAttr = gui.button( vbox, self, "", callback=self.moveAttrDOWN, tooltip="Move selected colors down", ) buttonUPAttr.setIcon(QIcon(gui.resource_filename("icons/Dlg_up3.png"))) buttonUPAttr.setSizePolicy( QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)) buttonUPAttr.setMaximumWidth(30) buttonDOWNAttr.setIcon( QIcon(gui.resource_filename("icons/Dlg_down3.png"))) buttonDOWNAttr.setSizePolicy( QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)) buttonDOWNAttr.setMaximumWidth(30) self.discListbox.itemDoubleClicked.connect(self.changeDiscreteColor) box = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, accepted=self.accept, rejected=self.reject, ) self.layout().addWidget(box) self.discListbox.setIconSize(QSize(25, 25)) for ind, (r, g, b) in enumerate(rgbColors): item = QListWidgetItem(ColorPixmap(QColor(r, g, b), 25), "Color %d" % (ind + 1)) item.rgbColor = (r, g, b) self.discListbox.addItem(item) self.resize(300, 300)
def __setupUi(self): layout = QVBoxLayout() label = QLabel(self) pixmap, _ = config.splash_screen() label.setPixmap(pixmap) layout.addWidget(label, Qt.AlignCenter) name = QApplication.applicationName() version = QApplication.applicationVersion() text = ABOUT_TEMPLATE.format( name=escape(name), version=escape(version), ) # TODO: Also list all known add-on versions??. text_label = QLabel(text) layout.addWidget(text_label, Qt.AlignCenter) buttons = QDialogButtonBox(QDialogButtonBox.Close, Qt.Horizontal, self) layout.addWidget(buttons) buttons.rejected.connect(self.accept) layout.setSizeConstraint(QVBoxLayout.SetFixedSize) self.setLayout(layout)
def initUI(self): "Create the GUI layout to be used in the tests." log.info("Initialising the UI") self.setWindowTitle(self.app_title) ## Create all necessary widgets ## Short alternate names make configuration simpler. ## Buttons self.button_bar = QDialogButtonBox.Ok | QDialogButtonBox.Cancel self.button_box = QDialogButtonBox(self.button_bar) ## Bring all the HBoxes together in a VBox vbox = QVBoxLayout() self.grid = self.form.render() vbox.addLayout(self.grid) vbox.addWidget(self.button_box) ## Connect UI signals to slots self.button_box.accepted.connect(self.accept) self.button_box.rejected.connect(self.reject) ## Establish the window layout self.setLayout(vbox) ## Set pints.components to desired initial state ## tb.setEnabled(False) ## sn.setEnabled(False) self.setGeometry(300, 300, 300, 250)
def __init__(self, parent=None, defaults=[True, False, False, False], enabled=[False, True, True, True], **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) for item, default in zip(self.items, defaults): setattr(self, item[0], default) for item, enable, checked in zip(self.items, enabled, defaults): cb = QCheckBox(text=item[1], checked=checked, enabled=enable) cb.toggled[bool].connect( lambda state, name=item[0]: setattr(self, name, state)) self.layout().addWidget(cb) bbox = QDialogButtonBox(Qt.Horizontal, standardButtons=QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bbox.accepted.connect(self.accept) bbox.rejected.connect(self.reject) self.layout().addWidget(bbox) self.layout().setSizeConstraint(QLayout.SetFixedSize)
def __setupUi(self): layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.editor = SchemeInfoEdit(self) self.editor.layout().setContentsMargins(20, 20, 20, 20) self.editor.layout().setSpacing(15) self.editor.setSizePolicy( QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding ) heading = self.tr("Workflow Info") heading = "<h3>{0}</h3>".format(heading) self.heading = QLabel(heading, self, objectName="heading") # Insert heading self.editor.layout().insertRow(0, self.heading) self.buttonbox = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self ) # Insert button box self.editor.layout().addRow(self.buttonbox) widget = StyledWidget(self, objectName="auto-show-container") check_layout = QHBoxLayout() check_layout.setContentsMargins(20, 10, 20, 10) self.__showAtNewSchemeCheck = QCheckBox( self.tr("Show when I make a New Workflow."), self, objectName="auto-show-check", checked=False, ) check_layout.addWidget(self.__showAtNewSchemeCheck) check_layout.addWidget( QLabel( self.tr( "You can also edit Workflow Info later " "(File -> Workflow Info)." ), self, objectName="auto-show-info", ), alignment=Qt.AlignRight, ) widget.setLayout(check_layout) widget.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) if self.__autoCommit: self.buttonbox.accepted.connect(self.editor.commit) self.buttonbox.accepted.connect(self.accept) self.buttonbox.rejected.connect(self.reject) layout.addWidget(self.editor, stretch=10) layout.addWidget(widget) self.setLayout(layout)
def __setupUi(self): layout = QVBoxLayout() label = QLabel(self) pixmap, _ = config.splash_screen() label.setPixmap(pixmap) layout.addWidget(label, Qt.AlignCenter) try: from Orange.version import version from Orange.version import git_revision except ImportError: dist = pkg_resources.get_distribution("Orange3") version = dist.version git_revision = "Unknown" text = ABOUT_TEMPLATE.format(version=version, git_revision=git_revision[:7]) # TODO: Also list all known add-on versions. text_label = QLabel(text) layout.addWidget(text_label, Qt.AlignCenter) buttons = QDialogButtonBox(QDialogButtonBox.Close, Qt.Horizontal, self) layout.addWidget(buttons) buttons.rejected.connect(self.accept) layout.setSizeConstraint(QVBoxLayout.SetFixedSize) self.setLayout(layout)
def __init__(self, parent=None): super(FileUploadHelper, self).__init__( parent, Qt.Window | Qt.WindowTitleHint | Qt.CustomizeWindowHint | Qt.WindowCloseButtonHint | Qt.WindowMaximizeButtonHint) self.setAttribute(Qt.WA_DeleteOnClose) self.setWindowTitle('Add new file') self.info_state = INFO_FILE_SCHEMA self.layout = QVBoxLayout(self) # domain selection combobox self.domain_selection = QComboBox() self.domain_selection.addItems(self.supported_domains.keys()) self.domain_selection.currentIndexChanged.connect( self.__on_domain_selection) self.__create_selection_row('Domain: ', self.domain_selection) # domain selection combobox self.hierarchy_selection = QComboBox() self.hierarchy_selection.addItems(self.hierarchies.keys()) self.layout.addWidget(self.hierarchy_selection, alignment=Qt.AlignVCenter) self.__on_domain_selection() # select organism self.organism_selection = QComboBox() self.organism_selection.addItems(self.supported_organisms) self.__create_selection_row('Organism: ', self.organism_selection) # title self.line_edit_title = QLineEdit() self.__create_selection_row('Title: ', self.line_edit_title) # tags self.line_edit_tags = QLineEdit() self.__create_selection_row('Tags (comma-separated): ', self.line_edit_tags) # file selector self.file_info = QLabel() self.file_select_btn = QPushButton('Select File', self) self.file_select_btn.clicked.connect(self.__handle_file_selector) self.__create_selection_row(' ', self.file_select_btn) # add file info section self.layout.addWidget(self.file_info, alignment=Qt.AlignCenter) self.layout.addStretch(1) # Ok and Cancel buttons self.buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self) self.layout.addWidget(self.buttons, alignment=Qt.AlignJustify) self.buttons.accepted.connect(self.__accept) self.buttons.rejected.connect(self.__close) # path to a selected file self.file_path = None
def __init__(self, parent=None, windowTitle="Color Palette List", **kwargs): super().__init__(parent, windowTitle=windowTitle, **kwargs) self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) sa = QScrollArea(horizontalScrollBarPolicy=Qt.ScrollBarAlwaysOff, verticalScrollBarPolicy=Qt.ScrollBarAlwaysOn) sa.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) sa.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.layout().addWidget(sa) space = QWidget(self) space.setLayout(QVBoxLayout()) sa.setWidget(space) sa.setWidgetResizable(True) self.buttons = [] self.setMinimumWidth(400) box = gui.vBox(space, "Information", addSpace=True) gui.widgetLabel( box, '<p align="center">This dialog shows a list of predefined ' 'color palettes <br>from colorbrewer.org that can be used ' 'in Orange.<br/>You can select a palette by clicking on it.</p>') box = gui.vBox(space, "Default Palette", addSpace=True) butt = _ColorButton(DefaultRGBColors, flat=True, toolTip="Default color palette", clicked=self._buttonClicked) box.layout().addWidget(butt) self.buttons.append(butt) for type in [ "Qualitative", "Spectral", "Diverging", "Sequential", "Pastels" ]: colorGroup = colorbrewer.colorSchemes.get(type.lower(), {}) if colorGroup: box = gui.vBox(space, type + " Palettes", addSpace=True) items = sorted(colorGroup.items()) for key, colors in items: butt = _ColorButton(colors, self, toolTip=key, flat=True, clicked=self._buttonClicked) box.layout().addWidget(butt) self.buttons.append(butt) buttons = QDialogButtonBox(QDialogButtonBox.Cancel, rejected=self.reject) self.layout().addWidget(buttons) self.selectedColors = None
def __init__(self, parent, label): super().__init__(parent) self.setWindowTitle('Confirmation') QBtn = QDialogButtonBox.Yes | QDialogButtonBox.No self.buttonBox = QDialogButtonBox(QBtn) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.layout = QVBoxLayout() message = QLabel(label) self.layout.addWidget(message) self.layout.addWidget(self.buttonBox) self.setLayout(self.layout)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setContentsMargins(0, 0, 0, 0) self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().setSpacing(0) self.__pageview = PagedWidget() self.__pageview.currentIndexChanged.connect(self.currentIndexChanged) self.__bottom = PagedDialog.BottomBar(objectName="bottom-area") self.__bottom.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.__bottom.setLayout(QHBoxLayout()) self.__buttons = QDialogButtonBox(objectName="dialog-buttons") self.__buttons.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) self.__buttons.setVisible(False) self.__buttons.rejected.connect(self.reject) self.__bottom.layout().addWidget(self.__buttons) self.layout().addWidget(self.__pageview) self.layout().addWidget(self.__bottom)
def __init__(self, parent=None, **kwargs): super().__init__(parent, acceptDrops=True, **kwargs) self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.addonwidget = AddonManagerWidget() self.layout().addWidget(self.addonwidget) info_bar = QWidget() info_layout = QHBoxLayout() info_bar.setLayout(info_layout) self.layout().addWidget(info_bar) buttons = QDialogButtonBox( orientation=Qt.Horizontal, standardButtons=QDialogButtonBox.Ok | QDialogButtonBox.Cancel ) buttons.accepted.connect(self.__accepted) buttons.rejected.connect(self.reject) self.layout().addWidget(buttons) # No system access => install into user site-packages self.user_install = not os.access(sysconfig.get_path("purelib"), os.W_OK) self._executor = concurrent.futures.ThreadPoolExecutor(max_workers=1) if AddonManagerDialog._packages is None: self._f_pypi_addons = self._executor.submit(list_pypi_addons) else: self._f_pypi_addons = concurrent.futures.Future() self._f_pypi_addons.set_result(AddonManagerDialog._packages) self._f_pypi_addons.add_done_callback( method_queued(self._set_packages, (object,)) ) self.__progress = QProgressDialog( self, Qt.Sheet, minimum=0, maximum=0, labelText=self.tr("Retrieving package list"), sizeGripEnabled=False, windowTitle="Progress" ) self.__progress.rejected.connect(self.reject) self.__thread = None self.__installer = None
def __setupUi(self): layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.setContentsMargins(0, 0, 0, 0) heading = self.tr("Preview") heading = "<h3>{0}</h3>".format(heading) self.__heading = QLabel(heading, self, objectName="heading") self.__heading.setContentsMargins(12, 12, 12, 0) self.__browser = previewbrowser.PreviewBrowser(self) self.__buttons = QDialogButtonBox(QDialogButtonBox.Open | \ QDialogButtonBox.Cancel, Qt.Horizontal,) self.__buttons.button(QDialogButtonBox.Open).setAutoDefault(True) # Set the Open dialog as disabled until the current index changes self.__buttons.button(QDialogButtonBox.Open).setEnabled(False) # The QDialogButtonsWidget messes with the layout if it is # contained directly in the QDialog. So we create an extra # layer of indirection. buttons = QWidget(objectName="button-container") buttons_l = QVBoxLayout() buttons_l.setContentsMargins(12, 0, 12, 12) buttons.setLayout(buttons_l) buttons_l.addWidget(self.__buttons) layout.addWidget(self.__heading) layout.addWidget(self.__browser) layout.addWidget(buttons) self.__buttons.accepted.connect(self.accept) self.__buttons.rejected.connect(self.reject) self.__browser.currentIndexChanged.connect( self.__on_currentIndexChanged ) self.__browser.activated.connect(self.__on_activated) layout.setSizeConstraint(QVBoxLayout.SetFixedSize) self.setLayout(layout) self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
def __init__(self, parent=None, **kwargs): super().__init__(parent, acceptDrops=True, **kwargs) self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.addonwidget = AddonManagerWidget() self.layout().addWidget(self.addonwidget) info_bar = QWidget() info_layout = QHBoxLayout() info_bar.setLayout(info_layout) self.layout().addWidget(info_bar) buttons = QDialogButtonBox( orientation=Qt.Horizontal, standardButtons=QDialogButtonBox.Ok | QDialogButtonBox.Cancel, ) addmore = QPushButton( "Add more...", toolTip="Add an add-on not listed below", autoDefault=False ) self.addonwidget.tophlayout.addWidget(addmore) addmore.clicked.connect(self.__run_add_package_dialog) buttons.accepted.connect(self.__accepted) buttons.rejected.connect(self.reject) self.layout().addWidget(buttons) self._executor = concurrent.futures.ThreadPoolExecutor(max_workers=1) if AddonManagerDialog._packages is None: self._f_pypi_addons = self._executor.submit(list_available_versions) else: self._f_pypi_addons = concurrent.futures.Future() self._f_pypi_addons.set_result(AddonManagerDialog._packages) self._f_pypi_addons.add_done_callback( method_queued(self._set_packages, (object,)) ) self.__progress = None # type: Optional[QProgressDialog] self.__thread = None self.__installer = None if not self._f_pypi_addons.done(): self.__progressDialog()
def __init__(self, parent=None, name="Open"): super().__init__(parent) self.__url_edit = QLineEdit() self.__url_edit.setMinimumWidth(300) button_box = QDialogButtonBox( QDialogButtonBox.Cancel | QDialogButtonBox.Open, Qt.Horizontal, self ) button_box.accepted.connect(self.accept) button_box.rejected.connect(self.reject) layout = QVBoxLayout() layout_ = QHBoxLayout() layout_.addWidget(QLabel("URL:")) layout_.addWidget(self.__url_edit) layout.addLayout(layout_) layout.addWidget(button_box) self.setLayout(layout) self.setWindowTitle(name)
def __init__(self, parent=None, **kwargs): super(AddonManagerDialog, self).__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self.addonwidget = AddonManagerWidget() self.addonwidget.layout().setContentsMargins(0, 0, 0, 0) self.layout().addWidget(self.addonwidget) buttons = QDialogButtonBox( orientation=Qt.Horizontal, standardButtons=QDialogButtonBox.Ok | QDialogButtonBox.Cancel ) buttons.accepted.connect(self.__accepted) buttons.rejected.connect(self.reject) self.layout().addWidget(buttons) self.__progress = None # type: QProgressDialog # The installer thread self.__thread = None # The installer object self.__installer = None
class PreviewDialog(QDialog): """A Dialog for selecting an item from a PreviewItem. """ currentIndexChanged = Signal(int) def __init__(self, parent=None, flags=Qt.WindowFlags(0), model=None, **kwargs): QDialog.__init__(self, parent, flags, **kwargs) self.__setupUi() if model is not None: self.setModel(model) def __setupUi(self): layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.setContentsMargins(0, 0, 0, 0) heading = self.tr("Preview") heading = "<h3>{0}</h3>".format(heading) self.__heading = QLabel(heading, self, objectName="heading") self.__heading.setContentsMargins(12, 12, 12, 0) self.__browser = previewbrowser.PreviewBrowser(self) self.__buttons = QDialogButtonBox(QDialogButtonBox.Open | \ QDialogButtonBox.Cancel, Qt.Horizontal,) self.__buttons.button(QDialogButtonBox.Open).setAutoDefault(True) # Set the Open dialog as disabled until the current index changes self.__buttons.button(QDialogButtonBox.Open).setEnabled(False) # The QDialogButtonsWidget messes with the layout if it is # contained directly in the QDialog. So we create an extra # layer of indirection. buttons = QWidget(objectName="button-container") buttons_l = QVBoxLayout() buttons_l.setContentsMargins(12, 0, 12, 12) buttons.setLayout(buttons_l) buttons_l.addWidget(self.__buttons) layout.addWidget(self.__heading) layout.addWidget(self.__browser) layout.addWidget(buttons) self.__buttons.accepted.connect(self.accept) self.__buttons.rejected.connect(self.reject) self.__browser.currentIndexChanged.connect( self.__on_currentIndexChanged ) self.__browser.activated.connect(self.__on_activated) layout.setSizeConstraint(QVBoxLayout.SetFixedSize) self.setLayout(layout) self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) def setItems(self, items): """Set the items (a list of strings) for preview/selection. """ model = QStringListModel(items) self.setModel(model) def setModel(self, model): """Set the model for preview/selection. """ self.__browser.setModel(model) def model(self): """Return the model. """ return self.__browser.model() def currentIndex(self): return self.__browser.currentIndex() def setCurrentIndex(self, index): """Set the current selected (shown) index. """ self.__browser.setCurrentIndex(index) def setHeading(self, heading): """Set `heading` as the heading string ('<h3>Preview</h3>' by default). """ self.__heading.setText(heading) def heading(self): """Return the heading string. """ def __on_currentIndexChanged(self, index): button = self.__buttons.button(QDialogButtonBox.Open) button.setEnabled(index >= 0) self.currentIndexChanged.emit(index) def __on_activated(self, index): if self.currentIndex() != index: self.setCurrentIndex(index) self.accept()
class SchemeInfoDialog(QDialog): def __init__(self, *args, **kwargs): QDialog.__init__(self, *args, **kwargs) self.scheme = None self.__autoCommit = True self.__setupUi() def __setupUi(self): layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.editor = SchemeInfoEdit(self) self.editor.layout().setContentsMargins(20, 20, 20, 20) self.editor.layout().setSpacing(15) self.editor.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) heading = self.tr("数据挖掘流程属性信息") heading = "<h3>{0}</h3>".format(heading) self.heading = QLabel(heading, self, objectName="heading") # Insert heading self.editor.layout().insertRow(0, self.heading) self.buttonbox = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self ) #self.buttonBox = QDialogButtonBox(self) #self.buttonBox.setOrientation(Qt.Horizontal) self.buttonbox.button(QDialogButtonBox.Ok).setText("确定") self.buttonbox.button(QDialogButtonBox.Cancel).setText("取消") # Insert button box self.editor.layout().addRow(self.buttonbox) widget = StyledWidget(self, objectName="auto-show-container") check_layout = QHBoxLayout() check_layout.setContentsMargins(20, 10, 20, 10) self.__showAtNewSchemeCheck = \ QCheckBox(self.tr("创建新的数据挖掘流程时显示."), self, objectName="auto-show-check", checked=False, ) check_layout.addWidget(self.__showAtNewSchemeCheck) check_layout.addWidget( QLabel(self.tr("编辑数据挖掘流程属性信息" "(文件 -> 属性)."), self, objectName="auto-show-info"), alignment=Qt.AlignRight) widget.setLayout(check_layout) widget.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) if self.__autoCommit: self.buttonbox.accepted.connect(self.editor.commit) self.buttonbox.accepted.connect(self.accept) self.buttonbox.rejected.connect(self.reject) layout.addWidget(self.editor, stretch=10) layout.addWidget(widget) self.setLayout(layout) def setShowAtNewScheme(self, checked): """ Set the 'Show at new scheme' check state. """ self.__showAtNewSchemeCheck.setChecked(checked) def showAtNewScheme(self): """ Return the check state of the 'Show at new scheme' check box. """ return self.__showAtNewSchemeCheck.isChecked() def setAutoCommit(self, auto): if self.__autoCommit != auto: self.__autoCommit = auto if auto: self.buttonbox.accepted.connect(self.editor.commit) else: self.buttonbox.accepted.disconnect(self.editor.commit) def setScheme(self, scheme): """Set the scheme to display/edit. """ self.scheme = scheme self.editor.setScheme(scheme)
def __setupUi(self): """Set up the UI. """ if self.__macUnified: self.tab = QToolBar( floatable=False, movable=False, allowedAreas=Qt.TopToolBarArea, ) self.addToolBar(Qt.TopToolBarArea, self.tab) self.setUnifiedTitleAndToolBarOnMac(True) # This does not seem to work self.setWindowFlags(self.windowFlags() & \ ~Qt.MacWindowToolBarButtonHint) self.tab.actionTriggered[QAction].connect( self.__macOnToolBarAction) central = QStackedWidget() central.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) else: self.tab = central = QTabWidget(self) # Add a close button to the bottom of the dialog # (to satisfy GNOME 3 which shows the dialog without a title bar). container = container_widget_helper() container.layout().addWidget(central) buttonbox = QDialogButtonBox(QDialogButtonBox.Close) buttonbox.rejected.connect(self.close) container.layout().addWidget(buttonbox) self.setCentralWidget(container) self.stack = central # General Tab tab = QWidget() self.addTab(tab, self.tr("General"), toolTip=self.tr("General Options")) form = FormLayout() tab.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) nodes = QWidget(self, objectName="nodes") nodes.setLayout(QVBoxLayout()) nodes.layout().setContentsMargins(0, 0, 0, 0) cb_anim = QCheckBox(self.tr("Enable node animations"), objectName="enable-node-animations", toolTip=self.tr( "Enable shadow and ping animations for nodes " "in the workflow.")) self.bind(cb_anim, "checked", "schemeedit/enable-node-animations") nodes.layout().addWidget(cb_anim) form.addRow(self.tr("Nodes"), nodes) links = QWidget(self, objectName="links") links.setLayout(QVBoxLayout()) links.layout().setContentsMargins(0, 0, 0, 0) cb_show = QCheckBox(self.tr("Show channel names between widgets"), objectName="show-channel-names", toolTip=self.tr( "Show source and sink channel names " "over the links.")) self.bind(cb_show, "checked", "schemeedit/show-channel-names") links.layout().addWidget(cb_show) form.addRow(self.tr("Links"), links) quickmenu = QWidget(self, objectName="quickmenu-options") quickmenu.setLayout(QVBoxLayout()) quickmenu.layout().setContentsMargins(0, 0, 0, 0) cb1 = QCheckBox(self.tr("Open on double click"), toolTip=self.tr("Open quick menu on a double click " "on an empty spot in the canvas")) cb2 = QCheckBox(self.tr("Open on right click"), toolTip=self.tr("Open quick menu on a right click " "on an empty spot in the canvas")) cb3 = QCheckBox(self.tr("Open on space key press"), toolTip=self.tr( "Open quick menu on Space key press " "while the mouse is hovering over the canvas.")) cb4 = QCheckBox(self.tr("Open on any key press"), toolTip=self.tr( "Open quick menu on any key press " "while the mouse is hovering over the canvas.")) cb5 = QCheckBox(self.tr("Show categories"), toolTip=self.tr( "In addition to searching, allow filtering " "by categories.")) self.bind(cb1, "checked", "quickmenu/trigger-on-double-click") self.bind(cb2, "checked", "quickmenu/trigger-on-right-click") self.bind(cb3, "checked", "quickmenu/trigger-on-space-key") self.bind(cb4, "checked", "quickmenu/trigger-on-any-key") self.bind(cb5, "checked", "quickmenu/show-categories") quickmenu.layout().addWidget(cb1) quickmenu.layout().addWidget(cb2) quickmenu.layout().addWidget(cb3) quickmenu.layout().addWidget(cb4) quickmenu.layout().addWidget(cb5) form.addRow(self.tr("Quick menu"), quickmenu) startup = QWidget(self, objectName="startup-group") startup.setLayout(QVBoxLayout()) startup.layout().setContentsMargins(0, 0, 0, 0) cb_splash = QCheckBox(self.tr("Show splash screen"), self, objectName="show-splash-screen") cb_welcome = QCheckBox(self.tr("Show welcome screen"), self, objectName="show-welcome-screen") cb_crash = QCheckBox(self.tr("Load crashed scratch workflows"), self, objectName="load-crashed-workflows") self.bind(cb_splash, "checked", "startup/show-splash-screen") self.bind(cb_welcome, "checked", "startup/show-welcome-screen") self.bind(cb_crash, "checked", "startup/load-crashed-workflows") startup.layout().addWidget(cb_splash) startup.layout().addWidget(cb_welcome) startup.layout().addWidget(cb_crash) form.addRow(self.tr("On startup"), startup) toolbox = QWidget(self, objectName="toolbox-group") toolbox.setLayout(QVBoxLayout()) toolbox.layout().setContentsMargins(0, 0, 0, 0) exclusive = QCheckBox(self.tr("Only one tab can be open at a time")) self.bind(exclusive, "checked", "mainwindow/toolbox-dock-exclusive") toolbox.layout().addWidget(exclusive) form.addRow(self.tr("Tool box"), toolbox) tab.setLayout(form) # Style tab tab = StyleConfigWidget() self.addTab(tab, self.tr("&Style"), toolTip="Application style") self.bind(tab, "selectedStyle_", "application-style/style-name") self.bind(tab, "selectedPalette_", "application-style/palette") # Output Tab tab = QWidget() self.addTab(tab, self.tr("Output"), toolTip="Output Redirection") form = FormLayout() combo = QComboBox() combo.addItems([ self.tr("Critical"), self.tr("Error"), self.tr("Warn"), self.tr("Info"), self.tr("Debug") ]) self.bind(combo, "currentIndex", "logging/level") form.addRow(self.tr("Logging"), combo) box = QWidget() layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) cb1 = QCheckBox(self.tr("Open in external browser"), objectName="open-in-external-browser") self.bind(cb1, "checked", "help/open-in-external-browser") layout.addWidget(cb1) box.setLayout(layout) form.addRow(self.tr("Help window"), box) tab.setLayout(form) # Categories Tab tab = QWidget() layout = QVBoxLayout() view = QListView(editTriggers=QListView.NoEditTriggers) from .. import registry reg = registry.global_registry() model = QStandardItemModel() settings = QSettings() for cat in reg.categories(): item = QStandardItem() item.setText(cat.name) item.setCheckable(True) visible, _ = category_state(cat, settings) item.setCheckState(Qt.Checked if visible else Qt.Unchecked) model.appendRow([item]) view.setModel(model) layout.addWidget(view) tab.setLayout(layout) model.itemChanged.connect(lambda item: save_category_state( reg.category(str(item.text())), _State(item.checkState() == Qt.Checked, -1), settings)) self.addTab(tab, "Categories") # Add-ons Tab tab = QWidget() self.addTab(tab, self.tr("Add-ons"), toolTip="Settings related to add-on installation") form = FormLayout() conda = QWidget(self, objectName="conda-group") conda.setLayout(QVBoxLayout()) conda.layout().setContentsMargins(0, 0, 0, 0) cb_conda_install = QCheckBox(self.tr("Install add-ons with conda"), self, objectName="allow-conda") self.bind(cb_conda_install, "checked", "add-ons/allow-conda") conda.layout().addWidget(cb_conda_install) form.addRow(self.tr("Conda"), conda) form.addRow(self.tr("Pip"), QLabel("Pip install arguments:")) line_edit_pip = QLineEdit() self.bind(line_edit_pip, "text", "add-ons/pip-install-arguments") form.addRow("", line_edit_pip) tab.setLayout(form) # Network Tab tab = QWidget() self.addTab(tab, self.tr("Network"), toolTip="Settings related to networking") form = FormLayout() line_edit_http_proxy = QLineEdit() self.bind(line_edit_http_proxy, "text", "network/http-proxy") form.addRow("HTTP proxy:", line_edit_http_proxy) line_edit_https_proxy = QLineEdit() self.bind(line_edit_https_proxy, "text", "network/https-proxy") form.addRow("HTTPS proxy:", line_edit_https_proxy) tab.setLayout(form) if self.__macUnified: # Need some sensible size otherwise mac unified toolbar 'takes' # the space that should be used for layout of the contents self.adjustSize()
def __setupUi(self): layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.editor = SchemeInfoEdit(self) self.editor.layout().setContentsMargins(20, 20, 20, 20) self.editor.layout().setSpacing(15) self.editor.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) heading = self.tr("数据挖掘流程属性信息") heading = "<h3>{0}</h3>".format(heading) self.heading = QLabel(heading, self, objectName="heading") # Insert heading self.editor.layout().insertRow(0, self.heading) self.buttonbox = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self ) #self.buttonBox = QDialogButtonBox(self) #self.buttonBox.setOrientation(Qt.Horizontal) self.buttonbox.button(QDialogButtonBox.Ok).setText("确定") self.buttonbox.button(QDialogButtonBox.Cancel).setText("取消") # Insert button box self.editor.layout().addRow(self.buttonbox) widget = StyledWidget(self, objectName="auto-show-container") check_layout = QHBoxLayout() check_layout.setContentsMargins(20, 10, 20, 10) self.__showAtNewSchemeCheck = \ QCheckBox(self.tr("创建新的数据挖掘流程时显示."), self, objectName="auto-show-check", checked=False, ) check_layout.addWidget(self.__showAtNewSchemeCheck) check_layout.addWidget( QLabel(self.tr("编辑数据挖掘流程属性信息" "(文件 -> 属性)."), self, objectName="auto-show-info"), alignment=Qt.AlignRight) widget.setLayout(check_layout) widget.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) if self.__autoCommit: self.buttonbox.accepted.connect(self.editor.commit) self.buttonbox.accepted.connect(self.accept) self.buttonbox.rejected.connect(self.reject) layout.addWidget(self.editor, stretch=10) layout.addWidget(widget) self.setLayout(layout)
def __init__(self): super().__init__() self.data = None # type: Optional[Orange.data.Table] #: The current selected variable index self.selected_index = -1 self._invalidated = False mainlayout = self.mainArea.layout() assert isinstance(mainlayout, QVBoxLayout) layout = QHBoxLayout() mainlayout.addLayout(layout) box = QGroupBox("Variables") box.setLayout(QVBoxLayout()) layout.addWidget(box) self.variables_model = VariableListModel(parent=self) self.variables_view = self.domain_view = QListView( selectionMode=QListView.SingleSelection, uniformItemSizes=True, ) self.variables_view.setItemDelegate(VariableEditDelegate(self)) self.variables_view.setModel(self.variables_model) self.variables_view.selectionModel().selectionChanged.connect( self._on_selection_changed) box.layout().addWidget(self.variables_view) box = QGroupBox("Edit", ) box.setLayout(QVBoxLayout(margin=4)) layout.addWidget(box) self.editor_stack = QStackedWidget() self.editor_stack.addWidget(DiscreteVariableEditor()) self.editor_stack.addWidget(ContinuousVariableEditor()) self.editor_stack.addWidget(TimeVariableEditor()) self.editor_stack.addWidget(VariableEditor()) box.layout().addWidget(self.editor_stack) bbox = QDialogButtonBox() bbox.setStyleSheet("button-layout: {:d};".format( QDialogButtonBox.MacLayout)) bapply = QPushButton( "Apply", objectName="button-apply", toolTip="Apply changes and commit data on output.", default=True, autoDefault=False) bapply.clicked.connect(self.commit) breset = QPushButton( "Reset Selected", objectName="button-reset", toolTip="Rest selected variable to its input state.", autoDefault=False) breset.clicked.connect(self.reset_selected) breset_all = QPushButton( "Reset All", objectName="button-reset-all", toolTip="Reset all variables to their input state.", autoDefault=False) breset_all.clicked.connect(self.reset_all) bbox.addButton(bapply, QDialogButtonBox.AcceptRole) bbox.addButton(breset, QDialogButtonBox.ResetRole) bbox.addButton(breset_all, QDialogButtonBox.ResetRole) mainlayout.addWidget(bbox) self.variables_view.setFocus(Qt.NoFocusReason) # initial focus
def __setupUi(self): """Set up the UI. """ if self.__macUnified: self.tab = QToolBar( floatable=False, movable=False, allowedAreas=Qt.TopToolBarArea, ) self.addToolBar(Qt.TopToolBarArea, self.tab) self.setUnifiedTitleAndToolBarOnMac(True) # This does not seem to work self.setWindowFlags(self.windowFlags() & \ ~Qt.MacWindowToolBarButtonHint) self.tab.actionTriggered[QAction].connect( self.__macOnToolBarAction ) central = QStackedWidget() central.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) else: self.tab = central = QTabWidget(self) # Add a close button to the bottom of the dialog # (to satisfy GNOME 3 which shows the dialog without a title bar). container = container_widget_helper() container.layout().addWidget(central) buttonbox = QDialogButtonBox(QDialogButtonBox.Close) buttonbox.rejected.connect(self.close) container.layout().addWidget(buttonbox) self.setCentralWidget(container) self.stack = central # General Tab tab = QWidget() self.addTab(tab, self.tr("常规"), toolTip=self.tr("常规选项")) form = FormLayout() tab.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) nodes = QWidget(self, objectName="nodes") nodes.setLayout(QVBoxLayout()) nodes.layout().setContentsMargins(0, 0, 0, 0) cb_anim = QCheckBox( self.tr("启用节点动画"), objectName="enable-node-animations", toolTip=self.tr("为工作流中的节点启用阴影和ping动画。") ) self.bind(cb_anim, "checked", "schemeedit/enable-node-animations") nodes.layout().addWidget(cb_anim) form.addRow(self.tr("结点"), nodes) links = QWidget(self, objectName="links") links.setLayout(QVBoxLayout()) links.layout().setContentsMargins(0, 0, 0, 0) cb_show = QCheckBox( self.tr("在窗口小部件之间显示通道名称"), objectName="show-channel-names", toolTip=self.tr("在链接上显示源和接收器通道名称。") ) self.bind(cb_show, "checked", "schemeedit/show-channel-names") links.layout().addWidget(cb_show) form.addRow(self.tr("链接"), links) quickmenu = QWidget(self, objectName="quickmenu-options") quickmenu.setLayout(QVBoxLayout()) quickmenu.layout().setContentsMargins(0, 0, 0, 0) cb1 = QCheckBox(self.tr("双击时打开"), toolTip=self.tr("双击画布中的空白位置打开快捷菜单")) cb2 = QCheckBox(self.tr("单击鼠标右键时打开"), toolTip=self.tr("右键单击画布中的空白处打开快捷菜单")) cb3 = QCheckBox(self.tr("按空格键时打开"), toolTip=self.tr("当鼠标悬停在画布上时,按空格键。")) cb4 = QCheckBox(self.tr("按任意按键时打开"), toolTip=self.tr("当鼠标悬停在画布上时,按任意键。")) cb5 = QCheckBox(self.tr("显示分类"), toolTip=self.tr("In addition to searching, allow filtering " "by categories.")) self.bind(cb1, "checked", "quickmenu/trigger-on-double-click") self.bind(cb2, "checked", "quickmenu/trigger-on-right-click") self.bind(cb3, "checked", "quickmenu/trigger-on-space-key") self.bind(cb4, "checked", "quickmenu/trigger-on-any-key") self.bind(cb5, "checked", "quickmenu/show-categories") quickmenu.layout().addWidget(cb1) quickmenu.layout().addWidget(cb2) quickmenu.layout().addWidget(cb3) quickmenu.layout().addWidget(cb4) quickmenu.layout().addWidget(cb5) form.addRow(self.tr("快捷菜单"), quickmenu) startup = QWidget(self, objectName="startup-group") startup.setLayout(QVBoxLayout()) startup.layout().setContentsMargins(0, 0, 0, 0) cb_splash = QCheckBox(self.tr("显示启动画面"), self, objectName="show-splash-screen") cb_welcome = QCheckBox(self.tr("显示欢迎界面"), self, objectName="show-welcome-screen") cb_crash = QCheckBox(self.tr("加载崩溃的工作流"), self, objectName="load-crashed-workflows") self.bind(cb_splash, "checked", "startup/show-splash-screen") self.bind(cb_welcome, "checked", "startup/show-welcome-screen") self.bind(cb_crash, "checked", "startup/load-crashed-workflows") startup.layout().addWidget(cb_splash) startup.layout().addWidget(cb_welcome) startup.layout().addWidget(cb_crash) form.addRow(self.tr("启动时"), startup) toolbox = QWidget(self, objectName="toolbox-group") toolbox.setLayout(QVBoxLayout()) toolbox.layout().setContentsMargins(0, 0, 0, 0) exclusive = QCheckBox(self.tr("一次只能打开一个选项卡")) self.bind(exclusive, "checked", "mainwindow/toolbox-dock-exclusive") toolbox.layout().addWidget(exclusive) form.addRow(self.tr("工具箱"), toolbox) tab.setLayout(form) # Style tab tab = StyleConfigWidget() self.addTab(tab, self.tr("&Style"), toolTip="Application style") self.bind(tab, "selectedStyle_", "application-style/style-name") self.bind(tab, "selectedPalette_", "application-style/palette") # Output Tab tab = QWidget() self.addTab(tab, self.tr("输出"), toolTip="输出重定向") form = FormLayout() combo = QComboBox() combo.addItems([self.tr("关键"), self.tr("错误"), self.tr("警告"), self.tr("信息"), self.tr("调试")]) self.bind(combo, "currentIndex", "logging/level") form.addRow(self.tr("记录"), combo) box = QWidget() layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) cb1 = QCheckBox(self.tr("在外部浏览器中打开"), objectName="open-in-external-browser") self.bind(cb1, "checked", "help/open-in-external-browser") layout.addWidget(cb1) box.setLayout(layout) form.addRow(self.tr("帮助窗口"), box) tab.setLayout(form) # Categories Tab tab = QWidget() layout = QVBoxLayout() view = QListView( editTriggers=QListView.NoEditTriggers ) from .. import registry reg = registry.global_registry() model = QStandardItemModel() settings = QSettings() for cat in reg.categories(): item = QStandardItem() item.setText(cat.name) item.setCheckable(True) visible, _ = category_state(cat, settings) item.setCheckState(Qt.Checked if visible else Qt.Unchecked) model.appendRow([item]) view.setModel(model) layout.addWidget(view) tab.setLayout(layout) model.itemChanged.connect( lambda item: save_category_state( reg.category(str(item.text())), _State(item.checkState() == Qt.Checked, -1), settings ) ) self.addTab(tab, "类别") # Add-ons Tab tab = QWidget() self.addTab(tab, self.tr("插件"), toolTip="与插件安装相关的设置") form = FormLayout() conda = QWidget(self, objectName="conda-group") conda.setLayout(QVBoxLayout()) conda.layout().setContentsMargins(0, 0, 0, 0) mirror_install = QCheckBox(self.tr("使用国内镜像安装"), self, objectName="allow-conda") self.bind(mirror_install, "checked", "add-ons/allow-conda") conda.layout().addWidget(mirror_install) form.addRow(self.tr("镜像"), conda) form.addRow(self.tr("Pip"), QLabel("Pip 安装参数:")) line_edit_pip = QLineEdit() # line_edit_pip.setText('-i https://mirrors.aliyun.com/pypi/simple') self.bind(line_edit_pip, "text", "add-ons/pip-install-arguments") form.addRow("", line_edit_pip) tab.setLayout(form) # Network Tab tab = QWidget() self.addTab(tab, self.tr("网络"), toolTip="与网络相关的设置") form = FormLayout() line_edit_http_proxy = QLineEdit() self.bind(line_edit_http_proxy, "text", "network/http-proxy") form.addRow("HTTP 代理:", line_edit_http_proxy) line_edit_https_proxy = QLineEdit() self.bind(line_edit_https_proxy, "text", "network/https-proxy") form.addRow("HTTPS 代理:", line_edit_https_proxy) tab.setLayout(form) if self.__macUnified: # Need some sensible size otherwise mac unified toolbar 'takes' # the space that should be used for layout of the contents self.adjustSize()
class PreviewDialog(QDialog): """A Dialog for selecting an item from a PreviewItem. """ currentIndexChanged = Signal(int) def __init__(self, parent=None, flags=Qt.WindowFlags(0), model=None, **kwargs): QDialog.__init__(self, parent, flags, **kwargs) self.__setupUi() if model is not None: self.setModel(model) def __setupUi(self): layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.setContentsMargins(0, 0, 0, 0) heading = self.tr("Preview") heading = u"<h3>{0}</h3>".format(heading) self.__heading = QLabel(heading, self, objectName="heading") self.__heading.setContentsMargins(12, 12, 12, 0) self.__browser = previewbrowser.PreviewBrowser(self) self.__buttons = QDialogButtonBox(QDialogButtonBox.Open | \ QDialogButtonBox.Cancel, Qt.Horizontal,) self.__buttons.button(QDialogButtonBox.Open).setAutoDefault(True) # Set the Open dialog as disabled until the current index changes self.__buttons.button(QDialogButtonBox.Open).setEnabled(False) # The QDialogButtonsWidget messes with the layout if it is # contained directly in the QDialog. So we create an extra # layer of indirection. buttons = QWidget(objectName="button-container") buttons_l = QVBoxLayout() buttons_l.setContentsMargins(12, 0, 12, 12) buttons.setLayout(buttons_l) buttons_l.addWidget(self.__buttons) layout.addWidget(self.__heading) layout.addWidget(self.__browser) layout.addWidget(buttons) self.__buttons.accepted.connect(self.accept) self.__buttons.rejected.connect(self.reject) self.__browser.currentIndexChanged.connect( self.__on_currentIndexChanged) self.__browser.activated.connect(self.__on_activated) layout.setSizeConstraint(QVBoxLayout.SetFixedSize) self.setLayout(layout) self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) def setItems(self, items): """Set the items (a list of strings) for preview/selection. """ model = QStringListModel(items) self.setModel(model) def setModel(self, model): """Set the model for preview/selection. """ self.__browser.setModel(model) def model(self): """Return the model. """ return self.__browser.model() def currentIndex(self): return self.__browser.currentIndex() def setCurrentIndex(self, index): """Set the current selected (shown) index. """ self.__browser.setCurrentIndex(index) def setHeading(self, heading): """Set `heading` as the heading string ('<h3>Preview</h3>' by default). """ self.__heading.setText(heading) def heading(self): """Return the heading string. """ def __on_currentIndexChanged(self, index): button = self.__buttons.button(QDialogButtonBox.Open) button.setEnabled(index >= 0) self.currentIndexChanged.emit(index) def __on_activated(self, index): if self.currentIndex() != index: self.setCurrentIndex(index) self.accept()
def __init__(self): super().__init__() self.data = None # type: Optional[Orange.data.Table] #: The current selected variable index self.selected_index = -1 self._invalidated = False mainlayout = self.mainArea.layout() assert isinstance(mainlayout, QVBoxLayout) layout = QHBoxLayout() mainlayout.addLayout(layout) box = QGroupBox("Variables") box.setLayout(QVBoxLayout()) layout.addWidget(box) self.variables_model = VariableListModel(parent=self) self.variables_view = self.domain_view = QListView( selectionMode=QListView.SingleSelection, uniformItemSizes=True, ) self.variables_view.setItemDelegate(VariableEditDelegate(self)) self.variables_view.setModel(self.variables_model) self.variables_view.selectionModel().selectionChanged.connect( self._on_selection_changed ) box.layout().addWidget(self.variables_view) box = QGroupBox("Edit", ) box.setLayout(QVBoxLayout(margin=4)) layout.addWidget(box) self.editor_stack = QStackedWidget() self.editor_stack.addWidget(DiscreteVariableEditor()) self.editor_stack.addWidget(ContinuousVariableEditor()) self.editor_stack.addWidget(TimeVariableEditor()) self.editor_stack.addWidget(VariableEditor()) box.layout().addWidget(self.editor_stack) bbox = QDialogButtonBox() bbox.setStyleSheet( "button-layout: {:d};".format(QDialogButtonBox.MacLayout)) bapply = QPushButton( "Apply", objectName="button-apply", toolTip="Apply changes and commit data on output.", default=True, autoDefault=False ) bapply.clicked.connect(self.commit) breset = QPushButton( "Reset Selected", objectName="button-reset", toolTip="Rest selected variable to its input state.", autoDefault=False ) breset.clicked.connect(self.reset_selected) breset_all = QPushButton( "Reset All", objectName="button-reset-all", toolTip="Reset all variables to their input state.", autoDefault=False ) breset_all.clicked.connect(self.reset_all) bbox.addButton(bapply, QDialogButtonBox.AcceptRole) bbox.addButton(breset, QDialogButtonBox.ResetRole) bbox.addButton(breset_all, QDialogButtonBox.ResetRole) mainlayout.addWidget(bbox) self.variables_view.setFocus(Qt.NoFocusReason) # initial focus
class PagedDialog(QDialog): """ A paged dialog widget. A paged widget dialog displays a tabbed paged interface """ currentIndexChanged = Signal(int) class BottomBar(QWidget): def paintEvent(self, event): style = self.style() # type: QStyle option = QStyleOption() option.initFrom(self) p = QPainter(self) style.drawPrimitive(QStyle.PE_PanelStatusBar, option, p, self) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setContentsMargins(0, 0, 0, 0) self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().setSpacing(0) self.__pageview = PagedWidget() self.__pageview.currentIndexChanged.connect(self.currentIndexChanged) self.__bottom = PagedDialog.BottomBar(objectName="bottom-area") self.__bottom.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.__bottom.setLayout(QHBoxLayout()) self.__buttons = QDialogButtonBox(objectName="dialog-buttons") self.__buttons.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) self.__buttons.setVisible(False) self.__buttons.rejected.connect(self.reject) self.__bottom.layout().addWidget(self.__buttons) self.layout().addWidget(self.__pageview) self.layout().addWidget(self.__bottom) def currentIndex(self): # type: () -> int return self.__pageview.currentIndex() def setCurrentIndex(self, index): # type: (int) -> None self.__pageview.setCurrentIndex(index) def count(self): # type: () -> int return self.__pageview.count() def addPage(self, icon, text, widget): # type: (QIcon, str, QWidget) -> int return self.__pageview.addPage(icon, text, widget) def insertPage(self, index, icon, text, widget): # type: (int, QIcon, str, QWidget) -> int return self.__pageview.insertPage(index, icon, text, widget) def removePage(self, index): # type: (int) -> None return self.__pageview.removePage(index) def widget(self, index): # type: (int) -> QWidget return self.__pageview.widget(index) def setPageEnabled(self, index, enabled): # type: (int, bool) -> None self.__pageview.setPageEnabled(index, enabled) def isPageEnabled(self, index): # type: (int) -> bool return self.__pageview.isPageEnabled(index) def buttonBox(self): # type: () -> QDialogButtonBox """ Return a QDialogButtonBox instance. """ return self.__buttons
def __run_add_package_dialog(self): dlg = QDialog(self, windowTitle="Add add-on by name") dlg.setAttribute(Qt.WA_DeleteOnClose) vlayout = QVBoxLayout() form = QFormLayout() form.setContentsMargins(0, 0, 0, 0) nameentry = QLineEdit(placeholderText="Package name", toolTip="Enter a package name as displayed on " "PyPI (capitalization is not important)") nameentry.setMinimumWidth(250) form.addRow("Name:", nameentry) vlayout.addLayout(form) buttons = QDialogButtonBox(standardButtons=QDialogButtonBox.Ok | QDialogButtonBox.Cancel) okb = buttons.button(QDialogButtonBox.Ok) okb.setEnabled(False) okb.setText("Add") def changed(name): okb.setEnabled(bool(name)) nameentry.textChanged.connect(changed) vlayout.addWidget(buttons) vlayout.setSizeConstraint(QVBoxLayout.SetFixedSize) dlg.setLayout(vlayout) f = None def query(): nonlocal f name = nameentry.text() f = self._executor.submit(pypi_json_query_project_meta, [name]) okb.setDisabled(True) def ondone(f): error_text = "" error_details = "" try: pkgs = f.result() except Exception: log.error("Query error:", exc_info=True) error_text = "Failed to query package index" error_details = traceback.format_exc() pkg = None else: pkg = pkgs[0] if pkg is None: error_text = "'{}' not was not found".format(name) if pkg: method_queued(self.add_package, (object, ))(pkg) method_queued(dlg.accept, ())() else: method_queued(self.__show_error_for_query, (str, str)) \ (error_text, error_details) method_queued(dlg.reject, ())() f.add_done_callback(ondone) buttons.accepted.connect(query) buttons.rejected.connect(dlg.reject) dlg.exec_()
def __run_add_package_dialog(self): dlg = QDialog(self, windowTitle="Add add-on by name") dlg.setAttribute(Qt.WA_DeleteOnClose) vlayout = QVBoxLayout() form = QFormLayout() form.setContentsMargins(0, 0, 0, 0) nameentry = QLineEdit( placeholderText="Package name", toolTip="Enter a package name as displayed on " "PyPI (capitalization is not important)") nameentry.setMinimumWidth(250) form.addRow("Name:", nameentry) vlayout.addLayout(form) buttons = QDialogButtonBox( standardButtons=QDialogButtonBox.Ok | QDialogButtonBox.Cancel ) okb = buttons.button(QDialogButtonBox.Ok) okb.setEnabled(False) okb.setText("Add") def changed(name): okb.setEnabled(bool(name)) nameentry.textChanged.connect(changed) vlayout.addWidget(buttons) vlayout.setSizeConstraint(QVBoxLayout.SetFixedSize) dlg.setLayout(vlayout) f = None def query(): nonlocal f name = nameentry.text() f = self._executor.submit(pypi_json_query_project_meta, [name]) okb.setDisabled(True) def ondone(f): error_text = "" error_details = "" try: pkgs = f.result() except Exception: log.error("Query error:", exc_info=True) error_text = "Failed to query package index" error_details = traceback.format_exc() pkg = None else: pkg = pkgs[0] if pkg is None: error_text = "'{}' not was not found".format(name) if pkg: method_queued(self.add_package, (object,))(pkg) method_queued(dlg.accept, ())() else: method_queued(self.__show_error_for_query, (str, str)) \ (error_text, error_details) method_queued(dlg.reject, ())() f.add_done_callback(ondone) buttons.accepted.connect(query) buttons.rejected.connect(dlg.reject) dlg.exec_()