Exemplo n.º 1
0
    def __init__(self):
        # Check if script is running
        self.scriptDir = abspath(dirname(__file__))
        self.filesDir = join(self.scriptDir, "files")
        self.scriptName = basename(__file__)
        self.umglobal = UmGlobal()
        self.ec = ExecCmd()

        # Handle arguments
        parser = argparse.ArgumentParser(
            description='Trail Update Manager Tray')
        parser.add_argument('-r', '--reload', action="store_true", help='')
        args, extra = parser.parse_known_args()

        print((">> args = {}".format(args)))
        if args.reload:
            pids = self.umglobal.getScriptPids("updatemanagertray.py")
            if len(pids) > 1:
                print(("updatemanagertray.py already running - kill pid {}".
                       format(pids[0])))
                os.system("kill {}".format(pids[0]))

        # Build status icon menu
        self.refreshText = _("Refresh")
        self.quitText = _("Quit")
        menu = Gtk.Menu()
        menuUm = Gtk.MenuItem(_("Update Manager"))
        menuUm.connect('activate', self.open_um)
        menu.append(menuUm)
        # Separator not functioning in wheezy
        #menuSep1 = Gtk.SeparatorMenuItem()
        #menu.append(menuSep1)
        menuPref = Gtk.MenuItem(_("Preferences"))
        menuPref.connect('activate', self.open_preferences)
        menu.append(menuPref)
        menuRefresh = Gtk.MenuItem(self.refreshText)
        menuRefresh.connect('activate', self.manualRefresh)
        menu.append(menuRefresh)
        menuQuit = Gtk.MenuItem(self.quitText)
        menuQuit.connect('activate', self.quit_tray)
        menu.append(menuQuit)

        self.statusIcon = Gtk.StatusIcon()
        self.umrefresh = UmRefresh(self.statusIcon, self.umglobal)
        self.notifier = UmNotifier(self.statusIcon, self.umglobal,
                                   self.umrefresh)

        self.statusIcon.connect('activate', self.icon_activate)
        self.statusIcon.connect('popup-menu', self.popup_menu, menu)

        # Initiate first check
        self.refresh()

        # Loop the refresh function
        # For some reason you cannot start a threaded class from init
        self.timeout = int(self.umglobal.settings["hrs-check-status"] * 60 *
                           60)
        GObject.timeout_add_seconds(self.timeout, self.refresh)
Exemplo n.º 2
0
    def __init__(self):
        # Check if script is running
        self.scriptName = basename(__file__)
        self.umglobal = UmGlobal()
        self.ec = ExecCmd()
        self.status = AppIndicator3.IndicatorStatus

        # Load window and widgets
        self.builder = Gtk.Builder()
        self.builder.add_from_file(
            join(self.umglobal.shareDir, 'updatemanagerlegend.glade'))
        go = self.builder.get_object
        # Main window objects
        self.legend = go("windowLegenda")
        go("imgConnected").set_from_file(
            join(self.umglobal.iconsDir,
                 self.umglobal.settings["icon-connected"]))
        go("imgDisconnected").set_from_file(
            join(self.umglobal.iconsDir,
                 self.umglobal.settings["icon-disconnected"]))
        go("imgError").set_from_file(
            join(self.umglobal.iconsDir, self.umglobal.settings["icon-error"]))
        go("imgExecute").set_from_file(
            join(self.umglobal.iconsDir,
                 self.umglobal.settings["icon-execute"]))
        go("imgUpdates").set_from_file(
            join(self.umglobal.iconsDir,
                 self.umglobal.settings["icon-updates"]))
        go("imgWarning").set_from_file(
            join(self.umglobal.iconsDir,
                 self.umglobal.settings["icon-warning"]))
        go("lblConnected").set_label(self.umglobal.connectedText)
        go("lblDisconnected").set_label(self.umglobal.disconnectedText)
        go("lblExecute").set_label(self.umglobal.executeText)
        self.lblError = go("lblError")
        self.lblWarning = go("lblWarning")
        self.lblUpdates = go("lblUpdates")
        self.builder.connect_signals(self)

        # Handle arguments
        parser = argparse.ArgumentParser(
            description='SolydXK Update Manager Tray')
        parser.add_argument('-r', '--reload', action="store_true", help='')
        args, extra = parser.parse_known_args()

        #print((">> args = {}".format(args)))
        if args.reload:
            pids = self.umglobal.getProcessPids("updatemanagertray.py")
            if len(pids) > 1:
                print(("updatemanagertray.py already running - kill pid {}".
                       format(pids[0])))
                os.system("kill {}".format(pids[0]))

        # Build status icon menu
        self.quitText = _("Quit")
        menu = Gtk.Menu()
        menuUm = Gtk.MenuItem(self.umglobal.title)
        menuUm.connect('activate', self.open_um)
        menu.append(menuUm)
        # Separator not functioning in wheezy
        menuSep1 = Gtk.SeparatorMenuItem()
        menu.append(menuSep1)
        menuQupd = Gtk.MenuItem(_("Quick Update"))
        menuQupd.connect('activate', self.quick_update)
        menu.append(menuQupd)
        menuSep2 = Gtk.SeparatorMenuItem()
        menu.append(menuSep2)
        menuPref = Gtk.MenuItem(_("Preferences"))
        menuPref.connect('activate', self.open_preferences)
        menu.append(menuPref)
        menuLegend = Gtk.MenuItem(_("Legend"))
        menuLegend.connect('activate', self.open_legend)
        menu.append(menuLegend)
        menuQuit = Gtk.MenuItem(self.quitText)
        menuQuit.connect('activate', self.quit_tray)
        menu.append(menuQuit)
        menu.show_all()

        if self.umglobal.isKf5:
            print(("> Running KDE5"))
            # Use this for KDE5
            self.indicator = AppIndicator3.Indicator.new_with_path(
                "updatemanager", self.umglobal.settings["icon-connected"],
                AppIndicator3.IndicatorCategory.SYSTEM_SERVICES,
                self.umglobal.iconsDir)
            # Title not showing in KDE4
            self.indicator.set_title("<strong>{}</strong>".format(
                self.umglobal.title))
            self.indicator.set_secondary_activate_target(menuUm)
            self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
            self.indicator.set_menu(menu)
        else:
            print(("> Running KDE4"))
            # Use this for KDE4
            self.indicator = Gtk.StatusIcon()
            #self.indicator.connect('activate', self.open_um)
            self.indicator.connect('popup-menu', self.popup_menu, menu)

        self.umrefresh = UmRefresh(self.umglobal, self.indicator)
        self.notifier = UmNotifier(self.umrefresh)

        # Initiate first check
        self.refresh()