Пример #1
0
    def __init__(self, parent, embed=False):
        QtWidgets.QWidget.__init__(self, parent)

        if embed:
            self.setupUi(parent)
        else:
            self.setupUi(self)

        self._in_progress = False

        # Animation
        self.animator = QtCore.QTimeLine(ANIM_TIME, self)

        # Initialize heights of animated widgets
        self.hideEditBox()

        # Backend
        self.iface = Interface()

        # Fail if no packages provide backend
        self.checkBackend()

        # Build "Add New" menu
        self.buildMenu()

        # Build filter
        self.buildFilter()

        # Build item list
        self.buildItemList()

        # User/group edit widgets
        layout = QtWidgets.QVBoxLayout(self.frameWidget)
        self.widgetUserEdit = EditUserWidget(self.frameWidget)
        layout.addWidget(self.widgetUserEdit)
        self.widgetGroupEdit = EditGroupWidget(self.frameWidget)
        layout.addWidget(self.widgetGroupEdit)

        # List user shells
        self.widgetUserEdit.listShells()

        # Signals
        self.comboFilter.currentIndexChanged[int].connect(self.slotFilterChanged)
        self.pushNew.triggered[QAction].connect(self.slotOpenEdit)
        self.buttonBox.accepted.connect(self.slotSaveEdit)
        self.buttonBox.accepted.connect(self.widgetUserEdit.checkFields)
        self.buttonBox.rejected.connect(self.slotCancelEdit)
        self.animator.frameChanged[int].connect(self.slotAnimate)
        self.animator.finished.connect(self.slotAnimationFinished)
        self.widgetUserEdit.buttonStatusChanged[int].connect(self.slotButtonStatusChanged)
        self.widgetGroupEdit.buttonStatusChanged[int].connect(self.slotButtonStatusChanged)
Пример #2
0
class MainWidget(QtGui.QWidget, Ui_MainWidget):
    def __init__(self, parent, embed=False):
        QtGui.QWidget.__init__(self, parent)

        if embed:
            self.setupUi(parent)
        else:
            self.setupUi(self)

        self._in_progress = False

        # Animation
        self.animator = QtCore.QTimeLine(ANIM_TIME, self)

        # Initialize heights of animated widgets
        self.hideEditBox()

        # Backend
        self.iface = Interface()

        # Fail if no packages provide backend
        self.checkBackend()

        # Build "Add New" menu
        self.buildMenu()

        # Build filter
        self.buildFilter()

        # Build item list
        self.buildItemList()

        # User/group edit widgets
        layout = QtGui.QVBoxLayout(self.frameWidget)
        self.widgetUserEdit = EditUserWidget(self.frameWidget)
        layout.addWidget(self.widgetUserEdit)
        self.widgetGroupEdit = EditGroupWidget(self.frameWidget)
        layout.addWidget(self.widgetGroupEdit)

        # List user shells
        self.widgetUserEdit.listShells()

        # Signals
        self.connect(self.comboFilter,
                     QtCore.SIGNAL("currentIndexChanged(int)"),
                     self.slotFilterChanged)
        self.connect(self.pushNew, QtCore.SIGNAL("triggered(QAction*)"),
                     self.slotOpenEdit)
        self.connect(self.buttonBox, QtCore.SIGNAL("accepted()"),
                     self.slotSaveEdit)
        self.connect(self.buttonBox, QtCore.SIGNAL("accepted()"),
                     self.widgetUserEdit.checkFields)
        self.connect(self.buttonBox, QtCore.SIGNAL("rejected()"),
                     self.slotCancelEdit)
        self.connect(self.animator, QtCore.SIGNAL("frameChanged(int)"),
                     self.slotAnimate)
        self.connect(self.animator, QtCore.SIGNAL("finished()"),
                     self.slotAnimationFinished)
        self.connect(self.widgetUserEdit,
                     QtCore.SIGNAL("buttonStatusChanged(int)"),
                     self.slotButtonStatusChanged)
        self.connect(self.widgetGroupEdit,
                     QtCore.SIGNAL("buttonStatusChanged(int)"),
                     self.slotButtonStatusChanged)

    def hiddenListWorkaround(self):
        """
            Workaround for hidden list items
        """
        self.listItems.setFocus()
        self.comboFilter.setFocus()

    def checkBackend(self):
        """
            Check if there are packages that provide required backend.
        """
        if not len(self.iface.getPackages()):
            kdeui.KMessageBox.error(
                self,
                kdecore.i18n(
                    "There are no packages that provide backend for this application.\nPlease make sure that packages are installed and configured correctly."
                ))
            return False
        return True

    def clearItemList(self):
        """
            Clears item list.
        """
        self.listItems.clear()

    def makeItemWidget(self,
                       id_,
                       title="",
                       description="",
                       type_=None,
                       icon=None,
                       state=None):
        """
            Makes an item widget having given properties.
        """
        widget = ItemWidget(self.listItems, id_, title, description, type_,
                            icon, state)

        self.connect(widget, QtCore.SIGNAL("stateChanged(int)"),
                     self.slotItemState)
        self.connect(widget, QtCore.SIGNAL("editClicked()"), self.slotItemEdit)
        self.connect(widget, QtCore.SIGNAL("deleteClicked()"),
                     self.slotItemDelete)

        return widget

    def addItem(self, id_, name="", description="", group=False):
        """
            Adds an item to list.
        """
        if group:
            type_ = "group"
            icon = "system-users"
        else:
            type_ = "user"
            icon = "user-identity"

        # Build widget and widget item
        widget = self.makeItemWidget(id_, name, description, type_,
                                     kdeui.KIcon(icon), None)
        widgetItem = ItemListWidgetItem(self.listItems, widget)

        # Groups are uneditable
        if group:
            widget.hideEdit()

        # Add to list
        self.listItems.setItemWidget(widgetItem, widget)

        # Check if a filter matches item
        if not self.itemMatchesFilter(widgetItem):
            self.listItems.setItemHidden(widgetItem, True)

    def buildItemList(self):
        """
            Builds item list.
        """
        # Clear list
        self.clearItemList()

        # Lists of all users/groups
        self.all_users = []
        self.all_groups = []

        def handleUserList(package, exception, args):
            if exception:
                pass
                # TODO: Handle exception
            else:
                users = args[0]
                for uid, name, fullname in sorted(
                        users, key=lambda username: username[1]):
                    self.all_users.append(name)
                    self.addItem(uid, name, fullname)

        self.iface.userList(func=handleUserList)

        def handleGroupList(package, exception, args):
            if exception:
                pass
                # TODO: Handle exception
            else:
                groups = args[0]
                for gid, name in sorted(groups,
                                        key=lambda groupname: groupname[1]):
                    self.all_groups.append(name)
                    self.addItem(gid, name, "", group=True)

        self.iface.groupList(func=handleGroupList)

    def callIface(self, method):
        """
            Grab all comar exceptions
        """
        try:
            method()
        except Exception, e:
            if "Comar.PolicyKit" in e._dbus_error_name:
                kdeui.KMessageBox.error(self, kdecore.i18n("Access denied."))
            else:
                kdeui.KMessageBox.error(self, unicode(e))
            return False
Пример #3
0
class MainWidget(QtWidgets.QWidget, Ui_MainWidget):
    def __init__(self, parent, embed=False):
        QtWidgets.QWidget.__init__(self, parent)

        if embed:
            self.setupUi(parent)
        else:
            self.setupUi(self)

        self._in_progress = False

        # Animation
        self.animator = QtCore.QTimeLine(ANIM_TIME, self)

        # Initialize heights of animated widgets
        self.hideEditBox()

        # Backend
        self.iface = Interface()

        # Fail if no packages provide backend
        self.checkBackend()

        # Build "Add New" menu
        self.buildMenu()

        # Build filter
        self.buildFilter()

        # Build item list
        self.buildItemList()

        # User/group edit widgets
        layout = QtWidgets.QVBoxLayout(self.frameWidget)
        self.widgetUserEdit = EditUserWidget(self.frameWidget)
        layout.addWidget(self.widgetUserEdit)
        self.widgetGroupEdit = EditGroupWidget(self.frameWidget)
        layout.addWidget(self.widgetGroupEdit)

        # List user shells
        self.widgetUserEdit.listShells()

        # Signals
        self.comboFilter.currentIndexChanged[int].connect(self.slotFilterChanged)
        self.pushNew.triggered[QAction].connect(self.slotOpenEdit)
        self.buttonBox.accepted.connect(self.slotSaveEdit)
        self.buttonBox.accepted.connect(self.widgetUserEdit.checkFields)
        self.buttonBox.rejected.connect(self.slotCancelEdit)
        self.animator.frameChanged[int].connect(self.slotAnimate)
        self.animator.finished.connect(self.slotAnimationFinished)
        self.widgetUserEdit.buttonStatusChanged[int].connect(self.slotButtonStatusChanged)
        self.widgetGroupEdit.buttonStatusChanged[int].connect(self.slotButtonStatusChanged)

    def hiddenListWorkaround(self):
        """
            Workaround for hidden list items
        """
        size = self.size()
        size += QtCore.QSize(1,1)
        self.resize(size)
        size -= QtCore.QSize(1,1)
        QtCore.QTimer.singleShot(1, lambda: self.resize(size))

    def checkBackend(self):
        """
            Check if there are packages that provide required backend.
        """
        if not len(self.iface.getPackages()):
           QMessageBox.critical(self,"Error", i18n("There are no packages that provide backend for this application.\nPlease make sure that packages are installed and configured correctly"))
           return False
        return True

    def clearItemList(self):
        """
            Clears item list.
        """
        self.listItems.clear()

    def makeItemWidget(self, id_, title="", description="", type_=None, icon=None, state=None):
        """
            Makes an item widget having given properties.
        """
        widget = ItemWidget(self.listItems, id_, title, description, type_, icon, state)
        
        widget.stateChanged[int].connect(self.slotItemState)
        widget.editClicked.connect(self.slotItemEdit)
        widget.deleteClicked.connect(self.slotItemDelete)

        return widget

    def addItem(self, id_, name="", description="", group=False):
        """
            Adds an item to list.
        """
        if group:
            type_ = "group"
            icon = "system-users"
        else:
            type_ = "user"
            icon = "user-identity"

        # Build widget and widget item
        widget = self.makeItemWidget(id_, name, description, type_,KIcon(icon), None)
        widgetItem = ItemListWidgetItem(self.listItems, widget)

        # Groups are uneditable
        if group:
            widget.hideEdit()

        # Add to list
        self.listItems.setItemWidget(widgetItem, widget)

        # Check if a filter matches item
        if not self.itemMatchesFilter(widgetItem):
            self.listItems.itemFromIndex(self.listItems.indexFromItem(widgetItem)).setHidden(True)            
            pass

    def buildItemList(self):
        """
            Builds item list.
        """
        # Clear list
        self.clearItemList()

        # Lists of all users/groups
        self.all_users = []
        self.all_groups = []

        def handleUserList(package, exception, args):
            if exception:
                pass
                # TODO: Handle exception
            else:
                users = args[0]
                for uid, name, fullname in users:
                    self.all_users.append(name)
                    self.addItem(uid, name, fullname)

        self.iface.userList(func=handleUserList)

        def handleGroupList(package, exception, args):
            if exception:
                pass
                # TODO: Handle exception
            else:
                groups = args[0]
                for gid, name in groups:
                    self.all_groups.append(name)
                    self.addItem(gid, name, "", group=True)

        self.iface.groupList(func=handleGroupList)

    def callIface(self, method):
        """
            Grab all comar exceptions
        """
        try:
            method()
        except Exception, e:
            if "Comar.PolicyKit" in e._dbus_error_name:
                QMessageBox.critical(self,"Error", i18n("Access denied"))
            else:
               QMessageBox.critical(self,"Error", unicode(e))
               return False