def __init__ (self):

		QAbstractItemModel.__init__ (self)
		self.list = list()

		self.folderIcon = KIconLoader.global_().loadIcon("folder", KIconLoader.NoGroup, KIconLoader.SizeSmall)
		self.textplainIcon = KIconLoader.global_().loadIcon("text-plain", KIconLoader.NoGroup, KIconLoader.SizeSmall)
Esempio n. 2
0
 def go(self, log, stat, steps):
     self.progress += steps
     if stat == ctx.OK:
         if log:
             logging.info(log)
         self.OKs += 1
     elif stat == ctx.WARNING:
         if log:
             logging.warning(log)
         self.warnings += 1
     elif stat == ctx.ERROR:
         if log:
             logging.error(log)
         self.errors += 1
     if self.progress >= self.steps:
         if self.errors > 0:
             pix = KIconLoader().loadIcon("dialog-cancel", KIconLoader.Toolbar)
         elif self.warnings > 0:
             pix = KIconLoader().loadIcon("emblem-important", KIconLoader.Toolbar)
         else:
             pix = KIconLoader().loadIcon("dialog-ok-apply", KIconLoader.Toolbar)
         self.icon.setPixmap(pix)
         return True
     else:
         return False
    def __init__(self, url, parent=None):
        QDialog.__init__(self, parent)
        self.setModal(True)
        uic.loadUi(os.path.join( os.path.dirname(__file__), "settings.ui" ), self)

        iconLoader = KIconLoader()
        self.btnAdd.setIcon( QIcon(iconLoader.loadIcon("list-add", KIconLoader.Small)) )
        self.btnDel.setIcon( QIcon(iconLoader.loadIcon("list-remove", KIconLoader.Small)) )

        self.url = url
Esempio n. 4
0
    def __init__(self, controller, *args, **kwargs):
        PageBase.__init__(self, *args, **kwargs)
        self.controller = controller

        from PyQt4 import uic
        from PyQt4.QtGui import QDialog
        from PyKDE4.kdeui import KIconLoader

        self.plugin_widgets = uic.loadUi(
            '/usr/share/ubiquity/qt/stepUserSetup.ui')
        self.page = self.plugin_widgets

        self.username_edited = False
        self.hostname_edited = False

        if self.controller.oem_config:
            self.page.fullname.setText('OEM Configuration (temporary user)')
            self.page.fullname.setReadOnly(True)
            self.page.fullname.setEnabled(False)
            self.page.username.setText('oem')
            self.page.username.setReadOnly(True)
            self.page.username.setEnabled(False)
            self.page.login_pass.hide()
            self.page.login_auto.hide()
            self.page.login_encrypt.hide()
            self.username_edited = True
            #self.hostname_edited = True

            #if self.laptop:
            #    self.page.hostname.setText('oem-laptop')
            #else:
            #    self.page.hostname.setText('oem-desktop')

            # The UserSetup component takes care of preseeding passwd/user-uid.
            execute_root('apt-install', 'oem-config-kde')

        iconLoader = KIconLoader()
        warningIcon = iconLoader.loadIcon("dialog-warning",
                                          KIconLoader.Desktop)
        self.page.fullname_error_image.setPixmap(warningIcon)
        self.page.username_error_image.setPixmap(warningIcon)
        self.page.password_error_image.setPixmap(warningIcon)
        self.page.hostname_error_image.setPixmap(warningIcon)

        self.clear_errors()

        self.page.fullname.textChanged[str].connect(self.on_fullname_changed)
        self.page.username.textChanged[str].connect(self.on_username_changed)
        self.page.hostname.textChanged[str].connect(self.on_hostname_changed)
        #self.page.password.textChanged[str].connect(self.on_password_changed)
        #self.page.verified_password.textChanged[str].connect(self.on_verified_password_changed)

        self.page.password_debug_warning_label.setVisible(
            'UBIQUITY_DEBUG' in os.environ)
    def __init__(self, controller, *args, **kwargs):
        PageBase.__init__(self, *args, **kwargs)
        self.controller = controller

        from PyQt4 import uic
        from PyQt4.QtGui import QDialog
        from PyKDE4.kdeui import KIconLoader

        self.plugin_widgets = uic.loadUi('/usr/share/ubiquity/qt/stepUserSetup.ui')
        self.page = self.plugin_widgets

        self.username_edited = False
        self.hostname_edited = False

        if self.controller.oem_config:
            self.page.fullname.setText('OEM Configuration (temporary user)')
            self.page.fullname.setReadOnly(True)
            self.page.fullname.setEnabled(False)
            self.page.username.setText('oem')
            self.page.username.setReadOnly(True)
            self.page.username.setEnabled(False)
            self.page.login_pass.hide()
            self.page.login_auto.hide()
            self.page.login_encrypt.hide()
            self.username_edited = True
            self.hostname_edited = True

            if self.laptop:
                self.page.hostname.setText('oem-laptop')
            else:
                self.page.hostname.setText('oem-desktop')

            # The UserSetup component takes care of preseeding passwd/user-uid.
            execute_root('apt-install', 'oem-config-kde')

        iconLoader = KIconLoader()
        warningIcon = iconLoader.loadIcon("dialog-warning", KIconLoader.Desktop)
        self.page.fullname_error_image.setPixmap(warningIcon)
        self.page.username_error_image.setPixmap(warningIcon)
        self.page.password_error_image.setPixmap(warningIcon)
        self.page.hostname_error_image.setPixmap(warningIcon)

        self.clear_errors()

        self.page.fullname.textChanged[str].connect(self.on_fullname_changed)
        self.page.username.textChanged[str].connect(self.on_username_changed)
        self.page.hostname.textChanged[str].connect(self.on_hostname_changed)
        #self.page.password.textChanged[str].connect(self.on_password_changed)
        #self.page.verified_password.textChanged[str].connect(self.on_verified_password_changed)

        self.page.password_debug_warning_label.setVisible('UBIQUITY_DEBUG' in os.environ)
Esempio n. 6
0
    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, connections={}):
        self.urls = []
        self.projectPaths = []

        QDialog.__init__(self, parent)
        uic.loadUi(os.path.join(os.path.dirname(__file__), "fuzzyopen.ui"), self)
        self.setModal(True)
        self.listUrl.setItemDelegate(HtmlItemDelegate(self.listUrl))
        self.hideProgress()

        self.iconLoader = KIconLoader()
        self.btnSettings.setIcon(QIcon(self.iconLoader.loadIcon("configure", KIconLoader.Small)))
        self.btnRefresh.setIcon(QIcon(self.iconLoader.loadIcon("view-refresh", KIconLoader.Small)))

        self.config = KConfig("katefuzzyopenrc")
        configPaths = self.config.group("ProjectPaths")
        for key in configPaths.keyList():
            path = configPaths.readPathEntry(key, "")
            if not path.endswith("/"):
                path += "/"
            self.projectPaths.append(path)

        configFilters = self.config.group("Filters")
        self.lister = DirLister()
        self.lister.fileFound.connect(self.listerFileFound)
        self.lister.directoryChanged.connect(self.listerDirChanged)
        self.lister.completed.connect(self.listerCompleted)
        self.lister.setIncludeFilters(configFilters.readEntry("include", ""))
        self.lister.setExcludeFilters(configFilters.readEntry("exclude", "~$\n\.bak$\n/\."))
Esempio n. 8
0
    def show_touchpad(self, touchpad):
        """
        Show information about the given ``touchpad`` in this widget.

        ``touchpad`` is a :class:`~synaptiks.touchpad.Touchpad` object.
        """
        self.nameLabel.setText(i18nc(
            '@info touchpad name', '<title><resources>%1</resource></title>',
            touchpad.name))

        pixmaps = {True: 'dialog-ok', False: 'dialog-cancel'}
        for key in pixmaps:
            pixmaps[key] = KIconLoader.global_().loadIcon(
                pixmaps[key], KIconLoader.Small)

        button_widgets = ('left', 'middle', 'right')
        for widget_name, is_supported in zip(button_widgets, touchpad.buttons):
            widget = getattr(self, '{0}Button'.format(widget_name))
            widget.setPixmap(pixmaps[is_supported])

        self.fingerDetection.setValue(touchpad.finger_detection)

        # disable the emulation box, if the touchpad natively supports two
        # fingers natively.
        if touchpad.finger_detection > 2:
            self.twoFingerEmulationBox.setEnabled(False)
        # nonetheless always assign proper pixmaps
        self.fingerWidthDetection.setPixmap(
            pixmaps[touchpad.has_finger_width_detection])
        self.pressureDetection.setPixmap(
            pixmaps[touchpad.has_pressure_detection])
        self.twoFingerEmulation.setPixmap(
            pixmaps[touchpad.has_two_finger_emulation])
Esempio n. 9
0
 def _icon_data(self, obj, col):
     if col == 2 and obj.isLocked():
             #print "object locked"
             #return QVariant("blah")
         return QVariant(KIconLoader.global_()
                         .loadIcon('object-locked', KIconLoader.Small))
     else:
         return QVariant()
Esempio n. 10
0
    def initialize(self):
        self.appGenericName.setText(self.item.genericName)
        self.appName.setText(self.item.name)

        self.appIcon.setPixmap(KIconLoader().loadIcon(self.item.icon,
                                                      KIconLoader.Desktop, 32))

        self.appName.hide()
Esempio n. 11
0
File: main.py Progetto: relu/gitioid
	def updateIcon(self):
		loader = KIconLoader()
		size = min(self.icon.size().width(), self.icon.size().height()) * 2

		if self.enabled:
			ico = KIconLoader.loadIcon(loader,
					self.icons['iconon'], KIconLoader.NoGroup,
					size)
		else:
			ico = KIconLoader.loadIcon(loader,
					self.icons['iconoff'], KIconLoader.NoGroup,
					size)

		paint = QPainter(ico)
		paint.setRenderHint(QPainter.SmoothPixmapTransform)
		paint.setRenderHint(QPainter.Antialiasing)

		paint.end()

		self.icon.setIcon(QIcon(ico))
		self.icon.update()
Esempio n. 12
0
 def notify_touchpad_state(self, is_off=None):
     if is_off is None:
         is_off = self.touchpad.off
     # show a notification
     if is_off:
         event_id = 'touchpadOff'
         text = i18nc('touchpad switched notification',
                      'Touchpad switched off')
     else:
         event_id = 'touchpadOn'
         text = i18nc('touchpad switched notification',
                      'Touchpad switched on')
     icon = KIconLoader.global_().loadIcon('synaptiks', KIconLoader.Panel)
     KNotification.event(event_id, text, icon)
Esempio n. 13
0
 def __init__(self, error, component_data, parent=None):
     SynaptiksKCMBase.__init__(self, component_data, parent)
     if isinstance(error, basestring):
         error_message = error
     else:
         from synaptiks.kde.error import get_localized_error_message
         error_message = get_localized_error_message(error)
     self.setLayout(QHBoxLayout(self))
     icon = QLabel('foobar', self)
     icon.setPixmap(KIconLoader.global_().loadIcon(
         'dialog-warning', KIconLoader.Desktop, KIconLoader.SizeLarge))
     icon.setAlignment(Qt.AlignTop | Qt.AlignLeft)
     # do not expand the icon horizontally, to avoid a wide empty space
     # between icon and text, and to given as much space as possible to the
     # text contents
     icon.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Expanding)
     self.layout().addWidget(icon)
     message = QLabel(error_message, self)
     message.setAlignment(Qt.AlignTop | Qt.AlignLeft)
     message.setWordWrap(True)
     message.setOpenExternalLinks(True)
     self.layout().addWidget(message)
     self.setButtons(self.Help)
Esempio n. 14
0
    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 = QtGui.QPixmap(option.rect.size())
        pixmap.fill(Qt.transparent)

        p = QtGui.QPainter(pixmap)
        p.setRenderHint(QtGui.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 []
            pix = KIconLoader().loadIcon(_icon, KIconLoader.NoGroup, 32, KIconLoader.DefaultState, overlay, '', True)
            if not pix.isNull():
                icon = QtGui.QIcon(pix.scaled(QSize(32, 32), Qt.KeepAspectRatio, Qt.SmoothTransformation))

        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

        # 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(QtGui.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(QtGui.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 == '':
                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 = QtGui.QStyleOptionViewItemV4(option)

            buttonStyle = QtGui.QStyleOptionButton()
            if option.state & QtGui.QStyle.State_MouseOver or option.state & QtGui.QStyle.State_HasFocus:
                buttonStyle.state |= QtGui.QStyle.State_HasFocus
            buttonStyle.state |= QtGui.QStyle.State_Enabled
            buttonStyle.text = i18n("Details")

            buttonStyle.rect = QRect(width - 100, position - 22, 100, 22)

        p.end()

        if option.state & QtGui.QStyle.State_HasFocus and self.animatable:
            option.state |= QtGui.QStyle.State_MouseOver
            # Use Oxygen style to draw focus rect like MouseOver effect of Oxygen..
            self.oxygen.drawPrimitive(QtGui.QStyle.PE_PanelItemViewItem, option, painter, None)

        if not self.rowAnimator.running() and buttonStyle:
            if self.show_details_button:
                PackageDelegate.AppStyle().drawControl(QtGui.QStyle.CE_PushButton, buttonStyle, painter, None)
                self.rowAnimator.hoverLinkFilter.button_rect = QRect(buttonStyle.rect)

        painter.drawPixmap(option.rect.topLeft(), pixmap)
        del pixmap
Esempio n. 15
0
 def start(self):
     pix = KIconLoader().loadIcon("1rightarrow", KIconLoader.Toolbar)
     self.icon.setPixmap(pix)
Esempio n. 16
0
class FuzzyOpen(QDialog):
    reason = ""

    def __init__(self, parent=None, connections={}):
        self.urls = []
        self.projectPaths = []

        QDialog.__init__(self, parent)
        uic.loadUi(os.path.join(os.path.dirname(__file__), "fuzzyopen.ui"), self)
        self.setModal(True)
        self.listUrl.setItemDelegate(HtmlItemDelegate(self.listUrl))
        self.hideProgress()

        self.iconLoader = KIconLoader()
        self.btnSettings.setIcon(QIcon(self.iconLoader.loadIcon("configure", KIconLoader.Small)))
        self.btnRefresh.setIcon(QIcon(self.iconLoader.loadIcon("view-refresh", KIconLoader.Small)))

        self.config = KConfig("katefuzzyopenrc")
        configPaths = self.config.group("ProjectPaths")
        for key in configPaths.keyList():
            path = configPaths.readPathEntry(key, "")
            if not path.endswith("/"):
                path += "/"
            self.projectPaths.append(path)

        configFilters = self.config.group("Filters")
        self.lister = DirLister()
        self.lister.fileFound.connect(self.listerFileFound)
        self.lister.directoryChanged.connect(self.listerDirChanged)
        self.lister.completed.connect(self.listerCompleted)
        self.lister.setIncludeFilters(configFilters.readEntry("include", ""))
        self.lister.setExcludeFilters(configFilters.readEntry("exclude", "~$\n\.bak$\n/\."))

    def showEvent(self, event):
        katerect = kate.mainInterfaceWindow().window().rect()
        diarect = self.rect()
        diarect.moveCenter(katerect.center())
        self.move(diarect.topLeft())

        self.reset()
        self.list()

    def getProjectUrl(self, url):
        for path in self.projectPaths:
            if url.url().startswith(path):
                return path
        return False

    def showProgress(self, text):
        self.lblProgress.setText(text)
        self.lblProgress.show()

    def hideProgress(self):
        self.lblProgress.hide()

    def reset(self):
        self.urls = []
        self.txtFilter.setText("")
        self.txtFilter.setFocus()
        self.listUrl.clear()
        self.lister.stop()

    def list(self):
        url = kate.activeDocument().url()
        self.project = self.getProjectUrl(url)

        for doc in kate.documentManager.documents():
            self.addFileUrl(doc.url(), "Open document")

        if self.project:
            self.reason = "In project %s" % self.project
            self.rootPath = KUrl(self.project)
        else:
            self.reason = "Same path of %s" % url.fileName()
            self.rootPath = url.upUrl()

        self.lister.list(self.rootPath, recurse=self.project != False)

    def addFileUrl(self, url, reason=None):
        if url not in self.urls:
            mime = KMimeType.findByUrl(url)[0]
            path = url.url()
            filename = url.fileName()

            item = QListWidgetItem()
            if self.project and path.startswith(self.project):
                path = path[len(self.project):]
                item.setWhatsThis(path)
                item.setText("<b>%s</b>: <i>%s</i>" % (filename, path))
            else:
                item.setWhatsThis(filename)
                item.setText("<b>%s</b>" % filename)
            if reason:
                item.setToolTip(reason)
            item.setIcon(QIcon(self.iconLoader.loadMimeTypeIcon(mime.iconName(), KIconLoader.Small)))
            self.listUrl.addItem(item)

            if url.fileName().find(self.txtFilter.text()) < 0:
                self.listUrl.setItemHidden(item, True)
            self.urls.append(url)

            self.refreshFilter()

    def refreshFilter(self):
        self.on_txtFilter_textEdited(self.txtFilter.text())

    def on_txtFilter_textEdited(self, s):
        firstMatch = -1
        pattern = re.compile(".*".join([re.escape(c) for c in s]), re.I)
        for i in range(self.listUrl.count()):
            matched = pattern.search(self.listUrl.item(i).whatsThis())
            if matched and firstMatch < 0:
                firstMatch = i
            self.listUrl.setItemHidden(self.listUrl.item(i), matched is None)
        self.listUrl.setItemSelected(self.listUrl.item(firstMatch), True)

    def on_txtFilter_keyPressed(self, event):
        selected = self.listUrl.selectedItems()
        if selected:
            current_index = self.listUrl.row(selected[0])
        else:
            current_index = -1

        increment = 0
        if event.key() == Qt.Key_Up:
            increment = -1
        elif event.key() == Qt.Key_Down:
            increment = 1

        if increment != 0:
            current_index += increment
            while 0 <= current_index < self.listUrl.count():
                if self.listUrl.isRowHidden(current_index):
                    current_index += increment
                else:
                    self.listUrl.setItemSelected(self.listUrl.item(current_index), True)
                    current_index = -1

    def on_txtFilter_returnPressed(self):
        if len(self.listUrl.selectedItems()) > 0:
            self.on_listUrl_itemActivated(self.listUrl.selectedItems()[0])

    def on_listUrl_itemActivated(self, item):
        self.lister.stop()
        self.close()
        i = self.listUrl.row(item)
        if 0 <= i < len(self.urls):
            url = self.urls[i]
            kate.mainInterfaceWindow().activateView(kate.documentManager.openUrl(url))

    @pyqtSignature("")
    def on_btnSettings_clicked(self):
        settingsDialog = SettingsDialog(kate.activeDocument().url(), self)
        settingsDialog.txtIncludePatterns.setPlainText("\n".join([r.pattern for r in self.lister.includeFilters]))
        settingsDialog.txtExcludePatterns.setPlainText("\n".join([r.pattern for r in self.lister.excludeFilters]))
        for path in self.projectPaths:
            settingsDialog.listProjectPaths.addItem(path)

        if settingsDialog.exec_():
            configPaths = self.config.group("ProjectPaths")
            for key in configPaths.keyList():
                configPaths.deleteEntry(key)
            self.projectPaths = []
            i = 0
            while i < settingsDialog.listProjectPaths.count():
                item = settingsDialog.listProjectPaths.item(i)
                configPaths.writePathEntry("path%s" % i, item.text())
                self.projectPaths.append(item.text())
                i += 1

            configFilters = self.config.group("Filters")
            includeFilters = settingsDialog.txtIncludePatterns.toPlainText()
            self.lister.setIncludeFilters(includeFilters)
            configFilters.writeEntry("include", includeFilters)

            excludeFilters = settingsDialog.txtExcludePatterns.toPlainText()
            self.lister.setExcludeFilters(excludeFilters)
            configFilters.writeEntry("exclude", excludeFilters)

            self.config.sync()

    @pyqtSignature("")
    def on_btnRefresh_clicked(self):
        url = self.rootPath.url()
        for k in self.lister.cache.keys():
            if k.startswith(url):
                del self.lister.cache[k]
        self.reset()
        self.list()

    def listerFileFound(self, url):
        QApplication.processEvents()
        self.addFileUrl(url, self.reason)

    def listerDirChanged(self, url):
        self.showProgress(url.url())

    def listerCompleted(self):
        self.hideProgress()
Esempio n. 17
0
 def icon(self, size):
     l = KIconLoader()
     return l.loadMimeTypeIcon(self._type.iconName(), KIconLoader.NoGroup, size) 
Esempio n. 18
0
    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 = QtGui.QPixmap(option.rect.size())
        pixmap.fill(Qt.transparent)

        p = QtGui.QPainter(pixmap)
        p.setRenderHint(QtGui.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 []
            pix = KIconLoader().loadIcon(_icon, KIconLoader.NoGroup, 32,
                                         KIconLoader.DefaultState, overlay, '',
                                         True)
            if not pix.isNull():
                icon = QtGui.QIcon(
                    pix.scaled(QSize(32, 32), Qt.KeepAspectRatio,
                               Qt.SmoothTransformation))

        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

        # 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(QtGui.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(QtGui.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 == '':
                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 = QtGui.QStyleOptionViewItemV4(option)

            buttonStyle = QtGui.QStyleOptionButton()
            if option.state & QtGui.QStyle.State_MouseOver or option.state & QtGui.QStyle.State_HasFocus:
                buttonStyle.state |= QtGui.QStyle.State_HasFocus
            buttonStyle.state |= QtGui.QStyle.State_Enabled
            buttonStyle.text = i18n("Details")

            buttonStyle.rect = QRect(width - 100, position - 22, 100, 22)

        p.end()

        if option.state & QtGui.QStyle.State_HasFocus and self.animatable:
            option.state |= QtGui.QStyle.State_MouseOver
            # Use Oxygen style to draw focus rect like MouseOver effect of Oxygen..
            self.oxygen.drawPrimitive(QtGui.QStyle.PE_PanelItemViewItem,
                                      option, painter, None)

        if not self.rowAnimator.running() and buttonStyle:
            if self.show_details_button:
                PackageDelegate.AppStyle().drawControl(
                    QtGui.QStyle.CE_PushButton, buttonStyle, painter, None)
                self.rowAnimator.hoverLinkFilter.button_rect = QRect(
                    buttonStyle.rect)

        painter.drawPixmap(option.rect.topLeft(), pixmap)
        del pixmap
	def load(self):

		configurePixmap = KIconLoader.global_().loadIcon(self.iconName, KIconLoader.NoGroup, self.height())

		self.setPixmap(configurePixmap)