Factored some code out to a helping function, added an option to disable the system tray icon

This commit is contained in:
Anna 2010-05-25 11:38:52 -04:00
parent fbaf131849
commit d0d9c4dbf9
2 changed files with 44 additions and 29 deletions

View File

@ -2,4 +2,5 @@
debug=0 debug=0
entries=20 entries=20
refreshtime=5 refreshtime=5
trayicon=1
dbfile=~/.hrafn.db dbfile=~/.hrafn.db

View File

@ -11,7 +11,6 @@ import apithreads
class Hrafn(): class Hrafn():
""" Display Tweets, post to twitter """ """ Display Tweets, post to twitter """
def __init__(self, config_file, resize): def __init__(self, config_file, resize):
@ -23,29 +22,16 @@ class Hrafn():
config.read(os.path.expanduser(config_file)) config.read(os.path.expanduser(config_file))
# Set config options to defaults, if they are not present # Set config options to defaults, if they are not present
new_data = False self._check_config(config, config_file)
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
# Write out new config data, if needed if config.get('global', 'debug') == '1':
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':
debug = True 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 # Init the glade stuff here, so we don't have a race condition with
# the lists-ready signal # the lists-ready signal
self.init_user_interface('./ui/default.glade') self.init_user_interface('./ui/default.glade')
@ -129,6 +115,7 @@ class Hrafn():
menu_item.show() menu_item.show()
# Add a system tray icon # Add a system tray icon
if self.use_trayicon:
self.tray_icon = gtk.status_icon_new_from_file('ui/icon.svg') 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('activate', self.on_tray_icon_clicked)
self.tray_icon.connect('popup-menu', self.on_tray_icon_popup) self.tray_icon.connect('popup-menu', self.on_tray_icon_popup)
@ -137,7 +124,6 @@ class Hrafn():
quit_item.connect('activate', self.gtk_main_quit) quit_item.connect('activate', self.gtk_main_quit)
self.tray_menu.attach(quit_item, 0, 1, 0, 1) self.tray_menu.attach(quit_item, 0, 1, 0, 1)
# Set the account label # Set the account label
self.update_account_label() self.update_account_label()
@ -598,6 +584,34 @@ class Hrafn():
else: else:
self.minimized = False 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 ### end class Hrafn