def toggle_notifier(self, *args): """ Toggle the state of the notifier, hidden or shown. It will save the size, position, and the last state when you closed Specto. """ #Creating the notifier window, but keeping it hidden if not self.notifier_initialized and self.notifier_keep_hidden: self.notifier = Notifier(self) #self.notifier.restore_size_and_position()#this is NOT needed here because it already does that on instanciation on the line above -kiddo self.notifier.notifier.hide() #Creating the notifier window and displaying it elif not self.notifier_initialized and not self.notifier_keep_hidden: self.notifier = Notifier(self) #self.notifier.restore_size_and_position()#this is NOT needed here because it already does that on instanciation on the line above -kiddo self.notifier.notifier.show() elif self.notifier_initialized: if self.notifier.get_state() == True and self.notifier_keep_hidden: self.logger.log(_("notifier: reappear"), "debug", self.__class__) self.specto_gconf.set_entry("show_notifier", True) self.notifier.restore_size_and_position( ) #to make sure that the x and y positions don't jump around self.notifier.notifier.show() elif self.notifier.get_state( ) == True and not self.notifier_keep_hidden: self.logger.log(_("notifier: hide"), "debug", self.__class__) self.specto_gconf.set_entry("show_notifier", False) self.notifier.notifier.hide() else: self.logger.log(_("notifier: reappear"), "debug", self.__class__) self.specto_gconf.set_entry("show_notifier", True) self.notifier.restore_size_and_position( ) #to make sure that the x and y positions don't jump around self.notifier.notifier.show() self.notifier_initialized = True
def create_watch(self, values): """ Add a watch to the watches repository. """ id = len(self.watch_db) if values['type'] == 0: #add a website from spectlib.watch_web_static import Web_watch self.watch_db[id] = Web_watch( self, values['name'], values['refresh'], values['uri'], id, values['error_margin']) #TODO: Authentication elif values['type'] == 1: #add an email if int(values['prot']) == 0: #check if pop3, imap or gmail is used import spectlib.watch_mail_pop3 self.watch_db[id] = spectlib.watch_mail_pop3.Mail_watch( values['refresh'], values['host'], values['username'], values['password'], values['ssl'], self, id, values['name']) elif int(values['prot']) == 1: import spectlib.watch_mail_imap self.watch_db[id] = spectlib.watch_mail_imap.Mail_watch( values['refresh'], values['host'], values['username'], values['password'], values['ssl'], self, id, values['name']) else: import spectlib.watch_mail_gmail self.watch_db[id] = spectlib.watch_mail_gmail.Mail_watch( values['refresh'], values['username'], values['password'], self, id, values['name']) elif values['type'] == 2: #add a file from spectlib.watch_file import File_watch self.watch_db[id] = File_watch(values['refresh'], values['file'], values['mode'], self, id, values['name']) elif values['type'] == 3: #add a process watch from spectlib.watch_process import Process_watch self.watch_db[id] = Process_watch(values['refresh'], values['process'], self, id, values['name']) elif values['type'] == 4: #add a port watch from spectlib.watch_port import Port_watch self.watch_db[id] = Port_watch(values['refresh'], values['port'], self, id, values['name']) elif values['type'] == 5: #add a google reader account from spectlib.watch_web_greader import Google_reader self.watch_db[id] = Google_reader(values['refresh'], values['username'], values['password'], self, id, values['name']) try: self.watch_db[id].updated = values['updated'] except: self.watch_db[id].updated = False try: self.watch_db[id].active = values['active'] except: self.watch_db[id].active = True try: self.watch_db[id].last_updated = values['last_updated'] except: self.watch_db[id].last_updated = _("No updates yet.") if GTK: if not self.notifier_initialized: self.notifier = Notifier(self) #self.notifier.restore_size_and_position()#fixme: is this necessary? this makes specto output stuff for nothing. self.notifier.add_notifier_entry(values['name'], values['type'], id) try: if values['updated']: self.toggle_updated(id) except: pass try: if values['active'] == False: self.notifier.deactivate(id) except: pass return id
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)