Add timer
This commit is contained in:
parent
4527ca3da6
commit
14630c1bd7
|
@ -526,11 +526,6 @@ def set_properties(model, properties):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def array_to_dict(values):
|
|
||||||
d = {r[0]: r[1] for r in values}
|
|
||||||
return d
|
|
||||||
|
|
||||||
|
|
||||||
# ~ Custom classes
|
# ~ Custom classes
|
||||||
class ObjectBase(object):
|
class ObjectBase(object):
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import platform
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
|
@ -56,8 +57,11 @@ try:
|
||||||
from peewee import Database, DateTimeField, DateField, TimeField, \
|
from peewee import Database, DateTimeField, DateField, TimeField, \
|
||||||
__exception_wrapper__
|
__exception_wrapper__
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
|
Database = object
|
||||||
|
DateField = object
|
||||||
|
TimeField = object
|
||||||
|
DateTimeField = object
|
||||||
print('Install peewee')
|
print('Install peewee')
|
||||||
peewee = None
|
|
||||||
|
|
||||||
|
|
||||||
LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
|
LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
|
||||||
|
@ -114,7 +118,7 @@ INFO_DEBUG = f"{sys.version}\n\n{platform.platform()}\n\n" + '\n'.join(sys.path)
|
||||||
|
|
||||||
|
|
||||||
SECONDS_DAY = 60 * 60 * 24
|
SECONDS_DAY = 60 * 60 * 24
|
||||||
|
_MACROS = {}
|
||||||
|
|
||||||
CTX = uno.getComponentContext()
|
CTX = uno.getComponentContext()
|
||||||
SM = CTX.getServiceManager()
|
SM = CTX.getServiceManager()
|
||||||
|
@ -160,14 +164,20 @@ d = get_app_config(node, 'DD')
|
||||||
DATE_OFFSET = datetime.date(y, m, d).toordinal()
|
DATE_OFFSET = datetime.date(y, m, d).toordinal()
|
||||||
|
|
||||||
|
|
||||||
|
def error(info):
|
||||||
|
log.error(info)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def debug(*args):
|
def debug(*args):
|
||||||
data = [str(a) for a in args]
|
data = [str(a) for a in args]
|
||||||
log.debug('\t'.join(data))
|
log.debug('\t'.join(data))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def error(info):
|
def info(*args):
|
||||||
log.error(info)
|
data = [str(a) for a in args]
|
||||||
|
log.info('\t'.join(data))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@ -255,6 +265,24 @@ def dict_to_property(values: dict, uno_any: bool=False):
|
||||||
return ps
|
return ps
|
||||||
|
|
||||||
|
|
||||||
|
def _array_to_dict(values):
|
||||||
|
d = {v[0]: v[1] for v in values}
|
||||||
|
return d
|
||||||
|
|
||||||
|
def _property_to_dict(values):
|
||||||
|
d = {v.Name: v.Value for v in values}
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
def data_to_dict(data):
|
||||||
|
if isinstance(data, tuple) and isinstance(data[0], tuple):
|
||||||
|
return _array_to_dict(data)
|
||||||
|
|
||||||
|
if isinstance(data, tuple) and isinstance(data[0], (PropertyValue, NamedValue)):
|
||||||
|
return _property_to_dict(data)
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
def _path_url(path: str) -> str:
|
def _path_url(path: str) -> str:
|
||||||
if path.startswith('file://'):
|
if path.startswith('file://'):
|
||||||
return path
|
return path
|
||||||
|
@ -319,6 +347,81 @@ def _struct_to_date(value):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
def _get_url_script(args):
|
||||||
|
library = args['library']
|
||||||
|
module = '.'
|
||||||
|
name = args['name']
|
||||||
|
language = args.get('language', 'Python')
|
||||||
|
location = args.get('location', 'user')
|
||||||
|
|
||||||
|
if language == 'Python':
|
||||||
|
module = '.py$'
|
||||||
|
elif language == 'Basic':
|
||||||
|
module = f".{module}."
|
||||||
|
if location == 'user':
|
||||||
|
location = 'application'
|
||||||
|
|
||||||
|
url = 'vnd.sun.star.script'
|
||||||
|
url = f'{url}:{library}{module}{name}?language={language}&location={location}'
|
||||||
|
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
|
def _call_macro(args):
|
||||||
|
#~ https://wiki.openoffice.org/wiki/Documentation/DevGuide/Scripting/Scripting_Framework_URI_Specification
|
||||||
|
|
||||||
|
url = _get_url_script(args)
|
||||||
|
args = args.get('args', ())
|
||||||
|
|
||||||
|
service = 'com.sun.star.script.provider.MasterScriptProviderFactory'
|
||||||
|
factory = create_instance(service)
|
||||||
|
script = factory.createScriptProvider('').getScript(url)
|
||||||
|
result = script.invoke(args, None, None)[0]
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def call_macro(args, in_thread=False):
|
||||||
|
result = None
|
||||||
|
if in_thread:
|
||||||
|
t = threading.Thread(target=_call_macro, args=(args,))
|
||||||
|
t.start()
|
||||||
|
else:
|
||||||
|
result = _call_macro(args)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class TimerThread(threading.Thread):
|
||||||
|
|
||||||
|
def __init__(self, event, seconds, macro):
|
||||||
|
threading.Thread.__init__(self)
|
||||||
|
self.stopped = event
|
||||||
|
self.seconds = seconds
|
||||||
|
self.macro = macro
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
info('Timer started... {}'.format(self.macro['name']))
|
||||||
|
while not self.stopped.wait(self.seconds):
|
||||||
|
_call_macro(self.macro)
|
||||||
|
info('Timer stopped... {}'.format(self.macro['name']))
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def start_timer(name, seconds, macro):
|
||||||
|
global _MACROS
|
||||||
|
_MACROS[name] = threading.Event()
|
||||||
|
thread = TimerThread(_MACROS[name], seconds, macro)
|
||||||
|
thread.start()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def stop_timer(name):
|
||||||
|
global _MACROS
|
||||||
|
_MACROS[name].set()
|
||||||
|
del _MACROS[name]
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
class LOBaseObject(object):
|
class LOBaseObject(object):
|
||||||
|
|
||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
|
@ -1943,11 +2046,8 @@ class LODialog(object):
|
||||||
|
|
||||||
class LOSheets(object):
|
class LOSheets(object):
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
return docs.active[index]
|
return LODocs().active[index]
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
|
@ -1958,11 +2058,8 @@ class LOSheets(object):
|
||||||
|
|
||||||
class LOCells(object):
|
class LOCells(object):
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
return docs.active.active[index]
|
return LODocs().active.active[index]
|
||||||
|
|
||||||
|
|
||||||
class Paths(object):
|
class Paths(object):
|
||||||
|
@ -1985,6 +2082,10 @@ def __getattr__(name):
|
||||||
return Paths()
|
return Paths()
|
||||||
if name == 'docs':
|
if name == 'docs':
|
||||||
return LODocs()
|
return LODocs()
|
||||||
|
if name == 'sheets':
|
||||||
|
return LOSheets()
|
||||||
|
if name == 'cells':
|
||||||
|
return LOCells()
|
||||||
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
||||||
|
|
||||||
|
|
||||||
|
@ -1998,10 +2099,6 @@ def get_fonts():
|
||||||
return device.FontDescriptors
|
return device.FontDescriptors
|
||||||
|
|
||||||
|
|
||||||
# ~ docs = LODocs()
|
|
||||||
sheets = LOSheets()
|
|
||||||
cells = LOCells()
|
|
||||||
|
|
||||||
# ~ https://en.wikipedia.org/wiki/Web_colors
|
# ~ https://en.wikipedia.org/wiki/Web_colors
|
||||||
def get_color(value):
|
def get_color(value):
|
||||||
COLORS = {
|
COLORS = {
|
||||||
|
|
Loading…
Reference in New Issue