Commits

elbaschid committed 5f4626a

removed unused methods and fixed indentation

Comments (0)

Files changed (1)

revelation_indicator.py

 
 from revelation import config, data, datahandler, dialog, entry, io, ui, util
 
-#from gi.repository import Gtk, GObject, Gio
-#from gi.repository import AppIndicator3
- 
-#try:
-#    from gi.repository import Notify
-#except:
-#    #print _("Please install")+" pynotify"
-#    print "Please install pynotify"
-
 
 class RevelationIndicator(object):
 
             "chain_username": False,
             "file": '',
             "menuaction": "show",
-            "show_passwords": True,
-            "show_searchentry": True
+            "show_passwords": False,
         }
 
         for key, value in defaults.items():
         if filename:
             self.config.set_force('file', filename)
 
-        ##TODO: debug only
-        for key, value in defaults.items():
-            print key, self.config.get(key)
-
+        ##TODO: checkout if this is still required
         # make sure the launchers have been set up, otherwise
         # install the Revelation schema
         #def check_launchers():
     def __init_facilities(self):
         "Sets up facilities"
 
-        self.clipboard		= data.Clipboard()
-        self.datafile		= io.DataFile(datahandler.Revelation)
-        self.entrystore		= data.EntryStore()
-        self.entrysearch	= data.EntrySearch(self.entrystore)
-        #self.items		= ui.ItemFactory(self.applet)
-        self.locktimer		= data.Timer()
+        self.clipboard = data.Clipboard()
+        self.datafile = io.DataFile(datahandler.Revelation)
+        self.entrystore = data.EntryStore()
+        self.entrysearch = data.EntrySearch(self.entrystore)
+        #self.items = ui.ItemFactory(self.applet)
+        self.locktimer = data.Timer()
 
-        self.config.monitor("autolock_timeout", lambda k,v,d: self.locktimer.start(v * 60))
+        self.config.monitor(
+            "autolock_timeout", 
+            lambda k,v,d: self.locktimer.start(v * 60)
+        )
         self.config.monitor("file", self.__cb_config_file)
 
         self.datafile.connect("changed", self.__cb_file_changed)
         )
 
         self.lock_item = gtk.MenuItem(_('Lock File'))
-        self.lock_item.show()
-        #( "file-lock",		lambda w,d=None: self.file_close() ),
-
-        self.reload_item = gtk.MenuItem(_('Reload File'))
-        self.reload_item.show()
-        #( "file-reload",	lambda w,d=None: self.file_reload() ),
+        self.lock_item.connect('activate', lambda w,d=None: self.file_close())
 
         self.start_revel_item = gtk.MenuItem(_('Start Revelation'))
-        self.start_revel_item.show()
         #( "revelation",		lambda w,d=None: util.execute_child("@bindir@/revelation") ),
 
         self.prefs_item = gtk.MenuItem(_('Preferences'))
-        self.prefs_item.show()
         self.prefs_item.connect('activate', lambda w,d=None: self.prefs())
 
         self.about_item = gtk.MenuItem(_('About'))
-        self.about_item.show()
         self.about_item.connect('activate', self.__cb_about)
 
+        self.quit_item = gtk.MenuItem('Quit')
+        self.quit_item.connect('activate', gtk.main_quit)
+
         self.menu.append(self.unlock_item)
         self.menu.append(self.lock_item)
-        self.menu.append(self.reload_item)
-        self.menu.append(self.start_revel_item)
+        #self.menu.append(self.reload_item)
+        #self.menu.append(self.start_revel_item)
         self.menu.append(self.prefs_item)
         self.menu.append(self.about_item)
+        self.menu.append(self.quit_item)
 
         self.ind.set_menu(self.menu)
         self.menu.show_all()
 
 		#self.entrymenu		= None
 
-    def main(self):
-        gtk.main()
-
-    def quit(self, widget):
-        sys.exit(0)
-
-    
     def file_close(self):
         self.__close_popups()
         self.locktimer.stop()
 
             #        self.icon.set_from_stock(ui.STOCK_REVELATION, ui.ICON_SIZE_APPLET)
 
-
-    def __cb_icon_buttonpress(self, widget, data = None):
-            "Callback for buttonpress on button"
-
-            if data.button != 1:
-                    return False
-
-            self.entry_menu(data.time)
-
-            return True
-
-
     def __cb_popup_activate(self, widget, data = None):
         self.locktimer.reset()
 
 
                 self.popup_entryview.close()
 
-        self.popup_entryview.button_goto.connect("clicked", cb_goto)
-        self.popup_entryview.button_goto.set_sensitive(self.__launcher_valid(e))
+        #self.popup_entryview.button_goto.connect("clicked", cb_goto)
+        #self.popup_entryview.button_goto.set_sensitive(self.__launcher_valid(e))
 
         self.popup_entryview.realize()
         x, y = self.__get_popup_offset(self.popup_entryview)
 
         return True
 
-
-    def __flash_entry(self, color = "#ffbaba", duration = 500):
-            "Flashes the entry with a color"
-
-            color_normal	= ui.Entry().rc_get_style().base[gtk.STATE_NORMAL]
-            color_new	= gtk.gdk.color_parse(color)
-
-            self.entry.modify_base(gtk.STATE_NORMAL, color_new)
-            gobject.timeout_add(duration, lambda: self.entry.modify_base(gtk.STATE_NORMAL, color_normal))
-
-
     def __focus_entry(self):
-            "Gives focus to the entry"
-
-            ##FIXME:
-            ##self.applet.request_focus(long(0))
-            pass
-
+        ##FIXME:
+        ##self.applet.request_focus(long(0))
+        pass
 
     def __generate_entrymenu(self, entrystore, parent = None):
-            "Generates an entry menu tree"
+        menu = gtk.Menu()
 
-            menu = gtk.Menu()
+        for i in range(entrystore.iter_n_children(parent)):
+            iter = entrystore.iter_nth_child(parent, i)
 
-            for i in range(entrystore.iter_n_children(parent)):
-                iter = entrystore.iter_nth_child(parent, i)
+            e = entrystore.get_entry(iter)
+            item = ui.ImageMenuItem(type(e) == entry.FolderEntry and ui.STOCK_FOLDER or e.icon, e.name)
+            item.connect("select", lambda w,d=None: self.locktimer.reset())
 
-                e = entrystore.get_entry(iter)
-                item = ui.ImageMenuItem(type(e) == entry.FolderEntry and ui.STOCK_FOLDER or e.icon, e.name)
-                item.connect("select", lambda w,d=None: self.locktimer.reset())
+            if type(e) == entry.FolderEntry:
+                item.set_submenu(self.__generate_entrymenu(entrystore, iter))
+            else:
+                item.connect("activate", self.__cb_popup_activate, e)
 
-                if type(e) == entry.FolderEntry:
-                    item.set_submenu(self.__generate_entrymenu(entrystore, iter))
-                else:
-                    item.connect("activate", self.__cb_popup_activate, e)
+            menu.append(item)
 
-                menu.append(item)
-
-            return menu 
+        return menu 
 
 
     def __get_launcher(self, e):
-            "Returns a launcher command for an entry, if possible"
+        command = self.config.get("/apps/revelation/launcher/%s" % e.id)
 
-            command = self.config.get("/apps/revelation/launcher/%s" % e.id)
+        if command in ( "", None ):
+            return None
 
-            if command in ( "", None ):
-                    return None
+        subst = {}
+        for field in e.fields:
+            subst[field.symbol] = field.value
 
-            subst = {}
-            for field in e.fields:
-                    subst[field.symbol] = field.value
+        command = util.parse_subst(command, subst)
 
-            command = util.parse_subst(command, subst)
-
-            return command
-
+        return command
 
     def __get_popup_offset(self, popup):
-            "Returns a tuple of x and y offset coords for popups"
+        x = gtk.gdk.screen_width() / 2
+        y = 50 
 
-            x = gtk.gdk.screen_width() / 2
-            y = 50 
-
-            return x, y
-
+        return x, y
 
     def __launcher_valid(self, e):
-            "Checks if a launcher is valid"
+        try:
+            command = self.__get_launcher(e)
 
-            try:
-                    command = self.__get_launcher(e)
+            return command != None
 
-                    return command != None
+        except ( util.SubstFormatError ):
+            return True
 
-            except ( util.SubstFormatError ):
-                    return True
-
-            except ( util.SubstValueError, config.ConfigError ):
-                    return False
-
+        except ( util.SubstValueError, config.ConfigError ):
+            return False
 
     def __require_file(self):
-            "Checks if a datafile is loaded, or alerts the user"
+        if self.datafile.get_file() != None:
+            return True
 
-            if self.datafile.get_file() != None:
-                    return True
+        if self.config.get("file") != "":
+            return self.file_open(self.config.get("file"))
 
-            if self.config.get("file") != "":
-                    return self.file_open(self.config.get("file"))
+        d = dialog.Info(
+            None, _('File not selected'),
+            _('You must select a Revelation data file to use - this can be done in the applet preferences.'),
+            ( ( gtk.STOCK_PREFERENCES, gtk.RESPONSE_ACCEPT ), ( gtk.STOCK_OK, gtk.RESPONSE_OK ) )
+        )
 
-            d = dialog.Info(
-                    None, _('File not selected'),
-                    _('You must select a Revelation data file to use - this can be done in the applet preferences.'),
-                    ( ( gtk.STOCK_PREFERENCES, gtk.RESPONSE_ACCEPT ), ( gtk.STOCK_OK, gtk.RESPONSE_OK ) )
-            )
 
+        if d.run() == gtk.RESPONSE_ACCEPT:
+            self.prefs()
 
-            if d.run() == gtk.RESPONSE_ACCEPT:
-                    self.prefs()
-
-            return False
-
-
-
+        return False
 
     def __cb_about(self, item):
         dialog = gtk.AboutDialog()
 class Preferences(dialog.Utility):
 
     def __init__(self, parent, cfg):
-            dialog.Utility.__init__(self, parent, "Preferences")
-            self.config = cfg
-            self.set_modal(False)
+        dialog.Utility.__init__(self, parent, "Preferences")
+        self.config = cfg
+        self.set_modal(False)
 
-            self.notebook = ui.Notebook()
-            self.vbox.pack_start(self.notebook)
+        self.notebook = ui.Notebook()
+        self.vbox.pack_start(self.notebook)
 
-            self.page_general = self.notebook.create_page(_('General'))
-            self.__init_section_file(self.page_general)
-            #self.__init_section_menuaction(self.page_general)
-            #self.__init_section_misc(self.page_general)
+        self.page_general = self.notebook.create_page(_('General'))
+        self.__init_section_file(self.page_general)
+        #self.__init_section_menuaction(self.page_general)
+        #self.__init_section_misc(self.page_general)
 
-            #self.page_goto = self.notebook.create_page(_('Goto Commands'))
-            #self.__init_section_gotocmd(self.page_goto)
-
-            self.connect("response", lambda w,d: self.destroy())
+        self.connect("response", lambda w,d: self.destroy())
 
 
     def __init_section_file(self, page):
-            self.section_file = page.add_section(_('File Handling'))
+        self.section_file = page.add_section(_('File Handling'))
 
-            # entry for file
-            self.button_file = ui.FileButton(_('Select File to Use'))
-            ui.config_bind(self.config, "file", self.button_file)
+        # entry for file
+        self.button_file = ui.FileButton(_('Select File to Use'))
+        ui.config_bind(self.config, "file", self.button_file)
 
-            eventbox = ui.EventBox(self.button_file)
-            eventbox.set_tooltip_text(_('The data file to search for accounts in'))
-            self.section_file.append_widget(_('File to use'), eventbox)
+        eventbox = ui.EventBox(self.button_file)
+        eventbox.set_tooltip_text(_('The data file to search for accounts in'))
+        self.section_file.append_widget(_('File to use'), eventbox)
 
-            # check-button for autolock
-            self.check_autolock = ui.CheckButton(_('Lock file when inactive for'))
-            ui.config_bind(self.config, "autolock", self.check_autolock)
-            self.check_autolock.connect("toggled", lambda w: self.spin_autolock_timeout.set_sensitive(w.get_active()))
-            self.check_autolock.set_tooltip_text(_('Automatically lock the file after a period of inactivity'))
+        # check-button for autolock
+        self.check_autolock = ui.CheckButton(_('Lock file when inactive for'))
+        ui.config_bind(self.config, "autolock", self.check_autolock)
+        self.check_autolock.connect("toggled", lambda w: self.spin_autolock_timeout.set_sensitive(w.get_active()))
+        self.check_autolock.set_tooltip_text(_('Automatically lock the file after a period of inactivity'))
 
-            # spin-entry for autolock-timeout
-            self.spin_autolock_timeout = ui.SpinEntry()
-            self.spin_autolock_timeout.set_range(1, 120)
-            self.spin_autolock_timeout.set_sensitive(self.check_autolock.get_active())
-            ui.config_bind(self.config, "autolock_timeout", self.spin_autolock_timeout)
-            self.spin_autolock_timeout.set_tooltip_text(_('The period of inactivity before locking the file, in minutes'))
+        # spin-entry for autolock-timeout
+        self.spin_autolock_timeout = ui.SpinEntry()
+        self.spin_autolock_timeout.set_range(1, 120)
+        self.spin_autolock_timeout.set_sensitive(self.check_autolock.get_active())
+        ui.config_bind(self.config, "autolock_timeout", self.spin_autolock_timeout)
+        self.spin_autolock_timeout.set_tooltip_text(_('The period of inactivity before locking the file, in minutes'))
 
-            # container for autolock-widgets
-            hbox = ui.HBox()
-            hbox.set_spacing(3)
-            hbox.pack_start(self.check_autolock)
-            hbox.pack_start(self.spin_autolock_timeout)
-            hbox.pack_start(ui.Label(_('minutes')))
-            self.section_file.append_widget(None, hbox)
-
-
-    #def __init_section_gotocmd(self, page):
-    #        "Sets up the goto command section"
-
-    #        self.section_goto = page.add_section(_('Goto Commands'))
-
-    #        for entrytype in entry.ENTRYLIST:
-    #                if entrytype == entry.FolderEntry:
-    #                        continue
-
-    #                e = entrytype()
-
-    #                widget = ui.Entry()
-    #                ui.config_bind(self.config, "/apps/revelation/launcher/%s" % e.id, widget)
-
-    #                tooltip = _('Goto command for %s accounts. The following expansion variables can be used:\n\n') % e.typename
-
-    #                for field in e.fields:
-    #                        tooltip += "%%%s: %s\n" % ( field.symbol, field.name )
-
-    #                tooltip += "\n"
-    #                tooltip += _('%%: a % sign') + "\n"
-    #                tooltip += _('%?x: optional expansion variable') + "\n"
-    #                tooltip += _('%(...%): optional substring expansion')
-
-    #                widget.set_tooltip_text(tooltip)
-    #                self.section_goto.append_widget(e.typename, widget)
-
+        # container for autolock-widgets
+        hbox = ui.HBox()
+        hbox.set_spacing(3)
+        hbox.pack_start(self.check_autolock)
+        hbox.pack_start(self.spin_autolock_timeout)
+        hbox.pack_start(ui.Label(_('minutes')))
+        self.section_file.append_widget(None, hbox)
 
     #def __init_section_menuaction(self, page):
-    #        "Sets up a menuaction section in a page"
+    #    "Sets up a menuaction section in a page"
 
-    #        self.section_menuaction = page.add_section(_('Menu Action'))
+    #    self.section_menuaction = page.add_section(_('Menu Action'))
 
-    #        # radio-button for show
-    #        self.radio_show = ui.RadioButton(None, _('Display account info'))
-    #        ui.config_bind(self.config, "menuaction", self.radio_show, "show")
+    #    # radio-button for show
+    #    self.radio_show = ui.RadioButton(None, _('Display account info'))
+    #    ui.config_bind(self.config, "menuaction", self.radio_show, "show")
 
-    #        self.radio_show.set_tooltip_text(_('Display the account information'))
-    #        self.section_menuaction.append_widget(None, self.radio_show)
+    #    self.radio_show.set_tooltip_text(_('Display the account information'))
+    #    self.section_menuaction.append_widget(None, self.radio_show)
 
-    #        # radio-button for goto
-    #        self.radio_goto = ui.RadioButton(self.radio_show, _('Go to account, if possible'))
-    #        ui.config_bind(self.config, "menuaction", self.radio_goto, "goto")
+    #    # radio-button for goto
+    #    self.radio_goto = ui.RadioButton(self.radio_show, _('Go to account, if possible'))
+    #    ui.config_bind(self.config, "menuaction", self.radio_goto, "goto")
 
-    #        self.radio_goto.set_tooltip_text(_('Open the account in an external application if possible, otherwise display it'))
-    #        self.section_menuaction.append_widget(None, self.radio_goto)
+    #    self.radio_goto.set_tooltip_text(_('Open the account in an external application if possible, otherwise display it'))
+    #    self.section_menuaction.append_widget(None, self.radio_goto)
 
-    #        # radio-button for copy username/password
-    #        self.radio_copy = ui.RadioButton(self.radio_show, _('Copy password to clipboard'))
-    #        ui.config_bind(self.config, "menuaction", self.radio_copy, "copy")
+    #    # radio-button for copy username/password
+    #    self.radio_copy = ui.RadioButton(self.radio_show, _('Copy password to clipboard'))
+    #    ui.config_bind(self.config, "menuaction", self.radio_copy, "copy")
 
-    #        self.radio_copy.set_tooltip_text(_('Copy the account password to the clipboard'))
-    #        self.section_menuaction.append_widget(None, self.radio_copy)
-
+    #    self.radio_copy.set_tooltip_text(_('Copy the account password to the clipboard'))
+    #    self.section_menuaction.append_widget(None, self.radio_copy)
 
     #def __init_section_misc(self, page):
-    #        "Sets up the misc section"
+    #    "Sets up the misc section"
 
-    #        self.section_misc = page.add_section(_('Miscellaneous'))
+    #    self.section_misc = page.add_section(_('Miscellaneous'))
 
-    #        # show searchentry checkbutton
-    #        self.check_show_searchentry = ui.CheckButton(_('Show search entry'))
-    #        ui.config_bind(self.config, "show_searchentry", self.check_show_searchentry)
+    #    # show searchentry checkbutton
+    #    self.check_show_searchentry = ui.CheckButton(_('Show search entry'))
+    #    ui.config_bind(self.config, "show_searchentry", self.check_show_searchentry)
 
-    #        self.check_show_searchentry.set_tooltip_text(_('Display an entry box in the applet for searching'))
-    #        self.section_misc.append_widget(None, self.check_show_searchentry)
+    #    self.check_show_searchentry.set_tooltip_text(_('Display an entry box in the applet for searching'))
+    #    self.section_misc.append_widget(None, self.check_show_searchentry)
 
-    #        # show passwords checkbutton
-    #        self.check_show_passwords = ui.CheckButton(_('Show passwords and other secrets'))
-    #        ui.config_bind(self.config, "show_passwords", self.check_show_passwords)
+    #    # show passwords checkbutton
+    #    self.check_show_passwords = ui.CheckButton(_('Show passwords and other secrets'))
+    #    ui.config_bind(self.config, "show_passwords", self.check_show_passwords)
 
-    #        self.check_show_passwords.set_tooltip_text(_('Display passwords and other secrets, such as PIN codes (otherwise, hide with ******)'))
-    #        self.section_misc.append_widget(None, self.check_show_passwords)
+    #    self.check_show_passwords.set_tooltip_text(_('Display passwords and other secrets, such as PIN codes (otherwise, hide with ******)'))
+    #    self.section_misc.append_widget(None, self.check_show_passwords)
 
-    #        # check-button for username
-    #        self.check_chain_username = ui.CheckButton(_('Also copy username when copying password'))
-    #        ui.config_bind(self.config, "chain_username", self.check_chain_username)
+    #    # check-button for username
+    #    self.check_chain_username = ui.CheckButton(_('Also copy username when copying password'))
+    #    ui.config_bind(self.config, "chain_username", self.check_chain_username)
 
-    #        self.check_chain_username.set_tooltip_text(_('When the password is copied to clipboard, put the username before the password as a clipboard "chain"'))
-    #        self.section_misc.append_widget(None, self.check_chain_username)
+    #    self.check_chain_username.set_tooltip_text(_('When the password is copied to clipboard, put the username before the password as a clipboard "chain"'))
+    #    self.section_misc.append_widget(None, self.check_chain_username)
 
 
     def run(self):
         self.entryview.display_entry(e)
 
         self.button_close = ui.Button(gtk.STOCK_CLOSE, lambda w: self.close())
-        self.button_goto = ui.Button(ui.STOCK_GOTO)
-        self.buttonbox = ui.HButtonBox(self.button_goto, self.button_close)
+        self.buttonbox = ui.HButtonBox(self.button_close)
 
         self.vbox = ui.VBox(self.entryview, self.buttonbox)
         self.vbox.set_border_width(12)
 
 
 def main(options=None):
+    revelation_indicator = RevelationIndicator(options)
 
-    revelation_indicator = RevelationIndicator(options)
-    revelation_indicator.main()
+    gtk.main()
+
 
 if __name__ == "__main__":
    
     parser.add_argument('-f', '--file', default='')
     options = parser.parse_args()
 
-    print options
-
     if options.debug:
         logger.setLevel(logging.DEBUG)