def __init__(self, parent=None, mainWindow=None, showDetailsButton=True, animatable=True): super(PackageDelegate, self).__init__(parent) self.webDialog = WebDialog(mainWindow) self.show_details_button = showDetailsButton self.rowAnimator = RowAnimator(parent.packageList) self.defaultIcon = QIcon( QPixmap('/usr/share/package-manager/data/tray-zero.svg').scaled( 32, 32)) #self.defaultIcon = KIcon(('package-x-generic', 'package_applications'), 32) self.defaultInstalledIcon = QIcon( QPixmap('/usr/share/package-manager/data/installed.svg').scaled( 32, 32)) #self.defaultInstalledIcon = KIcon(KIconLoader.loadOverlayed(('package-x-generic', 'package_applications'), CHECK_ICON, 32)) self.animatable = animatable self._max_height = ROW_HEIGHT self._rt_0 = QIcon(":/data/star_0.svg") self._rt_1 = QIcon(":/data/star_1.svg") self.types = { 'critical': (RED, _translate("Packaga Manager", 'critical')), 'security': (DARKRED, _translate("Packaga Manager", 'security')) } self.font = Pds.settings('font', 'Sans,10').split(',')[0] self.normalFont = QFont(self.font, 10, QFont.Normal) self.boldFont = QFont(self.font, 11, QFont.Bold) self.normalDetailFont = QFont(self.font, 9, QFont.Normal) self.boldDetailFont = QFont(self.font, 9, QFont.Bold) self.tagFont = QFont(self.font, 7, QFont.Normal) self.tagFontFM = QFontMetrics(self.tagFont) self.boldFontFM = QFontMetrics(self.boldFont) self.boldDetailFontFM = QFontMetrics(self.boldDetailFont) self.normalFontFM = QFontMetrics(self.normalFont) self.normalDetailFontFM = QFontMetrics(self.normalDetailFont) self._titles = { 'description': _translate("Packaga Manager", "Description:"), 'website': _translate("Packaga Manager", "Website:"), 'release': _translate("Packaga Manager", "Release:"), 'repository': _translate("Packaga Manager", "Repository:"), 'size': _translate("Packaga Manager", "Package Size:"), 'installVers': _translate("Packaga Manager", "Installed Version:") } self._titleFM = {} for key, value in self._titles.items(): self._titleFM[key] = self.boldDetailFontFM.width( value) + ICON_SIZE + 3 self.baseWidth = self.boldFontFM.width( max(self._titles.values(), key=len)) + ICON_SIZE self.parent = parent.packageList
def __init__(self, parent=None, mainWindow=None, showDetailsButton=True, animatable=True): super(PackageDelegate, self).__init__(parent) self.webDialog = WebDialog(mainWindow) self.show_details_button = showDetailsButton self.rowAnimator = RowAnimator(parent.packageList) KIconLoader().addExtraDesktopThemes() self.defaultIcon = QtGui.QIcon(KIconLoader().loadIcon('applications-other', \ KIconLoader.Desktop, 32)) self.defaultInstalledIcon = QtGui.QIcon(KIconLoader().loadIcon('applications-other', KIconLoader.Desktop, 32, KIconLoader.DefaultState, [CHECK_ICON])) self.animatable = animatable self._max_height = ROW_HEIGHT self._rt_0 = QtGui.QIcon(":/data/star_0.png") self._rt_1 = QtGui.QIcon(":/data/star_1.png") self.types = {'critical':(RED, i18n('critical')), 'security':(DARKRED, i18n('security'))} self.font = QtGui.qApp.font().toString().split(',')[0] self.normalFont = QtGui.QFont(self.font, 10, QtGui.QFont.Normal) self.boldFont = QtGui.QFont(self.font, 11, QtGui.QFont.Bold) self.normalDetailFont = QtGui.QFont(self.font, 9, QtGui.QFont.Normal) self.boldDetailFont = QtGui.QFont(self.font, 9, QtGui.QFont.Bold) self.tagFont = QtGui.QFont(self.font, 7, QtGui.QFont.Normal) self.tagFontFM = QtGui.QFontMetrics(self.tagFont) self.boldFontFM = QtGui.QFontMetrics(self.boldFont) self.boldDetailFontFM = QtGui.QFontMetrics(self.boldDetailFont) self.normalFontFM = QtGui.QFontMetrics(self.normalFont) self.normalDetailFontFM = QtGui.QFontMetrics(self.normalDetailFont) self._titles = {'description': i18n("Description:"), 'website' : i18n("Website:"), 'release' : i18n("Release:"), 'repository' : i18n("Repository:"), 'size' : i18n("Package Size:"), 'installVers': i18n("Installed Version:")} self._titleFM = {} for key, value in self._titles.items(): self._titleFM[key] = self.boldDetailFontFM.width(value) + ICON_SIZE + 3 self.baseWidth = self.boldFontFM.width(max(self._titles.values(), key=len)) + ICON_SIZE self.parent = parent.packageList # Base style for some of important features self.oxygen = QtGui.QStyleFactory.create('oxygen')
def __init__(self, parent = None): QWidget.__init__(self, parent) self.setupUi(self) self.parent = parent self._selectedGroups = [] self._preexceptions = [] self._postexceptions = [] self.state = StateManager(self) self.currentState = None self.completer = None self._updatesCheckedOnce = False #set style self._style = "/usr/share/kde4/apps/package-manager/data/style.qss" self.setStyleSheet(file(self._style).read()) # Search Thread self._searchThread = PThread(self, self.startSearch, self.searchFinished) self.statusUpdater = StatusUpdater() self.basket = BasketDialog(self.state, self.parent) self._postexceptions.append(lambda: self.basket.setActionEnabled(True)) self.searchButton.setIcon(KIcon("edit-find")) self.initializeUpdateTypeList() self.morewidgets = MoreWidgets(self.state, self.parent) self._postexceptions.append(lambda: self.morewidgets.setActionEnabled(True)) self.morewidgets._show() self.webdialog = WebDialog(self.state, self.parent) model = PackageModel(self) proxy = PackageProxy(self) proxy.setSourceModel(model) self.packageList.setModel(proxy) self.packageList.setItemDelegate(PackageDelegate(self, self.parent)) self.packageList.setColumnWidth(0, 32) self.connect(self.packageList.model(), SIGNAL("dataChanged(QModelIndex,QModelIndex)"), self.statusChanged) self.connect(self.packageList, SIGNAL("updateRequested()"), self.initialize) self.connect(self.morewidgets.randomPackageList, SIGNAL("itemDoubleClicked(QListWidgetItem*)"), self.showWebdialog) self.updateSettings() self.setActionButton() self.operation = OperationManager(self.state) self.progressDialog = ProgressDialog(self.state, self.parent) self._preexceptions.append(self.progressDialog._hide) self.progressDialog.registerFunction(FINISHED, lambda: self.parent.statusBar().setVisible(not self.progressDialog.isVisible())) self.progressDialog.registerFunction(OUT, lambda: self.parent.statusBar().show()) self.summaryDialog = SummaryDialog() self.connectOperationSignals() self.pdsMessageBox = PMessageBox(self.content)
def __init__(self, parent=None, mainWindow=None, showDetailsButton=True, animatable=True): super(PackageDelegate, self).__init__(parent) self.state = StateManager(self) self.webDialog = WebDialog(self.state, mainWindow) self.show_details_button = showDetailsButton self.rowAnimator = RowAnimator(parent.packageList) KIconLoader().addExtraDesktopThemes() self.defaultIcon = QtGui.QIcon(KIconLoader().loadIcon('applications-other', \ KIconLoader.Desktop, 32)) self.defaultInstalledIcon = QtGui.QIcon(KIconLoader().loadIcon('applications-other', KIconLoader.Desktop, 32, KIconLoader.DefaultState, [CHECK_ICON])) self.animatable = animatable self._max_height = ROW_HEIGHT self._rt_0 = QtGui.QIcon(":/data/star_0.png") self._rt_1 = QtGui.QIcon(":/data/star_1.png") self.types = {'critical':(RED, i18n('critical')), 'security':(DARKRED, i18n('security'))} self.font = QtGui.qApp.font().toString().split(',')[0] self.normalFont = QtGui.QFont(self.font, 10, QtGui.QFont.Normal) self.boldFont = QtGui.QFont(self.font, 11, QtGui.QFont.Bold) self.normalDetailFont = QtGui.QFont(self.font, 9, QtGui.QFont.Normal) self.boldDetailFont = QtGui.QFont(self.font, 9, QtGui.QFont.Bold) self.tagFont = QtGui.QFont(self.font, 7, QtGui.QFont.Normal) self.tagFontFM = QtGui.QFontMetrics(self.tagFont) self.boldFontFM = QtGui.QFontMetrics(self.boldFont) self.boldDetailFontFM = QtGui.QFontMetrics(self.boldDetailFont) self.normalFontFM = QtGui.QFontMetrics(self.normalFont) self.normalDetailFontFM = QtGui.QFontMetrics(self.normalDetailFont) self._titles = {'description': i18n("Description:"), 'website' : i18n("Website:"), 'release' : i18n("Release:"), 'repository' : i18n("Repository:"), 'size' : i18n("Package Size:"), 'installVers': i18n("Installed Version:")} self._titleFM = {} for key, value in self._titles.items(): self._titleFM[key] = self.boldDetailFontFM.width(value) + ICON_SIZE + 3 self.baseWidth = self.boldFontFM.width(max(self._titles.values(), key=len)) + ICON_SIZE self.parent = parent.packageList # Base style for some of important features self.oxygen = QtGui.QStyleFactory.create('oxygen')
def __init__(self, parent=None, mainWindow=None, showDetailsButton=True, animatable=True): super(PackageDelegate, self).__init__(parent) self.webDialog = WebDialog(mainWindow) self.show_details_button = showDetailsButton self.rowAnimator = RowAnimator(parent.packageList) self.defaultIcon = QIcon(QPixmap('/usr/share/package-manager/data/tray-zero.svg').scaled(32, 32)) #self.defaultIcon = KIcon(('package-x-generic', 'package_applications'), 32) self.defaultInstalledIcon = QIcon(QPixmap('/usr/share/package-manager/data/installed.svg').scaled(32, 32)) #self.defaultInstalledIcon = KIcon(KIconLoader.loadOverlayed(('package-x-generic', 'package_applications'), CHECK_ICON, 32)) self.animatable = animatable self._max_height = ROW_HEIGHT self._rt_0 = QIcon(":/data/star_0.svg") self._rt_1 = QIcon(":/data/star_1.svg") self.types = {'critical':(RED, _translate("Packaga Manager",'critical')), 'security':(DARKRED, _translate("Packaga Manager",'security'))} self.font = Pds.settings('font','Sans,10').split(',')[0] self.normalFont = QFont(self.font, 10, QFont.Normal) self.boldFont = QFont(self.font, 11, QFont.Bold) self.normalDetailFont = QFont(self.font, 9, QFont.Normal) self.boldDetailFont = QFont(self.font, 9, QFont.Bold) self.tagFont = QFont(self.font, 7, QFont.Normal) self.tagFontFM = QFontMetrics(self.tagFont) self.boldFontFM = QFontMetrics(self.boldFont) self.boldDetailFontFM = QFontMetrics(self.boldDetailFont) self.normalFontFM = QFontMetrics(self.normalFont) self.normalDetailFontFM = QFontMetrics(self.normalDetailFont) self._titles = {'description': _translate("Packaga Manager","Description:"), 'website' : _translate("Packaga Manager","Website:"), 'release' : _translate("Packaga Manager","Release:"), 'repository' : _translate("Packaga Manager","Repository:"), 'size' : _translate("Packaga Manager","Package Size:"), 'installVers': _translate("Packaga Manager","Installed Version:")} self._titleFM = {} for key, value in self._titles.items(): self._titleFM[key] = self.boldDetailFontFM.width(value) + ICON_SIZE + 3 self.baseWidth = self.boldFontFM.width(max(self._titles.values(), key=len)) + ICON_SIZE self.parent = parent.packageList
class PackageDelegate(QStyledItemDelegate): packageSelected=pyqtSignal([bool]) AppStyle = qApp.style def __init__(self, parent=None, mainWindow=None, showDetailsButton=True, animatable=True): super(PackageDelegate, self).__init__(parent) self.webDialog = WebDialog(mainWindow) self.show_details_button = showDetailsButton self.rowAnimator = RowAnimator(parent.packageList) self.defaultIcon = KIcon(('package-x-generic', 'package_applications'), 32) self.defaultInstalledIcon = QIcon(KIconLoader.loadOverlayed(('package-x-generic', 'package_applications'), CHECK_ICON, 32)) self.animatable = animatable self._max_height = ROW_HEIGHT self._rt_0 = QIcon(":/data/star_0.svg") self._rt_1 = QIcon(":/data/star_1.svg") self.types = {'critical':(RED, _translate("Packaga Manager",'critical')), 'security':(DARKRED, _translate("Packaga Manager",'security'))} self.font = Pds.settings('font','Sans,10').split(',')[0] self.normalFont = QFont(self.font, 10, QFont.Normal) self.boldFont = QFont(self.font, 11, QFont.Bold) self.normalDetailFont = QFont(self.font, 9, QFont.Normal) self.boldDetailFont = QFont(self.font, 9, QFont.Bold) self.tagFont = QFont(self.font, 7, QFont.Normal) self.tagFontFM = QFontMetrics(self.tagFont) self.boldFontFM = QFontMetrics(self.boldFont) self.boldDetailFontFM = QFontMetrics(self.boldDetailFont) self.normalFontFM = QFontMetrics(self.normalFont) self.normalDetailFontFM = QFontMetrics(self.normalDetailFont) self._titles = {'description': _translate("Packaga Manager","Description:"), 'website' : _translate("Packaga Manager","Website:"), 'release' : _translate("Packaga Manager","Release:"), 'repository' : _translate("Packaga Manager","Repository:"), 'size' : _translate("Packaga Manager","Package Size:"), 'installVers': _translate("Packaga Manager","Installed Version:")} self._titleFM = {} for key, value in self._titles.items(): self._titleFM[key] = self.boldDetailFontFM.width(value) + ICON_SIZE + 3 self.baseWidth = self.boldFontFM.width(max(self._titles.values(), key=len)) + ICON_SIZE self.parent = parent.packageList # Base style for some of important features # self.plastik = QStyleFactory.create('plastique') def paint(self, painter, option, index): if not index.isValid(): return super(PackageDelegate, self).paint(painter, option, index) if index.flags() & Qt.ItemIsUserCheckable: if index.column() == 0: self.paintCheckBoxColumn(painter, option, index) else: self.paintInfoColumn(painter, option, index) else: self.paintInfoColumn(painter, option, index, width_limit = 10) def paintCheckBoxColumn(self, painter, option, index): opt = QStyleOptionViewItem(option) buttonStyle = QStyleOptionButton() buttonStyle.state = QStyle.State_On if index.model().data(index, Qt.CheckStateRole) == QVariant(Qt.Checked) else QStyle.State_Off buttonStyle.state |= QStyle.State_Enabled if option.state & QStyle.State_MouseOver or option.state & QStyle.State_HasFocus: buttonStyle.state |= QStyle.State_HasFocus | QStyle.State_MouseOver buttonStyle.rect = opt.rect.adjusted(4, -opt.rect.height() + ROW_HEIGHT, 0, 0) PackageDelegate.AppStyle().drawControl(QStyle.CE_CheckBox, buttonStyle, painter, None) def paintInfoColumn(self, painter, option, index, width_limit = 0): left = option.rect.left() + 3 top = option.rect.top() width = option.rect.width() - width_limit pixmap = QPixmap(option.rect.size()) pixmap.fill(Qt.transparent) p = QPainter(pixmap) p.setRenderHint(QPainter.Antialiasing, True) p.translate(-option.rect.topLeft()) textInner = 2 * ICON_PADDING + ROW_HEIGHT - 10 itemHeight = ROW_HEIGHT + 2 * ICON_PADDING margin = left + ICON_PADDING - 10 title = QVariant.value(index.model().data(index, NameRole)) summary = QVariant.value(index.model().data(index, SummaryRole)) ptype = QVariant.value(index.model().data(index, TypeRole)) rate = int(QVariant.value(index.model().data(index, RateRole))) if QVariant.value(index.model().data(index, RateRole))!= None else 0 installed = True if QVariant.value(index.model().data(index, InstalledRole))=="True" else False # We need to request update if its not possible to get meta data about the package try: # Get Package Icon if exists _icon = QVariant.value(index.model().data(index, Qt.DecorationRole)) except: p.end() painter.drawPixmap(option.rect.topLeft(), pixmap) self.parent.requestUpdate() return icon = None if _icon: overlay = [CHECK_ICON] if installed else [] KIconLoader._forceCache = True pix = KIconLoader.loadOverlayed(_icon, overlay, 32) if not pix.isNull(): icon = QIcon(pix.scaled(QSize(32, 32), Qt.KeepAspectRatio, Qt.SmoothTransformation)) KIconLoader._forceCache = False if not icon: icon = self.defaultIcon if not installed else self.defaultInstalledIcon # Paint the Icon icon.paint(p, margin, top + ICON_PADDING, ROW_HEIGHT, ROW_HEIGHT, Qt.AlignCenter) fix_pos = 0 if index.model().columnCount() <= 1: fix_pos = 22 if config.USE_APPINFO: # Rating Stars for _rt_i in range(5): self._rt_0.paint(p, width + 10 * _rt_i - 30 - fix_pos, top + ROW_HEIGHT / 4, 10, 10, Qt.AlignCenter) for _rt_i in range(rate): self._rt_1.paint(p, width + 10 * _rt_i - 30 - fix_pos, top + ROW_HEIGHT / 4, 10, 10, Qt.AlignCenter) foregroundColor = option.palette.color(QPalette.Text) p.setPen(foregroundColor) # Package Name p.setFont(self.boldFont) p.drawText(left + textInner, top, width - textInner, itemHeight / 2,Qt.AlignBottom | Qt.AlignLeft, title) # tagWidth = 0 _component_width = 0 if self.parent.showComponents: component = str(QVariant.value(index.model().data(index, ComponentRole))) widthOfTitle = self.boldFontFM.width(title) + 6 + left + textInner p.setFont(self.tagFont) rect = self.tagFontFM.boundingRect(option.rect, Qt.TextWordWrap, component) p.setPen(LIGHTGREEN) p.setBrush(LIGHTGREEN) p.drawRoundedRect(widthOfTitle , top + 12, rect.width() + 4, rect.height(), 10, 10) p.setPen(DARKGREEN) p.drawText(widthOfTitle + 2, top + 12, rect.width(), rect.height(), Qt.AlignCenter, component) p.setPen(foregroundColor) _component_width = rect.width() + 8 if self.parent.showIsA: isa = str(QVariant.value(index.model().data(index, IsaRole))) if not isa == '': widthOfTitle = self.boldFontFM.width(title) + 6 + left + textInner + _component_width p.setFont(self.tagFont) rect = self.tagFontFM.boundingRect(option.rect, Qt.TextWordWrap, isa) p.setPen(LIGHTBLUE) p.setBrush(LIGHTBLUE) p.drawRoundedRect(widthOfTitle , top + 12, rect.width() + 4, rect.height(), 10, 10) p.setPen(DARKVIOLET) p.drawText(widthOfTitle + 2, top + 12, rect.width(), rect.height(), Qt.AlignCenter, isa) p.setPen(foregroundColor) _component_width += rect.width() + 8 if ptype not in ('None', 'normal'): widthOfTitle = self.boldFontFM.width(title) + 6 + left + textInner + _component_width p.setFont(self.tagFont) rect = self.tagFontFM.boundingRect(option.rect, Qt.TextWordWrap, self.types[ptype][1]) p.setPen(self.types[ptype][0]) p.setBrush(self.types[ptype][0]) p.drawRoundedRect(widthOfTitle, top + 12, rect.width() + 4, rect.height(), 10, 10) p.setPen(WHITE) p.drawText(widthOfTitle + 2, top + 12, rect.width(), rect.height(), Qt.AlignCenter, self.types[ptype][1]) p.setPen(foregroundColor) tagWidth = rect.width() # Package Summary p.setFont(self.normalFont) foregroundColor.setAlpha(160) p.setPen(foregroundColor) elided_summary = self.normalFontFM.elidedText(summary, Qt.ElideRight, width - textInner - tagWidth - 22) p.drawText(left + textInner, top + itemHeight / 2, width - textInner, itemHeight / 2, Qt.TextDontClip, elided_summary) foregroundColor.setAlpha(255) p.setPen(foregroundColor) buttonStyle = None if self.rowAnimator.currentRow() == index.row(): description = str(QVariant.value(index.model().data(index, DescriptionRole))) size = str(QVariant.value(index.model().data(index, SizeRole))) homepage = str(QVariant.value(index.model().data(index, HomepageRole))) installedVersion = str(QVariant.value(index.model().data(index, InstalledVersionRole))) version = str(QVariant.value(index.model().data(index, VersionRole))) # Package Detail Label position = top + ROW_HEIGHT p.setFont(self.normalDetailFont) baseRect = QRect(left, position, width - 8, option.rect.height()) rect = self.normalDetailFontFM.boundingRect(baseRect, Qt.TextWordWrap | Qt.TextDontClip, description) p.drawText(left + 2, position, width - 8, rect.height(), Qt.TextWordWrap | Qt.TextDontClip, description) # Package Detail Homepage position += rect.height() + 4 p.setFont(self.boldDetailFont) p.drawText(left + ICON_SIZE , position, width - textInner, itemHeight / 2, Qt.AlignLeft, self._titles['website']) p.setFont(self.normalDetailFont) homepage = self.normalDetailFontFM.elidedText(homepage, Qt.ElideRight, width - self._titleFM['website']) rect = self.normalDetailFontFM.boundingRect(option.rect, Qt.TextSingleLine, homepage) self.rowAnimator.hoverLinkFilter.link_rect = QRect(left + self._titleFM['website'] + 2, position + 2 + 32, rect.width(), rect.height()) p.setPen(option.palette.color(QPalette.Link)) p.drawText(left + self._titleFM['website'], position, width, rect.height(), Qt.TextSingleLine, homepage) p.setPen(foregroundColor) # Package Detail Version position += rect.height() p.setFont(self.boldDetailFont) p.drawText(left + ICON_SIZE , position, width - textInner, itemHeight / 2, Qt.AlignLeft, self._titles['release']) p.setFont(self.normalDetailFont) rect = self.normalDetailFontFM.boundingRect(option.rect, Qt.TextWordWrap, version) p.drawText(left + self._titleFM['release'], position, width, rect.height(), Qt.TextWordWrap, version) if not installedVersion == '' or not installedVersion == None: position += rect.height() p.setFont(self.boldDetailFont) p.drawText(left + ICON_SIZE , position, width - textInner, itemHeight / 2, Qt.AlignLeft, self._titles['installVers']) p.setFont(self.normalDetailFont) rect = self.normalDetailFontFM.boundingRect(option.rect, Qt.TextWordWrap, installedVersion) p.drawText(left + self._titleFM['installVers'], position, width, rect.height(), Qt.TextWordWrap, installedVersion) # Package Detail Repository repository = QVariant.value(index.model().data(index, RepositoryRole)) if not repository == '': repository = _translate("Packaga Manager",'Unknown') if repository == 'N/A' else repository position += rect.height() p.setFont(self.boldDetailFont) p.drawText(left + ICON_SIZE , position, width - textInner, itemHeight / 2, Qt.AlignLeft, self._titles['repository']) p.setFont(self.normalDetailFont) p.drawText(left + self._titleFM['repository'], position, width, itemHeight / 2, Qt.TextWordWrap, repository) # Package Detail Size position += rect.height() p.setFont(self.boldDetailFont) p.drawText(left + ICON_SIZE , position, width - textInner, itemHeight / 2, Qt.AlignLeft, self._titles['size']) p.setFont(self.normalDetailFont) p.drawText(left + self._titleFM['size'], position, width, itemHeight / 2, Qt.TextWordWrap, size) position += rect.height() self.rowAnimator.max_height = position - top + 8 # Package More info button opt = QStyleOptionViewItem(option) buttonStyle = QStyleOptionButton() if option.state & QStyle.State_MouseOver or option.state & QStyle.State_HasFocus: buttonStyle.state |= QStyle.State_HasFocus buttonStyle.state |= QStyle.State_Enabled buttonStyle.text = _translate("Packaga Manager","Details") buttonStyle.rect = QRect(width - 100, position - 22, 100, 22) p.end() # FIXME # if option.state & QStyle.State_HasFocus and self.animatable: # option.state |= QStyle.State_MouseOver # Use Plastique style to draw focus rect like MouseOver effect of Oxygen. # self.plastik.drawPrimitive(QStyle.PE_FrameLineEdit, option, painter, None) if not self.rowAnimator.running() and buttonStyle: if self.show_details_button and (installed or config.USE_APPINFO): PackageDelegate.AppStyle().drawControl(QStyle.CE_PushButton, buttonStyle, painter, None) self.rowAnimator.hoverLinkFilter.button_rect = QRect(buttonStyle.rect) painter.drawPixmap(option.rect.topLeft(), pixmap) del pixmap def editorEvent(self, event, model, option, index): #paket seçim olayında hata var seçim olayı gerçekleşiyor ama packageList sonraki seçimde görüyor #geçici çözümle giderildi tamamen çözülmeli if event.type() == QEvent.MouseButtonRelease and index.column() == 0 and index.flags() & Qt.ItemIsUserCheckable: toggled = Qt.Checked if model.data(index, Qt.CheckStateRole) == QVariant(Qt.Unchecked) else Qt.Unchecked self.packageSelected.emit(bool(toggled)) return model.setData(index, toggled, Qt.CheckStateRole) __event = QItemDelegate(self).editorEvent(event, model, option, index) animate_requested = False if event.type() == QEvent.MouseButtonRelease and self.animatable: if self.rowAnimator.row == index.row(): epos = event.pos() if self.rowAnimator.hoverLinkFilter.link_rect.contains(QPoint(epos.x(), epos.y() + 32)): url = QUrl(QVariant.value(model.data(index, HomepageRole))) QDesktopServices.openUrl(url) return __event elif self.rowAnimator.hoverLinkFilter.button_rect.contains(epos, True): self.showPackageDetails(model, index) return __event animate_requested = True elif event.type() == QEvent.KeyPress and self.animatable: # KeyCode 32 : Space key if event.key() == 32 and index.column() == index.model().columnCount() - 1: animate_requested = True if not QVariant.value(model.data(index, DescriptionRole)) == '' and animate_requested: self.rowAnimator.animate(index.row()) return __event def showPackageDetails(self, model, index): def _getter(role): return model.data(index, role) name = _getter(NameRole) summary = _getter(SummaryRole) description = _getter(DescriptionRole) installed = True if str(QVariant.value(model.data(index, InstalledRole)))=="True" else False self.webDialog.showPackageDetails(name, installed, summary, description) def sizeHint(self, option, index): if self.rowAnimator.currentRow() == index.row() and not index.row() == 0: return self.rowAnimator.size() else: width = ICON_SIZE if index.column() == 0 else 0 return QSize(width, ROW_HEIGHT) def setAnimatable(self, animatable): self.animatable = animatable def reset(self): self.rowAnimator.reset()
class PackageDelegate(QStyledItemDelegate): AppStyle = QApplication.style def __init__(self, parent=None, mainWindow=None, showDetailsButton=True, animatable=True): super(PackageDelegate, self).__init__(parent) self.webDialog = WebDialog(mainWindow) self.show_details_button = showDetailsButton self.rowAnimator = RowAnimator(parent.packageList) self.defaultIcon = KIcon(('package-x-generic', 'package_applications'), 32) self.defaultInstalledIcon = QIcon( KIconLoader.loadOverlayed( ('package-x-generic', 'package_applications'), CHECK_ICON, 32)) self.animatable = animatable self._max_height = ROW_HEIGHT self._rt_0 = QIcon(":/data/star_0.png") self._rt_1 = QIcon(":/data/star_1.png") self.types = { 'critical': (RED, self.tr('critical')), 'security': (DARKRED, self.tr('security')) } self.font = Pds.settings('font', 'Sans,10').split(',')[0] self.normalFont = QFont(self.font, 10, QFont.Normal) self.boldFont = QFont(self.font, 11, QFont.Bold) self.normalDetailFont = QFont(self.font, 9, QFont.Normal) self.boldDetailFont = QFont(self.font, 9, QFont.Bold) self.tagFont = QFont(self.font, 7, QFont.Normal) self.tagFontFM = QFontMetrics(self.tagFont) self.boldFontFM = QFontMetrics(self.boldFont) self.boldDetailFontFM = QFontMetrics(self.boldDetailFont) self.normalFontFM = QFontMetrics(self.normalFont) self.normalDetailFontFM = QFontMetrics(self.normalDetailFont) self._titles = { 'description': self.tr("Description:"), 'website': self.tr("Website:"), 'release': self.tr("Release:"), 'repository': self.tr("Repository:"), 'size': self.tr("Package Size:"), 'installVers': self.tr("Installed Version:") } self._titleFM = {} for key, value in self._titles.items(): self._titleFM[key] = self.boldDetailFontFM.width( value) + ICON_SIZE + 3 self.baseWidth = self.boldFontFM.width( max(self._titles.values(), key=len)) + ICON_SIZE self.parent = parent.packageList # Base style for some of important features # self.plastik = QStyleFactory.create('plastique') def paint(self, painter, option, index): if not index.isValid(): return super(PackageDelegate, self).paint(painter, option, index) if index.flags() & Qt.ItemIsUserCheckable: if index.column() == 0: self.paintCheckBoxColumn(painter, option, index) else: self.paintInfoColumn(painter, option, index) else: self.paintInfoColumn(painter, option, index, width_limit=10) def paintCheckBoxColumn(self, painter, option, index): opt = QStyleOptionViewItem(option) buttonStyle = QStyleOptionButton() buttonStyle.state = QStyle.State_On if index.model().data( index, Qt.CheckStateRole) == QVariant( Qt.Checked) else QStyle.State_Off if option.state & QStyle.State_MouseOver or option.state & QStyle.State_HasFocus: buttonStyle.state |= QStyle.State_HasFocus buttonStyle.rect = opt.rect.adjusted(4, -opt.rect.height() + ROW_HEIGHT, 0, 0) PackageDelegate.AppStyle().drawControl(QStyle.CE_CheckBox, buttonStyle, painter, None) def paintInfoColumn(self, painter, option, index, width_limit=0): left = option.rect.left() + 3 top = option.rect.top() width = option.rect.width() - width_limit pixmap = QPixmap(option.rect.size()) pixmap.fill(Qt.transparent) p = QPainter(pixmap) p.setRenderHint(QPainter.Antialiasing, True) p.translate(-option.rect.topLeft()) textInner = 2 * ICON_PADDING + ROW_HEIGHT - 10 itemHeight = ROW_HEIGHT + 2 * ICON_PADDING margin = left + ICON_PADDING - 10 title = index.model().data(index, NameRole).toString() summary = index.model().data(index, SummaryRole).toString() ptype = str(index.model().data(index, TypeRole).toString()) rate = int(index.model().data(index, RateRole).toInt()[0]) installed = index.model().data(index, InstalledRole).toBool() # We need to request update if its not possible to get meta data about the package try: # Get Package Icon if exists _icon = index.model().data(index, Qt.DecorationRole).toString() except: p.end() painter.drawPixmap(option.rect.topLeft(), pixmap) self.parent.requestUpdate() return icon = None if _icon: overlay = [CHECK_ICON] if installed else [] KIconLoader._forceCache = True pix = KIconLoader.loadOverlayed(_icon, overlay, 32) if not pix.isNull(): icon = QIcon( pix.scaled(QSize(32, 32), Qt.KeepAspectRatio, Qt.SmoothTransformation)) KIconLoader._forceCache = False if not icon: icon = self.defaultIcon if not installed else self.defaultInstalledIcon # Paint the Icon icon.paint(p, margin, top + ICON_PADDING, ROW_HEIGHT, ROW_HEIGHT, Qt.AlignCenter) fix_pos = 0 if index.model().columnCount() <= 1: fix_pos = 22 if config.USE_APPINFO: # Rating Stars for _rt_i in range(5): self._rt_0.paint(p, width + 10 * _rt_i - 30 - fix_pos, top + ROW_HEIGHT / 4, 10, 10, Qt.AlignCenter) for _rt_i in range(rate): self._rt_1.paint(p, width + 10 * _rt_i - 30 - fix_pos, top + ROW_HEIGHT / 4, 10, 10, Qt.AlignCenter) foregroundColor = option.palette.color(QPalette.Text) p.setPen(foregroundColor) # Package Name p.setFont(self.boldFont) p.drawText(left + textInner, top, width - textInner, itemHeight / 2, Qt.AlignBottom | Qt.AlignLeft, title) tagWidth = 0 _component_width = 0 if self.parent.showComponents: component = str(index.model().data(index, ComponentRole).toString()) widthOfTitle = self.boldFontFM.width(title) + 6 + left + textInner p.setFont(self.tagFont) rect = self.tagFontFM.boundingRect(option.rect, Qt.TextWordWrap, component) p.setPen(LIGHTGREEN) p.setBrush(LIGHTGREEN) p.drawRoundRect(widthOfTitle, top + 12, rect.width() + 4, rect.height(), 10, 10) p.setPen(DARKGREEN) p.drawText(widthOfTitle + 2, top + 12, rect.width(), rect.height(), Qt.AlignCenter, component) p.setPen(foregroundColor) _component_width = rect.width() + 8 if self.parent.showIsA: isa = str(index.model().data(index, IsaRole).toString()) if not isa == '': widthOfTitle = self.boldFontFM.width( title) + 6 + left + textInner + _component_width p.setFont(self.tagFont) rect = self.tagFontFM.boundingRect(option.rect, Qt.TextWordWrap, isa) p.setPen(LIGHTBLUE) p.setBrush(LIGHTBLUE) p.drawRoundRect(widthOfTitle, top + 12, rect.width() + 4, rect.height(), 10, 10) p.setPen(DARKVIOLET) p.drawText(widthOfTitle + 2, top + 12, rect.width(), rect.height(), Qt.AlignCenter, isa) p.setPen(foregroundColor) _component_width += rect.width() + 8 if ptype not in ('None', 'normal'): widthOfTitle = self.boldFontFM.width( title) + 6 + left + textInner + _component_width p.setFont(self.tagFont) rect = self.tagFontFM.boundingRect(option.rect, Qt.TextWordWrap, self.types[ptype][1]) p.setPen(self.types[ptype][0]) p.setBrush(self.types[ptype][0]) p.drawRoundRect(widthOfTitle, top + 12, rect.width() + 4, rect.height(), 10, 10) p.setPen(WHITE) p.drawText(widthOfTitle + 2, top + 12, rect.width(), rect.height(), Qt.AlignCenter, self.types[ptype][1]) p.setPen(foregroundColor) tagWidth = rect.width() # Package Summary p.setFont(self.normalFont) foregroundColor.setAlpha(160) p.setPen(foregroundColor) elided_summary = self.normalFontFM.elidedText( summary, Qt.ElideRight, width - textInner - tagWidth - 22) p.drawText(left + textInner, top + itemHeight / 2, width - textInner, itemHeight / 2, Qt.TextDontClip, elided_summary) foregroundColor.setAlpha(255) p.setPen(foregroundColor) buttonStyle = None if self.rowAnimator.currentRow() == index.row(): description = index.model().data(index, DescriptionRole).toString() size = index.model().data(index, SizeRole).toString() homepage = index.model().data(index, HomepageRole).toString() installedVersion = str(index.model().data( index, InstalledVersionRole).toString()) version = index.model().data(index, VersionRole) # Package Detail Label position = top + ROW_HEIGHT p.setFont(self.normalDetailFont) baseRect = QRect(left, position, width - 8, option.rect.height()) rect = self.normalDetailFontFM.boundingRect( baseRect, Qt.TextWordWrap | Qt.TextDontClip, description) p.drawText(left + 2, position, width - 8, rect.height(), Qt.TextWordWrap | Qt.TextDontClip, description) # Package Detail Homepage position += rect.height() + 4 p.setFont(self.boldDetailFont) p.drawText(left + ICON_SIZE, position, width - textInner, itemHeight / 2, Qt.AlignLeft, self._titles['website']) p.setFont(self.normalDetailFont) homepage = self.normalDetailFontFM.elidedText( homepage, Qt.ElideRight, width - self._titleFM['website']) rect = self.normalDetailFontFM.boundingRect( option.rect, Qt.TextSingleLine, homepage) self.rowAnimator.hoverLinkFilter.link_rect = QRect( left + self._titleFM['website'] + 2, position + 2 + 32, rect.width(), rect.height()) p.setPen(option.palette.color(QPalette.Link)) p.drawText(left + self._titleFM['website'], position, width, rect.height(), Qt.TextSingleLine, homepage) p.setPen(foregroundColor) # Package Detail Version position += rect.height() p.setFont(self.boldDetailFont) p.drawText(left + ICON_SIZE, position, width - textInner, itemHeight / 2, Qt.AlignLeft, self._titles['release']) p.setFont(self.normalDetailFont) rect = self.normalDetailFontFM.boundingRect( option.rect, Qt.TextWordWrap, version.toString()) p.drawText(left + self._titleFM['release'], position, width, rect.height(), Qt.TextWordWrap, version.toString()) if not installedVersion == '': position += rect.height() p.setFont(self.boldDetailFont) p.drawText(left + ICON_SIZE, position, width - textInner, itemHeight / 2, Qt.AlignLeft, self._titles['installVers']) p.setFont(self.normalDetailFont) rect = self.normalDetailFontFM.boundingRect( option.rect, Qt.TextWordWrap, installedVersion) p.drawText(left + self._titleFM['installVers'], position, width, rect.height(), Qt.TextWordWrap, installedVersion) # Package Detail Repository repository = index.model().data(index, RepositoryRole).toString() if not repository == '': repository = self.tr( 'Unknown') if repository == 'N/A' else repository position += rect.height() p.setFont(self.boldDetailFont) p.drawText(left + ICON_SIZE, position, width - textInner, itemHeight / 2, Qt.AlignLeft, self._titles['repository']) p.setFont(self.normalDetailFont) p.drawText(left + self._titleFM['repository'], position, width, itemHeight / 2, Qt.TextWordWrap, repository) # Package Detail Size position += rect.height() p.setFont(self.boldDetailFont) p.drawText(left + ICON_SIZE, position, width - textInner, itemHeight / 2, Qt.AlignLeft, self._titles['size']) p.setFont(self.normalDetailFont) p.drawText(left + self._titleFM['size'], position, width, itemHeight / 2, Qt.TextWordWrap, size) position += rect.height() self.rowAnimator.max_height = position - top + 8 # Package More info button opt = QStyleOptionViewItem(option) buttonStyle = QStyleOptionButton() if option.state & QStyle.State_MouseOver or option.state & QStyle.State_HasFocus: buttonStyle.state |= QStyle.State_HasFocus buttonStyle.state |= QStyle.State_Enabled buttonStyle.text = self.tr("Details") buttonStyle.rect = QRect(width - 100, position - 22, 100, 22) p.end() # FIXME # if option.state & QStyle.State_HasFocus and self.animatable: # option.state |= QStyle.State_MouseOver # Use Plastique style to draw focus rect like MouseOver effect of Oxygen. # self.plastik.drawPrimitive(QStyle.PE_FrameLineEdit, option, painter, None) if not self.rowAnimator.running() and buttonStyle: if self.show_details_button and (installed or config.USE_APPINFO): PackageDelegate.AppStyle().drawControl(QStyle.CE_PushButton, buttonStyle, painter, None) self.rowAnimator.hoverLinkFilter.button_rect = QRect( buttonStyle.rect) painter.drawPixmap(option.rect.topLeft(), pixmap) del pixmap def editorEvent(self, event, model, option, index): if event.type() == QEvent.MouseButtonRelease and index.column( ) == 0 and index.flags() & Qt.ItemIsUserCheckable: toggled = Qt.Checked if model.data( index, Qt.CheckStateRole) == QVariant( Qt.Unchecked) else Qt.Unchecked return model.setData(index, toggled, Qt.CheckStateRole) __event = QItemDelegate(self).editorEvent(event, model, option, index) animate_requested = False if event.type() == QEvent.MouseButtonRelease and self.animatable: if self.rowAnimator.row == index.row(): epos = event.pos() if self.rowAnimator.hoverLinkFilter.link_rect.contains( QPoint(epos.x(), epos.y() + 32)): url = QUrl(model.data(index, HomepageRole).toString()) QDesktopServices.openUrl(url) return __event elif self.rowAnimator.hoverLinkFilter.button_rect.contains( epos, True): self.showPackageDetails(model, index) return __event animate_requested = True elif event.type() == QEvent.KeyPress and self.animatable: # KeyCode 32 : Space key if event.key() == 32 and index.column( ) == index.model().columnCount() - 1: animate_requested = True if not unicode(model.data( index, DescriptionRole).toString()) == '' and animate_requested: self.rowAnimator.animate(index.row()) return __event def showPackageDetails(self, model, index): def _getter(role): return model.data(index, role).toString() name = _getter(NameRole) summary = _getter(SummaryRole) description = _getter(DescriptionRole) installed = model.data(index, InstalledRole).toBool() self.webDialog.showPackageDetails(name, installed, summary, description) def sizeHint(self, option, index): if self.rowAnimator.currentRow() == index.row( ) and not index.row() == 0: return self.rowAnimator.size() else: width = ICON_SIZE if index.column() == 0 else 0 return QSize(width, ROW_HEIGHT) def setAnimatable(self, animatable): self.animatable = animatable def reset(self): self.rowAnimator.reset()
class MainWidget(QWidget, PM, Ui_MainWidget): def __init__(self, parent = None): QWidget.__init__(self, parent) self.setupUi(self) self.parent = parent self._selectedGroups = [] self._preexceptions = [] self._postexceptions = [] self.state = StateManager(self) self.currentState = None self.completer = None self._updatesCheckedOnce = False #set style self._style = "/usr/share/kde4/apps/package-manager/data/style.qss" self.setStyleSheet(file(self._style).read()) # Search Thread self._searchThread = PThread(self, self.startSearch, self.searchFinished) self.statusUpdater = StatusUpdater() self.basket = BasketDialog(self.state, self.parent) self._postexceptions.append(lambda: self.basket.setActionEnabled(True)) self.searchButton.setIcon(KIcon("edit-find")) self.initializeUpdateTypeList() self.morewidgets = MoreWidgets(self.state, self.parent) self._postexceptions.append(lambda: self.morewidgets.setActionEnabled(True)) self.morewidgets._show() self.webdialog = WebDialog(self.state, self.parent) model = PackageModel(self) proxy = PackageProxy(self) proxy.setSourceModel(model) self.packageList.setModel(proxy) self.packageList.setItemDelegate(PackageDelegate(self, self.parent)) self.packageList.setColumnWidth(0, 32) self.connect(self.packageList.model(), SIGNAL("dataChanged(QModelIndex,QModelIndex)"), self.statusChanged) self.connect(self.packageList, SIGNAL("updateRequested()"), self.initialize) self.connect(self.morewidgets.randomPackageList, SIGNAL("itemDoubleClicked(QListWidgetItem*)"), self.showWebdialog) self.updateSettings() self.setActionButton() self.operation = OperationManager(self.state) self.progressDialog = ProgressDialog(self.state, self.parent) self._preexceptions.append(self.progressDialog._hide) self.progressDialog.registerFunction(FINISHED, lambda: self.parent.statusBar().setVisible(not self.progressDialog.isVisible())) self.progressDialog.registerFunction(OUT, lambda: self.parent.statusBar().show()) self.summaryDialog = SummaryDialog() self.connectOperationSignals() self.pdsMessageBox = PMessageBox(self.content) def connectMainSignals(self): self.connect(self.actionButton, SIGNAL("clicked()"), self.showBasket) self.connect(self.buttonMore, SIGNAL("clicked()"), self.showMoreWidgets) self.connect(self.checkUpdatesButton, SIGNAL("clicked()"), self.state.updateRepoAction) self.connect(self.searchButton, SIGNAL("clicked()"), self.searchActivated) self.connect(self.searchLine, SIGNAL("textEdited(const QString&)"), self.searchLineChanged) self.connect(self.searchLine, SIGNAL("returnPressed()"), self.searchActivated) self.connect(self.searchLine, SIGNAL("clearButtonClicked()"), self.groupFilter) self.connect(self.typeCombo, SIGNAL("activated(int)"), self.typeFilter) self.connect(self.stateTab, SIGNAL("currentChanged(int)"), self.switchState) self.connect(self.groupList, SIGNAL("groupChanged()"), self.groupFilter) self.connect(self.groupList, SIGNAL("groupChanged()"), lambda:self.searchButton.setEnabled(False)) self.connect(self.packageList.select_all, SIGNAL("clicked(bool)"), self.toggleSelectAll) self.connect(self.statusUpdater, SIGNAL("selectedInfoChanged(int, QString, int, QString)"), self.emitStatusBarInfo) self.connect(self.statusUpdater, SIGNAL("selectedInfoChanged(QString)"), lambda message: self.emit(SIGNAL("selectionStatusChanged(QString)"), message)) self.connect(self.statusUpdater, SIGNAL("finished()"), self.statusUpdated) def initialize(self): waitCursor() self.searchLine.clear() self._started = False self._last_packages = None self.state.reset() self.initializePackageList() self.initializeGroupList() self.initializeStatusUpdater() self.statusChanged() self._selectedGroups = [] self.packageList.select_all.setChecked(False) self.initializeBasket() self.searchLine.setFocus(True) if self.currentState == self.state.UPGRADE: if self.groupList.count() == 0: QTimer.singleShot(0, \ lambda: self.pdsMessageBox.showMessage(i18n("All packages are up to date"), icon = "games-endturn")) if self.groupList.count() > 0: if self.state.inUpgrade(): self.pdsMessageBox.hideMessage(force = True) restoreCursor() def initializeStatusUpdater(self): self.statusUpdater.calculate_deps = not self.state.state == self.state.ALL self.statusUpdater.setModel(self.packageList.model().sourceModel()) def initializeBasket(self): waitCursor() self.basket.setModel(self.packageList.model().sourceModel()) restoreCursor() def initializePackageList(self): self.packageList.model().reset() self.packageList.setPackages(self.state.packages()) if self.completer: self.completer.deleteLater() del self.completer self.completer = QCompleter(self.state.packages(), self) self.completer.setCaseSensitivity(Qt.CaseInsensitive) self.searchLine.setCompleter(self.completer) def selectComponent(self, component): if not self.state.iface.operationInProgress(): if self.basket.isVisible(): self.basket._hide() self.stateTab.setCurrentIndex(1) self.switchState(self.state.INSTALL) if component in self.groupList._list: self.groupList.setCurrentItem(self.groupList._list[component]) self.groupFilter() def updateSettings(self): self.packageList.showComponents = PMConfig().showComponents() self.packageList.showIsA = PMConfig().showIsA() self.packageList.setFocus() def searchLineChanged(self, text): self.searchButton.setEnabled(bool(text)) if text == '': self.searchActivated() def statusUpdated(self): if self.statusUpdater.needsUpdate: self.statusUpdater.needsUpdate = False self.statusChanged() def statusChanged(self): self.setActionEnabled() if self.statusUpdater.isRunning(): self.statusUpdater.needsUpdate = True else: self.emit(SIGNAL("updatingStatus()")) self.statusUpdater.start() def initializeGroupList(self): self.groupList.clear() self.groupList._list = {} self.groupList.setAlternatingRowColors(False) self.groupList.setIconSize(QSize(32, 32)) self.groupList.setState(self.state) self.groupList.addGroups(self.state.groups()) if self.state.state == self.state.UPGRADE: self.typeCombo.show() else: self.typeCombo.hide() self.state._typeFilter = 'normal' self.groupFilter() def packageFilter(self, text): self.packageList.model().setFilterRole(Qt.DisplayRole) self.packageList.model().setFilterRegExp(QRegExp(unicode(text), Qt.CaseInsensitive, QRegExp.FixedString)) def typeFilter(self, index): if self.state.state == self.state.UPGRADE: filter = self.typeCombo.itemData(index).toString() if not self.state._typeFilter == filter: self.state._typeFilter = filter self.initializeGroupList() def groupFilter(self): waitCursor() self.packageList.resetMoreInfoRow() packages = self.state.groupPackages(self.groupList.currentGroup()) self.packageList.model().setFilterRole(GroupRole) self.packageList.model().setFilterPackages(packages) self.packageList.scrollToTop() self.packageList.select_all.setChecked(self.groupList.currentGroup() in self._selectedGroups) restoreCursor() def searchActivated(self): if self.currentState == self.state.UPGRADE: if self.groupList.count() == 0 and not self.searchUsed: return if not self.searchLine.text() == '': self.pdsMessageBox.showMessage(i18n("Searching..."), busy = True) self.groupList.lastSelected = None self._searchThread.start() self.searchUsed = True else: self.state.cached_packages = None self.state.packages() self.searchUsed = False self.searchFinished() def searchFinished(self): if self.state.cached_packages == []: self.pdsMessageBox.showMessage(i18n("No results found."), "dialog-information") else: self.pdsMessageBox.hideMessage() self.initializeGroupList() def startSearch(self): searchText = str(self.searchLine.text()).split() sourceModel = self.packageList.model().sourceModel() self.state.cached_packages = sourceModel.search(searchText) def setActionButton(self): self.actionButton.setEnabled(False) if self.state.state == self.state.ALL: menu = QMenu(self.actionButton) self.__install_action = menu.addAction(self.state.getActionIcon(self.state.INSTALL), self.state.getActionName(self.state.INSTALL), self.showBasket) self.__remove_action = menu.addAction(self.state.getActionIcon(self.state.REMOVE), self.state.getActionName(self.state.REMOVE), self.showBasket) self.actionButton.setMenu(menu) else: self.actionButton.setMenu(None) self.actionButton.setIcon(self.state.getActionIcon()) self.actionButton.setText(self.state.getActionName()) def actionStarted(self, operation): self.pdsMessageBox.hideMessage() self.progressDialog.reset() if not operation in ["System.Manager.updateRepository", "System.Manager.updateAllRepositories"]: totalPackages = self.packageList.packageCount() extraPackages = self.packageList.extraPackagesCount() self.operation.setTotalPackages(totalPackages) self.operation.setExtraPackages(extraPackages) self.progressDialog.updateStatus(0, totalPackages, self.state.toBe()) if self.isVisible(): if operation in ["System.Manager.updateRepository", "System.Manager.updateAllRepositories"]: self.progressDialog.repoOperationView() if self.basket.isVisible(): self.basket._hide() QTimer.singleShot(0, self.progressDialog._show) else: self.progressDialog._show() if not self._started: self.progressDialog.disableCancel() else: self.progressDialog.enableCancel() def actionFinished(self, operation): if operation in ("System.Manager.installPackage", "System.Manager.removePackage", "System.Manager.updatePackage"): self.notifyFinished() if operation == "System.Manager.installPackage" and self._started: self.summaryDialog.setDesktopFiles(self.operation.desktopFiles) self.summaryDialog.showSummary() if operation in ("System.Manager.updateRepository", "System.Manager.updateAllRepositories"): self.emit(SIGNAL("repositoriesUpdated()")) self.searchLine.clear() self.state.reset() self.progressDialog._hide() if not self.currentState == self.state.UPGRADE: self.switchState(self.currentState) self.initialize() def actionCancelled(self): self.progressDialog._hide() self.progressDialog.reset() self.switchState(self.currentState) self.groupFilter() def setActionEnabled(self): enabled = self.packageList.isSelected() self.actionButton.setEnabled(enabled) self.basket.setActionEnabled(enabled) def switchState(self, state): self.pdsMessageBox.hideMessage(force = True) self._states[state][1].setChecked(True) self.state.setState(state) self.currentState = state self._selectedGroups = [] if not state == self.state.HISTORY: self.setActionButton() self.state.cached_packages = None if state == self.state.UPGRADE or (state == self.state.INSTALL and self.groupList.count() == 1): if not self._updatesCheckedOnce: self._updatesCheckedOnce = self.state.updateRepoAction(silence = True) self.checkUpdatesButton.setHidden(not state == self.state.UPGRADE) self.initialize() # self.contentHistory.hide() self.content.show() # else: # self.contentHistory.show() # self.content.hide() def emitStatusBarInfo(self, packages, packagesSize, extraPackages, extraPackagesSize): self.emit(SIGNAL("selectionStatusChanged(QString)"), self.state.statusText(packages, packagesSize, extraPackages, extraPackagesSize)) def setSelectAll(self, packages=None): if packages: self.packageList.reverseSelection(packages) def setReverseAll(self, packages=None): if packages: self.packageList.selectAll(packages) def toggleSelectAll(self, toggled): self._last_packages = self.packageList.model().getFilteredPackages() if toggled: if self.groupList.currentGroup() not in self._selectedGroups: self._selectedGroups.append(self.groupList.currentGroup()) self.setReverseAll(self._last_packages) else: if self.groupList.currentGroup() in self._selectedGroups: self._selectedGroups.remove(self.groupList.currentGroup()) self.setSelectAll(self._last_packages) # A hacky solution to repaint the list to take care of selection changes # FIXME Later self.packageList.setFocus() self.statusChanged() def showBasket(self): if self.basket.isVisible(): return waitCursor() self.statusUpdater.wait() if self.currentState == self.state.ALL: action = {self.__remove_action:self.state.REMOVE, self.__install_action:self.state.INSTALL}.get(self.sender(), self.state.INSTALL) if action: if action == self.state.REMOVE: installed_packages = self.state.iface.getInstalledPackages() filtered_packages = filter(lambda x: x not in installed_packages, self.basket.model.selectedPackages()) if filtered_packages == self.basket.model.selectedPackages(): restoreCursor() QMessageBox(i18n("Select packages"), i18n("You must select at least one installed package"), QMessageBox.Information, QMessageBox.Ok, 0, 0).exec_() return self.packageList.model().sourceModel().selectPackages(filtered_packages, state = False) self.state.state = action self.basket._show() restoreCursor() def showMoreWidgets(self): if self.morewidgets.isVisible(): return waitCursor() self.morewidgets._show() restoreCursor() def showWebdialog(self): packageName = unicode(self.morewidgets.randomPackageList.currentItem().text()) print packageName waitCursor() self.morewidgets._hide() self.webdialog._show() restoreCursor() def initializeUpdateTypeList(self): self.typeCombo.clear() UPDATE_TYPES = [['normal', i18n('All Updates'), 'system-software-update'], ['security', i18n('Security Updates'), 'security-medium'], ['critical', i18n('Critical Updates'), 'security-low']] for type in UPDATE_TYPES: self.typeCombo.addItem(KIcon(type[2]), type[1], QVariant(type[0]))