Commits

elbaschid committed 5960d7c

added initial version of indicator (work in progress)

  • Participants

Comments (0)

Files changed (2)

File README.md

Empty file added.

File revelation-indicator.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import sys
+
+import gtk
+import appindicator
+
+import gettext
+_ = gettext.gettext
+
+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):
+
+    def __init__(self):
+        self.ind = appindicator.Indicator(
+            "revelation-indicator-locked",
+            "revelation-indicator",
+            appindicator.CATEGORY_APPLICATION_STATUS
+        )
+
+        self.ind.set_status(appindicator.STATUS_ACTIVE)
+
+        #self.ind.set_status(AppIndicator3.STATUS_ACTIVE)
+        #self.ind.set_attention_icon("new-messages-red")
+
+        import sys
+        sys.excepthook	= self.__cb_exception
+
+        gettext.bindtextdomain(config.PACKAGE, config.DIR_LOCALE)
+        gettext.bind_textdomain_codeset(config.PACKAGE, "UTF-8")
+        gettext.textdomain(config.PACKAGE)
+        
+        try:
+            #self.__init_config()
+            self.__init_facilities()
+            self.__init_ui()
+            #self.__init_states()
+
+        except config.ConfigError:
+            dialog.Error(
+                None, 
+                _('Missing configuration data'), 
+                _('The applet could not find its configuration data, please'
+                  'reinstall Revelation.')
+            ).run()
+            sys.exit(1)
+
+    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.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.datafile.connect("content-changed", self.__cb_file_content_changed)
+        #self.locktimer.connect("ring", self.__cb_file_autolock)
+
+        #self.entrysearch.folders = False
+    
+    def __init_ui(self):
+        self.menu = gtk.Menu()
+
+        self.unlock_item = gtk.MenuItem(_('Unlock File'))
+        self.unlock_item.show()
+
+        self.lock_item = gtk.MenuItem(_('Lock File'))
+        self.lock_item.show()
+
+        self.reload_item = gtk.MenuItem(_('Reload File'))
+        self.reload_item.show()
+
+        self.start_revel_item = gtk.MenuItem(_('Start Revelation'))
+        self.start_revel_item.show()
+
+        self.prefs_item = gtk.MenuItem(_('Preferences'))
+        self.prefs_item.show()
+
+        self.about_item = gtk.MenuItem(_('About'))
+        self.about_item.show()
+
+        #self.quit_item.connect("activate", self.quit)
+        #self.quit_item.show()
+        #self.menu.append(self.quit_item)
+        self.menu.append(self.lock_item)
+        self.menu.append(self.unlock_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.ind.set_menu(self.menu)
+
+#		gtk.about_dialog_set_url_hook(lambda d,l: gtk.show_uri(None, l, gtk.get_current_event_time()))
+#		gtk.about_dialog_set_email_hook(lambda d,l: gtk.show_uri(None, "mailto:" + l, gtk.get_current_event_time()))
+#
+#		# set up applet
+#		self.applet.set_flags(gnomeapplet.EXPAND_MINOR)
+#
+#		# set up window icons
+#		pixbufs = [ self.items.get_pixbuf("revelation", size) for size in ( 48, 32, 24, 16) ]
+#		pixbufs = [ pixbuf for pixbuf in pixbufs if pixbuf != None ]
+#
+#		if len(pixbufs) > 0:
+#			gtk.window_set_default_icon_list(*pixbufs)
+#
+		# set up popup menu
+		#self.applet.setup_menu("""
+		#	<popup name="button3">
+		#		<menuitem name="file-unlock"	verb="file-unlock"	label=\"""" + _('Unlock File') + """\"		pixtype="stock" pixname="revelation-unlock" />
+		#		<menuitem name="file-lock"	verb="file-lock"	label=\"""" + _('Lock File') + """\"		pixtype="stock" pixname="revelation-lock" />
+		#		<menuitem name="file-reload"	verb="file-reload"	label=\"""" + _('Reload File') + """\"		pixtype="stock" pixname="revelation-reload" />
+		#		<separator />
+		#		<menuitem name="revelation"	verb="revelation"	label=\"""" + _('Start Revelation') + """\"	pixtype="stock" pixname="revelation-revelation" />
+		#		<menuitem name="prefs"		verb="prefs"		label=\"""" + _('Preferences') + """\"		pixtype="stock"	pixname="gtk-properties" />
+		#		<menuitem name="about"		verb="about"		label=\"""" + _('About') + """\"		pixtype="stock"	pixname="gnome-stock-about" />
+		#	</popup>
+		#""", (
+		#	( "about",		lambda w,d=None: self.about() ),
+		#	( "file-lock",		lambda w,d=None: self.file_close() ),
+		#	( "file-reload",	lambda w,d=None: self.file_reload() ),
+		#	( "file-unlock",	lambda w,d=None: self.file_open(self.config.get("file")) ),
+		#	( "prefs",		lambda w,d=None: self.prefs() ),
+		#	( "revelation",		lambda w,d=None: util.execute_child("@bindir@/revelation") ),
+		#), None)
+
+		## set up ui items
+		#self.entry = ui.Entry()
+		#self.entry.set_width_chars(14)
+		#self.entry.connect("activate", self.__cb_entry_activate)
+		#self.entry.connect("button_press_event", self.__cb_entry_buttonpress)
+		#self.entry.connect("key_press_event", lambda w,d=None: self.locktimer.reset())
+
+		#self.icon = ui.Image()
+		#self.eventbox = ui.EventBox(self.icon)
+		#self.eventbox.connect("button_press_event", self.__cb_icon_buttonpress)
+
+		#self.hbox = ui.HBox(self.eventbox, self.entry)
+		#self.applet.add(self.hbox)
+		#
+		## handle Gnome Panel background
+		#self.applet.connect("change-background",self.panel_bg)
+
+		#self.applet.show_all()
+
+		## set up various ui element holders
+		#self.popup_entryview	= None
+		#self.popup_entrylist	= None
+
+		#self.entrymenu		= None
+
+    def main(self):
+        gtk.main()
+
+    def quit(self, widget):
+        sys.exit(0)
+
+
+
+    def __cb_exception(self, type, value, trace):
+
+        if type == KeyboardInterrupt:
+            sys.exit(1)
+
+        traceback = util.trace_exception(type, value, trace)
+        sys.stderr.write(traceback)
+
+        if dialog.Exception(None, traceback).run() == True:
+            gtk.main()
+        else:
+            sys.exit(1)
+            
+
+def main():
+    revelation_indicator = RevelationIndicator()
+    revelation_indicator.main()
+
+if __name__ == "__main__":
+    main()