From d0d9c4dbf9e96f4e77d8f1f322b2e4108764accd Mon Sep 17 00:00:00 2001 From: Anna Date: Tue, 25 May 2010 11:38:52 -0400 Subject: [PATCH] Factored some code out to a helping function, added an option to disable the system tray icon --- hrafn.conf | 1 + hrafn.py | 72 ++++++++++++++++++++++++++++++++---------------------- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/hrafn.conf b/hrafn.conf index 3309942..de5e15f 100644 --- a/hrafn.conf +++ b/hrafn.conf @@ -2,4 +2,5 @@ debug=0 entries=20 refreshtime=5 +trayicon=1 dbfile=~/.hrafn.db diff --git a/hrafn.py b/hrafn.py index f095ace..53de52f 100755 --- a/hrafn.py +++ b/hrafn.py @@ -11,7 +11,6 @@ import apithreads class Hrafn(): - """ Display Tweets, post to twitter """ def __init__(self, config_file, resize): @@ -23,28 +22,15 @@ class Hrafn(): config.read(os.path.expanduser(config_file)) # Set config options to defaults, if they are not present - new_data = False - if not config.has_section('global'): - config.add_section('global') - new_data = True - if not config.has_option('global', 'entries'): - config.set('global', 'entries', '20') - new_data = True - if not config.has_option('global', 'refreshtime'): - config.set('global', 'refreshtime', '5') - new_data = True - if not config.has_option('global', 'dbfile'): - config.set('global', 'dbfile', '~/.hrafn.db') - new_data = True + self._check_config(config, config_file) - # Write out new config data, if needed - if new_data: - config_filehandle = open(os.path.expanduser(config_file), 'wb') - config.write(config_filehandle) - config_filehandle.close() - - if config.has_option('global', 'debug') and config.get('global', 'debug') == '1': + if config.get('global', 'debug') == '1': debug = True + + if config.get('global', 'trayicon') == '1': + self.use_trayicon = True + else: + self.use_trayicon = False # Init the glade stuff here, so we don't have a race condition with # the lists-ready signal @@ -129,14 +115,14 @@ class Hrafn(): menu_item.show() # Add a system tray icon - self.tray_icon = gtk.status_icon_new_from_file('ui/icon.svg') - self.tray_icon.connect('activate', self.on_tray_icon_clicked) - self.tray_icon.connect('popup-menu', self.on_tray_icon_popup) - self.tray_menu = gtk.Menu() - quit_item = gtk.MenuItem(gtk.STOCK_QUIT) - quit_item.connect('activate', self.gtk_main_quit) - self.tray_menu.attach(quit_item, 0, 1, 0, 1) - + if self.use_trayicon: + self.tray_icon = gtk.status_icon_new_from_file('ui/icon.svg') + self.tray_icon.connect('activate', self.on_tray_icon_clicked) + self.tray_icon.connect('popup-menu', self.on_tray_icon_popup) + self.tray_menu = gtk.Menu() + quit_item = gtk.MenuItem(gtk.STOCK_QUIT) + quit_item.connect('activate', self.gtk_main_quit) + self.tray_menu.attach(quit_item, 0, 1, 0, 1) # Set the account label self.update_account_label() @@ -598,6 +584,34 @@ class Hrafn(): else: self.minimized = False + + def _check_config(self, config, config_file): + new_data = False + if not config.has_section('global'): + config.add_section('global') + new_data = True + if not config.has_option('global', 'entries'): + config.set('global', 'entries', '20') + new_data = True + if not config.has_option('global', 'refreshtime'): + config.set('global', 'refreshtime', '5') + new_data = True + if not config.has_option('global', 'trayicon'): + config.set('global', 'trayicon', '1') + new_data = True + if not config.has_option('global', 'debug'): + config.set('global', 'trayicon', '0') + new_data = True + if not config.has_option('global', 'dbfile'): + config.set('global', 'dbfile', '~/.hrafn.db') + new_data = True + + # Write out new config data, if needed + if new_data: + config_filehandle = open(os.path.expanduser(config_file), 'wb') + config.write(config_filehandle) + config_filehandle.close() + ### end class Hrafn