def __init__(self, *args, **kwargs): QWidget.__init__(self, *args, **kwargs) layout = QGridLayout(self) self.setLayout(layout) self.addButton = KPushButton(KStandardGuiItem.add()) self.editButton = KPushButton(KStandardGuiItem.configure()) self.removeButton = KPushButton(KStandardGuiItem.remove()) self.listBox = QListWidget() layout.setContentsMargins(1, 1, 1, 1) layout.setSpacing(0) layout.addWidget(self.listBox, 0, 0, 4, 1) layout.addWidget(self.addButton, 0, 1) layout.addWidget(self.editButton, 1, 1) layout.addWidget(self.removeButton, 2, 1) @self.addButton.clicked.connect def addClicked(): item = self.createItem() if self.openEditor(item): self.addItem(item) @self.editButton.clicked.connect def editClicked(): item = self.listBox.currentItem() item and self.editItem(item) @self.removeButton.clicked.connect def removeClicked(): item = self.listBox.currentItem() if item: self.removeItem(item) @self.listBox.itemDoubleClicked.connect def itemDoubleClicked(item): item and self.editItem(item) self.listBox.model().layoutChanged.connect(self.changed) def updateSelection(): selected = bool(self.listBox.currentItem()) self.editButton.setEnabled(selected) self.removeButton.setEnabled(selected) self.changed.connect(updateSelection) self.listBox.itemSelectionChanged.connect(updateSelection) updateSelection()
def __init__(self, parent): QSplitter.__init__(self, parent) parent.addPage(self, i18n("Parts")) # The part types overview widget. v = KVBox() self.addWidget(v) QLabel('<b>{0}</b>'.format(i18n("Available parts:")), v) allParts = QTreeWidget(v) addButton = KPushButton(KStandardGuiItem.add(), v) addButton.setToolTip(i18n("Add selected part to your score.")) # The listbox with selected parts v = KVBox() self.addWidget(v) QLabel('<b>{0}</b>'.format(i18n("Score:")), v) score = QListWidget(v) self.score = score # so the partList method can find us h = KHBox(v) removeButton = KPushButton(KStandardGuiItem.remove(), h) upButton = QToolButton(h) upButton.setIcon(KIcon("go-up")) downButton = QToolButton(h) downButton.setIcon(KIcon("go-down")) # The StackedWidget with settings partSettings = QStackedWidget() self.addWidget(partSettings) self.setStretchFactor(0, 1) self.setStretchFactor(1, 1) self.setStretchFactor(2, 1) self.setSizes((100, 100, 100)) allParts.setSelectionMode(QTreeWidget.ExtendedSelection) allParts.setRootIsDecorated(False) allParts.headerItem().setHidden(True) score.setSelectionMode(QListWidget.ExtendedSelection) score.setDragDropMode(QListWidget.InternalMove) class PartItem(QListWidgetItem): """ A part from the score, instantiating a config widget as well. """ def __init__(self, partClass): name = partClass.name() # partClass.name is a ki18n object QListWidgetItem.__init__(self, name, score) self.w = QGroupBox(name) partSettings.addWidget(self.w) self.part = partClass() layout = QVBoxLayout(self.w) self.part.widgets(layout) layout.addStretch(1) if score.count() == 1: score.setCurrentRow(0) self.setSelected(True) parent.enableButton(KPageDialog.Try, True) def showSettingsWidget(self): partSettings.setCurrentWidget(self.w) def remove(self): if score.count() == 1: parent.enableButton(KPageDialog.Try, False) sip.delete(self.w) sip.delete(self) # TODO: check if necessary @allParts.itemDoubleClicked.connect def addPart(item, col): if hasattr(item, "partClass"): PartItem(item.partClass) @allParts.itemClicked.connect def toggleExpand(item, col): item.setExpanded(not item.isExpanded()) @addButton.clicked.connect def addSelectedParts(): for item in allParts.selectedItems(): PartItem(item.partClass) @removeButton.clicked.connect def removeSelectedParts(): for item in score.selectedItems(): item.remove() def keepSel(func): """ Restore the selection and current element after reordering parts. """ def decorator(): selItems = score.selectedItems() curItem = score.currentItem() func() score.setCurrentItem(curItem) for i in selItems: i.setSelected(True) return decorator @upButton.clicked.connect @keepSel def moveUp(): """ Move selected parts up. """ for row in range(1, score.count()): if score.item(row).isSelected(): item = score.takeItem(row) score.insertItem(row - 1, item) @downButton.clicked.connect @keepSel def moveDown(): """ Move selected parts down. """ for row in range(score.count() - 1, -1, -1): if score.item(row).isSelected(): item = score.takeItem(row) score.insertItem(row + 1, item) @score.currentItemChanged.connect def showItem(cur, prev): if cur: cur.showSettingsWidget() from frescobaldi_app.scorewiz.parts import categories for name, parts in categories(): group = QTreeWidgetItem(allParts, [name]) group.setFlags(Qt.ItemIsEnabled) group.setIcon(0, KIcon("inode-directory")) for part in parts: p = QTreeWidgetItem(group, [part.name()]) p.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) p.partClass = part
def __init__(self, manager): self.manager = manager KDialog.__init__(self, manager.mainwin) self.setCaption(i18n("Expansion Manager")) self.setButtons(KDialog.ButtonCode( KDialog.Help | KDialog.Ok | KDialog.Close | KDialog.User1 | KDialog.User2 )) self.setButtonGuiItem(KDialog.User1, KStandardGuiItem.remove()) self.setButtonGuiItem(KDialog.User2, KStandardGuiItem.add()) self.setHelp("expand") layout = QVBoxLayout(self.mainWidget()) layout.setContentsMargins(0, 0, 0, 0) search = KTreeWidgetSearchLine() search.setClickMessage(i18n("Search...")) layout.addWidget(search) splitter = QSplitter() splitter.setOrientation(Qt.Vertical) layout.addWidget(splitter) tree = QTreeWidget() tree.setColumnCount(3) tree.setHeaderLabels((i18n("Name"), i18n("Description"), i18n("Shortcut"))) tree.setRootIsDecorated(False) tree.setAllColumnsShowFocus(True) search.setTreeWidget(tree) splitter.addWidget(tree) box = KVBox() splitter.addWidget(box) key = KKeySequenceWidget(box) key.layout().setContentsMargins(0, 0, 0, 0) key.layout().insertStretch(0, 1) key.setEnabled(False) edit = QTextEdit(box) edit.setAcceptRichText(False) edit.setStyleSheet("QTextEdit { font-family: monospace; }") edit.item = None edit.dirty = False ExpandHighlighter(edit.document()) # whats this etc. tree.setWhatsThis(i18n( "This is the list of defined expansions.\n\n" "Click on a row to see or change the associated text. " "Doubleclick a shortcut or its description to change it. " "You can also press F2 to edit the current shortcut.\n\n" "Use the buttons below to add or remove expansions.\n\n" "There are two ways to use the expansion: either type the " "shortcut in the text and then call the Expand function, or " "just call the Expand function (default shortcut: Ctrl+.), " "choose the expansion from the list and press Enter or click Ok." )) edit.setWhatsThis( "<html><head><style type='text/css'>" "td.short {{ font-family: monospace; font-weight: bold; }}" "</style></head><body>" "<p>{0}</p><table border=0 width=300 cellspacing=2><tbody>" "<tr><td class=short align=center>(|)</td><td>{1}</td></tr>" "<tr><td class=short align=center>@</td><td>{2}</td></tr>" "</tbody></table></body></html>".format( i18n("This is the text associated with the selected shortcut. " "Some characters have special meaning:"), i18n("Place the cursor on this spot."), i18n("Translate the following pitch."), )) self.searchLine = search self.treeWidget = tree self.key = key self.edit = edit self.restoreDialogSize(config()) # load the expansions for name in sorted(self.manager.expansionsList()): self.createItem(name, self.manager.description(name)) tree.sortByColumn(1, Qt.AscendingOrder) tree.setSortingEnabled(True) tree.resizeColumnToContents(1) self.user1Clicked.connect(self.removeItem) self.user2Clicked.connect(self.addItem) edit.textChanged.connect(self.editChanged) search.textChanged.connect(self.checkMatch) tree.itemSelectionChanged.connect(self.updateSelection) tree.itemChanged.connect(self.itemChanged, Qt.QueuedConnection) key.keySequenceChanged.connect(self.keySequenceChanged)