class Genres(QWidget): def __init__(self, parent=None, status=None): QWidget.__init__(self, parent) if status is None: self._status = {} genres = load_genres() else: self._status = status genres = status['genres'] self.listbox = ListBox() self._itemflags = Qt.ItemIsSelectable | Qt.ItemIsEditable | Qt.ItemIsEnabled [self.listbox.addItem(self._createItem(z)) for z in genres] buttons = ListButtons() self.listbox.connectToListButtons(buttons) self.listbox.setAutoScroll(False) self.connect(buttons, SIGNAL('add'), self.add) self.connect(buttons, SIGNAL('edit'), self.edit) hbox = QHBoxLayout() hbox.addWidget(self.listbox, 1) hbox.addLayout(buttons, 0) self.setLayout(hbox) def _createItem(self, text): item = QListWidgetItem(text) item.setFlags(self._itemflags) return item def add(self): self.listbox.setAutoScroll(True) item = self._createItem('') self.listbox.addItem(item) self.listbox.clearSelection() self.listbox.setCurrentItem(item) self.listbox.editItem(item) self.listbox.setAutoScroll(False) def edit(self): self.listbox.setAutoScroll(True) self.listbox.editItem(self.listbox.currentItem()) self.listbox.setAutoScroll(False) def applySettings(self, control=None): item = self.listbox.item genres = [ unicode(item(row).text()) for row in xrange(self.listbox.count()) ] self._status['genres'] = genres
class Genres(QWidget): def __init__(self, parent=None, status=None): QWidget.__init__(self, parent) if status is None: self._status = {} genres = load_genres() else: self._status = status genres = status['genres'] self.listbox = ListBox() self._itemflags = Qt.ItemIsSelectable | Qt.ItemIsEditable | Qt.ItemIsEnabled [self.listbox.addItem(self._createItem(z)) for z in genres] buttons = ListButtons() self.listbox.connectToListButtons(buttons) self.listbox.setAutoScroll(False) self.connect(buttons, SIGNAL('add'), self.add) self.connect(buttons, SIGNAL('edit'), self.edit) hbox = QHBoxLayout() hbox.addWidget(self.listbox,1) hbox.addLayout(buttons, 0) self.setLayout(hbox) def _createItem(self, text): item = QListWidgetItem(text) item.setFlags(self._itemflags) return item def add(self): self.listbox.setAutoScroll(True) item = self._createItem('') self.listbox.addItem(item) self.listbox.clearSelection() self.listbox.setCurrentItem(item) self.listbox.editItem(item) self.listbox.setAutoScroll(False) def edit(self): self.listbox.setAutoScroll(True) self.listbox.editItem(self.listbox.currentItem()) self.listbox.setAutoScroll(False) def applySettings(self, control=None): item = self.listbox.item genres = [unicode(item(row).text()) for row in xrange(self.listbox.count())] self._status['genres'] = genres
class SortOptionEditor(QDialog): def __init__(self, options, parent = None): """options is a list of strings. Each a comma-delimited field list. Eg. ['artist, title', 'album, genre'] """ QDialog.__init__(self, parent) connect = lambda c, signal, s: self.connect(c, SIGNAL(signal), s) self.listbox = ListBox() self.listbox.setSelectionMode(self.listbox.ExtendedSelection) buttons = ListButtons() self.listbox.addItems(options) hbox = QHBoxLayout() hbox.addWidget(self.listbox, 1) hbox.addLayout(buttons) okcancel = OKCancel() vbox = QVBoxLayout() vbox.addLayout(hbox) vbox.addLayout(okcancel) self.setLayout(vbox) connect(buttons, "add", self.addPattern) connect(buttons, "edit", self.editItem) buttons.duplicate.setVisible(False) self.connect(okcancel, SIGNAL('ok'), self.applySettings) self.connect(okcancel, SIGNAL('cancel'), self.applySettings) self.listbox.connectToListButtons(buttons) self.listbox.editButton = buttons.edit connect(self.listbox, 'itemDoubleClicked(QListWidgetItem *)', self._doubleClicked) def addPattern(self): l = self.listbox.item patterns = [unicode(l(z).text()) for z in range(self.listbox.count())] row = self.listbox.currentRow() if row < 0: row = 0 (text, ok) = QInputDialog().getItem(self, translate("WebDB", 'Add sort option'), translate("WebDB", 'Enter a sorting option (a comma-separated list of fields. ' 'Eg. "artist, title")'), patterns, row) if ok: self.listbox.clearSelection() self.listbox.addItem(text) self.listbox.setCurrentRow(self.listbox.count() - 1) def _doubleClicked(self, item): self.editItem() def editItem(self, row=None): if row is None: row = self.listbox.currentRow() l = self.listbox.item patterns = [unicode(l(z).text()) for z in range(self.listbox.count())] (text, ok) = QInputDialog().getItem(self, translate("WebDB", 'Edit sort option'), translate("WebDB", 'Enter a sorting option (a comma-separated list of fields. ' 'Eg. "artist, title")'), patterns, row) if ok: item = l(row) item.setText(text) self.listbox.setItemSelected(item, True) def applySettings(self): item = self.listbox.item options = [unicode(item(row).text()) for row in xrange(self.listbox.count())] self.close() self.emit(SIGNAL('options'), options)
class SortOptionEditor(QDialog): def __init__(self, options, parent=None): """options is a list of strings. Each a comma-delimited field list. Eg. ['artist, title', 'album, genre'] """ QDialog.__init__(self, parent) connect = lambda c, signal, s: self.connect(c, SIGNAL(signal), s) self.listbox = ListBox() self.listbox.setSelectionMode(self.listbox.ExtendedSelection) buttons = ListButtons() self.listbox.addItems(options) hbox = QHBoxLayout() hbox.addWidget(self.listbox, 1) hbox.addLayout(buttons) okcancel = OKCancel() vbox = QVBoxLayout() vbox.addLayout(hbox) vbox.addLayout(okcancel) self.setLayout(vbox) connect(buttons, "add", self.addPattern) connect(buttons, "edit", self.editItem) buttons.duplicate.setVisible(False) self.connect(okcancel, SIGNAL('ok'), self.applySettings) self.connect(okcancel, SIGNAL('cancel'), self.applySettings) self.listbox.connectToListButtons(buttons) self.listbox.editButton = buttons.edit connect(self.listbox, 'itemDoubleClicked(QListWidgetItem *)', self._doubleClicked) def addPattern(self): l = self.listbox.item patterns = [unicode(l(z).text()) for z in range(self.listbox.count())] row = self.listbox.currentRow() if row < 0: row = 0 (text, ok) = QInputDialog().getItem( self, translate("WebDB", 'Add sort option'), translate( "WebDB", 'Enter a sorting option (a comma-separated list of fields. ' 'Eg. "artist, title")'), patterns, row) if ok: self.listbox.clearSelection() self.listbox.addItem(text) self.listbox.setCurrentRow(self.listbox.count() - 1) def _doubleClicked(self, item): self.editItem() def editItem(self, row=None): if row is None: row = self.listbox.currentRow() l = self.listbox.item patterns = [unicode(l(z).text()) for z in range(self.listbox.count())] (text, ok) = QInputDialog().getItem( self, translate("WebDB", 'Edit sort option'), translate( "WebDB", 'Enter a sorting option (a comma-separated list of fields. ' 'Eg. "artist, title")'), patterns, row) if ok: item = l(row) item.setText(text) self.listbox.setItemSelected(item, True) def applySettings(self): item = self.listbox.item options = [ unicode(item(row).text()) for row in xrange(self.listbox.count()) ] self.close() self.emit(SIGNAL('options'), options)