Beispiel #1
0
    def __init__(self):
        self.DEBUG = DEBUG
        import gettext  #this is for the glade files
        self.glade_gettext = gettext.textdomain("specto")
        self.logger = Logger(self)
        self.check_instance()  #see if specto is already running
        self.util = util
        self.PATH = self.util.get_path()
        self.specto_gconf = specto_gconf
        self.check_default_settings(
        )  #if this is the first run of specto, set the default values for gconf. Whenever you add some gconf preference for specto, this function will also need to be updated.
        self.GTK = GTK
        if GTK:
            self.tray = Tray(self)
            self.icon_theme = gtk.icon_theme_get_default()
        self.watch_db = {}
        self.watch_io = Watch_io()
        watch_value_db = self.watch_io.read_options()
        self.preferences_initialized = False
        self.notifier_initialized = False
        #listen for gconf keys
        self.specto_gconf.notify_entry("debug_mode", self.key_changed, "debug")

        self.connection_manager = conmgr.get_net_listener()

        if GTK:
            if self.specto_gconf.get_entry("always_show_icon") == False:
                #if the user has not requested the tray icon to be shown at all times, it's impossible that the notifier is hidden on startup, so we must show it.
                self.notifier_keep_hidden = False
                self.toggle_notifier()
            elif self.specto_gconf.get_entry("show_notifier") == True:
                self.notifier_keep_hidden = False
                self.toggle_notifier()
            elif self.specto_gconf.get_entry("show_notifier") == False:
                self.notifier_keep_hidden = True
                self.toggle_notifier()
                self.notifier_keep_hidden = False
            else:  #just in case the entry was never created in gconf
                self.notifier_keep_hidden = False
                self.toggle_notifier()

        self.create_all_watches(watch_value_db)

        if GTK:
            gtk.main()
        else:
            self.go = gobject.MainLoop()
            self.go.run()
Beispiel #2
0
    def __init__(self):
        self.DEBUG = DEBUG
        self.util = util

        self.PATH = self.util.get_path()
        self.LOGO_PATH = os.path.join(self.PATH, "icons/specto.svg")
        self.SRC_PATH = self.util.get_path("src")
        self.SPECTO_DIR = self.util.get_path("specto")
        self.CACHE_DIR = self.util.get_path("tmp")
        self.FILE = self.util.get_file()

        self.logger = Logger(self)

        self.VERSION = VERSION  # The Specto version number

        self.GTK = GTK
        if not self.check_instance():  #see if specto is already running
            self.specto_gconf = specto_gconf
            self.check_default_settings()

            self.connection_manager = conmgr.get_net_listener()
            self.use_keyring = self.specto_gconf.get_entry("use_keyring")

            #create the watch collection and add the watches
            self.watch_db = Watch_collection(self)
            self.watch_io = Watch_io(self, self.FILE)

            if (sys.argv[1:]
                    and "--console" in sys.argv[1:][0]) or not self.GTK:
                self.logger.log(_("Console mode enabled."), "debug", "specto")
                self.GTK = False
                self.CONSOLE = True
                try:
                    args = sys.argv[1:][1]
                except:
                    args = ""
                self.console = Console(self, args)

            elif self.GTK:
                self.GTK = True
                self.CONSOLE = False
                self.icon_theme = gtk.icon_theme_get_default()

                #allow users to hide the window on startup
                if sys.argv[1:] and "--no-window" in sys.argv[1:][0]:
                    self.notifier_hide = True
                #always show if there's no icon and no indicator support
                elif self.specto_gconf.get_entry(
                        "always_show_icon") == False and not INDICATOR:
                    self.notifier_hide = False
                elif self.specto_gconf.get_entry("show_notifier") == True:
                    self.notifier_hide = False
                elif self.specto_gconf.get_entry("show_notifier") == False:
                    self.notifier_hide = True
                else:  #just in case the entry was never created in gconf
                    self.notifier_keep_hidden = False

                self.notifier = Notifier(self)
            else:
                sys.exit(0)

            #listen for gconf keys
            self.specto_gconf.notify_entry("debug_mode", self.key_changed,
                                           "debug")

            values = self.watch_io.read_all_watches(True)
            try:
                self.watch_db.create(values)
            except AttributeError as error_fields:
                self.logger.log(_("Could not create a watch, because it is corrupt."), \
                                    "critical", "specto")

            if self.GTK:
                for watch in self.watch_db:
                    self.notifier.add_notifier_entry(watch.id)

                # Listen for USR1. If received, answer and show the window
                def listen_for_USR1(signum, frame):
                    f = open(self.SPECTO_DIR + "/" + "specto.pid.boot")
                    pid = int(f.readline())
                    f.close()
                    os.kill(pid, signal.SIGUSR1)
                    # If window was not shown, make it appear
                    if not self.notifier.get_state():
                        self.logger.log(
                            "Showing window, the user ran another instance of specto",
                            "debug", "specto")
                        self.toggle_notifier()
                    else:
                        # Based on http://www.pygtk.org/docs/pygtk/class-gtkwindow.html#method-gtkwindow--present
                        self.logger.log(
                            "Window is already visible! Raising it to the front.",
                            "debug", "specto")
                        self.notifier.notifier.present()

                signal.signal(signal.SIGUSR1, listen_for_USR1)

                self.notifier.refresh_all_watches()
            else:
                self.console.start_watches()

        if self.GTK:
            gtk.main()
        else:
            try:
                self.go = gobject.MainLoop()
                self.go.run()
            except (KeyboardInterrupt, SystemExit):
                sys.exit(0)