Factored some code out to a helping function, added an option to disable the system tray icon
This commit is contained in:
parent
fbaf131849
commit
d0d9c4dbf9
|
@ -2,4 +2,5 @@
|
|||
debug=0
|
||||
entries=20
|
||||
refreshtime=5
|
||||
trayicon=1
|
||||
dbfile=~/.hrafn.db
|
||||
|
|
72
hrafn.py
72
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
|
||||
|
||||
|
||||
|
|
Reference in New Issue
Block a user