def __init__(self, addFunction=None, removeFunction=None, horizontal=False): QWidget.__init__(self) self.addButton = QToolButton(self) self.addButton.setIcon(resourceIcon("add")) self.addButton.setIconSize(QSize(16, 16)) self.addButton.clicked.connect(addFunction) self.removeButton = QToolButton(self) self.removeButton.setIcon(resourceIcon("remove")) self.removeButton.setIconSize(QSize(16, 16)) self.removeButton.clicked.connect(removeFunction) if horizontal: self.buttonLayout = QHBoxLayout() else: self.buttonLayout = QVBoxLayout() self.buttonLayout.setContentsMargins(0, 0, 0, 0) if horizontal: self.buttonLayout.addStretch(1) self.buttonLayout.addWidget(self.addButton) self.buttonLayout.addWidget(self.removeButton) if not horizontal: self.buttonLayout.addStretch(1) else: self.buttonLayout.addSpacing(2) self.setLayout(self.buttonLayout)
def actionButton(self, action): if isinstance(action, QAction): button = QToolButton(self) button.setDefaultAction(action) return button elif isinstance(action, QAbstractButton): return action
def _addScript(self, bool, deletable=True): layout2 = QHBoxLayout() findScriptLabel = QLabel("Filter = ") findScriptLineEdit = QLineEdit("") findScriptLineEdit.setToolTip("Example: object.Label == 'Particle1' ") scriptAdd = QToolButton() scriptAdd.setText("+") scriptDelete = QToolButton() scriptDelete.setText("-") if deletable: scriptAdd.hide() else: scriptDelete.hide() layout2.addWidget(scriptAdd) layout2.addWidget(scriptDelete) layout2.addWidget(findScriptLabel) layout2.addWidget(findScriptLineEdit) self.connect(findScriptLineEdit, SIGNAL("textChanged(QString)"), self.edited) self.connect(scriptAdd, SIGNAL("clicked(bool)"), self._addScript) self.connect(scriptDelete, SIGNAL("clicked(bool)"), self._removeScript) self.layout().insertLayout(len(self._properties) + len(self._scripts) + 1, layout2) self._scripts += [(layout2, findScriptLineEdit, findScriptLabel, scriptAdd, scriptDelete)]
def __createCornerWidget(self): self.__rightCornerWidget = QWidget(self) self.__rightCornerWidgetLayout = QHBoxLayout(self.__rightCornerWidget) self.__rightCornerWidgetLayout.setMargin(0) self.__rightCornerWidgetLayout.setSpacing(0) self.__navigationMenu = QMenu(self) # self.__navigationMenu.aboutToShow.connect(self.__showNavigationMenu) # self.__navigationMenu.triggered.connect(self.__navigationMenuTriggered) self.__navigationButton = QToolButton(self) self.__navigationButton.setIcon(QIcon("resource/Solid Iron Chest.ico")) self.__navigationButton.setToolTip("显示导航菜单") self.__navigationButton.setPopupMode(QToolButton.InstantPopup) self.__navigationButton.setMenu(self.__navigationMenu) self.__navigationButton.setEnabled(True) self.__rightCornerWidgetLayout.addWidget(self.__navigationButton) self.__closeButton = QToolButton(self) self.__closeButton.setIcon(QIcon("resource/Solid Iron Chest.ico")) self.__closeButton.setToolTip("关闭当前视图") self.__closeButton.setEnabled(True) self.__closeButton.clicked[bool].connect(self.addEmptyTab) self.__rightCornerWidgetLayout.addWidget(self.__closeButton) self.setCornerWidget(self.__rightCornerWidget, Qt.TopRightCorner)
def __init__(self, model, path_label="Path", help_link=""): HelpedWidget.__init__(self, path_label, help_link) self.__editing = True self.path_line = QLineEdit() self.addWidget(self.path_line) dialog_button = QToolButton(self) dialog_button.setIcon(resourceIcon("folder")) dialog_button.setIconSize(QSize(16, 16)) self.connect(dialog_button, SIGNAL('clicked()'), self.selectDirectory) self.addWidget(dialog_button) self.valid_color = self.path_line.palette().color(self.path_line.backgroundRole()) self.path_line.setText(os.getcwd()) self.__editing = False assert isinstance(model, PathModelMixin) self.model = model model.observable().attach(PathModelMixin.PATH_CHANGED_EVENT, self.getPathFromModel) self.getPathFromModel() self.connect(self.path_line, SIGNAL('editingFinished()'), self.validatePath) self.connect(self.path_line, SIGNAL('editingFinished()'), self.contentsChanged) self.connect(self.path_line, SIGNAL('textChanged(QString)'), self.validatePath)
def __init__(self, parent=None, **kwargs): QToolButton.__init__(self, parent, **kwargs) self.setToolButtonStyle(Qt.ToolButtonIconOnly) self.setCheckable(True) self.__flat = True self.__showMenuIndicator = False
def __init__(self, dockwidget): super(Widget, self).__init__(dockwidget) self._document = None self._fileSelector = QComboBox(editable=True, insertPolicy=QComboBox.NoInsert) widgets.drag.ComboDrag(self._fileSelector).role = Qt.UserRole self._fileSelector.lineEdit().setReadOnly(True) self._fileSelector.lineEdit().setFocusPolicy(Qt.NoFocus) self._stopButton = QToolButton() self._playButton = QToolButton() self._timeSlider = QSlider(Qt.Horizontal, tracking=False, singleStep=500, pageStep=5000, invertedControls=True) self._display = Display() self._tempoFactor = QSlider(Qt.Vertical, minimum=-50, maximum=50, singleStep=1, pageStep=5) grid = QGridLayout(spacing=0) self.setLayout(grid) grid.addWidget(self._fileSelector, 0, 0, 1, 3) grid.addWidget(self._stopButton, 1, 0) grid.addWidget(self._playButton, 1, 1) grid.addWidget(self._timeSlider, 1, 2) grid.addWidget(self._display, 2, 0, 1, 3) grid.addWidget(self._tempoFactor, 0, 3, 3, 1) # size policy of combo p = self._fileSelector.sizePolicy() p.setHorizontalPolicy(QSizePolicy.Ignored) self._fileSelector.setSizePolicy(p) # size policy of combo popup p = self._fileSelector.view().sizePolicy() p.setHorizontalPolicy(QSizePolicy.MinimumExpanding) self._fileSelector.view().setSizePolicy(p) self._player = player.Player() self._outputCloseTimer = QTimer(interval=60000, singleShot=True, timeout=self.closeOutput) self._timeSliderTicker = QTimer(interval=200, timeout=self.updateTimeSlider) self._fileSelector.activated[int].connect(self.slotFileSelected) self._tempoFactor.valueChanged.connect(self.slotTempoChanged) self._timeSlider.valueChanged.connect(self.slotTimeSliderChanged) self._timeSlider.sliderMoved.connect(self.slotTimeSliderMoved) self._player.beat.connect(self.updateDisplayBeat) self._player.time.connect(self.updateDisplayTime) self._player.stateChanged.connect(self.slotPlayerStateChanged) self.slotPlayerStateChanged(False) dockwidget.mainwindow().currentDocumentChanged.connect(self.loadResults) app.documentLoaded.connect(self.slotUpdatedFiles) app.jobFinished.connect(self.slotUpdatedFiles) app.aboutToQuit.connect(self.stop) midihub.aboutToRestart.connect(self.slotAboutToRestart) midihub.settingsChanged.connect(self.clearMidiSettings, -100) midihub.settingsChanged.connect(self.readMidiSettings) app.documentClosed.connect(self.slotDocumentClosed) app.translateUI(self) self.readMidiSettings() d = dockwidget.mainwindow().currentDocument() if d: self.loadResults(d)
class Header(QHeaderView): def __init__(self, orientation, parent=None): QHeaderView.__init__(self, orientation, parent) self.setModel(QStandardItemModel(self)) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.setStretchLastSection(True) self.setFixedHeight(25) self._menuButton = None def createMenuButton(self, label=">"): self._menuButton = QToolButton(self) self._menuButton.setText(label) return self._menuButton def menuButton(self): return self._menuButton def setText(self, text): if self.orientation() == Qt.Horizontal: self.model().setHorizontalHeaderLabels([text]) elif self.orientation() == Qt.Vertical: self.model().setVerticalHeaderLabels([text]) def mousePressEvent(self,event): QHeaderView.mousePressEvent(self,event) if event.button()==Qt.RightButton: self.emit(SIGNAL("mouseRightPressed"), event.globalPos())
def __init__(self, parent, message, severity, actions=None): QFrame.__init__(self, parent) self.ui = Ui_NotificationFrame() self.ui.setupUi(self) self.ui.closeButton.setIcon(QApplication.style().standardIcon(QStyle.SP_DialogCloseButton)) if severity == self.INFO: bgcolor = "#4398c8" fgcolor = self.palette().base().color().name() icon = self._standardIconAsPixmap(QStyle.SP_MessageBoxInformation) elif severity == self.WARNING: bgcolor = "#d0b05f" fgcolor = self.palette().text().color().name() icon = self._standardIconAsPixmap(QStyle.SP_MessageBoxWarning) elif severity == self.ERROR: bgcolor = "#cda8a8" fgcolor = self.palette().text().color().name() icon = self._standardIconAsPixmap(QStyle.SP_MessageBoxCritical) self.ui.iconLabel.setPixmap(icon) self.ui.messageLabel.setText(message) self._setColor(bgcolor, fgcolor) if actions: for action in reversed(actions): action.triggered.connect(self.deleteLater) b = QToolButton() b.setDefaultAction(action) self.layout().insertWidget(2, b)
def appendAddRow(self): """ Append a row with a field to add new properties. """ self.insertRow(self.lastRow()+1) lineedit=QLineEdit() lineedit.setFrame(False) lineedit.setContentsMargins(0, 0, 0, 0) self.setCellWidget(self.lastRow(), 0, lineedit) widget=QWidget() widget.setContentsMargins(0, 0, 0, 0) widget.setLayout(QHBoxLayout()) widget.layout().setSpacing(0) widget.layout().setContentsMargins(0, 0, 0, 0) typelist=ComboBoxReturn() types=["String","Boolean","Integer","Double","File","FileVector"] for type in types: typelist.addItem(type) widget.layout().addWidget(typelist) addButton=QToolButton() addButton.setText("+") widget.layout().addWidget(addButton) self.setCellWidget(self.lastRow(), 1, widget) self.verticalHeader().resizeSection(self.lastRow(), Property.DEFAULT_HEIGHT) self.connect(addButton, SIGNAL('clicked(bool)'), self.addProperty) self.connect(lineedit, SIGNAL('returnPressed()'), self.addProperty) self.connect(typelist, SIGNAL('returnPressed()'), self.addProperty) addButton._lineedit=lineedit addButton._typelist=typelist lineedit._lineedit=lineedit lineedit._typelist=typelist typelist._lineedit=lineedit typelist._typelist=typelist
class RasterPage(QWidget): def __init__(self, parent=None, filters=""): QWidget.__init__(self, parent) self.parent = parent self.filters = filters self.layerLineEdit = QLineEdit() self.browseToolButton = QToolButton() self.browseToolButton.setAutoRaise(True) self.browseToolButton.setIcon(QIcon(":document-open")) layerLabel = QLabel("&Dataset:") layerLabel.setBuddy(self.layerLineEdit) hbox = QHBoxLayout() hbox.addWidget(layerLabel) hbox.addWidget(self.layerLineEdit) hbox.addWidget(self.browseToolButton) vbox = QVBoxLayout() vbox.addLayout(hbox) self.setLayout(vbox) self.connect(self.browseToolButton, SIGNAL("clicked()"), self.browseToFile) def browseToFile(self): dialog = QFileDialog(self, "manageR - Open Raster File", unicode(robjects.r.getwd()[0]), self.filters) if not dialog.exec_() == QDialog.Accepted: return files = dialog.selectedFiles() file = files.first().trimmed() self.layerLineEdit.setText(file) self.emit(SIGNAL("filePathChanged(QString)"), file)
def __init__(self, plus_callback, minus_callback, parent=None): super(PlusMinusWidget, self).__init__(parent) self._plus_button = QToolButton(self) self._minus_button = QToolButton(self) self._plus_button.setText("+") self._minus_button.setText("-") style = """ QToolButton { border: 1px solid #979797; border-radius: 0px; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #F9F9F9, stop: 1 #E6E6E6); min-width: 20px; min-height: 20px; max-width: 20px; max-height: 20px; } QToolButton:pressed { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #dadbde, stop: 1 #f6f7fa); } """ self._minus_button.setStyleSheet(style) self._plus_button.setStyleSheet(style) self._plus_button.clicked.connect(plus_callback) self._minus_button.clicked.connect(minus_callback) self.addWidget(self._plus_button) self.addWidget(self._minus_button)
class SearchLineEdit(QLineEdit): def __init__(self, parent = None): QLineEdit.__init__(self, parent) self.searchButton = QToolButton(self) self.searchButton.setCursor(QCursor()) self.searchButton.setIcon(QIcon("./img/search.svg")) frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth); self.searchButton.setStyleSheet("QToolButton {border: none; padding: 0px;}") self.setStyleSheet(QString( '''QLineEdit { padding-right: %1px; padding-left: 2px; padding-top: 1px; padding-bottom: 1px; } ''').arg(self.searchButton.sizeHint().width() + frameWidth + 1)); def resizeEvent(self, event = None): if event: QLineEdit.resizeEvent(self, event) sz = self.searchButton.sizeHint() frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth) self.searchButton.move(self.rect().right() - frameWidth - sz.width(), (self.rect().bottom() + 1 - sz.height())/2) def focusInEvent(self, event = None): QLineEdit.focusInEvent(self, event) self.emit(SIGNAL("focusChange()")) def focusOutEvent(self, event = None): QLineEdit.focusOutEvent(self, event) self.emit(SIGNAL("focusChange()"))
def buildfromauto(formconfig): widgetsconfig = formconfig['widgets'] outlayout = QFormLayout() outwidget = QWidget() outwidget.setLayout(outlayout) for config in widgetsconfig: widgettype = config['widget'] field = config['field'] name = config.get('name', field) label = QLabel(name) label.setObjectName(field + "_label") widgetwrapper = WidgetsRegistry.createwidget(widgettype, layer=None, field=field, widget=None, label=label, config=None) widget = widgetwrapper.widget widget.setObjectName(field) layoutwidget = QWidget() layoutwidget.setLayout(QBoxLayout(QBoxLayout.LeftToRight)) layoutwidget.layout().addWidget(widget) if config.get('rememberlastvalue', False): savebutton = QToolButton() savebutton.setObjectName('{}_save'.format(field)) layoutwidget.layout().addWidget(savebutton) hidden = config.get('hidden', False) if not hidden: outlayout.addRow(label, layoutwidget) outlayout.addItem(QSpacerItem(10,10)) return outwidget
def __initLayout(self): # layout layout = QGridLayout() central_widget = QWidget(self) central_widget.setLayout(layout) self.setCentralWidget(central_widget) # create plot manager self.__p_manager = PlotManager(self) # toolbar if (self.__p_toolbar): self.__p_toolbar.clear() else: self.__p_toolbar = self.addToolBar("tools") # end if # resize button icon = QIcon("icons/center.png") button = QToolButton() button.setIcon(icon) button.setToolTip("Resize") self.connect(button, SIGNAL("clicked()"), self.__onAutoScale) self.__p_manager.add_toolbar(self.__p_toolbar, id(self.__p_toolbar)) self.__p_toolbar.addWidget(button) self.__v_wasInitialized = True
def __init__(self, parent=None): super(XZoomSlider, self).__init__(parent) # define the interface in_icon = projexui.resources.find('img/zoom_in.png') out_icon = projexui.resources.find('img/zoom_out.png') self._zoomInButton = QToolButton(self) self._zoomInButton.setAutoRaise(True) self._zoomInButton.setToolTip('Zoom In') self._zoomInButton.setIcon(QIcon(in_icon)) self._zoomOutButton = QToolButton(self) self._zoomOutButton.setAutoRaise(True) self._zoomOutButton.setToolTip('Zoom Out') self._zoomOutButton.setIcon(QIcon(out_icon)) self._zoomSlider = QSlider(Qt.Horizontal, self) self._zoomSlider.setRange(10, 100) self._zoomSlider.setValue(100) # define the layout layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addWidget(self._zoomOutButton) layout.addWidget(self._zoomSlider) layout.addWidget(self._zoomInButton) self.setLayout(layout) # create connections self._zoomSlider.valueChanged.connect(self.emitZoomAmountChanged) self._zoomInButton.clicked.connect(self.zoomIn) self._zoomOutButton.clicked.connect(self.zoomOut)
def buildfromauto(formconfig, base): widgetsconfig = formconfig['widgets'] outlayout = QFormLayout() outlayout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) outwidget = base outwidget.setLayout(outlayout) for config in widgetsconfig: widgettype = config['widget'] field = config['field'] name = config.get('name', field) if not field: utils.warning("Field can't be null for {}".format(name)) utils.warning("Skipping widget") continue label = QLabel(name) label.setObjectName(field + "_label") widget = roam.editorwidgets.core.createwidget(widgettype, parent=base) widget.setObjectName(field) layoutwidget = QWidget() layoutwidget.setLayout(QBoxLayout(QBoxLayout.LeftToRight)) layoutwidget.layout().addWidget(widget) if config.get('rememberlastvalue', False): savebutton = QToolButton() savebutton.setObjectName('{}_save'.format(field)) layoutwidget.layout().addWidget(savebutton) outlayout.addRow(label, layoutwidget) outlayout.addItem(QSpacerItem(10, 10)) installflickcharm(outwidget) return outwidget
def __init__(self): QWidget.__init__(self) self.__filter_popup = FilterPopup(self) self.__filter_popup.filterSettingsChanged.connect(self.onItemChanged) layout = QVBoxLayout() self.model = DataTypeKeysListModel() self.filter_model = DataTypeProxyModel(self.model) filter_layout = QHBoxLayout() self.search_box = SearchBox() self.search_box.filterChanged.connect(self.setSearchString) filter_layout.addWidget(self.search_box) filter_popup_button = QToolButton() filter_popup_button.setIcon(util.resourceIcon("ide/cog_edit.png")) filter_popup_button.clicked.connect(self.showFilterPopup) filter_layout.addWidget(filter_popup_button) layout.addLayout(filter_layout) self.data_type_keys_widget = QListView() self.data_type_keys_widget.setModel(self.filter_model) self.data_type_keys_widget.selectionModel().selectionChanged.connect(self.itemSelected) layout.addSpacing(15) layout.addWidget(self.data_type_keys_widget, 2) layout.addStretch() # layout.addWidget(Legend("Default types", DataTypeKeysListModel.DEFAULT_DATA_TYPE)) layout.addWidget(Legend("Observations available", DataTypeKeysListModel.HAS_OBSERVATIONS)) self.setLayout(layout)
def __init__( self, parent = None ): DesignerWidget.__init__( self, Ui_ResultsTable, parent ) self.add_button = QToolButton( self ) self.add_button.setIcon( QIcon.fromTheme( "list-add" ) ) self.add_button.setAutoRaise( True ) self.connect( self.add_button, SIGNAL( 'clicked()' ), self.add_button_clicked ) self.tabWidget.setCornerWidget( self.add_button, Qt.TopLeftCorner ) self.remove_button = QToolButton( self ) self.remove_button.setIcon( QIcon.fromTheme( "list-remove" ) ) self.remove_button.setAutoRaise( True ) self.connect( self.remove_button, SIGNAL( 'clicked()' ), self.remove_button_clicked ) self.tabWidget.setCornerWidget( self.remove_button, Qt.TopRightCorner ) self.connect( self.tabWidget, SIGNAL( 'currentChanged(int)' ), self.update_buttons ) self.configure_extra_columns.setIcon( QIcon.fromTheme( 'configure' ) ) self.configure_dialog = ResultsTableDialog() self.connect( self.configure_extra_columns, SIGNAL( 'clicked()' ), self.configure_extra_columns_clicked ) self.export_pdf.setIcon( QIcon.fromTheme( 'application-pdf' ) ) self.export_latex.setIcon( QIcon.fromTheme( 'text-x-tex' ) ) self.connect( self.export_pdf, SIGNAL( 'clicked()' ), self.export_as_pdf ) self.connect( self.export_latex, SIGNAL( 'clicked()' ), self.export_as_latex ) self.splitter.setSizes( [1000,200] ) self.chk_global = [ self.global_lines, self.global_gates, self.global_qc, self.global_tc ] self.update_buttons()
def __init__(self, possible_items): QWidget.__init__(self) self._editing = True self._possible_items = possible_items self._list_edit_line = AutoCompleteLineEdit(possible_items, self) self._list_edit_line.setMinimumWidth(350) layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self._list_edit_line) dialog_button = QToolButton(self) dialog_button.setIcon(resourceIcon("ide/small/add")) dialog_button.setIconSize(QSize(16, 16)) dialog_button.clicked.connect(self.addChoice) layout.addWidget(dialog_button) self.setLayout(layout) self._validation_support = ValidationSupport(self) self._valid_color = self._list_edit_line.palette().color(self._list_edit_line.backgroundRole()) self._list_edit_line.setText("") self._editing = False self._list_edit_line.editingFinished.connect(self.validateList) self._list_edit_line.textChanged.connect(self.validateList) self.validateList()
def createEditor(self): self.createToolBar(0) self._editorSplitter = QSplitter(Qt.Horizontal) toolBarSectionId = self.toolBar().addSection(SplitterToolBar.ALIGNMENT_LEFT) self._editorTableView=CodeTableView(self._editorSplitter) self._editorSplitter.setSizes([100, 300]) self._minimizeButton = QToolButton() self._minimizeButton.setText("v") self._minimizeButton.setCheckable(True) self._originalButton = QToolButton() self._originalButton.setText("-") self._originalButton.setCheckable(True) self._originalButton.setChecked(True) self._maximizeButton = QToolButton() self._maximizeButton.setText("^") self._maximizeButton.setCheckable(True) self._centerViewToolBarId = self.toolBar().addSection(SplitterToolBar.ALIGNMENT_CENTER) self.toolBar().addWidgetToSection(self._minimizeButton, self._centerViewToolBarId) self.toolBar().addWidgetToSection(self._originalButton, self._centerViewToolBarId) self.toolBar().addWidgetToSection(self._maximizeButton, self._centerViewToolBarId) self.verticalSplitter().insertWidget(0,self._editorSplitter) self.updateToolBarSizes() controller = self.controller() if controller: self.connect(self._minimizeButton, SIGNAL('clicked(bool)'), controller.minimizeEditor) self.connect(self._originalButton, SIGNAL('clicked(bool)'), controller.originalEditor) self.connect(self._maximizeButton, SIGNAL('clicked(bool)'), controller.maximizeEditor)
def __init__(self, possible_items, label="ListEdit", help_link=""): HelpedWidget.__init__(self, label, help_link) self.__editing = True self.__valid = True self.__possible_items = possible_items self.list_edit_line = AutoCompleteLineEdit(possible_items, self) self.list_edit_line.setMinimumWidth(350) self.addWidget(self.list_edit_line) dialog_button = QToolButton(self) dialog_button.setIcon(resourceIcon("ide/small/add")) dialog_button.setIconSize(QSize(16, 16)) self.connect(dialog_button, SIGNAL('clicked()'), self.addChoice) self.addWidget(dialog_button) self.valid_color = self.list_edit_line.palette().color(self.list_edit_line.backgroundRole()) self.list_edit_line.setText("") self.__editing = False self.connect(self.list_edit_line, SIGNAL('editingFinished()'), self.validateList) self.connect(self.list_edit_line, SIGNAL('textChanged(QString)'), self.validateList) self.validateList()
def __init__(self, parent, bottomOffset): self.window = parent self.bottomOffset = bottomOffset QToolButton.__init__(self, parent) # set the fullsize icon from Maemo's theme self.setIcon(QIcon.fromTheme("general_fullsize")); # ensure that our size is fixed to our ideal size self.setFixedSize(self.sizeHint()); # set the background to 0.5 alpha pal = self.palette(); backgroundColor = pal.color(self.backgroundRole()); backgroundColor.setAlpha(128); pal.setColor(self.backgroundRole(), backgroundColor); self.setPalette(pal); # ensure that we're painting our background self.setAutoFillBackground(True); # when we're clicked, tell the parent to exit fullscreen self.connect(self, QtCore.SIGNAL("clicked()"), parent.showNormal); # install an event filter to listen for the parent's events parent.installEventFilter(self);
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 toggle_select_features_widget(title, text, button_text, layer, new_feature_ids, old_feature_ids): """ Create a widget for QgsMessageBar to switch between two sets. :param title: The title :type title: str :param text: The text message :type text: str :param button_text: The text on the toggle button :type button_text: str :param layer: The QgsVectorLayer where the selection is applied :type layer: QgsVectorLayer :param new_feature_ids: The list to select if use_new is true :type new_feature_ids: QgsFeatureIds :param old_feature_ids: The list to select if use_new is false :type old_feature_ids: QgsFeatureIds """ widget = QgsMessageBar.createMessage(title, text) button = QToolButton(widget) button.setCheckable(True) button.setText(button_text) button.toggled.connect( lambda on, layer=layer, new_feature_ids=new_feature_ids, old_feature_ids=old_feature_ids: toggle_select_features(layer, on, new_feature_ids, old_feature_ids)) widget.layout().addWidget(button) return widget
class ProtocolCountGraph_ui(Analysis_ui): ''' Description: Initialize the Men bar with actions and tool bar with tool buttons ''' def __init__(self, parent = None): Analysis_ui.__init__(self) self.parent = parent self.action = ProtocolCountGraphAction(self, parent) menuAnalysis = self.parent.GetMenu("Analysis") if menuAnalysis != None: menuAnalysis.addAction(self.action) toolBarAnalysis = self.parent.GetToolBar("Analysis") if toolBarAnalysis != None: pcgPixmap = QPixmap(os.path.dirname(os.path.realpath(__file__)) + '/barGraph.png') pcgIcon = QIcon(pcgPixmap) self.pcgButton = QToolButton(self.parent) self.pcgButton.setIcon(pcgIcon) self.pcgButton.setIconSize(QSize(32, 32)) self.pcgButton.clicked.connect(self.OnTrigger) toolBarAnalysis.addWidget(self.pcgButton) ''' Description: Set the packet list to be analysed and plot the graph ''' def OnTrigger(self): widget = self.parent.GetCurrentTab() if widget != None and isinstance(widget, PacketData_ui): obj = ProtocolCountGraph() obj.setPacketList(widget.packetList) obj.plotGraph()
def __init__(self, iterable=False, load_all = False, help_link=""): QWidget.__init__(self) self._iterable = iterable addHelpToWidget(self, help_link) layout = QHBoxLayout() analysis_module_combo = QComboBox() self._module_names = getAnalysisModuleNames(self._iterable) if load_all: self._module_names += getAnalysisModuleNames(not self._iterable) for module_name in self._module_names: analysis_module_combo.addItem(module_name) self._current_module_name = self._getCurrentAnalysisModuleName() if self._current_module_name is not None: analysis_module_combo.setCurrentIndex(self._module_names.index(self._current_module_name)) analysis_module_combo.currentIndexChanged[int].connect(self.analysisModuleChanged) variables_popup_button = QToolButton() variables_popup_button.setIcon(resourceIcon("ide/small/cog_edit.png")) variables_popup_button.clicked.connect(self.showVariablesPopup) variables_popup_button.setMaximumSize(20, 20) layout.addWidget(analysis_module_combo, 0, Qt.AlignLeft) layout.addWidget(variables_popup_button, 0, Qt.AlignLeft) layout.setContentsMargins(QMargins(0, 0, 0, 0)) layout.addStretch() self.setLayout(layout)
def initGUI(self): self.setWindowTitle(QApplication.applicationName()) layout = QVBoxLayout() headerlayout = QHBoxLayout() homeBtn = QToolButton() homeBtn.setIcon(self.ih.homeButton) homeBtn.setFixedSize(64,64) homeBtn.clicked.connect(self.home) headerlayout.addWidget(homeBtn) label = QLabel("<b>Location</b>") label.setMargin(10) label.setFixedSize(label.sizeHint()) headerlayout.addWidget(label) self.currentLocation = ClickableLabel("") self.currentLocation.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) self.currentLocation.setWordWrap(True) self.currentLocation.setFixedSize(400,64) self.currentLocation.clicked.connect(self.back) headerlayout.addWidget(self.currentLocation) headerlayout.addStretch() layout.addLayout(headerlayout) self.view = QListView() self.view.setSelectionMode( QAbstractItemView.SingleSelection) self.view.setEditTriggers(QAbstractItemView.NoEditTriggers) self.view.setContextMenuPolicy(Qt.CustomContextMenu) self.view.customContextMenuRequested.connect(self.contextMenu) self.view.setModel(self.model) self.view.setModelColumn(0) #self.view.doubleClicked.connect(self.doubleClicked) self.view.activated.connect(self.activated) layout.addWidget(self.view) self.setLayout(layout)
def initUi(self): openPixmap = QPixmap(os.path.dirname(os.path.realpath(__file__)) + '/Open.png') savePixmap = QPixmap(os.path.dirname(os.path.realpath(__file__)) + '/Save.png') openIcon = QIcon(openPixmap) saveIcon = QIcon(savePixmap) self.openToolButton = QToolButton(self.parent) self.saveToolButton = QToolButton(self.parent) self.openToolButton.setIcon(openIcon) self.saveToolButton.setIcon(saveIcon) self.openToolButton.setIconSize(QSize(32, 32)) self.saveToolButton.setIconSize(QSize(32, 32)) self.openToolButton.clicked.connect(self.openToolButtonClicked) self.saveToolButton.clicked.connect(self.saveToolButtonClicked) self.openAction = QAction("Open", self.parent) self.openAction.triggered.connect(self.openToolButtonClicked) self.saveAction = QAction("Save", self.parent) self.saveAction.triggered.connect(self.saveToolButtonClicked) menuCapture = self.parent.GetMenu("File") if menuCapture != None: menuCapture.addAction(self.openAction) menuCapture.addAction(self.saveAction) menuCapture.addSeparator() toolBarCapture = self.parent.GetToolBar("File") if toolBarCapture != None: toolBarCapture.addWidget(self.openToolButton) toolBarCapture.addWidget(self.saveToolButton)
class downloadItemClass(QWidget): def __init__(self, title, size, parent=None): QWidget.__init__(self, parent) self.mainLayout = QHBoxLayout(self) self.size = size self.statusButton = QToolButton() self.mainLayout.addWidget(self.statusButton) self.downloadItemInfo = StackedWidget() self.mainLayout.addWidget(self.downloadItemInfo) self.downloadItemMainInfo = downloadItemMainInfoClass(title) self.downloadItemInfo.addWidget(self.downloadItemMainInfo) self.connect(self.statusButton, SIGNAL('clicked()'), self.downloadItemInfo.next) self.update() def update(self, torrent = None): if not torrent: self.downloadItemMainInfo.fillData(self.size, 0, 0, 0, 0, 0, 0, 2) self.statusButton.setIcon(states[2][1]) else: size = torrent.size downloaded = torrent.downloaded uploaded = torrent.uploaded ratio = 0 if downloaded == 0 else uploaded/float(downloaded) self.downloadItemMainInfo.fillData(size, downloaded, uploaded, ratio, 100*(float(downloaded)/size), torrent.downspeed, torrent.upspeed, torrent.state) self.statusButton.setIcon(states[torrent.state][1])
def __init__(self, possible_items, label="ListEdit", help_link=""): HelpedWidget.__init__(self, label, help_link) self.__editing = True self.__valid = True self.__possible_items = possible_items self.list_edit_line = AutoCompleteLineEdit(possible_items, self) self.list_edit_line.setMinimumWidth(350) self.addWidget(self.list_edit_line) dialog_button = QToolButton(self) dialog_button.setIcon(resourceIcon("ide/small/add")) dialog_button.setIconSize(QSize(16, 16)) self.connect(dialog_button, SIGNAL('clicked()'), self.addChoice) self.addWidget(dialog_button) self.valid_color = self.list_edit_line.palette().color( self.list_edit_line.backgroundRole()) self.list_edit_line.setText("") self.__editing = False self.connect(self.list_edit_line, SIGNAL('editingFinished()'), self.validateList) self.connect(self.list_edit_line, SIGNAL('textChanged(QString)'), self.validateList) self.validateList()
def __init__(self, possible_items): QWidget.__init__(self) self._editing = True self._possible_items = possible_items self._list_edit_line = AutoCompleteLineEdit(possible_items, self) self._list_edit_line.setMinimumWidth(350) layout = QHBoxLayout() layout.setMargin(0) layout.addWidget(self._list_edit_line) dialog_button = QToolButton(self) dialog_button.setIcon(resourceIcon("ide/small/add")) dialog_button.setIconSize(QSize(16, 16)) dialog_button.clicked.connect(self.addChoice) layout.addWidget(dialog_button) self.setLayout(layout) self._validation_support = ValidationSupport(self) self._valid_color = self._list_edit_line.palette().color( self._list_edit_line.backgroundRole()) self._list_edit_line.setText("") self._editing = False self._list_edit_line.editingFinished.connect(self.validateList) self._list_edit_line.textChanged.connect(self.validateList) self.validateList()
def __init__(self): QMainWindow.__init__(self) self.d_plot = TVPlot(self) self.setCentralWidget( self.d_plot ) self.toolBar = QToolBar( self ) self.typeBox = QComboBox( self.toolBar ) self.typeBox.addItem( "Outline" ) self.typeBox.addItem( "Columns" ) self.typeBox.addItem( "Lines" ) self.typeBox.addItem( "Column Symbol" ) self.typeBox.setCurrentIndex( self.typeBox.count() - 1 ) self.typeBox.setSizePolicy( QSizePolicy.Fixed, QSizePolicy.Fixed ) self.btnExport = QToolButton( self.toolBar ) self.btnExport.setText( "Export" ) self.btnExport.setToolButtonStyle( Qt.ToolButtonTextUnderIcon ) #connect( btnExport, SIGNAL( clicked() ), d_plot, SLOT( exportPlot() ) ) self.btnExport.clicked.connect(self.d_plot.exportPlot) self.toolBar.addWidget( self.typeBox ) self.toolBar.addWidget( self.btnExport ) self.addToolBar( self.toolBar ) self.d_plot.setMode( self.typeBox.currentIndex() ) self.typeBox.currentIndexChanged['int'].connect(self.d_plot.setMode)
def __init__(self, *args, **kwargs): super(LineEdit, self).__init__(*args, **kwargs) self._clearButton = b = QToolButton(self, iconSize=QSize(16, 16), autoRaise=True) b.setFixedSize(QSize(16, 16)) b.setStyleSheet("QToolButton { border: none; }") b.clicked.connect(self.clear) b.setCursor(Qt.ArrowCursor) b.setFocusPolicy(Qt.NoFocus) self.textChanged.connect(self._updateClearButton) self._updateLayoutDirection() self._updateClearButton()
def __init__(self, parent=None): super(XSearchEdit, self).__init__(parent) # setup custom properties self._cancelButton = QToolButton(self) self._cancelButton.setIcon(QIcon( resources.find('img/remove_dark.png'))) self._cancelButton.setAutoRaise(True) self._cancelButton.setToolTip('Clear Search Text') self._cancelButton.hide() self.addButton(self._cancelButton) # setup default properties self.setHint('enter search') self.setIcon(QIcon(resources.find('img/search.png'))) self.setCornerRadius(8) self.adjustStyleSheet() self.adjustTextMargins() # create connections self._cancelButton.clicked.connect(self.clear) self.textChanged.connect(self.toggleCancelButton)
def initGui(self): self.popupMenu = QMenu(self.iface.mainWindow()) self.open_connections_action = self._create_action( "Add Vector Tiles Layer...", "server.svg", self._show_connections_dialog) self.reload_action = self._create_action(self._reload_button_text, "reload.svg", self._reload_tiles, False) self.export_action = self._create_action("Export selected layers", "save.svg", self._export_tiles) self.clear_cache_action = self._create_action("Clear cache", "delete.svg", FileHelper.clear_cache) self.iface.insertAddLayerAction( self.open_connections_action ) # Add action to the menu: Layer->Add Layer self.popupMenu.addAction(self.open_connections_action) self.popupMenu.addAction(self.reload_action) self.popupMenu.addAction(self.export_action) self.toolButton = QToolButton() self.toolButton.setMenu(self.popupMenu) self.toolButton.setDefaultAction(self.open_connections_action) self.toolButton.setPopupMode(QToolButton.MenuButtonPopup) self.toolButtonAction = self.iface.layerToolBar().addWidget( self.toolButton) self.about_action = self._create_action("About", "info.svg", self.show_about) self.iface.addPluginToVectorMenu("&Vector Tiles Reader", self.about_action) self.iface.addPluginToVectorMenu("&Vector Tiles Reader", self.open_connections_action) self.iface.addPluginToVectorMenu("&Vector Tiles Reader", self.reload_action) self.iface.addPluginToVectorMenu("&Vector Tiles Reader", self.export_action) self.iface.addPluginToVectorMenu("&Vector Tiles Reader", self.clear_cache_action) info("Vector Tile Reader Plugin loaded...")
def test_dock_mainwinow(self): mw = QMainWindow() dock = CollapsibleDockWidget() w1 = QTextEdit() w2 = QToolButton() w2.setFixedSize(38, 200) dock.setExpandedWidget(w1) dock.setCollapsedWidget(w2) mw.addDockWidget(Qt.LeftDockWidgetArea, dock) mw.setCentralWidget(QTextEdit()) mw.show() def toogle(): dock.setExpanded(not dock.expanded()) self.singleShot(2000, toogle) toogle() self.app.exec_()
class Spanners(tool.Tool): """Dynamics tool in the quick insert panel toolbox.""" def __init__(self, panel): super(Spanners, self).__init__(panel) self.removemenu = QToolButton(self, autoRaise=True, popupMode=QToolButton.InstantPopup, icon=icons.get('edit-clear')) mainwindow = panel.parent().mainwindow() mainwindow.selectionStateChanged.connect(self.removemenu.setEnabled) self.removemenu.setEnabled(mainwindow.hasSelection()) ac = documentactions.DocumentActions.instance( mainwindow).actionCollection self.removemenu.addAction(ac.tools_quick_remove_slurs) layout = QHBoxLayout() layout.addWidget(self.removemenu) layout.addStretch(1) self.layout().addLayout(layout) self.layout().addWidget(ArpeggioGroup(self)) self.layout().addWidget(GlissandoGroup(self)) self.layout().addWidget(SpannerGroup(self)) self.layout().addWidget(GraceGroup(self)) self.layout().addStretch(1) def icon(self): """Should return an icon for our tab.""" return symbols.icon("spanner_phrasingslur") def title(self): """Should return a title for our tab.""" return _("Spanners") def tooltip(self): """Returns a tooltip""" return _("Slurs, spanners, etcetera.")
class XSearchEdit(XLineEdit): def __init__(self, parent=None): super(XSearchEdit, self).__init__(parent) # setup custom properties self._cancelButton = QToolButton(self) self._cancelButton.setIcon(QIcon( resources.find('img/remove_dark.png'))) self._cancelButton.setAutoRaise(True) self._cancelButton.setToolTip('Clear Search Text') self._cancelButton.hide() self.addButton(self._cancelButton) # setup default properties self.setHint('enter search') self.setIcon(QIcon(resources.find('img/search.png'))) self.setCornerRadius(8) self.adjustStyleSheet() self.adjustTextMargins() # create connections self._cancelButton.clicked.connect(self.clear) self.textChanged.connect(self.toggleCancelButton) def clear(self): """ Clears the search text for this instance. """ super(XLineEdit, self).clear() self.textEntered.emit('') def toggleCancelButton(self): """ Toggles the visibility for the cancel button based on the current text. """ self._cancelButton.setVisible(self.text() != '')
class PathSelector(QWidget): pathChanged = pyqtSignal(QString) def __init__(self, parent=None): QWidget.__init__(self, parent) # Components self.path_edit = QLineEdit(self) self.path_edit.setReadOnly(True) self.button = QToolButton(self) self.button.setIcon(QIcon.fromTheme("document-open-folder")) # Completer completer = QCompleter(self) completer.setModel(QDirModel(completer)) self.path_edit.setCompleter(completer) # Setup Widget self.setLayout(QHBoxLayout()) self.layout().setMargin(0) self.layout().setSpacing(0) self.layout().addWidget(self.path_edit) self.layout().addWidget(self.button) # Actions self.connect(self.button, SIGNAL('clicked()'), self.selectPath) def selectPath(self): self.path_edit.setText( QFileDialog.getExistingDirectory(self, "Open Directory")) self.pathChanged.emit(self.path_edit.text()) def path(self): return self.path_edit.text() def setPath(self, p): self.path_edit.setText(p)
def _createItem(self, object, properties): """ Create item for an object. """ TableView._createItem(self, object, properties) button = QToolButton() button.object = object if self.dataAccessor().label(object) == "Import": button.setText("...") self.connect(button, SIGNAL('clicked(bool)'), self.importButtonClicked) elif self.dataAccessor().label(object) == "Apply tool": button.setText("+") self.connect(button, SIGNAL('clicked(bool)'), self.applyButtonClicked) else: button.setText("X") self.connect(button, SIGNAL('clicked(bool)'), self.removeButtonClicked) self.setCellWidget(self.rowCount() - 1, 0, button)
def __init__(self): QWidget.__init__(self) self.__filter_popup = FilterPopup(self) self.__filter_popup.filterSettingsChanged.connect(self.onItemChanged) layout = QVBoxLayout() self.model = DataTypeKeysListModel() self.filter_model = DataTypeProxyModel(self.model) filter_layout = QHBoxLayout() self.search_box = SearchBox() self.search_box.filterChanged.connect(self.setSearchString) filter_layout.addWidget(self.search_box) filter_popup_button = QToolButton() filter_popup_button.setIcon(util.resourceIcon("ide/cog_edit.png")) filter_popup_button.clicked.connect(self.showFilterPopup) filter_layout.addWidget(filter_popup_button) layout.addLayout(filter_layout) self.data_type_keys_widget = QListView() self.data_type_keys_widget.setModel(self.filter_model) self.data_type_keys_widget.selectionModel().selectionChanged.connect( self.itemSelected) layout.addSpacing(15) layout.addWidget(self.data_type_keys_widget, 2) layout.addStretch() # layout.addWidget(Legend("Default types", DataTypeKeysListModel.DEFAULT_DATA_TYPE)) layout.addWidget( Legend("Observations available", DataTypeKeysListModel.HAS_OBSERVATIONS)) self.setLayout(layout)
def __init__(self, panel): super(Dynamics, self).__init__(panel) self.removemenu = QToolButton(self, autoRaise=True, popupMode=QToolButton.InstantPopup, icon=icons.get('edit-clear')) mainwindow = panel.parent().mainwindow() mainwindow.selectionStateChanged.connect(self.removemenu.setEnabled) self.removemenu.setEnabled(mainwindow.hasSelection()) ac = documentactions.DocumentActions.instance( mainwindow).actionCollection self.removemenu.addAction(ac.tools_quick_remove_dynamics) layout = QHBoxLayout() layout.addWidget(self.removemenu) layout.addStretch(1) self.layout().addLayout(layout) self.layout().addWidget(DynamicGroup(self)) self.layout().addWidget(SpannerGroup(self)) self.layout().addStretch(1)
def _create_toolbar(self): toolbar = QToolBar() toolbar.setFloatable(False) toolbar.setMovable(False) self.layout_combo = LayoutCombo() toolbar.addWidget(self.layout_combo) self.layout_combo.layout_changed.connect(self._plot_layout_changed) self._settings_button = QToolButton() self._settings_button.setToolTip("Toggle settings visibility") self._settings_button.setIcon(resource_icon("cog.png")) self._settings_button.setCheckable(True) self._settings_button.toggled.connect(self._show_settings) toolbar.addWidget(self._settings_button) def toggle_on_close(event): self._settings_button.setChecked(False) event.accept() self._settings_window.closeEvent = toggle_on_close return toolbar
def queueStatusBarShow(self): """Add to QGIS status bar buttons to show and clear the VESPER queue""" # source: https://gis.stackexchange.com/a/153170 # https://github.com/ActiveState/code/blob/master/recipes/Python/578692_QGstartscript_Change_display/recipe-578692.py if not self.vesper_queue_showing: # it is not initiated self.iface.mainWindow().statusBar().setSizeGripEnabled(False) self.lblVesperQueue = QLabel() self.lblVesperQueue.setText('{} tasks in VESPER queue'.format(len(self.vesper_queue))) self.iface.mainWindow().statusBar().insertPermanentWidget(1, self.lblVesperQueue) self.btnShowQueue = QToolButton() # QToolButton() takes up less room self.btnShowQueue.setToolButtonStyle(Qt.ToolButtonTextOnly) self.btnShowQueue.setText("Show") self.btnShowQueue.clicked.connect(self.queueDisplay) self.iface.mainWindow().statusBar().insertPermanentWidget(2, self.btnShowQueue) self.btnClearQueue = QToolButton() # QPushButton() self.btnClearQueue.setToolButtonStyle(Qt.ToolButtonTextOnly) self.btnClearQueue.setText("Clear") self.btnClearQueue.pressed.connect(self.queueClear) self.iface.mainWindow().statusBar().insertPermanentWidget(3, self.btnClearQueue) self.vesper_queue_showing = True
def __init__(self): QWidget.__init__(self) layout = QHBoxLayout() layout.addSpacing(10) workflow_model = WorkflowsModel() # workflow_model.observable().attach(WorkflowsModel.CURRENT_CHOICE_CHANGED_EVENT, self.showWorkflow) workflow_combo = ComboChoice(workflow_model, "Select Workflow", "run/workflow") layout.addWidget(QLabel(workflow_combo.getLabel()), 0, Qt.AlignVCenter) layout.addWidget(workflow_combo, 0, Qt.AlignVCenter) # simulation_mode_layout.addStretch() layout.addSpacing(20) self.run_button = QToolButton() self.run_button.setIconSize(QSize(32, 32)) self.run_button.setText("Start Workflow") self.run_button.setIcon(util.resourceIcon("ide/gear_in_play")) self.run_button.clicked.connect(self.startWorkflow) self.run_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) layout.addWidget(self.run_button) layout.addStretch(1) self.setLayout(layout) self.__running_workflow_dialog = None self.workflowSucceeded.connect(self.workflowFinished) self.workflowFailed.connect(self.workflowFinishedWithFail) self.workflowKilled.connect(self.workflowStoppedByUser) self.__workflow_runner = None """:type: WorkflowRunner"""
def __init__(self, iface): """Constructor. :param iface: An interface instance that will be passed to this class which provides the hook by which you can manipulate the QGIS application at run time. :type iface: QgsInterface """ # Save reference to the QGIS interface self.iface = iface # initialize plugin directory self.plugin_dir = os.path.dirname(__file__) # initialize locale locale = QSettings().value('locale/userLocale')[0:2] locale_path = os.path.join( self.plugin_dir, 'i18n', 'Safecast_{}.qm'.format(locale)) if os.path.exists(locale_path): self.translator = QTranslator() self.translator.load(locale_path) if qVersion() > '4.3.3': QCoreApplication.installTranslator(self.translator) # Declare instance attributes self.actions = [] self.menu = self.tr(u'&Safecast') # add plugin icon into plugin toolbar self.toolButton = QToolButton() self.pluginIsActive = False self.dockwidget = None
def __init__(self): QWidget.__init__(self) layout = QHBoxLayout() layout.addSpacing(10) self._workflow_combo = QComboBox() addHelpToWidget(self._workflow_combo, "run/workflow") self._workflow_combo.addItems(getWorkflowNames()) layout.addWidget(QLabel("Select Workflow:"), 0, Qt.AlignVCenter) layout.addWidget(self._workflow_combo, 0, Qt.AlignVCenter) # simulation_mode_layout.addStretch() layout.addSpacing(20) self.run_button = QToolButton() self.run_button.setIconSize(QSize(32, 32)) self.run_button.setText("Start Workflow") self.run_button.setIcon(resourceIcon("ide/gear_in_play")) self.run_button.clicked.connect(self.startWorkflow) self.run_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) layout.addWidget(self.run_button) layout.addStretch(1) self.setLayout(layout) self._running_workflow_dialog = None self.workflowSucceeded.connect(self.workflowFinished) self.workflowFailed.connect(self.workflowFinishedWithFail) self.workflowKilled.connect(self.workflowStoppedByUser) self._workflow_runner = None """:type: WorkflowRunner"""
def __init__(self, parent): QLineEdit.__init__(self, parent) self._highlight_effect = QGraphicsDropShadowEffect(self) self._highlight_effect.setOffset(0.0) self._highlight_effect.setBlurRadius(5.0) self._highlight_effect.setColor(QColor(50, 50, 200)) self.setGraphicsEffect(self._highlight_effect) self._highlight_effect.setEnabled(False) self.clear_button = QToolButton(self) self.clear_button.setIcon( QIcon.fromTheme("edit-clear", QIcon("icons/delete_icon.png"))) self.clear_button.setCursor(Qt.ArrowCursor) self.clear_button.setStyleSheet( "QToolButton { border: none; padding: 1.5px; }") icon_size = int(self.sizeHint().height() * 0.65) self.clear_button.setIconSize(QSize(icon_size, icon_size)) self.clear_button.clicked.connect(self.clear) #self.clear_button.hide() # some padding stuff frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth) self.setStyleSheet("QLineEdit {{ padding-right: {}px; }} ".format( self.clear_button.sizeHint().width() + frameWidth))
def __init__(self, parent=None): QWidget.__init__(self, parent) layout = QGridLayout() self.setLayout(layout) self.mainInputLabel = QLabel("Main Source") self.mainInputComboBox = QComboBox() self.mainInputSetupButton = QToolButton() self.mainInputSetupButton.setText("Settings") configIcon = QIcon.fromTheme("preferences-other") self.mainInputSetupButton.setIcon(configIcon) self.mainInputSetupButton.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.mainInputSetupButton.setToolButtonStyle(Qt.ToolButtonIconOnly) self.mainInputSetupStack = QStackedWidget() blankWidget = QWidget() self.mainInputSetupStack.addWidget(blankWidget) self.mainInputSetupStack.addWidget(self.mainInputSetupButton) layout.addWidget(self.mainInputLabel, 0, 0) layout.addWidget(self.mainInputComboBox, 0, 1) layout.addWidget(self.mainInputSetupStack, 0, 2) self.pipInputLabel = QLabel("PIP Source") self.pipInputComboBox = QComboBox() self.pipInputSetupButton = QToolButton() self.pipInputSetupButton.setText("Settings") self.pipInputSetupButton.setIcon(configIcon) # reuse the one from main input self.pipInputSetupButton.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.pipInputSetupButton.setToolButtonStyle(Qt.ToolButtonIconOnly) self.pipInputSetupStack = QStackedWidget() blankWidget = QWidget() self.pipInputSetupStack.addWidget(blankWidget) self.pipInputSetupStack.addWidget(self.pipInputSetupButton) layout.addWidget(self.pipInputLabel, 1, 0) layout.addWidget(self.pipInputComboBox, 1, 1) layout.addWidget(self.pipInputSetupStack, 1, 2)
def _create_run_test_action(self): """Create action for running tests (developer mode, non final only).""" if self.hide_developer_buttons: return default_package = unicode( setting('testPackage', 'safe', expected_type=str)) msg = self.tr('Run tests in %s' % default_package) self.test_button = QToolButton() self.test_button.setMenu(QMenu()) self.test_button.setPopupMode(QToolButton.MenuButtonPopup) icon = resources_path('img', 'icons', 'run-tests.svg') self.action_run_tests = QAction(QIcon(icon), msg, self.iface.mainWindow()) self.action_run_tests.setStatusTip(msg) self.action_run_tests.setWhatsThis(msg) self.action_run_tests.triggered.connect(self.run_tests) self.test_button.menu().addAction(self.action_run_tests) self.test_button.setDefaultAction(self.action_run_tests) self.action_select_package = QAction(QIcon(icon), self.tr('Select package'), self.iface.mainWindow()) self.action_select_package.setStatusTip(self.tr('Select Test Package')) self.action_select_package.setWhatsThis(self.tr('Select Test Package')) self.action_select_package.triggered.connect(self.select_test_package) self.test_button.menu().addAction(self.action_select_package) self.toolbar.addWidget(self.test_button) self.add_action(self.action_run_tests, add_to_toolbar=False) self.add_action(self.action_select_package, add_to_toolbar=False)
def __init__(self, parent=None): QWidget.__init__(self, parent) # Components self.path_edit = QLineEdit(self) self.path_edit.setReadOnly(True) self.button = QToolButton(self) self.button.setIcon(QIcon.fromTheme("document-open-folder")) # Completer completer = QCompleter(self) completer.setModel(QDirModel(completer)) self.path_edit.setCompleter(completer) # Setup Widget self.setLayout(QHBoxLayout()) self.layout().setMargin(0) self.layout().setSpacing(0) self.layout().addWidget(self.path_edit) self.layout().addWidget(self.button) # Actions self.connect(self.button, SIGNAL('clicked()'), self.selectPath)
def addMixTab(self, tabs): tab_mix = QWidget(self) tabs.addTab(tab_mix, "Mix") tab_layout = QHBoxLayout() tab_mix.setLayout(tab_layout) in_labels = self.labels[self.id]["inputs"] in_idxs = self.inputs[self.id][0] mix_labels = self.labels[self.id]["mixers"] mix_idxs = self.mixers[self.id][0] for i in range(len(mix_idxs)): if mix_labels[i] == 'Aux 1/2': continue grp = QGroupBox(tab_mix) grp_layout = QVBoxLayout() grp.setLayout(grp_layout) tab_layout.addWidget(grp) label = QLabel(grp) grp_layout.addWidget(label) label.setText(mix_labels[i]) label.setAlignment(Qt.AlignCenter) label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) for j in range(len(in_idxs)): mix_in_id = self.mixers[self.id][2][j] button = QToolButton(grp) grp_layout.addWidget(button) button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) button.setText('%s In' % in_labels[j]) button.setCheckable(True) self.Mixers[button] = [ "/Mixer/EnhancedMixer_%d" % mix_idxs[i], mix_in_id, j, i ] grp_layout.addStretch() tab_layout.addStretch()
class ProtocolCountGraph_ui(Analysis_ui): ''' Description: Initialize the Men bar with actions and tool bar with tool buttons ''' def __init__(self, parent=None): Analysis_ui.__init__(self) self.parent = parent self.action = ProtocolCountGraphAction(self, parent) menuAnalysis = self.parent.GetMenu("Analysis") if menuAnalysis != None: menuAnalysis.addAction(self.action) toolBarAnalysis = self.parent.GetToolBar("Analysis") if toolBarAnalysis != None: pcgPixmap = QPixmap( os.path.dirname(os.path.realpath(__file__)) + '/barGraph.png') pcgIcon = QIcon(pcgPixmap) self.pcgButton = QToolButton(self.parent) self.pcgButton.setIcon(pcgIcon) self.pcgButton.setIconSize(QSize(32, 32)) self.pcgButton.clicked.connect(self.OnTrigger) toolBarAnalysis.addWidget(self.pcgButton) ''' Description: Set the packet list to be analysed and plot the graph ''' def OnTrigger(self): widget = self.parent.GetCurrentTab() if widget != None and isinstance(widget, PacketData_ui): obj = ProtocolCountGraph() obj.setPacketList(widget.packetList) obj.plotGraph()
def __createToolbar(self): " Creates the toolbar " self.__toolbar = QToolBar(self) self.__toolbar.setOrientation(Qt.Vertical) self.__toolbar.setMovable(False) self.__toolbar.setAllowedAreas(Qt.RightToolBarArea) self.__toolbar.setIconSize(QSize(16, 16)) self.__toolbar.setFixedWidth(28) self.__toolbar.setContentsMargins(0, 0, 0, 0) # Buttons saveAsMenu = QMenu(self) saveAsSVGAct = saveAsMenu.addAction(getIcon('filesvg.png'), 'Save as SVG...') saveAsSVGAct.triggered.connect(self.onSaveAsSVG) saveAsPDFAct = saveAsMenu.addAction(getIcon('filepdf.png'), 'Save as PDF...') saveAsPDFAct.triggered.connect(self.onSaveAsPDF) saveAsPNGAct = saveAsMenu.addAction(getIcon('filepixmap.png'), 'Save as PNG...') saveAsPNGAct.triggered.connect(self.onSaveAsPNG) saveAsMenu.addSeparator() saveAsCopyToClipboardAct = saveAsMenu.addAction( getIcon('copymenu.png'), 'Copy to clipboard') saveAsCopyToClipboardAct.triggered.connect(self.copyToClipboard) self.__saveAsButton = QToolButton(self) self.__saveAsButton.setIcon(getIcon('saveasmenu.png')) self.__saveAsButton.setToolTip('Save as') self.__saveAsButton.setPopupMode(QToolButton.InstantPopup) self.__saveAsButton.setMenu(saveAsMenu) self.__saveAsButton.setFocusPolicy(Qt.NoFocus) self.__toolbar.addWidget(self.__saveAsButton) return self.__toolbar
def buildfromauto(formconfig, base): widgetsconfig = formconfig['widgets'] outlayout = QFormLayout() outlayout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) outwidget = base outwidget.setLayout(outlayout) if roam.config.settings.get("form_geom_edit", False): geomwidget = GeomWidget() geomwidget.setObjectName("__geomwidget") outlayout.addRow("Geometry", geomwidget) for config in widgetsconfig: widgettype = config['widget'] field = config['field'] name = config.get('name', field) if not field: utils.warning("Field can't be null for {}".format(name)) utils.warning("Skipping widget") continue label = QLabel(name) label.setObjectName(field + "_label") widget = roam.editorwidgets.core.createwidget(widgettype, parent=base) widget.setObjectName(field) layoutwidget = QWidget() layoutwidget.setLayout(QBoxLayout(QBoxLayout.LeftToRight)) layoutwidget.layout().addWidget(widget) if config.get('rememberlastvalue', False): savebutton = QToolButton() savebutton.setObjectName('{}_save'.format(field)) layoutwidget.layout().addWidget(savebutton) outlayout.addRow(label, layoutwidget) outlayout.addItem(QSpacerItem(10, 500)) installflickcharm(outwidget) return outwidget
def __init__(self, parent=None): QWidget.__init__(self, parent) layout = QFormLayout() self.setLayout(layout) self.label = QLabel("Audio Input") self.inputLayout = QHBoxLayout() self.combobox = QComboBox() self.combobox.setMinimumWidth(150) self.inputSettingsToolButton = QToolButton() self.inputSettingsToolButton.setText("Settings") configIcon = QIcon.fromTheme("preferences-other") self.inputSettingsToolButton.setIcon(configIcon) self.inputSettingsToolButton.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.inputSettingsToolButton.setToolButtonStyle(Qt.ToolButtonIconOnly) self.inputSettingsStack = QStackedWidget() blankWidget = QWidget() self.inputSettingsStack.addWidget(blankWidget) self.inputSettingsStack.addWidget(self.inputSettingsToolButton) self.inputLayout.addWidget(self.combobox) self.inputLayout.addWidget(self.inputSettingsStack) layout.addRow(self.label, self.inputLayout)
def _setup_actions(self): ''' Bind actions to callbacks and setup keyboard shortcuts ''' # Keyboard shortcuts self.actOpenProject.setShortcut('Ctrl+O') self.actSaveProject.setShortcut('Ctrl+S') self.actSaveProjectAs.setShortcut('Ctrl+Shift+S') self.actCloseProject.setShortcut('Ctrl+W') self.actVariableLibrary.setShortcut('Ctrl+V') self.actLaunchResultBrowser.setShortcut('Ctrl+R') self.actDatabaseSettings.setShortcut('Ctrl+D') self.actPreferences.setShortcut('Ctrl+P') # Connect trigger slots using a little quickie function def connect(action, callback): QObject.connect(action, SIGNAL("triggered()"), callback) connect(self.actNewProject, self.newProject) connect(self.actOpenProject, self.openProject) connect(self.actSaveProject, self.saveProject) connect(self.actSaveProjectAs, self.saveProjectAs) connect(self.actCloseProject, self.closeProject) connect(self.actExit, self.close) connect(self.actAbout, self.openAbout) connect(self.actPreferences, self.openPreferences) connect(self.actDatabaseSettings, self.openDatabaseSettings) connect(self.actVariableLibrary, self.editAllVariables) connect(self.actLogView, self.openLogTab) connect(self.actLaunchResultBrowser, self.openResultBrowser) # Create a 'Close tab' widget action = QAction(self) action.setIcon(QIcon(':/Images/Images/cross.png')) connect(action, self.closeCurrentTab) widget = QToolButton(self) widget.setDefaultAction(action) widget.setWhatsThis('Close tab') widget.setToolTip('Close tab') self.tabWidget.setCornerWidget(widget) # GIS -- disabled for time being # connect(self.actionMap_View, self.openMapTab) # Disable some options by default self.actVariableLibrary.setEnabled(False) self.actLaunchResultBrowser.setEnabled(False)
def _addToolButton(self, action, featureType): toolButton = QToolButton(self) toolButton.setFixedWidth(30) toolButton.setFixedHeight(30) toolButton.setDefaultAction(action) geometryType = FeatureType.toGeometryType(featureType) if geometryType == QGis.Point: self._addToolWidget(self.pointToolLayout, toolButton, self._pointTool) self._pointTool += 1 elif geometryType == QGis.Line: self._addToolWidget(self.lineToolLayout, toolButton, self._lineTool) self._lineTool += 1 elif geometryType == QGis.Polygon: self._addToolWidget(self.polygonToolLayout, toolButton, self._polygonTool) self._polygonTool += 1