def create_action(win, name, control, command, icon = None, enabled=ALWAYS, tooltip=None, shortcut=None, status=None, togglecheck=None, checkstate=None, icon_name=None): if icon: action = QAction(get_icon(icon_name, icon), name, win) else: action = QAction(name, win) action.setEnabled(False) if shortcut: try: action.setShortcut(shortcut) except TypeError: action.setShortcuts(shortcut) if tooltip: action.setToolTip(translate('Menus', tooltip)) if togglecheck is not None: action.setCheckable(True) checked = int(checkstate) action.setChecked(bool(checked)) action.togglecheck = togglecheck action.enabled = enabled action.command = command action.control = control action.status = status return action
def __init__(self, parent=None, row=None, files=None, preview_mode=False, artwork=True, status=None): if status is None: status = {'cover_pattern': 'folder'} self.status = status QDialog.__init__(self, parent) winsettings('extendedtags', self) self.get_fieldlist = [] self.previewMode = preview_mode add = QColor.fromRgb(255, 255, 0) edit = QColor.fromRgb(0, 255, 0) remove = QColor.fromRgb(255, 0, 0) self._colors = {ADD: QBrush(add), EDIT: QBrush(edit), REMOVE: QBrush(remove)} self.table = QTableWidget(0, 2, self) self.table.setVerticalHeader(VerticalHeader()) self.table.verticalHeader().setVisible(False) self.table.setSortingEnabled(True) self.table.setSelectionBehavior(QAbstractItemView.SelectRows) self.table.setHorizontalHeaderLabels([ translate('Extended Tags', 'Field'), translate('Extended Tags', 'Value')]) header = self.table.horizontalHeader() header.setVisible(True) header.setSortIndicatorShown (True) header.setStretchLastSection (True) header.setSortIndicator (0, Qt.AscendingOrder) self.piclabel = PicWidget(buttons = True) self.connect(self.piclabel, SIGNAL('imageChanged'), self._imageChanged) if not isinstance(self.piclabel.removepic, QAction): self.connect(self.piclabel.removepic, SIGNAL('clicked()'), self.removePic) else: self.connect(self.piclabel.removepic, SIGNAL('triggered()'), self.removePic) if row >= 0 and files: buttons = MoveButtons(files, row) self.connect(buttons, SIGNAL('indexChanged'), self._prevnext) buttons.setVisible(True) else: buttons = MoveButtons([], row) buttons.setVisible(False) self._files = files self.okcancel = OKCancel() self.okcancel.insertWidget(0, buttons) self._reset = QToolButton() self._reset.setToolTip(translate('Extended Tags', 'Resets the selected fields to their original value.')) self._reset.setIcon(get_icon('edit-undo', ':/undo.png')) self.connect(self._reset, SIGNAL('clicked()'), self.resetFields) self.listbuttons = ListButtons() self.listbuttons.layout().addWidget(self._reset) self.listbuttons.moveup.hide() self.listbuttons.movedown.hide() listframe = QFrame() listframe.setFrameStyle(QFrame.Box) hbox = QHBoxLayout() hbox.addWidget(self.table, 1) hbox.addLayout(self.listbuttons, 0) listframe.setLayout(hbox) layout = QVBoxLayout() if artwork: imageframe = QFrame() imageframe.setFrameStyle(QFrame.Box) vbox = QVBoxLayout() vbox.setMargin(0) vbox.addWidget(self.piclabel) vbox.addStretch() vbox.addStrut(0) imageframe.setLayout(vbox) hbox = QHBoxLayout() hbox.addWidget(listframe, 1) hbox.addSpacing(4) hbox.addWidget(imageframe) hbox.addStrut(1) layout.addLayout(hbox) else: layout.addWidget(listframe) layout.addLayout(self.okcancel) self.setLayout(layout) self.connect(self.okcancel, SIGNAL("cancel"), self.closeMe) self.connect(self.table, SIGNAL("itemDoubleClicked(QTableWidgetItem *)"), self.editField) self.connect(self.table, SIGNAL("itemSelectionChanged()"), self._checkListBox) self.connect(self.okcancel, SIGNAL("ok"), self.okClicked) clicked = SIGNAL('clicked()') self.connect(self.listbuttons, SIGNAL('edit'), self.editField) self.connect(self.listbuttons.add, clicked, self.addField) self.connect(self.listbuttons.remove, clicked, self.removeField) self.connect(self.listbuttons, SIGNAL('duplicate'), self.duplicate) self.setMinimumSize(450, 350) self.canceled = False self.filechanged = False if row >= 0 and files: self._prevnext(row) else: self.loadFiles(files)
def __init__(self, parent=None, row=None, files=None, preview_mode=False, artwork=True, status=None): if status is None: status = {'cover_pattern': 'folder'} self.status = status QDialog.__init__(self, parent) winsettings('extendedtags', self) self.get_fieldlist = [] self.previewMode = preview_mode add = QColor.fromRgb(255, 255, 0) edit = QColor.fromRgb(0, 255, 0) remove = QColor.fromRgb(255, 0, 0) self._colors = { ADD: QBrush(add), EDIT: QBrush(edit), REMOVE: QBrush(remove) } self.table = QTableWidget(0, 2, self) self.table.setVerticalHeader(VerticalHeader()) self.table.verticalHeader().setVisible(False) self.table.setSortingEnabled(True) self.table.setSelectionBehavior(QAbstractItemView.SelectRows) self.table.setHorizontalHeaderLabels([ translate('Extended Tags', 'Field'), translate('Extended Tags', 'Value') ]) header = self.table.horizontalHeader() header.setVisible(True) header.setSortIndicatorShown(True) header.setStretchLastSection(True) header.setSortIndicator(0, Qt.AscendingOrder) self.piclabel = PicWidget(buttons=True) self.connect(self.piclabel, SIGNAL('imageChanged'), self._imageChanged) if not isinstance(self.piclabel.removepic, QAction): self.connect(self.piclabel.removepic, SIGNAL('clicked()'), self.removePic) else: self.connect(self.piclabel.removepic, SIGNAL('triggered()'), self.removePic) if row >= 0 and files: buttons = MoveButtons(files, row) self.connect(buttons, SIGNAL('indexChanged'), self._prevnext) buttons.setVisible(True) else: buttons = MoveButtons([], row) buttons.setVisible(False) self._files = files self.okcancel = OKCancel() self.okcancel.insertWidget(0, buttons) self._reset = QToolButton() self._reset.setToolTip( translate('Extended Tags', 'Resets the selected fields to their original value.')) self._reset.setIcon(get_icon('edit-undo', ':/undo.png')) self.connect(self._reset, SIGNAL('clicked()'), self.resetFields) self.listbuttons = ListButtons() self.listbuttons.layout().addWidget(self._reset) self.listbuttons.moveup.hide() self.listbuttons.movedown.hide() listframe = QFrame() listframe.setFrameStyle(QFrame.Box) hbox = QHBoxLayout() hbox.addWidget(self.table, 1) hbox.addLayout(self.listbuttons, 0) listframe.setLayout(hbox) layout = QVBoxLayout() if artwork: imageframe = QFrame() imageframe.setFrameStyle(QFrame.Box) vbox = QVBoxLayout() vbox.setMargin(0) vbox.addWidget(self.piclabel) vbox.addStretch() vbox.addStrut(0) imageframe.setLayout(vbox) hbox = QHBoxLayout() hbox.addWidget(listframe, 1) hbox.addSpacing(4) hbox.addWidget(imageframe) hbox.addStrut(1) layout.addLayout(hbox) else: layout.addWidget(listframe) layout.addLayout(self.okcancel) self.setLayout(layout) self.connect(self.okcancel, SIGNAL("cancel"), self.closeMe) self.connect(self.table, SIGNAL("itemDoubleClicked(QTableWidgetItem *)"), self.editField) self.connect(self.table, SIGNAL("itemSelectionChanged()"), self._checkListBox) self.connect(self.okcancel, SIGNAL("ok"), self.okClicked) clicked = SIGNAL('clicked()') self.connect(self.listbuttons, SIGNAL('edit'), self.editField) self.connect(self.listbuttons.add, clicked, self.addField) self.connect(self.listbuttons.remove, clicked, self.removeField) self.connect(self.listbuttons, SIGNAL('duplicate'), self.duplicate) self.setMinimumSize(450, 350) self.canceled = False self.filechanged = False if row >= 0 and files: self._prevnext(row) else: self.loadFiles(files)