OSDN Git Service

Added willcom mode (--no-icon, --maxn)
authorHirotaka Kawata <hktechno@hotmail.com>
Thu, 18 Feb 2010 17:38:39 +0000 (02:38 +0900)
committerHirotaka Kawata <hktechno@hotmail.com>
Thu, 18 Feb 2010 17:38:39 +0000 (02:38 +0900)
gwit
iconstore.py
main.py
timeline.py
twitterapi.py

diff --git a/gwit b/gwit
index 8c3471e..bcfeda5 100755 (executable)
--- a/gwit
+++ b/gwit
@@ -2,18 +2,34 @@
 #-*- 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
@@ -23,7 +39,7 @@ if __name__ == "__main__":
       from setupwizard import SetupWizard
       setup = SetupWizard()
       setup.main()
-
+       
       if setup.ok:
          # if setup ok, set settings
          confp.set("DEFAULT", "default_user", setup.screen_name)
@@ -33,7 +49,7 @@ if __name__ == "__main__":
          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)
@@ -47,13 +63,17 @@ if __name__ == "__main__":
    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()
index 1b39dbe..87db701 100644 (file)
@@ -10,7 +10,8 @@ import urllib2
 import cStringIO
 
 class IconStore:
-    def __init__(self):
+    def __init__(self, iconmode = True):
+        self.iconmode = iconmode
         self.data = dict()
         self.stores = list()
     
@@ -25,7 +26,9 @@ class IconStore:
     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
         
diff --git a/main.py b/main.py
index 00151c8..4dcf679 100644 (file)
--- a/main.py
+++ b/main.py
@@ -17,7 +17,7 @@ from iconstore import IconStore
 # 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
@@ -32,13 +32,14 @@ class Main:
         
         # 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):        
@@ -49,11 +50,11 @@ class Main:
         # 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),
@@ -79,7 +80,7 @@ class Main:
     
     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
index d9463b0..f606841 100644 (file)
@@ -13,7 +13,7 @@ import urlregex
 import webbrowser
 
 class timeline:
-    def __init__(self, api, icons):
+    def __init__(self, api, icons, iconmode = True):
         self.api = api
         self.icons = icons
         
@@ -47,6 +47,8 @@ class timeline:
         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))
         
index 2a58306..02595cf 100644 (file)
@@ -8,21 +8,22 @@ import sys
 
 # 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)
@@ -35,7 +36,7 @@ class timeline_thread(threading.Thread):
         # API Arguments
         self.args = args
         self.kwargs = kwargs
-        self.kwargs["count"] = 200
+        self.kwargs["count"] = maxn
     
     # Thread run
     def run(self):