diff --git a/hrafn.py b/hrafn.py index a8d1f9a..55cb176 100755 --- a/hrafn.py +++ b/hrafn.py @@ -13,23 +13,14 @@ import apithreads class Hrafn(): """ Display Tweets, post to twitter """ - def __init__(self, config_file, resize): - global debug + def __init__(self, resize): + global config self.resize = resize self.lists = {} self.lists_cond = Condition() - config = ConfigParser.ConfigParser() - config.read(os.path.expanduser(config_file)) - - # Set config options to defaults, if they are not present - self._check_config(config, config_file) - - if config.get('global', 'debug') == '1': - debug = True - if config.get('global', 'trayicon') == '1': self.use_trayicon = True if config.get('global', 'taskbar_when_minimized') == '1': @@ -645,37 +636,6 @@ class Hrafn(): self.window.set_property('skip-taskbar-hint', 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', 'taskbar_when_minimized'): - config.set('global', 'taskbar_when_minimized', '0') - new_data = True - if not config.has_option('global', 'debug'): - config.set('global', 'debug', '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() - - def on_read_tweets_changed(self, widget): unread_tweets = 0 for i in range(self.tweet_notebook.get_n_pages()): @@ -690,20 +650,60 @@ class Hrafn(): ### end class Hrafn +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', 'taskbar_when_minimized'): + config.set('global', 'taskbar_when_minimized', '0') + new_data = True + if not config.has_option('global', 'debug'): + config.set('global', 'debug', '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() + + # main -debug = False +if __name__ == "__main__": + parser = optparse.OptionParser() + parser.add_option('-c' ,'--config', dest="filename", default="~/.hrafn.conf", help="read configuration from FILENAME instead of the default ~/.hrafn.conf") + parser.add_option('-n' ,'--no-resize', dest="resize", action='store_false', default=True, help="use the default window size instead of the size from the last session") + (options, args) = parser.parse_args() -parser = optparse.OptionParser() -parser.add_option('-c' ,'--config', dest="filename", default="~/.hrafn.conf", help="read configuration from FILENAME instead of the default ~/.hrafn.conf") -parser.add_option('-n' ,'--no-resize', dest="resize", action='store_false', default=True, help="use the default window size instead of the size from the last session") -(options, args) = parser.parse_args() + config = ConfigParser.ConfigParser() + config.read(os.path.expanduser(options.filename)) -base_icon = gtk.gdk.pixbuf_new_from_file('ui/icon.svg') -icon = base_icon.scale_simple(128, 128, gtk.gdk.INTERP_BILINEAR) -gtk.window_set_default_icon(icon) -my_twitter = Hrafn(options.filename, options.resize) + # Set config options to defaults, if they are not present + _check_config(config, config_file) -gtk.gdk.threads_init() -gtk.gdk.threads_enter() -gtk.main() -gtk.gdk.threads_leave() + debug = False + if config.get('global', 'debug') == 1: + debug = True + + base_icon = gtk.gdk.pixbuf_new_from_file('ui/icon.svg') + icon = base_icon.scale_simple(128, 128, gtk.gdk.INTERP_BILINEAR) + gtk.window_set_default_icon(icon) + my_twitter = Hrafn(options.resize) + + gtk.gdk.threads_init() + gtk.gdk.threads_enter() + gtk.main() + gtk.gdk.threads_leave()