pygtk.require('2.0')
import gtk
+import sys
import threading
import random
import time
from timeline import timeline
from twitterapi import twitterapi
from iconstore import IconStore
+from saveconfig import save_configs, save_config, get_config
# Main Class
class Main:
init = threading.Thread(target=self.initialize, args=(keys, maxn))
init.start()
- def main(self):
+ def main(self):
# Gtk Multithread Setup
gtk.gdk.threads_init()
gtk.gdk.threads_enter()
+
+ # settings allocation
+ try:
+ alloc = get_config("DEFAULT", "allocation")
+ alloc = eval(alloc)
+ self.obj.window1.resize(alloc.width, alloc.height)
+ except:
+ print >>sys.stderr, "[Warning] Allocation not defined"
+
self.obj.window1.show_all()
+
# Start gtk main loop
gtk.main()
gtk.gdk.threads_leave()
# Window close event
def close(self, widget):
+ # Save Allocation (window position, size)
+ print widget.get_position()
+ alloc = repr(widget.allocation)
+ save_config("DEFAULT", "allocation", alloc)
+
gtk.main_quit()
# Get text
--- /dev/null
+#!/usr/bin/env python
+#-*- coding: utf-8 -*-
+
+import os
+from ConfigParser import SafeConfigParser
+
+def save_config(section, key, value):
+ confp = _open()
+ confp.set(section, key, value)
+ _close(confp)
+
+def save_configs(conftuple):
+ confp = _open()
+ for section, key, value in conftuple:
+ confp.set(section, key, str(value))
+ _close(confp)
+
+def get_config(section, keys):
+ confp = _open()
+ items = dict(confp.items(section))
+ return items[keys]
+
+def _open():
+ confp = SafeConfigParser()
+ conf_path = os.path.join(
+ os.path.dirname(__file__), "gwit.conf")
+
+ if os.path.isfile(conf_path):
+ confp.read(conf_path)
+
+ return confp
+
+def _close(confp):
+ conf_path = os.path.join(
+ os.path.dirname(__file__), "gwit.conf")
+
+ fp = open(conf_path, "w")
+ confp.write(fp)
+ fp.close()