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 test_toolbox(self): w = QWidget() layout = QHBoxLayout() reg = global_registry() qt_reg = QtWidgetRegistry(reg) triggered_actions = [] model = qt_reg.model() file_action = qt_reg.action_for_widget( "Orange.widgets.data.owfile.OWFile" ) box = WidgetToolBox() box.setModel(model) box.triggered.connect(triggered_actions.append) layout.addWidget(box) box.setButtonSize(QSize(50, 80)) w.setLayout(layout) w.show() file_action.trigger() box.setButtonSize(QSize(60, 80)) box.setIconSize(QSize(35, 35)) box.setTabButtonHeight(40) box.setTabIconSize(QSize(30, 30)) self.app.exec_()
def __init__(self, parent=None, icon=QIcon(), text="", wordWrap=False, textFormat=Qt.AutoText, standardButtons=NoButton, **kwargs): super().__init__(parent, **kwargs) self.__text = text self.__icon = QIcon() self.__wordWrap = wordWrap self.__standardButtons = MessageWidget.NoButton self._buttons = [] layout = QHBoxLayout() layout.setContentsMargins(8, 0, 8, 0) self.__iconlabel = QLabel(objectName="icon-label") self.__iconlabel.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.__textlabel = QLabel(objectName="text-label", text=text, wordWrap=wordWrap, textFormat=textFormat) if sys.platform == "darwin": self.__textlabel.setAttribute(Qt.WA_MacSmallSize) layout.addWidget(self.__iconlabel) layout.addWidget(self.__textlabel) self.setLayout(layout) self.setIcon(icon) self.setStandardButtons(standardButtons)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setFocusPolicy(Qt.TabFocus) vlayout = QVBoxLayout(spacing=0) vlayout.setContentsMargins(0, 0, 0, 0) self.__currentIndex = -1 self.__contents = QLabel( sizePolicy=QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)) vlayout.addWidget(self.__contents) hlayout = QHBoxLayout(spacing=0) hlayout.setContentsMargins(0, 0, 0, 0) self.__items = items = [ FancyWelcomeScreen.StartItem(objectName="item"), FancyWelcomeScreen.StartItem(objectName="item"), FancyWelcomeScreen.StartItem(objectName="item"), ] items[0].setProperty("-position", QStyleOptionViewItem.Beginning) items[1].setProperty("-position", QStyleOptionViewItem.Middle) items[-1].setProperty("-position", QStyleOptionViewItem.End) for item in items: hlayout.addWidget(item) vlayout.addLayout(hlayout) self.setLayout(vlayout) self.setCurrentIndex(0)
def __init__(self, parent=None, text="", icon=QIcon(), alignment=Qt.AlignTop, wordWrap=False, standardButtons=NoButton, **kwargs): super().__init__(parent, alignment=alignment, **kwargs) layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.__msgwidget = MessageWidget(parent=self, text=text, icon=icon, wordWrap=wordWrap, standardButtons=standardButtons) self.__msgwidget.accepted.connect(self.accepted) self.__msgwidget.rejected.connect(self.rejected) self.__msgwidget.clicked.connect(self.clicked) self.__msgwidget.helpRequested.connect(self.helpRequested) self.__msgwidget.accepted.connect(self.hide) self.__msgwidget.rejected.connect(self.hide) layout.addWidget(self.__msgwidget) self.setLayout(layout)
def __init__(self, widget, model_format, provider_format, model_button_label='Model', provider_button_label='Provider'): QWidget.__init__(self) OWComponent.__init__(self, widget) self.model_path = None layout = QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) self.model_widget = FileWidget(recent_files=self.recent_files, dialog_title='Load model', dialog_format=model_format, start_dir=None, on_open=self.load_model, allow_empty=False, reload_button=False, browse_label=model_button_label) self.model_path = self.recent_files[0] if self.recent_files else None layout.addWidget(self.model_widget) self.provider_widget = FileWidget(recent_files=self.recent_provider, dialog_title='Load provider', dialog_format=provider_format, start_dir=None, on_open=self.load_provider, allow_empty=False, reload_button=False, browse_label=provider_button_label) layout.addWidget(self.provider_widget)
def __init__(self): OWWidget.__init__(self) ConcurrentWidgetMixin.__init__(self) self.corpus = None self.last_config = None # to avoid reruns with the same params self.strings_attrs = [] self.profiler = TweetProfiler(on_server_down=self.Error.server_down) # Settings self.controlArea.layout().addWidget(self.generate_grid_layout()) # Auto commit buttons_layout = QHBoxLayout() buttons_layout.addSpacing(15) buttons_layout.addWidget( gui.auto_commit(None, self, 'auto_commit', 'Commit', box=False) ) self.controlArea.layout().addLayout(buttons_layout) self.cancel_button = QPushButton( 'Cancel', icon=self.style() .standardIcon(QStyle.SP_DialogCancelButton)) self.cancel_button.clicked.connect(self.cancel) hbox = gui.hBox(self.controlArea) hbox.layout().addWidget(self.cancel_button) self.cancel_button.setDisabled(True)
def test_dock_standalone(self): widget = QWidget() layout = QHBoxLayout() widget.setLayout(layout) layout.addStretch(1) widget.show() dock = CollapsibleDockWidget() layout.addWidget(dock) list_view = QListView() list_view.setModel(QStringListModel(["a", "b"], list_view)) label = QLabel("A label. ") label.setWordWrap(True) dock.setExpandedWidget(label) dock.setCollapsedWidget(list_view) dock.setExpanded(True) dock.setExpanded(False) timer = QTimer(dock, interval=50) timer.timeout.connect(lambda: dock.setExpanded(not dock.expanded())) timer.start() self.qWait() timer.stop()
def __init__(self, parent): QFrame.__init__(self, parent) self.setContentsMargins(0, 0, 0, 0) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(1) self._setNameLineEdit = QLineEdit(self) layout.addWidget(self._setNameLineEdit) self._setListView = QListView(self) self._listModel = QStandardItemModel(self) self._proxyModel = QSortFilterProxyModel(self) self._proxyModel.setSourceModel(self._listModel) self._setListView.setModel(self._proxyModel) self._setListView.setItemDelegate(ListItemDelegate(self)) self._setNameLineEdit.textChanged.connect( self._proxyModel.setFilterFixedString) self._completer = QCompleter(self._listModel, self) self._setNameLineEdit.setCompleter(self._completer) self._listModel.itemChanged.connect(self._onSetNameChange) layout.addWidget(self._setListView) buttonLayout = QHBoxLayout() self._addAction = QAction( "+", self, toolTip="Add a new sort key") self._updateAction = QAction( "Update", self, toolTip="Update/save current selection") self._removeAction = QAction( "\u2212", self, toolTip="Remove selected sort key.") self._addToolButton = QToolButton(self) self._updateToolButton = QToolButton(self) self._removeToolButton = QToolButton(self) self._updateToolButton.setSizePolicy( QSizePolicy.MinimumExpanding, QSizePolicy.Minimum) self._addToolButton.setDefaultAction(self._addAction) self._updateToolButton.setDefaultAction(self._updateAction) self._removeToolButton.setDefaultAction(self._removeAction) buttonLayout.addWidget(self._addToolButton) buttonLayout.addWidget(self._updateToolButton) buttonLayout.addWidget(self._removeToolButton) layout.addLayout(buttonLayout) self.setLayout(layout) self._addAction.triggered.connect(self.addCurrentSelection) self._updateAction.triggered.connect(self.updateSelectedSelection) self._removeAction.triggered.connect(self.removeSelectedSelection) self._setListView.selectionModel().selectionChanged.connect( self._onListViewSelectionChanged) self.selectionModel = None self._selections = []
def __init__(self, parent=None, icon=QIcon(), text="", wordWrap=False, textFormat=Qt.AutoText, standardButtons=NoButton, **kwargs): super().__init__(parent, **kwargs) self.__text = text self.__icon = QIcon() self.__wordWrap = wordWrap self.__standardButtons = MessageWidget.NoButton self.__buttons = [] layout = QHBoxLayout() layout.setContentsMargins(8, 0, 8, 0) self.__iconlabel = QLabel(objectName="icon-label") self.__iconlabel.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.__textlabel = QLabel(objectName="text-label", text=text, wordWrap=wordWrap, textFormat=textFormat) if sys.platform == "darwin": self.__textlabel.setAttribute(Qt.WA_MacSmallSize) layout.addWidget(self.__iconlabel) layout.addWidget(self.__textlabel) self.setLayout(layout) self.setIcon(icon) self.setStandardButtons(standardButtons)
def test_dock_standalone(self): widget = QWidget() layout = QHBoxLayout() widget.setLayout(layout) layout.addStretch(1) widget.show() dock = CollapsibleDockWidget() layout.addWidget(dock) list_view = QListView() list_view.setModel(QStringListModel(["a", "b"], list_view)) label = QLabel("A label. ") label.setWordWrap(True) dock.setExpandedWidget(label) dock.setCollapsedWidget(list_view) dock.setExpanded(True) self.app.processEvents() def toogle(): dock.setExpanded(not dock.expanded()) self.singleShot(2000, toogle) toogle() self.app.exec_()
def setupUi(self): self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().setSpacing(0) self.__mainLayout = QVBoxLayout() self.__mainLayout.setContentsMargins(0, 40, 0, 40) self.__mainLayout.setSpacing(65) self.layout().addLayout(self.__mainLayout) self.setStyleSheet(WELCOME_WIDGET_BUTTON_STYLE) bottom_bar = QWidget(objectName="bottom-bar") bottom_bar_layout = QHBoxLayout() bottom_bar_layout.setContentsMargins(20, 10, 20, 10) bottom_bar.setLayout(bottom_bar_layout) bottom_bar.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Maximum) check = QCheckBox(self.tr("Show at startup"), bottom_bar) check.setChecked(False) self.__showAtStartupCheck = check bottom_bar_layout.addWidget(check, alignment=Qt.AlignVCenter | \ Qt.AlignLeft) self.layout().addWidget(bottom_bar, alignment=Qt.AlignBottom, stretch=1) self.setSizeGripEnabled(False) self.setFixedSize(620, 390)
def test_toolbox(self): w = QWidget() layout = QHBoxLayout() reg = registry_tests.small_testing_registry() qt_reg = QtWidgetRegistry(reg) triggered_actions = [] model = qt_reg.model() one_action = qt_reg.action_for_widget("one") box = WidgetToolBox() box.setModel(model) box.triggered.connect(triggered_actions.append) layout.addWidget(box) box.setButtonSize(QSize(50, 80)) w.setLayout(layout) w.show() one_action.trigger() box.setButtonSize(QSize(60, 80)) box.setIconSize(QSize(35, 35)) box.setTabButtonHeight(40) box.setTabIconSize(QSize(30, 30)) self.app.exec_()
def add_row(self): def sync_combos(): combo = self.sender() index = combo.currentIndex() model = combo.model() other = ({row_items.left_combo, row_items.right_combo} - {combo}).pop() other_index = other.currentIndex() other_model = other.model() if 0 <= index < len(combo.model()): var = model[index] if isinstance(var, str): other.setCurrentText(model[index]) elif isinstance(other_model[other_index], str): for other_var in other_model: if isinstance(other_var, Variable) \ and var.name == other_var.name \ and (type(other_var) is type(var) or (not var.is_continuous and not other_var.is_continuous)): other.setCurrentText(var.name) break self.emit_list() def get_combo(model): combo = QComboBox(self) combo.setModel(model) # We use signal activated because it is triggered only on user # interaction, not programmatically. combo.activated.connect(sync_combos) return combo def get_button(label, callback): button = QPushButton(label, self) button.setFlat(True) button.setFixedWidth(12) button.clicked.connect(callback) return button row = self.layout().count() row_items = self.RowItems( QLabel("and" if row else self.pre_label), get_combo(self.model_left), QLabel(self.in_label), get_combo(self.model_right), get_button("×", self.on_remove_row), get_button("+", self.on_add_row) ) layout = QHBoxLayout() layout.setSpacing(10) self.layout().addLayout(layout) layout.addStretch(10) for item in row_items: layout.addWidget(item) self.rows.append(row_items) self._reset_buttons()
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 _setup_gui_labels(self): vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) vlayout.setSpacing(1) self.labels_edit = QTreeView() self.labels_edit.setEditTriggers(QTreeView.CurrentChanged) self.labels_edit.setRootIsDecorated(False) self.labels_model = DictItemsModel() self.labels_edit.setModel(self.labels_model) self.labels_edit.selectionModel().selectionChanged.connect( self.on_label_selection_changed) # Necessary signals to know when the labels change self.labels_model.dataChanged.connect(self.on_labels_changed) self.labels_model.rowsInserted.connect(self.on_labels_changed) self.labels_model.rowsRemoved.connect(self.on_labels_changed) vlayout.addWidget(self.labels_edit) hlayout = QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) hlayout.setSpacing(1) self.add_label_action = QAction( "+", self, toolTip="Add a new label.", triggered=self.on_add_label, enabled=False, shortcut=QKeySequence(QKeySequence.New), ) self.remove_label_action = QAction( unicodedata.lookup("MINUS SIGN"), self, toolTip="Remove selected label.", triggered=self.on_remove_label, enabled=False, shortcut=QKeySequence(QKeySequence.Delete), ) button_size = gui.toolButtonSizeHint() button_size = QSize(button_size, button_size) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.add_label_action) hlayout.addWidget(button) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.remove_label_action) hlayout.addWidget(button) hlayout.addStretch(10) vlayout.addLayout(hlayout) self.main_form.addRow("Labels:", vlayout)
def _setup_gui_labels(self): vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) vlayout.setSpacing(1) self.labels_edit = QTreeView() self.labels_edit.setEditTriggers(QTreeView.CurrentChanged) self.labels_edit.setRootIsDecorated(False) self.labels_model = DictItemsModel() self.labels_edit.setModel(self.labels_model) self.labels_edit.selectionModel().selectionChanged.connect( self.on_label_selection_changed) # Necessary signals to know when the labels change self.labels_model.dataChanged.connect(self.on_labels_changed) self.labels_model.rowsInserted.connect(self.on_labels_changed) self.labels_model.rowsRemoved.connect(self.on_labels_changed) vlayout.addWidget(self.labels_edit) hlayout = QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) hlayout.setSpacing(1) self.add_label_action = QAction( "+", self, toolTip="Add a new label.", triggered=self.on_add_label, enabled=False, shortcut=QKeySequence(QKeySequence.New)) self.remove_label_action = QAction( unicodedata.lookup("MINUS SIGN"), self, toolTip="Remove selected label.", triggered=self.on_remove_label, enabled=False, shortcut=QKeySequence(QKeySequence.Delete)) button_size = gui.toolButtonSizeHint() button_size = QSize(button_size, button_size) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.add_label_action) hlayout.addWidget(button) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.remove_label_action) hlayout.addWidget(button) hlayout.addStretch(10) vlayout.addLayout(hlayout) self.main_form.addRow("Labels:", vlayout)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) layout = QFormLayout( fieldGrowthPolicy=QFormLayout.ExpandingFieldsGrow ) layout.setContentsMargins(0, 0, 0, 0) self.nameedit = QLineEdit( placeholderText="Name...", sizePolicy=QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) ) self.expressionedit = QLineEdit( placeholderText="Expression..." ) self.attrs_model = itemmodels.VariableListModel( ["Select Feature"], parent=self) self.attributescb = QComboBox( minimumContentsLength=16, sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon, sizePolicy=QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) ) self.attributescb.setModel(self.attrs_model) sorted_funcs = sorted(self.FUNCTIONS) self.funcs_model = itemmodels.PyListModelTooltip() self.funcs_model.setParent(self) self.funcs_model[:] = chain(["Select Function"], sorted_funcs) self.funcs_model.tooltips[:] = chain( [''], [self.FUNCTIONS[func].__doc__ for func in sorted_funcs]) self.functionscb = QComboBox( minimumContentsLength=16, sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon, sizePolicy=QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)) self.functionscb.setModel(self.funcs_model) hbox = QHBoxLayout() hbox.addWidget(self.attributescb) hbox.addWidget(self.functionscb) layout.addRow(self.nameedit, self.expressionedit) layout.addRow(self.tr(""), hbox) self.setLayout(layout) self.nameedit.editingFinished.connect(self._invalidate) self.expressionedit.textChanged.connect(self._invalidate) self.attributescb.currentIndexChanged.connect(self.on_attrs_changed) self.functionscb.currentIndexChanged.connect(self.on_funcs_changed) self._modified = False
def __init__(self, parent=None, **kwargs): super(AddonManagerWidget, self).__init__(parent, **kwargs) self.__items = [] self.setLayout(QVBoxLayout()) self.__header = QLabel(wordWrap=True, textFormat=Qt.RichText) self.__search = QLineEdit(placeholderText=self.tr("Filter")) self.__only_trusted = QCheckBox(self.tr("Show only trusted add-ons"), ) topline = QHBoxLayout() topline.addWidget(self.__search) topline.addWidget(self.__only_trusted) self.layout().addLayout(topline) self.__only_trusted.setChecked(True) self.show_only_trusted = True self.__only_trusted.stateChanged.connect( self._show_only_trusted_changed) self.__view = view = QTreeView(rootIsDecorated=False, editTriggers=QTreeView.NoEditTriggers, selectionMode=QTreeView.SingleSelection, alternatingRowColors=True) self.__view.setItemDelegateForColumn(0, TristateCheckItemDelegate()) self.layout().addWidget(view) self.__model = model = QStandardItemModel() model.setHorizontalHeaderLabels(["", "Name", "Version", "Action"]) model.dataChanged.connect(self.__data_changed) self.__proxy = proxy = SortFilterProxyTrusted( filterKeyColumn=1, filterCaseSensitivity=Qt.CaseInsensitive) proxy.setSourceModel(model) self.__search.textChanged.connect(proxy.setFilterFixedString) view.setModel(proxy) view.selectionModel().selectionChanged.connect(self.__update_details) header = self.__view.header() header.setSectionResizeMode(0, QHeaderView.Fixed) header.setSectionResizeMode(2, QHeaderView.ResizeToContents) self.__details = QTextBrowser( frameShape=QTextBrowser.NoFrame, readOnly=True, lineWrapMode=QTextBrowser.WidgetWidth, openExternalLinks=True, ) self.__details.setWordWrapMode(QTextOption.WordWrap) palette = QPalette(self.palette()) palette.setColor(QPalette.Base, Qt.transparent) self.__details.setPalette(palette) self.layout().addWidget(self.__details)
def __init__(self, parent, title="", text="", textFormat=Qt.AutoText, icon=QIcon(), wordWrap=True, standardButtons=NoButton, acceptLabel="Ok", rejectLabel="No", **kwargs): super().__init__(parent, **kwargs) self._dismissMargin = 10 layout = QHBoxLayout() if sys.platform == "darwin": layout.setContentsMargins(6, 6, 6, 6) else: layout.setContentsMargins(9, 9, 9, 9) self._msgWidget = NotificationMessageWidget( parent=self, title=title, text=text, textFormat=textFormat, icon=icon, wordWrap=wordWrap, standardButtons=standardButtons, acceptLabel=acceptLabel, rejectLabel=rejectLabel) self.dismissButton = DismissButton( parent=self, icon=QIcon(self.style().standardIcon( QStyle.SP_TitleBarCloseButton))) self.dismissButton.setFixedSize(18, 18) self.dismissButton.clicked.connect(self.dismissed) def dismiss_handler(): self.clicked.emit(self.dismissButton) self.dismissButton.clicked.connect(dismiss_handler) self._msgWidget.accepted.connect(self.accepted) self._msgWidget.rejected.connect(self.rejected) self._msgWidget.clicked.connect(self.clicked) layout.addWidget(self._msgWidget) self.setLayout(layout) self.setFixedWidth(400)
def _setup_gui_values(self): vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) vlayout.setSpacing(1) self.values_edit = QListView() self.values_edit.setEditTriggers(QTreeView.CurrentChanged) self.values_model = itemmodels.PyListModel(flags=Qt.ItemIsSelectable | \ Qt.ItemIsEnabled | Qt.ItemIsEditable) self.values_edit.setModel(self.values_model) self.values_edit.selectionModel().selectionChanged.connect( self.on_value_selection_changed) self.values_model.dataChanged.connect(self.on_values_changed) vlayout.addWidget(self.values_edit) hlayout = QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) hlayout.setSpacing(1) self.move_value_up = QAction(unicodedata.lookup("UPWARDS ARROW"), self, toolTip="Move up.", triggered=self.move_up, enabled=False, shortcut=QKeySequence(QKeySequence.New)) self.move_value_down = QAction(unicodedata.lookup("DOWNWARDS ARROW"), self, toolTip="Move down.", triggered=self.move_down, enabled=False, shortcut=QKeySequence( QKeySequence.Delete)) button_size = gui.toolButtonSizeHint() button_size = QSize(button_size, button_size) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.move_value_up) hlayout.addWidget(button) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.move_value_down) hlayout.addWidget(button) hlayout.addStretch(10) vlayout.addLayout(hlayout) self.main_form.addRow("Values:", vlayout)
def __init__(self): super().__init__() self.corpus = None self.method = None box = QGroupBox(title='选项') box.setLayout(self.create_configuration_layout()) self.controlArea.layout().addWidget(box) buttons_layout = QHBoxLayout() buttons_layout.addSpacing(15) buttons_layout.addWidget( gui.auto_commit(None, self, 'autocommit', '提交', '自动提交', box=False)) self.controlArea.layout().addLayout(buttons_layout) self.update_method()
def __init__(self, widget, master, attribute, minimum=0., maximum=1., step=.05, min_label=None, max_label=None, allow_absolute=False, dtype=float, callback=None, *args): super().__init__(*args) if widget: widget.layout().addWidget(self) self.allow_absolute_values = allow_absolute self.master = master self.attribute = attribute self.min = minimum self.max = maximum self.step = step self.min_label = min_label self.max_label = max_label a, b = self.master_value() layout = QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) if self.allow_absolute_values: SpinBox = AbsoluteRelativeSpinBox else: if dtype == float: SpinBox = QDoubleSpinBox else: SpinBox = QSpinBox if self.min_label: layout.addWidget(QLabel(self.min_label)) self.min_spin = SpinBox(value=a) self.min_spin.setSingleStep(self.step) layout.addWidget(self.min_spin) if self.max_label: layout.addWidget(QLabel(self.max_label)) self.max_spin = SpinBox(value=b) self.max_spin.setSingleStep(self.step) layout.addWidget(self.max_spin) self.set_range() self.min_spin.valueChanged.connect(self.synchronize) self.min_spin.editingFinished.connect(self.editingFinished) self.max_spin.valueChanged.connect(self.synchronize) self.max_spin.editingFinished.connect(self.editingFinished) if callback: self.valueChanged.connect(callback)
def __init__(self, state=AVAILABLE, parent=None): QWidget.__init__(self, parent) layout = QHBoxLayout() layout.setSpacing(1) layout.setContentsMargins(1, 1, 1, 1) self.checkButton = QCheckBox() layout.addWidget(self.checkButton) self.setLayout(layout) self.setMinimumHeight(20) self.setMaximumHeight(20) self._state = state self._update()
def __init__(self, state=AVAILABLE, parent=None): QWidget.__init__(self, parent) layout = QHBoxLayout() layout.setSpacing(1) layout.setContentsMargins(1, 1, 1, 1) self.checkButton = QCheckBox() layout.addWidget(self.checkButton) self.setLayout(layout) self.setMinimumHeight(20) self.setMaximumHeight(20) self.state = -1 self.setState(state)
def __init__(self): super().__init__() self.corpus = None self.last_config = None # to avoid reruns with the same params self.strings_attrs = [] self.profiler = TweetProfiler(on_server_down=self.Error.server_down) # Settings self.controlArea.layout().addWidget(self.generate_grid_layout()) # Auto commit buttons_layout = QHBoxLayout() buttons_layout.addSpacing(15) buttons_layout.addWidget( gui.auto_commit(None, self, 'auto_commit', 'Commit', box=False)) self.controlArea.layout().addLayout(buttons_layout)
def __init__(self): super().__init__() self.corpus = None self.method = None box = QGroupBox(title='Options') box.setLayout(self.create_configuration_layout()) self.controlArea.layout().addWidget(box) buttons_layout = QHBoxLayout() buttons_layout.addSpacing(15) buttons_layout.addWidget( gui.auto_commit(None, self, 'autocommit', 'Commit', box=False) ) self.controlArea.layout().addLayout(buttons_layout) self.update_method()
def __init__(self, parent=None, label=""): QWidget.__init__(self, parent) OWComponent.__init__(self, None) layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) self.position = 0 self.edit = lineEditFloatRange(self, self, "position", callback=self.edited.emit) layout.addWidget(self.edit) self.edit.focusIn.connect(self.focusIn.emit) self.line = MovableVline(position=self.position, label=label) connect_line(self.line, self, "position") self.line.sigMoveFinished.connect(self.edited.emit)
def test_widgettoolgrid(self): w = QWidget() layout = QHBoxLayout() reg = global_registry() qt_reg = QtWidgetRegistry(reg) triggered_actions1 = [] triggered_actions2 = [] model = qt_reg.model() data_descriptions = qt_reg.widgets("Data") file_action = qt_reg.action_for_widget( "Orange.widgets.data.owfile.OWFile" ) actions = list(map(qt_reg.action_for_widget, data_descriptions)) grid = ToolGrid(w) grid.setActions(actions) grid.actionTriggered.connect(triggered_actions1.append) layout.addWidget(grid) grid = WidgetToolGrid(w) # First category ("Data") grid.setModel(model, rootIndex=model.index(0, 0)) self.assertIs(model, grid.model()) # Test order of buttons grid_layout = grid.layout() for i in range(len(actions)): button = grid_layout.itemAtPosition(i / 4, i % 4).widget() self.assertIs(button.defaultAction(), actions[i]) grid.actionTriggered.connect(triggered_actions2.append) layout.addWidget(grid) w.setLayout(layout) w.show() file_action.trigger() self.app.exec_()
def __init__(self): super().__init__() self.corpus = None self.last_config = None # to avoid reruns with the same params self.strings_attrs = [] self.profiler = TweetProfiler(on_server_down=self.Error.server_down) # Settings self.controlArea.layout().addWidget(self.generate_grid_layout()) # Auto commit buttons_layout = QHBoxLayout() buttons_layout.addSpacing(15) buttons_layout.addWidget( gui.auto_commit(None, self, 'auto_commit', 'Commit', box=False) ) self.controlArea.layout().addLayout(buttons_layout)
def __setupUi(self): vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) top_layout = QHBoxLayout() top_layout.setContentsMargins(12, 12, 12, 12) # Top row with full text description and a large preview # image. self.__label = QLabel( self, objectName="description-label", wordWrap=True, alignment=Qt.AlignTop | Qt.AlignLeft, ) self.__label.setWordWrap(True) self.__label.setFixedSize(220, PREVIEW_SIZE[1]) self.__image = QSvgWidget(self, objectName="preview-image") self.__image.setFixedSize(*PREVIEW_SIZE) self.__imageFrame = DropShadowFrame(self) self.__imageFrame.setWidget(self.__image) # Path text below the description and image path_layout = QHBoxLayout() path_layout.setContentsMargins(12, 0, 12, 0) path_label = QLabel("<b>{0!s}</b>".format(self.tr("Path:")), self, objectName="path-label") self.__path = TextLabel(self, objectName="path-text") path_layout.addWidget(path_label) path_layout.addWidget(self.__path) self.__selectAction = QAction(self.tr("Select"), self, objectName="select-action") top_layout.addWidget(self.__label, 1, alignment=Qt.AlignTop | Qt.AlignLeft) top_layout.addWidget(self.__image, 1, alignment=Qt.AlignTop | Qt.AlignRight) vlayout.addLayout(top_layout) vlayout.addLayout(path_layout) # An list view with small preview icons. self.__previewList = LinearIconView(objectName="preview-list-view") self.__previewList.doubleClicked.connect(self.__onDoubleClicked) vlayout.addWidget(self.__previewList) self.setLayout(vlayout)
def test_widgettoolgrid(self): w = QWidget() layout = QHBoxLayout() reg = global_registry() qt_reg = QtWidgetRegistry(reg) triggered_actions1 = [] triggered_actions2 = [] model = qt_reg.model() data_descriptions = qt_reg.widgets("Data") file_action = qt_reg.action_for_widget( "Orange.widgets.data.owfile.OWFile") actions = list(map(qt_reg.action_for_widget, data_descriptions)) grid = ToolGrid(w) grid.setActions(actions) grid.actionTriggered.connect(triggered_actions1.append) layout.addWidget(grid) grid = WidgetToolGrid(w) # First category ("Data") grid.setModel(model, rootIndex=model.index(0, 0)) self.assertIs(model, grid.model()) # Test order of buttons grid_layout = grid.layout() for i in range(len(actions)): button = grid_layout.itemAtPosition(i / 4, i % 4).widget() self.assertIs(button.defaultAction(), actions[i]) grid.actionTriggered.connect(triggered_actions2.append) layout.addWidget(grid) w.setLayout(layout) w.show() file_action.trigger() self.app.exec_()
def setupUi(self): self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().setSpacing(0) self.__mainLayout = QVBoxLayout() self.__mainLayout.setContentsMargins(0, 40, 0, 40) self.__mainLayout.setSpacing(65) self.layout().addLayout(self.__mainLayout) self.setStyleSheet(WELCOME_WIDGET_BUTTON_STYLE) bottom_bar = QWidget(objectName="bottom-bar") bottom_bar_layout = QHBoxLayout() bottom_bar_layout.setContentsMargins(20, 10, 20, 10) bottom_bar.setLayout(bottom_bar_layout) bottom_bar.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Maximum) check = QCheckBox(self.tr("启动显示"), bottom_bar) check.setChecked(False) self.__showAtStartupCheck = check """ feedback = QLabel( '<a href="http://orange.biolab.si/survey/long.html">Help us improve!</a>') feedback.setTextInteractionFlags(Qt.TextBrowserInteraction) feedback.setOpenExternalLinks(True) """ bottom_bar_layout.addWidget(check, alignment=Qt.AlignVCenter | \ Qt.AlignLeft) """ bottom_bar_layout.addWidget(feedback, alignment=Qt.AlignVCenter | \ Qt.AlignRight) """ self.layout().addWidget(bottom_bar, alignment=Qt.AlignBottom, stretch=1) self.setSizeGripEnabled(False) self.setFixedSize(620, 390)
def __init__(self, parent=None, text="", icon=QIcon(), alignment=Qt.AlignTop, wordWrap=False, standardButtons=NoButton, **kwargs): super().__init__(parent, alignment=alignment, **kwargs) layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.__msgwidget = MessageWidget( parent=self, text=text, icon=icon, wordWrap=wordWrap, standardButtons=standardButtons ) self.__msgwidget.accepted.connect(self.accepted) self.__msgwidget.rejected.connect(self.rejected) self.__msgwidget.clicked.connect(self.clicked) self.__msgwidget.helpRequested.connect(self.helpRequested) self.__msgwidget.accepted.connect(self.hide) self.__msgwidget.rejected.connect(self.hide) layout.addWidget(self.__msgwidget) self.setLayout(layout)
def __init__(self, parent=None, **kwargs): BaseEditor.__init__(self, parent, **kwargs) self.__method = DiscretizeEditor.EqualFreq self.__nintervals = 4 layout = QVBoxLayout() self.setLayout(layout) self.__group = group = QButtonGroup(self, exclusive=True) for method in [ self.EntropyMDL, self.EqualFreq, self.EqualWidth, self.Drop ]: rb = QRadioButton(self, text=self.Names[method], checked=self.__method == method) layout.addWidget(rb) group.addButton(rb, method) group.buttonClicked.connect(self.__on_buttonClicked) self.__slbox = slbox = QGroupBox( title="间隔数(等宽/等频)Number of intervals (for equal width/frequency)", flat=True) slbox.setLayout(QHBoxLayout()) self.__slider = slider = QSlider(orientation=Qt.Horizontal, minimum=2, maximum=10, value=self.__nintervals, enabled=self.__method in [self.EqualFreq, self.EqualWidth], pageStep=1, tickPosition=QSlider.TicksBelow) slider.valueChanged.connect(self.__on_valueChanged) slbox.layout().addWidget(slider) self.__slabel = slabel = QLabel() slbox.layout().addWidget(slabel) container = QHBoxLayout() container.setContentsMargins(13, 0, 0, 0) container.addWidget(slbox) self.layout().insertLayout(3, container) self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred)
def __init__(self, parent=None, **kwargs): # type: (Optional[QWidget], Any) -> None super().__init__(parent, **kwargs) self.__currentIndex = -1 layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(6) self.__tab = TabBarWidget(self) self.__tab.currentChanged.connect(self.setCurrentIndex) self.__tab.setChangeOnHover(True) self.__stack = MenuStackWidget(self) layout.addWidget(self.__tab, alignment=Qt.AlignTop) layout.addWidget(self.__stack) self.setLayout(layout)
def __init__(self, parent=None, **kwargs): QWidget.__init__(self, parent, **kwargs) self.__pages = [] self.__currentIndex = -1 layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(6) self.__tab = TabBarWidget(self) self.__tab.currentChanged.connect(self.setCurrentIndex) self.__tab.setChangeOnHover(True) self.__stack = MenuStackWidget(self) layout.addWidget(self.__tab, alignment=Qt.AlignTop) layout.addWidget(self.__stack) self.setLayout(layout)
def __setupUi(self): vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) top_layout = QHBoxLayout() top_layout.setContentsMargins(12, 12, 12, 12) # Top row with full text description and a large preview # image. self.__label = QLabel(self, objectName="description-label", wordWrap=True, alignment=Qt.AlignTop | Qt.AlignLeft) self.__label.setWordWrap(True) self.__label.setFixedSize(220, PREVIEW_SIZE[1]) self.__image = QSvgWidget(self, objectName="preview-image") self.__image.setFixedSize(*PREVIEW_SIZE) self.__imageFrame = DropShadowFrame(self) self.__imageFrame.setWidget(self.__image) # Path text below the description and image path_layout = QHBoxLayout() path_layout.setContentsMargins(12, 0, 12, 0) path_label = QLabel("<b>{0!s}</b>".format(self.tr("Path:")), self, objectName="path-label") self.__path = TextLabel(self, objectName="path-text") path_layout.addWidget(path_label) path_layout.addWidget(self.__path) self.__selectAction = \ QAction(self.tr("Select"), self, objectName="select-action", ) top_layout.addWidget(self.__label, 1, alignment=Qt.AlignTop | Qt.AlignLeft) top_layout.addWidget(self.__image, 1, alignment=Qt.AlignTop | Qt.AlignRight) vlayout.addLayout(top_layout) vlayout.addLayout(path_layout) # An list view with small preview icons. self.__previewList = LinearIconView(objectName="preview-list-view") self.__previewList.doubleClicked.connect(self.__onDoubleClicked) vlayout.addWidget(self.__previewList) self.setLayout(vlayout)
def __init__(self, parent=None, **kwargs): BaseEditor.__init__(self, parent, **kwargs) self.__method = DiscretizeEditor.EqualFreq self.__nintervals = 4 layout = QVBoxLayout() self.setLayout(layout) self.__group = group = QButtonGroup(self, exclusive=True) for method in [self.EntropyMDL, self.EqualFreq, self.EqualWidth, self.Drop]: rb = QRadioButton( self, text=self.Names[method], checked=self.__method == method ) layout.addWidget(rb) group.addButton(rb, method) group.buttonClicked.connect(self.__on_buttonClicked) self.__slbox = slbox = QGroupBox( title="Number of intervals (for equal width/frequency)", flat=True ) slbox.setLayout(QHBoxLayout()) self.__slider = slider = QSlider( orientation=Qt.Horizontal, minimum=2, maximum=10, value=self.__nintervals, enabled=self.__method in [self.EqualFreq, self.EqualWidth], pageStep=1, tickPosition=QSlider.TicksBelow ) slider.valueChanged.connect(self.__on_valueChanged) slbox.layout().addWidget(slider) self.__slabel = slabel = QLabel() slbox.layout().addWidget(slabel) container = QHBoxLayout() container.setContentsMargins(13, 0, 0, 0) container.addWidget(slbox) self.layout().insertLayout(3, container) self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred)
def init_form(self): self._boundingbox = GaugeWidgetHorizontal() if self._horizontal else GaugeWidgetVertical() self._boundingbox.changed_event = self.__update if self._show_spinboxes: self._form = hwidget = QWidget() if self._horizontal: hlayout = QHBoxLayout() else: hlayout = QVBoxLayout() if _api.USED_API == _api.QT_API_PYQT5: hlayout.setContentsMargins(0,0,0,0) elif _api.USED_API == _api.QT_API_PYQT4: hlayout.setMargin(0) hwidget.setLayout(hlayout) self._min_spinbox = QSpinBox() self._min_spinbox.valueChanged.connect(self.__min_spinbox_changed) self._min_spinbox.setMaximumWidth(95) self._max_spinbox = QSpinBox() self._max_spinbox.valueChanged.connect(self.__max_spinbox_changed) self._max_spinbox.setMaximumWidth(95) if self._horizontal: hlayout.addWidget(self._min_spinbox) else: hlayout.addWidget(self._max_spinbox) hlayout.addWidget(self._boundingbox) if self._horizontal: hlayout.addWidget(self._max_spinbox) else: hlayout.addWidget(self._min_spinbox) else: self._form = self._boundingbox super(ControlBoundingSlider, self).init_form()
def button(id_, *controls, stretch=True): layout = QHBoxLayout() desc = Options[id_] button = QRadioButton(desc.label) button.setToolTip(desc.tooltip) self.button_group.addButton(button, id_) layout.addWidget(button) if controls: if stretch: layout.addStretch(1) for c, signal in controls: layout.addWidget(c) if signal is not None: @signal.connect def arg_changed(): self.button_group.button(id_).setChecked(True) self.update_hints(id_) children.append(layout) button_box.layout().addLayout(layout) return (*controls, (None, ))[0][0]
def setupUi(self): self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().setSpacing(0) self.__mainLayout = QVBoxLayout() self.__mainLayout.setContentsMargins(0, 40, 0, 40) self.__mainLayout.setSpacing(65) self.layout().addLayout(self.__mainLayout) self.setStyleSheet(WELCOME_WIDGET_BUTTON_STYLE) bottom_bar = QWidget(objectName="bottom-bar") bottom_bar_layout = QHBoxLayout() bottom_bar_layout.setContentsMargins(20, 10, 20, 10) bottom_bar.setLayout(bottom_bar_layout) bottom_bar.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Maximum) self.__showAtStartupCheck = QCheckBox( self.tr("Show at startup"), bottom_bar, checked=False ) self.__feedbackLabel = QLabel( textInteractionFlags=Qt.TextBrowserInteraction, openExternalLinks=True, visible=False, ) bottom_bar_layout.addWidget( self.__showAtStartupCheck, alignment=Qt.AlignVCenter | Qt.AlignLeft ) bottom_bar_layout.addWidget( self.__feedbackLabel, alignment=Qt.AlignVCenter | Qt.AlignRight ) self.layout().addWidget(bottom_bar, alignment=Qt.AlignBottom, stretch=1) self.setSizeGripEnabled(False) self.setFixedSize(620, 390)
def setupUi(self): self.setLayout(QVBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().setSpacing(0) self.__mainLayout = QVBoxLayout() self.__mainLayout.setContentsMargins(0, 40, 0, 40) self.__mainLayout.setSpacing(65) self.layout().addLayout(self.__mainLayout) self.setStyleSheet(WELCOME_WIDGET_BUTTON_STYLE) bottom_bar = QWidget(objectName="bottom-bar") bottom_bar_layout = QHBoxLayout() bottom_bar_layout.setContentsMargins(20, 10, 20, 10) bottom_bar.setLayout(bottom_bar_layout) bottom_bar.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Maximum) check = QCheckBox(self.tr("Show at startup"), bottom_bar) check.setChecked(False) self.__showAtStartupCheck = check feedback = QLabel( '<a href="http://orange.biolab.si/survey/long.html">Help us improve!</a>') feedback.setTextInteractionFlags(Qt.TextBrowserInteraction) feedback.setOpenExternalLinks(True) bottom_bar_layout.addWidget(check, alignment=Qt.AlignVCenter | \ Qt.AlignLeft) bottom_bar_layout.addWidget(feedback, alignment=Qt.AlignVCenter | \ Qt.AlignRight) self.layout().addWidget(bottom_bar, alignment=Qt.AlignBottom, stretch=1) self.setSizeGripEnabled(False) self.setFixedSize(620, 390)
def __setupUi(self): vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) top_layout = QVBoxLayout(objectName="top-layout") margin = self.__margin top_layout.setContentsMargins(margin, margin, margin, margin) # Optional heading label self.__heading = QLabel( self, objectName="heading", visible=False ) # Horizontal row with full text description and a large preview # image. hlayout = QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) self.__label = QLabel( self, objectName="description-label", wordWrap=True, alignment=Qt.AlignTop | Qt.AlignLeft ) self.__label.setWordWrap(True) self.__label.setFixedSize(220, PREVIEW_SIZE[1]) self.__label.setMinimumWidth(PREVIEW_SIZE[0] // 2) self.__label.setMaximumHeight(PREVIEW_SIZE[1]) self.__image = QSvgWidget(self, objectName="preview-image") self.__image.setFixedSize(*PREVIEW_SIZE) self.__imageFrame = DropShadowFrame(self) self.__imageFrame.setWidget(self.__image) hlayout.addWidget(self.__label) hlayout.addWidget(self.__image) # Path text below the description and image path_layout = QHBoxLayout() path_layout.setContentsMargins(0, 0, 0, 0) path_label = QLabel("<b>{0!s}</b>".format(self.tr("Path:")), self, objectName="path-label") self.__path = TextLabel(self, objectName="path-text") path_layout.addWidget(path_label) path_layout.addWidget(self.__path) top_layout.addWidget(self.__heading) top_layout.addLayout(hlayout) top_layout.addLayout(path_layout) vlayout.addLayout(top_layout) # An list view with small preview icons. self.__previewList = LinearIconView( objectName="preview-list-view", wordWrap=True ) self.__previewList.doubleClicked.connect(self.__onDoubleClicked) vlayout.addWidget(self.__previewList) self.setLayout(vlayout)
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, widget, model_format, provider_format, model_button_label='Model', provider_button_label='Provider'): QWidget.__init__(self) OWComponent.__init__(self, widget) self.model_path = None layout = QHBoxLayout(self, spacing=0) layout.setContentsMargins(0, 0, 0, 0) self.model_widget = FileWidget(recent_files=self.recent_files, dialog_title='Load model', dialog_format=model_format, start_dir=None, on_open=self.load_model, allow_empty=False, reload_button=False, browse_label=model_button_label) self.model_path = self.recent_files[0] if self.recent_files else None layout.addWidget(self.model_widget) self.provider_widget = FileWidget(recent_files=None, dialog_title='Load provider', dialog_format=provider_format, start_dir=None, on_open=self.load_provider, allow_empty=False, reload_button=False, browse_label=provider_button_label) layout.addWidget(self.provider_widget)
def test_dock_standalone(self): widget = QWidget() layout = QHBoxLayout() widget.setLayout(layout) layout.addStretch(1) widget.show() dock = CollapsibleDockWidget() layout.addWidget(dock) list_view = QListView() list_view.setModel(QStringListModel(["a", "b"], list_view)) label = QLabel("A label. ") label.setWordWrap(True) dock.setExpandedWidget(label) dock.setCollapsedWidget(list_view) dock.setExpanded(True) dock.setExpanded(False) timer = QTimer(dock, interval=200) timer.timeout.connect(lambda: dock.setExpanded(not dock.expanded())) timer.start()
def __init__(self): super().__init__() self.data = None # type: Optional[Orange.data.Table] self.learner = None # type: Optional[Learner] self.default_learner = SimpleTreeLearner() self.modified = False self.executor = qconcurrent.ThreadExecutor(self) self.__task = None main_layout = QVBoxLayout() main_layout.setContentsMargins(10, 10, 10, 10) self.controlArea.layout().addLayout(main_layout) box = QGroupBox(title=self.tr("Default Method"), flat=False) box_layout = QVBoxLayout(box) main_layout.addWidget(box) button_group = QButtonGroup() button_group.buttonClicked[int].connect(self.set_default_method) for method, _ in list(METHODS.items())[1:-1]: imputer = self.create_imputer(method) button = QRadioButton(imputer.name) button.setChecked(method == self.default_method_index) button_group.addButton(button, method) box_layout.addWidget(button) self.default_button_group = button_group box = QGroupBox(title=self.tr("Individual Attribute Settings"), flat=False) main_layout.addWidget(box) horizontal_layout = QHBoxLayout(box) main_layout.addWidget(box) self.varview = QListView( selectionMode=QListView.ExtendedSelection, uniformItemSizes=True ) self.varview.setItemDelegate(DisplayFormatDelegate()) self.varmodel = itemmodels.VariableListModel() self.varview.setModel(self.varmodel) self.varview.selectionModel().selectionChanged.connect( self._on_var_selection_changed ) self.selection = self.varview.selectionModel() horizontal_layout.addWidget(self.varview) method_layout = QVBoxLayout() horizontal_layout.addLayout(method_layout) button_group = QButtonGroup() for method in Method: imputer = self.create_imputer(method) button = QRadioButton(text=imputer.name) button_group.addButton(button, method) method_layout.addWidget(button) self.value_combo = QComboBox( minimumContentsLength=8, sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLength, activated=self._on_value_selected ) self.value_double = QDoubleSpinBox( editingFinished=self._on_value_selected, minimum=-1000., maximum=1000., singleStep=.1, decimals=3, ) self.value_stack = value_stack = QStackedWidget() value_stack.addWidget(self.value_combo) value_stack.addWidget(self.value_double) method_layout.addWidget(value_stack) button_group.buttonClicked[int].connect( self.set_method_for_current_selection ) method_layout.addStretch(2) reset_button = QPushButton( "Restore All to Default", checked=False, checkable=False, clicked=self.reset_variable_state, default=False, autoDefault=False) method_layout.addWidget(reset_button) self.variable_button_group = button_group box = gui.auto_commit( self.controlArea, self, "autocommit", "Apply", orientation=Qt.Horizontal, checkbox_label="Apply automatically") box.button.setFixedWidth(180) box.layout().insertStretch(0)
def __init__(self, parent=None, filename=None): super(MainForm, self).__init__(parent) self.view = GraphicsView() background = QPixmap(filename) # assume screnshots were taken on the same system stamper is being used on # DPI check might be more robust, can be added if needed background.setDevicePixelRatio(self.devicePixelRatioF()) self.filename = os.path.splitext(filename)[0] if ("-%s" % ORG) in self.filename: self.filename = self.filename[:-len(ORG)-5] + ".png" # self.view.setBackgroundBrush(QBrush(background)) # self.view.setCacheMode(QGraphicsView.CacheBackground) # self.view.setDragMode(QGraphicsView.ScrollHandDrag) self.scene = QGraphicsScene(self) self.scene.addPixmap(background) global scene scene = self.scene self.view.dialog = self self.view.setScene(self.scene) self.prevPoint = QPoint() self.lastStamp = -1 buttonLayout = QVBoxLayout() for text, slot in ( ("&Tag", self.addTag), ("Align &bottom", self.alignBottom), ("Align &left", self.alignLeft), ("&Save", self.save), ("&Quit", self.accept)): button = QPushButton(text) button.clicked.connect(slot) if not MAC: button.setFocusPolicy(Qt.NoFocus) self.lineedit.returnPressed.connect(self.updateUi) if text == "&Save": buttonLayout.addStretch(5) if text == "&Quit": buttonLayout.addStretch(1) buttonLayout.addWidget(button) buttonLayout.addStretch() size = background.size() / background.devicePixelRatioF() self.view.resize(size.width(), size.height()) self.scene.setSceneRect(0, 0, size.width(), size.height()) self.view.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) layout = QHBoxLayout() layout.addWidget(self.view, 1) layout.addLayout(buttonLayout) self.setLayout(layout) self.setWindowTitle(AppName) info_name = self.filename + "-" + TAG + ".txt" if os.path.exists(info_name): for tag, x, y in [line.strip().split("\t") for line in open(info_name, "rt").readlines()]: self.addTag(int(tag), QPointF(int(x), int(y)), adjust_position=False) global Dirty; Dirty=False self.show() self.raise_()
def __init__(self): super().__init__() #: input data self.data = None #: Current variable discretization state self.var_state = {} #: Saved variable discretization settings (context setting) self.saved_var_states = {} self.method = 0 self.k = 5 box = gui.vBox(self.controlArea, self.tr("Default Discretization")) self.default_bbox = rbox = gui.radioButtons( box, self, "default_method", callback=self._default_disc_changed) rb = gui.hBox(rbox) self.left = gui.vBox(rb) right = gui.vBox(rb) rb.layout().setStretch(0, 1) rb.layout().setStretch(1, 1) options = self.options = [ self.tr("Default"), self.tr("Leave numeric"), self.tr("Entropy-MDL discretization"), self.tr("Equal-frequency discretization"), self.tr("Equal-width discretization"), self.tr("Remove numeric variables") ] for opt in options[1:]: t = gui.appendRadioButton(rbox, opt) # This condition is ugly, but it keeps the same order of # options for backward compatibility of saved schemata [right, self.left][opt.startswith("Equal")].layout().addWidget(t) gui.separator(right, 18, 18) def _intbox(widget, attr, callback): box = gui.indentedBox(widget) s = gui.spin( box, self, attr, minv=2, maxv=10, label="Num. of intervals:", callback=callback) s.setMaximumWidth(60) s.setAlignment(Qt.AlignRight) gui.rubber(s.box) return box.box self.k_general = _intbox(self.left, "default_k", self._default_disc_changed) self.k_general.layout().setContentsMargins(0, 0, 0, 0) vlayout = QHBoxLayout() box = gui.widgetBox( self.controlArea, "Individual Attribute Settings", orientation=vlayout, spacing=8 ) # List view with all attributes self.varview = QListView(selectionMode=QListView.ExtendedSelection) self.varview.setItemDelegate(DiscDelegate()) self.varmodel = itemmodels.VariableListModel() self.varview.setModel(self.varmodel) self.varview.selectionModel().selectionChanged.connect( self._var_selection_changed ) vlayout.addWidget(self.varview) # Controls for individual attr settings self.bbox = controlbox = gui.radioButtons( box, self, "method", callback=self._disc_method_changed ) vlayout.addWidget(controlbox) for opt in options[:5]: gui.appendRadioButton(controlbox, opt) self.k_specific = _intbox(controlbox, "k", self._disc_method_changed) gui.appendRadioButton(controlbox, "Remove attribute") gui.rubber(controlbox) controlbox.setEnabled(False) self.controlbox = controlbox box = gui.auto_commit( self.controlArea, self, "autosend", "Apply", orientation=Qt.Horizontal, checkbox_label="Apply automatically") box.layout().insertSpacing(0, 20) box.layout().insertWidget(0, self.report_button) self._update_spin_positions()
def __init__(self): super().__init__() main_layout = QVBoxLayout() main_layout.setContentsMargins(10, 10, 10, 10) self.controlArea.layout().addLayout(main_layout) box = QGroupBox(title=self.tr("Default Method"), flat=False) box_layout = QVBoxLayout(box) main_layout.addWidget(box) button_group = QButtonGroup() button_group.buttonClicked[int].connect(self.set_default_method) for i, method in enumerate(self.METHODS): if not method.columns_only: button = QRadioButton(method.name) button.setChecked(i == self.default_method_index) button_group.addButton(button, i) box_layout.addWidget(button) self.default_button_group = button_group box = QGroupBox(title=self.tr("Individual Attribute Settings"), flat=False) main_layout.addWidget(box) horizontal_layout = QHBoxLayout(box) main_layout.addWidget(box) self.varview = QListView( selectionMode=QListView.ExtendedSelection ) self.varview.setItemDelegate(DisplayFormatDelegate()) self.varmodel = itemmodels.VariableListModel() self.varview.setModel(self.varmodel) self.varview.selectionModel().selectionChanged.connect( self._on_var_selection_changed ) self.selection = self.varview.selectionModel() horizontal_layout.addWidget(self.varview) method_layout = QVBoxLayout() horizontal_layout.addLayout(method_layout) button_group = QButtonGroup() for i, method in enumerate(self.METHODS): button = QRadioButton(text=method.name) button_group.addButton(button, i) method_layout.addWidget(button) self.value_combo = QComboBox( minimumContentsLength=8, sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLength, activated=self._on_value_selected ) self.value_combo.currentIndexChanged.connect(self._on_value_changed) self.value_double = QDoubleSpinBox( editingFinished=self._on_value_selected, minimum=-1000., maximum=1000., singleStep=.1, decimals=3, value=self.default_value ) self.value_stack = value_stack = QStackedLayout() value_stack.addWidget(self.value_combo) value_stack.addWidget(self.value_double) method_layout.addLayout(value_stack) button_group.buttonClicked[int].connect( self.set_method_for_current_selection ) method_layout.addStretch(2) reset_button = QPushButton( "Restore All to Default", checked=False, checkable=False, clicked=self.reset_variable_methods, default=False, autoDefault=False) method_layout.addWidget(reset_button) self.variable_button_group = button_group box = gui.auto_commit( self.controlArea, self, "autocommit", "Apply", orientation=Qt.Horizontal, checkbox_label="Apply automatically") box.layout().insertSpacing(0, 80) box.layout().insertWidget(0, self.report_button) self.data = None self.modified = False self.default_method = self.METHODS[self.default_method_index] self.update_varview()
class PreprocessorModule(gui.OWComponent, QWidget): """The base widget for the pre-processing modules.""" change_signal = pyqtSignal() # Emitted when the settings are changed. title = NotImplemented attribute = NotImplemented methods = NotImplemented single_method = True toggle_enabled = True enabled = settings.Setting(True) disabled_value = None Layout = QGridLayout def __init__(self, master): QWidget.__init__(self) gui.OWComponent.__init__(self, master) self.master = master # Title bar. title_holder = QWidget() title_holder.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) title_holder.setStyleSheet(""" .QWidget { background: qlineargradient( x1:0 y1:0, x2:0 y2:1, stop:0 #F8F8F8, stop:1 #C8C8C8); border-bottom: 1px solid #B3B3B3; } """) self.titleArea = QHBoxLayout() self.titleArea.setContentsMargins(10, 5, 10, 5) self.titleArea.setSpacing(0) title_holder.setLayout(self.titleArea) self.title_label = QLabel(self.title) self.title_label.mouseDoubleClickEvent = self.on_toggle self.title_label.setStyleSheet('font-size: 12px; border: 2px solid red;') self.titleArea.addWidget(self.title_label) self.off_label = QLabel('[disabled]') self.off_label.setStyleSheet('color: #B0B0B0; margin-left: 5px;') self.titleArea.addWidget(self.off_label) self.off_label.hide() self.titleArea.addStretch() # Root. self.rootArea = QVBoxLayout() self.rootArea.setContentsMargins(0, 0, 0, 0) self.rootArea.setSpacing(0) self.setLayout(self.rootArea) self.rootArea.addWidget(title_holder) self.contents = QWidget() contentArea = QVBoxLayout() contentArea.setContentsMargins(15, 10, 15, 10) self.contents.setLayout(contentArea) self.rootArea.addWidget(self.contents) self.method_layout = self.Layout() self.setup_method_layout() self.contents.layout().addLayout(self.method_layout) if self.toggle_enabled: self.on_off_button = OnOffButton(enabled=self.enabled) self.on_off_button.stateChanged.connect(self.on_toggle) self.on_off_button.setContentsMargins(0, 0, 0, 0) self.titleArea.addWidget(self.on_off_button) self.display_widget() @staticmethod def get_tooltip(method): return ' '.join([l.strip() for l in method.__doc__.split('\n')]).strip('.') \ if method.__doc__ else None @staticmethod def textify(text): return text.replace('&', '&&') @property def value(self): if self.enabled: return self.get_value() return self.disabled_value def setup_method_layout(self): raise NotImplementedError def on_toggle(self, event=None): # Activated when the widget is enabled/disabled. self.enabled = not self.enabled self.display_widget() self.update_value() def display_widget(self): if self.enabled: self.off_label.hide() self.contents.show() self.title_label.setStyleSheet('color: #000000;') else: self.off_label.show() self.contents.hide() self.title_label.setStyleSheet('color: #B0B0B0;') def get_value(self): raise NotImplemented def update_value(self): self.change_signal.emit()
def __init__(self): super().__init__() self.data = None self.editors = {} box = gui.vBox(self.controlArea, "Variable Definitions") toplayout = QHBoxLayout() toplayout.setContentsMargins(0, 0, 0, 0) box.layout().addLayout(toplayout) self.editorstack = QStackedWidget( sizePolicy=QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) ) for descclass, editorclass in self.EDITORS: editor = editorclass() editor.featureChanged.connect(self._on_modified) self.editors[descclass] = editor self.editorstack.addWidget(editor) self.editorstack.setEnabled(False) buttonlayout = QVBoxLayout(spacing=10) buttonlayout.setContentsMargins(0, 0, 0, 0) self.addbutton = QPushButton( "New", toolTip="Create a new variable", minimumWidth=120, shortcut=QKeySequence.New ) def unique_name(fmt, reserved): candidates = (fmt.format(i) for i in count(1)) return next(c for c in candidates if c not in reserved) def reserved_names(): varnames = [] if self.data is not None: varnames = [var.name for var in self.data.domain.variables + self.data.domain.metas] varnames += [desc.name for desc in self.featuremodel] return set(varnames) def generate_newname(fmt): return unique_name(fmt, reserved_names()) menu = QMenu(self.addbutton) cont = menu.addAction("Numeric") cont.triggered.connect( lambda: self.addFeature( ContinuousDescriptor(generate_newname("X{}"), "", 3)) ) disc = menu.addAction("Categorical") disc.triggered.connect( lambda: self.addFeature( DiscreteDescriptor(generate_newname("D{}"), "", ("A", "B"), -1, False)) ) string = menu.addAction("Text") string.triggered.connect( lambda: self.addFeature( StringDescriptor(generate_newname("S{}"), "")) ) menu.addSeparator() self.duplicateaction = menu.addAction("Duplicate Selected Variable") self.duplicateaction.triggered.connect(self.duplicateFeature) self.duplicateaction.setEnabled(False) self.addbutton.setMenu(menu) self.removebutton = QPushButton( "Remove", toolTip="Remove selected variable", minimumWidth=120, shortcut=QKeySequence.Delete ) self.removebutton.clicked.connect(self.removeSelectedFeature) buttonlayout.addWidget(self.addbutton) buttonlayout.addWidget(self.removebutton) buttonlayout.addStretch(10) toplayout.addLayout(buttonlayout, 0) toplayout.addWidget(self.editorstack, 10) # Layout for the list view layout = QVBoxLayout(spacing=1, margin=0) self.featuremodel = DescriptorModel(parent=self) self.featureview = QListView( minimumWidth=200, sizePolicy=QSizePolicy(QSizePolicy.Minimum, QSizePolicy.MinimumExpanding) ) self.featureview.setItemDelegate(FeatureItemDelegate(self)) self.featureview.setModel(self.featuremodel) self.featureview.selectionModel().selectionChanged.connect( self._on_selectedVariableChanged ) layout.addWidget(self.featureview) box.layout().addLayout(layout, 1) box = gui.hBox(self.controlArea) gui.rubber(box) commit = gui.button(box, self, "Send", callback=self.apply, default=True) commit.setMinimumWidth(180)
def __init__(self, *args): QWidget.__init__(self, *args) self.setContentsMargins(0, 0, 0, 0) gridLayout = QGridLayout() gridLayout.setContentsMargins(0, 0, 0, 0) gridLayout.setSpacing(1) model = QStandardItemModel(self) model.rowsInserted.connect(self.__changed) model.rowsRemoved.connect(self.__changed) model.dataChanged.connect(self.__changed) self._listView = QListView(self) self._listView.setModel(model) # self._listView.setDragEnabled(True) self._listView.setDropIndicatorShown(True) self._listView.setDragDropMode(QListView.InternalMove) self._listView.viewport().setAcceptDrops(True) self._listView.setMinimumHeight(100) gridLayout.addWidget(self._listView, 0, 0, 2, 2) vButtonLayout = QVBoxLayout() self._upAction = QAction( "\u2191", self, toolTip="Move up") self._upButton = QToolButton(self) self._upButton.setDefaultAction(self._upAction) self._upButton.setSizePolicy( QSizePolicy.Fixed, QSizePolicy.MinimumExpanding) self._downAction = QAction( "\u2193", self, toolTip="Move down") self._downButton = QToolButton(self) self._downButton.setDefaultAction(self._downAction) self._downButton.setSizePolicy( QSizePolicy.Fixed, QSizePolicy.MinimumExpanding) vButtonLayout.addWidget(self._upButton) vButtonLayout.addWidget(self._downButton) gridLayout.addLayout(vButtonLayout, 0, 2, 2, 1) hButtonLayout = QHBoxLayout() self._addAction = QAction("+", self) self._addButton = QToolButton(self) self._addButton.setDefaultAction(self._addAction) self._removeAction = QAction("-", self) self._removeButton = QToolButton(self) self._removeButton.setDefaultAction(self._removeAction) hButtonLayout.addWidget(self._addButton) hButtonLayout.addWidget(self._removeButton) hButtonLayout.addStretch(10) gridLayout.addLayout(hButtonLayout, 2, 0, 1, 2) self.setLayout(gridLayout) self._addAction.triggered.connect(self._onAddAction) self._removeAction.triggered.connect(self._onRemoveAction) self._upAction.triggered.connect(self._onUpAction) self._downAction.triggered.connect(self._onDownAction)
def __init__(self, data): icon = QApplication.style().standardIcon(QStyle.SP_MessageBoxWarning) F = self.DataField def _finished(*, key=(data.get(F.MODULE), data.get(F.WIDGET_MODULE)), filename=data.get(F.WIDGET_SCHEME)): self._cache.add(key) try: os.remove(filename) except Exception: pass super().__init__(None, Qt.Window, modal=True, sizeGripEnabled=True, windowIcon=icon, windowTitle='Unexpected Error', finished=_finished) self._data = data layout = QVBoxLayout(self) self.setLayout(layout) labels = QWidget(self) labels_layout = QHBoxLayout(self) labels.setLayout(labels_layout) labels_layout.addWidget(QLabel(pixmap=icon.pixmap(50, 50))) labels_layout.addWidget(QLabel( 'The program encountered an unexpected error. Please<br>' 'report it anonymously to the developers.<br><br>' 'The following data will be reported:')) labels_layout.addStretch(1) layout.addWidget(labels) font = QFont('Monospace', 10) font.setStyleHint(QFont.Monospace) font.setFixedPitch(True) textbrowser = QTextBrowser(self, font=font, openLinks=False, lineWrapMode=QTextBrowser.NoWrap, anchorClicked=QDesktopServices.openUrl) layout.addWidget(textbrowser) def _reload_text(): add_scheme = cb.isChecked() settings.setValue('error-reporting/add-scheme', add_scheme) lines = ['<table>'] for k, v in data.items(): if k.startswith('_'): continue _v, v = v, escape(str(v)) if k == F.WIDGET_SCHEME: if not add_scheme: continue v = '<a href="{}">{}</a>'.format(urljoin('file:', pathname2url(_v)), v) if k in (F.STACK_TRACE, F.LOCALS): v = v.replace('\n', '<br>').replace(' ', ' ') lines.append('<tr><th align="left">{}:</th><td>{}</td></tr>'.format(k, v)) lines.append('</table>') textbrowser.setHtml(''.join(lines)) settings = QSettings() cb = QCheckBox( 'Include workflow (data will NOT be transmitted)', self, checked=settings.value('error-reporting/add-scheme', True, type=bool)) cb.stateChanged.connect(_reload_text) _reload_text() layout.addWidget(cb) buttons = QWidget(self) buttons_layout = QHBoxLayout(self) buttons.setLayout(buttons_layout) buttons_layout.addWidget( QPushButton('Send Report (Thanks!)', default=True, clicked=self.accept)) buttons_layout.addWidget(QPushButton("Don't Send", default=False, clicked=self.reject)) layout.addWidget(buttons)