def updateField(self, field: QtGui.QStandardItem): if field.checkState() == QtCore.Qt.Checked: if not field.data() in self.currentFieldSelection: self.currentFieldSelection = [] for i in range(self.model.rowCount()): field = self.model.item(i, 0) if field.checkState() == QtCore.Qt.Checked: self.currentFieldSelection.append(field.data()) else: if field.data() in self.currentFieldSelection: self.currentFieldSelection.remove(field.data()) self.updateMarker()
def __on_list_widget_item_changed(self, list_item: QStandardItem): """ Catches when items check-box was triggered. Enables/disables plugin. """ if list_item: status = list_item.checkState() == QtCore.Qt.Checked name = list_item.text() plugin = self._get_item_by_name(name) plugin.set_enabled(status)
def sync_checked_state(self, root: QStandardItem): result = [] target_state = root.checkState() node_stack = [root] while node_stack: cur_node = node_stack.pop(0) if not cur_node.checkState() == target_state: cur_node.setCheckState(target_state) for i in self._get_all_children(cur_node)[::-1]: node_stack.insert(0, i) return result
def listview_vectors_navi_item_change(item: QStandardItem): if NavigationConfigInputInterface.set_enable_flag is True: return vector: str = item.text() condition: dict = {'vector': vector} item_state: Qt.CheckState = item.checkState() if item_state == Qt.Checked: # checked state NavigationConfigInputInterface.log_entries_conditions.append( condition) elif item_state == Qt.Unchecked: # unchecked state NavigationConfigInputInterface.log_entries_conditions.remove( condition)
def checkState(self) -> QtCore.Qt.CheckState: if QStandardItem.checkState(self)==QtCore.Qt.Checked: print("ciao") return QStandardItem.checkState(self)
def __setupUi(self): """Set up the UI. """ if self.__macUnified: self.tab = QToolBar() self.addToolBar(Qt.TopToolBarArea, self.tab) self.setUnifiedTitleAndToolBarOnMac(True) # This does not seem to work self.setWindowFlags(self.windowFlags() & \ ~Qt.MacWindowToolBarButtonHint) self.tab.actionTriggered[QAction].connect( self.__macOnToolBarAction) central = QStackedWidget() central.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) else: self.tab = central = QTabWidget(self) # Add a close button to the bottom of the dialog # (to satisfy GNOME 3 which shows the dialog without a title bar). container = container_widget_helper() container.layout().addWidget(central) buttonbox = QDialogButtonBox(QDialogButtonBox.Close) buttonbox.rejected.connect(self.close) container.layout().addWidget(buttonbox) self.setCentralWidget(container) self.stack = central # General Tab tab = QWidget() self.addTab(tab, self.tr("General"), toolTip=self.tr("General Options")) form = QFormLayout() tab.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) nodes = QWidget(self, objectName="nodes") nodes.setLayout(QVBoxLayout()) nodes.layout().setContentsMargins(0, 0, 0, 0) cb_anim = QCheckBox(self.tr("Enable node animations"), objectName="enable-node-animations", toolTip=self.tr( "Enable shadow and ping animations for nodes " "in the workflow.")) self.bind(cb_anim, "checked", "schemeedit/enable-node-animations") nodes.layout().addWidget(cb_anim) form.addRow(self.tr("Nodes"), nodes) links = QWidget(self, objectName="links") links.setLayout(QVBoxLayout()) links.layout().setContentsMargins(0, 0, 0, 0) cb_show = QCheckBox(self.tr("Show channel names between widgets"), objectName="show-channel-names", toolTip=self.tr( "Show source and sink channel names " "over the links.")) self.bind(cb_show, "checked", "schemeedit/show-channel-names") links.layout().addWidget(cb_show) form.addRow(self.tr("Links"), links) quickmenu = QWidget(self, objectName="quickmenu-options") quickmenu.setLayout(QVBoxLayout()) quickmenu.layout().setContentsMargins(0, 0, 0, 0) cb1 = QCheckBox(self.tr("On double click"), toolTip=self.tr("Open quick menu on a double click " "on an empty spot in the canvas")) cb2 = QCheckBox(self.tr("On right click"), toolTip=self.tr("Open quick menu on a right click " "on an empty spot in the canvas")) cb3 = QCheckBox(self.tr("On space key press"), toolTip=self.tr("On Space key press while the mouse" "is hovering over the canvas.")) cb4 = QCheckBox(self.tr("On any key press"), toolTip=self.tr("On any key press while the mouse" "is hovering over the canvas.")) self.bind(cb1, "checked", "quickmenu/trigger-on-double-click") self.bind(cb2, "checked", "quickmenu/trigger-on-right-click") self.bind(cb3, "checked", "quickmenu/trigger-on-space-key") self.bind(cb4, "checked", "quickmenu/trigger-on-any-key") quickmenu.layout().addWidget(cb1) quickmenu.layout().addWidget(cb2) quickmenu.layout().addWidget(cb3) quickmenu.layout().addWidget(cb4) form.addRow(self.tr("Open quick menu on"), quickmenu) startup = QWidget(self, objectName="startup-group") startup.setLayout(QVBoxLayout()) startup.layout().setContentsMargins(0, 0, 0, 0) cb_splash = QCheckBox(self.tr("Show splash screen"), self, objectName="show-splash-screen") cb_welcome = QCheckBox(self.tr("Show welcome screen"), self, objectName="show-welcome-screen") self.bind(cb_splash, "checked", "startup/show-splash-screen") self.bind(cb_welcome, "checked", "startup/show-welcome-screen") startup.layout().addWidget(cb_splash) startup.layout().addWidget(cb_welcome) form.addRow(self.tr("On startup"), startup) toolbox = QWidget(self, objectName="toolbox-group") toolbox.setLayout(QVBoxLayout()) toolbox.layout().setContentsMargins(0, 0, 0, 0) exclusive = QCheckBox(self.tr("Only one tab can be open at a time")) self.bind(exclusive, "checked", "mainwindow/toolbox-dock-exclusive") toolbox.layout().addWidget(exclusive) form.addRow(self.tr("Tool box"), toolbox) tab.setLayout(form) # Output Tab tab = QWidget() self.addTab(tab, self.tr("Output"), toolTip="Output Redirection") form = QFormLayout() box = QWidget(self, objectName="streams") layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) cb1 = QCheckBox(self.tr("Standard output")) cb2 = QCheckBox(self.tr("Standard error")) self.bind(cb1, "checked", "output/redirect-stdout") self.bind(cb2, "checked", "output/redirect-stderr") layout.addWidget(cb1) layout.addWidget(cb2) box.setLayout(layout) form.addRow(self.tr("Redirect output"), box) box = QWidget() layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) combo = QComboBox() combo.addItems([ self.tr("Critical"), self.tr("Error"), self.tr("Warn"), self.tr("Info"), self.tr("Debug") ]) cb = QCheckBox(self.tr("Show output on 'Error'"), objectName="focus-on-error") self.bind(combo, "currentIndex", "logging/level") self.bind(cb, "checked", "output/show-on-error") layout.addWidget(combo) layout.addWidget(cb) box.setLayout(layout) form.addRow(self.tr("Logging"), box) box = QWidget() layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) cb1 = QCheckBox(self.tr("Stay on top"), objectName="stay-on-top") cb2 = QCheckBox(self.tr("Dockable"), objectName="output-dockable") self.bind(cb1, "checked", "output/stay-on-top") self.bind(cb2, "checked", "output/dockable") layout.addWidget(cb1) layout.addWidget(cb2) box.setLayout(layout) form.addRow(self.tr("Output window"), box) box = QWidget() layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) cb1 = QCheckBox(self.tr("Open in external browser"), objectName="open-in-external-browser") cb2 = QCheckBox(self.tr("Stay on top"), objectName="help-stay-on-top") cb3 = QCheckBox(self.tr("Dockable"), objectName="help-dockable") self.bind(cb1, "checked", "help/open-in-external-browser") self.bind(cb2, "checked", "help/stay-on-top") self.bind(cb3, "checked", "help/dockable") layout.addWidget(cb1) layout.addWidget(cb2) layout.addWidget(cb3) box.setLayout(layout) form.addRow(self.tr("Help window"), box) tab.setLayout(form) # Categories Tab tab = QWidget() layout = QVBoxLayout() view = QListView() from .. import registry reg = registry.global_registry() model = QStandardItemModel() settings = QSettings() for cat in reg.categories(): item = QStandardItem() item.setText(cat.name) item.setCheckable(True) visible, _ = category_state(cat, settings) item.setCheckState(Qt.Checked if visible else Qt.Unchecked) model.appendRow([item]) view.setModel(model) layout.addWidget(view) tab.setLayout(layout) model.itemChanged.connect(lambda item: save_category_state( reg.category(str(item.text())), _State(item.checkState() == Qt.Checked, -1), settings)) self.addTab(tab, "Categories") if self.__macUnified: # Need some sensible size otherwise mac unified toolbar 'takes' # the space that should be used for layout of the contents self.adjustSize()
def project_checked(self, item: QStandardItem): if item.hasChildren(): for index in range(item.rowCount()): item.child(index, 0).setCheckState(item.checkState())
def register(self, url=None): if url is str: url = [url] self.curr_layer = str(self.count_imagelayer()) layer = self.image_layers[self.curr_layer] = Layer( self.curr_layer, url, 0, self.parent, self.axes) layer.readfits(url[0]) ic = layer.image_control ic.control_dataField.clear() # always remove items first ic.control_dataField.addItems(layer.fits_fields) self.parent.parent_widget.actionDisplay_Header.setEnabled(True) self.parent.parent_widget.actionDisplay_Header.triggered.connect( self.parent.DisplayHeader) layer.updatedata_from_widget() ic.control_displayMode.clear() control_displaymode = ['Images'] for cidx, c_dm in enumerate( layer.img_slicer.slicers_axisinfo['CTYPE'][:-2]): control_displaymode.append( 'Transparent Contours - Dim {}'.format(c_dm)) ic.control_displayMode.addItems(control_displaymode) print('register layer: {}'.format(self.curr_layer)) layer.telescope = layer.img_slicer.header['TELESCOP'] layer.category = 'image' layer.updateColormapList() layer.set_plot_data() layer.drange = [np.nanmin(layer.img_data), np.nanmax(layer.img_data)] if layer.telescope == 'SDO/AIA': clrange = utils.sdo_aia_scale_dict(wavelength=layer.fits_data[ layer.fits_current_field_id].header['WAVELNTH']) else: clrange = {'low': None, 'high': None, 'log': False} ic.control_log_check.setChecked(clrange['log']) layer.init_drange_sliders(layer.drange, dmaxvalue=clrange['high'], dminvalue=clrange['low']) ## add the layer to the QListView widget layer.layer_title = self.layerTitle(layer.img_slicer.header) item = QStandardItem(' '.join(layer.layer_title.values())) item.setCheckable(True) item.setDragEnabled(True) item.setDropEnabled(False) item.setCheckState(Qt.Checked) item.setWhatsThis(self.curr_layer) self.List.model.insertRow(int(self.curr_layer), item) self.List.image_layers = self.image_layers ## update the layer layer.widget2layer() ## connect control signals layer.image_control_connect() ## plot the solar grid and limb if self.curr_layer == '0': self.axes.cla() # set the layer to be checked # embed() for itemname in ['Limb', 'Grid']: item = self.List.model.findItems(itemname)[0] self.image_layers[item.whatsThis()].parent = layer if not item.checkState(): item.setCheckState(Qt.Checked) else: self.image_layers[item.whatsThis()].im = [] print('self.toggle_im(True, layer)', self.image_layers[item.whatsThis()]) self.toggle_im(True, self.image_layers[item.whatsThis()]) ## plot the layer layer.plot() self.set_zorders()
# Add some textual items foods = [ '.pyx', '.py', '.c', '.pyi', '.dll', '.h', '.cpp', '.ipynb', '.txt', '.md', '.doc', '.docx', '.ppt', '.pptx', '.csv', '.xls', '.xlsx','.tab','.dat','.tsv', '.sav', '.zsav', '.sas7bdat' ] for food in foods: # create an item with a caption item = QStandardItem(food) # add a checkbox to it item.setCheckable(True) item.setTristate(False) item.setCheckState(Qt.Checked) # Add the item to the model model.appendRow(item) for i in range(model.rowCount()): txt = model.item(i).text() checked = QStandardItem.checkState(model.item(i)) print(txt, checked) # Apply the model to the list view list.setModel(model) # Show the window and run the app list.show() app.exec_()