Beispiel #1
0
class PreviewDialog(PAbstractBox, Ui_Preview):
    def __init__(self, parent, url):
        PAbstractBox.__init__(self, parent.parent)
        self.setupUi(self)
        self.parent = parent

        # PDS Settings
        self._animation = 1
        self._duration = 1
        self.enableOverlay()
        self.setOverlayOpacity(150)
        # self._disable_parent_in_shown = True

        self.cancelButton.clicked.connect(self._hide)
        self.cancelButton.setIcon(KIcon("cancel"))

        # Hide Scrollbars and context menu in webview
        self.webView.setContextMenuPolicy(Qt.NoContextMenu)
        self.webView.page().mainFrame().setScrollBarPolicy(
            Qt.Vertical, Qt.ScrollBarAlwaysOff)
        self.webView.page().mainFrame().setScrollBarPolicy(
            Qt.Horizontal, Qt.ScrollBarAlwaysOff)

        self.busy = QProgressIndicator(self, "white")
        self.busy.setMaximumSize(QSize(48, 48))
        self.webLayout.addWidget(self.busy)
        self.busy.hide()

        self.parent._hide()
        QTimer.singleShot(0, lambda: self.showPackageScreenShot(url))

        self.setOverlayClickMethod(lambda x: self._hide())

    def showPackageScreenShot(self, url):
        if network_available():

            self.webView.loadFinished.connect(
                lambda x: self.webView.setVisible(x))
            self.webView.loadFinished.connect(
                lambda x: self.busy.setVisible(not x))
            self.webView.loadFinished.connect(
                lambda x: self.cancelButton.setVisible(x))

            self.registerFunction(FINISHED, lambda: self.webView.load(url))

            self.cancelButton.hide()
            self.webView.hide()
            self.busy.busy()

            self.animate(start=BOTCENTER, stop=MIDCENTER)

    def _hide(self):
        self.busy.stopAnimation()
        self.webView.loadFinished.disconnect()
        self.animate(start=MIDCENTER, stop=BOTCENTER, direction=OUT)
        self.parent.animate(start=BOTCENTER, stop=MIDCENTER)
Beispiel #2
0
class PMessageBox(PAbstractBox):

    # STYLE SHEET
    STYLE = """color:white;font-size:16pt;"""
    OUT_POS = MIDCENTER
    IN_POS = MIDCENTER
    STOP_POS = MIDCENTER

    def __init__(self, parent):
        PAbstractBox.__init__(self, parent)
        self.ui = Ui_MessageBox()
        self.ui.setupUi(self)

        self.busy = QProgressIndicator(self, "white")
        self.busy.setMinimumSize(QSize(32, 32))
        self.busy.hide()
        self.ui.mainLayout.insertWidget(1, self.busy)

        self._animation = 2
        self._duration = 1
        self.last_msg = None
        self.setStyleSheet(PMessageBox.STYLE)
        self.enableOverlay()
        self.setOverlayOpacity(150)
        self.hide()

    def showMessage(self, message, icon=None, busy=False):
        self.ui.label.setText(message)

        if busy:
            self.busy.busy()
            self.ui.icon.hide()
        else:
            if icon:
                if type(icon) == str:
                    icon = KIcon(icon).pixmap(32, 32)
                self.ui.icon.setPixmap(QPixmap(icon))
                self.ui.icon.show()
            else:
                self.ui.icon.hide()
            self.busy.hide()

        self.last_msg = self.animate(start=PMessageBox.IN_POS,
                                     stop=PMessageBox.STOP_POS)
        qApp.processEvents()  # ???

    def hideMessage(self, force=False):
        if self.isVisible() or force:
            self.animate(start=PMessageBox.STOP_POS,
                         stop=PMessageBox.OUT_POS,
                         direction=OUT,
                         dont_animate=True)
class PMessageBox(PAbstractBox):

    # STYLE SHEET
    STYLE = """color:white;font-size:16pt;"""
    OUT_POS  = MIDCENTER
    IN_POS   = MIDCENTER
    STOP_POS = MIDCENTER

    def __init__(self, parent):
        PAbstractBox.__init__(self, parent)
        self.ui = Ui_MessageBox()
        self.ui.setupUi(self)

        self.busy = QProgressIndicator(self, "white")
        self.busy.setMinimumSize(QtCore.QSize(32, 32))
        self.busy.hide()
        self.ui.mainLayout.insertWidget(1, self.busy)

        self._animation = 2
        self._duration = 1
        self.last_msg = None
        self.setStyleSheet(PMessageBox.STYLE)
        self.enableOverlay()
        self.setOverlayOpacity(150)
        self.hide()

    def showMessage(self, message, icon = None, busy = False):
        self.ui.label.setText(message)

        if busy:
            self.busy.busy()
            self.ui.icon.hide()
        else:
            if icon:
                if type(icon) == str:
                    icon = QIcon(icon).pixmap(32,32)
                self.ui.icon.setPixmap(QtGui.QPixmap(icon))
                self.ui.icon.show()
            else:
                self.ui.icon.hide()
            self.busy.hide()

        self.last_msg = self.animate(start = PMessageBox.IN_POS, stop = PMessageBox.STOP_POS)
        QtWidgets.qApp.processEvents()

    def hideMessage(self, force = False):
        if self.isVisible() or force:
            self.animate(start = PMessageBox.STOP_POS,
                         stop  = PMessageBox.OUT_POS,
                         direction = OUT,
                         dont_animate = True)
Beispiel #4
0
class PreviewDialog(PAbstractBox, Ui_Preview):
    def __init__(self, parent, url):
        PAbstractBox.__init__(self, parent.parent)
        self.setupUi(self)
        self.parent = parent

        # PDS Settings
        self._animation = 1
        self._duration = 1
        self.enableOverlay()
        self.setOverlayOpacity(150)
        # self._disable_parent_in_shown = True

        self.cancelButton.clicked.connect(self._hide)
        self.cancelButton.setIcon(KIcon("cancel"))

        # Hide Scrollbars and context menu in webview
        self.webView.setContextMenuPolicy(Qt.NoContextMenu)
        self.webView.page().mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
        self.webView.page().mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)

        self.busy = QProgressIndicator(self, "white")
        self.busy.setMaximumSize(QSize(48, 48))
        self.webLayout.addWidget(self.busy)
        self.busy.hide()

        self.parent._hide()
        QTimer.singleShot(0, lambda: self.showPackageScreenShot(url))

        self.setOverlayClickMethod(lambda x:self._hide())

    def showPackageScreenShot(self, url):
        if network_available():

            self.webView.loadFinished.connect(lambda x: self.webView.setVisible(x))
            self.webView.loadFinished.connect(lambda x: self.busy.setVisible(not x))
            self.webView.loadFinished.connect(lambda x: self.cancelButton.setVisible(x))

            self.registerFunction(FINISHED, lambda: self.webView.load(url))

            self.cancelButton.hide()
            self.webView.hide()
            self.busy.busy()

            self.animate(start = BOTCENTER, stop = MIDCENTER)

    def _hide(self):
        self.busy.stopAnimation()
        self.webView.loadFinished.disconnect()
        self.animate(start = MIDCENTER, stop = BOTCENTER, direction = OUT)
        self.parent.animate(start = BOTCENTER, stop = MIDCENTER)
Beispiel #5
0
class MainWindow(KXmlGuiWindow, Ui_MainWindow):
    def __init__(self, app = None):
        KXmlGuiWindow.__init__(self, None)
        self.setupUi(self)

        self.app = app
        self.iface = backend.pm.Iface()

        self.busy = QProgressIndicator(self)
        self.busy.setFixedSize(QSize(20, 20))

        self.setWindowIcon(KIcon(":/data/package-manager.png"))

        self.setCentralWidget(MainWidget(self))
        self.cw = self.centralWidget()

        self.settingsDialog = SettingsDialog(self)

        self.initializeActions()
        self.initializeStatusBar()
        self.initializeTray()
        self.connectMainSignals()

        self.pdsMessageBox = PMessageBox(self)

    def connectMainSignals(self):
        self.cw.connectMainSignals()
        self.connect(QShortcut(QKeySequence(Qt.CTRL + Qt.Key_Tab),self),
                SIGNAL("activated()"), lambda: self.moveTab('next'))
        self.connect(QShortcut(QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_Tab),self),
                SIGNAL("activated()"), lambda: self.moveTab('prev'))
        self.connect(QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F),self),
                SIGNAL("activated()"), self.cw.searchLine.setFocus)
        self.connect(QShortcut(QKeySequence(Qt.Key_F3),self),
                SIGNAL("activated()"), self.cw.searchLine.setFocus)

        self.connect(self.settingsDialog, SIGNAL("packagesChanged()"), self.cw.initialize)
        self.connect(self.settingsDialog, SIGNAL("packageViewChanged()"), self.cw.updateSettings)
        self.connect(self.settingsDialog, SIGNAL("traySettingChanged()"), self.tray.settingsChanged)
        self.connect(self.cw.state, SIGNAL("repositoriesChanged()"), self.tray.populateRepositoryMenu)
        self.connect(self.cw, SIGNAL("repositoriesUpdated()"), self.tray.updateTrayUnread)
        self.connect(KApplication.kApplication(), SIGNAL("shutDown()"), self.slotQuit)

    def moveTab(self, direction):
        new_index = self.cw.stateTab.currentIndex() - 1
        if direction == 'next':
            new_index = self.cw.stateTab.currentIndex() + 1
        if new_index not in range(self.cw.stateTab.count()):
            new_index = 0
        self.cw.stateTab.setCurrentIndex(new_index)

    def initializeTray(self):
        self.tray = Tray(self, self.iface)
        self.connect(self.cw.operation, SIGNAL("finished(QString)"), self.trayAction)
        self.connect(self.cw.operation, SIGNAL("finished(QString)"), self.tray.stop)
        self.connect(self.cw.operation, SIGNAL("operationCancelled()"), self.tray.stop)
        self.connect(self.cw.operation, SIGNAL("started(QString)"), self.tray.animate)
        self.connect(self.tray, SIGNAL("showUpdatesSelected()"), self.trayShowUpdates)

    def trayShowUpdates(self):
        self.showUpgradeAction.setChecked(True)

        self.cw.switchState(StateManager.UPGRADE)

        KApplication.kApplication().updateUserTimestamp()

        self.show()
        self.raise_()

    def trayAction(self, operation):
        if not self.isVisible() and operation in ["System.Manager.updateRepository", "System.Manager.updateAllRepositories"]:
            self.tray.showPopup()
        if self.tray.isActive() and operation in ["System.Manager.updatePackage",
                                                  "System.Manager.installPackage",
                                                  "System.Manager.removePackage"]:
            self.tray.updateTrayUnread()

    def initializeStatusBar(self):
        self.cw.mainLayout.insertWidget(0, self.busy)
        self.statusBar().addPermanentWidget(self.cw.actions, 1)
        self.statusBar().show()

        self.updateStatusBar('')

        self.connect(self.cw, SIGNAL("selectionStatusChanged(QString)"), self.updateStatusBar)
        self.connect(self.cw, SIGNAL("updatingStatus()"), self.statusWaiting)

    def initializeActions(self):
        self.toolBar().setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        KStandardAction.quit(KApplication.kApplication().quit, self.actionCollection())
        KStandardAction.preferences(self.settingsDialog.show, self.actionCollection())
        self.setupGUI(KXmlGuiWindow.Default, "/usr/share/kde4/apps/package-manager/data/packagemanagerui.rc")
        self.initializeOperationActions()

    def initializeOperationActions(self):
        actionGroup = QtGui.QActionGroup(self)

        self.showAllAction = KToggleAction(KIcon("applications-other"), i18n("All Packages"), self)
        self.actionCollection().addAction("showAllAction", self.showAllAction)
        self.connect(self.showAllAction, SIGNAL("triggered()"), lambda:self.cw.switchState(StateManager.ALL))
        self.cw.stateTab.addTab(QWidget(), KIcon("applications-other"), i18n("All Packages"))
        actionGroup.addAction(self.showAllAction)

        self.showInstallAction = KToggleAction(KIcon("list-add"), i18n("Installable Packages"), self)
        self.actionCollection().addAction("showInstallAction", self.showInstallAction)
        self.connect(self.showInstallAction, SIGNAL("triggered()"), lambda:self.cw.switchState(StateManager.INSTALL))
        self.cw.stateTab.addTab(QWidget(), KIcon("list-add"), i18n("Installable Packages"))
        actionGroup.addAction(self.showInstallAction)

        self.showRemoveAction = KToggleAction(KIcon("list-remove"), i18n("Installed Packages"), self)
        self.actionCollection().addAction("showRemoveAction", self.showRemoveAction)
        self.connect(self.showRemoveAction, SIGNAL("triggered()"), lambda:self.cw.switchState(StateManager.REMOVE))
        self.cw.stateTab.addTab(QWidget(), KIcon("list-remove"), i18n("Installed Packages"))
        actionGroup.addAction(self.showRemoveAction)

        self.showUpgradeAction = KToggleAction(KIcon("system-software-update"), i18n("Updates"), self)
        self.actionCollection().addAction("showUpgradeAction", self.showUpgradeAction)
        self.connect(self.showUpgradeAction, SIGNAL("triggered()"), lambda:self.cw.switchState(StateManager.UPGRADE))
        self.cw.stateTab.addTab(QWidget(), KIcon("system-software-update"), i18n("Updates"))
        actionGroup.addAction(self.showUpgradeAction)

        # self.showHistoryAction = KToggleAction(KIcon("view-refresh"), i18n("History"), self)
        # self.actionCollection().addAction("showHistoryAction", self.showHistoryAction)
        # self.connect(self.showHistoryAction, SIGNAL("triggered()"), lambda:self.cw.switchState(StateManager.HISTORY))
        # self.cw.stateTab.addTab(QWidget(), KIcon("view-refresh"), i18n("History"))
        # actionGroup.addAction(self.showHistoryAction)

        self.cw.menuButton.setMenu(QMenu('MainMenu', self.cw.menuButton))
        self.cw.menuButton.setIcon(KIcon('preferences-other'))
        self.cw.menuButton.menu().clear()

        self.cw.contentHistory.hide()

        # self.cw.menuButton.menu().addAction(self.showAllAction)
        # self.cw.menuButton.menu().addAction(self.showInstallAction)
        # self.cw.menuButton.menu().addAction(self.showRemoveAction)
        # self.cw.menuButton.menu().addAction(self.showUpgradeAction)
        # self.cw.menuButton.menu().addSeparator()

        self.cw.menuButton.menu().addAction(self.actionCollection().action(KStandardAction.name(KStandardAction.Preferences)))
        self.cw.menuButton.menu().addAction(self.actionCollection().action(KStandardAction.name(KStandardAction.Help)))
        self.cw.menuButton.menu().addSeparator()
        self.cw.menuButton.menu().addAction(self.actionCollection().action(KStandardAction.name(KStandardAction.AboutApp)))
        self.cw.menuButton.menu().addAction(self.actionCollection().action(KStandardAction.name(KStandardAction.AboutKDE)))
        self.cw.menuButton.menu().addSeparator()
        self.cw.menuButton.menu().addAction(self.actionCollection().action(KStandardAction.name(KStandardAction.Quit)))

        self.cw._states = {self.cw.state.ALL    :(0, self.showAllAction),
                           self.cw.state.INSTALL:(1, self.showInstallAction),
                           self.cw.state.REMOVE :(2, self.showRemoveAction),
                           self.cw.state.UPGRADE:(3, self.showUpgradeAction)}
        #                  self.cw.state.HISTORY:(4, self.showHistoryAction)}

        self.showAllAction.setChecked(True)
        self.cw.checkUpdatesButton.hide()
        self.cw.checkUpdatesButton.setIcon(KIcon('view-refresh'))
        self.cw.showBasketButton.clicked.connect(self.cw.showBasket)

        # Little time left for the new ui
        self.menuBar().setVisible(False)
        self.cw.switchState(self.cw.state.ALL)

    def statusWaiting(self):
        self.updateStatusBar(i18n('Calculating dependencies...'), busy = True)

    def updateStatusBar(self, text, busy = False):
        if text == '':
            text = i18n("Currently your basket is empty.")
            self.busy.hide()
            self.cw.showBasketButton.hide()
        else:
            self.cw.showBasketButton.show()

        if busy:
            self.busy.busy()
            self.cw.showBasketButton.hide()
        else:
            self.busy.hide()

        self.cw.statusLabel.setText(text)

    def queryClose(self):
        if config.PMConfig().systemTray() and not KApplication.kApplication().sessionSaving():
            self.hide()
            return False
        return True

    def queryExit(self):
        if not self.iface.operationInProgress():
            if self.tray:
                del self.tray.notification
            return True
        return False

    def slotQuit(self):
        if self.iface.operationInProgress():
            return
class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, app=None):
        QMainWindow.__init__(self, None)
        self.setupUi(self)

        self.app = app
        self.iface = backend.pm.Iface()

        self.busy = QProgressIndicator(self)
        self.busy.setFixedSize(QSize(20, 20))

        self.setWindowIcon(QIcon(":/data/package-manager.png"))

        self.setCentralWidget(MainWidget(self))
        self.cw = self.centralWidget()

        self.settingsDialog = SettingsDialog(self)

        self.initializeActions()
        self.initializeStatusBar()
        self.initializeTray()
        self.connectMainSignals()

        self.pdsMessageBox = PMessageBox(self)

    activated = pyqtSignal()

    def connectMainSignals(self):
        self.cw.connectMainSignals()
        QShortcut(QKeySequence(Qt.CTRL + Qt.Key_Tab),
                  self).activated.connect(lambda: self.moveTab('next'))
        QShortcut(QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_Tab),
                  self).activated.connect(lambda: self.moveTab('prev'))
        QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F),
                  self).activated.connect(self.cw.searchLine.setFocus)
        QShortcut(QKeySequence(Qt.Key_F3),
                  self).activated.connect(self.cw.searchLine.setFocus)

        self.settingsDialog.packagesChanged.connect(self.cw.initialize)
        self.settingsDialog.packageViewChanged.connect(self.cw.updateSettings)
        self.settingsDialog.traySettingChanged.connect(
            self.tray.settingsChanged)
        self.cw.state.repositoriesChanged.connect(
            self.tray.populateRepositoryMenu)
        self.cw.repositoriesUpdated.connect(self.tray.updateTrayUnread)
        qApp.shutDown.connect(self.slotQuit)

    def moveTab(self, direction):
        new_index = self.cw.stateTab.currentIndex() - 1
        if direction == 'next':
            new_index = self.cw.stateTab.currentIndex() + 1
        if new_index not in range(self.cw.stateTab.count()):
            new_index = 0
        self.cw.stateTab.setCurrentIndex(new_index)

    def initializeTray(self):
        self.tray = Tray(self, self.iface)
        self.cw.operation.finished.connect(self.trayAction)
        self.cw.operation.finished.connect(self.tray.stop)
        self.cw.operation.operationCancelled.connect(self.tray.stop)
        self.cw.operation.started.connect(self.tray.animate)
        self.tray.showUpdatesSelected.connect(self.trayShowUpdates)

    def trayShowUpdates(self):
        self.showUpgradeAction.setChecked(True)

        self.cw.switchState(StateManager.UPGRADE)

        KApplication.kApplication().updateUserTimestamp()

        self.show()
        self.raise_()

    def trayAction(self, operation):
        if not self.isVisible() and operation in [
                "System.Manager.updateRepository",
                "System.Manager.updateAllRepositories"
        ]:
            self.tray.showPopup()
        if self.tray.isVisible() and operation in [
                "System.Manager.updatePackage",
                "System.Manager.installPackage", "System.Manager.removePackage"
        ]:
            self.tray.updateTrayUnread()

    def initializeStatusBar(self):
        self.cw.mainLayout.insertWidget(0, self.busy)
        self.statusBar().addPermanentWidget(self.cw.actions, 1)
        self.statusBar().show()

        self.updateStatusBar('')

        self.cw.selectionStatusChanged.connect(self.updateStatusBar)
        self.cw.updatingStatus.connect(self.statusWaiting)

    def initializeActions(self):
        self.initializeOperationActions()

    def initializeOperationActions(self):

        self.showAllAction = QAction(
            KIcon(("applications-other", "package_applications")),
            self.tr("All Packages"), self)
        self.showAllAction.triggered.connect(
            lambda: self.cw.switchState(StateManager.ALL))
        self.cw.stateTab.addTab(
            QWidget(), KIcon(("applications-other", "package_applications")),
            self.tr("All Packages"))

        self.showInstallAction = QAction(KIcon(("list-add", "add")),
                                         self.tr("Installable Packages"), self)
        self.showInstallAction.triggered.connect(
            lambda: self.cw.switchState(StateManager.INSTALL))
        self.cw.stateTab.addTab(QWidget(), KIcon(("list-add", "add")),
                                self.tr("Installable Packages"))

        self.showRemoveAction = QAction(KIcon(("list-remove", "remove")),
                                        self.tr("Installed Packages"), self)
        self.showRemoveAction.triggered.connect(
            lambda: self.cw.switchState(StateManager.REMOVE))
        self.cw.stateTab.addTab(QWidget(), KIcon(("list-remove", "remove")),
                                self.tr("Installed Packages"))

        self.showUpgradeAction = QAction(
            KIcon(("system-software-update", "gear")), self.tr("Updates"),
            self)
        self.showUpgradeAction.triggered.connect(
            lambda: self.cw.switchState(StateManager.UPGRADE))
        self.cw.stateTab.addTab(QWidget(),
                                KIcon(("system-software-update", "gear")),
                                self.tr("Updates"))

        self.showPreferences = QAction(
            KIcon(("preferences-system", "package_settings")),
            self.tr("Settings"), self)
        self.showPreferences.triggered.connect(self.settingsDialog.show)

        self.actionHelp = QAction(KIcon("help"), self.tr("Help"), self)
        self.actionHelp.setShortcuts(QKeySequence.HelpContents)
        self.actionHelp.triggered.connect(self.showHelp)

        self.actionQuit = QAction(KIcon("exit"), self.tr("Quit"), self)
        self.actionQuit.setShortcuts(QKeySequence.Quit)
        self.actionQuit.triggered.connect(qApp.exit)

        self.cw.menuButton.setMenu(QMenu('MainMenu', self.cw.menuButton))
        self.cw.menuButton.setIcon(
            KIcon(("preferences-system", "package_settings")))
        self.cw.menuButton.menu().clear()

        self.cw.contentHistory.hide()

        self.cw.menuButton.menu().addAction(self.showPreferences)
        self.cw.menuButton.menu().addSeparator()
        self.cw.menuButton.menu().addAction(self.actionHelp)
        self.cw.menuButton.menu().addAction(self.actionQuit)

        self.cw._states = {
            self.cw.state.ALL: (0, self.showAllAction),
            self.cw.state.INSTALL: (1, self.showInstallAction),
            self.cw.state.REMOVE: (2, self.showRemoveAction),
            self.cw.state.UPGRADE: (3, self.showUpgradeAction)
        }

        self.showAllAction.setChecked(True)
        self.cw.checkUpdatesButton.hide()
        self.cw.checkUpdatesButton.setIcon(KIcon(("view-refresh", "reload")))
        self.cw.showBasketButton.clicked.connect(self.cw.showBasket)

        # Little time left for the new ui
        self.menuBar().setVisible(False)
        self.cw.switchState(self.cw.state.ALL)

    def statusWaiting(self):
        self.updateStatusBar(self.tr('Calculating dependencies...'), busy=True)

    def showHelp(self):
        self.Pds = pds.Pds()
        self.lang = localedata.setSystemLocale(justGet=True)

        if self.lang in os.listdir("/usr/share/package-manager/help"):
            pass
        else:
            self.lang = "en"

        if self.Pds.session == pds.Kde3:
            os.popen(
                "khelpcenter /usr/share/package-manager/help/%s/main_help.html"
                % (self.lang))
        else:
            helpdialog.HelpDialog(self, helpdialog.MAINAPP)

    def updateStatusBar(self, text, busy=False):
        if text == '':
            text = self.tr("Currently your basket is empty.")
            self.busy.hide()
            self.cw.showBasketButton.hide()
        else:
            self.cw.showBasketButton.show()

        if busy:
            self.busy.busy()
            self.cw.showBasketButton.hide()
        else:
            self.busy.hide()

        self.cw.statusLabel.setText(text)
        self.cw.statusLabel.setToolTip(text)

    def queryClose(self):
        if config.PMConfig().systemTray():
            self.hide()
            return False
        return True

    def queryExit(self):
        if not self.iface.operationInProgress():
            if self.tray:
                del self.tray.notification
            return True
        return False

    def slotQuit(self):
        if self.iface.operationInProgress():
            return
Beispiel #7
0
class MainWindow(KXmlGuiWindow, Ui_MainWindow):
    def __init__(self, app=None):
        KXmlGuiWindow.__init__(self, None)
        self.setupUi(self)

        self.app = app
        self.iface = backend.pm.Iface()

        self.busy = QProgressIndicator(self)
        self.busy.setFixedSize(QSize(20, 20))

        self.setWindowIcon(KIcon(":/data/package-manager.png"))

        self.setCentralWidget(MainWidget(self))
        self.cw = self.centralWidget()

        self.settingsDialog = SettingsDialog(self)

        self.initializeActions()
        self.initializeStatusBar()
        self.initializeTray()
        self.connectMainSignals()

        self.pdsMessageBox = PMessageBox(self)

    def connectMainSignals(self):
        self.cw.connectMainSignals()
        self.connect(QShortcut(QKeySequence(Qt.CTRL + Qt.Key_Tab), self),
                     SIGNAL("activated()"), lambda: self.moveTab('next'))
        self.connect(
            QShortcut(QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_Tab), self),
            SIGNAL("activated()"), lambda: self.moveTab('prev'))
        self.connect(QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F), self),
                     SIGNAL("activated()"), self.cw.searchLine.setFocus)
        self.connect(QShortcut(QKeySequence(Qt.Key_F3), self),
                     SIGNAL("activated()"), self.cw.searchLine.setFocus)

        self.connect(self.settingsDialog, SIGNAL("packagesChanged()"),
                     self.cw.initialize)
        self.connect(self.settingsDialog, SIGNAL("packageViewChanged()"),
                     self.cw.updateSettings)
        self.connect(self.settingsDialog, SIGNAL("traySettingChanged()"),
                     self.tray.settingsChanged)
        self.connect(self.cw.state, SIGNAL("repositoriesChanged()"),
                     self.tray.populateRepositoryMenu)
        self.connect(self.cw, SIGNAL("repositoriesUpdated()"),
                     self.tray.updateTrayUnread)
        self.connect(KApplication.kApplication(), SIGNAL("shutDown()"),
                     self.slotQuit)

    def moveTab(self, direction):
        new_index = self.cw.stateTab.currentIndex() - 1
        if direction == 'next':
            new_index = self.cw.stateTab.currentIndex() + 1
        if new_index not in range(self.cw.stateTab.count()):
            new_index = 0
        self.cw.stateTab.setCurrentIndex(new_index)

    def initializeTray(self):
        self.tray = Tray(self, self.iface)
        self.connect(self.cw.operation, SIGNAL("finished(QString)"),
                     self.trayAction)
        self.connect(self.cw.operation, SIGNAL("finished(QString)"),
                     self.tray.stop)
        self.connect(self.cw.operation, SIGNAL("operationCancelled()"),
                     self.tray.stop)
        self.connect(self.cw.operation, SIGNAL("started(QString)"),
                     self.tray.animate)
        self.connect(self.tray, SIGNAL("showUpdatesSelected()"),
                     self.trayShowUpdates)

    def trayShowUpdates(self):
        self.showUpgradeAction.setChecked(True)

        self.cw.switchState(StateManager.UPGRADE)

        KApplication.kApplication().updateUserTimestamp()

        self.show()
        self.raise_()

    def trayAction(self, operation):
        if not self.isVisible() and operation in [
                "System.Manager.updateRepository",
                "System.Manager.updateAllRepositories"
        ]:
            self.tray.showPopup()
        if self.tray.isActive() and operation in [
                "System.Manager.updatePackage",
                "System.Manager.installPackage", "System.Manager.removePackage"
        ]:
            self.tray.updateTrayUnread()

    def initializeStatusBar(self):
        self.cw.mainLayout.insertWidget(0, self.busy)
        self.statusBar().addPermanentWidget(self.cw.actions, 1)
        self.statusBar().show()

        self.updateStatusBar('')

        self.connect(self.cw, SIGNAL("selectionStatusChanged(QString)"),
                     self.updateStatusBar)
        self.connect(self.cw, SIGNAL("updatingStatus()"), self.statusWaiting)

    def initializeActions(self):
        self.toolBar().setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        KStandardAction.quit(KApplication.kApplication().quit,
                             self.actionCollection())
        KStandardAction.preferences(self.settingsDialog.show,
                                    self.actionCollection())
        self.setupGUI(
            KXmlGuiWindow.Default,
            "/usr/share/kde4/apps/package-manager/data/packagemanagerui.rc")
        self.initializeOperationActions()

    def initializeOperationActions(self):
        actionGroup = QtGui.QActionGroup(self)

        self.showAllAction = KToggleAction(KIcon("applications-other"),
                                           i18n("All Packages"), self)
        self.actionCollection().addAction("showAllAction", self.showAllAction)
        self.connect(self.showAllAction, SIGNAL("triggered()"),
                     lambda: self.cw.switchState(StateManager.ALL))
        self.cw.stateTab.addTab(QWidget(), KIcon("applications-other"),
                                i18n("All Packages"))
        actionGroup.addAction(self.showAllAction)

        self.showInstallAction = KToggleAction(KIcon("list-add"),
                                               i18n("Installable Packages"),
                                               self)
        self.actionCollection().addAction("showInstallAction",
                                          self.showInstallAction)
        self.connect(self.showInstallAction, SIGNAL("triggered()"),
                     lambda: self.cw.switchState(StateManager.INSTALL))
        self.cw.stateTab.addTab(QWidget(), KIcon("list-add"),
                                i18n("Installable Packages"))
        actionGroup.addAction(self.showInstallAction)

        self.showRemoveAction = KToggleAction(KIcon("list-remove"),
                                              i18n("Installed Packages"), self)
        self.actionCollection().addAction("showRemoveAction",
                                          self.showRemoveAction)
        self.connect(self.showRemoveAction, SIGNAL("triggered()"),
                     lambda: self.cw.switchState(StateManager.REMOVE))
        self.cw.stateTab.addTab(QWidget(), KIcon("list-remove"),
                                i18n("Installed Packages"))
        actionGroup.addAction(self.showRemoveAction)

        self.showUpgradeAction = KToggleAction(KIcon("system-software-update"),
                                               i18n("Updates"), self)
        self.actionCollection().addAction("showUpgradeAction",
                                          self.showUpgradeAction)
        self.connect(self.showUpgradeAction, SIGNAL("triggered()"),
                     lambda: self.cw.switchState(StateManager.UPGRADE))
        self.cw.stateTab.addTab(QWidget(), KIcon("system-software-update"),
                                i18n("Updates"))
        actionGroup.addAction(self.showUpgradeAction)

        # self.showHistoryAction = KToggleAction(KIcon("view-refresh"), i18n("History"), self)
        # self.actionCollection().addAction("showHistoryAction", self.showHistoryAction)
        # self.connect(self.showHistoryAction, SIGNAL("triggered()"), lambda:self.cw.switchState(StateManager.HISTORY))
        # self.cw.stateTab.addTab(QWidget(), KIcon("view-refresh"), i18n("History"))
        # actionGroup.addAction(self.showHistoryAction)

        self.cw.menuButton.setMenu(QMenu('MainMenu', self.cw.menuButton))
        self.cw.menuButton.setIcon(KIcon('preferences-other'))
        self.cw.menuButton.menu().clear()

        self.cw.contentHistory.hide()

        # self.cw.menuButton.menu().addAction(self.showAllAction)
        # self.cw.menuButton.menu().addAction(self.showInstallAction)
        # self.cw.menuButton.menu().addAction(self.showRemoveAction)
        # self.cw.menuButton.menu().addAction(self.showUpgradeAction)
        # self.cw.menuButton.menu().addSeparator()

        self.cw.menuButton.menu().addAction(self.actionCollection().action(
            KStandardAction.name(KStandardAction.Preferences)))
        self.cw.menuButton.menu().addAction(self.actionCollection().action(
            KStandardAction.name(KStandardAction.Help)))
        self.cw.menuButton.menu().addSeparator()
        self.cw.menuButton.menu().addAction(self.actionCollection().action(
            KStandardAction.name(KStandardAction.AboutApp)))
        self.cw.menuButton.menu().addAction(self.actionCollection().action(
            KStandardAction.name(KStandardAction.AboutKDE)))
        self.cw.menuButton.menu().addSeparator()
        self.cw.menuButton.menu().addAction(self.actionCollection().action(
            KStandardAction.name(KStandardAction.Quit)))

        self.cw._states = {
            self.cw.state.ALL: (0, self.showAllAction),
            self.cw.state.INSTALL: (1, self.showInstallAction),
            self.cw.state.REMOVE: (2, self.showRemoveAction),
            self.cw.state.UPGRADE: (3, self.showUpgradeAction)
        }
        #                  self.cw.state.HISTORY:(4, self.showHistoryAction)}

        self.showAllAction.setChecked(True)
        self.cw.checkUpdatesButton.hide()
        self.cw.checkUpdatesButton.setIcon(KIcon('view-refresh'))
        self.cw.showBasketButton.clicked.connect(self.cw.showBasket)

        # Little time left for the new ui
        self.menuBar().setVisible(False)
        self.cw.switchState(self.cw.state.ALL)

    def statusWaiting(self):
        self.updateStatusBar(i18n('Calculating dependencies...'), busy=True)

    def updateStatusBar(self, text, busy=False):
        if text == '':
            text = i18n("Currently your basket is empty.")
            self.busy.hide()
            self.cw.showBasketButton.hide()
        else:
            self.cw.showBasketButton.show()

        if busy:
            self.busy.busy()
            self.cw.showBasketButton.hide()
        else:
            self.busy.hide()

        self.cw.statusLabel.setText(text)

    def queryClose(self):
        if config.PMConfig().systemTray(
        ) and not KApplication.kApplication().sessionSaving():
            self.hide()
            return False
        return True

    def queryExit(self):
        if not self.iface.operationInProgress():
            if self.tray:
                del self.tray.notification
            return True
        return False

    def slotQuit(self):
        if self.iface.operationInProgress():
            return
class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, app = None):
        #QMainWindow.__init__(self, None)
        super(MainWindow, self).__init__(None)
        self.setupUi(self)

        self.app = app
        self.iface = backend.pm.Iface()

        self.busy = QProgressIndicator(self)
        self.busy.setFixedSize(QSize(20, 20))

        self.setWindowIcon(QIcon("/usr/share/package-manager/data/tray-zero.svg"))

        self.setCentralWidget(MainWidget(self))
        self.cw = self.centralWidget()

        self.settingsDialog = SettingsDialog(self)

        self.initializeActions()
        self.initializeStatusBar()
        self.initializeTray()
        self.connectMainSignals()

        self.pdsMessageBox = PMessageBox(self)
        

    def connectMainSignals(self):
        self.cw.connectMainSignals()
        
        move_shortcut=QShortcut(QKeySequence(Qt.CTRL + Qt.Key_Tab),self)
        move_shortcut.activated.connect(lambda: self.moveTab('next'))
        QShortcut(QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_Tab),self).activated.connect(lambda: self.moveTab('prev'))
        QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F),self).activated.connect(self.cw.searchLine.setFocus)
        QShortcut(QKeySequence(Qt.Key_F3),self).activated.connect(self.cw.searchLine.setFocus)

        self.settingsDialog.generalSettings.packagesChanged.connect(self.cw.initialize)
        self.settingsDialog.generalSettings.packageViewChanged.connect(self.cw.updateSettings)
        self.settingsDialog.generalSettings.traySettingChanged.connect(self.tray.settingsChanged)
        self.cw.state.repositoriesChanged.connect(self.tray.populateRepositoryMenu)
        self.cw.repositoriesUpdated.connect(self.tray.updateTrayUnread)
        

    def moveTab(self, direction):
        new_index = self.cw.stateTab.currentIndex() - 1
        if direction == 'next':
            new_index = self.cw.stateTab.currentIndex() + 1
        if new_index not in range(self.cw.stateTab.count()):
            new_index = 0
        self.cw.stateTab.setCurrentIndex(new_index)

    def initializeTray(self):
        self.tray = Tray(self, self.iface)
        self.cw.operation.finished[str].connect(self.trayAction)
        self.cw.operation.finished[str].connect(self.tray.stop)
        self.cw.operation.operationCancelled.connect(self.tray.stop)
        self.cw.operation.started[str].connect(self.tray.animate)
        self.tray.showUpdatesSelected.connect(self.trayShowUpdates)         # buraya dikkat

    def trayShowUpdates(self):
        self.showUpgradeAction.setChecked(True)

        self.cw.switchState(StateManager.UPGRADE)

        KApplication.kApplication().updateUserTimestamp()
       
        self.show()
        self.raise_()

    def trayAction(self, operation):
        if not self.isVisible() and operation in ["System.Manager.updateRepository", "System.Manager.updateAllRepositories"]:
            self.tray.showPopup()
        if self.tray.isVisible() and operation in ["System.Manager.updatePackage",
                                                   "System.Manager.installPackage",
                                                   "System.Manager.removePackage"]:
            self.tray.updateTrayUnread()

    def initializeStatusBar(self):
        self.cw.mainLayout.insertWidget(0, self.busy)
        self.statusBar().addPermanentWidget(self.cw.actions, 1)
        self.statusBar().show()

        self.updateStatusBar('')

        self.cw.selectionStatusChanged[str].connect(self.updateStatusBar)
        self.cw.updatingStatus.connect(self.statusWaiting)

    def initializeActions(self):
        self.initializeOperationActions()

    def initializeOperationActions(self):

        self.showAllAction = QAction(QIcon.fromTheme("media-optical"), _translate("Packaga Manager","All Packages"), self)
        self.showAllAction.triggered.connect(lambda:self.cw.switchState(StateManager.ALL))
        self.cw.stateTab.addTab(QWidget(), QIcon.fromTheme("media-optical"), _translate("Packaga Manager","All Packages"))

        self.showInstallAction = QAction(QIcon.fromTheme("list-remove"), _translate("Packaga Manager","Installable Packages"), self)
        self.showInstallAction.triggered.connect(lambda:self.cw.switchState(StateManager.INSTALL))
        self.cw.stateTab.addTab(QWidget(), QIcon.fromTheme("list-add"), _translate("Packaga Manager","Installable Packages"))

        self.showRemoveAction = QAction(QIcon.fromTheme("list-add"), _translate("Packaga Manager","Installed Packages"), self)
        self.showRemoveAction.triggered.connect(lambda:self.cw.switchState(StateManager.REMOVE))
        self.cw.stateTab.addTab(QWidget(), QIcon.fromTheme("list-remove"), _translate("Packaga Manager","Installed Packages"))

        self.showUpgradeAction = QAction(QIcon.fromTheme("system-software-update"), _translate("Packaga Manager","Updates"), self)
        self.showUpgradeAction.triggered.connect(lambda:self.cw.switchState(StateManager.UPGRADE))
        self.cw.stateTab.addTab(QWidget(), QIcon("/usr/share/package-manager/data/star_1.svg"), _translate("Packaga Manager","Updates"))

        self.showPreferences = QAction(QIcon.fromTheme("preferences-system"), _translate("Packaga Manager","Settings"), self)
        self.showPreferences.triggered.connect(self.settingsDialog.show_)

        self.actionHelp = QAction(QIcon.fromTheme("help-about"), _translate("Packaga Manager","Help"), self)
        self.actionHelp.setShortcuts(QKeySequence.HelpContents)
        self.actionHelp.triggered.connect(self.showHelp)

        self.actionQuit = QAction(QIcon.fromTheme("media-eject"), _translate("Packaga Manager","Quit"), self)
        self.actionQuit.setShortcuts(QKeySequence.Quit)
        self.actionQuit.triggered.connect(qApp.exit)

        self.cw.menuButton.setMenu(QMenu('MainMenu', self.cw.menuButton))
        self.cw.menuButton.setIcon(QIcon.fromTheme("preferences-system"))
        self.cw.menuButton.menu().clear()

        self.cw.contentHistory.hide()

        self.cw.menuButton.menu().addAction(self.showPreferences)
        self.cw.menuButton.menu().addSeparator()
        self.cw.menuButton.menu().addAction(self.actionHelp)
        self.cw.menuButton.menu().addAction(self.actionQuit)

        self.cw._states = {self.cw.state.ALL    :(0, self.showAllAction),
                           self.cw.state.INSTALL:(1, self.showInstallAction),
                           self.cw.state.REMOVE :(2, self.showRemoveAction),
                           self.cw.state.UPGRADE:(3, self.showUpgradeAction)}

        self.showAllAction.setChecked(True)
        self.cw.checkUpdatesButton.hide()
        self.cw.checkUpdatesButton.setIcon(QIcon.fromTheme("system-reboot"))
        self.cw.showBasketButton.clicked.connect(self.cw.showBasket)

        # Little time left for the new ui
        self.menuBar().setVisible(False)
        self.cw.switchState(self.cw.state.ALL)

    def statusWaiting(self):
        self.updateStatusBar(_translate("Packaga Manager",'Calculating dependencies...'), busy = True)

    def showHelp(self):
        self.Pds = pds.Pds()
        self.lang = localedata.setSystemLocale(justGet = True)
        
        if self.lang in os.listdir("/usr/share/package-manager/help"):
            pass
        else:
            self.lang = "en"

        
        if self.Pds.session == pds.Kde3 :
            os.popen("khelpcenter /usr/share/package-manager/help/%s/main_help.html" %(self.lang))
        else:
            helpdialog.HelpDialog(self,helpdialog.MAINAPP)


    def updateStatusBar(self, text, busy = False):
        if text == '':
            text = _translate("Packaga Manager","Currently your basket is empty.")
            self.busy.hide()
            self.cw.showBasketButton.hide()
        else:
            self.cw.showBasketButton.show()

        if busy:
            self.busy.busy()
            self.cw.showBasketButton.hide()
        else:
            self.busy.hide()

        self.cw.statusLabel.setText(text)
        self.cw.statusLabel.setToolTip(text)

    def queryClose(self):
        if config.PMConfig().systemTray():
            self.hide()
            return False
        return True

    def queryExit(self):
        if not self.iface.operationInProgress():
            if self.tray:
                del self.tray.notification
            return True
        return False

    def CloseEvent(self,event):
        if self.iface.operationInProgress():
            return
class ConnectionItem(QtWidgets.QWidget, Ui_ConnectionItem):

    def __init__(self, parent, connection):
        QtWidgets.QWidget.__init__(self, parent)
        self.setupUi(self)

        self.available = True
        self.parent = parent
        self.connection = connection

        bus = parent.bus.get_object(NM_BUS_NAME, str(connection.proxy.object_path))
        interface = dbus.Interface(bus, NM_SETTINGS_CONNECTION)

        interface.connect_to_signal("Removed", parent.fillConnections)
        interface.connect_to_signal("Updated", self.updateState)

        self.busy = QProgressIndicator(self)
        self.busy.setMinimumSize(QSize(32, 32))
        self.mainLayout.insertWidget(0, self.busy)
        self.busy.hide()

        self.connect(parent, SIGNAL("stateChanged()"), self.updateState)
        self.button.clicked.connect(lambda: self.parent.setState(self))

        self.updateState()
        self.toggleButtons()

    def updateState(self, *args):
        if self.available is not True:
            return

        active = self.parent.isActive(self.connection)

        if active:
            state = self.parent.getState(self.connection)
            if state == ActiveConnectionState.ACTIVATED.value:
                self.setIcon(get_icon(self.connection.settings.conn_type, True))
            elif state == ActiveConnectionState.ACTIVATING.value:
                self.showBusy()
        else:
            self.setIcon(get_icon(self.connection.settings.conn_type, False))

        self.name.setText(unicode(self.connection.settings.id))
        self.details.setText(unicode(self.connection.settings.conn_type))
        self.button.setText("Disconnect" if active else "Connect")

    def showBusy(self):
        self.busy.busy()
        self.icon.hide()

    def setIcon(self, icon):
        self.busy.hide()
        self.icon.setPixmap(icon)
        self.icon.show()

    def resizeEvent(self, event):
        if self.parent.msgbox:
            self.parent.msgbox._resizeCallBacks(event)

    def enterEvent(self, event):
        if not self.button.isVisible():
            self.toggleButtons(True)

    def leaveEvent(self, event):
        if self.button.isVisible():
            self.toggleButtons()

    def toggleButtons(self, toggle=False):
        self.button.setVisible(toggle)
class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, app=None):
        QMainWindow.__init__(self, None)
        self.setupUi(self)

        self.app = app
        self.iface = backend.pm.Iface()

        self.busy = QProgressIndicator(self)
        self.busy.setFixedSize(QSize(20, 20))

        self.setWindowIcon(QIcon(":/data/package-manager.png"))

        self.setCentralWidget(MainWidget(self))
        self.cw = self.centralWidget()

        self.settingsDialog = SettingsDialog(self)

        self.initializeActions()
        self.initializeStatusBar()
        self.initializeTray()
        self.connectMainSignals()

        self.pdsMessageBox = PMessageBox(self)

    def connectMainSignals(self):
        self.cw.connectMainSignals()
        self.connect(
            QShortcut(QKeySequence(Qt.CTRL + Qt.Key_Tab), self), SIGNAL("activated()"), lambda: self.moveTab("next")
        )
        self.connect(
            QShortcut(QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_Tab), self),
            SIGNAL("activated()"),
            lambda: self.moveTab("prev"),
        )
        self.connect(
            QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F), self), SIGNAL("activated()"), self.cw.searchLine.setFocus
        )
        self.connect(QShortcut(QKeySequence(Qt.Key_F3), self), SIGNAL("activated()"), self.cw.searchLine.setFocus)

        self.connect(self.settingsDialog, SIGNAL("packagesChanged()"), self.cw.initialize)
        self.connect(self.settingsDialog, SIGNAL("packageViewChanged()"), self.cw.updateSettings)
        self.connect(self.settingsDialog, SIGNAL("traySettingChanged()"), self.tray.settingsChanged)
        self.connect(self.cw.state, SIGNAL("repositoriesChanged()"), self.tray.populateRepositoryMenu)
        self.connect(self.cw, SIGNAL("repositoriesUpdated()"), self.tray.updateTrayUnread)
        self.connect(qApp, SIGNAL("shutDown()"), self.slotQuit)

    def moveTab(self, direction):
        new_index = self.cw.stateTab.currentIndex() - 1
        if direction == "next":
            new_index = self.cw.stateTab.currentIndex() + 1
        if new_index not in range(self.cw.stateTab.count()):
            new_index = 0
        self.cw.stateTab.setCurrentIndex(new_index)

    def initializeTray(self):
        self.tray = Tray(self, self.iface)
        self.connect(self.cw.operation, SIGNAL("finished(QString)"), self.trayAction)
        self.connect(self.cw.operation, SIGNAL("finished(QString)"), self.tray.stop)
        self.connect(self.cw.operation, SIGNAL("operationCancelled()"), self.tray.stop)
        self.connect(self.cw.operation, SIGNAL("started(QString)"), self.tray.animate)
        self.connect(self.tray, SIGNAL("showUpdatesSelected()"), self.trayShowUpdates)

    def trayShowUpdates(self):
        self.showUpgradeAction.setChecked(True)

        self.cw.switchState(StateManager.UPGRADE)

        KApplication.kApplication().updateUserTimestamp()

        self.show()
        self.raise_()

    def trayAction(self, operation):
        if not self.isVisible() and operation in [
            "System.Manager.updateRepository",
            "System.Manager.updateAllRepositories",
        ]:
            self.tray.showPopup()
        if self.tray.isVisible() and operation in [
            "System.Manager.updatePackage",
            "System.Manager.installPackage",
            "System.Manager.removePackage",
        ]:
            self.tray.updateTrayUnread()

    def initializeStatusBar(self):
        self.cw.mainLayout.insertWidget(0, self.busy)
        self.statusBar().addPermanentWidget(self.cw.actions, 1)
        self.statusBar().show()

        self.updateStatusBar("")

        self.connect(self.cw, SIGNAL("selectionStatusChanged(QString)"), self.updateStatusBar)
        self.connect(self.cw, SIGNAL("updatingStatus()"), self.statusWaiting)

    def initializeActions(self):
        self.initializeOperationActions()

    def initializeOperationActions(self):

        self.showAllAction = QAction(KIcon(("applications-other", "package_applications")), i18n("All Packages"), self)
        self.connect(self.showAllAction, SIGNAL("triggered()"), lambda: self.cw.switchState(StateManager.ALL))
        self.cw.stateTab.addTab(QWidget(), KIcon(("applications-other", "package_applications")), i18n("All Packages"))

        self.showInstallAction = QAction(KIcon(("list-add", "add")), i18n("Installable Packages"), self)
        self.connect(self.showInstallAction, SIGNAL("triggered()"), lambda: self.cw.switchState(StateManager.INSTALL))
        self.cw.stateTab.addTab(QWidget(), KIcon(("list-add", "add")), i18n("Installable Packages"))

        self.showRemoveAction = QAction(KIcon(("list-remove", "remove")), i18n("Installed Packages"), self)
        self.connect(self.showRemoveAction, SIGNAL("triggered()"), lambda: self.cw.switchState(StateManager.REMOVE))
        self.cw.stateTab.addTab(QWidget(), KIcon(("list-remove", "remove")), i18n("Installed Packages"))

        self.showUpgradeAction = QAction(KIcon(("system-software-update", "gear")), i18n("Updates"), self)
        self.connect(self.showUpgradeAction, SIGNAL("triggered()"), lambda: self.cw.switchState(StateManager.UPGRADE))
        self.cw.stateTab.addTab(QWidget(), KIcon(("system-software-update", "gear")), i18n("Updates"))

        self.showPreferences = QAction(KIcon(("preferences-system", "package_settings")), i18n("Settings"), self)
        self.connect(self.showPreferences, SIGNAL("triggered()"), self.settingsDialog.show)

        self.actionQuit = QAction(KIcon("exit"), i18n("Quit"), self)
        self.actionQuit.setShortcuts(QKeySequence.Quit)
        self.connect(self.actionQuit, SIGNAL("triggered()"), qApp.exit)

        self.cw.menuButton.setMenu(QMenu("MainMenu", self.cw.menuButton))
        self.cw.menuButton.setIcon(KIcon(("preferences-system", "package_settings")))
        self.cw.menuButton.menu().clear()

        self.cw.contentHistory.hide()

        self.cw.menuButton.menu().addAction(self.showPreferences)
        self.cw.menuButton.menu().addSeparator()
        self.cw.menuButton.menu().addAction(self.actionQuit)

        self.cw._states = {
            self.cw.state.ALL: (0, self.showAllAction),
            self.cw.state.INSTALL: (1, self.showInstallAction),
            self.cw.state.REMOVE: (2, self.showRemoveAction),
            self.cw.state.UPGRADE: (3, self.showUpgradeAction),
        }

        self.showAllAction.setChecked(True)
        self.cw.checkUpdatesButton.hide()
        self.cw.checkUpdatesButton.setIcon(KIcon(("view-refresh", "reload")))
        self.cw.showBasketButton.clicked.connect(self.cw.showBasket)

        # Little time left for the new ui
        self.menuBar().setVisible(False)
        self.cw.switchState(self.cw.state.ALL)

    def statusWaiting(self):
        self.updateStatusBar(i18n("Calculating dependencies..."), busy=True)

    def updateStatusBar(self, text, busy=False):
        if text == "":
            text = i18n("Currently your basket is empty.")
            self.busy.hide()
            self.cw.showBasketButton.hide()
        else:
            self.cw.showBasketButton.show()

        if busy:
            self.busy.busy()
            self.cw.showBasketButton.hide()
        else:
            self.busy.hide()

        self.cw.statusLabel.setText(text)
        self.cw.statusLabel.setToolTip(text)

    def queryClose(self):
        if config.PMConfig().systemTray():
            self.hide()
            return False
        return True

    def queryExit(self):
        if not self.iface.operationInProgress():
            if self.tray:
                del self.tray.notification
            return True
        return False

    def slotQuit(self):
        if self.iface.operationInProgress():
            return
Beispiel #11
0
class ConnectionItem(QtGui.QWidget, Ui_ConnectionItem):
    def __init__(self, parent, connection):
        QtGui.QWidget.__init__(self, parent)
        self.setupUi(self)

        self.available = True
        self.parent = parent
        self.connection = connection

        bus = parent.bus.get_object(NM_BUS_NAME,
                                    str(connection.proxy.object_path))
        interface = dbus.Interface(bus, NM_SETTINGS_CONNECTION)

        interface.connect_to_signal("Removed", parent.fillConnections)
        interface.connect_to_signal("Updated", self.updateState)

        self.busy = QProgressIndicator(self)
        self.busy.setMinimumSize(QSize(32, 32))
        self.mainLayout.insertWidget(0, self.busy)
        self.busy.hide()

        self.connect(parent, SIGNAL("stateChanged()"), self.updateState)
        self.button.clicked.connect(lambda: self.parent.setState(self))

        self.updateState()
        self.toggleButtons()

    def updateState(self, *args):
        if self.available is not True:
            return

        active = self.parent.isActive(self.connection)

        if active:
            state = self.parent.getState(self.connection)
            if state == ActiveConnectionState.ACTIVATED.value:
                self.setIcon(get_icon(self.connection.settings.conn_type,
                                      True))
            elif state == ActiveConnectionState.ACTIVATING.value:
                self.showBusy()
        else:
            self.setIcon(get_icon(self.connection.settings.conn_type, False))

        self.name.setText(unicode(self.connection.settings.id))
        self.details.setText(unicode(self.connection.settings.conn_type))
        self.button.setText("Disconnect" if active else "Connect")

    def showBusy(self):
        self.busy.busy()
        self.icon.hide()

    def setIcon(self, icon):
        self.busy.hide()
        self.icon.setPixmap(icon)
        self.icon.show()

    def resizeEvent(self, event):
        if self.parent.msgbox:
            self.parent.msgbox._resizeCallBacks(event)

    def enterEvent(self, event):
        if not self.button.isVisible():
            self.toggleButtons(True)

    def leaveEvent(self, event):
        if self.button.isVisible():
            self.toggleButtons()

    def toggleButtons(self, toggle=False):
        self.button.setVisible(toggle)