Made config options a global feature, added __main__ section
This commit is contained in:
parent
676b9d2e3e
commit
9857187635
56
hrafn.py
56
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,6 +636,20 @@ class Hrafn():
|
|||
self.window.set_property('skip-taskbar-hint', False)
|
||||
|
||||
|
||||
def on_read_tweets_changed(self, widget):
|
||||
unread_tweets = 0
|
||||
for i in range(self.tweet_notebook.get_n_pages()):
|
||||
pane = self.tweet_notebook.get_nth_page(i)
|
||||
unread_tweets += pane.num_new_tweets
|
||||
|
||||
if unread_tweets > 0:
|
||||
self.tray_icon.set_property('blinking', True)
|
||||
else:
|
||||
self.tray_icon.set_property('blinking', False)
|
||||
|
||||
### end class Hrafn
|
||||
|
||||
|
||||
def _check_config(self, config, config_file):
|
||||
new_data = False
|
||||
if not config.has_section('global'):
|
||||
|
@ -676,32 +681,27 @@ class Hrafn():
|
|||
config_filehandle.close()
|
||||
|
||||
|
||||
def on_read_tweets_changed(self, widget):
|
||||
unread_tweets = 0
|
||||
for i in range(self.tweet_notebook.get_n_pages()):
|
||||
pane = self.tweet_notebook.get_nth_page(i)
|
||||
unread_tweets += pane.num_new_tweets
|
||||
|
||||
if unread_tweets > 0:
|
||||
self.tray_icon.set_property('blinking', True)
|
||||
else:
|
||||
self.tray_icon.set_property('blinking', False)
|
||||
|
||||
### end class Hrafn
|
||||
|
||||
|
||||
# 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()
|
||||
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.read(os.path.expanduser(options.filename))
|
||||
|
||||
# Set config options to defaults, if they are not present
|
||||
_check_config(config, config_file)
|
||||
|
||||
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.filename, options.resize)
|
||||
my_twitter = Hrafn(options.resize)
|
||||
|
||||
gtk.gdk.threads_init()
|
||||
gtk.gdk.threads_enter()
|
||||
|
|
Reference in New Issue
Block a user