예제 #1
0
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
예제 #2
0
class Gui(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        
        self.setWindowTitle(cons.APP_TITLE)
        self.setWindowIcon(QIcon(os.path.join(cons.MEDIA_PATH, "misc", "ochd.ico")))
        self.resize(MIN_WIDTH, MIN_HEIGHT)
        self.center()
        
        self.restore_wnd_geometry()

        self.downloads = Downloads(self)
        self.add_downloads = AddDownloads(self)
        self.log = Log(self)
        
        self.stop = (QToolButton(), media.get_icon(media.STOP, media.MEDIUM), _('Stop Download'), self.on_stop_download, False)
        self.start = (QToolButton(), media.get_icon(media.START, media.MEDIUM), _('Start Download'), self.on_start_download, False)
        self.accounts = (QToolButton(), media.get_icon(media.ACCOUNTS, media.MEDIUM), _('Accounts'), self.on_accounts, True)
        self.preferences = (QToolButton(), media.get_icon(media.PREFERENCES, media.MEDIUM), _('Preferences'), self.on_preferences, True)
        self.about = (QToolButton(), media.get_icon(media.ABOUT, media.MEDIUM), _('About'), self.on_about, True)
        
        self.menu = QMenu()
        self.preferences[BTN].setPopupMode(QToolButton.MenuButtonPopup)
        self.preferences[BTN].setMenu(self.menu)
        
        self.toolbar = Toolbar(self, [self.start, self.stop, None, self.accounts, self.preferences, None, self.about])

        self.addToolBar(self.toolbar)

        #tabs
        self.previous_tab = None
        self.tab = QTabWidget()
        #
        self.tab.addTab(self.downloads, _('Downloads'))
        #
        self.tab_add_downloads = QWidget()
        self.tab_add_downloads.setLayout(self.add_downloads)
        self.tab.addTab(self.tab_add_downloads, _('Add downloads'))
        #
        #addons
        self.addons_manager = AddonsManager(self)
        self.addons_list = self.addons_manager.addons_list
        #...tabs
        self.addon_tab_widgets = []
        self.load_addon_tabs()
        #
        self.tab_log = QWidget()
        self.tab_log.setLayout(self.log)
        self.tab.addTab(self.tab_log, _('Log'))
        #
        self.preferences = Preferences(self.addons_list)
        #self.tab.addTab(self.preferences, 'Preferences')
        #
        self.tab.currentChanged.connect(self.on_tab_switch)
        #
        self.setCentralWidget(self.tab)

        #status bar
        self.status_bar = StatusBar(self)
        self.setStatusBar(self.status_bar)

        #drop down menu
        [addon.set_menu_item() for addon in self.addons_list]
        #self.menu.addSeparator()
        #self.menu.addAction('Preferences', self.on_preferences)

        #system tray icon
        self.tray = Tray(self)
        self.show_or_hide_tray()

        #load session.
        self.load_session()

        #add core's event loop
        self.dispatcher = ThreadDispatcher(self)
        self.dispatcher.start()

        #quit event
        events.quit.connect(self.event_close)

        #custom qt signals
        signals.switch_tab.connect(self.switch_tab)
        signals.show_or_hide_tray.connect(self.show_or_hide_tray)

        self.show()

    def customEvent(self, event):
        #process idle_queue_dispacher events
        event.callback()

    def switch_tab(self, index):
        self.tab.setCurrentIndex(index)

    def center(self):
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())
    
    def restore_wnd_geometry(self):
        wx, wy, ww, wh = QDesktopWidget().availableGeometry().getRect()
        x, y, w, h = conf.get_window_settings()
        if ww <= w or wh <= h:
            self.showMaximized()
        elif ww > x >= 0 and wh > y >= 0: #resize and move
            self.setGeometry(x, y, w, h)
        else: #resize only
            self.resize(w, h)

    def on_stop_download(self):
        rows = self.downloads.get_selected_rows()
        if rows:
            for row in rows:
                items = self.downloads.items
                id_item = items[row][0]
                stopped = api.stop_download(id_item)
                if stopped:
                    if items[row][1] == self.downloads.icons_dict[cons.STATUS_QUEUE]:
                        items[row][1] = self.downloads.icons_dict[cons.STATUS_STOPPED]
                    self.stop[BTN].setEnabled(False)
                    self.start[BTN].setEnabled(True)

    def on_start_download(self):
        rows = self.downloads.get_selected_rows()
        if rows:
            for row in rows:
                items = self.downloads.items
                id_item = items[row][0]
                started = api.start_download(id_item)
                if started:
                    items[row][1] = self.downloads.icons_dict[cons.STATUS_QUEUE] #status
                    items[row][10] = None #status_msg
                    self.stop[BTN].setEnabled(True)
                    self.start[BTN].setEnabled(False)
            id_item_list = [row[0] for row in items]
            api.reorder_queue(id_item_list)
    
    def on_accounts(self):
        accounts = ConfigAccounts(self)
    
    def on_preferences(self):
        index_page = self.tab.indexOf(self.preferences) #get the page containig the widget
        if index_page >= 0: #if = -1 there is not such tab.
            self.tab.setCurrentIndex(index_page)
        else:
            index_page = self.tab.addTab(self.preferences, _('Preferences'))
            btn_close = QPushButton(self)
            #btn_close.setIcon(QIcon('stop.png'))
            #btn_close.setIconSize(QSize(10, 10))
            btn_close.setFixedHeight(12)
            btn_close.setFixedWidth(12)
            #btn_close.setFlat(True)
            btn_close.clicked.connect(self.on_close_preferences)
            self.tab.tabBar().setTabButton(index_page, QTabBar.RightSide, btn_close)
            #
            last_index = self.tab.count() - 1
            self.tab.setCurrentIndex(last_index)
    
    def on_close_preferences(self):
        index_page = self.tab.indexOf(self.preferences)
        if index_page >= 0:
            self.tab.removeTab(index_page)
        #self.tab.setCurrentIndex(0)
    
    def on_about(self):
        about = About(self)
    
    def on_tab_switch(self, index):
        current_widget = self.tab.currentWidget()
        if current_widget == self.tab_log:
            self.log.on_load()
        elif current_widget in self.addon_tab_widgets:
            tab = current_widget.layout()
            tab.on_load()

        if self.previous_tab == self.preferences:
            self.previous_tab.on_close()
        elif self.previous_tab in self.addon_tab_widgets:
            tab = self.previous_tab.layout()
            tab.on_close()
        self.previous_tab = current_widget

    def show_or_hide_tray(self):
        if self.tray.is_available() and conf.get_tray_available():
            self.tray.show()
        else:
            self.tray.hide()

    def load_addon_tabs(self):
        for tab, addon in [(addon.get_tab(), addon) for addon in self.addons_list]:
            if tab is not None:
                tab_widget = QWidget()
                tab_widget.setLayout(tab)
                self.tab.addTab(tab_widget, addon.name)
                self.addon_tab_widgets.append(tab_widget)

    def load_session(self):
        """"""
        download_items = api.load_session()
        for download_item in download_items:
            self.downloads.store_item(download_item)
    
    def save_session(self):
        """"""
        id_item_list = [row[0] for row in self.downloads.items]
        api.save_session(id_item_list)
    
    def idle_timeout(self, interval, func):
        timer = QTimer()
        timer.timeout.connect(func)
        timer.start(interval)
        return timer

    def event_close(self):
        self.tray.hide()
        self.close()

    def closeEvent(self, event):
        # overridden
        if not self.tray.isVisible():
            x, y, w, h = self.geometry().getRect()
            self.hide()
            self.save_session()
            self.preferences.on_close()
            self.dispatcher.stop()
            conf.set_window_settings(x, y, w, h)
            conf.save()
            accounts_manager.save()
            event.accept()
        else:  # hide only
            self.hide()
            event.ignore()
예제 #3
0
파일: mainwindow.py 프로젝트: Tayyib/uludag
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
    def __init__(self, app = None, silence = False):
        QtGui.QMainWindow.__init__(self)
        self.setupUi(self)
        self.iface = backend.pm.Iface()
        self.setWindowIcon(QtGui.QIcon(":/data/package-manager.png"))
        self.connect(app, SIGNAL("aboutToQuit()"), self.slotQuit)
        self.setCentralWidget(MainWidget(self, silence))
        self.initializeActions()

        if not silence:
            self.settingsDialog = SettingsDialog(self)
            self.initializeStatusBar()
            self.initializeTray()
            self.connectMainSignals()

    def connectMainSignals(self):
        self.connect(self.settingsDialog, SIGNAL("packagesChanged()"), self.centralWidget().initialize)
        self.connect(self.settingsDialog, SIGNAL("packageViewChanged()"), self.centralWidget().updateSettings)
        self.connect(self.settingsDialog, SIGNAL("traySettingChanged()"), self.tray.settingsChanged)
        self.connect(self.centralWidget().state, SIGNAL("repositoriesChanged()"), self.tray.populateRepositoryMenu)

    def initializeTray(self):
        self.tray = Tray(self, self.iface)
        self.connect(self.centralWidget().operation, SIGNAL("finished(QString)"), self.trayAction)
        self.connect(self.tray, SIGNAL("showUpdatesSelected()"), self.trayShowUpdates)

    def trayShowUpdates(self):
        self.showUpgradeAction.setChecked(True)
        self.centralWidget().switchState(StateManager.UPGRADE, action=False)
        self.centralWidget().initialize()
        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.statusLabel = QtGui.QLabel(i18n("Currently your basket is empty."), self.statusBar())
        self.statusLabel.setAlignment(QtCore.Qt.AlignCenter)
        self.statusBar().addWidget(self.statusLabel)
        self.statusBar().setSizeGripEnabled(True)
        self.wheelMovie = QtGui.QMovie(self)
        self.statusLabel.setText(i18n("Currently your basket is empty."))
        self.wheelMovie.setFileName(":/data/wheel.mng")
        self.connect(self.centralWidget(), SIGNAL("selectionStatusChanged(QString)"), self.updateStatusBar)
        self.connect(self.centralWidget(), SIGNAL("updatingStatus()"), self.statusWaiting)

    def initializeActions(self):
        self.toolBar = QtGui.QToolBar(self)
        self.toolBar.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
        self.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)

        self.initializeOperationActions()

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

        self.menubar = QtGui.QMenuBar(self)

        self.menuFile = QtGui.QMenu(i18n('File'), self.menubar)
        self.menuOptions = QtGui.QMenu(i18n('Settings'), self.menubar)
        self.menuHelp = QtGui.QMenu(i18n('Help'), self.menubar)

        self.quitAppAction = QtGui.QAction(KIcon(('exit', 'application-exit')), i18n("Quit"), self)
        self.quitAppAction.setShortcut(QtGui.QKeySequence('Ctrl+q'))
        self.quitAppAction.triggered.connect(self.slotQuit)

        self.helpAppAction = QtGui.QAction(KIcon(('help', 'help-contents')), i18n("Help"), self)
        self.helpAppAction.setShortcut(QtGui.QKeySequence('F1'))
        self.helpAppAction.triggered.connect(self.showHelp)
        self.menuHelp.addAction(self.helpAppAction)

        self.setMenuBar(self.menubar)

        # Action Show Installable Packages
        self.showInstallAction = QtGui.QAction(KIcon("list-add"),
                          i18n("Show Installable Packages"), self)
        self.showInstallAction.setCheckable(True)
        self.showInstallAction.setChecked(True)
        self.showInstallAction.triggered.connect(lambda:self.centralWidget().switchState(StateManager.INSTALL))
        actionGroup.addAction(self.showInstallAction)
        self.toolBar.addAction(self.showInstallAction)
        self.menuFile.addAction(self.showInstallAction)

        # Action Show Installed Packages
        self.showRemoveAction = QtGui.QAction(KIcon("list-remove"),
                          i18n("Show Installed Packages"), self)
        self.showRemoveAction.setCheckable(True)
        self.showRemoveAction.triggered.connect(lambda:self.centralWidget().switchState(StateManager.REMOVE))
        actionGroup.addAction(self.showRemoveAction)
        self.toolBar.addAction(self.showRemoveAction)
        self.menuFile.addAction(self.showRemoveAction)

        # Action Show Upgradable Packages
        self.showUpgradeAction = QtGui.QAction(KIcon("view-refresh"),
                          i18n("Show Upgradable Packages"), self)
        self.showUpgradeAction.setCheckable(True)
        self.showUpgradeAction.triggered.connect(lambda:self.centralWidget().switchState(StateManager.UPGRADE))
        actionGroup.addAction(self.showUpgradeAction)
        self.toolBar.addAction(self.showUpgradeAction)
        self.menuFile.addAction(self.showUpgradeAction)
        self.menuFile.addSeparator()
        self.menuFile.addAction(self.quitAppAction)

        self.showSettingsAction = QtGui.QAction(KIcon("preferences-system"),
                          i18n("Package Manager Settings"), self)
        self.showSettingsAction.triggered.connect(self.showSettingsDialog)
        self.menuOptions.addAction(self.showSettingsAction)

        self.menubar.addAction(self.menuFile.menuAction())
        self.menubar.addAction(self.menuOptions.menuAction())
        self.menubar.addAction(self.menuHelp.menuAction())

    def showSettingsDialog(self):
        self.settingsDialog.show()

    def statusWaiting(self):
        self.statusLabel.setMovie(self.wheelMovie)
        self.wheelMovie.start()

    def updateStatusBar(self, text):
        self.wheelMovie.stop()
        self.statusLabel.setText(text)

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

    def showHelp(self):
        helpDialog = helpdialog.HelpDialog(self, helpdialog.MAINAPP)
        helpDialog.show()

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

    def slotQuit(self):
        if self.iface.operationInProgress():
            return
        QtCore.QCoreApplication.quit()
예제 #4
0
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
예제 #5
0
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
예제 #6
0
class Gui(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.setWindowTitle(cons.APP_TITLE)
        self.setWindowIcon(
            QIcon(os.path.join(cons.MEDIA_PATH, "misc", "ochd.ico")))
        self.resize(MIN_WIDTH, MIN_HEIGHT)
        self.center()

        self.restore_wnd_geometry()

        self.downloads = Downloads(self)
        self.add_downloads = AddDownloads(self)
        self.log = Log(self)

        self.stop = (QToolButton(), media.get_icon(media.STOP, media.MEDIUM),
                     _('Stop Download'), self.on_stop_download, False)
        self.start = (QToolButton(), media.get_icon(media.START, media.MEDIUM),
                      _('Start Download'), self.on_start_download, False)
        self.accounts = (QToolButton(),
                         media.get_icon(media.ACCOUNTS, media.MEDIUM),
                         _('Accounts'), self.on_accounts, True)
        self.preferences = (QToolButton(),
                            media.get_icon(media.PREFERENCES, media.MEDIUM),
                            _('Preferences'), self.on_preferences, True)
        self.about = (QToolButton(), media.get_icon(media.ABOUT, media.MEDIUM),
                      _('About'), self.on_about, True)

        self.menu = QMenu()
        self.preferences[BTN].setPopupMode(QToolButton.MenuButtonPopup)
        self.preferences[BTN].setMenu(self.menu)

        self.toolbar = Toolbar(self, [
            self.start, self.stop, None, self.accounts, self.preferences, None,
            self.about
        ])

        self.addToolBar(self.toolbar)

        #tabs
        self.previous_tab = None
        self.tab = QTabWidget()
        #
        self.tab.addTab(self.downloads, _('Downloads'))
        #
        self.tab_add_downloads = QWidget()
        self.tab_add_downloads.setLayout(self.add_downloads)
        self.tab.addTab(self.tab_add_downloads, _('Add downloads'))
        #
        #addons
        self.addons_manager = AddonsManager(self)
        self.addons_list = self.addons_manager.addons_list
        #...tabs
        self.addon_tab_widgets = []
        self.load_addon_tabs()
        #
        self.tab_log = QWidget()
        self.tab_log.setLayout(self.log)
        self.tab.addTab(self.tab_log, _('Log'))
        #
        self.preferences = Preferences(self.addons_list)
        #self.tab.addTab(self.preferences, 'Preferences')
        #
        self.tab.currentChanged.connect(self.on_tab_switch)
        #
        self.setCentralWidget(self.tab)

        #status bar
        self.status_bar = StatusBar(self)
        self.setStatusBar(self.status_bar)

        #drop down menu
        [addon.set_menu_item() for addon in self.addons_list]
        #self.menu.addSeparator()
        #self.menu.addAction('Preferences', self.on_preferences)

        #system tray icon
        self.tray = Tray(self)
        self.show_or_hide_tray()

        #load session.
        self.load_session()

        #add core's event loop
        self.dispatcher = ThreadDispatcher(self)
        self.dispatcher.start()

        #quit event
        events.quit.connect(self.event_close)

        #custom qt signals
        signals.switch_tab.connect(self.switch_tab)
        signals.show_or_hide_tray.connect(self.show_or_hide_tray)

        self.show()

    def customEvent(self, event):
        #process idle_queue_dispacher events
        event.callback()

    def switch_tab(self, index):
        self.tab.setCurrentIndex(index)

    def center(self):
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())

    def restore_wnd_geometry(self):
        wx, wy, ww, wh = QDesktopWidget().availableGeometry().getRect()
        x, y, w, h = conf.get_window_settings()
        if ww <= w or wh <= h:
            self.showMaximized()
        elif ww > x >= 0 and wh > y >= 0:  #resize and move
            self.setGeometry(x, y, w, h)
        else:  #resize only
            self.resize(w, h)

    def on_stop_download(self):
        rows = self.downloads.get_selected_rows()
        if rows:
            for row in rows:
                items = self.downloads.items
                id_item = items[row][0]
                stopped = api.stop_download(id_item)
                if stopped:
                    if items[row][1] == self.downloads.icons_dict[
                            cons.STATUS_QUEUE]:
                        items[row][1] = self.downloads.icons_dict[
                            cons.STATUS_STOPPED]
                    self.stop[BTN].setEnabled(False)
                    self.start[BTN].setEnabled(True)

    def on_start_download(self):
        rows = self.downloads.get_selected_rows()
        if rows:
            for row in rows:
                items = self.downloads.items
                id_item = items[row][0]
                started = api.start_download(id_item)
                if started:
                    items[row][1] = self.downloads.icons_dict[
                        cons.STATUS_QUEUE]  #status
                    items[row][10] = None  #status_msg
                    self.stop[BTN].setEnabled(True)
                    self.start[BTN].setEnabled(False)
            id_item_list = [row[0] for row in items]
            api.reorder_queue(id_item_list)

    def on_accounts(self):
        accounts = ConfigAccounts(self)

    def on_preferences(self):
        index_page = self.tab.indexOf(
            self.preferences)  #get the page containig the widget
        if index_page >= 0:  #if = -1 there is not such tab.
            self.tab.setCurrentIndex(index_page)
        else:
            index_page = self.tab.addTab(self.preferences, _('Preferences'))
            btn_close = QPushButton(self)
            #btn_close.setIcon(QIcon('stop.png'))
            #btn_close.setIconSize(QSize(10, 10))
            btn_close.setFixedHeight(12)
            btn_close.setFixedWidth(12)
            #btn_close.setFlat(True)
            btn_close.clicked.connect(self.on_close_preferences)
            self.tab.tabBar().setTabButton(index_page, QTabBar.RightSide,
                                           btn_close)
            #
            last_index = self.tab.count() - 1
            self.tab.setCurrentIndex(last_index)

    def on_close_preferences(self):
        index_page = self.tab.indexOf(self.preferences)
        if index_page >= 0:
            self.tab.removeTab(index_page)
        #self.tab.setCurrentIndex(0)

    def on_about(self):
        about = About(self)

    def on_tab_switch(self, index):
        current_widget = self.tab.currentWidget()
        if current_widget == self.tab_log:
            self.log.on_load()
        elif current_widget in self.addon_tab_widgets:
            tab = current_widget.layout()
            tab.on_load()

        if self.previous_tab == self.preferences:
            self.previous_tab.on_close()
        elif self.previous_tab in self.addon_tab_widgets:
            tab = self.previous_tab.layout()
            tab.on_close()
        self.previous_tab = current_widget

    def show_or_hide_tray(self):
        if self.tray.is_available() and conf.get_tray_available():
            self.tray.show()
        else:
            self.tray.hide()

    def load_addon_tabs(self):
        for tab, addon in [(addon.get_tab(), addon)
                           for addon in self.addons_list]:
            if tab is not None:
                tab_widget = QWidget()
                tab_widget.setLayout(tab)
                self.tab.addTab(tab_widget, addon.name)
                self.addon_tab_widgets.append(tab_widget)

    def load_session(self):
        """"""
        download_items = api.load_session()
        for download_item in download_items:
            self.downloads.store_item(download_item)

    def save_session(self):
        """"""
        id_item_list = [row[0] for row in self.downloads.items]
        api.save_session(id_item_list)

    def idle_timeout(self, interval, func):
        timer = QTimer()
        timer.timeout.connect(func)
        timer.start(interval)
        return timer

    def event_close(self):
        self.tray.hide()
        self.close()

    def closeEvent(self, event):
        # overridden
        if not self.tray.isVisible():
            x, y, w, h = self.geometry().getRect()
            self.hide()
            self.save_session()
            self.preferences.on_close()
            self.dispatcher.stop()
            conf.set_window_settings(x, y, w, h)
            conf.save()
            accounts_manager.save()
            event.accept()
        else:  # hide only
            self.hide()
            event.ignore()
예제 #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()
        _time()
        self.setWindowIcon(KIcon(":/data/package-manager.png"))
        self.setCentralWidget(MainWidget(self))
        self.settingsDialog = SettingsDialog(self)
        self.initializeActions()
        self.initializeStatusBar()
        self.initializeTray()
        self.connectMainSignals()
        _time()

    def resizeEvent(self, event):
        # info label should be resized automatically,
        # if the mainwindow resized.
        width = self.width()
        height = self.statusBar().height() + 4
        self.statusLabel.resize(QSize(width, height))
        self.statusLabel.move(0, self.height() - height + 2)#self.width() / 2 - 170, self.height() / 2 - 40)

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

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

    def trayShowUpdates(self):
        self.showUpgradeAction.setChecked(True)
        self.centralWidget().switchState(StateManager.UPGRADE, action=False)
        self.centralWidget().initialize()
        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):

        # An info label to show a proper information,
        # if there is no updates available.
        self.statusLabel = QLabel(i18n("Currently your basket is empty."), self)
        self.statusLabel.setAlignment(Qt.AlignVCenter | Qt.AlignLeft)
        self.statusLabel.setStyleSheet("background-color:rgba(0,0,0,220); \
                                 color:white; \
                                 border: 1px solid white;")
        # self.info.hide()
        self.statusLabel.show()
        self.wheelMovie = QtGui.QMovie(self)
        self.statusLabel.setText(i18n("Currently your basket is empty."))
        self.wheelMovie.setFileName(":/data/wheel.mng")
        self.connect(self.centralWidget(), SIGNAL("selectionStatusChanged(QString)"), self.updateStatusBar)
        self.connect(self.centralWidget(), 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.initializeOperationActions()
        self.setupGUI(KXmlGuiWindow.Default, "/usr/share/package-manager/data/packagemanagerui.rc")

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

        self.showInstallAction = KToggleAction(KIcon("list-add"), i18n("Show Installable Packages"), self)
        self.showInstallAction.setChecked(True)
        self.actionCollection().addAction("showInstallAction", self.showInstallAction)
        self.connect(self.showInstallAction, SIGNAL("triggered()"), lambda:self.centralWidget().switchState(StateManager.INSTALL))
        actionGroup.addAction(self.showInstallAction)

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

        self.showUpgradeAction = KToggleAction(KIcon("view-refresh"), i18n("Show Upgradable Packages"), self)
        self.actionCollection().addAction("showUpgradeAction", self.showUpgradeAction)
        self.connect(self.showUpgradeAction, SIGNAL("triggered()"), lambda:self.centralWidget().switchState(StateManager.UPGRADE))
        actionGroup.addAction(self.showUpgradeAction)

    def statusWaiting(self):
        self.statusLabel.setMovie(self.wheelMovie)
        self.wheelMovie.start()

    def updateStatusBar(self, text):
        self.wheelMovie.stop()
        self.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
예제 #8
0
파일: mainwindow.py 프로젝트: Tayyib/uludag
class MainWindow(KXmlGuiWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        KXmlGuiWindow.__init__(self, parent)
        self.setupUi(self)
        self.iface = backend.pm.Iface()
        self.setWindowIcon(KIcon(":/data/package-manager.png"))
        self.setCentralWidget(MainWidget(self))
        self.settingsDialog = SettingsDialog(self)
        self.initializeActions()
        self.initializeStatusBar()
        self.initializeTray()
        self.connectMainSignals()

    def connectMainSignals(self):
        self.connect(self.settingsDialog, SIGNAL("packagesChanged()"), self.centralWidget().initialize)
        self.connect(self.settingsDialog, SIGNAL("traySettingChanged()"), self.tray.settingsChanged)
        self.connect(self.centralWidget().state, SIGNAL("repositoriesChanged()"), self.tray.populateRepositoryMenu)
        self.connect(KApplication.kApplication(), SIGNAL("shutDown()"), self.slotQuit)

    def initializeTray(self):
        self.tray = Tray(self)
        self.connect(self.centralWidget().operation, SIGNAL("finished(QString)"), self.trayAction)
        self.connect(self.tray, SIGNAL("showUpdatesSelected()"), self.trayShowUpdates)

    def trayShowUpdates(self):
        self.showUpgradeAction.setChecked(True)
        self.centralWidget().switchState(StateManager.UPGRADE, action=False)
        self.centralWidget().initialize()
        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.statusLabel = QtGui.QLabel(i18n("Currently your basket is empty."), self.statusBar())
        self.statusLabel.setAlignment(Qt.AlignCenter)
        self.statusBar().addWidget(self.statusLabel)
        self.statusBar().setSizeGripEnabled(True)
        self.wheelMovie = QtGui.QMovie(self)
        self.statusLabel.setText(i18n("Currently your basket is empty."))
        self.wheelMovie.setFileName(":/data/wheel.mng")
        self.connect(self.centralWidget(), SIGNAL("selectionStatusChanged(QString)"), self.updateStatusBar)
        self.connect(self.centralWidget(), 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.initializeOperationActions()
        self.setupGUI(KXmlGuiWindow.Default, "data/packagemanagerui.rc")

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

        self.showInstallAction = KToggleAction(KIcon("list-add"), i18n("Show Installable Packages"), self)
        self.showInstallAction.setChecked(True)
        self.actionCollection().addAction("showInstallAction", self.showInstallAction)
        self.connect(self.showInstallAction, SIGNAL("triggered()"), lambda:self.centralWidget().switchState(StateManager.INSTALL))
        self.connect(self.showInstallAction, SIGNAL("triggered()"), self.centralWidget().initialize)
        actionGroup.addAction(self.showInstallAction)

        self.showRemoveAction = KToggleAction(KIcon("list-remove"), i18n("Show Installed Packages"), self)
        self.actionCollection().addAction("showRemoveAction", self.showRemoveAction)
        self.connect(self.showRemoveAction, SIGNAL("triggered()"), lambda:self.centralWidget().switchState(StateManager.REMOVE))
        self.connect(self.showRemoveAction, SIGNAL("triggered()"), self.centralWidget().initialize)
        actionGroup.addAction(self.showRemoveAction)

        self.showUpgradeAction = KToggleAction(KIcon("view-refresh"), i18n("Show Upgradable Packages"), self)
        self.actionCollection().addAction("showUpgradeAction", self.showUpgradeAction)
        self.connect(self.showUpgradeAction, SIGNAL("triggered()"), lambda:self.centralWidget().switchState(StateManager.UPGRADE))
        actionGroup.addAction(self.showUpgradeAction)

    def statusWaiting(self):
        self.statusLabel.setMovie(self.wheelMovie)
        self.wheelMovie.start()

    def updateStatusBar(self, text):
        self.wheelMovie.stop()
        self.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.notification:
                self.tray.notification.close()
            return True
        return False

    def slotQuit(self):
        if self.iface.operationInProgress():
            return