def __init__(self, parent_dialog, plugin_action): self.parent_dialog = parent_dialog self.plugin_action = plugin_action QWidget.__init__(self) self.l = QVBoxLayout() self.setLayout(self.l) label = QLabel(_("If you have custom columns defined, they will be listed below. Choose how you would like these columns handled.")) label.setWordWrap(True) self.l.addWidget(label) self.l.addSpacing(5) scrollable = QScrollArea() scrollcontent = QWidget() scrollable.setWidget(scrollcontent) scrollable.setWidgetResizable(True) self.l.addWidget(scrollable) self.sl = QVBoxLayout() scrollcontent.setLayout(self.sl) self.custcol_dropdowns = {} custom_columns = self.plugin_action.gui.library_view.model().custom_columns grid = QGridLayout() self.sl.addLayout(grid) row=0 for key, column in custom_columns.iteritems(): if column['datatype'] in permitted_values: # print("\n============== %s ===========\n"%key) # for (k,v) in column.iteritems(): # print("column['%s'] => %s"%(k,v)) label = QLabel('%s(%s)'%(column['name'],key)) label.setToolTip(_("Set this %s column on new merged books...")%column['datatype']) grid.addWidget(label,row,0) dropdown = QComboBox(self) dropdown.addItem('','none') for md in permitted_values[column['datatype']]: # tags-like column also 'text' if md == 'union' and not column['is_multiple']: continue if md == 'concat' and column['is_multiple']: continue dropdown.addItem(titleLabels[md],md) self.custcol_dropdowns[key] = dropdown if key in prefs['custom_cols']: dropdown.setCurrentIndex(dropdown.findData(prefs['custom_cols'][key])) dropdown.setToolTip(_("How this column will be populated by default.")) grid.addWidget(dropdown,row,1) row+=1 self.sl.insertStretch(-1)
def __init__(self, parent_dialog, plugin_action): self.parent_dialog = parent_dialog self.plugin_action = plugin_action QWidget.__init__(self) self.l = QVBoxLayout() self.setLayout(self.l) label = QLabel(_("If you have custom columns defined, they will be listed below. Choose how you would like these columns handled.")) label.setWordWrap(True) self.l.addWidget(label) self.l.addSpacing(5) scrollable = QScrollArea() scrollcontent = QWidget() scrollable.setWidget(scrollcontent) scrollable.setWidgetResizable(True) self.l.addWidget(scrollable) self.sl = QVBoxLayout() scrollcontent.setLayout(self.sl) self.custcol_dropdowns = {} custom_columns = self.plugin_action.gui.library_view.model().custom_columns grid = QGridLayout() self.sl.addLayout(grid) row=0 for key, column in custom_columns.iteritems(): if column['datatype'] in permitted_values: # logger.debug("\n============== %s ===========\n"%key) # for (k,v) in column.iteritems(): # logger.debug("column['%s'] => %s"%(k,v)) label = QLabel('%s(%s)'%(column['name'],key)) label.setToolTip(_("Set this %s column on new merged books...")%column['datatype']) grid.addWidget(label,row,0) dropdown = QComboBox(self) dropdown.addItem('','none') for md in permitted_values[column['datatype']]: # tags-like column also 'text' if md == 'union' and not column['is_multiple']: continue if md == 'concat' and column['is_multiple']: continue dropdown.addItem(titleLabels[md],md) self.custcol_dropdowns[key] = dropdown if key in prefs['custom_cols']: dropdown.setCurrentIndex(dropdown.findData(prefs['custom_cols'][key])) dropdown.setToolTip(_("How this column will be populated by default.")) grid.addWidget(dropdown,row,1) row+=1 self.sl.insertStretch(-1)
class CustomColumnsTab(QWidget): def __init__(self, parent_dialog, plugin_action): self.parent_dialog = parent_dialog self.plugin_action = plugin_action QWidget.__init__(self) self.l = QVBoxLayout() self.setLayout(self.l) label = QLabel( _("If you have custom columns defined, they will be listed below. Choose if you would like these columns copied to new split books." )) label.setWordWrap(True) self.l.addWidget(label) self.l.addSpacing(5) scrollable = QScrollArea() scrollcontent = QWidget() scrollable.setWidget(scrollcontent) scrollable.setWidgetResizable(True) self.l.addWidget(scrollable) self.sl = QVBoxLayout() scrollcontent.setLayout(self.sl) self.custcol_checkboxes = {} custom_columns = self.plugin_action.gui.library_view.model( ).custom_columns for key, column in custom_columns.iteritems(): # print("\n============== %s ===========\n"%key) # for (k,v) in column.iteritems(): # print("column['%s'] => %s"%(k,v)) checkbox = QCheckBox('%s(%s)' % (column['name'], key)) checkbox.setToolTip( _("Copy this %s column to new split books...") % column['datatype']) checkbox.setChecked(key in prefs['custom_cols'] and prefs['custom_cols'][key]) self.custcol_checkboxes[key] = checkbox self.sl.addWidget(checkbox) self.sl.insertStretch(-1) self.l.addSpacing(5) label = QLabel(_("Source column:")) label.setToolTip( _("If set, the column below will be populated with the template below to record the source of the split file." )) label.setWordWrap(True) self.l.addWidget(label) horz = QHBoxLayout() self.sourcecol = QComboBox(self) self.sourcecol.setToolTip( _("Choose a column to populate with template on split.")) self.sourcecol.addItem('', 'none') for key, column in custom_columns.iteritems(): if column['datatype'] in ('text', 'comments'): self.sourcecol.addItem(column['name'], key) self.sourcecol.setCurrentIndex( self.sourcecol.findData(prefs['sourcecol'])) horz.addWidget(self.sourcecol) self.sourcetemplate = QLineEdit(self) self.sourcetemplate.setToolTip( _("Template from source book. Example: {title} by {authors}")) # if 'sourcetemplate' in prefs: self.sourcetemplate.setText(prefs['sourcetemplate']) # else: # self.sourcetemplate.setText("{title} by {authors}") horz.addWidget(self.sourcetemplate) self.l.addLayout(horz)
class ParameterMeshGroupView(ParameterView): """Top-level table editor item.""" meshFileChanged = pyqtSignal(str, str, float, bool) meshGroupCheck = pyqtSignal(str, str, str) meshGroupUnCheck = pyqtSignal(str, str, str) meshChanged = pyqtSignal() """Signal: emitted when mesh is changed in the combo box.""" def __init__(self, panel, **kwargs): """ Create view. Arguments: **kwargs: Arbitrary keyword arguments. """ super(ParameterMeshGroupView, self).__init__(panel, **kwargs) self.setStretchable(True) self._mesh = QComboBox(self) self._mesh.setObjectName("MESH") self._msg = QLabel(self) self._list = QTreeWidget(self) self._list.setAllColumnsShowFocus(True) self._list.setSelectionMode(QTreeWidget.SingleSelection) self._list.setColumnCount(2) titles = [] titles.append(translate("AsterStudy", "Name")) titles.append(translate("AsterStudy", "Size")) self._list.setHeaderLabels(titles) self._list.header().setSectionResizeMode(QHeaderView.ResizeToContents) self._list.header().setStretchLastSection(True) manlabel = QLabel(translate("ParameterPanel", "Manual selection"), self) manlabel.setToolTip( translate( "ParameterPanel", "Enter manually the wanted groups if " "not present in the list")) self._manual = QLineEdit(self) self._manual.setObjectName("MANUAL_INPUT") base = self.grid() base.addWidget(self._mesh, 0, 0, 1, -1) base.addWidget(self._msg, 1, 0, 1, -1) base.addWidget(self._list, 2, 0, 1, -1) base.addWidget(manlabel, 3, 0, 1, -1) base.addWidget(self._manual, 4, 0, 1, -1) self._mesh.activated[int].connect(self._meshActivated) self._updateMeshList() self.meshFileChanged.connect(self.meshview().displayMEDFileName) self.meshGroupCheck.connect(self.meshview().displayMeshGroup) self.meshGroupUnCheck.connect(self.meshview().undisplayMeshGroup) self._list.itemChanged.connect(self.meshGroupToChange) def meshList(self): """ Gets the mesh commands list Returns: list (Command): List of commands with meshes. """ mlist = [] for i in xrange(self._mesh.count()): mlist.append(self._mesh.itemData(i).name) return mlist def setMeshList(self, meshlist): """ Sets the mesh commands list Arguments: meshlist: List of commands with meshes. """ self._mesh.clear() show_title = behavior().show_catalogue_name_in_selectors title_mask = '{n} ({t})' if show_title else '{n}' for meshcmd in meshlist: title = title_mask.format(n=meshcmd.name, t=meshcmd.title) self._mesh.addItem(title, meshcmd) def mesh(self): """ Gets the currently selected mesh command object or None in error case. Returns: Command: Current mesh command object. """ idx = self._mesh.currentIndex() return self._mesh.itemData(idx) if idx >= 0 else None def setMesh(self, mesh): """ Sets the current mesh command object if it exists in the list. Arguments: mesh: Current mesh command object. """ self._mesh.setCurrentIndex(self._mesh.findData(mesh)) def message(self): """ Gets the info message text. Returns: str: info message text. """ return self._msg.text() def setMessage(self, msg): """ Sets the info message text. Arguments: msg (str): info message text. """ self._msg.setText(msg) self._msg.setVisible(len(msg) > 0) def setMeshGroups(self, groups): """ Sets the mesh group list Arguments: groups (dict[int, list[tuple[str, int]]]): Mesh groups info. """ self._list.clear() grp_types = sorted(groups.keys()) for typ in grp_types: names = groups[typ] if not names: continue title = MeshElemType.value2str(typ) item = QTreeWidgetItem(self._list, [title]) for name, size in names: sub_item = QTreeWidgetItem(item, [name, str(size)]) sub_item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) sub_item.setCheckState(0, Qt.Unchecked) sub_item.setTextAlignment(1, Qt.AlignRight) self._list.expandAll() def inputMeshGroups(self): """ Gets the mesh group names list entered manually Returns: list (str): List of group names. """ text = self._manual.text().strip() return [i.strip() for i in text.split(",")] if len(text) > 0 else [] def setInputMeshGroups(self, groups): """ Sets the mesh group list entered manually Arguments: groups: List of mesh group names. """ self._manual.setText(",".join(groups)) def selectedMeshGroups(self): """ Gets the names of selected (checked) mesh groups. Returns: list (str): List of selected group names. """ groups = [] for i in range(self._list.topLevelItemCount()): item = self._list.topLevelItem(i) for j in xrange(item.childCount()): sub_item = item.child(j) if sub_item.checkState(0) == Qt.Checked: groups.append(sub_item.text(0)) return list(set(groups)) def setSelectedMeshGroups(self, groups): """ Sets the specified group names are selected (checked) and unchecked all other. Arguments: groups: List of selected mesh group names. """ for i in range(self._list.topLevelItemCount()): item = self._list.topLevelItem(i) for j in xrange(item.childCount()): sub_item = item.child(j) state = Qt.Checked if sub_item.text(0) in groups \ else Qt.Unchecked sub_item.setCheckState(0, state) @pyqtSlot(QTreeWidgetItem, int) def meshGroupToChange(self, item, column): """ Emits display signal whenever the user clicks a check box """ meshcmd = self._meshcmd(self._mesh.currentIndex()) if meshcmd is not None: file_name, nom_med = get_cmd_mesh(meshcmd) if file_name is not None and nom_med is not None: if item.checkState(column) == Qt.Checked: self.meshGroupCheck.emit(file_name, nom_med, item.text(0)) else: self.meshGroupUnCheck.emit(file_name, nom_med, item.text(0)) def _meshcmd(self, index): """ Returns the *Command* instance associated with the panel """ meshcmd = None if 0 <= index < self._mesh.count(): meshcmd = self._mesh.itemData(index) return meshcmd def itemValue(self, **kwargs): """ Get selected values. Returns: tuple: List with all selected mesh groups """ res = tuple(self.selectedMeshGroups() + self.inputMeshGroups()) return res if len(res) > 0 else None def setItemValue(self, values): """ Set values of child items. Arguments: values: Tuple with item values (see `childValues()`). """ grplist = [] if values is not None: if isinstance(values, (tuple, list)): grplist = list(values) else: grplist = [values] self.setSelectedMeshGroups(grplist) check = dict.fromkeys(self.selectedMeshGroups()) grplist = [grp for grp in grplist if grp not in check] self.setInputMeshGroups(grplist) self._cache = self.itemValue() def filterItem(self, text): """ Filter out the item. Arguments: text (str): Regular expression. """ regex = QRegExp(text, Qt.CaseInsensitive) for i in range(self._list.topLevelItemCount()): item = self._list.topLevelItem(i) cnt_visible = 0 for j in xrange(item.childCount()): sub_item = item.child(j) item_text = sub_item.text(0) hidden = text != "" and regex.indexIn(item_text) == -1 sub_item.setHidden(hidden) if not hidden: cnt_visible += 1 item.setHidden(cnt_visible == 0) def _updateMeshList(self): """ Updates the mesh list in the combobox """ meshlist = avail_meshes(parameterPanel(self).pendingStorage()) meshlist.reverse() self.setMeshList(meshlist) msg = "" if len(meshlist) > 1: msg = translate("ParameterPanel", "More than one mesh found") elif len(meshlist) == 0: msg = translate("ParameterPanel", "No mesh found") self.setMessage(msg) self._meshActivated(self._mesh.currentIndex()) def _meshActivated(self, index): """ Updates the mesh groups in checkable list. Invoked after mesh changing in mesh combobox. """ meshcmd = None if 0 <= index < self._mesh.count(): meshcmd = self._mesh.itemData(index) groups = {} if meshcmd is not None: group_type = self._meshGroupType() file_name, nom_med = get_cmd_mesh(meshcmd) if is_medfile(file_name) or is_reference(file_name): self.meshFileChanged.emit(file_name, nom_med, 0.1, False) try: groups = get_cmd_groups(meshcmd, group_type, with_size=True) except TypeError: pass self.setMeshGroups(groups) self.meshChanged.emit() def _meshGroupType(self): """ Get the type of the mesh group Returns: str: Mesh group type (see `MeshGroupType`). """ mgtype = -1 name = self.itemName() if name.endswith("_MA") or is_contains_word(name, "MA"): mgtype = MeshGroupType.GElement elif name.endswith("_NO") or is_contains_word(name, "NO"): mgtype = MeshGroupType.GNode return mgtype
class HotkeyWidget(QWidget): def __init__(self, prefs, configName, title): QWidget.__init__(self) self.l = QVBoxLayout() self.setLayout(self.l) self.configName = configName self.hotkeyLayout = QHBoxLayout() self.l.addLayout(self.hotkeyLayout) enabledLabel = QLabel(title) self.hotkeyLayout.addWidget(enabledLabel) self.enabledBox = QCheckBox() self.hotkeyLayout.addWidget(self.enabledBox) self.enabledBox.setChecked(prefs[configName + '_hotkey_enabled']) hotkeyLayout2 = QHBoxLayout() self.l.addLayout(hotkeyLayout2) ctrlLabel = QLabel("Ctrl") self.ctrlBox = QCheckBox() self.ctrlBox.setChecked(prefs[configName + '_hotkey_ctrl']) ctrlLabel.setBuddy(self.ctrlBox) hotkeyLayout2.addWidget(ctrlLabel) hotkeyLayout2.addWidget(self.ctrlBox) altLabel = QLabel("Alt") self.altBox = QCheckBox() self.altBox.setChecked(prefs[configName + '_hotkey_alt']) altLabel.setBuddy(self.altBox) hotkeyLayout2.addWidget(altLabel) hotkeyLayout2.addWidget(self.altBox) shiftLabel = QLabel("Shift") self.shiftBox = QCheckBox() self.shiftBox.setChecked(prefs[configName + '_hotkey_shift']) shiftLabel.setBuddy(self.shiftBox) hotkeyLayout2.addWidget(shiftLabel) hotkeyLayout2.addWidget(self.shiftBox) self.keycodeBox = QComboBox() for key, value in keycodes.iteritems(): self.keycodeBox.addItem(key, value) index = self.keycodeBox.findData(prefs[configName + '_hotkey_keycode']) if index != -1: self.keycodeBox.setCurrentIndex(index) hotkeyLayout2.addWidget(self.keycodeBox) def save_settings(self, prefs): prefs[self.configName + '_hotkey_enabled'] = self.enabledBox.isChecked() prefs[self.configName + '_hotkey_ctrl'] = self.ctrlBox.isChecked() prefs[self.configName + '_hotkey_alt'] = self.altBox.isChecked() prefs[self.configName + '_hotkey_shift'] = self.shiftBox.isChecked() prefs[self.configName + '_hotkey_keycode'] = keycodes[unicode(self.keycodeBox.currentText())]
def __init__(self, parent_dialog, plugin_action): self.parent_dialog = parent_dialog self.plugin_action = plugin_action QWidget.__init__(self) self.l = QVBoxLayout() self.setLayout(self.l) label = QLabel('<b>' + _('Standard Columns:') + '</b>') label.setWordWrap(True) self.l.addWidget(label) self.l.addSpacing(5) self.firstseries = QCheckBox(_('Take Series from first book'), self) self.firstseries.setToolTip( _('''If set, the Series name and index from the first book will be set on the merged book.''' )) self.firstseries.setChecked(prefs['firstseries']) self.l.addWidget(self.firstseries) self.l.addSpacing(5) label = QLabel('<b>' + _('Custom Columns:') + '</b>') label.setWordWrap(True) self.l.addWidget(label) label = QLabel( _("If you have custom columns defined, they will be listed below. Choose how you would like these columns handled." )) label.setWordWrap(True) self.l.addWidget(label) self.l.addSpacing(5) scrollable = QScrollArea() scrollcontent = QWidget() scrollable.setWidget(scrollcontent) scrollable.setWidgetResizable(True) self.l.addWidget(scrollable) self.sl = QVBoxLayout() scrollcontent.setLayout(self.sl) self.custcol_dropdowns = {} custom_columns = self.plugin_action.gui.library_view.model( ).custom_columns grid = QGridLayout() self.sl.addLayout(grid) row = 0 ## sort by visible Column Name (vs #name) for key, column in sorted(custom_columns.items(), key=lambda x: x[1]['name']): if column['datatype'] in permitted_values: # logger.debug("\n============== %s ===========\n"%key) label = QLabel('%s(%s)' % (column['name'], key)) label.setToolTip( _("Set this %s column on new merged books...") % column['datatype']) grid.addWidget(label, row, 0) dropdown = QComboBox(self) dropdown.addItem('', 'none') for md in permitted_values[column['datatype']]: # tags-like column also 'text' if md == 'union' and not column['is_multiple']: continue if md == 'concat' and column['is_multiple']: continue dropdown.addItem(titleLabels[md], md) self.custcol_dropdowns[key] = dropdown if key in prefs['custom_cols']: dropdown.setCurrentIndex( dropdown.findData(prefs['custom_cols'][key])) dropdown.setToolTip( _("How this column will be populated by default.")) grid.addWidget(dropdown, row, 1) row += 1 self.sl.insertStretch(-1)
class CustomColumnsTab(QWidget): def __init__(self, parent_dialog, plugin_action): self.parent_dialog = parent_dialog self.plugin_action = plugin_action QWidget.__init__(self) custom_columns = self.plugin_action.gui.library_view.model().custom_columns self.l = QVBoxLayout() self.setLayout(self.l) label = QLabel(_("Save Source column:")) label.setToolTip(_("If set, the column below will be populated with the template below to record the source of the split file.")) label.setWordWrap(True) self.l.addWidget(label) horz = QHBoxLayout() self.sourcecol = QComboBox(self) self.sourcecol.setToolTip(_("Choose a column to populate with template on split.")) self.sourcecol.addItem('','none') for key, column in custom_columns.iteritems(): if column['datatype'] in ('text','comments','series'): self.sourcecol.addItem(column['name'],key) self.sourcecol.setCurrentIndex(self.sourcecol.findData(prefs['sourcecol'])) horz.addWidget(self.sourcecol) self.sourcetemplate = QLineEdit(self) self.sourcetemplate.setToolTip(_("Template from source book. Example: {title} by {authors}")) # if 'sourcetemplate' in prefs: self.sourcetemplate.setText(prefs['sourcetemplate']) # else: # self.sourcetemplate.setText("{title} by {authors}") horz.addWidget(self.sourcetemplate) self.l.addLayout(horz) self.l.addSpacing(5) label = QLabel(_("If you have custom columns defined, they will be listed below. Choose if you would like these columns copied to new split books.")) label.setWordWrap(True) self.l.addWidget(label) self.l.addSpacing(5) scrollable = QScrollArea() scrollcontent = QWidget() scrollable.setWidget(scrollcontent) scrollable.setWidgetResizable(True) self.l.addWidget(scrollable) self.sl = QVBoxLayout() scrollcontent.setLayout(self.sl) self.custcol_checkboxes = {} for key, column in custom_columns.iteritems(): # print("\n============== %s ===========\n"%key) # for (k,v) in column.iteritems(): # print("column['%s'] => %s"%(k,v)) checkbox = QCheckBox('%s(%s)'%(column['name'],key)) checkbox.setToolTip(_("Copy this %s column to new split books...")%column['datatype']) checkbox.setChecked(key in prefs['custom_cols'] and prefs['custom_cols'][key]) self.custcol_checkboxes[key] = checkbox self.sl.addWidget(checkbox) self.sl.insertStretch(-1)