Added some code for starting

This commit is contained in:
2016-02-13 17:06:36 -06:00
parent 364472da5c
commit 0266100d66
110 changed files with 6044 additions and 0 deletions

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

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

@@ -0,0 +1,17 @@
import os
import languageHandler
import logging
log = logging.getLogger("mysc.localization")
def get(rootFolder):
log.debug("Getting documentation folder. RootFolder: %s" % (rootFolder,))
defaultLocale = languageHandler.curLang
if len(defaultLocale) > 2:
defaultLocale = defaultLocale[:2]
log.debug("Locale: %s" % (defaultLocale,))
if os.path.exists(rootFolder+"/"+defaultLocale):
return defaultLocale
else:
log.debug("The folder does not exist, using the English folder...")
return "en"

View File

@@ -0,0 +1,36 @@
import threading
import logging
log = logging.getLogger("mysc.repeating_timer")
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"""
log.debug("Stopping repeater for %s" % (self.function,))
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:
log.exception("Execution failed. Function: %r args: %r and kwargs: %r" % (self.function, self.args, self.kwargs))

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

@@ -0,0 +1,11 @@
# -*- coding: cp1252
import sys, os
def restart_program():
""" Function that restarts the application if is executed."""
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)

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

@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
import threading
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:
# pass
thread = threading.Thread(target=new_func, args=args, kwargs=kwargs)
thread.daemon = True
thread.start()
return thread