Putting all the code from the current master branch of TWBlue

This commit is contained in:
2014-10-27 16:29:04 -06:00
parent 58c82e5486
commit 1af4a8b291
284 changed files with 58760 additions and 0 deletions

0
src/mysc/__init__.py Normal file
View File

41
src/mysc/event.py Normal file
View File

@@ -0,0 +1,41 @@
# -- coding: utf-8 -*-
from wx.lib.newevent import NewEvent
import wx
EVT_DELETED = wx.NewEventType()
MyEVT_DELETED = wx.PyEventBinder(EVT_DELETED, 1)
EVT_STARTED = wx.NewEventType()
MyEVT_STARTED = wx.PyEventBinder(EVT_STARTED, 1)
EVT_OBJECT = wx.NewEventType()
MyEVT_OBJECT = wx.PyEventBinder(EVT_OBJECT, 1)
ResultEvent, EVT_RESULT = NewEvent()
#DeletedEvent, EVT_DELETED = NewEvent()
class event(wx.PyCommandEvent):
def __init__(self, evtType, id):
self.text = ""
wx.PyCommandEvent.__init__(self, evtType, id)
def SetItem(self, item):
self.item = item
def GetItem(self):
return self.item
def SetAnnounce(self, text ):
self.text = text
def GetAnnounce(self):
try: return self.text
except: pass
class infoEvent(event):
def __init__(self, evtType, id):
event.__init__(self, evtType, id)
def SetItem(self, page, items):
self.page = page
self.items = items
def GetItem(self):
return [self.page, self.items]

9
src/mysc/localization.py Normal file
View File

@@ -0,0 +1,9 @@
import gettext_windows, os
def get(rootFolder):
defaultLocale = gettext_windows.get_language()[0][:2]
if os.path.exists(rootFolder+"/"+defaultLocale):
return defaultLocale
else:
return "en"

38
src/mysc/paths.py Normal file
View File

@@ -0,0 +1,38 @@
import platform
import os
import sys
from functools import wraps
def merge_paths(func):
@wraps(func)
def merge_paths_wrapper(*a):
return unicode(os.path.join(func(), *a))
return merge_paths_wrapper
@merge_paths
def app_path():
if hasattr(sys, "frozen"):
from win32api import GetModuleFileName #We should only be here if using py2exe hence windows
app_path = os.path.dirname(GetModuleFileName(0))
else:
app_path = os.path.normpath(os.path.dirname(__file__))
return app_path
@merge_paths
def config_path():
path = app_path(u"config")
if not os.path.exists(path):
os.mkdir(path)
return path
@merge_paths
def data_path(app_name='Blu JM'):
# if platform.system() == "Windows":
# import shlobj
# data_path = os.path.join(shlobj.SHGetFolderPath(0, shlobj.CSIDL_APPDATA), app_name)
# else:
data_path = os.path.join(os.environ['HOME'], ".%s" % app_name)
if not os.path.exists(data_path):
os.mkdir(data_path)
return data_path

View File

@@ -0,0 +1,34 @@
import threading
class RepeatingTimer(threading.Thread):
"""Call a function after a specified number of seconds, it will then repeat again after the specified number of seconds
Note: If the function provided takes time to execute, this time is NOT taken from the next wait period
t = RepeatingTimer(30.0, f, args=[], kwargs={})
t.start()
t.cancel() # stop the timer's actions
"""
def __init__(self, interval, function, daemon=True, *args, **kwargs):
threading.Thread.__init__(self)
self.daemon = daemon
self.interval = float(interval)
self.function = function
self.args = args
self.kwargs = kwargs
self.finished = threading.Event()
def cancel(self):
"""Stop the timer if it hasn't finished yet"""
self.finished.set()
stop = cancel
def run(self):
while not self.finished.is_set():
self.finished.wait(self.interval)
if not self.finished.is_set(): #In case someone has canceled while waiting
try:
self.function(*self.args, **self.kwargs)
except:
pass
# logging.exception("Execution failed. Function: %r args: %r and kwargs: %r" % (self.function, self.args, self.kwargs))

12
src/mysc/restart.py Normal file
View File

@@ -0,0 +1,12 @@
# -*- coding: cp1252
import sys, os, config
def restart_program():
""" Function that restarts the application if is executed."""
config.main.write()
args = sys.argv[:]
if not hasattr(sys, "frozen"):
args.insert(0, sys.executable)
if sys.platform == 'win32':
args = ['"%s"' % arg for arg in args]
os.execv(sys.executable, args)

21
src/mysc/thread_utils.py Normal file
View File

@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
import threading
import wx
from twython import TwythonRateLimitError
import time
def call_threaded(func, *args, **kwargs):
#Call the given function in a daemonized thread and return the thread.
def new_func(*a, **k):
try:
func(*a, **k)
except TwythonRateLimitError:
wx.MessageDialog(None, u"Has superado el límite de llamadas a la API que Twitter permite. Eso puede deberse a muchas líneas temporales abiertas, a abrir y cerrar el programa en un periodo corto de tiempo, o a tener muchas llamadas a la API en tu configuración. TW Blue esperará 5 minutos y volverá a intentarlo.", u"Límite de llamadas a la API Superado", wx.ICON_ERROR|wx.OK).ShowModal()
time.sleep(300)
call_threaded(func, *args, **kwargs)
# except:
# pass
thread = threading.Thread(target=new_func, args=args, kwargs=kwargs)
thread.daemon = True
thread.start()
return thread