# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+import pygtk
+pygtk.require('2.0')
+import gtk
+import gobject
import os.path
import re
-import threading
from datetime import tzinfo, timedelta, datetime
import itertools
+import traceback
import config
from BbsType import bbs_type_exception
raise ValueError
-class ThreadInvoker(threading.Thread):
- def __init__(self, on_end, *methods):
- super(ThreadInvoker, self).__init__()
- self.on_end = on_end
- self.methods = methods
- def run(self):
- try:
- for m in self.methods:
- m()
- finally:
- self.on_end()
-
-
class FileWrap:
def __init__(self, path, mode="a+"):
self.__file = None
def tabbed_to_dict(tabbed, sep="\t"):
"""Creates a dict from key equal value pairs seperated with tab"""
return dict([pair for pair in tabbed_to_dict_generator(tabbed, sep)])
+
+
+class StopChainException: pass
+
+def _do_chain(function, on_end, iterable):
+ try:
+ value = iterable.next()
+ function(value)
+ except StopIteration:
+ # normal end.
+ on_end()
+ except StopChainException:
+ # normal end.
+ on_end()
+ except:
+ # an error is occurred.
+ on_end()
+ traceback.print_exc()
+ else:
+ gobject.idle_add(_do_chain, function, on_end, iterable)
+
+def chain(function, on_end, iterable):
+ gobject.idle_add(_do_chain, function, on_end, iterable)