#-*- coding: utf-8 -*-
import os
+import optparse
from ConfigParser import SafeConfigParser
from main import Main
if __name__ == "__main__":
+ # Option Parser
+ p = optparse.OptionParser()
+ p.add_option("-u", "--user", dest="user",
+ help="choose auth user", metavar="USER")
+ p.add_option("--add", dest="add", action="store_true",
+ help="add new user")
+ p.add_option("-v", "--version", dest="version",
+ action="store_true", help="print version")
+ p.add_option("--no-icon", dest="noicon", default=True,
+ action="store_false", help="no icon mode")
+ p.add_option("-n", "--maxn", dest="max",
+ help="max number of status of once", metavar="N")
+
+ (options, args) = p.parse_args()
+
# Config Parser
confp = SafeConfigParser()
-
+
# Config file absolute path
conf_path = os.path.join(
os.path.dirname(__file__), "gwit.conf")
-
+
# config file exist?
if os.path.isfile(conf_path):
# readfile
from setupwizard import SetupWizard
setup = SetupWizard()
setup.main()
-
+
if setup.ok:
# if setup ok, set settings
confp.set("DEFAULT", "default_user", setup.screen_name)
confp.set(setup.screen_name, "atoken", setup.keys[2])
confp.set(setup.screen_name, "asecret", setup.keys[3])
del setup
-
+
# write config
fp = open(conf_path, "w")
confp.write(fp)
settings["DEFAULT"] = dict(confp.items("DEFAULT"))
for i in confp.sections():
settings[i] = dict(confp.items(i))
-
+
# Read settings
user = settings["DEFAULT"]["default_user"]
keys = (settings[user]["ckey"], settings[user]["csecret"],
- settings[user]["atoken"], settings[user]["asecret"])
+ settings[user]["atoken"], settings[user]["asecret"])
# Run Main()
gladefile = "gwit.glade"
- gwit = Main(gladefile, keys)
+ if options.max and int(options.max) <= 200:
+ maxn = int(options.max)
+ else:
+ maxn = 200
+ gwit = Main(gladefile, keys, maxn, options.noicon)
gwit.main()
import cStringIO
class IconStore:
- def __init__(self):
+ def __init__(self, iconmode = True):
+ self.iconmode = iconmode
self.data = dict()
self.stores = list()
def new(self, user):
# New Icon thread start
newico = NewIcon(user, self.stores, self.data)
- newico.start()
+ if self.iconmode:
+ # start thread for wget icon if iconmode is True
+ newico.start()
self.data[user.id] = None
# Main Class
class Main:
# Constractor
- def __init__(self, glade, keys):
+ def __init__(self, glade, keys, maxn = 200, iconmode = True):
# GtkBuilder instance
builder = gtk.Builder()
# Glade file input
# Set Default Mention Flag
self.re = 0
+ self.iconmode = iconmode
# init status timelines
self.timelines = list()
# init icon store
- self.icons = IconStore()
-
- init = threading.Thread(target=self.initialize, args=(keys))
+ self.icons = IconStore(iconmode)
+
+ init = threading.Thread(target=self.initialize, args=(keys, maxn))
init.start()
def main(self):
# Start gtk main loop
gtk.main()
gtk.gdk.threads_leave()
-
+
# Initialize Twitter API and Tabs (in another thread)
- def initialize(self, *keys):
+ def initialize(self, keys, maxn):
# Twitter class instance
- self.twitter = twitterapi(keys)
+ self.twitter = twitterapi(keys, maxn)
# Set Status Views
for i in (("Home", "home_timeline", 30),
def _tab_append(self, name, method, sleep, *args, **kwargs):
# Create Timeline Object
- tl = timeline(self.twitter, self.icons)
+ tl = timeline(self.twitter, self.icons, self.iconmode)
self.timelines.append(tl)
# Start sync timeline
import webbrowser
class timeline:
- def __init__(self, api, icons):
+ def __init__(self, api, icons, iconmode = True):
self.api = api
self.icons = icons
tcol = list()
tcol.append(
gtk.TreeViewColumn("Icon", crpix, pixbuf = 0))
+ # visible is False if no-icon
+ tcol[-1].set_visible(iconmode)
tcol.append(
gtk.TreeViewColumn("Status", crtxt, markup = 1))
# Twitter API Class
class twitterapi():
- def __init__(self, keys):
+ def __init__(self, keys, maxn):
# Generate API Library instance
self.api = twoauth.api(*keys)
+ self.maxn = maxn
self.threads = list()
def create_timeline(self, func, sleep, args, kwargs):
# Add New Timeline Thread
th = timeline_thread(getattr(self.api, func),
- sleep, args, kwargs)
+ sleep, self.maxn, args, kwargs)
self.threads.append(th)
return th
# Timeline Thread
class timeline_thread(threading.Thread):
- def __init__(self, func, sleep, args, kwargs):
+ def __init__(self, func, sleep, maxn, args, kwargs):
# Thread Initialize
threading.Thread.__init__(self)
self.setDaemon(True)
# API Arguments
self.args = args
self.kwargs = kwargs
- self.kwargs["count"] = 200
+ self.kwargs["count"] = maxn
# Thread run
def run(self):